blob: 4534a7ce77b823fae8e6bf1ebec0b09a907ef551 [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 *
Jens Remus6c6571912018-05-03 13:52:47 +02006 * Copyright IBM Corp. 2002, 2018
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
Steffen Maierbf3ea3a2013-04-26 16:13:53 +020026static u32 dbflevel = 3;
27
28module_param(dbflevel, uint, 0400);
29MODULE_PARM_DESC(dbflevel,
30 "log level for each debug feature area "
31 "(default 3, range 0..6)");
32
Swen Schilliga54ca0f2010-12-02 15:16:14 +010033static inline unsigned int zfcp_dbf_plen(unsigned int offset)
Martin Peschkec15450e2008-03-27 14:21:55 +010034{
Swen Schilliga54ca0f2010-12-02 15:16:14 +010035 return sizeof(struct zfcp_dbf_pay) + offset - ZFCP_DBF_PAY_MAX_REC;
36}
Martin Peschkec15450e2008-03-27 14:21:55 +010037
Swen Schilliga54ca0f2010-12-02 15:16:14 +010038static inline
39void zfcp_dbf_pl_write(struct zfcp_dbf *dbf, void *data, u16 length, char *area,
40 u64 req_id)
41{
42 struct zfcp_dbf_pay *pl = &dbf->pay_buf;
43 u16 offset = 0, rec_length;
44
45 spin_lock(&dbf->pay_lock);
46 memset(pl, 0, sizeof(*pl));
47 pl->fsf_req_id = req_id;
48 memcpy(pl->area, area, ZFCP_DBF_TAG_LEN);
49
50 while (offset < length) {
51 rec_length = min((u16) ZFCP_DBF_PAY_MAX_REC,
52 (u16) (length - offset));
53 memcpy(pl->data, data + offset, rec_length);
54 debug_event(dbf->pay, 1, pl, zfcp_dbf_plen(rec_length));
55
56 offset += rec_length;
57 pl->counter++;
Martin Peschkec15450e2008-03-27 14:21:55 +010058 }
Swen Schilliga54ca0f2010-12-02 15:16:14 +010059
60 spin_unlock(&dbf->pay_lock);
Martin Peschkec15450e2008-03-27 14:21:55 +010061}
62
Swen Schilliga54ca0f2010-12-02 15:16:14 +010063/**
64 * zfcp_dbf_hba_fsf_res - trace event for fsf responses
65 * @tag: tag indicating which kind of unsolicited status has been received
66 * @req: request for which a response was received
67 */
Steffen Maier35f040d2016-08-10 18:30:47 +020068void zfcp_dbf_hba_fsf_res(char *tag, int level, struct zfcp_fsf_req *req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020069{
Swen Schilliga54ca0f2010-12-02 15:16:14 +010070 struct zfcp_dbf *dbf = req->adapter->dbf;
71 struct fsf_qtcb_prefix *q_pref = &req->qtcb->prefix;
72 struct fsf_qtcb_header *q_head = &req->qtcb->header;
73 struct zfcp_dbf_hba *rec = &dbf->hba_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020074 unsigned long flags;
75
Swen Schillig57717102009-08-18 15:43:21 +020076 spin_lock_irqsave(&dbf->hba_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +020077 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020078
Swen Schilliga54ca0f2010-12-02 15:16:14 +010079 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
80 rec->id = ZFCP_DBF_HBA_RES;
81 rec->fsf_req_id = req->req_id;
82 rec->fsf_req_status = req->status;
83 rec->fsf_cmd = req->fsf_command;
84 rec->fsf_seq_no = req->seq_no;
85 rec->u.res.req_issued = req->issued;
86 rec->u.res.prot_status = q_pref->prot_status;
87 rec->u.res.fsf_status = q_head->fsf_status;
Steffen Maier7c964ff2016-08-10 18:30:50 +020088 rec->u.res.port_handle = q_head->port_handle;
89 rec->u.res.lun_handle = q_head->lun_handle;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020090
Swen Schilliga54ca0f2010-12-02 15:16:14 +010091 memcpy(rec->u.res.prot_status_qual, &q_pref->prot_status_qual,
92 FSF_PROT_STATUS_QUAL_SIZE);
93 memcpy(rec->u.res.fsf_status_qual, &q_head->fsf_status_qual,
94 FSF_STATUS_QUALIFIER_SIZE);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +020095
Swen Schilliga54ca0f2010-12-02 15:16:14 +010096 if (req->fsf_command != FSF_QTCB_FCP_CMND) {
97 rec->pl_len = q_head->log_length;
98 zfcp_dbf_pl_write(dbf, (char *)q_pref + q_head->log_start,
99 rec->pl_len, "fsf_res", req->req_id);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200100 }
101
Steffen Maier35f040d2016-08-10 18:30:47 +0200102 debug_event(dbf->hba, level, rec, sizeof(*rec));
Swen Schillig57717102009-08-18 15:43:21 +0200103 spin_unlock_irqrestore(&dbf->hba_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200104}
105
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100106/**
107 * zfcp_dbf_hba_fsf_uss - trace event for an unsolicited status buffer
108 * @tag: tag indicating which kind of unsolicited status has been received
109 * @req: request providing the unsolicited status
110 */
111void zfcp_dbf_hba_fsf_uss(char *tag, struct zfcp_fsf_req *req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200112{
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100113 struct zfcp_dbf *dbf = req->adapter->dbf;
114 struct fsf_status_read_buffer *srb = req->data;
115 struct zfcp_dbf_hba *rec = &dbf->hba_buf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200116 unsigned long flags;
117
Swen Schillig57717102009-08-18 15:43:21 +0200118 spin_lock_irqsave(&dbf->hba_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200119 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200120
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100121 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
122 rec->id = ZFCP_DBF_HBA_USS;
123 rec->fsf_req_id = req->req_id;
124 rec->fsf_req_status = req->status;
125 rec->fsf_cmd = req->fsf_command;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200126
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100127 if (!srb)
128 goto log;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200129
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100130 rec->u.uss.status_type = srb->status_type;
131 rec->u.uss.status_subtype = srb->status_subtype;
132 rec->u.uss.d_id = ntoh24(srb->d_id);
133 rec->u.uss.lun = srb->fcp_lun;
134 memcpy(&rec->u.uss.queue_designator, &srb->queue_designator,
135 sizeof(rec->u.uss.queue_designator));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200136
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100137 /* status read buffer payload length */
138 rec->pl_len = (!srb->length) ? 0 : srb->length -
139 offsetof(struct fsf_status_read_buffer, payload);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200140
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100141 if (rec->pl_len)
142 zfcp_dbf_pl_write(dbf, srb->payload.data, rec->pl_len,
143 "fsf_uss", req->req_id);
144log:
145 debug_event(dbf->hba, 2, rec, sizeof(*rec));
Swen Schillig57717102009-08-18 15:43:21 +0200146 spin_unlock_irqrestore(&dbf->hba_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200147}
148
Martin Peschkebfab1632008-03-31 11:15:31 +0200149/**
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100150 * zfcp_dbf_hba_bit_err - trace event for bit error conditions
151 * @tag: tag indicating which kind of unsolicited status has been received
152 * @req: request which caused the bit_error condition
Martin Peschkebfab1632008-03-31 11:15:31 +0200153 */
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100154void zfcp_dbf_hba_bit_err(char *tag, struct zfcp_fsf_req *req)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200155{
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100156 struct zfcp_dbf *dbf = req->adapter->dbf;
157 struct zfcp_dbf_hba *rec = &dbf->hba_buf;
Swen Schillig57069382008-10-01 12:42:21 +0200158 struct fsf_status_read_buffer *sr_buf = req->data;
Swen Schillig57069382008-10-01 12:42:21 +0200159 unsigned long flags;
160
Swen Schillig57717102009-08-18 15:43:21 +0200161 spin_lock_irqsave(&dbf->hba_lock, flags);
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100162 memset(rec, 0, sizeof(*rec));
163
164 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
165 rec->id = ZFCP_DBF_HBA_BIT;
166 rec->fsf_req_id = req->req_id;
167 rec->fsf_req_status = req->status;
168 rec->fsf_cmd = req->fsf_command;
169 memcpy(&rec->u.be, &sr_buf->payload.bit_error,
170 sizeof(struct fsf_bit_error_payload));
171
172 debug_event(dbf->hba, 1, rec, sizeof(*rec));
Swen Schillig57717102009-08-18 15:43:21 +0200173 spin_unlock_irqrestore(&dbf->hba_lock, flags);
Swen Schillig57069382008-10-01 12:42:21 +0200174}
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200175
Swen Schillig86a96682011-08-15 14:40:32 +0200176/**
177 * zfcp_dbf_hba_def_err - trace event for deferred error messages
178 * @adapter: pointer to struct zfcp_adapter
179 * @req_id: request id which caused the deferred error message
180 * @scount: number of sbals incl. the signaling sbal
181 * @pl: array of all involved sbals
182 */
183void zfcp_dbf_hba_def_err(struct zfcp_adapter *adapter, u64 req_id, u16 scount,
184 void **pl)
185{
186 struct zfcp_dbf *dbf = adapter->dbf;
187 struct zfcp_dbf_pay *payload = &dbf->pay_buf;
188 unsigned long flags;
189 u16 length;
190
191 if (!pl)
192 return;
193
194 spin_lock_irqsave(&dbf->pay_lock, flags);
195 memset(payload, 0, sizeof(*payload));
196
197 memcpy(payload->area, "def_err", 7);
198 payload->fsf_req_id = req_id;
199 payload->counter = 0;
200 length = min((u16)sizeof(struct qdio_buffer),
201 (u16)ZFCP_DBF_PAY_MAX_REC);
202
Steffen Maier01e60522012-09-04 15:23:31 +0200203 while (payload->counter < scount && (char *)pl[payload->counter]) {
Swen Schillig86a96682011-08-15 14:40:32 +0200204 memcpy(payload->data, (char *)pl[payload->counter], length);
205 debug_event(dbf->pay, 1, payload, zfcp_dbf_plen(length));
206 payload->counter++;
207 }
208
209 spin_unlock_irqrestore(&dbf->pay_lock, flags);
210}
211
Steffen Maiercb452142012-09-04 15:23:32 +0200212/**
213 * zfcp_dbf_hba_basic - trace event for basic adapter events
214 * @adapter: pointer to struct zfcp_adapter
215 */
216void zfcp_dbf_hba_basic(char *tag, struct zfcp_adapter *adapter)
217{
218 struct zfcp_dbf *dbf = adapter->dbf;
219 struct zfcp_dbf_hba *rec = &dbf->hba_buf;
220 unsigned long flags;
221
222 spin_lock_irqsave(&dbf->hba_lock, flags);
223 memset(rec, 0, sizeof(*rec));
224
225 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
226 rec->id = ZFCP_DBF_HBA_BASIC;
227
228 debug_event(dbf->hba, 1, rec, sizeof(*rec));
229 spin_unlock_irqrestore(&dbf->hba_lock, flags);
230}
231
Swen Schilligae0904f2010-12-02 15:16:12 +0100232static void zfcp_dbf_set_common(struct zfcp_dbf_rec *rec,
233 struct zfcp_adapter *adapter,
234 struct zfcp_port *port,
235 struct scsi_device *sdev)
Martin Peschked79a83d2008-03-27 14:22:00 +0100236{
Swen Schilligae0904f2010-12-02 15:16:12 +0100237 rec->adapter_status = atomic_read(&adapter->status);
238 if (port) {
239 rec->port_status = atomic_read(&port->status);
240 rec->wwpn = port->wwpn;
241 rec->d_id = port->d_id;
Martin Peschked79a83d2008-03-27 14:22:00 +0100242 }
Swen Schilligae0904f2010-12-02 15:16:12 +0100243 if (sdev) {
244 rec->lun_status = atomic_read(&sdev_to_zfcp(sdev)->status);
245 rec->lun = zfcp_scsi_dev_lun(sdev);
Steffen Maier0102a302016-08-10 18:30:48 +0200246 } else
247 rec->lun = ZFCP_DBF_INVALID_LUN;
Martin Peschke348447e2008-03-27 14:22:01 +0100248}
249
Christof Schmittaa0fec62008-05-19 12:17:47 +0200250/**
Swen Schilligae0904f2010-12-02 15:16:12 +0100251 * zfcp_dbf_rec_trig - trace event related to triggered recovery
252 * @tag: identifier for event
253 * @adapter: adapter on which the erp_action should run
254 * @port: remote port involved in the erp_action
255 * @sdev: scsi device involved in the erp_action
256 * @want: wanted erp_action
257 * @need: required erp_action
258 *
259 * The adapter->erp_lock has to be held.
Christof Schmittaa0fec62008-05-19 12:17:47 +0200260 */
Swen Schilligae0904f2010-12-02 15:16:12 +0100261void zfcp_dbf_rec_trig(char *tag, struct zfcp_adapter *adapter,
262 struct zfcp_port *port, struct scsi_device *sdev,
263 u8 want, u8 need)
Martin Peschke9467a9b2008-03-27 14:22:03 +0100264{
Christof Schmittd46f3842009-08-18 15:43:07 +0200265 struct zfcp_dbf *dbf = adapter->dbf;
Swen Schilligae0904f2010-12-02 15:16:12 +0100266 struct zfcp_dbf_rec *rec = &dbf->rec_buf;
267 struct list_head *entry;
Martin Peschke9467a9b2008-03-27 14:22:03 +0100268 unsigned long flags;
269
Swen Schillig57717102009-08-18 15:43:21 +0200270 spin_lock_irqsave(&dbf->rec_lock, flags);
Swen Schilligae0904f2010-12-02 15:16:12 +0100271 memset(rec, 0, sizeof(*rec));
272
273 rec->id = ZFCP_DBF_REC_TRIG;
274 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
275 zfcp_dbf_set_common(rec, adapter, port, sdev);
276
277 list_for_each(entry, &adapter->erp_ready_head)
278 rec->u.trig.ready++;
279
280 list_for_each(entry, &adapter->erp_running_head)
281 rec->u.trig.running++;
282
283 rec->u.trig.want = want;
284 rec->u.trig.need = need;
285
286 debug_event(dbf->rec, 1, rec, sizeof(*rec));
Swen Schillig57717102009-08-18 15:43:21 +0200287 spin_unlock_irqrestore(&dbf->rec_lock, flags);
Martin Peschke9467a9b2008-03-27 14:22:03 +0100288}
289
Jens Remus6c6571912018-05-03 13:52:47 +0200290/**
291 * zfcp_dbf_rec_trig_lock - trace event related to triggered recovery with lock
292 * @tag: identifier for event
293 * @adapter: adapter on which the erp_action should run
294 * @port: remote port involved in the erp_action
295 * @sdev: scsi device involved in the erp_action
296 * @want: wanted erp_action
297 * @need: required erp_action
298 *
299 * The adapter->erp_lock must not be held.
300 */
301void zfcp_dbf_rec_trig_lock(char *tag, struct zfcp_adapter *adapter,
302 struct zfcp_port *port, struct scsi_device *sdev,
303 u8 want, u8 need)
304{
305 unsigned long flags;
306
307 read_lock_irqsave(&adapter->erp_lock, flags);
308 zfcp_dbf_rec_trig(tag, adapter, port, sdev, want, need);
309 read_unlock_irqrestore(&adapter->erp_lock, flags);
310}
Swen Schilligae0904f2010-12-02 15:16:12 +0100311
Martin Peschke6f4f3652008-03-27 14:22:04 +0100312/**
Steffen Maier2a940b82016-12-09 17:16:33 +0100313 * zfcp_dbf_rec_run_lvl - trace event related to running recovery
314 * @level: trace level to be used for event
Swen Schilligae0904f2010-12-02 15:16:12 +0100315 * @tag: identifier for event
316 * @erp: erp_action running
Martin Peschke6f4f3652008-03-27 14:22:04 +0100317 */
Steffen Maier2a940b82016-12-09 17:16:33 +0100318void zfcp_dbf_rec_run_lvl(int level, char *tag, struct zfcp_erp_action *erp)
Martin Peschke6f4f3652008-03-27 14:22:04 +0100319{
Swen Schilligae0904f2010-12-02 15:16:12 +0100320 struct zfcp_dbf *dbf = erp->adapter->dbf;
321 struct zfcp_dbf_rec *rec = &dbf->rec_buf;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100322 unsigned long flags;
323
Swen Schillig57717102009-08-18 15:43:21 +0200324 spin_lock_irqsave(&dbf->rec_lock, flags);
Swen Schilligae0904f2010-12-02 15:16:12 +0100325 memset(rec, 0, sizeof(*rec));
326
327 rec->id = ZFCP_DBF_REC_RUN;
328 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
329 zfcp_dbf_set_common(rec, erp->adapter, erp->port, erp->sdev);
330
331 rec->u.run.fsf_req_id = erp->fsf_req_id;
332 rec->u.run.rec_status = erp->status;
333 rec->u.run.rec_step = erp->step;
334 rec->u.run.rec_action = erp->action;
335
336 if (erp->sdev)
337 rec->u.run.rec_count =
338 atomic_read(&sdev_to_zfcp(erp->sdev)->erp_counter);
339 else if (erp->port)
340 rec->u.run.rec_count = atomic_read(&erp->port->erp_counter);
341 else
342 rec->u.run.rec_count = atomic_read(&erp->adapter->erp_counter);
343
Steffen Maier2a940b82016-12-09 17:16:33 +0100344 debug_event(dbf->rec, level, rec, sizeof(*rec));
Swen Schillig57717102009-08-18 15:43:21 +0200345 spin_unlock_irqrestore(&dbf->rec_lock, flags);
Martin Peschke6f4f3652008-03-27 14:22:04 +0100346}
347
Steffen Maierd27a7cb2016-08-10 18:30:49 +0200348/**
Steffen Maier2a940b82016-12-09 17:16:33 +0100349 * zfcp_dbf_rec_run - trace event related to running recovery
350 * @tag: identifier for event
351 * @erp: erp_action running
352 */
353void zfcp_dbf_rec_run(char *tag, struct zfcp_erp_action *erp)
354{
355 zfcp_dbf_rec_run_lvl(1, tag, erp);
356}
357
358/**
Steffen Maierd27a7cb2016-08-10 18:30:49 +0200359 * zfcp_dbf_rec_run_wka - trace wka port event with info like running recovery
360 * @tag: identifier for event
361 * @wka_port: well known address port
362 * @req_id: request ID to correlate with potential HBA trace record
363 */
364void zfcp_dbf_rec_run_wka(char *tag, struct zfcp_fc_wka_port *wka_port,
365 u64 req_id)
366{
367 struct zfcp_dbf *dbf = wka_port->adapter->dbf;
368 struct zfcp_dbf_rec *rec = &dbf->rec_buf;
369 unsigned long flags;
370
371 spin_lock_irqsave(&dbf->rec_lock, flags);
372 memset(rec, 0, sizeof(*rec));
373
374 rec->id = ZFCP_DBF_REC_RUN;
375 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
376 rec->port_status = wka_port->status;
377 rec->d_id = wka_port->d_id;
378 rec->lun = ZFCP_DBF_INVALID_LUN;
379
380 rec->u.run.fsf_req_id = req_id;
381 rec->u.run.rec_status = ~0;
382 rec->u.run.rec_step = ~0;
383 rec->u.run.rec_action = ~0;
384 rec->u.run.rec_count = ~0;
385
386 debug_event(dbf->rec, 1, rec, sizeof(*rec));
387 spin_unlock_irqrestore(&dbf->rec_lock, flags);
388}
389
Swen Schillig2c55b752010-12-02 15:16:13 +0100390static inline
Steffen Maieraceeffb2016-08-10 18:30:53 +0200391void zfcp_dbf_san(char *tag, struct zfcp_dbf *dbf,
392 char *paytag, struct scatterlist *sg, u8 id, u16 len,
393 u64 req_id, u32 d_id, u16 cap_len)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200394{
Swen Schillig2c55b752010-12-02 15:16:13 +0100395 struct zfcp_dbf_san *rec = &dbf->san_buf;
396 u16 rec_len;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200397 unsigned long flags;
Steffen Maieraceeffb2016-08-10 18:30:53 +0200398 struct zfcp_dbf_pay *payload = &dbf->pay_buf;
399 u16 pay_sum = 0;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200400
Swen Schillig57717102009-08-18 15:43:21 +0200401 spin_lock_irqsave(&dbf->san_lock, flags);
Martin Peschke6bc473d2008-03-31 11:15:29 +0200402 memset(rec, 0, sizeof(*rec));
Swen Schillig2c55b752010-12-02 15:16:13 +0100403
404 rec->id = id;
405 rec->fsf_req_id = req_id;
406 rec->d_id = d_id;
Swen Schillig2c55b752010-12-02 15:16:13 +0100407 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
Steffen Maieraceeffb2016-08-10 18:30:53 +0200408 rec->pl_len = len; /* full length even if we cap pay below */
409 if (!sg)
410 goto out;
411 rec_len = min_t(unsigned int, sg->length, ZFCP_DBF_SAN_MAX_PAYLOAD);
412 memcpy(rec->payload, sg_virt(sg), rec_len); /* part of 1st sg entry */
413 if (len <= rec_len)
414 goto out; /* skip pay record if full content in rec->payload */
Swen Schillig2c55b752010-12-02 15:16:13 +0100415
Steffen Maieraceeffb2016-08-10 18:30:53 +0200416 /* if (len > rec_len):
417 * dump data up to cap_len ignoring small duplicate in rec->payload
418 */
Dan Carpentere7cb08e2016-10-14 16:18:39 -0400419 spin_lock(&dbf->pay_lock);
Steffen Maieraceeffb2016-08-10 18:30:53 +0200420 memset(payload, 0, sizeof(*payload));
421 memcpy(payload->area, paytag, ZFCP_DBF_TAG_LEN);
422 payload->fsf_req_id = req_id;
423 payload->counter = 0;
424 for (; sg && pay_sum < cap_len; sg = sg_next(sg)) {
425 u16 pay_len, offset = 0;
426
427 while (offset < sg->length && pay_sum < cap_len) {
428 pay_len = min((u16)ZFCP_DBF_PAY_MAX_REC,
429 (u16)(sg->length - offset));
430 /* cap_len <= pay_sum < cap_len+ZFCP_DBF_PAY_MAX_REC */
431 memcpy(payload->data, sg_virt(sg) + offset, pay_len);
432 debug_event(dbf->pay, 1, payload,
433 zfcp_dbf_plen(pay_len));
434 payload->counter++;
435 offset += pay_len;
436 pay_sum += pay_len;
437 }
438 }
439 spin_unlock(&dbf->pay_lock);
440
441out:
Swen Schillig2c55b752010-12-02 15:16:13 +0100442 debug_event(dbf->san, 1, rec, sizeof(*rec));
Swen Schillig57717102009-08-18 15:43:21 +0200443 spin_unlock_irqrestore(&dbf->san_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200444}
445
Martin Peschkebfab1632008-03-31 11:15:31 +0200446/**
Swen Schillig2c55b752010-12-02 15:16:13 +0100447 * zfcp_dbf_san_req - trace event for issued SAN request
Maxime Jayat3f794102013-10-12 01:29:46 +0200448 * @tag: identifier for event
Swen Schillig2c55b752010-12-02 15:16:13 +0100449 * @fsf_req: request containing issued CT data
450 * d_id: destination ID
Martin Peschkebfab1632008-03-31 11:15:31 +0200451 */
Swen Schillig2c55b752010-12-02 15:16:13 +0100452void zfcp_dbf_san_req(char *tag, struct zfcp_fsf_req *fsf, u32 d_id)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200453{
Swen Schillig2c55b752010-12-02 15:16:13 +0100454 struct zfcp_dbf *dbf = fsf->adapter->dbf;
455 struct zfcp_fsf_ct_els *ct_els = fsf->data;
456 u16 length;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200457
Steffen Maieraceeffb2016-08-10 18:30:53 +0200458 length = (u16)zfcp_qdio_real_bytes(ct_els->req);
459 zfcp_dbf_san(tag, dbf, "san_req", ct_els->req, ZFCP_DBF_SAN_REQ,
460 length, fsf->req_id, d_id, length);
461}
462
463static u16 zfcp_dbf_san_res_cap_len_if_gpn_ft(char *tag,
464 struct zfcp_fsf_req *fsf,
465 u16 len)
466{
467 struct zfcp_fsf_ct_els *ct_els = fsf->data;
468 struct fc_ct_hdr *reqh = sg_virt(ct_els->req);
469 struct fc_ns_gid_ft *reqn = (struct fc_ns_gid_ft *)(reqh + 1);
470 struct scatterlist *resp_entry = ct_els->resp;
Steffen Maier0cbb7432017-07-28 12:30:53 +0200471 struct fc_ct_hdr *resph;
Steffen Maieraceeffb2016-08-10 18:30:53 +0200472 struct fc_gpn_ft_resp *acc;
473 int max_entries, x, last = 0;
474
475 if (!(memcmp(tag, "fsscth2", 7) == 0
476 && ct_els->d_id == FC_FID_DIR_SERV
477 && reqh->ct_rev == FC_CT_REV
478 && reqh->ct_in_id[0] == 0
479 && reqh->ct_in_id[1] == 0
480 && reqh->ct_in_id[2] == 0
481 && reqh->ct_fs_type == FC_FST_DIR
482 && reqh->ct_fs_subtype == FC_NS_SUBTYPE
483 && reqh->ct_options == 0
484 && reqh->_ct_resvd1 == 0
485 && reqh->ct_cmd == FC_NS_GPN_FT
486 /* reqh->ct_mr_size can vary so do not match but read below */
487 && reqh->_ct_resvd2 == 0
488 && reqh->ct_reason == 0
489 && reqh->ct_explan == 0
490 && reqh->ct_vendor == 0
491 && reqn->fn_resvd == 0
492 && reqn->fn_domain_id_scope == 0
493 && reqn->fn_area_id_scope == 0
494 && reqn->fn_fc4_type == FC_TYPE_FCP))
495 return len; /* not GPN_FT response so do not cap */
496
497 acc = sg_virt(resp_entry);
Steffen Maier0cbb7432017-07-28 12:30:53 +0200498
499 /* cap all but accept CT responses to at least the CT header */
500 resph = (struct fc_ct_hdr *)acc;
501 if ((ct_els->status) ||
502 (resph->ct_cmd != cpu_to_be16(FC_FS_ACC)))
503 return max(FC_CT_HDR_LEN, ZFCP_DBF_SAN_MAX_PAYLOAD);
504
Steffen Maieraceeffb2016-08-10 18:30:53 +0200505 max_entries = (reqh->ct_mr_size * 4 / sizeof(struct fc_gpn_ft_resp))
506 + 1 /* zfcp_fc_scan_ports: bytes correct, entries off-by-one
507 * to account for header as 1st pseudo "entry" */;
508
509 /* the basic CT_IU preamble is the same size as one entry in the GPN_FT
510 * response, allowing us to skip special handling for it - just skip it
511 */
512 for (x = 1; x < max_entries && !last; x++) {
513 if (x % (ZFCP_FC_GPN_FT_ENT_PAGE + 1))
514 acc++;
515 else
516 acc = sg_virt(++resp_entry);
517
518 last = acc->fp_flags & FC_NS_FID_LAST;
519 }
520 len = min(len, (u16)(x * sizeof(struct fc_gpn_ft_resp)));
521 return len; /* cap after last entry */
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200522}
523
Martin Peschkebfab1632008-03-31 11:15:31 +0200524/**
Swen Schillig2c55b752010-12-02 15:16:13 +0100525 * zfcp_dbf_san_res - trace event for received SAN request
Maxime Jayat3f794102013-10-12 01:29:46 +0200526 * @tag: identifier for event
Swen Schillig2c55b752010-12-02 15:16:13 +0100527 * @fsf_req: request containing issued CT data
Martin Peschkebfab1632008-03-31 11:15:31 +0200528 */
Swen Schillig2c55b752010-12-02 15:16:13 +0100529void zfcp_dbf_san_res(char *tag, struct zfcp_fsf_req *fsf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200530{
Swen Schillig2c55b752010-12-02 15:16:13 +0100531 struct zfcp_dbf *dbf = fsf->adapter->dbf;
532 struct zfcp_fsf_ct_els *ct_els = fsf->data;
533 u16 length;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200534
Steffen Maieraceeffb2016-08-10 18:30:53 +0200535 length = (u16)zfcp_qdio_real_bytes(ct_els->resp);
536 zfcp_dbf_san(tag, dbf, "san_res", ct_els->resp, ZFCP_DBF_SAN_RES,
537 length, fsf->req_id, ct_els->d_id,
538 zfcp_dbf_san_res_cap_len_if_gpn_ft(tag, fsf, length));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200539}
540
Martin Peschkebfab1632008-03-31 11:15:31 +0200541/**
Swen Schillig2c55b752010-12-02 15:16:13 +0100542 * zfcp_dbf_san_in_els - trace event for incoming ELS
Maxime Jayat3f794102013-10-12 01:29:46 +0200543 * @tag: identifier for event
Swen Schillig2c55b752010-12-02 15:16:13 +0100544 * @fsf_req: request containing issued CT data
Martin Peschkebfab1632008-03-31 11:15:31 +0200545 */
Swen Schillig2c55b752010-12-02 15:16:13 +0100546void zfcp_dbf_san_in_els(char *tag, struct zfcp_fsf_req *fsf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200547{
Swen Schillig2c55b752010-12-02 15:16:13 +0100548 struct zfcp_dbf *dbf = fsf->adapter->dbf;
549 struct fsf_status_read_buffer *srb =
550 (struct fsf_status_read_buffer *) fsf->data;
551 u16 length;
Steffen Maieraceeffb2016-08-10 18:30:53 +0200552 struct scatterlist sg;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200553
Swen Schillig2c55b752010-12-02 15:16:13 +0100554 length = (u16)(srb->length -
555 offsetof(struct fsf_status_read_buffer, payload));
Steffen Maieraceeffb2016-08-10 18:30:53 +0200556 sg_init_one(&sg, srb->payload.data, length);
557 zfcp_dbf_san(tag, dbf, "san_els", &sg, ZFCP_DBF_SAN_ELS, length,
558 fsf->req_id, ntoh24(srb->d_id), length);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200559}
560
Swen Schillig250a1352010-12-02 15:16:15 +0100561/**
562 * zfcp_dbf_scsi - trace event for scsi commands
563 * @tag: identifier for event
564 * @sc: pointer to struct scsi_cmnd
565 * @fsf: pointer to struct zfcp_fsf_req
566 */
Steffen Maier35f040d2016-08-10 18:30:47 +0200567void zfcp_dbf_scsi(char *tag, int level, struct scsi_cmnd *sc,
568 struct zfcp_fsf_req *fsf)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200569{
Swen Schillig250a1352010-12-02 15:16:15 +0100570 struct zfcp_adapter *adapter =
571 (struct zfcp_adapter *) sc->device->host->hostdata[0];
572 struct zfcp_dbf *dbf = adapter->dbf;
573 struct zfcp_dbf_scsi *rec = &dbf->scsi_buf;
Christof Schmitt4318e082009-11-24 16:54:08 +0100574 struct fcp_resp_with_ext *fcp_rsp;
Swen Schillig250a1352010-12-02 15:16:15 +0100575 struct fcp_resp_rsp_info *fcp_rsp_info;
576 unsigned long flags;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200577
Swen Schillig57717102009-08-18 15:43:21 +0200578 spin_lock_irqsave(&dbf->scsi_lock, flags);
Swen Schillig250a1352010-12-02 15:16:15 +0100579 memset(rec, 0, sizeof(*rec));
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200580
Swen Schillig250a1352010-12-02 15:16:15 +0100581 memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
582 rec->id = ZFCP_DBF_SCSI_CMND;
583 rec->scsi_result = sc->result;
584 rec->scsi_retries = sc->retries;
585 rec->scsi_allowed = sc->allowed;
586 rec->scsi_id = sc->device->id;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +0200587 rec->scsi_lun = (u32)sc->device->lun;
Steffen Maierc24f7222017-07-28 12:30:58 +0200588 rec->scsi_lun_64_hi = (u32)(sc->device->lun >> 32);
Swen Schillig250a1352010-12-02 15:16:15 +0100589 rec->host_scribble = (unsigned long)sc->host_scribble;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200590
Swen Schillig250a1352010-12-02 15:16:15 +0100591 memcpy(rec->scsi_opcode, sc->cmnd,
592 min((int)sc->cmd_len, ZFCP_DBF_SCSI_OPCODE));
593
594 if (fsf) {
595 rec->fsf_req_id = fsf->req_id;
Steffen Maier52837872017-07-28 12:30:56 +0200596 rec->pl_len = FCP_RESP_WITH_EXT;
Swen Schillig250a1352010-12-02 15:16:15 +0100597 fcp_rsp = (struct fcp_resp_with_ext *)
598 &(fsf->qtcb->bottom.io.fcp_rsp);
Steffen Maier52837872017-07-28 12:30:56 +0200599 /* mandatory parts of FCP_RSP IU in this SCSI record */
Swen Schillig250a1352010-12-02 15:16:15 +0100600 memcpy(&rec->fcp_rsp, fcp_rsp, FCP_RESP_WITH_EXT);
601 if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL) {
602 fcp_rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
603 rec->fcp_rsp_info = fcp_rsp_info->rsp_code;
Steffen Maier52837872017-07-28 12:30:56 +0200604 rec->pl_len += be32_to_cpu(fcp_rsp->ext.fr_rsp_len);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200605 }
Swen Schillig250a1352010-12-02 15:16:15 +0100606 if (fcp_rsp->resp.fr_flags & FCP_SNS_LEN_VAL) {
Steffen Maier52837872017-07-28 12:30:56 +0200607 rec->pl_len += be32_to_cpu(fcp_rsp->ext.fr_sns_len);
Swen Schillig250a1352010-12-02 15:16:15 +0100608 }
Steffen Maier52837872017-07-28 12:30:56 +0200609 /* complete FCP_RSP IU in associated PAYload record
610 * but only if there are optional parts
611 */
612 if (fcp_rsp->resp.fr_flags != 0)
613 zfcp_dbf_pl_write(
614 dbf, fcp_rsp,
615 /* at least one full PAY record
616 * but not beyond hardware response field
617 */
618 min_t(u16, max_t(u16, rec->pl_len,
619 ZFCP_DBF_PAY_MAX_REC),
620 FSF_FCP_RSP_SIZE),
621 "fcp_riu", fsf->req_id);
Swen Schillig250a1352010-12-02 15:16:15 +0100622 }
623
Steffen Maier35f040d2016-08-10 18:30:47 +0200624 debug_event(dbf->scsi, level, rec, sizeof(*rec));
Swen Schillig57717102009-08-18 15:43:21 +0200625 spin_unlock_irqrestore(&dbf->scsi_lock, flags);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200626}
627
Swen Schilligea4a3a62010-12-02 15:16:16 +0100628static debug_info_t *zfcp_dbf_reg(const char *name, int size, int rec_size)
Christof Schmittd46f3842009-08-18 15:43:07 +0200629{
630 struct debug_info *d;
631
Swen Schilligea4a3a62010-12-02 15:16:16 +0100632 d = debug_register(name, size, 1, rec_size);
Christof Schmittd46f3842009-08-18 15:43:07 +0200633 if (!d)
634 return NULL;
635
636 debug_register_view(d, &debug_hex_ascii_view);
Steffen Maierbf3ea3a2013-04-26 16:13:53 +0200637 debug_set_level(d, dbflevel);
Christof Schmittd46f3842009-08-18 15:43:07 +0200638
639 return d;
640}
641
Swen Schilligea4a3a62010-12-02 15:16:16 +0100642static void zfcp_dbf_unregister(struct zfcp_dbf *dbf)
643{
644 if (!dbf)
645 return;
646
647 debug_unregister(dbf->scsi);
648 debug_unregister(dbf->san);
649 debug_unregister(dbf->hba);
650 debug_unregister(dbf->pay);
651 debug_unregister(dbf->rec);
652 kfree(dbf);
653}
654
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200655/**
656 * zfcp_adapter_debug_register - registers debug feature for an adapter
657 * @adapter: pointer to adapter for which debug features should be registered
658 * return: -ENOMEM on error, 0 otherwise
659 */
Swen Schillig57717102009-08-18 15:43:21 +0200660int zfcp_dbf_adapter_register(struct zfcp_adapter *adapter)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200661{
Swen Schilligea4a3a62010-12-02 15:16:16 +0100662 char name[DEBUG_MAX_NAME_LEN];
Christof Schmittd46f3842009-08-18 15:43:07 +0200663 struct zfcp_dbf *dbf;
664
Swen Schilligd23948e2010-07-16 15:37:40 +0200665 dbf = kzalloc(sizeof(struct zfcp_dbf), GFP_KERNEL);
Christof Schmittd46f3842009-08-18 15:43:07 +0200666 if (!dbf)
667 return -ENOMEM;
668
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100669 spin_lock_init(&dbf->pay_lock);
Swen Schillig57717102009-08-18 15:43:21 +0200670 spin_lock_init(&dbf->hba_lock);
671 spin_lock_init(&dbf->san_lock);
672 spin_lock_init(&dbf->scsi_lock);
673 spin_lock_init(&dbf->rec_lock);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200674
675 /* debug feature area which records recovery activity */
Swen Schilligea4a3a62010-12-02 15:16:16 +0100676 sprintf(name, "zfcp_%s_rec", dev_name(&adapter->ccw_device->dev));
677 dbf->rec = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_rec));
Swen Schillig57717102009-08-18 15:43:21 +0200678 if (!dbf->rec)
679 goto err_out;
Martin Peschked79a83d2008-03-27 14:22:00 +0100680
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200681 /* debug feature area which records HBA (FSF and QDIO) conditions */
Swen Schilligea4a3a62010-12-02 15:16:16 +0100682 sprintf(name, "zfcp_%s_hba", dev_name(&adapter->ccw_device->dev));
683 dbf->hba = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_hba));
Swen Schillig57717102009-08-18 15:43:21 +0200684 if (!dbf->hba)
685 goto err_out;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200686
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100687 /* debug feature area which records payload info */
Swen Schilligea4a3a62010-12-02 15:16:16 +0100688 sprintf(name, "zfcp_%s_pay", dev_name(&adapter->ccw_device->dev));
689 dbf->pay = zfcp_dbf_reg(name, dbfsize * 2, sizeof(struct zfcp_dbf_pay));
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100690 if (!dbf->pay)
691 goto err_out;
692
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200693 /* debug feature area which records SAN command failures and recovery */
Swen Schilligea4a3a62010-12-02 15:16:16 +0100694 sprintf(name, "zfcp_%s_san", dev_name(&adapter->ccw_device->dev));
695 dbf->san = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_san));
Swen Schillig57717102009-08-18 15:43:21 +0200696 if (!dbf->san)
697 goto err_out;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200698
699 /* debug feature area which records SCSI command failures and recovery */
Swen Schilligea4a3a62010-12-02 15:16:16 +0100700 sprintf(name, "zfcp_%s_scsi", dev_name(&adapter->ccw_device->dev));
701 dbf->scsi = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_scsi));
Swen Schillig57717102009-08-18 15:43:21 +0200702 if (!dbf->scsi)
703 goto err_out;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200704
Christof Schmittd46f3842009-08-18 15:43:07 +0200705 adapter->dbf = dbf;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200706
Swen Schilligea4a3a62010-12-02 15:16:16 +0100707 return 0;
Swen Schillig57717102009-08-18 15:43:21 +0200708err_out:
Swen Schilligea4a3a62010-12-02 15:16:16 +0100709 zfcp_dbf_unregister(dbf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200710 return -ENOMEM;
711}
712
713/**
714 * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
Swen Schilligea4a3a62010-12-02 15:16:16 +0100715 * @adapter: pointer to adapter for which debug features should be unregistered
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200716 */
Swen Schilligea4a3a62010-12-02 15:16:16 +0100717void zfcp_dbf_adapter_unregister(struct zfcp_adapter *adapter)
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200718{
Swen Schilligea4a3a62010-12-02 15:16:16 +0100719 struct zfcp_dbf *dbf = adapter->dbf;
720
721 adapter->dbf = NULL;
722 zfcp_dbf_unregister(dbf);
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200723}
Swen Schillig57717102009-08-18 15:43:21 +0200724