Commit | Line | Data |
---|---|---|
8a36e453 | 1 | /* |
553448f6 | 2 | * zfcp device driver |
8a36e453 | 3 | * |
553448f6 | 4 | * Debug traces for zfcp. |
8a36e453 | 5 | * |
d46f384a | 6 | * Copyright IBM Corporation 2002, 2009 |
8a36e453 MS |
7 | */ |
8 | ||
ecf39d42 CS |
9 | #define KMSG_COMPONENT "zfcp" |
10 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt | |
11 | ||
8a36e453 | 12 | #include <linux/ctype.h> |
5a0e3ad6 | 13 | #include <linux/slab.h> |
364c8558 | 14 | #include <asm/debug.h> |
d46f384a | 15 | #include "zfcp_dbf.h" |
8a36e453 | 16 | #include "zfcp_ext.h" |
bd0072ec | 17 | #include "zfcp_fc.h" |
8a36e453 MS |
18 | |
19 | static u32 dbfsize = 4; | |
20 | ||
21 | module_param(dbfsize, uint, 0400); | |
22 | MODULE_PARM_DESC(dbfsize, | |
23 | "number of pages for each debug feature area (default 4)"); | |
24 | ||
c15450e3 MP |
25 | static void zfcp_dbf_hexdump(debug_info_t *dbf, void *to, int to_len, |
26 | int level, char *from, int from_len) | |
27 | { | |
28 | int offset; | |
29 | struct zfcp_dbf_dump *dump = to; | |
30 | int room = to_len - sizeof(*dump); | |
31 | ||
32 | for (offset = 0; offset < from_len; offset += dump->size) { | |
33 | memset(to, 0, to_len); | |
34 | strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE); | |
35 | dump->total_size = from_len; | |
36 | dump->offset = offset; | |
37 | dump->size = min(from_len - offset, room); | |
38 | memcpy(dump->data, from + offset, dump->size); | |
d94ce6c6 | 39 | debug_event(dbf, level, dump, dump->size + sizeof(*dump)); |
c15450e3 MP |
40 | } |
41 | } | |
42 | ||
a9c85775 | 43 | static void zfcp_dbf_tag(char **p, const char *label, const char *tag) |
8a36e453 | 44 | { |
a9c85775 | 45 | int i; |
8a36e453 | 46 | |
a9c85775 | 47 | *p += sprintf(*p, "%-24s", label); |
8a36e453 | 48 | for (i = 0; i < ZFCP_DBF_TAG_SIZE; i++) |
a9c85775 MP |
49 | *p += sprintf(*p, "%c", tag[i]); |
50 | *p += sprintf(*p, "\n"); | |
8a36e453 MS |
51 | } |
52 | ||
10223c60 MP |
53 | static void zfcp_dbf_outs(char **buf, const char *s1, const char *s2) |
54 | { | |
55 | *buf += sprintf(*buf, "%-24s%s\n", s1, s2); | |
56 | } | |
57 | ||
58 | static void zfcp_dbf_out(char **buf, const char *s, const char *format, ...) | |
59 | { | |
60 | va_list arg; | |
61 | ||
62 | *buf += sprintf(*buf, "%-24s", s); | |
63 | va_start(arg, format); | |
64 | *buf += vsprintf(*buf, format, arg); | |
65 | va_end(arg); | |
66 | *buf += sprintf(*buf, "\n"); | |
67 | } | |
68 | ||
df29f4ac MP |
69 | static void zfcp_dbf_outd(char **p, const char *label, char *buffer, |
70 | int buflen, int offset, int total_size) | |
8a36e453 | 71 | { |
df29f4ac MP |
72 | if (!offset) |
73 | *p += sprintf(*p, "%-24s ", label); | |
8a36e453 MS |
74 | while (buflen--) { |
75 | if (offset > 0) { | |
76 | if ((offset % 32) == 0) | |
df29f4ac | 77 | *p += sprintf(*p, "\n%-24c ", ' '); |
8a36e453 | 78 | else if ((offset % 4) == 0) |
df29f4ac | 79 | *p += sprintf(*p, " "); |
8a36e453 | 80 | } |
df29f4ac | 81 | *p += sprintf(*p, "%02x", *buffer++); |
8a36e453 | 82 | if (++offset == total_size) { |
df29f4ac | 83 | *p += sprintf(*p, "\n"); |
8a36e453 MS |
84 | break; |
85 | } | |
86 | } | |
df29f4ac MP |
87 | if (!total_size) |
88 | *p += sprintf(*p, "\n"); | |
8a36e453 MS |
89 | } |
90 | ||
92c7a83f MP |
91 | static int zfcp_dbf_view_header(debug_info_t *id, struct debug_view *view, |
92 | int area, debug_entry_t *entry, char *out_buf) | |
8a36e453 MS |
93 | { |
94 | struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)DEBUG_DATA(entry); | |
8fc5af16 | 95 | struct timespec t; |
b634fff7 | 96 | char *p = out_buf; |
8a36e453 MS |
97 | |
98 | if (strncmp(dump->tag, "dump", ZFCP_DBF_TAG_SIZE) != 0) { | |
b592e89a | 99 | stck_to_timespec(entry->id.stck, &t); |
b634fff7 MP |
100 | zfcp_dbf_out(&p, "timestamp", "%011lu:%06lu", |
101 | t.tv_sec, t.tv_nsec); | |
102 | zfcp_dbf_out(&p, "cpu", "%02i", entry->id.fields.cpuid); | |
103 | } else { | |
d94ce6c6 | 104 | zfcp_dbf_outd(&p, "", dump->data, dump->size, dump->offset, |
df29f4ac | 105 | dump->total_size); |
8a36e453 | 106 | if ((dump->offset + dump->size) == dump->total_size) |
b634fff7 | 107 | p += sprintf(p, "\n"); |
8a36e453 | 108 | } |
b634fff7 | 109 | return p - out_buf; |
8a36e453 MS |
110 | } |
111 | ||
5771710b SS |
112 | void _zfcp_dbf_hba_fsf_response(const char *tag2, int level, |
113 | struct zfcp_fsf_req *fsf_req, | |
114 | struct zfcp_dbf *dbf) | |
8a36e453 | 115 | { |
8a36e453 MS |
116 | struct fsf_qtcb *qtcb = fsf_req->qtcb; |
117 | union fsf_prot_status_qual *prot_status_qual = | |
92c7a83f | 118 | &qtcb->prefix.prot_status_qual; |
8a36e453 MS |
119 | union fsf_status_qual *fsf_status_qual = &qtcb->header.fsf_status_qual; |
120 | struct scsi_cmnd *scsi_cmnd; | |
121 | struct zfcp_port *port; | |
122 | struct zfcp_unit *unit; | |
123 | struct zfcp_send_els *send_els; | |
5771710b SS |
124 | struct zfcp_dbf_hba_record *rec = &dbf->hba_buf; |
125 | struct zfcp_dbf_hba_record_response *response = &rec->u.response; | |
8a36e453 MS |
126 | unsigned long flags; |
127 | ||
5771710b | 128 | spin_lock_irqsave(&dbf->hba_lock, flags); |
6bc473dd | 129 | memset(rec, 0, sizeof(*rec)); |
8a36e453 | 130 | strncpy(rec->tag, "resp", ZFCP_DBF_TAG_SIZE); |
2e261af8 | 131 | strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE); |
8a36e453 MS |
132 | |
133 | response->fsf_command = fsf_req->fsf_command; | |
f0216ae9 | 134 | response->fsf_reqid = fsf_req->req_id; |
8a36e453 MS |
135 | response->fsf_seqno = fsf_req->seq_no; |
136 | response->fsf_issued = fsf_req->issued; | |
137 | response->fsf_prot_status = qtcb->prefix.prot_status; | |
138 | response->fsf_status = qtcb->header.fsf_status; | |
139 | memcpy(response->fsf_prot_status_qual, | |
140 | prot_status_qual, FSF_PROT_STATUS_QUAL_SIZE); | |
141 | memcpy(response->fsf_status_qual, | |
142 | fsf_status_qual, FSF_STATUS_QUALIFIER_SIZE); | |
143 | response->fsf_req_status = fsf_req->status; | |
34c2b712 CS |
144 | response->sbal_first = fsf_req->qdio_req.sbal_first; |
145 | response->sbal_last = fsf_req->qdio_req.sbal_last; | |
146 | response->sbal_response = fsf_req->qdio_req.sbal_response; | |
8a36e453 MS |
147 | response->pool = fsf_req->pool != NULL; |
148 | response->erp_action = (unsigned long)fsf_req->erp_action; | |
149 | ||
150 | switch (fsf_req->fsf_command) { | |
151 | case FSF_QTCB_FCP_CMND: | |
152 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) | |
153 | break; | |
154 | scsi_cmnd = (struct scsi_cmnd *)fsf_req->data; | |
6bc473dd MP |
155 | if (scsi_cmnd) { |
156 | response->u.fcp.cmnd = (unsigned long)scsi_cmnd; | |
157 | response->u.fcp.serial = scsi_cmnd->serial_number; | |
8a36e453 MS |
158 | } |
159 | break; | |
160 | ||
161 | case FSF_QTCB_OPEN_PORT_WITH_DID: | |
162 | case FSF_QTCB_CLOSE_PORT: | |
163 | case FSF_QTCB_CLOSE_PHYSICAL_PORT: | |
164 | port = (struct zfcp_port *)fsf_req->data; | |
6bc473dd MP |
165 | response->u.port.wwpn = port->wwpn; |
166 | response->u.port.d_id = port->d_id; | |
167 | response->u.port.port_handle = qtcb->header.port_handle; | |
8a36e453 MS |
168 | break; |
169 | ||
170 | case FSF_QTCB_OPEN_LUN: | |
171 | case FSF_QTCB_CLOSE_LUN: | |
172 | unit = (struct zfcp_unit *)fsf_req->data; | |
173 | port = unit->port; | |
6bc473dd MP |
174 | response->u.unit.wwpn = port->wwpn; |
175 | response->u.unit.fcp_lun = unit->fcp_lun; | |
176 | response->u.unit.port_handle = qtcb->header.port_handle; | |
177 | response->u.unit.lun_handle = qtcb->header.lun_handle; | |
8a36e453 MS |
178 | break; |
179 | ||
180 | case FSF_QTCB_SEND_ELS: | |
181 | send_els = (struct zfcp_send_els *)fsf_req->data; | |
800c0cad | 182 | response->u.els.d_id = ntoh24(qtcb->bottom.support.d_id); |
8a36e453 MS |
183 | break; |
184 | ||
185 | case FSF_QTCB_ABORT_FCP_CMND: | |
186 | case FSF_QTCB_SEND_GENERIC: | |
187 | case FSF_QTCB_EXCHANGE_CONFIG_DATA: | |
188 | case FSF_QTCB_EXCHANGE_PORT_DATA: | |
189 | case FSF_QTCB_DOWNLOAD_CONTROL_FILE: | |
190 | case FSF_QTCB_UPLOAD_CONTROL_FILE: | |
191 | break; | |
192 | } | |
193 | ||
5771710b | 194 | debug_event(dbf->hba, level, rec, sizeof(*rec)); |
b75db731 MP |
195 | |
196 | /* have fcp channel microcode fixed to use as little as possible */ | |
197 | if (fsf_req->fsf_command != FSF_QTCB_FCP_CMND) { | |
198 | /* adjust length skipping trailing zeros */ | |
199 | char *buf = (char *)qtcb + qtcb->header.log_start; | |
200 | int len = qtcb->header.log_length; | |
201 | for (; len && !buf[len - 1]; len--); | |
5771710b | 202 | zfcp_dbf_hexdump(dbf->hba, rec, sizeof(*rec), level, buf, |
d46f384a | 203 | len); |
b75db731 MP |
204 | } |
205 | ||
5771710b | 206 | spin_unlock_irqrestore(&dbf->hba_lock, flags); |
8a36e453 MS |
207 | } |
208 | ||
5771710b SS |
209 | void _zfcp_dbf_hba_fsf_unsol(const char *tag, int level, struct zfcp_dbf *dbf, |
210 | struct fsf_status_read_buffer *status_buffer) | |
8a36e453 | 211 | { |
5771710b | 212 | struct zfcp_dbf_hba_record *rec = &dbf->hba_buf; |
8a36e453 MS |
213 | unsigned long flags; |
214 | ||
5771710b | 215 | spin_lock_irqsave(&dbf->hba_lock, flags); |
6bc473dd | 216 | memset(rec, 0, sizeof(*rec)); |
8a36e453 MS |
217 | strncpy(rec->tag, "stat", ZFCP_DBF_TAG_SIZE); |
218 | strncpy(rec->tag2, tag, ZFCP_DBF_TAG_SIZE); | |
219 | ||
5771710b | 220 | rec->u.status.failed = atomic_read(&dbf->adapter->stat_miss); |
8a36e453 | 221 | if (status_buffer != NULL) { |
6bc473dd MP |
222 | rec->u.status.status_type = status_buffer->status_type; |
223 | rec->u.status.status_subtype = status_buffer->status_subtype; | |
224 | memcpy(&rec->u.status.queue_designator, | |
8a36e453 MS |
225 | &status_buffer->queue_designator, |
226 | sizeof(struct fsf_queue_designator)); | |
227 | ||
228 | switch (status_buffer->status_type) { | |
229 | case FSF_STATUS_READ_SENSE_DATA_AVAIL: | |
6bc473dd | 230 | rec->u.status.payload_size = |
8a36e453 MS |
231 | ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL; |
232 | break; | |
233 | ||
234 | case FSF_STATUS_READ_BIT_ERROR_THRESHOLD: | |
6bc473dd | 235 | rec->u.status.payload_size = |
8a36e453 MS |
236 | ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD; |
237 | break; | |
238 | ||
239 | case FSF_STATUS_READ_LINK_DOWN: | |
aef4a983 MS |
240 | switch (status_buffer->status_subtype) { |
241 | case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK: | |
242 | case FSF_STATUS_READ_SUB_FDISC_FAILED: | |
6bc473dd | 243 | rec->u.status.payload_size = |
aef4a983 MS |
244 | sizeof(struct fsf_link_down_info); |
245 | } | |
8a36e453 MS |
246 | break; |
247 | ||
aef4a983 | 248 | case FSF_STATUS_READ_FEATURE_UPDATE_ALERT: |
6bc473dd | 249 | rec->u.status.payload_size = |
aef4a983 MS |
250 | ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT; |
251 | break; | |
8a36e453 | 252 | } |
6bc473dd MP |
253 | memcpy(&rec->u.status.payload, |
254 | &status_buffer->payload, rec->u.status.payload_size); | |
8a36e453 MS |
255 | } |
256 | ||
5771710b SS |
257 | debug_event(dbf->hba, level, rec, sizeof(*rec)); |
258 | spin_unlock_irqrestore(&dbf->hba_lock, flags); | |
8a36e453 MS |
259 | } |
260 | ||
bfab1637 | 261 | /** |
5771710b | 262 | * zfcp_dbf_hba_qdio - trace event for QDIO related failure |
564e1c86 | 263 | * @qdio: qdio structure affected by this QDIO related event |
bfab1637 | 264 | * @qdio_error: as passed by qdio module |
bfab1637 MP |
265 | * @sbal_index: first buffer with error condition, as passed by qdio module |
266 | * @sbal_count: number of buffers affected, as passed by qdio module | |
267 | */ | |
5771710b SS |
268 | void zfcp_dbf_hba_qdio(struct zfcp_dbf *dbf, unsigned int qdio_error, |
269 | int sbal_index, int sbal_count) | |
8a36e453 | 270 | { |
5771710b | 271 | struct zfcp_dbf_hba_record *r = &dbf->hba_buf; |
8a36e453 MS |
272 | unsigned long flags; |
273 | ||
5771710b | 274 | spin_lock_irqsave(&dbf->hba_lock, flags); |
6bc473dd MP |
275 | memset(r, 0, sizeof(*r)); |
276 | strncpy(r->tag, "qdio", ZFCP_DBF_TAG_SIZE); | |
6bc473dd | 277 | r->u.qdio.qdio_error = qdio_error; |
6bc473dd MP |
278 | r->u.qdio.sbal_index = sbal_index; |
279 | r->u.qdio.sbal_count = sbal_count; | |
5771710b SS |
280 | debug_event(dbf->hba, 0, r, sizeof(*r)); |
281 | spin_unlock_irqrestore(&dbf->hba_lock, flags); | |
8a36e453 MS |
282 | } |
283 | ||
57069386 | 284 | /** |
5771710b SS |
285 | * zfcp_dbf_hba_berr - trace event for bit error threshold |
286 | * @dbf: dbf structure affected by this QDIO related event | |
57069386 SS |
287 | * @req: fsf request |
288 | */ | |
5771710b | 289 | void zfcp_dbf_hba_berr(struct zfcp_dbf *dbf, struct zfcp_fsf_req *req) |
57069386 | 290 | { |
5771710b | 291 | struct zfcp_dbf_hba_record *r = &dbf->hba_buf; |
57069386 SS |
292 | struct fsf_status_read_buffer *sr_buf = req->data; |
293 | struct fsf_bit_error_payload *err = &sr_buf->payload.bit_error; | |
294 | unsigned long flags; | |
295 | ||
5771710b | 296 | spin_lock_irqsave(&dbf->hba_lock, flags); |
57069386 SS |
297 | memset(r, 0, sizeof(*r)); |
298 | strncpy(r->tag, "berr", ZFCP_DBF_TAG_SIZE); | |
299 | memcpy(&r->u.berr, err, sizeof(struct fsf_bit_error_payload)); | |
5771710b SS |
300 | debug_event(dbf->hba, 0, r, sizeof(*r)); |
301 | spin_unlock_irqrestore(&dbf->hba_lock, flags); | |
57069386 | 302 | } |
5771710b SS |
303 | static void zfcp_dbf_hba_view_response(char **p, |
304 | struct zfcp_dbf_hba_record_response *r) | |
8a36e453 | 305 | { |
8fc5af16 | 306 | struct timespec t; |
8a36e453 | 307 | |
a9c85775 MP |
308 | zfcp_dbf_out(p, "fsf_command", "0x%08x", r->fsf_command); |
309 | zfcp_dbf_out(p, "fsf_reqid", "0x%0Lx", r->fsf_reqid); | |
310 | zfcp_dbf_out(p, "fsf_seqno", "0x%08x", r->fsf_seqno); | |
b592e89a | 311 | stck_to_timespec(r->fsf_issued, &t); |
a9c85775 MP |
312 | zfcp_dbf_out(p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec); |
313 | zfcp_dbf_out(p, "fsf_prot_status", "0x%08x", r->fsf_prot_status); | |
314 | zfcp_dbf_out(p, "fsf_status", "0x%08x", r->fsf_status); | |
315 | zfcp_dbf_outd(p, "fsf_prot_status_qual", r->fsf_prot_status_qual, | |
df29f4ac | 316 | FSF_PROT_STATUS_QUAL_SIZE, 0, FSF_PROT_STATUS_QUAL_SIZE); |
a9c85775 | 317 | zfcp_dbf_outd(p, "fsf_status_qual", r->fsf_status_qual, |
df29f4ac | 318 | FSF_STATUS_QUALIFIER_SIZE, 0, FSF_STATUS_QUALIFIER_SIZE); |
a9c85775 MP |
319 | zfcp_dbf_out(p, "fsf_req_status", "0x%08x", r->fsf_req_status); |
320 | zfcp_dbf_out(p, "sbal_first", "0x%02x", r->sbal_first); | |
e891bffe | 321 | zfcp_dbf_out(p, "sbal_last", "0x%02x", r->sbal_last); |
c3baa9a2 | 322 | zfcp_dbf_out(p, "sbal_response", "0x%02x", r->sbal_response); |
a9c85775 | 323 | zfcp_dbf_out(p, "pool", "0x%02x", r->pool); |
b634fff7 MP |
324 | |
325 | switch (r->fsf_command) { | |
8a36e453 | 326 | case FSF_QTCB_FCP_CMND: |
b634fff7 | 327 | if (r->fsf_req_status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) |
8a36e453 | 328 | break; |
6bc473dd MP |
329 | zfcp_dbf_out(p, "scsi_cmnd", "0x%0Lx", r->u.fcp.cmnd); |
330 | zfcp_dbf_out(p, "scsi_serial", "0x%016Lx", r->u.fcp.serial); | |
5a3fb308 | 331 | *p += sprintf(*p, "\n"); |
8a36e453 MS |
332 | break; |
333 | ||
334 | case FSF_QTCB_OPEN_PORT_WITH_DID: | |
335 | case FSF_QTCB_CLOSE_PORT: | |
336 | case FSF_QTCB_CLOSE_PHYSICAL_PORT: | |
6bc473dd MP |
337 | zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->u.port.wwpn); |
338 | zfcp_dbf_out(p, "d_id", "0x%06x", r->u.port.d_id); | |
339 | zfcp_dbf_out(p, "port_handle", "0x%08x", r->u.port.port_handle); | |
8a36e453 MS |
340 | break; |
341 | ||
342 | case FSF_QTCB_OPEN_LUN: | |
343 | case FSF_QTCB_CLOSE_LUN: | |
6bc473dd MP |
344 | zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->u.unit.wwpn); |
345 | zfcp_dbf_out(p, "fcp_lun", "0x%016Lx", r->u.unit.fcp_lun); | |
346 | zfcp_dbf_out(p, "port_handle", "0x%08x", r->u.unit.port_handle); | |
347 | zfcp_dbf_out(p, "lun_handle", "0x%08x", r->u.unit.lun_handle); | |
8a36e453 MS |
348 | break; |
349 | ||
350 | case FSF_QTCB_SEND_ELS: | |
6bc473dd | 351 | zfcp_dbf_out(p, "d_id", "0x%06x", r->u.els.d_id); |
8a36e453 MS |
352 | break; |
353 | ||
354 | case FSF_QTCB_ABORT_FCP_CMND: | |
355 | case FSF_QTCB_SEND_GENERIC: | |
356 | case FSF_QTCB_EXCHANGE_CONFIG_DATA: | |
357 | case FSF_QTCB_EXCHANGE_PORT_DATA: | |
358 | case FSF_QTCB_DOWNLOAD_CONTROL_FILE: | |
359 | case FSF_QTCB_UPLOAD_CONTROL_FILE: | |
360 | break; | |
361 | } | |
8a36e453 MS |
362 | } |
363 | ||
5771710b SS |
364 | static void zfcp_dbf_hba_view_status(char **p, |
365 | struct zfcp_dbf_hba_record_status *r) | |
8a36e453 | 366 | { |
a9c85775 MP |
367 | zfcp_dbf_out(p, "failed", "0x%02x", r->failed); |
368 | zfcp_dbf_out(p, "status_type", "0x%08x", r->status_type); | |
369 | zfcp_dbf_out(p, "status_subtype", "0x%08x", r->status_subtype); | |
370 | zfcp_dbf_outd(p, "queue_designator", (char *)&r->queue_designator, | |
df29f4ac MP |
371 | sizeof(struct fsf_queue_designator), 0, |
372 | sizeof(struct fsf_queue_designator)); | |
a9c85775 | 373 | zfcp_dbf_outd(p, "payload", (char *)&r->payload, r->payload_size, 0, |
df29f4ac | 374 | r->payload_size); |
8a36e453 MS |
375 | } |
376 | ||
5771710b | 377 | static void zfcp_dbf_hba_view_qdio(char **p, struct zfcp_dbf_hba_record_qdio *r) |
8a36e453 | 378 | { |
a9c85775 | 379 | zfcp_dbf_out(p, "qdio_error", "0x%08x", r->qdio_error); |
a9c85775 MP |
380 | zfcp_dbf_out(p, "sbal_index", "0x%02x", r->sbal_index); |
381 | zfcp_dbf_out(p, "sbal_count", "0x%02x", r->sbal_count); | |
8a36e453 MS |
382 | } |
383 | ||
5771710b | 384 | static void zfcp_dbf_hba_view_berr(char **p, struct fsf_bit_error_payload *r) |
57069386 SS |
385 | { |
386 | zfcp_dbf_out(p, "link_failures", "%d", r->link_failure_error_count); | |
387 | zfcp_dbf_out(p, "loss_of_sync_err", "%d", r->loss_of_sync_error_count); | |
388 | zfcp_dbf_out(p, "loss_of_sig_err", "%d", r->loss_of_signal_error_count); | |
389 | zfcp_dbf_out(p, "prim_seq_err", "%d", | |
390 | r->primitive_sequence_error_count); | |
391 | zfcp_dbf_out(p, "inval_trans_word_err", "%d", | |
392 | r->invalid_transmission_word_error_count); | |
393 | zfcp_dbf_out(p, "CRC_errors", "%d", r->crc_error_count); | |
394 | zfcp_dbf_out(p, "prim_seq_event_to", "%d", | |
395 | r->primitive_sequence_event_timeout_count); | |
396 | zfcp_dbf_out(p, "elast_buf_overrun_err", "%d", | |
397 | r->elastic_buffer_overrun_error_count); | |
398 | zfcp_dbf_out(p, "adv_rec_buf2buf_cred", "%d", | |
399 | r->advertised_receive_b2b_credit); | |
400 | zfcp_dbf_out(p, "curr_rec_buf2buf_cred", "%d", | |
401 | r->current_receive_b2b_credit); | |
402 | zfcp_dbf_out(p, "adv_trans_buf2buf_cred", "%d", | |
403 | r->advertised_transmit_b2b_credit); | |
404 | zfcp_dbf_out(p, "curr_trans_buf2buf_cred", "%d", | |
405 | r->current_transmit_b2b_credit); | |
406 | } | |
407 | ||
5771710b | 408 | static int zfcp_dbf_hba_view_format(debug_info_t *id, struct debug_view *view, |
a9c85775 | 409 | char *out_buf, const char *in_buf) |
8a36e453 | 410 | { |
5771710b | 411 | struct zfcp_dbf_hba_record *r = (struct zfcp_dbf_hba_record *)in_buf; |
a9c85775 | 412 | char *p = out_buf; |
8a36e453 | 413 | |
a9c85775 | 414 | if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0) |
8a36e453 MS |
415 | return 0; |
416 | ||
a9c85775 MP |
417 | zfcp_dbf_tag(&p, "tag", r->tag); |
418 | if (isalpha(r->tag2[0])) | |
419 | zfcp_dbf_tag(&p, "tag2", r->tag2); | |
420 | ||
421 | if (strncmp(r->tag, "resp", ZFCP_DBF_TAG_SIZE) == 0) | |
5771710b | 422 | zfcp_dbf_hba_view_response(&p, &r->u.response); |
a9c85775 | 423 | else if (strncmp(r->tag, "stat", ZFCP_DBF_TAG_SIZE) == 0) |
5771710b | 424 | zfcp_dbf_hba_view_status(&p, &r->u.status); |
a9c85775 | 425 | else if (strncmp(r->tag, "qdio", ZFCP_DBF_TAG_SIZE) == 0) |
5771710b | 426 | zfcp_dbf_hba_view_qdio(&p, &r->u.qdio); |
57069386 | 427 | else if (strncmp(r->tag, "berr", ZFCP_DBF_TAG_SIZE) == 0) |
5771710b | 428 | zfcp_dbf_hba_view_berr(&p, &r->u.berr); |
a9c85775 | 429 | |
d94ce6c6 CS |
430 | if (strncmp(r->tag, "resp", ZFCP_DBF_TAG_SIZE) != 0) |
431 | p += sprintf(p, "\n"); | |
a9c85775 | 432 | return p - out_buf; |
8a36e453 MS |
433 | } |
434 | ||
5771710b SS |
435 | static struct debug_view zfcp_dbf_hba_view = { |
436 | .name = "structured", | |
437 | .header_proc = zfcp_dbf_view_header, | |
438 | .format_proc = zfcp_dbf_hba_view_format, | |
8a36e453 MS |
439 | }; |
440 | ||
5771710b | 441 | static const char *zfcp_dbf_rec_tags[] = { |
348447e8 | 442 | [ZFCP_REC_DBF_ID_THREAD] = "thread", |
698ec016 | 443 | [ZFCP_REC_DBF_ID_TARGET] = "target", |
9467a9b3 | 444 | [ZFCP_REC_DBF_ID_TRIGGER] = "trigger", |
6f4f365e | 445 | [ZFCP_REC_DBF_ID_ACTION] = "action", |
d79a83db MP |
446 | }; |
447 | ||
5771710b | 448 | static int zfcp_dbf_rec_view_format(debug_info_t *id, struct debug_view *view, |
d79a83db MP |
449 | char *buf, const char *_rec) |
450 | { | |
5771710b | 451 | struct zfcp_dbf_rec_record *r = (struct zfcp_dbf_rec_record *)_rec; |
d79a83db | 452 | char *p = buf; |
5ffd51a5 | 453 | char hint[ZFCP_DBF_ID_SIZE + 1]; |
d79a83db | 454 | |
5ffd51a5 SS |
455 | memcpy(hint, r->id2, ZFCP_DBF_ID_SIZE); |
456 | hint[ZFCP_DBF_ID_SIZE] = 0; | |
5771710b | 457 | zfcp_dbf_outs(&p, "tag", zfcp_dbf_rec_tags[r->id]); |
5ffd51a5 | 458 | zfcp_dbf_outs(&p, "hint", hint); |
d79a83db | 459 | switch (r->id) { |
348447e8 | 460 | case ZFCP_REC_DBF_ID_THREAD: |
348447e8 MP |
461 | zfcp_dbf_out(&p, "total", "%d", r->u.thread.total); |
462 | zfcp_dbf_out(&p, "ready", "%d", r->u.thread.ready); | |
463 | zfcp_dbf_out(&p, "running", "%d", r->u.thread.running); | |
464 | break; | |
698ec016 MP |
465 | case ZFCP_REC_DBF_ID_TARGET: |
466 | zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.target.ref); | |
467 | zfcp_dbf_out(&p, "status", "0x%08x", r->u.target.status); | |
468 | zfcp_dbf_out(&p, "erp_count", "%d", r->u.target.erp_count); | |
469 | zfcp_dbf_out(&p, "d_id", "0x%06x", r->u.target.d_id); | |
470 | zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.target.wwpn); | |
471 | zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.target.fcp_lun); | |
472 | break; | |
9467a9b3 MP |
473 | case ZFCP_REC_DBF_ID_TRIGGER: |
474 | zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.trigger.ref); | |
475 | zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.trigger.action); | |
476 | zfcp_dbf_out(&p, "requested", "%d", r->u.trigger.want); | |
477 | zfcp_dbf_out(&p, "executed", "%d", r->u.trigger.need); | |
478 | zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.trigger.wwpn); | |
479 | zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.trigger.fcp_lun); | |
480 | zfcp_dbf_out(&p, "adapter_status", "0x%08x", r->u.trigger.as); | |
481 | zfcp_dbf_out(&p, "port_status", "0x%08x", r->u.trigger.ps); | |
482 | zfcp_dbf_out(&p, "unit_status", "0x%08x", r->u.trigger.us); | |
483 | break; | |
6f4f365e MP |
484 | case ZFCP_REC_DBF_ID_ACTION: |
485 | zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.action.action); | |
486 | zfcp_dbf_out(&p, "fsf_req", "0x%016Lx", r->u.action.fsf_req); | |
487 | zfcp_dbf_out(&p, "status", "0x%08Lx", r->u.action.status); | |
488 | zfcp_dbf_out(&p, "step", "0x%08Lx", r->u.action.step); | |
489 | break; | |
d79a83db | 490 | } |
b634fff7 MP |
491 | p += sprintf(p, "\n"); |
492 | return p - buf; | |
d79a83db MP |
493 | } |
494 | ||
5771710b SS |
495 | static struct debug_view zfcp_dbf_rec_view = { |
496 | .name = "structured", | |
497 | .header_proc = zfcp_dbf_view_header, | |
498 | .format_proc = zfcp_dbf_rec_view_format, | |
d79a83db MP |
499 | }; |
500 | ||
348447e8 | 501 | /** |
5771710b | 502 | * zfcp_dbf_rec_thread - trace event related to recovery thread operation |
348447e8 | 503 | * @id2: identifier for event |
5771710b | 504 | * @dbf: reference to dbf structure |
aa0fec62 | 505 | * This function assumes that the caller is holding erp_lock. |
348447e8 | 506 | */ |
5771710b | 507 | void zfcp_dbf_rec_thread(char *id2, struct zfcp_dbf *dbf) |
348447e8 | 508 | { |
5771710b SS |
509 | struct zfcp_adapter *adapter = dbf->adapter; |
510 | struct zfcp_dbf_rec_record *r = &dbf->rec_buf; | |
348447e8 MP |
511 | unsigned long flags = 0; |
512 | struct list_head *entry; | |
513 | unsigned ready = 0, running = 0, total; | |
514 | ||
348447e8 MP |
515 | list_for_each(entry, &adapter->erp_ready_head) |
516 | ready++; | |
517 | list_for_each(entry, &adapter->erp_running_head) | |
518 | running++; | |
519 | total = adapter->erp_total_count; | |
348447e8 | 520 | |
5771710b | 521 | spin_lock_irqsave(&dbf->rec_lock, flags); |
348447e8 MP |
522 | memset(r, 0, sizeof(*r)); |
523 | r->id = ZFCP_REC_DBF_ID_THREAD; | |
5ffd51a5 | 524 | memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE); |
348447e8 MP |
525 | r->u.thread.total = total; |
526 | r->u.thread.ready = ready; | |
527 | r->u.thread.running = running; | |
5771710b SS |
528 | debug_event(dbf->rec, 6, r, sizeof(*r)); |
529 | spin_unlock_irqrestore(&dbf->rec_lock, flags); | |
348447e8 MP |
530 | } |
531 | ||
aa0fec62 | 532 | /** |
5771710b | 533 | * zfcp_dbf_rec_thread - trace event related to recovery thread operation |
aa0fec62 CS |
534 | * @id2: identifier for event |
535 | * @adapter: adapter | |
536 | * This function assumes that the caller does not hold erp_lock. | |
537 | */ | |
5771710b | 538 | void zfcp_dbf_rec_thread_lock(char *id2, struct zfcp_dbf *dbf) |
aa0fec62 | 539 | { |
5771710b | 540 | struct zfcp_adapter *adapter = dbf->adapter; |
aa0fec62 CS |
541 | unsigned long flags; |
542 | ||
543 | read_lock_irqsave(&adapter->erp_lock, flags); | |
5771710b | 544 | zfcp_dbf_rec_thread(id2, dbf); |
aa0fec62 CS |
545 | read_unlock_irqrestore(&adapter->erp_lock, flags); |
546 | } | |
547 | ||
5771710b SS |
548 | static void zfcp_dbf_rec_target(char *id2, void *ref, struct zfcp_dbf *dbf, |
549 | atomic_t *status, atomic_t *erp_count, u64 wwpn, | |
550 | u32 d_id, u64 fcp_lun) | |
698ec016 | 551 | { |
5771710b | 552 | struct zfcp_dbf_rec_record *r = &dbf->rec_buf; |
698ec016 MP |
553 | unsigned long flags; |
554 | ||
5771710b | 555 | spin_lock_irqsave(&dbf->rec_lock, flags); |
698ec016 MP |
556 | memset(r, 0, sizeof(*r)); |
557 | r->id = ZFCP_REC_DBF_ID_TARGET; | |
5ffd51a5 | 558 | memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE); |
1f6f7129 | 559 | r->u.target.ref = (unsigned long)ref; |
698ec016 MP |
560 | r->u.target.status = atomic_read(status); |
561 | r->u.target.wwpn = wwpn; | |
562 | r->u.target.d_id = d_id; | |
563 | r->u.target.fcp_lun = fcp_lun; | |
564 | r->u.target.erp_count = atomic_read(erp_count); | |
5771710b SS |
565 | debug_event(dbf->rec, 3, r, sizeof(*r)); |
566 | spin_unlock_irqrestore(&dbf->rec_lock, flags); | |
698ec016 MP |
567 | } |
568 | ||
569 | /** | |
5771710b | 570 | * zfcp_dbf_rec_adapter - trace event for adapter state change |
698ec016 MP |
571 | * @id: identifier for trigger of state change |
572 | * @ref: additional reference (e.g. request) | |
5771710b | 573 | * @dbf: reference to dbf structure |
698ec016 | 574 | */ |
5771710b | 575 | void zfcp_dbf_rec_adapter(char *id, void *ref, struct zfcp_dbf *dbf) |
698ec016 | 576 | { |
5771710b SS |
577 | struct zfcp_adapter *adapter = dbf->adapter; |
578 | ||
579 | zfcp_dbf_rec_target(id, ref, dbf, &adapter->status, | |
d21e9daa CS |
580 | &adapter->erp_counter, 0, 0, |
581 | ZFCP_DBF_INVALID_LUN); | |
698ec016 MP |
582 | } |
583 | ||
584 | /** | |
5771710b | 585 | * zfcp_dbf_rec_port - trace event for port state change |
698ec016 MP |
586 | * @id: identifier for trigger of state change |
587 | * @ref: additional reference (e.g. request) | |
588 | * @port: port | |
589 | */ | |
5771710b | 590 | void zfcp_dbf_rec_port(char *id, void *ref, struct zfcp_port *port) |
698ec016 | 591 | { |
5771710b | 592 | struct zfcp_dbf *dbf = port->adapter->dbf; |
698ec016 | 593 | |
5771710b | 594 | zfcp_dbf_rec_target(id, ref, dbf, &port->status, |
d21e9daa CS |
595 | &port->erp_counter, port->wwpn, port->d_id, |
596 | ZFCP_DBF_INVALID_LUN); | |
698ec016 MP |
597 | } |
598 | ||
599 | /** | |
5771710b | 600 | * zfcp_dbf_rec_unit - trace event for unit state change |
698ec016 MP |
601 | * @id: identifier for trigger of state change |
602 | * @ref: additional reference (e.g. request) | |
603 | * @unit: unit | |
604 | */ | |
5771710b | 605 | void zfcp_dbf_rec_unit(char *id, void *ref, struct zfcp_unit *unit) |
698ec016 MP |
606 | { |
607 | struct zfcp_port *port = unit->port; | |
5771710b | 608 | struct zfcp_dbf *dbf = port->adapter->dbf; |
698ec016 | 609 | |
5771710b | 610 | zfcp_dbf_rec_target(id, ref, dbf, &unit->status, |
698ec016 MP |
611 | &unit->erp_counter, port->wwpn, port->d_id, |
612 | unit->fcp_lun); | |
613 | } | |
614 | ||
9467a9b3 | 615 | /** |
5771710b | 616 | * zfcp_dbf_rec_trigger - trace event for triggered error recovery |
9467a9b3 MP |
617 | * @id2: identifier for error recovery trigger |
618 | * @ref: additional reference (e.g. request) | |
619 | * @want: originally requested error recovery action | |
620 | * @need: error recovery action actually initiated | |
621 | * @action: address of error recovery action struct | |
622 | * @adapter: adapter | |
623 | * @port: port | |
624 | * @unit: unit | |
625 | */ | |
5771710b SS |
626 | void zfcp_dbf_rec_trigger(char *id2, void *ref, u8 want, u8 need, void *action, |
627 | struct zfcp_adapter *adapter, struct zfcp_port *port, | |
628 | struct zfcp_unit *unit) | |
9467a9b3 | 629 | { |
d46f384a | 630 | struct zfcp_dbf *dbf = adapter->dbf; |
5771710b | 631 | struct zfcp_dbf_rec_record *r = &dbf->rec_buf; |
9467a9b3 MP |
632 | unsigned long flags; |
633 | ||
5771710b | 634 | spin_lock_irqsave(&dbf->rec_lock, flags); |
9467a9b3 MP |
635 | memset(r, 0, sizeof(*r)); |
636 | r->id = ZFCP_REC_DBF_ID_TRIGGER; | |
5ffd51a5 | 637 | memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE); |
1f6f7129 | 638 | r->u.trigger.ref = (unsigned long)ref; |
9467a9b3 MP |
639 | r->u.trigger.want = want; |
640 | r->u.trigger.need = need; | |
1f6f7129 | 641 | r->u.trigger.action = (unsigned long)action; |
9467a9b3 MP |
642 | r->u.trigger.as = atomic_read(&adapter->status); |
643 | if (port) { | |
644 | r->u.trigger.ps = atomic_read(&port->status); | |
645 | r->u.trigger.wwpn = port->wwpn; | |
646 | } | |
d21e9daa | 647 | if (unit) |
9467a9b3 | 648 | r->u.trigger.us = atomic_read(&unit->status); |
d21e9daa | 649 | r->u.trigger.fcp_lun = unit ? unit->fcp_lun : ZFCP_DBF_INVALID_LUN; |
5771710b SS |
650 | debug_event(dbf->rec, action ? 1 : 4, r, sizeof(*r)); |
651 | spin_unlock_irqrestore(&dbf->rec_lock, flags); | |
9467a9b3 MP |
652 | } |
653 | ||
6f4f365e | 654 | /** |
5771710b | 655 | * zfcp_dbf_rec_action - trace event showing progress of recovery action |
6f4f365e MP |
656 | * @id2: identifier |
657 | * @erp_action: error recovery action struct pointer | |
658 | */ | |
5771710b | 659 | void zfcp_dbf_rec_action(char *id2, struct zfcp_erp_action *erp_action) |
6f4f365e | 660 | { |
5771710b SS |
661 | struct zfcp_dbf *dbf = erp_action->adapter->dbf; |
662 | struct zfcp_dbf_rec_record *r = &dbf->rec_buf; | |
6f4f365e MP |
663 | unsigned long flags; |
664 | ||
5771710b | 665 | spin_lock_irqsave(&dbf->rec_lock, flags); |
6f4f365e MP |
666 | memset(r, 0, sizeof(*r)); |
667 | r->id = ZFCP_REC_DBF_ID_ACTION; | |
5ffd51a5 | 668 | memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE); |
1f6f7129 | 669 | r->u.action.action = (unsigned long)erp_action; |
6f4f365e MP |
670 | r->u.action.status = erp_action->status; |
671 | r->u.action.step = erp_action->step; | |
e60a6d69 | 672 | r->u.action.fsf_req = erp_action->fsf_req_id; |
5771710b SS |
673 | debug_event(dbf->rec, 5, r, sizeof(*r)); |
674 | spin_unlock_irqrestore(&dbf->rec_lock, flags); | |
6f4f365e MP |
675 | } |
676 | ||
bfab1637 | 677 | /** |
5771710b | 678 | * zfcp_dbf_san_ct_request - trace event for issued CT request |
bfab1637 | 679 | * @fsf_req: request containing issued CT data |
7c7dc196 | 680 | * @d_id: destination id where ct request is sent to |
bfab1637 | 681 | */ |
7c7dc196 | 682 | void zfcp_dbf_san_ct_request(struct zfcp_fsf_req *fsf_req, u32 d_id) |
8a36e453 | 683 | { |
7c7dc196 CS |
684 | struct zfcp_fsf_ct_els *ct = (struct zfcp_fsf_ct_els *)fsf_req->data; |
685 | struct zfcp_adapter *adapter = fsf_req->adapter; | |
d46f384a | 686 | struct zfcp_dbf *dbf = adapter->dbf; |
dbf5dfe9 | 687 | struct fc_ct_hdr *hdr = sg_virt(ct->req); |
5771710b SS |
688 | struct zfcp_dbf_san_record *r = &dbf->san_buf; |
689 | struct zfcp_dbf_san_record_ct_request *oct = &r->u.ct_req; | |
d94ce6c6 | 690 | int level = 3; |
6bc473dd | 691 | unsigned long flags; |
8a36e453 | 692 | |
5771710b | 693 | spin_lock_irqsave(&dbf->san_lock, flags); |
6bc473dd MP |
694 | memset(r, 0, sizeof(*r)); |
695 | strncpy(r->tag, "octc", ZFCP_DBF_TAG_SIZE); | |
f0216ae9 | 696 | r->fsf_reqid = fsf_req->req_id; |
6bc473dd | 697 | r->fsf_seqno = fsf_req->seq_no; |
7c7dc196 | 698 | oct->d_id = d_id; |
dbf5dfe9 CS |
699 | oct->cmd_req_code = hdr->ct_cmd; |
700 | oct->revision = hdr->ct_rev; | |
701 | oct->gs_type = hdr->ct_fs_type; | |
702 | oct->gs_subtype = hdr->ct_fs_subtype; | |
703 | oct->options = hdr->ct_options; | |
704 | oct->max_res_size = hdr->ct_mr_size; | |
705 | oct->len = min((int)ct->req->length - (int)sizeof(struct fc_ct_hdr), | |
d94ce6c6 | 706 | ZFCP_DBF_SAN_MAX_PAYLOAD); |
5771710b SS |
707 | debug_event(dbf->san, level, r, sizeof(*r)); |
708 | zfcp_dbf_hexdump(dbf->san, r, sizeof(*r), level, | |
dbf5dfe9 | 709 | (void *)hdr + sizeof(struct fc_ct_hdr), oct->len); |
5771710b | 710 | spin_unlock_irqrestore(&dbf->san_lock, flags); |
8a36e453 MS |
711 | } |
712 | ||
bfab1637 | 713 | /** |
5771710b | 714 | * zfcp_dbf_san_ct_response - trace event for completion of CT request |
bfab1637 MP |
715 | * @fsf_req: request containing CT response |
716 | */ | |
5771710b | 717 | void zfcp_dbf_san_ct_response(struct zfcp_fsf_req *fsf_req) |
8a36e453 | 718 | { |
7c7dc196 CS |
719 | struct zfcp_fsf_ct_els *ct = (struct zfcp_fsf_ct_els *)fsf_req->data; |
720 | struct zfcp_adapter *adapter = fsf_req->adapter; | |
dbf5dfe9 | 721 | struct fc_ct_hdr *hdr = sg_virt(ct->resp); |
d46f384a | 722 | struct zfcp_dbf *dbf = adapter->dbf; |
5771710b SS |
723 | struct zfcp_dbf_san_record *r = &dbf->san_buf; |
724 | struct zfcp_dbf_san_record_ct_response *rct = &r->u.ct_resp; | |
d94ce6c6 | 725 | int level = 3; |
6bc473dd | 726 | unsigned long flags; |
8a36e453 | 727 | |
5771710b | 728 | spin_lock_irqsave(&dbf->san_lock, flags); |
6bc473dd MP |
729 | memset(r, 0, sizeof(*r)); |
730 | strncpy(r->tag, "rctc", ZFCP_DBF_TAG_SIZE); | |
f0216ae9 | 731 | r->fsf_reqid = fsf_req->req_id; |
6bc473dd | 732 | r->fsf_seqno = fsf_req->seq_no; |
dbf5dfe9 CS |
733 | rct->cmd_rsp_code = hdr->ct_cmd; |
734 | rct->revision = hdr->ct_rev; | |
735 | rct->reason_code = hdr->ct_reason; | |
736 | rct->expl = hdr->ct_explan; | |
737 | rct->vendor_unique = hdr->ct_vendor; | |
738 | rct->max_res_size = hdr->ct_mr_size; | |
739 | rct->len = min((int)ct->resp->length - (int)sizeof(struct fc_ct_hdr), | |
d94ce6c6 | 740 | ZFCP_DBF_SAN_MAX_PAYLOAD); |
5771710b SS |
741 | debug_event(dbf->san, level, r, sizeof(*r)); |
742 | zfcp_dbf_hexdump(dbf->san, r, sizeof(*r), level, | |
dbf5dfe9 | 743 | (void *)hdr + sizeof(struct fc_ct_hdr), rct->len); |
5771710b | 744 | spin_unlock_irqrestore(&dbf->san_lock, flags); |
8a36e453 MS |
745 | } |
746 | ||
5771710b | 747 | static void zfcp_dbf_san_els(const char *tag, int level, |
7c7dc196 CS |
748 | struct zfcp_fsf_req *fsf_req, u32 d_id, |
749 | void *buffer, int buflen) | |
8a36e453 MS |
750 | { |
751 | struct zfcp_adapter *adapter = fsf_req->adapter; | |
d46f384a | 752 | struct zfcp_dbf *dbf = adapter->dbf; |
5771710b | 753 | struct zfcp_dbf_san_record *rec = &dbf->san_buf; |
8a36e453 | 754 | unsigned long flags; |
8a36e453 | 755 | |
5771710b | 756 | spin_lock_irqsave(&dbf->san_lock, flags); |
6bc473dd | 757 | memset(rec, 0, sizeof(*rec)); |
0f65e951 | 758 | strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE); |
f0216ae9 | 759 | rec->fsf_reqid = fsf_req->req_id; |
0f65e951 | 760 | rec->fsf_seqno = fsf_req->seq_no; |
7c7dc196 | 761 | rec->u.els.d_id = d_id; |
5771710b SS |
762 | debug_event(dbf->san, level, rec, sizeof(*rec)); |
763 | zfcp_dbf_hexdump(dbf->san, rec, sizeof(*rec), level, | |
d94ce6c6 | 764 | buffer, min(buflen, ZFCP_DBF_SAN_MAX_PAYLOAD)); |
5771710b | 765 | spin_unlock_irqrestore(&dbf->san_lock, flags); |
8a36e453 MS |
766 | } |
767 | ||
bfab1637 | 768 | /** |
5771710b | 769 | * zfcp_dbf_san_els_request - trace event for issued ELS |
bfab1637 MP |
770 | * @fsf_req: request containing issued ELS |
771 | */ | |
5771710b | 772 | void zfcp_dbf_san_els_request(struct zfcp_fsf_req *fsf_req) |
8a36e453 | 773 | { |
7c7dc196 CS |
774 | struct zfcp_fsf_ct_els *els = (struct zfcp_fsf_ct_els *)fsf_req->data; |
775 | u32 d_id = ntoh24(fsf_req->qtcb->bottom.support.d_id); | |
8a36e453 | 776 | |
7c7dc196 CS |
777 | zfcp_dbf_san_els("oels", 2, fsf_req, d_id, |
778 | sg_virt(els->req), els->req->length); | |
8a36e453 MS |
779 | } |
780 | ||
bfab1637 | 781 | /** |
5771710b | 782 | * zfcp_dbf_san_els_response - trace event for completed ELS |
bfab1637 MP |
783 | * @fsf_req: request containing ELS response |
784 | */ | |
5771710b | 785 | void zfcp_dbf_san_els_response(struct zfcp_fsf_req *fsf_req) |
8a36e453 | 786 | { |
7c7dc196 CS |
787 | struct zfcp_fsf_ct_els *els = (struct zfcp_fsf_ct_els *)fsf_req->data; |
788 | u32 d_id = ntoh24(fsf_req->qtcb->bottom.support.d_id); | |
8a36e453 | 789 | |
7c7dc196 CS |
790 | zfcp_dbf_san_els("rels", 2, fsf_req, d_id, |
791 | sg_virt(els->resp), els->resp->length); | |
8a36e453 MS |
792 | } |
793 | ||
bfab1637 | 794 | /** |
5771710b | 795 | * zfcp_dbf_san_incoming_els - trace event for incomig ELS |
bfab1637 MP |
796 | * @fsf_req: request containing unsolicited status buffer with incoming ELS |
797 | */ | |
5771710b | 798 | void zfcp_dbf_san_incoming_els(struct zfcp_fsf_req *fsf_req) |
8a36e453 | 799 | { |
92c7a83f MP |
800 | struct fsf_status_read_buffer *buf = |
801 | (struct fsf_status_read_buffer *)fsf_req->data; | |
802 | int length = (int)buf->length - | |
803 | (int)((void *)&buf->payload - (void *)buf); | |
804 | ||
800c0cad | 805 | zfcp_dbf_san_els("iels", 1, fsf_req, ntoh24(buf->d_id), |
7c7dc196 | 806 | (void *)buf->payload.data, length); |
8a36e453 MS |
807 | } |
808 | ||
5771710b | 809 | static int zfcp_dbf_san_view_format(debug_info_t *id, struct debug_view *view, |
92c7a83f | 810 | char *out_buf, const char *in_buf) |
8a36e453 | 811 | { |
5771710b | 812 | struct zfcp_dbf_san_record *r = (struct zfcp_dbf_san_record *)in_buf; |
b634fff7 | 813 | char *p = out_buf; |
8a36e453 | 814 | |
b634fff7 | 815 | if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0) |
8a36e453 MS |
816 | return 0; |
817 | ||
a9c85775 | 818 | zfcp_dbf_tag(&p, "tag", r->tag); |
b634fff7 MP |
819 | zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid); |
820 | zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno); | |
b634fff7 MP |
821 | |
822 | if (strncmp(r->tag, "octc", ZFCP_DBF_TAG_SIZE) == 0) { | |
5771710b | 823 | struct zfcp_dbf_san_record_ct_request *ct = &r->u.ct_req; |
7c7dc196 | 824 | zfcp_dbf_out(&p, "d_id", "0x%06x", ct->d_id); |
6bc473dd MP |
825 | zfcp_dbf_out(&p, "cmd_req_code", "0x%04x", ct->cmd_req_code); |
826 | zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision); | |
827 | zfcp_dbf_out(&p, "gs_type", "0x%02x", ct->gs_type); | |
828 | zfcp_dbf_out(&p, "gs_subtype", "0x%02x", ct->gs_subtype); | |
829 | zfcp_dbf_out(&p, "options", "0x%02x", ct->options); | |
830 | zfcp_dbf_out(&p, "max_res_size", "0x%04x", ct->max_res_size); | |
b634fff7 | 831 | } else if (strncmp(r->tag, "rctc", ZFCP_DBF_TAG_SIZE) == 0) { |
5771710b | 832 | struct zfcp_dbf_san_record_ct_response *ct = &r->u.ct_resp; |
6bc473dd MP |
833 | zfcp_dbf_out(&p, "cmd_rsp_code", "0x%04x", ct->cmd_rsp_code); |
834 | zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision); | |
835 | zfcp_dbf_out(&p, "reason_code", "0x%02x", ct->reason_code); | |
836 | zfcp_dbf_out(&p, "reason_code_expl", "0x%02x", ct->expl); | |
837 | zfcp_dbf_out(&p, "vendor_unique", "0x%02x", ct->vendor_unique); | |
39eb7e9a | 838 | zfcp_dbf_out(&p, "max_res_size", "0x%04x", ct->max_res_size); |
b634fff7 MP |
839 | } else if (strncmp(r->tag, "oels", ZFCP_DBF_TAG_SIZE) == 0 || |
840 | strncmp(r->tag, "rels", ZFCP_DBF_TAG_SIZE) == 0 || | |
841 | strncmp(r->tag, "iels", ZFCP_DBF_TAG_SIZE) == 0) { | |
5771710b | 842 | struct zfcp_dbf_san_record_els *els = &r->u.els; |
7c7dc196 | 843 | zfcp_dbf_out(&p, "d_id", "0x%06x", els->d_id); |
8a36e453 | 844 | } |
b634fff7 | 845 | return p - out_buf; |
8a36e453 MS |
846 | } |
847 | ||
5771710b SS |
848 | static struct debug_view zfcp_dbf_san_view = { |
849 | .name = "structured", | |
850 | .header_proc = zfcp_dbf_view_header, | |
851 | .format_proc = zfcp_dbf_san_view_format, | |
8a36e453 MS |
852 | }; |
853 | ||
5771710b SS |
854 | void _zfcp_dbf_scsi(const char *tag, const char *tag2, int level, |
855 | struct zfcp_dbf *dbf, struct scsi_cmnd *scsi_cmnd, | |
856 | struct zfcp_fsf_req *fsf_req, unsigned long old_req_id) | |
8a36e453 | 857 | { |
5771710b | 858 | struct zfcp_dbf_scsi_record *rec = &dbf->scsi_buf; |
8a36e453 MS |
859 | struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)rec; |
860 | unsigned long flags; | |
4318e08c CS |
861 | struct fcp_resp_with_ext *fcp_rsp; |
862 | struct fcp_resp_rsp_info *fcp_rsp_info = NULL; | |
863 | char *fcp_sns_info = NULL; | |
8a36e453 MS |
864 | int offset = 0, buflen = 0; |
865 | ||
5771710b | 866 | spin_lock_irqsave(&dbf->scsi_lock, flags); |
8a36e453 | 867 | do { |
6bc473dd | 868 | memset(rec, 0, sizeof(*rec)); |
8a36e453 MS |
869 | if (offset == 0) { |
870 | strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE); | |
871 | strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE); | |
ed829ad6 MS |
872 | if (scsi_cmnd != NULL) { |
873 | if (scsi_cmnd->device) { | |
874 | rec->scsi_id = scsi_cmnd->device->id; | |
875 | rec->scsi_lun = scsi_cmnd->device->lun; | |
876 | } | |
877 | rec->scsi_result = scsi_cmnd->result; | |
878 | rec->scsi_cmnd = (unsigned long)scsi_cmnd; | |
879 | rec->scsi_serial = scsi_cmnd->serial_number; | |
64a87b24 | 880 | memcpy(rec->scsi_opcode, scsi_cmnd->cmnd, |
ed829ad6 MS |
881 | min((int)scsi_cmnd->cmd_len, |
882 | ZFCP_DBF_SCSI_OPCODE)); | |
883 | rec->scsi_retries = scsi_cmnd->retries; | |
884 | rec->scsi_allowed = scsi_cmnd->allowed; | |
8a36e453 | 885 | } |
8a36e453 | 886 | if (fsf_req != NULL) { |
4318e08c CS |
887 | fcp_rsp = (struct fcp_resp_with_ext *) |
888 | &(fsf_req->qtcb->bottom.io.fcp_rsp); | |
889 | fcp_rsp_info = (struct fcp_resp_rsp_info *) | |
890 | &fcp_rsp[1]; | |
891 | fcp_sns_info = (char *) &fcp_rsp[1]; | |
892 | if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL) | |
893 | fcp_sns_info += fcp_rsp->ext.fr_sns_len; | |
894 | ||
895 | rec->rsp_validity = fcp_rsp->resp.fr_flags; | |
896 | rec->rsp_scsi_status = fcp_rsp->resp.fr_status; | |
897 | rec->rsp_resid = fcp_rsp->ext.fr_resid; | |
898 | if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL) | |
899 | rec->rsp_code = fcp_rsp_info->rsp_code; | |
900 | if (fcp_rsp->resp.fr_flags & FCP_SNS_LEN_VAL) { | |
901 | buflen = min(fcp_rsp->ext.fr_sns_len, | |
902 | (u32)ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO); | |
6bc473dd MP |
903 | rec->sns_info_len = buflen; |
904 | memcpy(rec->sns_info, fcp_sns_info, | |
8a36e453 MS |
905 | min(buflen, |
906 | ZFCP_DBF_SCSI_FCP_SNS_INFO)); | |
907 | offset += min(buflen, | |
908 | ZFCP_DBF_SCSI_FCP_SNS_INFO); | |
909 | } | |
910 | ||
f0216ae9 | 911 | rec->fsf_reqid = fsf_req->req_id; |
8a36e453 MS |
912 | rec->fsf_seqno = fsf_req->seq_no; |
913 | rec->fsf_issued = fsf_req->issued; | |
914 | } | |
6bc473dd | 915 | rec->old_fsf_reqid = old_req_id; |
8a36e453 MS |
916 | } else { |
917 | strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE); | |
918 | dump->total_size = buflen; | |
919 | dump->offset = offset; | |
920 | dump->size = min(buflen - offset, | |
921 | (int)sizeof(struct | |
5771710b | 922 | zfcp_dbf_scsi_record) - |
8a36e453 MS |
923 | (int)sizeof(struct zfcp_dbf_dump)); |
924 | memcpy(dump->data, fcp_sns_info + offset, dump->size); | |
925 | offset += dump->size; | |
926 | } | |
5771710b | 927 | debug_event(dbf->scsi, level, rec, sizeof(*rec)); |
8a36e453 | 928 | } while (offset < buflen); |
5771710b | 929 | spin_unlock_irqrestore(&dbf->scsi_lock, flags); |
8a36e453 MS |
930 | } |
931 | ||
5771710b | 932 | static int zfcp_dbf_scsi_view_format(debug_info_t *id, struct debug_view *view, |
92c7a83f | 933 | char *out_buf, const char *in_buf) |
8a36e453 | 934 | { |
5771710b | 935 | struct zfcp_dbf_scsi_record *r = (struct zfcp_dbf_scsi_record *)in_buf; |
8fc5af16 | 936 | struct timespec t; |
b634fff7 | 937 | char *p = out_buf; |
8a36e453 | 938 | |
b634fff7 | 939 | if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0) |
8a36e453 MS |
940 | return 0; |
941 | ||
a9c85775 MP |
942 | zfcp_dbf_tag(&p, "tag", r->tag); |
943 | zfcp_dbf_tag(&p, "tag2", r->tag2); | |
b634fff7 MP |
944 | zfcp_dbf_out(&p, "scsi_id", "0x%08x", r->scsi_id); |
945 | zfcp_dbf_out(&p, "scsi_lun", "0x%08x", r->scsi_lun); | |
946 | zfcp_dbf_out(&p, "scsi_result", "0x%08x", r->scsi_result); | |
947 | zfcp_dbf_out(&p, "scsi_cmnd", "0x%0Lx", r->scsi_cmnd); | |
948 | zfcp_dbf_out(&p, "scsi_serial", "0x%016Lx", r->scsi_serial); | |
df29f4ac MP |
949 | zfcp_dbf_outd(&p, "scsi_opcode", r->scsi_opcode, ZFCP_DBF_SCSI_OPCODE, |
950 | 0, ZFCP_DBF_SCSI_OPCODE); | |
b634fff7 MP |
951 | zfcp_dbf_out(&p, "scsi_retries", "0x%02x", r->scsi_retries); |
952 | zfcp_dbf_out(&p, "scsi_allowed", "0x%02x", r->scsi_allowed); | |
953 | if (strncmp(r->tag, "abrt", ZFCP_DBF_TAG_SIZE) == 0) | |
6bc473dd | 954 | zfcp_dbf_out(&p, "old_fsf_reqid", "0x%0Lx", r->old_fsf_reqid); |
b634fff7 MP |
955 | zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid); |
956 | zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno); | |
b592e89a | 957 | stck_to_timespec(r->fsf_issued, &t); |
b634fff7 MP |
958 | zfcp_dbf_out(&p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec); |
959 | ||
960 | if (strncmp(r->tag, "rslt", ZFCP_DBF_TAG_SIZE) == 0) { | |
6bc473dd MP |
961 | zfcp_dbf_out(&p, "fcp_rsp_validity", "0x%02x", r->rsp_validity); |
962 | zfcp_dbf_out(&p, "fcp_rsp_scsi_status", "0x%02x", | |
963 | r->rsp_scsi_status); | |
964 | zfcp_dbf_out(&p, "fcp_rsp_resid", "0x%08x", r->rsp_resid); | |
965 | zfcp_dbf_out(&p, "fcp_rsp_code", "0x%08x", r->rsp_code); | |
966 | zfcp_dbf_out(&p, "fcp_sns_info_len", "0x%08x", r->sns_info_len); | |
967 | zfcp_dbf_outd(&p, "fcp_sns_info", r->sns_info, | |
968 | min((int)r->sns_info_len, | |
df29f4ac | 969 | ZFCP_DBF_SCSI_FCP_SNS_INFO), 0, |
6bc473dd | 970 | r->sns_info_len); |
8a36e453 | 971 | } |
b634fff7 MP |
972 | p += sprintf(p, "\n"); |
973 | return p - out_buf; | |
8a36e453 MS |
974 | } |
975 | ||
5771710b SS |
976 | static struct debug_view zfcp_dbf_scsi_view = { |
977 | .name = "structured", | |
978 | .header_proc = zfcp_dbf_view_header, | |
979 | .format_proc = zfcp_dbf_scsi_view_format, | |
8a36e453 MS |
980 | }; |
981 | ||
d46f384a CS |
982 | static debug_info_t *zfcp_dbf_reg(const char *name, int level, |
983 | struct debug_view *view, int size) | |
984 | { | |
985 | struct debug_info *d; | |
986 | ||
987 | d = debug_register(name, dbfsize, level, size); | |
988 | if (!d) | |
989 | return NULL; | |
990 | ||
991 | debug_register_view(d, &debug_hex_ascii_view); | |
992 | debug_register_view(d, view); | |
993 | debug_set_level(d, level); | |
994 | ||
995 | return d; | |
996 | } | |
997 | ||
8a36e453 MS |
998 | /** |
999 | * zfcp_adapter_debug_register - registers debug feature for an adapter | |
1000 | * @adapter: pointer to adapter for which debug features should be registered | |
1001 | * return: -ENOMEM on error, 0 otherwise | |
1002 | */ | |
5771710b | 1003 | int zfcp_dbf_adapter_register(struct zfcp_adapter *adapter) |
8a36e453 MS |
1004 | { |
1005 | char dbf_name[DEBUG_MAX_NAME_LEN]; | |
d46f384a CS |
1006 | struct zfcp_dbf *dbf; |
1007 | ||
1008 | dbf = kmalloc(sizeof(struct zfcp_dbf), GFP_KERNEL); | |
1009 | if (!dbf) | |
1010 | return -ENOMEM; | |
1011 | ||
5771710b SS |
1012 | dbf->adapter = adapter; |
1013 | ||
1014 | spin_lock_init(&dbf->hba_lock); | |
1015 | spin_lock_init(&dbf->san_lock); | |
1016 | spin_lock_init(&dbf->scsi_lock); | |
1017 | spin_lock_init(&dbf->rec_lock); | |
8a36e453 | 1018 | |
d79a83db | 1019 | /* debug feature area which records recovery activity */ |
b225cf9b | 1020 | sprintf(dbf_name, "zfcp_%s_rec", dev_name(&adapter->ccw_device->dev)); |
5771710b SS |
1021 | dbf->rec = zfcp_dbf_reg(dbf_name, 3, &zfcp_dbf_rec_view, |
1022 | sizeof(struct zfcp_dbf_rec_record)); | |
1023 | if (!dbf->rec) | |
1024 | goto err_out; | |
d79a83db | 1025 | |
8a36e453 | 1026 | /* debug feature area which records HBA (FSF and QDIO) conditions */ |
b225cf9b | 1027 | sprintf(dbf_name, "zfcp_%s_hba", dev_name(&adapter->ccw_device->dev)); |
5771710b SS |
1028 | dbf->hba = zfcp_dbf_reg(dbf_name, 3, &zfcp_dbf_hba_view, |
1029 | sizeof(struct zfcp_dbf_hba_record)); | |
1030 | if (!dbf->hba) | |
1031 | goto err_out; | |
8a36e453 MS |
1032 | |
1033 | /* debug feature area which records SAN command failures and recovery */ | |
b225cf9b | 1034 | sprintf(dbf_name, "zfcp_%s_san", dev_name(&adapter->ccw_device->dev)); |
5771710b SS |
1035 | dbf->san = zfcp_dbf_reg(dbf_name, 6, &zfcp_dbf_san_view, |
1036 | sizeof(struct zfcp_dbf_san_record)); | |
1037 | if (!dbf->san) | |
1038 | goto err_out; | |
8a36e453 MS |
1039 | |
1040 | /* debug feature area which records SCSI command failures and recovery */ | |
b225cf9b | 1041 | sprintf(dbf_name, "zfcp_%s_scsi", dev_name(&adapter->ccw_device->dev)); |
5771710b SS |
1042 | dbf->scsi = zfcp_dbf_reg(dbf_name, 3, &zfcp_dbf_scsi_view, |
1043 | sizeof(struct zfcp_dbf_scsi_record)); | |
1044 | if (!dbf->scsi) | |
1045 | goto err_out; | |
8a36e453 | 1046 | |
d46f384a | 1047 | adapter->dbf = dbf; |
8a36e453 MS |
1048 | return 0; |
1049 | ||
5771710b SS |
1050 | err_out: |
1051 | zfcp_dbf_adapter_unregister(dbf); | |
8a36e453 MS |
1052 | return -ENOMEM; |
1053 | } | |
1054 | ||
1055 | /** | |
1056 | * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter | |
5771710b | 1057 | * @dbf: pointer to dbf for which debug features should be unregistered |
8a36e453 | 1058 | */ |
5771710b | 1059 | void zfcp_dbf_adapter_unregister(struct zfcp_dbf *dbf) |
8a36e453 | 1060 | { |
f3450c7b SS |
1061 | if (!dbf) |
1062 | return; | |
5771710b SS |
1063 | debug_unregister(dbf->scsi); |
1064 | debug_unregister(dbf->san); | |
1065 | debug_unregister(dbf->hba); | |
1066 | debug_unregister(dbf->rec); | |
1067 | dbf->adapter->dbf = NULL; | |
1068 | kfree(dbf); | |
8a36e453 | 1069 | } |
5771710b | 1070 |