blob: b57a47b64b80af6b520e6036e6d7972f5da43d7f [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 *
Christof Schmittd46f3842009-08-18 15:43:07 +02006 * Copyright IBM Corporation 2002, 2009
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
Martin Peschkea9c85772008-03-31 11:15:27 +020055static void zfcp_dbf_tag(char **p, const char *label, const char *tag)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020056{
Martin Peschkea9c85772008-03-31 11:15:27 +020057 int i;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020058
Martin Peschkea9c85772008-03-31 11:15:27 +020059 *p += sprintf(*p, "%-24s", label);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020060 for (i = 0; i < ZFCP_DBF_TAG_SIZE; i++)
Martin Peschkea9c85772008-03-31 11:15:27 +020061 *p += sprintf(*p, "%c", tag[i]);
62 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020063}
64
Martin Peschke10223c62008-03-27 14:21:59 +010065static 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
Martin Peschkedf29f4a2008-03-31 11:15:26 +020076static void zfcp_dbf_outd(char **p, const char *label, char *buffer,
77 int buflen, int offset, int total_size)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020078{
Martin Peschkedf29f4a2008-03-31 11:15:26 +020079 if (!offset)
80 *p += sprintf(*p, "%-24s ", label);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020081 while (buflen--) {
82 if (offset > 0) {
83 if ((offset % 32) == 0)
Martin Peschkedf29f4a2008-03-31 11:15:26 +020084 *p += sprintf(*p, "\n%-24c ", ' ');
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020085 else if ((offset % 4) == 0)
Martin Peschkedf29f4a2008-03-31 11:15:26 +020086 *p += sprintf(*p, " ");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020087 }
Martin Peschkedf29f4a2008-03-31 11:15:26 +020088 *p += sprintf(*p, "%02x", *buffer++);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020089 if (++offset == total_size) {
Martin Peschkedf29f4a2008-03-31 11:15:26 +020090 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020091 break;
92 }
93 }
Martin Peschkedf29f4a2008-03-31 11:15:26 +020094 if (!total_size)
95 *p += sprintf(*p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020096}
97
Martin Peschke92c7a832008-03-31 11:15:30 +020098static int zfcp_dbf_view_header(debug_info_t *id, struct debug_view *view,
99 int area, debug_entry_t *entry, char *out_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200100{
101 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)DEBUG_DATA(entry);
Martin Peschke8fc5af12008-03-31 11:15:23 +0200102 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200103 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200104
105 if (strncmp(dump->tag, "dump", ZFCP_DBF_TAG_SIZE) != 0) {
Christof Schmittb592e892009-08-18 15:43:31 +0200106 stck_to_timespec(entry->id.stck, &t);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200107 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 {
Christof Schmittd94ce6c2008-11-04 16:35:12 +0100111 zfcp_dbf_outd(&p, "", dump->data, dump->size, dump->offset,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200112 dump->total_size);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200113 if ((dump->offset + dump->size) == dump->total_size)
Martin Peschkeb634fff2008-03-31 11:15:24 +0200114 p += sprintf(p, "\n");
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200115 }
Martin Peschkeb634fff2008-03-31 11:15:24 +0200116 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200117}
118
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100119/**
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 */
124void zfcp_dbf_hba_fsf_res(char *tag, struct zfcp_fsf_req *req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200125{
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100126 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;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200130 unsigned long flags;
131
Swen Schillig57717102009-08-18 15:43:21 +0200132 spin_lock_irqsave(&dbf->hba_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200133 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200134
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100135 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;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200144
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100145 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);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200149
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100150 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);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200154 }
155
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100156 debug_event(dbf->hba, 1, rec, sizeof(*rec));
Swen Schillig57717102009-08-18 15:43:21 +0200157 spin_unlock_irqrestore(&dbf->hba_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200158}
159
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100160/**
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 */
165void zfcp_dbf_hba_fsf_uss(char *tag, struct zfcp_fsf_req *req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200166{
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100167 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;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200170 unsigned long flags;
171
Swen Schillig57717102009-08-18 15:43:21 +0200172 spin_lock_irqsave(&dbf->hba_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200173 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200174
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100175 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;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200180
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100181 if (!srb)
182 goto log;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200183
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100184 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));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200190
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100191 /* status read buffer payload length */
192 rec->pl_len = (!srb->length) ? 0 : srb->length -
193 offsetof(struct fsf_status_read_buffer, payload);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200194
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100195 if (rec->pl_len)
196 zfcp_dbf_pl_write(dbf, srb->payload.data, rec->pl_len,
197 "fsf_uss", req->req_id);
198log:
199 debug_event(dbf->hba, 2, rec, sizeof(*rec));
Swen Schillig57717102009-08-18 15:43:21 +0200200 spin_unlock_irqrestore(&dbf->hba_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200201}
202
Martin Peschkebfab1632008-03-31 11:15:31 +0200203/**
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100204 * 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
Martin Peschkebfab1632008-03-31 11:15:31 +0200207 */
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100208void zfcp_dbf_hba_bit_err(char *tag, struct zfcp_fsf_req *req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200209{
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100210 struct zfcp_dbf *dbf = req->adapter->dbf;
211 struct zfcp_dbf_hba *rec = &dbf->hba_buf;
Swen Schillig57069382008-10-01 12:42:21 +0200212 struct fsf_status_read_buffer *sr_buf = req->data;
Swen Schillig57069382008-10-01 12:42:21 +0200213 unsigned long flags;
214
Swen Schillig57717102009-08-18 15:43:21 +0200215 spin_lock_irqsave(&dbf->hba_lock, flags);
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100216 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));
Swen Schillig57717102009-08-18 15:43:21 +0200227 spin_unlock_irqrestore(&dbf->hba_lock, flags);
Swen Schillig57069382008-10-01 12:42:21 +0200228}
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200229
Swen Schilligae0904f2010-12-02 15:16:12 +0100230static 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)
Martin Peschked79a83d2008-03-27 14:22:00 +0100234{
Swen Schilligae0904f2010-12-02 15:16:12 +0100235 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;
Martin Peschked79a83d2008-03-27 14:22:00 +0100240 }
Swen Schilligae0904f2010-12-02 15:16:12 +0100241 if (sdev) {
242 rec->lun_status = atomic_read(&sdev_to_zfcp(sdev)->status);
243 rec->lun = zfcp_scsi_dev_lun(sdev);
244 }
Martin Peschke348447e2008-03-27 14:22:01 +0100245}
246
Christof Schmittaa0fec62008-05-19 12:17:47 +0200247/**
Swen Schilligae0904f2010-12-02 15:16:12 +0100248 * 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.
Christof Schmittaa0fec62008-05-19 12:17:47 +0200257 */
Swen Schilligae0904f2010-12-02 15:16:12 +0100258void zfcp_dbf_rec_trig(char *tag, struct zfcp_adapter *adapter,
259 struct zfcp_port *port, struct scsi_device *sdev,
260 u8 want, u8 need)
Martin Peschke9467a9b2008-03-27 14:22:03 +0100261{
Christof Schmittd46f3842009-08-18 15:43:07 +0200262 struct zfcp_dbf *dbf = adapter->dbf;
Swen Schilligae0904f2010-12-02 15:16:12 +0100263 struct zfcp_dbf_rec *rec = &dbf->rec_buf;
264 struct list_head *entry;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100265 unsigned long flags;
266
Swen Schillig57717102009-08-18 15:43:21 +0200267 spin_lock_irqsave(&dbf->rec_lock, flags);
Swen Schilligae0904f2010-12-02 15:16:12 +0100268 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));
Swen Schillig57717102009-08-18 15:43:21 +0200284 spin_unlock_irqrestore(&dbf->rec_lock, flags);
Martin Peschke9467a9b2008-03-27 14:22:03 +0100285}
286
Swen Schilligae0904f2010-12-02 15:16:12 +0100287
Martin Peschke6f4f3652008-03-27 14:22:04 +0100288/**
Swen Schilligae0904f2010-12-02 15:16:12 +0100289 * zfcp_dbf_rec_run - trace event related to running recovery
290 * @tag: identifier for event
291 * @erp: erp_action running
Martin Peschke6f4f3652008-03-27 14:22:04 +0100292 */
Swen Schilligae0904f2010-12-02 15:16:12 +0100293void zfcp_dbf_rec_run(char *tag, struct zfcp_erp_action *erp)
Martin Peschke6f4f3652008-03-27 14:22:04 +0100294{
Swen Schilligae0904f2010-12-02 15:16:12 +0100295 struct zfcp_dbf *dbf = erp->adapter->dbf;
296 struct zfcp_dbf_rec *rec = &dbf->rec_buf;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100297 unsigned long flags;
298
Swen Schillig57717102009-08-18 15:43:21 +0200299 spin_lock_irqsave(&dbf->rec_lock, flags);
Swen Schilligae0904f2010-12-02 15:16:12 +0100300 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));
Swen Schillig57717102009-08-18 15:43:21 +0200320 spin_unlock_irqrestore(&dbf->rec_lock, flags);
Martin Peschke6f4f3652008-03-27 14:22:04 +0100321}
322
Swen Schillig2c55b752010-12-02 15:16:13 +0100323static inline
324void zfcp_dbf_san(char *tag, struct zfcp_dbf *dbf, void *data, u8 id, u16 len,
325 u64 req_id, u32 d_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200326{
Swen Schillig2c55b752010-12-02 15:16:13 +0100327 struct zfcp_dbf_san *rec = &dbf->san_buf;
328 u16 rec_len;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200329 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200330
Swen Schillig57717102009-08-18 15:43:21 +0200331 spin_lock_irqsave(&dbf->san_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200332 memset(rec, 0, sizeof(*rec));
Swen Schillig2c55b752010-12-02 15:16:13 +0100333
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));
Swen Schillig57717102009-08-18 15:43:21 +0200342 spin_unlock_irqrestore(&dbf->san_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200343}
344
Martin Peschkebfab1632008-03-31 11:15:31 +0200345/**
Swen Schillig2c55b752010-12-02 15:16:13 +0100346 * 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
Martin Peschkebfab1632008-03-31 11:15:31 +0200350 */
Swen Schillig2c55b752010-12-02 15:16:13 +0100351void zfcp_dbf_san_req(char *tag, struct zfcp_fsf_req *fsf, u32 d_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200352{
Swen Schillig2c55b752010-12-02 15:16:13 +0100353 struct zfcp_dbf *dbf = fsf->adapter->dbf;
354 struct zfcp_fsf_ct_els *ct_els = fsf->data;
355 u16 length;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200356
Swen Schillig2c55b752010-12-02 15:16:13 +0100357 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);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200360}
361
Martin Peschkebfab1632008-03-31 11:15:31 +0200362/**
Swen Schillig2c55b752010-12-02 15:16:13 +0100363 * zfcp_dbf_san_res - trace event for received SAN request
364 * @tag: indentifier for event
365 * @fsf_req: request containing issued CT data
Martin Peschkebfab1632008-03-31 11:15:31 +0200366 */
Swen Schillig2c55b752010-12-02 15:16:13 +0100367void zfcp_dbf_san_res(char *tag, struct zfcp_fsf_req *fsf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200368{
Swen Schillig2c55b752010-12-02 15:16:13 +0100369 struct zfcp_dbf *dbf = fsf->adapter->dbf;
370 struct zfcp_fsf_ct_els *ct_els = fsf->data;
371 u16 length;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200372
Swen Schillig2c55b752010-12-02 15:16:13 +0100373 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);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200376}
377
Martin Peschkebfab1632008-03-31 11:15:31 +0200378/**
Swen Schillig2c55b752010-12-02 15:16:13 +0100379 * zfcp_dbf_san_in_els - trace event for incoming ELS
380 * @tag: indentifier for event
381 * @fsf_req: request containing issued CT data
Martin Peschkebfab1632008-03-31 11:15:31 +0200382 */
Swen Schillig2c55b752010-12-02 15:16:13 +0100383void zfcp_dbf_san_in_els(char *tag, struct zfcp_fsf_req *fsf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200384{
Swen Schillig2c55b752010-12-02 15:16:13 +0100385 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;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200389
Swen Schillig2c55b752010-12-02 15:16:13 +0100390 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));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200394}
395
Swen Schillig57717102009-08-18 15:43:21 +0200396void _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)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200399{
Swen Schillig57717102009-08-18 15:43:21 +0200400 struct zfcp_dbf_scsi_record *rec = &dbf->scsi_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200401 struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)rec;
402 unsigned long flags;
Christof Schmitt4318e082009-11-24 16:54:08 +0100403 struct fcp_resp_with_ext *fcp_rsp;
404 struct fcp_resp_rsp_info *fcp_rsp_info = NULL;
405 char *fcp_sns_info = NULL;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200406 int offset = 0, buflen = 0;
407
Swen Schillig57717102009-08-18 15:43:21 +0200408 spin_lock_irqsave(&dbf->scsi_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200409 do {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200410 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200411 if (offset == 0) {
412 strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
413 strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE);
Maxim Shchetynined829ad2006-02-11 01:42:58 +0100414 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;
Boaz Harrosh64a87b22008-04-30 11:19:47 +0300421 memcpy(rec->scsi_opcode, scsi_cmnd->cmnd,
Maxim Shchetynined829ad2006-02-11 01:42:58 +0100422 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;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200426 }
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200427 if (fsf_req != NULL) {
Christof Schmitt4318e082009-11-24 16:54:08 +0100428 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;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200435
Christof Schmitt4318e082009-11-24 16:54:08 +0100436 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);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200444 rec->sns_info_len = buflen;
445 memcpy(rec->sns_info, fcp_sns_info,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200446 min(buflen,
447 ZFCP_DBF_SCSI_FCP_SNS_INFO));
448 offset += min(buflen,
449 ZFCP_DBF_SCSI_FCP_SNS_INFO);
450 }
451
Christof Schmittf0216ae2009-05-15 13:18:14 +0200452 rec->fsf_reqid = fsf_req->req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200453 rec->fsf_seqno = fsf_req->seq_no;
454 rec->fsf_issued = fsf_req->issued;
455 }
Martin Peschke6bc473d2008-03-31 11:15:29 +0200456 rec->old_fsf_reqid = old_req_id;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200457 } 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
Swen Schillig57717102009-08-18 15:43:21 +0200463 zfcp_dbf_scsi_record) -
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200464 (int)sizeof(struct zfcp_dbf_dump));
465 memcpy(dump->data, fcp_sns_info + offset, dump->size);
466 offset += dump->size;
467 }
Swen Schillig57717102009-08-18 15:43:21 +0200468 debug_event(dbf->scsi, level, rec, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200469 } while (offset < buflen);
Swen Schillig57717102009-08-18 15:43:21 +0200470 spin_unlock_irqrestore(&dbf->scsi_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200471}
472
Swen Schillig57717102009-08-18 15:43:21 +0200473static int zfcp_dbf_scsi_view_format(debug_info_t *id, struct debug_view *view,
Martin Peschke92c7a832008-03-31 11:15:30 +0200474 char *out_buf, const char *in_buf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200475{
Swen Schillig57717102009-08-18 15:43:21 +0200476 struct zfcp_dbf_scsi_record *r = (struct zfcp_dbf_scsi_record *)in_buf;
Martin Peschke8fc5af12008-03-31 11:15:23 +0200477 struct timespec t;
Martin Peschkeb634fff2008-03-31 11:15:24 +0200478 char *p = out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200479
Martin Peschkeb634fff2008-03-31 11:15:24 +0200480 if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200481 return 0;
482
Martin Peschkea9c85772008-03-31 11:15:27 +0200483 zfcp_dbf_tag(&p, "tag", r->tag);
484 zfcp_dbf_tag(&p, "tag2", r->tag2);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200485 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);
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200489 zfcp_dbf_outd(&p, "scsi_opcode", r->scsi_opcode, ZFCP_DBF_SCSI_OPCODE,
490 0, ZFCP_DBF_SCSI_OPCODE);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200491 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)
Martin Peschke6bc473d2008-03-31 11:15:29 +0200494 zfcp_dbf_out(&p, "old_fsf_reqid", "0x%0Lx", r->old_fsf_reqid);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200495 zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
496 zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
Christof Schmittb592e892009-08-18 15:43:31 +0200497 stck_to_timespec(r->fsf_issued, &t);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200498 zfcp_dbf_out(&p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200499
Martin Peschkeb634fff2008-03-31 11:15:24 +0200500 if (strncmp(r->tag, "rslt", ZFCP_DBF_TAG_SIZE) == 0) {
Martin Peschke6bc473d2008-03-31 11:15:29 +0200501 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,
Martin Peschkedf29f4a2008-03-31 11:15:26 +0200509 ZFCP_DBF_SCSI_FCP_SNS_INFO), 0,
Martin Peschke6bc473d2008-03-31 11:15:29 +0200510 r->sns_info_len);
Martin Peschkeb634fff2008-03-31 11:15:24 +0200511 }
512 p += sprintf(p, "\n");
513 return p - out_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200514}
515
Swen Schillig57717102009-08-18 15:43:21 +0200516static 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,
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200520};
521
Christof Schmittd46f3842009-08-18 15:43:07 +0200522static 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
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200538/**
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 */
Swen Schillig57717102009-08-18 15:43:21 +0200543int zfcp_dbf_adapter_register(struct zfcp_adapter *adapter)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200544{
545 char dbf_name[DEBUG_MAX_NAME_LEN];
Christof Schmittd46f3842009-08-18 15:43:07 +0200546 struct zfcp_dbf *dbf;
547
Swen Schilligd23948e2010-07-16 15:37:40 +0200548 dbf = kzalloc(sizeof(struct zfcp_dbf), GFP_KERNEL);
Christof Schmittd46f3842009-08-18 15:43:07 +0200549 if (!dbf)
550 return -ENOMEM;
551
Swen Schillig57717102009-08-18 15:43:21 +0200552 dbf->adapter = adapter;
553
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100554 spin_lock_init(&dbf->pay_lock);
Swen Schillig57717102009-08-18 15:43:21 +0200555 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);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200559
560 /* debug feature area which records recovery activity */
Christof Schmittb225cf92008-12-19 16:57:00 +0100561 sprintf(dbf_name, "zfcp_%s_rec", dev_name(&adapter->ccw_device->dev));
Swen Schilligae0904f2010-12-02 15:16:12 +0100562 dbf->rec = zfcp_dbf_reg(dbf_name, 3, NULL, sizeof(struct zfcp_dbf_rec));
Swen Schillig57717102009-08-18 15:43:21 +0200563 if (!dbf->rec)
564 goto err_out;
Martin Peschked79a83d2008-03-27 14:22:00 +0100565
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200566 /* debug feature area which records HBA (FSF and QDIO) conditions */
Christof Schmittb225cf92008-12-19 16:57:00 +0100567 sprintf(dbf_name, "zfcp_%s_hba", dev_name(&adapter->ccw_device->dev));
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100568 dbf->hba = zfcp_dbf_reg(dbf_name, 3, NULL, sizeof(struct zfcp_dbf_hba));
Swen Schillig57717102009-08-18 15:43:21 +0200569 if (!dbf->hba)
570 goto err_out;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200571
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100572 /* 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
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200579 /* debug feature area which records SAN command failures and recovery */
Christof Schmittb225cf92008-12-19 16:57:00 +0100580 sprintf(dbf_name, "zfcp_%s_san", dev_name(&adapter->ccw_device->dev));
Swen Schillig2c55b752010-12-02 15:16:13 +0100581 dbf->san = zfcp_dbf_reg(dbf_name, 3, NULL, sizeof(struct zfcp_dbf_san));
Swen Schillig57717102009-08-18 15:43:21 +0200582 if (!dbf->san)
583 goto err_out;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200584
585 /* debug feature area which records SCSI command failures and recovery */
Christof Schmittb225cf92008-12-19 16:57:00 +0100586 sprintf(dbf_name, "zfcp_%s_scsi", dev_name(&adapter->ccw_device->dev));
Swen Schillig57717102009-08-18 15:43:21 +0200587 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;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200591
Christof Schmittd46f3842009-08-18 15:43:07 +0200592 adapter->dbf = dbf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200593 return 0;
594
Swen Schillig57717102009-08-18 15:43:21 +0200595err_out:
596 zfcp_dbf_adapter_unregister(dbf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200597 return -ENOMEM;
598}
599
600/**
601 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
Swen Schillig57717102009-08-18 15:43:21 +0200602 * @dbf: pointer to dbf for which debug features should be unregistered
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200603 */
Swen Schillig57717102009-08-18 15:43:21 +0200604void zfcp_dbf_adapter_unregister(struct zfcp_dbf *dbf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200605{
Swen Schilligf3450c72009-11-24 16:53:59 +0100606 if (!dbf)
607 return;
Swen Schillig57717102009-08-18 15:43:21 +0200608 debug_unregister(dbf->scsi);
609 debug_unregister(dbf->san);
610 debug_unregister(dbf->hba);
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100611 debug_unregister(dbf->pay);
Swen Schillig57717102009-08-18 15:43:21 +0200612 debug_unregister(dbf->rec);
613 dbf->adapter->dbf = NULL;
614 kfree(dbf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200615}
Swen Schillig57717102009-08-18 15:43:21 +0200616