]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/s390/scsi/zfcp_dbf.c
scsi: zfcp: clean up unnecessary module_param_named() with no_auto_port_rescan
[mirror_ubuntu-bionic-kernel.git] / drivers / s390 / scsi / zfcp_dbf.c
CommitLineData
8a36e453 1/*
553448f6 2 * zfcp device driver
8a36e453 3 *
553448f6 4 * Debug traces for zfcp.
8a36e453 5 *
975171b4 6 * Copyright IBM Corp. 2002, 2017
8a36e453
MS
7 */
8
ecf39d42
CS
9#define KMSG_COMPONENT "zfcp"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11
3a4c5d59 12#include <linux/module.h>
8a36e453 13#include <linux/ctype.h>
5a0e3ad6 14#include <linux/slab.h>
364c8558 15#include <asm/debug.h>
d46f384a 16#include "zfcp_dbf.h"
8a36e453 17#include "zfcp_ext.h"
bd0072ec 18#include "zfcp_fc.h"
8a36e453
MS
19
20static u32 dbfsize = 4;
21
22module_param(dbfsize, uint, 0400);
23MODULE_PARM_DESC(dbfsize,
24 "number of pages for each debug feature area (default 4)");
25
bf3ea3ae
SM
26static u32 dbflevel = 3;
27
28module_param(dbflevel, uint, 0400);
29MODULE_PARM_DESC(dbflevel,
30 "log level for each debug feature area "
31 "(default 3, range 0..6)");
32
a54ca0f6 33static inline unsigned int zfcp_dbf_plen(unsigned int offset)
c15450e3 34{
a54ca0f6
SS
35 return sizeof(struct zfcp_dbf_pay) + offset - ZFCP_DBF_PAY_MAX_REC;
36}
37
38static inline
39void zfcp_dbf_pl_write(struct zfcp_dbf *dbf, void *data, u16 length, char *area,
40 u64 req_id)
41{
42 struct zfcp_dbf_pay *pl = &dbf->pay_buf;
43 u16 offset = 0, rec_length;
44
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);
49
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));
55
56 offset += rec_length;
57 pl->counter++;
c15450e3 58 }
a54ca0f6
SS
59
60 spin_unlock(&dbf->pay_lock);
c15450e3
MP
61}
62
a54ca0f6
SS
63/**
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
67 */
35f040df 68void zfcp_dbf_hba_fsf_res(char *tag, int level, struct zfcp_fsf_req *req)
8a36e453 69{
a54ca0f6
SS
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;
8a36e453
MS
74 unsigned long flags;
75
5771710b 76 spin_lock_irqsave(&dbf->hba_lock, flags);
6bc473dd 77 memset(rec, 0, sizeof(*rec));
8a36e453 78
a54ca0f6
SS
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;
7c964ffe
SM
88 rec->u.res.port_handle = q_head->port_handle;
89 rec->u.res.lun_handle = q_head->lun_handle;
a54ca0f6
SS
90
91 memcpy(rec->u.res.prot_status_qual, &q_pref->prot_status_qual,
92 FSF_PROT_STATUS_QUAL_SIZE);
93 memcpy(rec->u.res.fsf_status_qual, &q_head->fsf_status_qual,
94 FSF_STATUS_QUALIFIER_SIZE);
95
96 if (req->fsf_command != FSF_QTCB_FCP_CMND) {
97 rec->pl_len = q_head->log_length;
98 zfcp_dbf_pl_write(dbf, (char *)q_pref + q_head->log_start,
99 rec->pl_len, "fsf_res", req->req_id);
8a36e453
MS
100 }
101
35f040df 102 debug_event(dbf->hba, level, rec, sizeof(*rec));
5771710b 103 spin_unlock_irqrestore(&dbf->hba_lock, flags);
8a36e453
MS
104}
105
bfab1637 106/**
a54ca0f6
SS
107 * zfcp_dbf_hba_fsf_uss - trace event for an unsolicited status buffer
108 * @tag: tag indicating which kind of unsolicited status has been received
109 * @req: request providing the unsolicited status
bfab1637 110 */
a54ca0f6 111void zfcp_dbf_hba_fsf_uss(char *tag, struct zfcp_fsf_req *req)
8a36e453 112{
a54ca0f6
SS
113 struct zfcp_dbf *dbf = req->adapter->dbf;
114 struct fsf_status_read_buffer *srb = req->data;
115 struct zfcp_dbf_hba *rec = &dbf->hba_buf;
8a36e453
MS
116 unsigned long flags;
117
5771710b 118 spin_lock_irqsave(&dbf->hba_lock, flags);
a54ca0f6
SS
119 memset(rec, 0, sizeof(*rec));
120
121 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
122 rec->id = ZFCP_DBF_HBA_USS;
123 rec->fsf_req_id = req->req_id;
124 rec->fsf_req_status = req->status;
125 rec->fsf_cmd = req->fsf_command;
126
127 if (!srb)
128 goto log;
129
130 rec->u.uss.status_type = srb->status_type;
131 rec->u.uss.status_subtype = srb->status_subtype;
132 rec->u.uss.d_id = ntoh24(srb->d_id);
133 rec->u.uss.lun = srb->fcp_lun;
134 memcpy(&rec->u.uss.queue_designator, &srb->queue_designator,
135 sizeof(rec->u.uss.queue_designator));
136
137 /* status read buffer payload length */
138 rec->pl_len = (!srb->length) ? 0 : srb->length -
139 offsetof(struct fsf_status_read_buffer, payload);
140
141 if (rec->pl_len)
142 zfcp_dbf_pl_write(dbf, srb->payload.data, rec->pl_len,
143 "fsf_uss", req->req_id);
144log:
145 debug_event(dbf->hba, 2, rec, sizeof(*rec));
5771710b 146 spin_unlock_irqrestore(&dbf->hba_lock, flags);
8a36e453
MS
147}
148
57069386 149/**
a54ca0f6
SS
150 * zfcp_dbf_hba_bit_err - trace event for bit error conditions
151 * @tag: tag indicating which kind of unsolicited status has been received
152 * @req: request which caused the bit_error condition
57069386 153 */
a54ca0f6 154void zfcp_dbf_hba_bit_err(char *tag, struct zfcp_fsf_req *req)
57069386 155{
a54ca0f6
SS
156 struct zfcp_dbf *dbf = req->adapter->dbf;
157 struct zfcp_dbf_hba *rec = &dbf->hba_buf;
57069386 158 struct fsf_status_read_buffer *sr_buf = req->data;
57069386
SS
159 unsigned long flags;
160
5771710b 161 spin_lock_irqsave(&dbf->hba_lock, flags);
a54ca0f6 162 memset(rec, 0, sizeof(*rec));
8a36e453 163
a54ca0f6
SS
164 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
165 rec->id = ZFCP_DBF_HBA_BIT;
166 rec->fsf_req_id = req->req_id;
167 rec->fsf_req_status = req->status;
168 rec->fsf_cmd = req->fsf_command;
169 memcpy(&rec->u.be, &sr_buf->payload.bit_error,
170 sizeof(struct fsf_bit_error_payload));
171
172 debug_event(dbf->hba, 1, rec, sizeof(*rec));
173 spin_unlock_irqrestore(&dbf->hba_lock, flags);
8a36e453
MS
174}
175
86a9668a
SS
176/**
177 * zfcp_dbf_hba_def_err - trace event for deferred error messages
178 * @adapter: pointer to struct zfcp_adapter
179 * @req_id: request id which caused the deferred error message
180 * @scount: number of sbals incl. the signaling sbal
181 * @pl: array of all involved sbals
182 */
183void zfcp_dbf_hba_def_err(struct zfcp_adapter *adapter, u64 req_id, u16 scount,
184 void **pl)
185{
186 struct zfcp_dbf *dbf = adapter->dbf;
187 struct zfcp_dbf_pay *payload = &dbf->pay_buf;
188 unsigned long flags;
189 u16 length;
190
191 if (!pl)
192 return;
193
194 spin_lock_irqsave(&dbf->pay_lock, flags);
195 memset(payload, 0, sizeof(*payload));
196
197 memcpy(payload->area, "def_err", 7);
198 payload->fsf_req_id = req_id;
199 payload->counter = 0;
200 length = min((u16)sizeof(struct qdio_buffer),
201 (u16)ZFCP_DBF_PAY_MAX_REC);
202
01e60527 203 while (payload->counter < scount && (char *)pl[payload->counter]) {
86a9668a
SS
204 memcpy(payload->data, (char *)pl[payload->counter], length);
205 debug_event(dbf->pay, 1, payload, zfcp_dbf_plen(length));
206 payload->counter++;
207 }
208
209 spin_unlock_irqrestore(&dbf->pay_lock, flags);
210}
211
cb452149
SM
212/**
213 * zfcp_dbf_hba_basic - trace event for basic adapter events
214 * @adapter: pointer to struct zfcp_adapter
215 */
216void zfcp_dbf_hba_basic(char *tag, struct zfcp_adapter *adapter)
217{
218 struct zfcp_dbf *dbf = adapter->dbf;
219 struct zfcp_dbf_hba *rec = &dbf->hba_buf;
220 unsigned long flags;
221
222 spin_lock_irqsave(&dbf->hba_lock, flags);
223 memset(rec, 0, sizeof(*rec));
224
225 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
226 rec->id = ZFCP_DBF_HBA_BASIC;
227
228 debug_event(dbf->hba, 1, rec, sizeof(*rec));
229 spin_unlock_irqrestore(&dbf->hba_lock, flags);
230}
231
ae0904f6
SS
232static void zfcp_dbf_set_common(struct zfcp_dbf_rec *rec,
233 struct zfcp_adapter *adapter,
234 struct zfcp_port *port,
235 struct scsi_device *sdev)
d79a83db 236{
ae0904f6
SS
237 rec->adapter_status = atomic_read(&adapter->status);
238 if (port) {
239 rec->port_status = atomic_read(&port->status);
240 rec->wwpn = port->wwpn;
241 rec->d_id = port->d_id;
242 }
243 if (sdev) {
244 rec->lun_status = atomic_read(&sdev_to_zfcp(sdev)->status);
245 rec->lun = zfcp_scsi_dev_lun(sdev);
0102a30a
SM
246 } else
247 rec->lun = ZFCP_DBF_INVALID_LUN;
d79a83db
MP
248}
249
348447e8 250/**
ae0904f6
SS
251 * zfcp_dbf_rec_trig - trace event related to triggered recovery
252 * @tag: identifier for event
253 * @adapter: adapter on which the erp_action should run
254 * @port: remote port involved in the erp_action
255 * @sdev: scsi device involved in the erp_action
256 * @want: wanted erp_action
257 * @need: required erp_action
258 *
259 * The adapter->erp_lock has to be held.
348447e8 260 */
ae0904f6
SS
261void zfcp_dbf_rec_trig(char *tag, struct zfcp_adapter *adapter,
262 struct zfcp_port *port, struct scsi_device *sdev,
263 u8 want, u8 need)
348447e8 264{
ae0904f6
SS
265 struct zfcp_dbf *dbf = adapter->dbf;
266 struct zfcp_dbf_rec *rec = &dbf->rec_buf;
348447e8 267 struct list_head *entry;
698ec016
MP
268 unsigned long flags;
269
5771710b 270 spin_lock_irqsave(&dbf->rec_lock, flags);
ae0904f6 271 memset(rec, 0, sizeof(*rec));
5771710b 272
ae0904f6
SS
273 rec->id = ZFCP_DBF_REC_TRIG;
274 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
275 zfcp_dbf_set_common(rec, adapter, port, sdev);
698ec016 276
ae0904f6
SS
277 list_for_each(entry, &adapter->erp_ready_head)
278 rec->u.trig.ready++;
698ec016 279
ae0904f6
SS
280 list_for_each(entry, &adapter->erp_running_head)
281 rec->u.trig.running++;
698ec016 282
ae0904f6
SS
283 rec->u.trig.want = want;
284 rec->u.trig.need = need;
698ec016 285
ae0904f6
SS
286 debug_event(dbf->rec, 1, rec, sizeof(*rec));
287 spin_unlock_irqrestore(&dbf->rec_lock, flags);
698ec016
MP
288}
289
ae0904f6 290
9467a9b3 291/**
6f2ce1c6
SM
292 * zfcp_dbf_rec_run_lvl - trace event related to running recovery
293 * @level: trace level to be used for event
ae0904f6
SS
294 * @tag: identifier for event
295 * @erp: erp_action running
9467a9b3 296 */
6f2ce1c6 297void zfcp_dbf_rec_run_lvl(int level, char *tag, struct zfcp_erp_action *erp)
9467a9b3 298{
ae0904f6
SS
299 struct zfcp_dbf *dbf = erp->adapter->dbf;
300 struct zfcp_dbf_rec *rec = &dbf->rec_buf;
9467a9b3
MP
301 unsigned long flags;
302
5771710b 303 spin_lock_irqsave(&dbf->rec_lock, flags);
ae0904f6 304 memset(rec, 0, sizeof(*rec));
9467a9b3 305
ae0904f6
SS
306 rec->id = ZFCP_DBF_REC_RUN;
307 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
308 zfcp_dbf_set_common(rec, erp->adapter, erp->port, erp->sdev);
6f4f365e 309
ae0904f6
SS
310 rec->u.run.fsf_req_id = erp->fsf_req_id;
311 rec->u.run.rec_status = erp->status;
312 rec->u.run.rec_step = erp->step;
313 rec->u.run.rec_action = erp->action;
314
315 if (erp->sdev)
316 rec->u.run.rec_count =
317 atomic_read(&sdev_to_zfcp(erp->sdev)->erp_counter);
318 else if (erp->port)
319 rec->u.run.rec_count = atomic_read(&erp->port->erp_counter);
320 else
321 rec->u.run.rec_count = atomic_read(&erp->adapter->erp_counter);
322
6f2ce1c6 323 debug_event(dbf->rec, level, rec, sizeof(*rec));
5771710b 324 spin_unlock_irqrestore(&dbf->rec_lock, flags);
6f4f365e
MP
325}
326
6f2ce1c6
SM
327/**
328 * zfcp_dbf_rec_run - trace event related to running recovery
329 * @tag: identifier for event
330 * @erp: erp_action running
331 */
332void zfcp_dbf_rec_run(char *tag, struct zfcp_erp_action *erp)
333{
334 zfcp_dbf_rec_run_lvl(1, tag, erp);
335}
336
d27a7cb9
SM
337/**
338 * zfcp_dbf_rec_run_wka - trace wka port event with info like running recovery
339 * @tag: identifier for event
340 * @wka_port: well known address port
341 * @req_id: request ID to correlate with potential HBA trace record
342 */
343void zfcp_dbf_rec_run_wka(char *tag, struct zfcp_fc_wka_port *wka_port,
344 u64 req_id)
345{
346 struct zfcp_dbf *dbf = wka_port->adapter->dbf;
347 struct zfcp_dbf_rec *rec = &dbf->rec_buf;
348 unsigned long flags;
349
350 spin_lock_irqsave(&dbf->rec_lock, flags);
351 memset(rec, 0, sizeof(*rec));
352
353 rec->id = ZFCP_DBF_REC_RUN;
354 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
355 rec->port_status = wka_port->status;
356 rec->d_id = wka_port->d_id;
357 rec->lun = ZFCP_DBF_INVALID_LUN;
358
359 rec->u.run.fsf_req_id = req_id;
360 rec->u.run.rec_status = ~0;
361 rec->u.run.rec_step = ~0;
362 rec->u.run.rec_action = ~0;
363 rec->u.run.rec_count = ~0;
364
365 debug_event(dbf->rec, 1, rec, sizeof(*rec));
366 spin_unlock_irqrestore(&dbf->rec_lock, flags);
367}
368
2c55b750 369static inline
aceeffbb
SM
370void zfcp_dbf_san(char *tag, struct zfcp_dbf *dbf,
371 char *paytag, struct scatterlist *sg, u8 id, u16 len,
372 u64 req_id, u32 d_id, u16 cap_len)
8a36e453 373{
2c55b750
SS
374 struct zfcp_dbf_san *rec = &dbf->san_buf;
375 u16 rec_len;
6bc473dd 376 unsigned long flags;
aceeffbb
SM
377 struct zfcp_dbf_pay *payload = &dbf->pay_buf;
378 u16 pay_sum = 0;
8a36e453 379
5771710b 380 spin_lock_irqsave(&dbf->san_lock, flags);
2c55b750 381 memset(rec, 0, sizeof(*rec));
8a36e453 382
2c55b750
SS
383 rec->id = id;
384 rec->fsf_req_id = req_id;
385 rec->d_id = d_id;
2c55b750 386 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
aceeffbb
SM
387 rec->pl_len = len; /* full length even if we cap pay below */
388 if (!sg)
389 goto out;
390 rec_len = min_t(unsigned int, sg->length, ZFCP_DBF_SAN_MAX_PAYLOAD);
391 memcpy(rec->payload, sg_virt(sg), rec_len); /* part of 1st sg entry */
392 if (len <= rec_len)
393 goto out; /* skip pay record if full content in rec->payload */
394
395 /* if (len > rec_len):
396 * dump data up to cap_len ignoring small duplicate in rec->payload
397 */
e7cb08e8 398 spin_lock(&dbf->pay_lock);
aceeffbb
SM
399 memset(payload, 0, sizeof(*payload));
400 memcpy(payload->area, paytag, ZFCP_DBF_TAG_LEN);
401 payload->fsf_req_id = req_id;
402 payload->counter = 0;
403 for (; sg && pay_sum < cap_len; sg = sg_next(sg)) {
404 u16 pay_len, offset = 0;
405
406 while (offset < sg->length && pay_sum < cap_len) {
407 pay_len = min((u16)ZFCP_DBF_PAY_MAX_REC,
408 (u16)(sg->length - offset));
409 /* cap_len <= pay_sum < cap_len+ZFCP_DBF_PAY_MAX_REC */
410 memcpy(payload->data, sg_virt(sg) + offset, pay_len);
411 debug_event(dbf->pay, 1, payload,
412 zfcp_dbf_plen(pay_len));
413 payload->counter++;
414 offset += pay_len;
415 pay_sum += pay_len;
416 }
417 }
418 spin_unlock(&dbf->pay_lock);
8a36e453 419
aceeffbb 420out:
2c55b750 421 debug_event(dbf->san, 1, rec, sizeof(*rec));
5771710b 422 spin_unlock_irqrestore(&dbf->san_lock, flags);
8a36e453
MS
423}
424
bfab1637 425/**
2c55b750 426 * zfcp_dbf_san_req - trace event for issued SAN request
3f79410c 427 * @tag: identifier for event
2c55b750
SS
428 * @fsf_req: request containing issued CT data
429 * d_id: destination ID
bfab1637 430 */
2c55b750 431void zfcp_dbf_san_req(char *tag, struct zfcp_fsf_req *fsf, u32 d_id)
8a36e453 432{
2c55b750
SS
433 struct zfcp_dbf *dbf = fsf->adapter->dbf;
434 struct zfcp_fsf_ct_els *ct_els = fsf->data;
435 u16 length;
8a36e453 436
aceeffbb
SM
437 length = (u16)zfcp_qdio_real_bytes(ct_els->req);
438 zfcp_dbf_san(tag, dbf, "san_req", ct_els->req, ZFCP_DBF_SAN_REQ,
439 length, fsf->req_id, d_id, length);
440}
441
442static u16 zfcp_dbf_san_res_cap_len_if_gpn_ft(char *tag,
443 struct zfcp_fsf_req *fsf,
444 u16 len)
445{
446 struct zfcp_fsf_ct_els *ct_els = fsf->data;
447 struct fc_ct_hdr *reqh = sg_virt(ct_els->req);
448 struct fc_ns_gid_ft *reqn = (struct fc_ns_gid_ft *)(reqh + 1);
449 struct scatterlist *resp_entry = ct_els->resp;
975171b4 450 struct fc_ct_hdr *resph;
aceeffbb
SM
451 struct fc_gpn_ft_resp *acc;
452 int max_entries, x, last = 0;
453
454 if (!(memcmp(tag, "fsscth2", 7) == 0
455 && ct_els->d_id == FC_FID_DIR_SERV
456 && reqh->ct_rev == FC_CT_REV
457 && reqh->ct_in_id[0] == 0
458 && reqh->ct_in_id[1] == 0
459 && reqh->ct_in_id[2] == 0
460 && reqh->ct_fs_type == FC_FST_DIR
461 && reqh->ct_fs_subtype == FC_NS_SUBTYPE
462 && reqh->ct_options == 0
463 && reqh->_ct_resvd1 == 0
9d464fc1 464 && reqh->ct_cmd == cpu_to_be16(FC_NS_GPN_FT)
aceeffbb
SM
465 /* reqh->ct_mr_size can vary so do not match but read below */
466 && reqh->_ct_resvd2 == 0
467 && reqh->ct_reason == 0
468 && reqh->ct_explan == 0
469 && reqh->ct_vendor == 0
470 && reqn->fn_resvd == 0
471 && reqn->fn_domain_id_scope == 0
472 && reqn->fn_area_id_scope == 0
473 && reqn->fn_fc4_type == FC_TYPE_FCP))
474 return len; /* not GPN_FT response so do not cap */
475
476 acc = sg_virt(resp_entry);
975171b4
SM
477
478 /* cap all but accept CT responses to at least the CT header */
479 resph = (struct fc_ct_hdr *)acc;
480 if ((ct_els->status) ||
481 (resph->ct_cmd != cpu_to_be16(FC_FS_ACC)))
482 return max(FC_CT_HDR_LEN, ZFCP_DBF_SAN_MAX_PAYLOAD);
483
9d464fc1
SM
484 max_entries = (be16_to_cpu(reqh->ct_mr_size) * 4 /
485 sizeof(struct fc_gpn_ft_resp))
aceeffbb
SM
486 + 1 /* zfcp_fc_scan_ports: bytes correct, entries off-by-one
487 * to account for header as 1st pseudo "entry" */;
488
489 /* the basic CT_IU preamble is the same size as one entry in the GPN_FT
490 * response, allowing us to skip special handling for it - just skip it
491 */
492 for (x = 1; x < max_entries && !last; x++) {
493 if (x % (ZFCP_FC_GPN_FT_ENT_PAGE + 1))
494 acc++;
495 else
496 acc = sg_virt(++resp_entry);
497
498 last = acc->fp_flags & FC_NS_FID_LAST;
499 }
500 len = min(len, (u16)(x * sizeof(struct fc_gpn_ft_resp)));
501 return len; /* cap after last entry */
8a36e453
MS
502}
503
bfab1637 504/**
2c55b750 505 * zfcp_dbf_san_res - trace event for received SAN request
3f79410c 506 * @tag: identifier for event
2c55b750 507 * @fsf_req: request containing issued CT data
bfab1637 508 */
2c55b750 509void zfcp_dbf_san_res(char *tag, struct zfcp_fsf_req *fsf)
8a36e453 510{
2c55b750
SS
511 struct zfcp_dbf *dbf = fsf->adapter->dbf;
512 struct zfcp_fsf_ct_els *ct_els = fsf->data;
513 u16 length;
8a36e453 514
aceeffbb
SM
515 length = (u16)zfcp_qdio_real_bytes(ct_els->resp);
516 zfcp_dbf_san(tag, dbf, "san_res", ct_els->resp, ZFCP_DBF_SAN_RES,
517 length, fsf->req_id, ct_els->d_id,
518 zfcp_dbf_san_res_cap_len_if_gpn_ft(tag, fsf, length));
8a36e453
MS
519}
520
bfab1637 521/**
2c55b750 522 * zfcp_dbf_san_in_els - trace event for incoming ELS
3f79410c 523 * @tag: identifier for event
2c55b750 524 * @fsf_req: request containing issued CT data
bfab1637 525 */
2c55b750 526void zfcp_dbf_san_in_els(char *tag, struct zfcp_fsf_req *fsf)
8a36e453 527{
2c55b750
SS
528 struct zfcp_dbf *dbf = fsf->adapter->dbf;
529 struct fsf_status_read_buffer *srb =
530 (struct fsf_status_read_buffer *) fsf->data;
531 u16 length;
aceeffbb 532 struct scatterlist sg;
2c55b750
SS
533
534 length = (u16)(srb->length -
535 offsetof(struct fsf_status_read_buffer, payload));
aceeffbb
SM
536 sg_init_one(&sg, srb->payload.data, length);
537 zfcp_dbf_san(tag, dbf, "san_els", &sg, ZFCP_DBF_SAN_ELS, length,
538 fsf->req_id, ntoh24(srb->d_id), length);
8a36e453
MS
539}
540
250a1352
SS
541/**
542 * zfcp_dbf_scsi - trace event for scsi commands
543 * @tag: identifier for event
544 * @sc: pointer to struct scsi_cmnd
545 * @fsf: pointer to struct zfcp_fsf_req
546 */
35f040df
SM
547void zfcp_dbf_scsi(char *tag, int level, struct scsi_cmnd *sc,
548 struct zfcp_fsf_req *fsf)
8a36e453 549{
250a1352
SS
550 struct zfcp_adapter *adapter =
551 (struct zfcp_adapter *) sc->device->host->hostdata[0];
552 struct zfcp_dbf *dbf = adapter->dbf;
553 struct zfcp_dbf_scsi *rec = &dbf->scsi_buf;
4318e08c 554 struct fcp_resp_with_ext *fcp_rsp;
250a1352
SS
555 struct fcp_resp_rsp_info *fcp_rsp_info;
556 unsigned long flags;
8a36e453 557
5771710b 558 spin_lock_irqsave(&dbf->scsi_lock, flags);
250a1352 559 memset(rec, 0, sizeof(*rec));
8a36e453 560
250a1352
SS
561 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
562 rec->id = ZFCP_DBF_SCSI_CMND;
563 rec->scsi_result = sc->result;
564 rec->scsi_retries = sc->retries;
565 rec->scsi_allowed = sc->allowed;
566 rec->scsi_id = sc->device->id;
9cb78c16 567 rec->scsi_lun = (u32)sc->device->lun;
5d4a3d0a 568 rec->scsi_lun_64_hi = (u32)(sc->device->lun >> 32);
250a1352
SS
569 rec->host_scribble = (unsigned long)sc->host_scribble;
570
571 memcpy(rec->scsi_opcode, sc->cmnd,
572 min((int)sc->cmd_len, ZFCP_DBF_SCSI_OPCODE));
573
574 if (fsf) {
575 rec->fsf_req_id = fsf->req_id;
12c3e575 576 rec->pl_len = FCP_RESP_WITH_EXT;
df00d7b8 577 fcp_rsp = &(fsf->qtcb->bottom.io.fcp_rsp.iu);
12c3e575 578 /* mandatory parts of FCP_RSP IU in this SCSI record */
250a1352
SS
579 memcpy(&rec->fcp_rsp, fcp_rsp, FCP_RESP_WITH_EXT);
580 if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL) {
581 fcp_rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
582 rec->fcp_rsp_info = fcp_rsp_info->rsp_code;
12c3e575 583 rec->pl_len += be32_to_cpu(fcp_rsp->ext.fr_rsp_len);
250a1352
SS
584 }
585 if (fcp_rsp->resp.fr_flags & FCP_SNS_LEN_VAL) {
12c3e575 586 rec->pl_len += be32_to_cpu(fcp_rsp->ext.fr_sns_len);
250a1352 587 }
12c3e575
SM
588 /* complete FCP_RSP IU in associated PAYload record
589 * but only if there are optional parts
590 */
591 if (fcp_rsp->resp.fr_flags != 0)
592 zfcp_dbf_pl_write(
593 dbf, fcp_rsp,
594 /* at least one full PAY record
595 * but not beyond hardware response field
596 */
597 min_t(u16, max_t(u16, rec->pl_len,
598 ZFCP_DBF_PAY_MAX_REC),
599 FSF_FCP_RSP_SIZE),
600 "fcp_riu", fsf->req_id);
8a36e453 601 }
8a36e453 602
35f040df 603 debug_event(dbf->scsi, level, rec, sizeof(*rec));
250a1352
SS
604 spin_unlock_irqrestore(&dbf->scsi_lock, flags);
605}
8a36e453 606
ea4a3a6a 607static debug_info_t *zfcp_dbf_reg(const char *name, int size, int rec_size)
d46f384a
CS
608{
609 struct debug_info *d;
610
ea4a3a6a 611 d = debug_register(name, size, 1, rec_size);
d46f384a
CS
612 if (!d)
613 return NULL;
614
615 debug_register_view(d, &debug_hex_ascii_view);
bf3ea3ae 616 debug_set_level(d, dbflevel);
d46f384a
CS
617
618 return d;
619}
620
ea4a3a6a
SS
621static void zfcp_dbf_unregister(struct zfcp_dbf *dbf)
622{
623 if (!dbf)
624 return;
625
626 debug_unregister(dbf->scsi);
627 debug_unregister(dbf->san);
628 debug_unregister(dbf->hba);
629 debug_unregister(dbf->pay);
630 debug_unregister(dbf->rec);
631 kfree(dbf);
632}
633
8a36e453
MS
634/**
635 * zfcp_adapter_debug_register - registers debug feature for an adapter
636 * @adapter: pointer to adapter for which debug features should be registered
637 * return: -ENOMEM on error, 0 otherwise
638 */
5771710b 639int zfcp_dbf_adapter_register(struct zfcp_adapter *adapter)
8a36e453 640{
ea4a3a6a 641 char name[DEBUG_MAX_NAME_LEN];
d46f384a
CS
642 struct zfcp_dbf *dbf;
643
d23948ea 644 dbf = kzalloc(sizeof(struct zfcp_dbf), GFP_KERNEL);
d46f384a
CS
645 if (!dbf)
646 return -ENOMEM;
647
a54ca0f6 648 spin_lock_init(&dbf->pay_lock);
5771710b
SS
649 spin_lock_init(&dbf->hba_lock);
650 spin_lock_init(&dbf->san_lock);
651 spin_lock_init(&dbf->scsi_lock);
652 spin_lock_init(&dbf->rec_lock);
8a36e453 653
d79a83db 654 /* debug feature area which records recovery activity */
ea4a3a6a
SS
655 sprintf(name, "zfcp_%s_rec", dev_name(&adapter->ccw_device->dev));
656 dbf->rec = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_rec));
5771710b
SS
657 if (!dbf->rec)
658 goto err_out;
d79a83db 659
8a36e453 660 /* debug feature area which records HBA (FSF and QDIO) conditions */
ea4a3a6a
SS
661 sprintf(name, "zfcp_%s_hba", dev_name(&adapter->ccw_device->dev));
662 dbf->hba = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_hba));
5771710b
SS
663 if (!dbf->hba)
664 goto err_out;
8a36e453 665
a54ca0f6 666 /* debug feature area which records payload info */
ea4a3a6a
SS
667 sprintf(name, "zfcp_%s_pay", dev_name(&adapter->ccw_device->dev));
668 dbf->pay = zfcp_dbf_reg(name, dbfsize * 2, sizeof(struct zfcp_dbf_pay));
a54ca0f6
SS
669 if (!dbf->pay)
670 goto err_out;
671
8a36e453 672 /* debug feature area which records SAN command failures and recovery */
ea4a3a6a
SS
673 sprintf(name, "zfcp_%s_san", dev_name(&adapter->ccw_device->dev));
674 dbf->san = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_san));
5771710b
SS
675 if (!dbf->san)
676 goto err_out;
8a36e453
MS
677
678 /* debug feature area which records SCSI command failures and recovery */
ea4a3a6a
SS
679 sprintf(name, "zfcp_%s_scsi", dev_name(&adapter->ccw_device->dev));
680 dbf->scsi = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_scsi));
5771710b
SS
681 if (!dbf->scsi)
682 goto err_out;
8a36e453 683
d46f384a 684 adapter->dbf = dbf;
8a36e453 685
ea4a3a6a 686 return 0;
5771710b 687err_out:
ea4a3a6a 688 zfcp_dbf_unregister(dbf);
8a36e453
MS
689 return -ENOMEM;
690}
691
692/**
693 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
ea4a3a6a 694 * @adapter: pointer to adapter for which debug features should be unregistered
8a36e453 695 */
ea4a3a6a 696void zfcp_dbf_adapter_unregister(struct zfcp_adapter *adapter)
8a36e453 697{
ea4a3a6a
SS
698 struct zfcp_dbf *dbf = adapter->dbf;
699
700 adapter->dbf = NULL;
701 zfcp_dbf_unregister(dbf);
8a36e453 702}
5771710b 703