blob: a9a816e4aa55f5c2ad8eadfe4302cba48609e421 [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
Heiko Carstens3a4c5d52011-07-30 09:25:15 +020012#include <linux/module.h>
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020013#include <linux/ctype.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090014#include <linux/slab.h>
Heiko Carstens364c8552007-10-12 16:11:35 +020015#include <asm/debug.h>
Christof Schmittd46f3842009-08-18 15:43:07 +020016#include "zfcp_dbf.h"
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020017#include "zfcp_ext.h"
Christof Schmittbd0072e2009-11-24 16:54:11 +010018#include "zfcp_fc.h"
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020019
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
Swen Schilliga54ca0f2010-12-02 15:16:14 +010026static inline unsigned int zfcp_dbf_plen(unsigned int offset)
Martin Peschkec15450e2008-03-27 14:21:55 +010027{
Swen Schilliga54ca0f2010-12-02 15:16:14 +010028 return sizeof(struct zfcp_dbf_pay) + offset - ZFCP_DBF_PAY_MAX_REC;
29}
Martin Peschkec15450e2008-03-27 14:21:55 +010030
Swen Schilliga54ca0f2010-12-02 15:16:14 +010031static inline
32void zfcp_dbf_pl_write(struct zfcp_dbf *dbf, void *data, u16 length, char *area,
33 u64 req_id)
34{
35 struct zfcp_dbf_pay *pl = &dbf->pay_buf;
36 u16 offset = 0, rec_length;
37
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);
42
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));
48
49 offset += rec_length;
50 pl->counter++;
Martin Peschkec15450e2008-03-27 14:21:55 +010051 }
Swen Schilliga54ca0f2010-12-02 15:16:14 +010052
53 spin_unlock(&dbf->pay_lock);
Martin Peschkec15450e2008-03-27 14:21:55 +010054}
55
Swen Schilliga54ca0f2010-12-02 15:16:14 +010056/**
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
60 */
61void zfcp_dbf_hba_fsf_res(char *tag, struct zfcp_fsf_req *req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020062{
Swen Schilliga54ca0f2010-12-02 15:16:14 +010063 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;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020067 unsigned long flags;
68
Swen Schillig57717102009-08-18 15:43:21 +020069 spin_lock_irqsave(&dbf->hba_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +020070 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020071
Swen Schilliga54ca0f2010-12-02 15:16:14 +010072 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;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020081
Swen Schilliga54ca0f2010-12-02 15:16:14 +010082 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);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020086
Swen Schilliga54ca0f2010-12-02 15:16:14 +010087 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);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020091 }
92
Swen Schilliga54ca0f2010-12-02 15:16:14 +010093 debug_event(dbf->hba, 1, rec, sizeof(*rec));
Swen Schillig57717102009-08-18 15:43:21 +020094 spin_unlock_irqrestore(&dbf->hba_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020095}
96
Swen Schilliga54ca0f2010-12-02 15:16:14 +010097/**
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
101 */
102void zfcp_dbf_hba_fsf_uss(char *tag, struct zfcp_fsf_req *req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200103{
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100104 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;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200107 unsigned long flags;
108
Swen Schillig57717102009-08-18 15:43:21 +0200109 spin_lock_irqsave(&dbf->hba_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200110 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200111
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100112 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;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200117
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100118 if (!srb)
119 goto log;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200120
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100121 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));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200127
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100128 /* status read buffer payload length */
129 rec->pl_len = (!srb->length) ? 0 : srb->length -
130 offsetof(struct fsf_status_read_buffer, payload);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200131
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100132 if (rec->pl_len)
133 zfcp_dbf_pl_write(dbf, srb->payload.data, rec->pl_len,
134 "fsf_uss", req->req_id);
135log:
136 debug_event(dbf->hba, 2, rec, sizeof(*rec));
Swen Schillig57717102009-08-18 15:43:21 +0200137 spin_unlock_irqrestore(&dbf->hba_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200138}
139
Martin Peschkebfab1632008-03-31 11:15:31 +0200140/**
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100141 * 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
Martin Peschkebfab1632008-03-31 11:15:31 +0200144 */
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100145void zfcp_dbf_hba_bit_err(char *tag, struct zfcp_fsf_req *req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200146{
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100147 struct zfcp_dbf *dbf = req->adapter->dbf;
148 struct zfcp_dbf_hba *rec = &dbf->hba_buf;
Swen Schillig57069382008-10-01 12:42:21 +0200149 struct fsf_status_read_buffer *sr_buf = req->data;
Swen Schillig57069382008-10-01 12:42:21 +0200150 unsigned long flags;
151
Swen Schillig57717102009-08-18 15:43:21 +0200152 spin_lock_irqsave(&dbf->hba_lock, flags);
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100153 memset(rec, 0, sizeof(*rec));
154
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));
162
163 debug_event(dbf->hba, 1, rec, sizeof(*rec));
Swen Schillig57717102009-08-18 15:43:21 +0200164 spin_unlock_irqrestore(&dbf->hba_lock, flags);
Swen Schillig57069382008-10-01 12:42:21 +0200165}
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200166
Swen Schillig86a96682011-08-15 14:40:32 +0200167/**
168 * zfcp_dbf_hba_def_err - trace event for deferred error messages
169 * @adapter: pointer to struct zfcp_adapter
170 * @req_id: request id which caused the deferred error message
171 * @scount: number of sbals incl. the signaling sbal
172 * @pl: array of all involved sbals
173 */
174void zfcp_dbf_hba_def_err(struct zfcp_adapter *adapter, u64 req_id, u16 scount,
175 void **pl)
176{
177 struct zfcp_dbf *dbf = adapter->dbf;
178 struct zfcp_dbf_pay *payload = &dbf->pay_buf;
179 unsigned long flags;
180 u16 length;
181
182 if (!pl)
183 return;
184
185 spin_lock_irqsave(&dbf->pay_lock, flags);
186 memset(payload, 0, sizeof(*payload));
187
188 memcpy(payload->area, "def_err", 7);
189 payload->fsf_req_id = req_id;
190 payload->counter = 0;
191 length = min((u16)sizeof(struct qdio_buffer),
192 (u16)ZFCP_DBF_PAY_MAX_REC);
193
194 while ((char *)pl[payload->counter] && payload->counter < scount) {
195 memcpy(payload->data, (char *)pl[payload->counter], length);
196 debug_event(dbf->pay, 1, payload, zfcp_dbf_plen(length));
197 payload->counter++;
198 }
199
200 spin_unlock_irqrestore(&dbf->pay_lock, flags);
201}
202
Swen Schilligae0904f2010-12-02 15:16:12 +0100203static void zfcp_dbf_set_common(struct zfcp_dbf_rec *rec,
204 struct zfcp_adapter *adapter,
205 struct zfcp_port *port,
206 struct scsi_device *sdev)
Martin Peschked79a83d2008-03-27 14:22:00 +0100207{
Swen Schilligae0904f2010-12-02 15:16:12 +0100208 rec->adapter_status = atomic_read(&adapter->status);
209 if (port) {
210 rec->port_status = atomic_read(&port->status);
211 rec->wwpn = port->wwpn;
212 rec->d_id = port->d_id;
Martin Peschked79a83d2008-03-27 14:22:00 +0100213 }
Swen Schilligae0904f2010-12-02 15:16:12 +0100214 if (sdev) {
215 rec->lun_status = atomic_read(&sdev_to_zfcp(sdev)->status);
216 rec->lun = zfcp_scsi_dev_lun(sdev);
217 }
Martin Peschke348447e2008-03-27 14:22:01 +0100218}
219
Christof Schmittaa0fec62008-05-19 12:17:47 +0200220/**
Swen Schilligae0904f2010-12-02 15:16:12 +0100221 * zfcp_dbf_rec_trig - trace event related to triggered recovery
222 * @tag: identifier for event
223 * @adapter: adapter on which the erp_action should run
224 * @port: remote port involved in the erp_action
225 * @sdev: scsi device involved in the erp_action
226 * @want: wanted erp_action
227 * @need: required erp_action
228 *
229 * The adapter->erp_lock has to be held.
Christof Schmittaa0fec62008-05-19 12:17:47 +0200230 */
Swen Schilligae0904f2010-12-02 15:16:12 +0100231void zfcp_dbf_rec_trig(char *tag, struct zfcp_adapter *adapter,
232 struct zfcp_port *port, struct scsi_device *sdev,
233 u8 want, u8 need)
Martin Peschke9467a9b2008-03-27 14:22:03 +0100234{
Christof Schmittd46f3842009-08-18 15:43:07 +0200235 struct zfcp_dbf *dbf = adapter->dbf;
Swen Schilligae0904f2010-12-02 15:16:12 +0100236 struct zfcp_dbf_rec *rec = &dbf->rec_buf;
237 struct list_head *entry;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100238 unsigned long flags;
239
Swen Schillig57717102009-08-18 15:43:21 +0200240 spin_lock_irqsave(&dbf->rec_lock, flags);
Swen Schilligae0904f2010-12-02 15:16:12 +0100241 memset(rec, 0, sizeof(*rec));
242
243 rec->id = ZFCP_DBF_REC_TRIG;
244 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
245 zfcp_dbf_set_common(rec, adapter, port, sdev);
246
247 list_for_each(entry, &adapter->erp_ready_head)
248 rec->u.trig.ready++;
249
250 list_for_each(entry, &adapter->erp_running_head)
251 rec->u.trig.running++;
252
253 rec->u.trig.want = want;
254 rec->u.trig.need = need;
255
256 debug_event(dbf->rec, 1, rec, sizeof(*rec));
Swen Schillig57717102009-08-18 15:43:21 +0200257 spin_unlock_irqrestore(&dbf->rec_lock, flags);
Martin Peschke9467a9b2008-03-27 14:22:03 +0100258}
259
Swen Schilligae0904f2010-12-02 15:16:12 +0100260
Martin Peschke6f4f3652008-03-27 14:22:04 +0100261/**
Swen Schilligae0904f2010-12-02 15:16:12 +0100262 * zfcp_dbf_rec_run - trace event related to running recovery
263 * @tag: identifier for event
264 * @erp: erp_action running
Martin Peschke6f4f3652008-03-27 14:22:04 +0100265 */
Swen Schilligae0904f2010-12-02 15:16:12 +0100266void zfcp_dbf_rec_run(char *tag, struct zfcp_erp_action *erp)
Martin Peschke6f4f3652008-03-27 14:22:04 +0100267{
Swen Schilligae0904f2010-12-02 15:16:12 +0100268 struct zfcp_dbf *dbf = erp->adapter->dbf;
269 struct zfcp_dbf_rec *rec = &dbf->rec_buf;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100270 unsigned long flags;
271
Swen Schillig57717102009-08-18 15:43:21 +0200272 spin_lock_irqsave(&dbf->rec_lock, flags);
Swen Schilligae0904f2010-12-02 15:16:12 +0100273 memset(rec, 0, sizeof(*rec));
274
275 rec->id = ZFCP_DBF_REC_RUN;
276 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
277 zfcp_dbf_set_common(rec, erp->adapter, erp->port, erp->sdev);
278
279 rec->u.run.fsf_req_id = erp->fsf_req_id;
280 rec->u.run.rec_status = erp->status;
281 rec->u.run.rec_step = erp->step;
282 rec->u.run.rec_action = erp->action;
283
284 if (erp->sdev)
285 rec->u.run.rec_count =
286 atomic_read(&sdev_to_zfcp(erp->sdev)->erp_counter);
287 else if (erp->port)
288 rec->u.run.rec_count = atomic_read(&erp->port->erp_counter);
289 else
290 rec->u.run.rec_count = atomic_read(&erp->adapter->erp_counter);
291
292 debug_event(dbf->rec, 1, rec, sizeof(*rec));
Swen Schillig57717102009-08-18 15:43:21 +0200293 spin_unlock_irqrestore(&dbf->rec_lock, flags);
Martin Peschke6f4f3652008-03-27 14:22:04 +0100294}
295
Swen Schillig2c55b752010-12-02 15:16:13 +0100296static inline
297void zfcp_dbf_san(char *tag, struct zfcp_dbf *dbf, void *data, u8 id, u16 len,
298 u64 req_id, u32 d_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200299{
Swen Schillig2c55b752010-12-02 15:16:13 +0100300 struct zfcp_dbf_san *rec = &dbf->san_buf;
301 u16 rec_len;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200302 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200303
Swen Schillig57717102009-08-18 15:43:21 +0200304 spin_lock_irqsave(&dbf->san_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200305 memset(rec, 0, sizeof(*rec));
Swen Schillig2c55b752010-12-02 15:16:13 +0100306
307 rec->id = id;
308 rec->fsf_req_id = req_id;
309 rec->d_id = d_id;
310 rec_len = min(len, (u16)ZFCP_DBF_SAN_MAX_PAYLOAD);
311 memcpy(rec->payload, data, rec_len);
312 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
313
314 debug_event(dbf->san, 1, rec, sizeof(*rec));
Swen Schillig57717102009-08-18 15:43:21 +0200315 spin_unlock_irqrestore(&dbf->san_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200316}
317
Martin Peschkebfab1632008-03-31 11:15:31 +0200318/**
Swen Schillig2c55b752010-12-02 15:16:13 +0100319 * zfcp_dbf_san_req - trace event for issued SAN request
320 * @tag: indentifier for event
321 * @fsf_req: request containing issued CT data
322 * d_id: destination ID
Martin Peschkebfab1632008-03-31 11:15:31 +0200323 */
Swen Schillig2c55b752010-12-02 15:16:13 +0100324void zfcp_dbf_san_req(char *tag, struct zfcp_fsf_req *fsf, u32 d_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200325{
Swen Schillig2c55b752010-12-02 15:16:13 +0100326 struct zfcp_dbf *dbf = fsf->adapter->dbf;
327 struct zfcp_fsf_ct_els *ct_els = fsf->data;
328 u16 length;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200329
Swen Schillig2c55b752010-12-02 15:16:13 +0100330 length = (u16)(ct_els->req->length + FC_CT_HDR_LEN);
331 zfcp_dbf_san(tag, dbf, sg_virt(ct_els->req), ZFCP_DBF_SAN_REQ, length,
332 fsf->req_id, d_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200333}
334
Martin Peschkebfab1632008-03-31 11:15:31 +0200335/**
Swen Schillig2c55b752010-12-02 15:16:13 +0100336 * zfcp_dbf_san_res - trace event for received SAN request
337 * @tag: indentifier for event
338 * @fsf_req: request containing issued CT data
Martin Peschkebfab1632008-03-31 11:15:31 +0200339 */
Swen Schillig2c55b752010-12-02 15:16:13 +0100340void zfcp_dbf_san_res(char *tag, struct zfcp_fsf_req *fsf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200341{
Swen Schillig2c55b752010-12-02 15:16:13 +0100342 struct zfcp_dbf *dbf = fsf->adapter->dbf;
343 struct zfcp_fsf_ct_els *ct_els = fsf->data;
344 u16 length;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200345
Swen Schillig2c55b752010-12-02 15:16:13 +0100346 length = (u16)(ct_els->resp->length + FC_CT_HDR_LEN);
347 zfcp_dbf_san(tag, dbf, sg_virt(ct_els->resp), ZFCP_DBF_SAN_RES, length,
348 fsf->req_id, 0);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200349}
350
Martin Peschkebfab1632008-03-31 11:15:31 +0200351/**
Swen Schillig2c55b752010-12-02 15:16:13 +0100352 * zfcp_dbf_san_in_els - trace event for incoming ELS
353 * @tag: indentifier for event
354 * @fsf_req: request containing issued CT data
Martin Peschkebfab1632008-03-31 11:15:31 +0200355 */
Swen Schillig2c55b752010-12-02 15:16:13 +0100356void zfcp_dbf_san_in_els(char *tag, struct zfcp_fsf_req *fsf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200357{
Swen Schillig2c55b752010-12-02 15:16:13 +0100358 struct zfcp_dbf *dbf = fsf->adapter->dbf;
359 struct fsf_status_read_buffer *srb =
360 (struct fsf_status_read_buffer *) fsf->data;
361 u16 length;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200362
Swen Schillig2c55b752010-12-02 15:16:13 +0100363 length = (u16)(srb->length -
364 offsetof(struct fsf_status_read_buffer, payload));
365 zfcp_dbf_san(tag, dbf, srb->payload.data, ZFCP_DBF_SAN_ELS, length,
366 fsf->req_id, ntoh24(srb->d_id));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200367}
368
Swen Schillig250a1352010-12-02 15:16:15 +0100369/**
370 * zfcp_dbf_scsi - trace event for scsi commands
371 * @tag: identifier for event
372 * @sc: pointer to struct scsi_cmnd
373 * @fsf: pointer to struct zfcp_fsf_req
374 */
375void zfcp_dbf_scsi(char *tag, struct scsi_cmnd *sc, struct zfcp_fsf_req *fsf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200376{
Swen Schillig250a1352010-12-02 15:16:15 +0100377 struct zfcp_adapter *adapter =
378 (struct zfcp_adapter *) sc->device->host->hostdata[0];
379 struct zfcp_dbf *dbf = adapter->dbf;
380 struct zfcp_dbf_scsi *rec = &dbf->scsi_buf;
Christof Schmitt4318e082009-11-24 16:54:08 +0100381 struct fcp_resp_with_ext *fcp_rsp;
Swen Schillig250a1352010-12-02 15:16:15 +0100382 struct fcp_resp_rsp_info *fcp_rsp_info;
383 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200384
Swen Schillig57717102009-08-18 15:43:21 +0200385 spin_lock_irqsave(&dbf->scsi_lock, flags);
Swen Schillig250a1352010-12-02 15:16:15 +0100386 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200387
Swen Schillig250a1352010-12-02 15:16:15 +0100388 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
389 rec->id = ZFCP_DBF_SCSI_CMND;
390 rec->scsi_result = sc->result;
391 rec->scsi_retries = sc->retries;
392 rec->scsi_allowed = sc->allowed;
393 rec->scsi_id = sc->device->id;
394 rec->scsi_lun = sc->device->lun;
395 rec->host_scribble = (unsigned long)sc->host_scribble;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200396
Swen Schillig250a1352010-12-02 15:16:15 +0100397 memcpy(rec->scsi_opcode, sc->cmnd,
398 min((int)sc->cmd_len, ZFCP_DBF_SCSI_OPCODE));
399
400 if (fsf) {
401 rec->fsf_req_id = fsf->req_id;
402 fcp_rsp = (struct fcp_resp_with_ext *)
403 &(fsf->qtcb->bottom.io.fcp_rsp);
404 memcpy(&rec->fcp_rsp, fcp_rsp, FCP_RESP_WITH_EXT);
405 if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL) {
406 fcp_rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
407 rec->fcp_rsp_info = fcp_rsp_info->rsp_code;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200408 }
Swen Schillig250a1352010-12-02 15:16:15 +0100409 if (fcp_rsp->resp.fr_flags & FCP_SNS_LEN_VAL) {
410 rec->pl_len = min((u16)SCSI_SENSE_BUFFERSIZE,
411 (u16)ZFCP_DBF_PAY_MAX_REC);
412 zfcp_dbf_pl_write(dbf, sc->sense_buffer, rec->pl_len,
413 "fcp_sns", fsf->req_id);
414 }
415 }
416
Swen Schilligea4a3a62010-12-02 15:16:16 +0100417 debug_event(dbf->scsi, 1, rec, sizeof(*rec));
Swen Schillig57717102009-08-18 15:43:21 +0200418 spin_unlock_irqrestore(&dbf->scsi_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200419}
420
Swen Schilligea4a3a62010-12-02 15:16:16 +0100421static debug_info_t *zfcp_dbf_reg(const char *name, int size, int rec_size)
Christof Schmittd46f3842009-08-18 15:43:07 +0200422{
423 struct debug_info *d;
424
Swen Schilligea4a3a62010-12-02 15:16:16 +0100425 d = debug_register(name, size, 1, rec_size);
Christof Schmittd46f3842009-08-18 15:43:07 +0200426 if (!d)
427 return NULL;
428
429 debug_register_view(d, &debug_hex_ascii_view);
Swen Schilligea4a3a62010-12-02 15:16:16 +0100430 debug_set_level(d, 3);
Christof Schmittd46f3842009-08-18 15:43:07 +0200431
432 return d;
433}
434
Swen Schilligea4a3a62010-12-02 15:16:16 +0100435static void zfcp_dbf_unregister(struct zfcp_dbf *dbf)
436{
437 if (!dbf)
438 return;
439
440 debug_unregister(dbf->scsi);
441 debug_unregister(dbf->san);
442 debug_unregister(dbf->hba);
443 debug_unregister(dbf->pay);
444 debug_unregister(dbf->rec);
445 kfree(dbf);
446}
447
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200448/**
449 * zfcp_adapter_debug_register - registers debug feature for an adapter
450 * @adapter: pointer to adapter for which debug features should be registered
451 * return: -ENOMEM on error, 0 otherwise
452 */
Swen Schillig57717102009-08-18 15:43:21 +0200453int zfcp_dbf_adapter_register(struct zfcp_adapter *adapter)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200454{
Swen Schilligea4a3a62010-12-02 15:16:16 +0100455 char name[DEBUG_MAX_NAME_LEN];
Christof Schmittd46f3842009-08-18 15:43:07 +0200456 struct zfcp_dbf *dbf;
457
Swen Schilligd23948e2010-07-16 15:37:40 +0200458 dbf = kzalloc(sizeof(struct zfcp_dbf), GFP_KERNEL);
Christof Schmittd46f3842009-08-18 15:43:07 +0200459 if (!dbf)
460 return -ENOMEM;
461
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100462 spin_lock_init(&dbf->pay_lock);
Swen Schillig57717102009-08-18 15:43:21 +0200463 spin_lock_init(&dbf->hba_lock);
464 spin_lock_init(&dbf->san_lock);
465 spin_lock_init(&dbf->scsi_lock);
466 spin_lock_init(&dbf->rec_lock);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200467
468 /* debug feature area which records recovery activity */
Swen Schilligea4a3a62010-12-02 15:16:16 +0100469 sprintf(name, "zfcp_%s_rec", dev_name(&adapter->ccw_device->dev));
470 dbf->rec = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_rec));
Swen Schillig57717102009-08-18 15:43:21 +0200471 if (!dbf->rec)
472 goto err_out;
Martin Peschked79a83d2008-03-27 14:22:00 +0100473
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200474 /* debug feature area which records HBA (FSF and QDIO) conditions */
Swen Schilligea4a3a62010-12-02 15:16:16 +0100475 sprintf(name, "zfcp_%s_hba", dev_name(&adapter->ccw_device->dev));
476 dbf->hba = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_hba));
Swen Schillig57717102009-08-18 15:43:21 +0200477 if (!dbf->hba)
478 goto err_out;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200479
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100480 /* debug feature area which records payload info */
Swen Schilligea4a3a62010-12-02 15:16:16 +0100481 sprintf(name, "zfcp_%s_pay", dev_name(&adapter->ccw_device->dev));
482 dbf->pay = zfcp_dbf_reg(name, dbfsize * 2, sizeof(struct zfcp_dbf_pay));
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100483 if (!dbf->pay)
484 goto err_out;
485
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200486 /* debug feature area which records SAN command failures and recovery */
Swen Schilligea4a3a62010-12-02 15:16:16 +0100487 sprintf(name, "zfcp_%s_san", dev_name(&adapter->ccw_device->dev));
488 dbf->san = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_san));
Swen Schillig57717102009-08-18 15:43:21 +0200489 if (!dbf->san)
490 goto err_out;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200491
492 /* debug feature area which records SCSI command failures and recovery */
Swen Schilligea4a3a62010-12-02 15:16:16 +0100493 sprintf(name, "zfcp_%s_scsi", dev_name(&adapter->ccw_device->dev));
494 dbf->scsi = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_scsi));
Swen Schillig57717102009-08-18 15:43:21 +0200495 if (!dbf->scsi)
496 goto err_out;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200497
Christof Schmittd46f3842009-08-18 15:43:07 +0200498 adapter->dbf = dbf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200499
Swen Schilligea4a3a62010-12-02 15:16:16 +0100500 return 0;
Swen Schillig57717102009-08-18 15:43:21 +0200501err_out:
Swen Schilligea4a3a62010-12-02 15:16:16 +0100502 zfcp_dbf_unregister(dbf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200503 return -ENOMEM;
504}
505
506/**
507 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
Swen Schilligea4a3a62010-12-02 15:16:16 +0100508 * @adapter: pointer to adapter for which debug features should be unregistered
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200509 */
Swen Schilligea4a3a62010-12-02 15:16:16 +0100510void zfcp_dbf_adapter_unregister(struct zfcp_adapter *adapter)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200511{
Swen Schilligea4a3a62010-12-02 15:16:16 +0100512 struct zfcp_dbf *dbf = adapter->dbf;
513
514 adapter->dbf = NULL;
515 zfcp_dbf_unregister(dbf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200516}
Swen Schillig57717102009-08-18 15:43:21 +0200517