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