blob: 96d1462e0bf5bddc8719e603702afb491981df3c [file] [log] [blame]
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02001/*
Christof Schmitt553448f2008-06-10 18:20:58 +02002 * zfcp device driver
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02003 *
Christof Schmitt553448f2008-06-10 18:20:58 +02004 * Debug traces for zfcp.
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02005 *
Swen Schillig250a1352010-12-02 15:16:15 +01006 * Copyright IBM Corporation 2002, 2010
Maxim Shchetynin8a36e452005-09-13 21:50:38 +02007 */
8
Christof Schmittecf39d42008-12-25 13:39:53 +01009#define KMSG_COMPONENT "zfcp"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020012#include <linux/ctype.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090013#include <linux/slab.h>
Heiko Carstens364c8552007-10-12 16:11:35 +020014#include <asm/debug.h>
Christof Schmittd46f3842009-08-18 15:43:07 +020015#include "zfcp_dbf.h"
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020016#include "zfcp_ext.h"
Christof Schmittbd0072e2009-11-24 16:54:11 +010017#include "zfcp_fc.h"
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020018
19static u32 dbfsize = 4;
20
21module_param(dbfsize, uint, 0400);
22MODULE_PARM_DESC(dbfsize,
23 "number of pages for each debug feature area (default 4)");
24
Swen Schilliga54ca0f2010-12-02 15:16:14 +010025static inline unsigned int zfcp_dbf_plen(unsigned int offset)
Martin Peschkec15450e2008-03-27 14:21:55 +010026{
Swen Schilliga54ca0f2010-12-02 15:16:14 +010027 return sizeof(struct zfcp_dbf_pay) + offset - ZFCP_DBF_PAY_MAX_REC;
28}
Martin Peschkec15450e2008-03-27 14:21:55 +010029
Swen Schilliga54ca0f2010-12-02 15:16:14 +010030static inline
31void 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++;
Martin Peschkec15450e2008-03-27 14:21:55 +010050 }
Swen Schilliga54ca0f2010-12-02 15:16:14 +010051
52 spin_unlock(&dbf->pay_lock);
Martin Peschkec15450e2008-03-27 14:21:55 +010053}
54
Swen Schilliga54ca0f2010-12-02 15:16:14 +010055/**
56 * zfcp_dbf_hba_fsf_res - trace event for fsf responses
57 * @tag: tag indicating which kind of unsolicited status has been received
58 * @req: request for which a response was received
59 */
60void zfcp_dbf_hba_fsf_res(char *tag, struct zfcp_fsf_req *req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020061{
Swen Schilliga54ca0f2010-12-02 15:16:14 +010062 struct zfcp_dbf *dbf = req->adapter->dbf;
63 struct fsf_qtcb_prefix *q_pref = &req->qtcb->prefix;
64 struct fsf_qtcb_header *q_head = &req->qtcb->header;
65 struct zfcp_dbf_hba *rec = &dbf->hba_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020066 unsigned long flags;
67
Swen Schillig57717102009-08-18 15:43:21 +020068 spin_lock_irqsave(&dbf->hba_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +020069 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020070
Swen Schilliga54ca0f2010-12-02 15:16:14 +010071 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
72 rec->id = ZFCP_DBF_HBA_RES;
73 rec->fsf_req_id = req->req_id;
74 rec->fsf_req_status = req->status;
75 rec->fsf_cmd = req->fsf_command;
76 rec->fsf_seq_no = req->seq_no;
77 rec->u.res.req_issued = req->issued;
78 rec->u.res.prot_status = q_pref->prot_status;
79 rec->u.res.fsf_status = q_head->fsf_status;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020080
Swen Schilliga54ca0f2010-12-02 15:16:14 +010081 memcpy(rec->u.res.prot_status_qual, &q_pref->prot_status_qual,
82 FSF_PROT_STATUS_QUAL_SIZE);
83 memcpy(rec->u.res.fsf_status_qual, &q_head->fsf_status_qual,
84 FSF_STATUS_QUALIFIER_SIZE);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020085
Swen Schilliga54ca0f2010-12-02 15:16:14 +010086 if (req->fsf_command != FSF_QTCB_FCP_CMND) {
87 rec->pl_len = q_head->log_length;
88 zfcp_dbf_pl_write(dbf, (char *)q_pref + q_head->log_start,
89 rec->pl_len, "fsf_res", req->req_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020090 }
91
Swen Schilliga54ca0f2010-12-02 15:16:14 +010092 debug_event(dbf->hba, 1, rec, sizeof(*rec));
Swen Schillig57717102009-08-18 15:43:21 +020093 spin_unlock_irqrestore(&dbf->hba_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020094}
95
Swen Schilliga54ca0f2010-12-02 15:16:14 +010096/**
97 * zfcp_dbf_hba_fsf_uss - trace event for an unsolicited status buffer
98 * @tag: tag indicating which kind of unsolicited status has been received
99 * @req: request providing the unsolicited status
100 */
101void zfcp_dbf_hba_fsf_uss(char *tag, struct zfcp_fsf_req *req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200102{
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100103 struct zfcp_dbf *dbf = req->adapter->dbf;
104 struct fsf_status_read_buffer *srb = req->data;
105 struct zfcp_dbf_hba *rec = &dbf->hba_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200106 unsigned long flags;
107
Swen Schillig57717102009-08-18 15:43:21 +0200108 spin_lock_irqsave(&dbf->hba_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200109 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200110
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100111 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
112 rec->id = ZFCP_DBF_HBA_USS;
113 rec->fsf_req_id = req->req_id;
114 rec->fsf_req_status = req->status;
115 rec->fsf_cmd = req->fsf_command;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200116
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100117 if (!srb)
118 goto log;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200119
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100120 rec->u.uss.status_type = srb->status_type;
121 rec->u.uss.status_subtype = srb->status_subtype;
122 rec->u.uss.d_id = ntoh24(srb->d_id);
123 rec->u.uss.lun = srb->fcp_lun;
124 memcpy(&rec->u.uss.queue_designator, &srb->queue_designator,
125 sizeof(rec->u.uss.queue_designator));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200126
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100127 /* status read buffer payload length */
128 rec->pl_len = (!srb->length) ? 0 : srb->length -
129 offsetof(struct fsf_status_read_buffer, payload);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200130
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100131 if (rec->pl_len)
132 zfcp_dbf_pl_write(dbf, srb->payload.data, rec->pl_len,
133 "fsf_uss", req->req_id);
134log:
135 debug_event(dbf->hba, 2, rec, sizeof(*rec));
Swen Schillig57717102009-08-18 15:43:21 +0200136 spin_unlock_irqrestore(&dbf->hba_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200137}
138
Martin Peschkebfab1632008-03-31 11:15:31 +0200139/**
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100140 * zfcp_dbf_hba_bit_err - trace event for bit error conditions
141 * @tag: tag indicating which kind of unsolicited status has been received
142 * @req: request which caused the bit_error condition
Martin Peschkebfab1632008-03-31 11:15:31 +0200143 */
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100144void zfcp_dbf_hba_bit_err(char *tag, struct zfcp_fsf_req *req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200145{
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100146 struct zfcp_dbf *dbf = req->adapter->dbf;
147 struct zfcp_dbf_hba *rec = &dbf->hba_buf;
Swen Schillig57069382008-10-01 12:42:21 +0200148 struct fsf_status_read_buffer *sr_buf = req->data;
Swen Schillig57069382008-10-01 12:42:21 +0200149 unsigned long flags;
150
Swen Schillig57717102009-08-18 15:43:21 +0200151 spin_lock_irqsave(&dbf->hba_lock, flags);
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100152 memset(rec, 0, sizeof(*rec));
153
154 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
155 rec->id = ZFCP_DBF_HBA_BIT;
156 rec->fsf_req_id = req->req_id;
157 rec->fsf_req_status = req->status;
158 rec->fsf_cmd = req->fsf_command;
159 memcpy(&rec->u.be, &sr_buf->payload.bit_error,
160 sizeof(struct fsf_bit_error_payload));
161
162 debug_event(dbf->hba, 1, rec, sizeof(*rec));
Swen Schillig57717102009-08-18 15:43:21 +0200163 spin_unlock_irqrestore(&dbf->hba_lock, flags);
Swen Schillig57069382008-10-01 12:42:21 +0200164}
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200165
Swen Schilligae0904f2010-12-02 15:16:12 +0100166static void zfcp_dbf_set_common(struct zfcp_dbf_rec *rec,
167 struct zfcp_adapter *adapter,
168 struct zfcp_port *port,
169 struct scsi_device *sdev)
Martin Peschked79a83d2008-03-27 14:22:00 +0100170{
Swen Schilligae0904f2010-12-02 15:16:12 +0100171 rec->adapter_status = atomic_read(&adapter->status);
172 if (port) {
173 rec->port_status = atomic_read(&port->status);
174 rec->wwpn = port->wwpn;
175 rec->d_id = port->d_id;
Martin Peschked79a83d2008-03-27 14:22:00 +0100176 }
Swen Schilligae0904f2010-12-02 15:16:12 +0100177 if (sdev) {
178 rec->lun_status = atomic_read(&sdev_to_zfcp(sdev)->status);
179 rec->lun = zfcp_scsi_dev_lun(sdev);
180 }
Martin Peschke348447e2008-03-27 14:22:01 +0100181}
182
Christof Schmittaa0fec62008-05-19 12:17:47 +0200183/**
Swen Schilligae0904f2010-12-02 15:16:12 +0100184 * zfcp_dbf_rec_trig - trace event related to triggered recovery
185 * @tag: identifier for event
186 * @adapter: adapter on which the erp_action should run
187 * @port: remote port involved in the erp_action
188 * @sdev: scsi device involved in the erp_action
189 * @want: wanted erp_action
190 * @need: required erp_action
191 *
192 * The adapter->erp_lock has to be held.
Christof Schmittaa0fec62008-05-19 12:17:47 +0200193 */
Swen Schilligae0904f2010-12-02 15:16:12 +0100194void zfcp_dbf_rec_trig(char *tag, struct zfcp_adapter *adapter,
195 struct zfcp_port *port, struct scsi_device *sdev,
196 u8 want, u8 need)
Martin Peschke9467a9b2008-03-27 14:22:03 +0100197{
Christof Schmittd46f3842009-08-18 15:43:07 +0200198 struct zfcp_dbf *dbf = adapter->dbf;
Swen Schilligae0904f2010-12-02 15:16:12 +0100199 struct zfcp_dbf_rec *rec = &dbf->rec_buf;
200 struct list_head *entry;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100201 unsigned long flags;
202
Swen Schillig57717102009-08-18 15:43:21 +0200203 spin_lock_irqsave(&dbf->rec_lock, flags);
Swen Schilligae0904f2010-12-02 15:16:12 +0100204 memset(rec, 0, sizeof(*rec));
205
206 rec->id = ZFCP_DBF_REC_TRIG;
207 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
208 zfcp_dbf_set_common(rec, adapter, port, sdev);
209
210 list_for_each(entry, &adapter->erp_ready_head)
211 rec->u.trig.ready++;
212
213 list_for_each(entry, &adapter->erp_running_head)
214 rec->u.trig.running++;
215
216 rec->u.trig.want = want;
217 rec->u.trig.need = need;
218
219 debug_event(dbf->rec, 1, rec, sizeof(*rec));
Swen Schillig57717102009-08-18 15:43:21 +0200220 spin_unlock_irqrestore(&dbf->rec_lock, flags);
Martin Peschke9467a9b2008-03-27 14:22:03 +0100221}
222
Swen Schilligae0904f2010-12-02 15:16:12 +0100223
Martin Peschke6f4f3652008-03-27 14:22:04 +0100224/**
Swen Schilligae0904f2010-12-02 15:16:12 +0100225 * zfcp_dbf_rec_run - trace event related to running recovery
226 * @tag: identifier for event
227 * @erp: erp_action running
Martin Peschke6f4f3652008-03-27 14:22:04 +0100228 */
Swen Schilligae0904f2010-12-02 15:16:12 +0100229void zfcp_dbf_rec_run(char *tag, struct zfcp_erp_action *erp)
Martin Peschke6f4f3652008-03-27 14:22:04 +0100230{
Swen Schilligae0904f2010-12-02 15:16:12 +0100231 struct zfcp_dbf *dbf = erp->adapter->dbf;
232 struct zfcp_dbf_rec *rec = &dbf->rec_buf;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100233 unsigned long flags;
234
Swen Schillig57717102009-08-18 15:43:21 +0200235 spin_lock_irqsave(&dbf->rec_lock, flags);
Swen Schilligae0904f2010-12-02 15:16:12 +0100236 memset(rec, 0, sizeof(*rec));
237
238 rec->id = ZFCP_DBF_REC_RUN;
239 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
240 zfcp_dbf_set_common(rec, erp->adapter, erp->port, erp->sdev);
241
242 rec->u.run.fsf_req_id = erp->fsf_req_id;
243 rec->u.run.rec_status = erp->status;
244 rec->u.run.rec_step = erp->step;
245 rec->u.run.rec_action = erp->action;
246
247 if (erp->sdev)
248 rec->u.run.rec_count =
249 atomic_read(&sdev_to_zfcp(erp->sdev)->erp_counter);
250 else if (erp->port)
251 rec->u.run.rec_count = atomic_read(&erp->port->erp_counter);
252 else
253 rec->u.run.rec_count = atomic_read(&erp->adapter->erp_counter);
254
255 debug_event(dbf->rec, 1, rec, sizeof(*rec));
Swen Schillig57717102009-08-18 15:43:21 +0200256 spin_unlock_irqrestore(&dbf->rec_lock, flags);
Martin Peschke6f4f3652008-03-27 14:22:04 +0100257}
258
Swen Schillig2c55b752010-12-02 15:16:13 +0100259static inline
260void zfcp_dbf_san(char *tag, struct zfcp_dbf *dbf, void *data, u8 id, u16 len,
261 u64 req_id, u32 d_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200262{
Swen Schillig2c55b752010-12-02 15:16:13 +0100263 struct zfcp_dbf_san *rec = &dbf->san_buf;
264 u16 rec_len;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200265 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200266
Swen Schillig57717102009-08-18 15:43:21 +0200267 spin_lock_irqsave(&dbf->san_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200268 memset(rec, 0, sizeof(*rec));
Swen Schillig2c55b752010-12-02 15:16:13 +0100269
270 rec->id = id;
271 rec->fsf_req_id = req_id;
272 rec->d_id = d_id;
273 rec_len = min(len, (u16)ZFCP_DBF_SAN_MAX_PAYLOAD);
274 memcpy(rec->payload, data, rec_len);
275 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
276
277 debug_event(dbf->san, 1, rec, sizeof(*rec));
Swen Schillig57717102009-08-18 15:43:21 +0200278 spin_unlock_irqrestore(&dbf->san_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200279}
280
Martin Peschkebfab1632008-03-31 11:15:31 +0200281/**
Swen Schillig2c55b752010-12-02 15:16:13 +0100282 * zfcp_dbf_san_req - trace event for issued SAN request
283 * @tag: indentifier for event
284 * @fsf_req: request containing issued CT data
285 * d_id: destination ID
Martin Peschkebfab1632008-03-31 11:15:31 +0200286 */
Swen Schillig2c55b752010-12-02 15:16:13 +0100287void zfcp_dbf_san_req(char *tag, struct zfcp_fsf_req *fsf, u32 d_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200288{
Swen Schillig2c55b752010-12-02 15:16:13 +0100289 struct zfcp_dbf *dbf = fsf->adapter->dbf;
290 struct zfcp_fsf_ct_els *ct_els = fsf->data;
291 u16 length;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200292
Swen Schillig2c55b752010-12-02 15:16:13 +0100293 length = (u16)(ct_els->req->length + FC_CT_HDR_LEN);
294 zfcp_dbf_san(tag, dbf, sg_virt(ct_els->req), ZFCP_DBF_SAN_REQ, length,
295 fsf->req_id, d_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200296}
297
Martin Peschkebfab1632008-03-31 11:15:31 +0200298/**
Swen Schillig2c55b752010-12-02 15:16:13 +0100299 * zfcp_dbf_san_res - trace event for received SAN request
300 * @tag: indentifier for event
301 * @fsf_req: request containing issued CT data
Martin Peschkebfab1632008-03-31 11:15:31 +0200302 */
Swen Schillig2c55b752010-12-02 15:16:13 +0100303void zfcp_dbf_san_res(char *tag, struct zfcp_fsf_req *fsf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200304{
Swen Schillig2c55b752010-12-02 15:16:13 +0100305 struct zfcp_dbf *dbf = fsf->adapter->dbf;
306 struct zfcp_fsf_ct_els *ct_els = fsf->data;
307 u16 length;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200308
Swen Schillig2c55b752010-12-02 15:16:13 +0100309 length = (u16)(ct_els->resp->length + FC_CT_HDR_LEN);
310 zfcp_dbf_san(tag, dbf, sg_virt(ct_els->resp), ZFCP_DBF_SAN_RES, length,
311 fsf->req_id, 0);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200312}
313
Martin Peschkebfab1632008-03-31 11:15:31 +0200314/**
Swen Schillig2c55b752010-12-02 15:16:13 +0100315 * zfcp_dbf_san_in_els - trace event for incoming ELS
316 * @tag: indentifier for event
317 * @fsf_req: request containing issued CT data
Martin Peschkebfab1632008-03-31 11:15:31 +0200318 */
Swen Schillig2c55b752010-12-02 15:16:13 +0100319void zfcp_dbf_san_in_els(char *tag, struct zfcp_fsf_req *fsf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200320{
Swen Schillig2c55b752010-12-02 15:16:13 +0100321 struct zfcp_dbf *dbf = fsf->adapter->dbf;
322 struct fsf_status_read_buffer *srb =
323 (struct fsf_status_read_buffer *) fsf->data;
324 u16 length;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200325
Swen Schillig2c55b752010-12-02 15:16:13 +0100326 length = (u16)(srb->length -
327 offsetof(struct fsf_status_read_buffer, payload));
328 zfcp_dbf_san(tag, dbf, srb->payload.data, ZFCP_DBF_SAN_ELS, length,
329 fsf->req_id, ntoh24(srb->d_id));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200330}
331
Swen Schillig250a1352010-12-02 15:16:15 +0100332/**
333 * zfcp_dbf_scsi - trace event for scsi commands
334 * @tag: identifier for event
335 * @sc: pointer to struct scsi_cmnd
336 * @fsf: pointer to struct zfcp_fsf_req
337 */
338void zfcp_dbf_scsi(char *tag, struct scsi_cmnd *sc, struct zfcp_fsf_req *fsf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200339{
Swen Schillig250a1352010-12-02 15:16:15 +0100340 struct zfcp_adapter *adapter =
341 (struct zfcp_adapter *) sc->device->host->hostdata[0];
342 struct zfcp_dbf *dbf = adapter->dbf;
343 struct zfcp_dbf_scsi *rec = &dbf->scsi_buf;
Christof Schmitt4318e082009-11-24 16:54:08 +0100344 struct fcp_resp_with_ext *fcp_rsp;
Swen Schillig250a1352010-12-02 15:16:15 +0100345 struct fcp_resp_rsp_info *fcp_rsp_info;
346 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200347
Swen Schillig57717102009-08-18 15:43:21 +0200348 spin_lock_irqsave(&dbf->scsi_lock, flags);
Swen Schillig250a1352010-12-02 15:16:15 +0100349 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200350
Swen Schillig250a1352010-12-02 15:16:15 +0100351 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
352 rec->id = ZFCP_DBF_SCSI_CMND;
353 rec->scsi_result = sc->result;
354 rec->scsi_retries = sc->retries;
355 rec->scsi_allowed = sc->allowed;
356 rec->scsi_id = sc->device->id;
357 rec->scsi_lun = sc->device->lun;
358 rec->host_scribble = (unsigned long)sc->host_scribble;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200359
Swen Schillig250a1352010-12-02 15:16:15 +0100360 memcpy(rec->scsi_opcode, sc->cmnd,
361 min((int)sc->cmd_len, ZFCP_DBF_SCSI_OPCODE));
362
363 if (fsf) {
364 rec->fsf_req_id = fsf->req_id;
365 fcp_rsp = (struct fcp_resp_with_ext *)
366 &(fsf->qtcb->bottom.io.fcp_rsp);
367 memcpy(&rec->fcp_rsp, fcp_rsp, FCP_RESP_WITH_EXT);
368 if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL) {
369 fcp_rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
370 rec->fcp_rsp_info = fcp_rsp_info->rsp_code;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200371 }
Swen Schillig250a1352010-12-02 15:16:15 +0100372 if (fcp_rsp->resp.fr_flags & FCP_SNS_LEN_VAL) {
373 rec->pl_len = min((u16)SCSI_SENSE_BUFFERSIZE,
374 (u16)ZFCP_DBF_PAY_MAX_REC);
375 zfcp_dbf_pl_write(dbf, sc->sense_buffer, rec->pl_len,
376 "fcp_sns", fsf->req_id);
377 }
378 }
379
Swen Schilligea4a3a62010-12-02 15:16:16 +0100380 debug_event(dbf->scsi, 1, rec, sizeof(*rec));
Swen Schillig57717102009-08-18 15:43:21 +0200381 spin_unlock_irqrestore(&dbf->scsi_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200382}
383
Swen Schilligea4a3a62010-12-02 15:16:16 +0100384static debug_info_t *zfcp_dbf_reg(const char *name, int size, int rec_size)
Christof Schmittd46f3842009-08-18 15:43:07 +0200385{
386 struct debug_info *d;
387
Swen Schilligea4a3a62010-12-02 15:16:16 +0100388 d = debug_register(name, size, 1, rec_size);
Christof Schmittd46f3842009-08-18 15:43:07 +0200389 if (!d)
390 return NULL;
391
392 debug_register_view(d, &debug_hex_ascii_view);
Swen Schilligea4a3a62010-12-02 15:16:16 +0100393 debug_set_level(d, 3);
Christof Schmittd46f3842009-08-18 15:43:07 +0200394
395 return d;
396}
397
Swen Schilligea4a3a62010-12-02 15:16:16 +0100398static void zfcp_dbf_unregister(struct zfcp_dbf *dbf)
399{
400 if (!dbf)
401 return;
402
403 debug_unregister(dbf->scsi);
404 debug_unregister(dbf->san);
405 debug_unregister(dbf->hba);
406 debug_unregister(dbf->pay);
407 debug_unregister(dbf->rec);
408 kfree(dbf);
409}
410
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200411/**
412 * zfcp_adapter_debug_register - registers debug feature for an adapter
413 * @adapter: pointer to adapter for which debug features should be registered
414 * return: -ENOMEM on error, 0 otherwise
415 */
Swen Schillig57717102009-08-18 15:43:21 +0200416int zfcp_dbf_adapter_register(struct zfcp_adapter *adapter)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200417{
Swen Schilligea4a3a62010-12-02 15:16:16 +0100418 char name[DEBUG_MAX_NAME_LEN];
Christof Schmittd46f3842009-08-18 15:43:07 +0200419 struct zfcp_dbf *dbf;
420
Swen Schilligd23948e2010-07-16 15:37:40 +0200421 dbf = kzalloc(sizeof(struct zfcp_dbf), GFP_KERNEL);
Christof Schmittd46f3842009-08-18 15:43:07 +0200422 if (!dbf)
423 return -ENOMEM;
424
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100425 spin_lock_init(&dbf->pay_lock);
Swen Schillig57717102009-08-18 15:43:21 +0200426 spin_lock_init(&dbf->hba_lock);
427 spin_lock_init(&dbf->san_lock);
428 spin_lock_init(&dbf->scsi_lock);
429 spin_lock_init(&dbf->rec_lock);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200430
431 /* debug feature area which records recovery activity */
Swen Schilligea4a3a62010-12-02 15:16:16 +0100432 sprintf(name, "zfcp_%s_rec", dev_name(&adapter->ccw_device->dev));
433 dbf->rec = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_rec));
Swen Schillig57717102009-08-18 15:43:21 +0200434 if (!dbf->rec)
435 goto err_out;
Martin Peschked79a83d2008-03-27 14:22:00 +0100436
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200437 /* debug feature area which records HBA (FSF and QDIO) conditions */
Swen Schilligea4a3a62010-12-02 15:16:16 +0100438 sprintf(name, "zfcp_%s_hba", dev_name(&adapter->ccw_device->dev));
439 dbf->hba = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_hba));
Swen Schillig57717102009-08-18 15:43:21 +0200440 if (!dbf->hba)
441 goto err_out;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200442
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100443 /* debug feature area which records payload info */
Swen Schilligea4a3a62010-12-02 15:16:16 +0100444 sprintf(name, "zfcp_%s_pay", dev_name(&adapter->ccw_device->dev));
445 dbf->pay = zfcp_dbf_reg(name, dbfsize * 2, sizeof(struct zfcp_dbf_pay));
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100446 if (!dbf->pay)
447 goto err_out;
448
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200449 /* debug feature area which records SAN command failures and recovery */
Swen Schilligea4a3a62010-12-02 15:16:16 +0100450 sprintf(name, "zfcp_%s_san", dev_name(&adapter->ccw_device->dev));
451 dbf->san = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_san));
Swen Schillig57717102009-08-18 15:43:21 +0200452 if (!dbf->san)
453 goto err_out;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200454
455 /* debug feature area which records SCSI command failures and recovery */
Swen Schilligea4a3a62010-12-02 15:16:16 +0100456 sprintf(name, "zfcp_%s_scsi", dev_name(&adapter->ccw_device->dev));
457 dbf->scsi = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_scsi));
Swen Schillig57717102009-08-18 15:43:21 +0200458 if (!dbf->scsi)
459 goto err_out;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200460
Christof Schmittd46f3842009-08-18 15:43:07 +0200461 adapter->dbf = dbf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200462
Swen Schilligea4a3a62010-12-02 15:16:16 +0100463 return 0;
Swen Schillig57717102009-08-18 15:43:21 +0200464err_out:
Swen Schilligea4a3a62010-12-02 15:16:16 +0100465 zfcp_dbf_unregister(dbf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200466 return -ENOMEM;
467}
468
469/**
470 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
Swen Schilligea4a3a62010-12-02 15:16:16 +0100471 * @adapter: pointer to adapter for which debug features should be unregistered
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200472 */
Swen Schilligea4a3a62010-12-02 15:16:16 +0100473void zfcp_dbf_adapter_unregister(struct zfcp_adapter *adapter)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200474{
Swen Schilligea4a3a62010-12-02 15:16:16 +0100475 struct zfcp_dbf *dbf = adapter->dbf;
476
477 adapter->dbf = NULL;
478 zfcp_dbf_unregister(dbf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200479}
Swen Schillig57717102009-08-18 15:43:21 +0200480