b57a47b64b80af6b520e6036e6d7972f5da43d7f
[pandora-kernel.git] / drivers / s390 / scsi / zfcp_dbf.c
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 <linux/slab.h>
14 #include <asm/debug.h>
15 #include "zfcp_dbf.h"
16 #include "zfcp_ext.h"
17 #include "zfcp_fc.h"
18
19 static u32 dbfsize = 4;
20
21 module_param(dbfsize, uint, 0400);
22 MODULE_PARM_DESC(dbfsize,
23                  "number of pages for each debug feature area (default 4)");
24
25 static inline unsigned int zfcp_dbf_plen(unsigned int offset)
26 {
27         return sizeof(struct zfcp_dbf_pay) + offset - ZFCP_DBF_PAY_MAX_REC;
28 }
29
30 static inline
31 void zfcp_dbf_pl_write(struct zfcp_dbf *dbf, void *data, u16 length, char *area,
32                        u64 req_id)
33 {
34         struct zfcp_dbf_pay *pl = &dbf->pay_buf;
35         u16 offset = 0, rec_length;
36
37         spin_lock(&dbf->pay_lock);
38         memset(pl, 0, sizeof(*pl));
39         pl->fsf_req_id = req_id;
40         memcpy(pl->area, area, ZFCP_DBF_TAG_LEN);
41
42         while (offset < length) {
43                 rec_length = min((u16) ZFCP_DBF_PAY_MAX_REC,
44                                  (u16) (length - offset));
45                 memcpy(pl->data, data + offset, rec_length);
46                 debug_event(dbf->pay, 1, pl, zfcp_dbf_plen(rec_length));
47
48                 offset += rec_length;
49                 pl->counter++;
50         }
51
52         spin_unlock(&dbf->pay_lock);
53 }
54
55 static void zfcp_dbf_tag(char **p, const char *label, const char *tag)
56 {
57         int i;
58
59         *p += sprintf(*p, "%-24s", label);
60         for (i = 0; i < ZFCP_DBF_TAG_SIZE; i++)
61                 *p += sprintf(*p, "%c", tag[i]);
62         *p += sprintf(*p, "\n");
63 }
64
65 static void zfcp_dbf_out(char **buf, const char *s, const char *format, ...)
66 {
67         va_list arg;
68
69         *buf += sprintf(*buf, "%-24s", s);
70         va_start(arg, format);
71         *buf += vsprintf(*buf, format, arg);
72         va_end(arg);
73         *buf += sprintf(*buf, "\n");
74 }
75
76 static void zfcp_dbf_outd(char **p, const char *label, char *buffer,
77                           int buflen, int offset, int total_size)
78 {
79         if (!offset)
80                 *p += sprintf(*p, "%-24s  ", label);
81         while (buflen--) {
82                 if (offset > 0) {
83                         if ((offset % 32) == 0)
84                                 *p += sprintf(*p, "\n%-24c  ", ' ');
85                         else if ((offset % 4) == 0)
86                                 *p += sprintf(*p, " ");
87                 }
88                 *p += sprintf(*p, "%02x", *buffer++);
89                 if (++offset == total_size) {
90                         *p += sprintf(*p, "\n");
91                         break;
92                 }
93         }
94         if (!total_size)
95                 *p += sprintf(*p, "\n");
96 }
97
98 static int zfcp_dbf_view_header(debug_info_t *id, struct debug_view *view,
99                                 int area, debug_entry_t *entry, char *out_buf)
100 {
101         struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)DEBUG_DATA(entry);
102         struct timespec t;
103         char *p = out_buf;
104
105         if (strncmp(dump->tag, "dump", ZFCP_DBF_TAG_SIZE) != 0) {
106                 stck_to_timespec(entry->id.stck, &t);
107                 zfcp_dbf_out(&p, "timestamp", "%011lu:%06lu",
108                              t.tv_sec, t.tv_nsec);
109                 zfcp_dbf_out(&p, "cpu", "%02i", entry->id.fields.cpuid);
110         } else  {
111                 zfcp_dbf_outd(&p, "", dump->data, dump->size, dump->offset,
112                               dump->total_size);
113                 if ((dump->offset + dump->size) == dump->total_size)
114                         p += sprintf(p, "\n");
115         }
116         return p - out_buf;
117 }
118
119 /**
120  * zfcp_dbf_hba_fsf_res - trace event for fsf responses
121  * @tag: tag indicating which kind of unsolicited status has been received
122  * @req: request for which a response was received
123  */
124 void zfcp_dbf_hba_fsf_res(char *tag, struct zfcp_fsf_req *req)
125 {
126         struct zfcp_dbf *dbf = req->adapter->dbf;
127         struct fsf_qtcb_prefix *q_pref = &req->qtcb->prefix;
128         struct fsf_qtcb_header *q_head = &req->qtcb->header;
129         struct zfcp_dbf_hba *rec = &dbf->hba_buf;
130         unsigned long flags;
131
132         spin_lock_irqsave(&dbf->hba_lock, flags);
133         memset(rec, 0, sizeof(*rec));
134
135         memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
136         rec->id = ZFCP_DBF_HBA_RES;
137         rec->fsf_req_id = req->req_id;
138         rec->fsf_req_status = req->status;
139         rec->fsf_cmd = req->fsf_command;
140         rec->fsf_seq_no = req->seq_no;
141         rec->u.res.req_issued = req->issued;
142         rec->u.res.prot_status = q_pref->prot_status;
143         rec->u.res.fsf_status = q_head->fsf_status;
144
145         memcpy(rec->u.res.prot_status_qual, &q_pref->prot_status_qual,
146                FSF_PROT_STATUS_QUAL_SIZE);
147         memcpy(rec->u.res.fsf_status_qual, &q_head->fsf_status_qual,
148                FSF_STATUS_QUALIFIER_SIZE);
149
150         if (req->fsf_command != FSF_QTCB_FCP_CMND) {
151                 rec->pl_len = q_head->log_length;
152                 zfcp_dbf_pl_write(dbf, (char *)q_pref + q_head->log_start,
153                                   rec->pl_len, "fsf_res", req->req_id);
154         }
155
156         debug_event(dbf->hba, 1, rec, sizeof(*rec));
157         spin_unlock_irqrestore(&dbf->hba_lock, flags);
158 }
159
160 /**
161  * zfcp_dbf_hba_fsf_uss - trace event for an unsolicited status buffer
162  * @tag: tag indicating which kind of unsolicited status has been received
163  * @req: request providing the unsolicited status
164  */
165 void zfcp_dbf_hba_fsf_uss(char *tag, struct zfcp_fsf_req *req)
166 {
167         struct zfcp_dbf *dbf = req->adapter->dbf;
168         struct fsf_status_read_buffer *srb = req->data;
169         struct zfcp_dbf_hba *rec = &dbf->hba_buf;
170         unsigned long flags;
171
172         spin_lock_irqsave(&dbf->hba_lock, flags);
173         memset(rec, 0, sizeof(*rec));
174
175         memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
176         rec->id = ZFCP_DBF_HBA_USS;
177         rec->fsf_req_id = req->req_id;
178         rec->fsf_req_status = req->status;
179         rec->fsf_cmd = req->fsf_command;
180
181         if (!srb)
182                 goto log;
183
184         rec->u.uss.status_type = srb->status_type;
185         rec->u.uss.status_subtype = srb->status_subtype;
186         rec->u.uss.d_id = ntoh24(srb->d_id);
187         rec->u.uss.lun = srb->fcp_lun;
188         memcpy(&rec->u.uss.queue_designator, &srb->queue_designator,
189                sizeof(rec->u.uss.queue_designator));
190
191         /* status read buffer payload length */
192         rec->pl_len = (!srb->length) ? 0 : srb->length -
193                         offsetof(struct fsf_status_read_buffer, payload);
194
195         if (rec->pl_len)
196                 zfcp_dbf_pl_write(dbf, srb->payload.data, rec->pl_len,
197                                   "fsf_uss", req->req_id);
198 log:
199         debug_event(dbf->hba, 2, rec, sizeof(*rec));
200         spin_unlock_irqrestore(&dbf->hba_lock, flags);
201 }
202
203 /**
204  * zfcp_dbf_hba_bit_err - trace event for bit error conditions
205  * @tag: tag indicating which kind of unsolicited status has been received
206  * @req: request which caused the bit_error condition
207  */
208 void zfcp_dbf_hba_bit_err(char *tag, struct zfcp_fsf_req *req)
209 {
210         struct zfcp_dbf *dbf = req->adapter->dbf;
211         struct zfcp_dbf_hba *rec = &dbf->hba_buf;
212         struct fsf_status_read_buffer *sr_buf = req->data;
213         unsigned long flags;
214
215         spin_lock_irqsave(&dbf->hba_lock, flags);
216         memset(rec, 0, sizeof(*rec));
217
218         memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
219         rec->id = ZFCP_DBF_HBA_BIT;
220         rec->fsf_req_id = req->req_id;
221         rec->fsf_req_status = req->status;
222         rec->fsf_cmd = req->fsf_command;
223         memcpy(&rec->u.be, &sr_buf->payload.bit_error,
224                sizeof(struct fsf_bit_error_payload));
225
226         debug_event(dbf->hba, 1, rec, sizeof(*rec));
227         spin_unlock_irqrestore(&dbf->hba_lock, flags);
228 }
229
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)
234 {
235         rec->adapter_status = atomic_read(&adapter->status);
236         if (port) {
237                 rec->port_status = atomic_read(&port->status);
238                 rec->wwpn = port->wwpn;
239                 rec->d_id = port->d_id;
240         }
241         if (sdev) {
242                 rec->lun_status = atomic_read(&sdev_to_zfcp(sdev)->status);
243                 rec->lun = zfcp_scsi_dev_lun(sdev);
244         }
245 }
246
247 /**
248  * zfcp_dbf_rec_trig - trace event related to triggered recovery
249  * @tag: identifier for event
250  * @adapter: adapter on which the erp_action should run
251  * @port: remote port involved in the erp_action
252  * @sdev: scsi device involved in the erp_action
253  * @want: wanted erp_action
254  * @need: required erp_action
255  *
256  * The adapter->erp_lock has to be held.
257  */
258 void zfcp_dbf_rec_trig(char *tag, struct zfcp_adapter *adapter,
259                        struct zfcp_port *port, struct scsi_device *sdev,
260                        u8 want, u8 need)
261 {
262         struct zfcp_dbf *dbf = adapter->dbf;
263         struct zfcp_dbf_rec *rec = &dbf->rec_buf;
264         struct list_head *entry;
265         unsigned long flags;
266
267         spin_lock_irqsave(&dbf->rec_lock, flags);
268         memset(rec, 0, sizeof(*rec));
269
270         rec->id = ZFCP_DBF_REC_TRIG;
271         memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
272         zfcp_dbf_set_common(rec, adapter, port, sdev);
273
274         list_for_each(entry, &adapter->erp_ready_head)
275                 rec->u.trig.ready++;
276
277         list_for_each(entry, &adapter->erp_running_head)
278                 rec->u.trig.running++;
279
280         rec->u.trig.want = want;
281         rec->u.trig.need = need;
282
283         debug_event(dbf->rec, 1, rec, sizeof(*rec));
284         spin_unlock_irqrestore(&dbf->rec_lock, flags);
285 }
286
287
288 /**
289  * zfcp_dbf_rec_run - trace event related to running recovery
290  * @tag: identifier for event
291  * @erp: erp_action running
292  */
293 void zfcp_dbf_rec_run(char *tag, struct zfcp_erp_action *erp)
294 {
295         struct zfcp_dbf *dbf = erp->adapter->dbf;
296         struct zfcp_dbf_rec *rec = &dbf->rec_buf;
297         unsigned long flags;
298
299         spin_lock_irqsave(&dbf->rec_lock, flags);
300         memset(rec, 0, sizeof(*rec));
301
302         rec->id = ZFCP_DBF_REC_RUN;
303         memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
304         zfcp_dbf_set_common(rec, erp->adapter, erp->port, erp->sdev);
305
306         rec->u.run.fsf_req_id = erp->fsf_req_id;
307         rec->u.run.rec_status = erp->status;
308         rec->u.run.rec_step = erp->step;
309         rec->u.run.rec_action = erp->action;
310
311         if (erp->sdev)
312                 rec->u.run.rec_count =
313                         atomic_read(&sdev_to_zfcp(erp->sdev)->erp_counter);
314         else if (erp->port)
315                 rec->u.run.rec_count = atomic_read(&erp->port->erp_counter);
316         else
317                 rec->u.run.rec_count = atomic_read(&erp->adapter->erp_counter);
318
319         debug_event(dbf->rec, 1, rec, sizeof(*rec));
320         spin_unlock_irqrestore(&dbf->rec_lock, flags);
321 }
322
323 static inline
324 void zfcp_dbf_san(char *tag, struct zfcp_dbf *dbf, void *data, u8 id, u16 len,
325                   u64 req_id, u32 d_id)
326 {
327         struct zfcp_dbf_san *rec = &dbf->san_buf;
328         u16 rec_len;
329         unsigned long flags;
330
331         spin_lock_irqsave(&dbf->san_lock, flags);
332         memset(rec, 0, sizeof(*rec));
333
334         rec->id = id;
335         rec->fsf_req_id = req_id;
336         rec->d_id = d_id;
337         rec_len = min(len, (u16)ZFCP_DBF_SAN_MAX_PAYLOAD);
338         memcpy(rec->payload, data, rec_len);
339         memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
340
341         debug_event(dbf->san, 1, rec, sizeof(*rec));
342         spin_unlock_irqrestore(&dbf->san_lock, flags);
343 }
344
345 /**
346  * zfcp_dbf_san_req - trace event for issued SAN request
347  * @tag: indentifier for event
348  * @fsf_req: request containing issued CT data
349  * d_id: destination ID
350  */
351 void zfcp_dbf_san_req(char *tag, struct zfcp_fsf_req *fsf, u32 d_id)
352 {
353         struct zfcp_dbf *dbf = fsf->adapter->dbf;
354         struct zfcp_fsf_ct_els *ct_els = fsf->data;
355         u16 length;
356
357         length = (u16)(ct_els->req->length + FC_CT_HDR_LEN);
358         zfcp_dbf_san(tag, dbf, sg_virt(ct_els->req), ZFCP_DBF_SAN_REQ, length,
359                      fsf->req_id, d_id);
360 }
361
362 /**
363  * zfcp_dbf_san_res - trace event for received SAN request
364  * @tag: indentifier for event
365  * @fsf_req: request containing issued CT data
366  */
367 void zfcp_dbf_san_res(char *tag, struct zfcp_fsf_req *fsf)
368 {
369         struct zfcp_dbf *dbf = fsf->adapter->dbf;
370         struct zfcp_fsf_ct_els *ct_els = fsf->data;
371         u16 length;
372
373         length = (u16)(ct_els->resp->length + FC_CT_HDR_LEN);
374         zfcp_dbf_san(tag, dbf, sg_virt(ct_els->resp), ZFCP_DBF_SAN_RES, length,
375                      fsf->req_id, 0);
376 }
377
378 /**
379  * zfcp_dbf_san_in_els - trace event for incoming ELS
380  * @tag: indentifier for event
381  * @fsf_req: request containing issued CT data
382  */
383 void zfcp_dbf_san_in_els(char *tag, struct zfcp_fsf_req *fsf)
384 {
385         struct zfcp_dbf *dbf = fsf->adapter->dbf;
386         struct fsf_status_read_buffer *srb =
387                 (struct fsf_status_read_buffer *) fsf->data;
388         u16 length;
389
390         length = (u16)(srb->length -
391                         offsetof(struct fsf_status_read_buffer, payload));
392         zfcp_dbf_san(tag, dbf, srb->payload.data, ZFCP_DBF_SAN_ELS, length,
393                      fsf->req_id, ntoh24(srb->d_id));
394 }
395
396 void _zfcp_dbf_scsi(const char *tag, const char *tag2, int level,
397                     struct zfcp_dbf *dbf, struct scsi_cmnd *scsi_cmnd,
398                     struct zfcp_fsf_req *fsf_req, unsigned long old_req_id)
399 {
400         struct zfcp_dbf_scsi_record *rec = &dbf->scsi_buf;
401         struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)rec;
402         unsigned long flags;
403         struct fcp_resp_with_ext *fcp_rsp;
404         struct fcp_resp_rsp_info *fcp_rsp_info = NULL;
405         char *fcp_sns_info = NULL;
406         int offset = 0, buflen = 0;
407
408         spin_lock_irqsave(&dbf->scsi_lock, flags);
409         do {
410                 memset(rec, 0, sizeof(*rec));
411                 if (offset == 0) {
412                         strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
413                         strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE);
414                         if (scsi_cmnd != NULL) {
415                                 if (scsi_cmnd->device) {
416                                         rec->scsi_id = scsi_cmnd->device->id;
417                                         rec->scsi_lun = scsi_cmnd->device->lun;
418                                 }
419                                 rec->scsi_result = scsi_cmnd->result;
420                                 rec->scsi_cmnd = (unsigned long)scsi_cmnd;
421                                 memcpy(rec->scsi_opcode, scsi_cmnd->cmnd,
422                                         min((int)scsi_cmnd->cmd_len,
423                                                 ZFCP_DBF_SCSI_OPCODE));
424                                 rec->scsi_retries = scsi_cmnd->retries;
425                                 rec->scsi_allowed = scsi_cmnd->allowed;
426                         }
427                         if (fsf_req != NULL) {
428                                 fcp_rsp = (struct fcp_resp_with_ext *)
429                                         &(fsf_req->qtcb->bottom.io.fcp_rsp);
430                                 fcp_rsp_info = (struct fcp_resp_rsp_info *)
431                                         &fcp_rsp[1];
432                                 fcp_sns_info = (char *) &fcp_rsp[1];
433                                 if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL)
434                                         fcp_sns_info += fcp_rsp->ext.fr_sns_len;
435
436                                 rec->rsp_validity = fcp_rsp->resp.fr_flags;
437                                 rec->rsp_scsi_status = fcp_rsp->resp.fr_status;
438                                 rec->rsp_resid = fcp_rsp->ext.fr_resid;
439                                 if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL)
440                                         rec->rsp_code = fcp_rsp_info->rsp_code;
441                                 if (fcp_rsp->resp.fr_flags & FCP_SNS_LEN_VAL) {
442                                         buflen = min(fcp_rsp->ext.fr_sns_len,
443                                            (u32)ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO);
444                                         rec->sns_info_len = buflen;
445                                         memcpy(rec->sns_info, fcp_sns_info,
446                                                min(buflen,
447                                                    ZFCP_DBF_SCSI_FCP_SNS_INFO));
448                                         offset += min(buflen,
449                                                       ZFCP_DBF_SCSI_FCP_SNS_INFO);
450                                 }
451
452                                 rec->fsf_reqid = fsf_req->req_id;
453                                 rec->fsf_seqno = fsf_req->seq_no;
454                                 rec->fsf_issued = fsf_req->issued;
455                         }
456                         rec->old_fsf_reqid = old_req_id;
457                 } else {
458                         strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
459                         dump->total_size = buflen;
460                         dump->offset = offset;
461                         dump->size = min(buflen - offset,
462                                          (int)sizeof(struct
463                                                      zfcp_dbf_scsi_record) -
464                                          (int)sizeof(struct zfcp_dbf_dump));
465                         memcpy(dump->data, fcp_sns_info + offset, dump->size);
466                         offset += dump->size;
467                 }
468                 debug_event(dbf->scsi, level, rec, sizeof(*rec));
469         } while (offset < buflen);
470         spin_unlock_irqrestore(&dbf->scsi_lock, flags);
471 }
472
473 static int zfcp_dbf_scsi_view_format(debug_info_t *id, struct debug_view *view,
474                                      char *out_buf, const char *in_buf)
475 {
476         struct zfcp_dbf_scsi_record *r = (struct zfcp_dbf_scsi_record *)in_buf;
477         struct timespec t;
478         char *p = out_buf;
479
480         if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
481                 return 0;
482
483         zfcp_dbf_tag(&p, "tag", r->tag);
484         zfcp_dbf_tag(&p, "tag2", r->tag2);
485         zfcp_dbf_out(&p, "scsi_id", "0x%08x", r->scsi_id);
486         zfcp_dbf_out(&p, "scsi_lun", "0x%08x", r->scsi_lun);
487         zfcp_dbf_out(&p, "scsi_result", "0x%08x", r->scsi_result);
488         zfcp_dbf_out(&p, "scsi_cmnd", "0x%0Lx", r->scsi_cmnd);
489         zfcp_dbf_outd(&p, "scsi_opcode", r->scsi_opcode, ZFCP_DBF_SCSI_OPCODE,
490                       0, ZFCP_DBF_SCSI_OPCODE);
491         zfcp_dbf_out(&p, "scsi_retries", "0x%02x", r->scsi_retries);
492         zfcp_dbf_out(&p, "scsi_allowed", "0x%02x", r->scsi_allowed);
493         if (strncmp(r->tag, "abrt", ZFCP_DBF_TAG_SIZE) == 0)
494                 zfcp_dbf_out(&p, "old_fsf_reqid", "0x%0Lx", r->old_fsf_reqid);
495         zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
496         zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
497         stck_to_timespec(r->fsf_issued, &t);
498         zfcp_dbf_out(&p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
499
500         if (strncmp(r->tag, "rslt", ZFCP_DBF_TAG_SIZE) == 0) {
501                 zfcp_dbf_out(&p, "fcp_rsp_validity", "0x%02x", r->rsp_validity);
502                 zfcp_dbf_out(&p, "fcp_rsp_scsi_status", "0x%02x",
503                              r->rsp_scsi_status);
504                 zfcp_dbf_out(&p, "fcp_rsp_resid", "0x%08x", r->rsp_resid);
505                 zfcp_dbf_out(&p, "fcp_rsp_code", "0x%08x", r->rsp_code);
506                 zfcp_dbf_out(&p, "fcp_sns_info_len", "0x%08x", r->sns_info_len);
507                 zfcp_dbf_outd(&p, "fcp_sns_info", r->sns_info,
508                               min((int)r->sns_info_len,
509                               ZFCP_DBF_SCSI_FCP_SNS_INFO), 0,
510                               r->sns_info_len);
511         }
512         p += sprintf(p, "\n");
513         return p - out_buf;
514 }
515
516 static struct debug_view zfcp_dbf_scsi_view = {
517         .name = "structured",
518         .header_proc = zfcp_dbf_view_header,
519         .format_proc = zfcp_dbf_scsi_view_format,
520 };
521
522 static debug_info_t *zfcp_dbf_reg(const char *name, int level,
523                                   struct debug_view *view, int size)
524 {
525         struct debug_info *d;
526
527         d = debug_register(name, dbfsize, level, size);
528         if (!d)
529                 return NULL;
530
531         debug_register_view(d, &debug_hex_ascii_view);
532         debug_register_view(d, view);
533         debug_set_level(d, level);
534
535         return d;
536 }
537
538 /**
539  * zfcp_adapter_debug_register - registers debug feature for an adapter
540  * @adapter: pointer to adapter for which debug features should be registered
541  * return: -ENOMEM on error, 0 otherwise
542  */
543 int zfcp_dbf_adapter_register(struct zfcp_adapter *adapter)
544 {
545         char dbf_name[DEBUG_MAX_NAME_LEN];
546         struct zfcp_dbf *dbf;
547
548         dbf = kzalloc(sizeof(struct zfcp_dbf), GFP_KERNEL);
549         if (!dbf)
550                 return -ENOMEM;
551
552         dbf->adapter = adapter;
553
554         spin_lock_init(&dbf->pay_lock);
555         spin_lock_init(&dbf->hba_lock);
556         spin_lock_init(&dbf->san_lock);
557         spin_lock_init(&dbf->scsi_lock);
558         spin_lock_init(&dbf->rec_lock);
559
560         /* debug feature area which records recovery activity */
561         sprintf(dbf_name, "zfcp_%s_rec", dev_name(&adapter->ccw_device->dev));
562         dbf->rec = zfcp_dbf_reg(dbf_name, 3, NULL, sizeof(struct zfcp_dbf_rec));
563         if (!dbf->rec)
564                 goto err_out;
565
566         /* debug feature area which records HBA (FSF and QDIO) conditions */
567         sprintf(dbf_name, "zfcp_%s_hba", dev_name(&adapter->ccw_device->dev));
568         dbf->hba = zfcp_dbf_reg(dbf_name, 3, NULL, sizeof(struct zfcp_dbf_hba));
569         if (!dbf->hba)
570                 goto err_out;
571
572         /* debug feature area which records payload info */
573         sprintf(dbf_name, "zfcp_%s_pay", dev_name(&adapter->ccw_device->dev));
574         dbf->pay = zfcp_dbf_reg(dbf_name, 3, NULL,
575                                 sizeof(struct zfcp_dbf_pay));
576         if (!dbf->pay)
577                 goto err_out;
578
579         /* debug feature area which records SAN command failures and recovery */
580         sprintf(dbf_name, "zfcp_%s_san", dev_name(&adapter->ccw_device->dev));
581         dbf->san = zfcp_dbf_reg(dbf_name, 3, NULL, sizeof(struct zfcp_dbf_san));
582         if (!dbf->san)
583                 goto err_out;
584
585         /* debug feature area which records SCSI command failures and recovery */
586         sprintf(dbf_name, "zfcp_%s_scsi", dev_name(&adapter->ccw_device->dev));
587         dbf->scsi = zfcp_dbf_reg(dbf_name, 3, &zfcp_dbf_scsi_view,
588                                  sizeof(struct zfcp_dbf_scsi_record));
589         if (!dbf->scsi)
590                 goto err_out;
591
592         adapter->dbf = dbf;
593         return 0;
594
595 err_out:
596         zfcp_dbf_adapter_unregister(dbf);
597         return -ENOMEM;
598 }
599
600 /**
601  * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
602  * @dbf: pointer to dbf for which debug features should be unregistered
603  */
604 void zfcp_dbf_adapter_unregister(struct zfcp_dbf *dbf)
605 {
606         if (!dbf)
607                 return;
608         debug_unregister(dbf->scsi);
609         debug_unregister(dbf->san);
610         debug_unregister(dbf->hba);
611         debug_unregister(dbf->pay);
612         debug_unregister(dbf->rec);
613         dbf->adapter->dbf = NULL;
614         kfree(dbf);
615 }
616