]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
8a36e453 | 2 | /* |
553448f6 | 3 | * zfcp device driver |
8a36e453 | 4 | * |
553448f6 | 5 | * Debug traces for zfcp. |
8a36e453 | 6 | * |
4f871ec1 | 7 | * Copyright IBM Corp. 2002, 2018 |
8a36e453 MS |
8 | */ |
9 | ||
ecf39d42 CS |
10 | #define KMSG_COMPONENT "zfcp" |
11 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt | |
12 | ||
3a4c5d59 | 13 | #include <linux/module.h> |
8a36e453 | 14 | #include <linux/ctype.h> |
5a0e3ad6 | 15 | #include <linux/slab.h> |
364c8558 | 16 | #include <asm/debug.h> |
d46f384a | 17 | #include "zfcp_dbf.h" |
8a36e453 | 18 | #include "zfcp_ext.h" |
bd0072ec | 19 | #include "zfcp_fc.h" |
8a36e453 MS |
20 | |
21 | static u32 dbfsize = 4; | |
22 | ||
23 | module_param(dbfsize, uint, 0400); | |
24 | MODULE_PARM_DESC(dbfsize, | |
25 | "number of pages for each debug feature area (default 4)"); | |
26 | ||
bf3ea3ae SM |
27 | static u32 dbflevel = 3; |
28 | ||
29 | module_param(dbflevel, uint, 0400); | |
30 | MODULE_PARM_DESC(dbflevel, | |
31 | "log level for each debug feature area " | |
32 | "(default 3, range 0..6)"); | |
33 | ||
a54ca0f6 | 34 | static inline unsigned int zfcp_dbf_plen(unsigned int offset) |
c15450e3 | 35 | { |
a54ca0f6 SS |
36 | return sizeof(struct zfcp_dbf_pay) + offset - ZFCP_DBF_PAY_MAX_REC; |
37 | } | |
38 | ||
39 | static inline | |
40 | void zfcp_dbf_pl_write(struct zfcp_dbf *dbf, void *data, u16 length, char *area, | |
41 | u64 req_id) | |
42 | { | |
43 | struct zfcp_dbf_pay *pl = &dbf->pay_buf; | |
44 | u16 offset = 0, rec_length; | |
45 | ||
46 | spin_lock(&dbf->pay_lock); | |
47 | memset(pl, 0, sizeof(*pl)); | |
48 | pl->fsf_req_id = req_id; | |
49 | memcpy(pl->area, area, ZFCP_DBF_TAG_LEN); | |
50 | ||
51 | while (offset < length) { | |
52 | rec_length = min((u16) ZFCP_DBF_PAY_MAX_REC, | |
53 | (u16) (length - offset)); | |
54 | memcpy(pl->data, data + offset, rec_length); | |
55 | debug_event(dbf->pay, 1, pl, zfcp_dbf_plen(rec_length)); | |
56 | ||
57 | offset += rec_length; | |
58 | pl->counter++; | |
c15450e3 | 59 | } |
a54ca0f6 SS |
60 | |
61 | spin_unlock(&dbf->pay_lock); | |
c15450e3 MP |
62 | } |
63 | ||
a54ca0f6 SS |
64 | /** |
65 | * zfcp_dbf_hba_fsf_res - trace event for fsf responses | |
66 | * @tag: tag indicating which kind of unsolicited status has been received | |
67 | * @req: request for which a response was received | |
68 | */ | |
35f040df | 69 | void zfcp_dbf_hba_fsf_res(char *tag, int level, struct zfcp_fsf_req *req) |
8a36e453 | 70 | { |
a54ca0f6 SS |
71 | struct zfcp_dbf *dbf = req->adapter->dbf; |
72 | struct fsf_qtcb_prefix *q_pref = &req->qtcb->prefix; | |
73 | struct fsf_qtcb_header *q_head = &req->qtcb->header; | |
74 | struct zfcp_dbf_hba *rec = &dbf->hba_buf; | |
8a36e453 MS |
75 | unsigned long flags; |
76 | ||
5771710b | 77 | spin_lock_irqsave(&dbf->hba_lock, flags); |
6bc473dd | 78 | memset(rec, 0, sizeof(*rec)); |
8a36e453 | 79 | |
a54ca0f6 SS |
80 | memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN); |
81 | rec->id = ZFCP_DBF_HBA_RES; | |
82 | rec->fsf_req_id = req->req_id; | |
83 | rec->fsf_req_status = req->status; | |
84 | rec->fsf_cmd = req->fsf_command; | |
85 | rec->fsf_seq_no = req->seq_no; | |
86 | rec->u.res.req_issued = req->issued; | |
87 | rec->u.res.prot_status = q_pref->prot_status; | |
88 | rec->u.res.fsf_status = q_head->fsf_status; | |
7c964ffe SM |
89 | rec->u.res.port_handle = q_head->port_handle; |
90 | rec->u.res.lun_handle = q_head->lun_handle; | |
a54ca0f6 SS |
91 | |
92 | memcpy(rec->u.res.prot_status_qual, &q_pref->prot_status_qual, | |
93 | FSF_PROT_STATUS_QUAL_SIZE); | |
94 | memcpy(rec->u.res.fsf_status_qual, &q_head->fsf_status_qual, | |
95 | FSF_STATUS_QUALIFIER_SIZE); | |
96 | ||
97 | if (req->fsf_command != FSF_QTCB_FCP_CMND) { | |
98 | rec->pl_len = q_head->log_length; | |
99 | zfcp_dbf_pl_write(dbf, (char *)q_pref + q_head->log_start, | |
100 | rec->pl_len, "fsf_res", req->req_id); | |
8a36e453 MS |
101 | } |
102 | ||
35f040df | 103 | debug_event(dbf->hba, level, rec, sizeof(*rec)); |
5771710b | 104 | spin_unlock_irqrestore(&dbf->hba_lock, flags); |
8a36e453 MS |
105 | } |
106 | ||
bfab1637 | 107 | /** |
a54ca0f6 SS |
108 | * zfcp_dbf_hba_fsf_uss - trace event for an unsolicited status buffer |
109 | * @tag: tag indicating which kind of unsolicited status has been received | |
110 | * @req: request providing the unsolicited status | |
bfab1637 | 111 | */ |
a54ca0f6 | 112 | void zfcp_dbf_hba_fsf_uss(char *tag, struct zfcp_fsf_req *req) |
8a36e453 | 113 | { |
a54ca0f6 SS |
114 | struct zfcp_dbf *dbf = req->adapter->dbf; |
115 | struct fsf_status_read_buffer *srb = req->data; | |
116 | struct zfcp_dbf_hba *rec = &dbf->hba_buf; | |
f32c9e03 | 117 | static int const level = 2; |
8a36e453 MS |
118 | unsigned long flags; |
119 | ||
f32c9e03 MP |
120 | if (unlikely(!debug_level_enabled(dbf->hba, level))) |
121 | return; | |
122 | ||
5771710b | 123 | spin_lock_irqsave(&dbf->hba_lock, flags); |
a54ca0f6 SS |
124 | memset(rec, 0, sizeof(*rec)); |
125 | ||
126 | memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN); | |
127 | rec->id = ZFCP_DBF_HBA_USS; | |
128 | rec->fsf_req_id = req->req_id; | |
129 | rec->fsf_req_status = req->status; | |
130 | rec->fsf_cmd = req->fsf_command; | |
131 | ||
132 | if (!srb) | |
133 | goto log; | |
134 | ||
135 | rec->u.uss.status_type = srb->status_type; | |
136 | rec->u.uss.status_subtype = srb->status_subtype; | |
137 | rec->u.uss.d_id = ntoh24(srb->d_id); | |
138 | rec->u.uss.lun = srb->fcp_lun; | |
139 | memcpy(&rec->u.uss.queue_designator, &srb->queue_designator, | |
140 | sizeof(rec->u.uss.queue_designator)); | |
141 | ||
142 | /* status read buffer payload length */ | |
143 | rec->pl_len = (!srb->length) ? 0 : srb->length - | |
144 | offsetof(struct fsf_status_read_buffer, payload); | |
145 | ||
146 | if (rec->pl_len) | |
147 | zfcp_dbf_pl_write(dbf, srb->payload.data, rec->pl_len, | |
148 | "fsf_uss", req->req_id); | |
149 | log: | |
f32c9e03 | 150 | debug_event(dbf->hba, level, rec, sizeof(*rec)); |
5771710b | 151 | spin_unlock_irqrestore(&dbf->hba_lock, flags); |
8a36e453 MS |
152 | } |
153 | ||
57069386 | 154 | /** |
a54ca0f6 SS |
155 | * zfcp_dbf_hba_bit_err - trace event for bit error conditions |
156 | * @tag: tag indicating which kind of unsolicited status has been received | |
157 | * @req: request which caused the bit_error condition | |
57069386 | 158 | */ |
a54ca0f6 | 159 | void zfcp_dbf_hba_bit_err(char *tag, struct zfcp_fsf_req *req) |
57069386 | 160 | { |
a54ca0f6 SS |
161 | struct zfcp_dbf *dbf = req->adapter->dbf; |
162 | struct zfcp_dbf_hba *rec = &dbf->hba_buf; | |
57069386 | 163 | struct fsf_status_read_buffer *sr_buf = req->data; |
f32c9e03 | 164 | static int const level = 1; |
57069386 SS |
165 | unsigned long flags; |
166 | ||
f32c9e03 MP |
167 | if (unlikely(!debug_level_enabled(dbf->hba, level))) |
168 | return; | |
169 | ||
5771710b | 170 | spin_lock_irqsave(&dbf->hba_lock, flags); |
a54ca0f6 | 171 | memset(rec, 0, sizeof(*rec)); |
8a36e453 | 172 | |
a54ca0f6 SS |
173 | memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN); |
174 | rec->id = ZFCP_DBF_HBA_BIT; | |
175 | rec->fsf_req_id = req->req_id; | |
176 | rec->fsf_req_status = req->status; | |
177 | rec->fsf_cmd = req->fsf_command; | |
178 | memcpy(&rec->u.be, &sr_buf->payload.bit_error, | |
179 | sizeof(struct fsf_bit_error_payload)); | |
180 | ||
f32c9e03 | 181 | debug_event(dbf->hba, level, rec, sizeof(*rec)); |
a54ca0f6 | 182 | spin_unlock_irqrestore(&dbf->hba_lock, flags); |
8a36e453 MS |
183 | } |
184 | ||
86a9668a SS |
185 | /** |
186 | * zfcp_dbf_hba_def_err - trace event for deferred error messages | |
187 | * @adapter: pointer to struct zfcp_adapter | |
188 | * @req_id: request id which caused the deferred error message | |
189 | * @scount: number of sbals incl. the signaling sbal | |
190 | * @pl: array of all involved sbals | |
191 | */ | |
192 | void zfcp_dbf_hba_def_err(struct zfcp_adapter *adapter, u64 req_id, u16 scount, | |
193 | void **pl) | |
194 | { | |
195 | struct zfcp_dbf *dbf = adapter->dbf; | |
196 | struct zfcp_dbf_pay *payload = &dbf->pay_buf; | |
197 | unsigned long flags; | |
f32c9e03 | 198 | static int const level = 1; |
86a9668a SS |
199 | u16 length; |
200 | ||
f32c9e03 MP |
201 | if (unlikely(!debug_level_enabled(dbf->pay, level))) |
202 | return; | |
203 | ||
86a9668a SS |
204 | if (!pl) |
205 | return; | |
206 | ||
207 | spin_lock_irqsave(&dbf->pay_lock, flags); | |
208 | memset(payload, 0, sizeof(*payload)); | |
209 | ||
210 | memcpy(payload->area, "def_err", 7); | |
211 | payload->fsf_req_id = req_id; | |
212 | payload->counter = 0; | |
213 | length = min((u16)sizeof(struct qdio_buffer), | |
214 | (u16)ZFCP_DBF_PAY_MAX_REC); | |
215 | ||
01e60527 | 216 | while (payload->counter < scount && (char *)pl[payload->counter]) { |
86a9668a | 217 | memcpy(payload->data, (char *)pl[payload->counter], length); |
f32c9e03 | 218 | debug_event(dbf->pay, level, payload, zfcp_dbf_plen(length)); |
86a9668a SS |
219 | payload->counter++; |
220 | } | |
221 | ||
222 | spin_unlock_irqrestore(&dbf->pay_lock, flags); | |
223 | } | |
224 | ||
cb452149 SM |
225 | /** |
226 | * zfcp_dbf_hba_basic - trace event for basic adapter events | |
227 | * @adapter: pointer to struct zfcp_adapter | |
228 | */ | |
229 | void zfcp_dbf_hba_basic(char *tag, struct zfcp_adapter *adapter) | |
230 | { | |
231 | struct zfcp_dbf *dbf = adapter->dbf; | |
232 | struct zfcp_dbf_hba *rec = &dbf->hba_buf; | |
f32c9e03 | 233 | static int const level = 1; |
cb452149 SM |
234 | unsigned long flags; |
235 | ||
f32c9e03 MP |
236 | if (unlikely(!debug_level_enabled(dbf->hba, level))) |
237 | return; | |
238 | ||
cb452149 SM |
239 | spin_lock_irqsave(&dbf->hba_lock, flags); |
240 | memset(rec, 0, sizeof(*rec)); | |
241 | ||
242 | memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN); | |
243 | rec->id = ZFCP_DBF_HBA_BASIC; | |
244 | ||
f32c9e03 | 245 | debug_event(dbf->hba, level, rec, sizeof(*rec)); |
cb452149 SM |
246 | spin_unlock_irqrestore(&dbf->hba_lock, flags); |
247 | } | |
248 | ||
ae0904f6 SS |
249 | static void zfcp_dbf_set_common(struct zfcp_dbf_rec *rec, |
250 | struct zfcp_adapter *adapter, | |
251 | struct zfcp_port *port, | |
252 | struct scsi_device *sdev) | |
d79a83db | 253 | { |
ae0904f6 SS |
254 | rec->adapter_status = atomic_read(&adapter->status); |
255 | if (port) { | |
256 | rec->port_status = atomic_read(&port->status); | |
257 | rec->wwpn = port->wwpn; | |
258 | rec->d_id = port->d_id; | |
259 | } | |
260 | if (sdev) { | |
261 | rec->lun_status = atomic_read(&sdev_to_zfcp(sdev)->status); | |
262 | rec->lun = zfcp_scsi_dev_lun(sdev); | |
0102a30a SM |
263 | } else |
264 | rec->lun = ZFCP_DBF_INVALID_LUN; | |
d79a83db MP |
265 | } |
266 | ||
348447e8 | 267 | /** |
ae0904f6 SS |
268 | * zfcp_dbf_rec_trig - trace event related to triggered recovery |
269 | * @tag: identifier for event | |
270 | * @adapter: adapter on which the erp_action should run | |
271 | * @port: remote port involved in the erp_action | |
272 | * @sdev: scsi device involved in the erp_action | |
273 | * @want: wanted erp_action | |
274 | * @need: required erp_action | |
275 | * | |
276 | * The adapter->erp_lock has to be held. | |
348447e8 | 277 | */ |
ae0904f6 SS |
278 | void zfcp_dbf_rec_trig(char *tag, struct zfcp_adapter *adapter, |
279 | struct zfcp_port *port, struct scsi_device *sdev, | |
280 | u8 want, u8 need) | |
348447e8 | 281 | { |
ae0904f6 SS |
282 | struct zfcp_dbf *dbf = adapter->dbf; |
283 | struct zfcp_dbf_rec *rec = &dbf->rec_buf; | |
f32c9e03 | 284 | static int const level = 1; |
348447e8 | 285 | struct list_head *entry; |
698ec016 MP |
286 | unsigned long flags; |
287 | ||
f32c9e03 MP |
288 | if (unlikely(!debug_level_enabled(dbf->rec, level))) |
289 | return; | |
290 | ||
5771710b | 291 | spin_lock_irqsave(&dbf->rec_lock, flags); |
ae0904f6 | 292 | memset(rec, 0, sizeof(*rec)); |
5771710b | 293 | |
ae0904f6 SS |
294 | rec->id = ZFCP_DBF_REC_TRIG; |
295 | memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN); | |
296 | zfcp_dbf_set_common(rec, adapter, port, sdev); | |
698ec016 | 297 | |
ae0904f6 SS |
298 | list_for_each(entry, &adapter->erp_ready_head) |
299 | rec->u.trig.ready++; | |
698ec016 | 300 | |
ae0904f6 SS |
301 | list_for_each(entry, &adapter->erp_running_head) |
302 | rec->u.trig.running++; | |
698ec016 | 303 | |
ae0904f6 SS |
304 | rec->u.trig.want = want; |
305 | rec->u.trig.need = need; | |
698ec016 | 306 | |
f32c9e03 | 307 | debug_event(dbf->rec, level, rec, sizeof(*rec)); |
ae0904f6 | 308 | spin_unlock_irqrestore(&dbf->rec_lock, flags); |
698ec016 MP |
309 | } |
310 | ||
4f871ec1 JR |
311 | /** |
312 | * zfcp_dbf_rec_trig_lock - trace event related to triggered recovery with lock | |
313 | * @tag: identifier for event | |
314 | * @adapter: adapter on which the erp_action should run | |
315 | * @port: remote port involved in the erp_action | |
316 | * @sdev: scsi device involved in the erp_action | |
317 | * @want: wanted erp_action | |
318 | * @need: required erp_action | |
319 | * | |
320 | * The adapter->erp_lock must not be held. | |
321 | */ | |
322 | void zfcp_dbf_rec_trig_lock(char *tag, struct zfcp_adapter *adapter, | |
323 | struct zfcp_port *port, struct scsi_device *sdev, | |
324 | u8 want, u8 need) | |
325 | { | |
326 | unsigned long flags; | |
327 | ||
328 | read_lock_irqsave(&adapter->erp_lock, flags); | |
329 | zfcp_dbf_rec_trig(tag, adapter, port, sdev, want, need); | |
330 | read_unlock_irqrestore(&adapter->erp_lock, flags); | |
331 | } | |
ae0904f6 | 332 | |
9467a9b3 | 333 | /** |
6f2ce1c6 SM |
334 | * zfcp_dbf_rec_run_lvl - trace event related to running recovery |
335 | * @level: trace level to be used for event | |
ae0904f6 SS |
336 | * @tag: identifier for event |
337 | * @erp: erp_action running | |
9467a9b3 | 338 | */ |
6f2ce1c6 | 339 | void zfcp_dbf_rec_run_lvl(int level, char *tag, struct zfcp_erp_action *erp) |
9467a9b3 | 340 | { |
ae0904f6 SS |
341 | struct zfcp_dbf *dbf = erp->adapter->dbf; |
342 | struct zfcp_dbf_rec *rec = &dbf->rec_buf; | |
9467a9b3 MP |
343 | unsigned long flags; |
344 | ||
f32c9e03 MP |
345 | if (!debug_level_enabled(dbf->rec, level)) |
346 | return; | |
347 | ||
5771710b | 348 | spin_lock_irqsave(&dbf->rec_lock, flags); |
ae0904f6 | 349 | memset(rec, 0, sizeof(*rec)); |
9467a9b3 | 350 | |
ae0904f6 SS |
351 | rec->id = ZFCP_DBF_REC_RUN; |
352 | memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN); | |
353 | zfcp_dbf_set_common(rec, erp->adapter, erp->port, erp->sdev); | |
6f4f365e | 354 | |
ae0904f6 SS |
355 | rec->u.run.fsf_req_id = erp->fsf_req_id; |
356 | rec->u.run.rec_status = erp->status; | |
357 | rec->u.run.rec_step = erp->step; | |
358 | rec->u.run.rec_action = erp->action; | |
359 | ||
360 | if (erp->sdev) | |
361 | rec->u.run.rec_count = | |
362 | atomic_read(&sdev_to_zfcp(erp->sdev)->erp_counter); | |
363 | else if (erp->port) | |
364 | rec->u.run.rec_count = atomic_read(&erp->port->erp_counter); | |
365 | else | |
366 | rec->u.run.rec_count = atomic_read(&erp->adapter->erp_counter); | |
367 | ||
6f2ce1c6 | 368 | debug_event(dbf->rec, level, rec, sizeof(*rec)); |
5771710b | 369 | spin_unlock_irqrestore(&dbf->rec_lock, flags); |
6f4f365e MP |
370 | } |
371 | ||
6f2ce1c6 SM |
372 | /** |
373 | * zfcp_dbf_rec_run - trace event related to running recovery | |
374 | * @tag: identifier for event | |
375 | * @erp: erp_action running | |
376 | */ | |
377 | void zfcp_dbf_rec_run(char *tag, struct zfcp_erp_action *erp) | |
378 | { | |
379 | zfcp_dbf_rec_run_lvl(1, tag, erp); | |
380 | } | |
381 | ||
d27a7cb9 SM |
382 | /** |
383 | * zfcp_dbf_rec_run_wka - trace wka port event with info like running recovery | |
384 | * @tag: identifier for event | |
385 | * @wka_port: well known address port | |
386 | * @req_id: request ID to correlate with potential HBA trace record | |
387 | */ | |
388 | void zfcp_dbf_rec_run_wka(char *tag, struct zfcp_fc_wka_port *wka_port, | |
389 | u64 req_id) | |
390 | { | |
391 | struct zfcp_dbf *dbf = wka_port->adapter->dbf; | |
392 | struct zfcp_dbf_rec *rec = &dbf->rec_buf; | |
f32c9e03 | 393 | static int const level = 1; |
d27a7cb9 SM |
394 | unsigned long flags; |
395 | ||
f32c9e03 MP |
396 | if (unlikely(!debug_level_enabled(dbf->rec, level))) |
397 | return; | |
398 | ||
d27a7cb9 SM |
399 | spin_lock_irqsave(&dbf->rec_lock, flags); |
400 | memset(rec, 0, sizeof(*rec)); | |
401 | ||
402 | rec->id = ZFCP_DBF_REC_RUN; | |
403 | memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN); | |
404 | rec->port_status = wka_port->status; | |
405 | rec->d_id = wka_port->d_id; | |
406 | rec->lun = ZFCP_DBF_INVALID_LUN; | |
407 | ||
408 | rec->u.run.fsf_req_id = req_id; | |
409 | rec->u.run.rec_status = ~0; | |
410 | rec->u.run.rec_step = ~0; | |
411 | rec->u.run.rec_action = ~0; | |
412 | rec->u.run.rec_count = ~0; | |
413 | ||
f32c9e03 | 414 | debug_event(dbf->rec, level, rec, sizeof(*rec)); |
d27a7cb9 SM |
415 | spin_unlock_irqrestore(&dbf->rec_lock, flags); |
416 | } | |
417 | ||
f32c9e03 MP |
418 | #define ZFCP_DBF_SAN_LEVEL 1 |
419 | ||
2c55b750 | 420 | static inline |
aceeffbb SM |
421 | void zfcp_dbf_san(char *tag, struct zfcp_dbf *dbf, |
422 | char *paytag, struct scatterlist *sg, u8 id, u16 len, | |
423 | u64 req_id, u32 d_id, u16 cap_len) | |
8a36e453 | 424 | { |
2c55b750 SS |
425 | struct zfcp_dbf_san *rec = &dbf->san_buf; |
426 | u16 rec_len; | |
6bc473dd | 427 | unsigned long flags; |
aceeffbb SM |
428 | struct zfcp_dbf_pay *payload = &dbf->pay_buf; |
429 | u16 pay_sum = 0; | |
8a36e453 | 430 | |
5771710b | 431 | spin_lock_irqsave(&dbf->san_lock, flags); |
2c55b750 | 432 | memset(rec, 0, sizeof(*rec)); |
8a36e453 | 433 | |
2c55b750 SS |
434 | rec->id = id; |
435 | rec->fsf_req_id = req_id; | |
436 | rec->d_id = d_id; | |
2c55b750 | 437 | memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN); |
aceeffbb SM |
438 | rec->pl_len = len; /* full length even if we cap pay below */ |
439 | if (!sg) | |
440 | goto out; | |
441 | rec_len = min_t(unsigned int, sg->length, ZFCP_DBF_SAN_MAX_PAYLOAD); | |
442 | memcpy(rec->payload, sg_virt(sg), rec_len); /* part of 1st sg entry */ | |
443 | if (len <= rec_len) | |
444 | goto out; /* skip pay record if full content in rec->payload */ | |
445 | ||
446 | /* if (len > rec_len): | |
447 | * dump data up to cap_len ignoring small duplicate in rec->payload | |
448 | */ | |
e7cb08e8 | 449 | spin_lock(&dbf->pay_lock); |
aceeffbb SM |
450 | memset(payload, 0, sizeof(*payload)); |
451 | memcpy(payload->area, paytag, ZFCP_DBF_TAG_LEN); | |
452 | payload->fsf_req_id = req_id; | |
453 | payload->counter = 0; | |
454 | for (; sg && pay_sum < cap_len; sg = sg_next(sg)) { | |
455 | u16 pay_len, offset = 0; | |
456 | ||
457 | while (offset < sg->length && pay_sum < cap_len) { | |
458 | pay_len = min((u16)ZFCP_DBF_PAY_MAX_REC, | |
459 | (u16)(sg->length - offset)); | |
460 | /* cap_len <= pay_sum < cap_len+ZFCP_DBF_PAY_MAX_REC */ | |
461 | memcpy(payload->data, sg_virt(sg) + offset, pay_len); | |
f32c9e03 | 462 | debug_event(dbf->pay, ZFCP_DBF_SAN_LEVEL, payload, |
aceeffbb SM |
463 | zfcp_dbf_plen(pay_len)); |
464 | payload->counter++; | |
465 | offset += pay_len; | |
466 | pay_sum += pay_len; | |
467 | } | |
468 | } | |
469 | spin_unlock(&dbf->pay_lock); | |
8a36e453 | 470 | |
aceeffbb | 471 | out: |
f32c9e03 | 472 | debug_event(dbf->san, ZFCP_DBF_SAN_LEVEL, rec, sizeof(*rec)); |
5771710b | 473 | spin_unlock_irqrestore(&dbf->san_lock, flags); |
8a36e453 MS |
474 | } |
475 | ||
bfab1637 | 476 | /** |
2c55b750 | 477 | * zfcp_dbf_san_req - trace event for issued SAN request |
3f79410c | 478 | * @tag: identifier for event |
2c55b750 SS |
479 | * @fsf_req: request containing issued CT data |
480 | * d_id: destination ID | |
bfab1637 | 481 | */ |
2c55b750 | 482 | void zfcp_dbf_san_req(char *tag, struct zfcp_fsf_req *fsf, u32 d_id) |
8a36e453 | 483 | { |
2c55b750 SS |
484 | struct zfcp_dbf *dbf = fsf->adapter->dbf; |
485 | struct zfcp_fsf_ct_els *ct_els = fsf->data; | |
486 | u16 length; | |
8a36e453 | 487 | |
f32c9e03 MP |
488 | if (unlikely(!debug_level_enabled(dbf->san, ZFCP_DBF_SAN_LEVEL))) |
489 | return; | |
490 | ||
aceeffbb SM |
491 | length = (u16)zfcp_qdio_real_bytes(ct_els->req); |
492 | zfcp_dbf_san(tag, dbf, "san_req", ct_els->req, ZFCP_DBF_SAN_REQ, | |
493 | length, fsf->req_id, d_id, length); | |
494 | } | |
495 | ||
496 | static u16 zfcp_dbf_san_res_cap_len_if_gpn_ft(char *tag, | |
497 | struct zfcp_fsf_req *fsf, | |
498 | u16 len) | |
499 | { | |
500 | struct zfcp_fsf_ct_els *ct_els = fsf->data; | |
501 | struct fc_ct_hdr *reqh = sg_virt(ct_els->req); | |
502 | struct fc_ns_gid_ft *reqn = (struct fc_ns_gid_ft *)(reqh + 1); | |
503 | struct scatterlist *resp_entry = ct_els->resp; | |
975171b4 | 504 | struct fc_ct_hdr *resph; |
aceeffbb SM |
505 | struct fc_gpn_ft_resp *acc; |
506 | int max_entries, x, last = 0; | |
507 | ||
508 | if (!(memcmp(tag, "fsscth2", 7) == 0 | |
509 | && ct_els->d_id == FC_FID_DIR_SERV | |
510 | && reqh->ct_rev == FC_CT_REV | |
511 | && reqh->ct_in_id[0] == 0 | |
512 | && reqh->ct_in_id[1] == 0 | |
513 | && reqh->ct_in_id[2] == 0 | |
514 | && reqh->ct_fs_type == FC_FST_DIR | |
515 | && reqh->ct_fs_subtype == FC_NS_SUBTYPE | |
516 | && reqh->ct_options == 0 | |
517 | && reqh->_ct_resvd1 == 0 | |
9d464fc1 | 518 | && reqh->ct_cmd == cpu_to_be16(FC_NS_GPN_FT) |
aceeffbb SM |
519 | /* reqh->ct_mr_size can vary so do not match but read below */ |
520 | && reqh->_ct_resvd2 == 0 | |
521 | && reqh->ct_reason == 0 | |
522 | && reqh->ct_explan == 0 | |
523 | && reqh->ct_vendor == 0 | |
524 | && reqn->fn_resvd == 0 | |
525 | && reqn->fn_domain_id_scope == 0 | |
526 | && reqn->fn_area_id_scope == 0 | |
527 | && reqn->fn_fc4_type == FC_TYPE_FCP)) | |
528 | return len; /* not GPN_FT response so do not cap */ | |
529 | ||
530 | acc = sg_virt(resp_entry); | |
975171b4 SM |
531 | |
532 | /* cap all but accept CT responses to at least the CT header */ | |
533 | resph = (struct fc_ct_hdr *)acc; | |
534 | if ((ct_els->status) || | |
535 | (resph->ct_cmd != cpu_to_be16(FC_FS_ACC))) | |
536 | return max(FC_CT_HDR_LEN, ZFCP_DBF_SAN_MAX_PAYLOAD); | |
537 | ||
9d464fc1 SM |
538 | max_entries = (be16_to_cpu(reqh->ct_mr_size) * 4 / |
539 | sizeof(struct fc_gpn_ft_resp)) | |
aceeffbb SM |
540 | + 1 /* zfcp_fc_scan_ports: bytes correct, entries off-by-one |
541 | * to account for header as 1st pseudo "entry" */; | |
542 | ||
543 | /* the basic CT_IU preamble is the same size as one entry in the GPN_FT | |
544 | * response, allowing us to skip special handling for it - just skip it | |
545 | */ | |
546 | for (x = 1; x < max_entries && !last; x++) { | |
547 | if (x % (ZFCP_FC_GPN_FT_ENT_PAGE + 1)) | |
548 | acc++; | |
549 | else | |
550 | acc = sg_virt(++resp_entry); | |
551 | ||
552 | last = acc->fp_flags & FC_NS_FID_LAST; | |
553 | } | |
554 | len = min(len, (u16)(x * sizeof(struct fc_gpn_ft_resp))); | |
555 | return len; /* cap after last entry */ | |
8a36e453 MS |
556 | } |
557 | ||
bfab1637 | 558 | /** |
2c55b750 | 559 | * zfcp_dbf_san_res - trace event for received SAN request |
3f79410c | 560 | * @tag: identifier for event |
2c55b750 | 561 | * @fsf_req: request containing issued CT data |
bfab1637 | 562 | */ |
2c55b750 | 563 | void zfcp_dbf_san_res(char *tag, struct zfcp_fsf_req *fsf) |
8a36e453 | 564 | { |
2c55b750 SS |
565 | struct zfcp_dbf *dbf = fsf->adapter->dbf; |
566 | struct zfcp_fsf_ct_els *ct_els = fsf->data; | |
567 | u16 length; | |
8a36e453 | 568 | |
f32c9e03 MP |
569 | if (unlikely(!debug_level_enabled(dbf->san, ZFCP_DBF_SAN_LEVEL))) |
570 | return; | |
571 | ||
aceeffbb SM |
572 | length = (u16)zfcp_qdio_real_bytes(ct_els->resp); |
573 | zfcp_dbf_san(tag, dbf, "san_res", ct_els->resp, ZFCP_DBF_SAN_RES, | |
574 | length, fsf->req_id, ct_els->d_id, | |
575 | zfcp_dbf_san_res_cap_len_if_gpn_ft(tag, fsf, length)); | |
8a36e453 MS |
576 | } |
577 | ||
bfab1637 | 578 | /** |
2c55b750 | 579 | * zfcp_dbf_san_in_els - trace event for incoming ELS |
3f79410c | 580 | * @tag: identifier for event |
2c55b750 | 581 | * @fsf_req: request containing issued CT data |
bfab1637 | 582 | */ |
2c55b750 | 583 | void zfcp_dbf_san_in_els(char *tag, struct zfcp_fsf_req *fsf) |
8a36e453 | 584 | { |
2c55b750 SS |
585 | struct zfcp_dbf *dbf = fsf->adapter->dbf; |
586 | struct fsf_status_read_buffer *srb = | |
587 | (struct fsf_status_read_buffer *) fsf->data; | |
588 | u16 length; | |
aceeffbb | 589 | struct scatterlist sg; |
2c55b750 | 590 | |
f32c9e03 MP |
591 | if (unlikely(!debug_level_enabled(dbf->san, ZFCP_DBF_SAN_LEVEL))) |
592 | return; | |
593 | ||
2c55b750 SS |
594 | length = (u16)(srb->length - |
595 | offsetof(struct fsf_status_read_buffer, payload)); | |
aceeffbb SM |
596 | sg_init_one(&sg, srb->payload.data, length); |
597 | zfcp_dbf_san(tag, dbf, "san_els", &sg, ZFCP_DBF_SAN_ELS, length, | |
598 | fsf->req_id, ntoh24(srb->d_id), length); | |
8a36e453 MS |
599 | } |
600 | ||
250a1352 SS |
601 | /** |
602 | * zfcp_dbf_scsi - trace event for scsi commands | |
603 | * @tag: identifier for event | |
604 | * @sc: pointer to struct scsi_cmnd | |
605 | * @fsf: pointer to struct zfcp_fsf_req | |
606 | */ | |
35f040df SM |
607 | void zfcp_dbf_scsi(char *tag, int level, struct scsi_cmnd *sc, |
608 | struct zfcp_fsf_req *fsf) | |
8a36e453 | 609 | { |
250a1352 SS |
610 | struct zfcp_adapter *adapter = |
611 | (struct zfcp_adapter *) sc->device->host->hostdata[0]; | |
612 | struct zfcp_dbf *dbf = adapter->dbf; | |
613 | struct zfcp_dbf_scsi *rec = &dbf->scsi_buf; | |
4318e08c | 614 | struct fcp_resp_with_ext *fcp_rsp; |
250a1352 SS |
615 | struct fcp_resp_rsp_info *fcp_rsp_info; |
616 | unsigned long flags; | |
8a36e453 | 617 | |
5771710b | 618 | spin_lock_irqsave(&dbf->scsi_lock, flags); |
250a1352 | 619 | memset(rec, 0, sizeof(*rec)); |
8a36e453 | 620 | |
250a1352 SS |
621 | memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN); |
622 | rec->id = ZFCP_DBF_SCSI_CMND; | |
623 | rec->scsi_result = sc->result; | |
624 | rec->scsi_retries = sc->retries; | |
625 | rec->scsi_allowed = sc->allowed; | |
626 | rec->scsi_id = sc->device->id; | |
9cb78c16 | 627 | rec->scsi_lun = (u32)sc->device->lun; |
5d4a3d0a | 628 | rec->scsi_lun_64_hi = (u32)(sc->device->lun >> 32); |
250a1352 SS |
629 | rec->host_scribble = (unsigned long)sc->host_scribble; |
630 | ||
631 | memcpy(rec->scsi_opcode, sc->cmnd, | |
632 | min((int)sc->cmd_len, ZFCP_DBF_SCSI_OPCODE)); | |
633 | ||
634 | if (fsf) { | |
635 | rec->fsf_req_id = fsf->req_id; | |
12c3e575 | 636 | rec->pl_len = FCP_RESP_WITH_EXT; |
df00d7b8 | 637 | fcp_rsp = &(fsf->qtcb->bottom.io.fcp_rsp.iu); |
12c3e575 | 638 | /* mandatory parts of FCP_RSP IU in this SCSI record */ |
250a1352 SS |
639 | memcpy(&rec->fcp_rsp, fcp_rsp, FCP_RESP_WITH_EXT); |
640 | if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL) { | |
641 | fcp_rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1]; | |
642 | rec->fcp_rsp_info = fcp_rsp_info->rsp_code; | |
12c3e575 | 643 | rec->pl_len += be32_to_cpu(fcp_rsp->ext.fr_rsp_len); |
250a1352 SS |
644 | } |
645 | if (fcp_rsp->resp.fr_flags & FCP_SNS_LEN_VAL) { | |
12c3e575 | 646 | rec->pl_len += be32_to_cpu(fcp_rsp->ext.fr_sns_len); |
250a1352 | 647 | } |
12c3e575 SM |
648 | /* complete FCP_RSP IU in associated PAYload record |
649 | * but only if there are optional parts | |
650 | */ | |
651 | if (fcp_rsp->resp.fr_flags != 0) | |
652 | zfcp_dbf_pl_write( | |
653 | dbf, fcp_rsp, | |
654 | /* at least one full PAY record | |
655 | * but not beyond hardware response field | |
656 | */ | |
657 | min_t(u16, max_t(u16, rec->pl_len, | |
658 | ZFCP_DBF_PAY_MAX_REC), | |
659 | FSF_FCP_RSP_SIZE), | |
660 | "fcp_riu", fsf->req_id); | |
8a36e453 | 661 | } |
8a36e453 | 662 | |
35f040df | 663 | debug_event(dbf->scsi, level, rec, sizeof(*rec)); |
250a1352 SS |
664 | spin_unlock_irqrestore(&dbf->scsi_lock, flags); |
665 | } | |
8a36e453 | 666 | |
96a98508 SM |
667 | /** |
668 | * zfcp_dbf_scsi_eh() - Trace event for special cases of scsi_eh callbacks. | |
669 | * @tag: Identifier for event. | |
670 | * @adapter: Pointer to zfcp adapter as context for this event. | |
671 | * @scsi_id: SCSI ID/target to indicate scope of task management function (TMF). | |
672 | * @ret: Return value of calling function. | |
673 | * | |
674 | * This SCSI trace variant does not depend on any of: | |
675 | * scsi_cmnd, zfcp_fsf_req, scsi_device. | |
676 | */ | |
677 | void zfcp_dbf_scsi_eh(char *tag, struct zfcp_adapter *adapter, | |
678 | unsigned int scsi_id, int ret) | |
679 | { | |
680 | struct zfcp_dbf *dbf = adapter->dbf; | |
681 | struct zfcp_dbf_scsi *rec = &dbf->scsi_buf; | |
682 | unsigned long flags; | |
683 | static int const level = 1; | |
684 | ||
685 | if (unlikely(!debug_level_enabled(adapter->dbf->scsi, level))) | |
686 | return; | |
687 | ||
688 | spin_lock_irqsave(&dbf->scsi_lock, flags); | |
689 | memset(rec, 0, sizeof(*rec)); | |
690 | ||
691 | memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN); | |
692 | rec->id = ZFCP_DBF_SCSI_CMND; | |
693 | rec->scsi_result = ret; /* re-use field, int is 4 bytes and fits */ | |
694 | rec->scsi_retries = ~0; | |
695 | rec->scsi_allowed = ~0; | |
696 | rec->fcp_rsp_info = ~0; | |
697 | rec->scsi_id = scsi_id; | |
698 | rec->scsi_lun = (u32)ZFCP_DBF_INVALID_LUN; | |
699 | rec->scsi_lun_64_hi = (u32)(ZFCP_DBF_INVALID_LUN >> 32); | |
700 | rec->host_scribble = ~0; | |
701 | memset(rec->scsi_opcode, 0xff, ZFCP_DBF_SCSI_OPCODE); | |
702 | ||
703 | debug_event(dbf->scsi, level, rec, sizeof(*rec)); | |
704 | spin_unlock_irqrestore(&dbf->scsi_lock, flags); | |
705 | } | |
706 | ||
ea4a3a6a | 707 | static debug_info_t *zfcp_dbf_reg(const char *name, int size, int rec_size) |
d46f384a CS |
708 | { |
709 | struct debug_info *d; | |
710 | ||
ea4a3a6a | 711 | d = debug_register(name, size, 1, rec_size); |
d46f384a CS |
712 | if (!d) |
713 | return NULL; | |
714 | ||
715 | debug_register_view(d, &debug_hex_ascii_view); | |
bf3ea3ae | 716 | debug_set_level(d, dbflevel); |
d46f384a CS |
717 | |
718 | return d; | |
719 | } | |
720 | ||
ea4a3a6a SS |
721 | static void zfcp_dbf_unregister(struct zfcp_dbf *dbf) |
722 | { | |
723 | if (!dbf) | |
724 | return; | |
725 | ||
726 | debug_unregister(dbf->scsi); | |
727 | debug_unregister(dbf->san); | |
728 | debug_unregister(dbf->hba); | |
729 | debug_unregister(dbf->pay); | |
730 | debug_unregister(dbf->rec); | |
731 | kfree(dbf); | |
732 | } | |
733 | ||
8a36e453 MS |
734 | /** |
735 | * zfcp_adapter_debug_register - registers debug feature for an adapter | |
736 | * @adapter: pointer to adapter for which debug features should be registered | |
737 | * return: -ENOMEM on error, 0 otherwise | |
738 | */ | |
5771710b | 739 | int zfcp_dbf_adapter_register(struct zfcp_adapter *adapter) |
8a36e453 | 740 | { |
ea4a3a6a | 741 | char name[DEBUG_MAX_NAME_LEN]; |
d46f384a CS |
742 | struct zfcp_dbf *dbf; |
743 | ||
d23948ea | 744 | dbf = kzalloc(sizeof(struct zfcp_dbf), GFP_KERNEL); |
d46f384a CS |
745 | if (!dbf) |
746 | return -ENOMEM; | |
747 | ||
a54ca0f6 | 748 | spin_lock_init(&dbf->pay_lock); |
5771710b SS |
749 | spin_lock_init(&dbf->hba_lock); |
750 | spin_lock_init(&dbf->san_lock); | |
751 | spin_lock_init(&dbf->scsi_lock); | |
752 | spin_lock_init(&dbf->rec_lock); | |
8a36e453 | 753 | |
d79a83db | 754 | /* debug feature area which records recovery activity */ |
ea4a3a6a SS |
755 | sprintf(name, "zfcp_%s_rec", dev_name(&adapter->ccw_device->dev)); |
756 | dbf->rec = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_rec)); | |
5771710b SS |
757 | if (!dbf->rec) |
758 | goto err_out; | |
d79a83db | 759 | |
8a36e453 | 760 | /* debug feature area which records HBA (FSF and QDIO) conditions */ |
ea4a3a6a SS |
761 | sprintf(name, "zfcp_%s_hba", dev_name(&adapter->ccw_device->dev)); |
762 | dbf->hba = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_hba)); | |
5771710b SS |
763 | if (!dbf->hba) |
764 | goto err_out; | |
8a36e453 | 765 | |
a54ca0f6 | 766 | /* debug feature area which records payload info */ |
ea4a3a6a SS |
767 | sprintf(name, "zfcp_%s_pay", dev_name(&adapter->ccw_device->dev)); |
768 | dbf->pay = zfcp_dbf_reg(name, dbfsize * 2, sizeof(struct zfcp_dbf_pay)); | |
a54ca0f6 SS |
769 | if (!dbf->pay) |
770 | goto err_out; | |
771 | ||
8a36e453 | 772 | /* debug feature area which records SAN command failures and recovery */ |
ea4a3a6a SS |
773 | sprintf(name, "zfcp_%s_san", dev_name(&adapter->ccw_device->dev)); |
774 | dbf->san = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_san)); | |
5771710b SS |
775 | if (!dbf->san) |
776 | goto err_out; | |
8a36e453 MS |
777 | |
778 | /* debug feature area which records SCSI command failures and recovery */ | |
ea4a3a6a SS |
779 | sprintf(name, "zfcp_%s_scsi", dev_name(&adapter->ccw_device->dev)); |
780 | dbf->scsi = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_scsi)); | |
5771710b SS |
781 | if (!dbf->scsi) |
782 | goto err_out; | |
8a36e453 | 783 | |
d46f384a | 784 | adapter->dbf = dbf; |
8a36e453 | 785 | |
ea4a3a6a | 786 | return 0; |
5771710b | 787 | err_out: |
ea4a3a6a | 788 | zfcp_dbf_unregister(dbf); |
8a36e453 MS |
789 | return -ENOMEM; |
790 | } | |
791 | ||
792 | /** | |
793 | * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter | |
ea4a3a6a | 794 | * @adapter: pointer to adapter for which debug features should be unregistered |
8a36e453 | 795 | */ |
ea4a3a6a | 796 | void zfcp_dbf_adapter_unregister(struct zfcp_adapter *adapter) |
8a36e453 | 797 | { |
ea4a3a6a SS |
798 | struct zfcp_dbf *dbf = adapter->dbf; |
799 | ||
800 | adapter->dbf = NULL; | |
801 | zfcp_dbf_unregister(dbf); | |
8a36e453 | 802 | } |
5771710b | 803 |