Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 1 | /* |
Andreas Herrmann | 4a9d2d8 | 2006-05-22 18:14:08 +0200 | [diff] [blame] | 2 | * This file is part of the zfcp device driver for |
| 3 | * FCP adapters for IBM System z9 and zSeries. |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 4 | * |
Andreas Herrmann | 4a9d2d8 | 2006-05-22 18:14:08 +0200 | [diff] [blame] | 5 | * (C) Copyright IBM Corp. 2002, 2006 |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2, or (at your option) |
| 10 | * any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | */ |
| 21 | |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 22 | #include <linux/ctype.h> |
Heiko Carstens | 364c855 | 2007-10-12 16:11:35 +0200 | [diff] [blame] | 23 | #include <asm/debug.h> |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 24 | #include "zfcp_ext.h" |
| 25 | |
| 26 | static u32 dbfsize = 4; |
| 27 | |
| 28 | module_param(dbfsize, uint, 0400); |
| 29 | MODULE_PARM_DESC(dbfsize, |
| 30 | "number of pages for each debug feature area (default 4)"); |
| 31 | |
| 32 | #define ZFCP_LOG_AREA ZFCP_LOG_AREA_OTHER |
| 33 | |
Martin Peschke | c15450e | 2008-03-27 14:21:55 +0100 | [diff] [blame] | 34 | static void zfcp_dbf_hexdump(debug_info_t *dbf, void *to, int to_len, |
| 35 | int level, char *from, int from_len) |
| 36 | { |
| 37 | int offset; |
| 38 | struct zfcp_dbf_dump *dump = to; |
| 39 | int room = to_len - sizeof(*dump); |
| 40 | |
| 41 | for (offset = 0; offset < from_len; offset += dump->size) { |
| 42 | memset(to, 0, to_len); |
| 43 | strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE); |
| 44 | dump->total_size = from_len; |
| 45 | dump->offset = offset; |
| 46 | dump->size = min(from_len - offset, room); |
| 47 | memcpy(dump->data, from + offset, dump->size); |
| 48 | debug_event(dbf, level, dump, dump->size); |
| 49 | } |
| 50 | } |
| 51 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 52 | static int |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 53 | zfcp_dbf_stck(char *out_buf, const char *label, unsigned long long stck) |
| 54 | { |
| 55 | unsigned long long sec; |
Heiko Carstens | 364c855 | 2007-10-12 16:11:35 +0200 | [diff] [blame] | 56 | struct timespec dbftime; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 57 | int len = 0; |
| 58 | |
| 59 | stck -= 0x8126d60e46000000LL - (0x3c26700LL * 1000000 * 4096); |
| 60 | sec = stck >> 12; |
| 61 | do_div(sec, 1000000); |
Heiko Carstens | 364c855 | 2007-10-12 16:11:35 +0200 | [diff] [blame] | 62 | dbftime.tv_sec = sec; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 63 | stck -= (sec * 1000000) << 12; |
Heiko Carstens | 364c855 | 2007-10-12 16:11:35 +0200 | [diff] [blame] | 64 | dbftime.tv_nsec = ((stck * 1000) >> 12); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 65 | len += sprintf(out_buf + len, "%-24s%011lu:%06lu\n", |
Heiko Carstens | 364c855 | 2007-10-12 16:11:35 +0200 | [diff] [blame] | 66 | label, dbftime.tv_sec, dbftime.tv_nsec); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 67 | |
| 68 | return len; |
| 69 | } |
| 70 | |
| 71 | static int zfcp_dbf_tag(char *out_buf, const char *label, const char *tag) |
| 72 | { |
| 73 | int len = 0, i; |
| 74 | |
| 75 | len += sprintf(out_buf + len, "%-24s", label); |
| 76 | for (i = 0; i < ZFCP_DBF_TAG_SIZE; i++) |
| 77 | len += sprintf(out_buf + len, "%c", tag[i]); |
| 78 | len += sprintf(out_buf + len, "\n"); |
| 79 | |
| 80 | return len; |
| 81 | } |
| 82 | |
| 83 | static int |
| 84 | zfcp_dbf_view(char *out_buf, const char *label, const char *format, ...) |
| 85 | { |
| 86 | va_list arg; |
| 87 | int len = 0; |
| 88 | |
| 89 | len += sprintf(out_buf + len, "%-24s", label); |
| 90 | va_start(arg, format); |
| 91 | len += vsprintf(out_buf + len, format, arg); |
| 92 | va_end(arg); |
| 93 | len += sprintf(out_buf + len, "\n"); |
| 94 | |
| 95 | return len; |
| 96 | } |
| 97 | |
| 98 | static int |
| 99 | zfcp_dbf_view_dump(char *out_buf, const char *label, |
| 100 | char *buffer, int buflen, int offset, int total_size) |
| 101 | { |
| 102 | int len = 0; |
| 103 | |
| 104 | if (offset == 0) |
| 105 | len += sprintf(out_buf + len, "%-24s ", label); |
| 106 | |
| 107 | while (buflen--) { |
| 108 | if (offset > 0) { |
| 109 | if ((offset % 32) == 0) |
| 110 | len += sprintf(out_buf + len, "\n%-24c ", ' '); |
| 111 | else if ((offset % 4) == 0) |
| 112 | len += sprintf(out_buf + len, " "); |
| 113 | } |
| 114 | len += sprintf(out_buf + len, "%02x", *buffer++); |
| 115 | if (++offset == total_size) { |
| 116 | len += sprintf(out_buf + len, "\n"); |
| 117 | break; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | if (total_size == 0) |
| 122 | len += sprintf(out_buf + len, "\n"); |
| 123 | |
| 124 | return len; |
| 125 | } |
| 126 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 127 | static int |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 128 | zfcp_dbf_view_header(debug_info_t * id, struct debug_view *view, int area, |
| 129 | debug_entry_t * entry, char *out_buf) |
| 130 | { |
| 131 | struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)DEBUG_DATA(entry); |
| 132 | int len = 0; |
| 133 | |
| 134 | if (strncmp(dump->tag, "dump", ZFCP_DBF_TAG_SIZE) != 0) { |
| 135 | len += zfcp_dbf_stck(out_buf + len, "timestamp", |
| 136 | entry->id.stck); |
| 137 | len += zfcp_dbf_view(out_buf + len, "cpu", "%02i", |
| 138 | entry->id.fields.cpuid); |
| 139 | } else { |
| 140 | len += zfcp_dbf_view_dump(out_buf + len, NULL, |
| 141 | dump->data, |
| 142 | dump->size, |
| 143 | dump->offset, dump->total_size); |
| 144 | if ((dump->offset + dump->size) == dump->total_size) |
| 145 | len += sprintf(out_buf + len, "\n"); |
| 146 | } |
| 147 | |
| 148 | return len; |
| 149 | } |
| 150 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 151 | void zfcp_hba_dbf_event_fsf_response(struct zfcp_fsf_req *fsf_req) |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 152 | { |
| 153 | struct zfcp_adapter *adapter = fsf_req->adapter; |
| 154 | struct fsf_qtcb *qtcb = fsf_req->qtcb; |
| 155 | union fsf_prot_status_qual *prot_status_qual = |
| 156 | &qtcb->prefix.prot_status_qual; |
| 157 | union fsf_status_qual *fsf_status_qual = &qtcb->header.fsf_status_qual; |
| 158 | struct scsi_cmnd *scsi_cmnd; |
| 159 | struct zfcp_port *port; |
| 160 | struct zfcp_unit *unit; |
| 161 | struct zfcp_send_els *send_els; |
| 162 | struct zfcp_hba_dbf_record *rec = &adapter->hba_dbf_buf; |
| 163 | struct zfcp_hba_dbf_record_response *response = &rec->type.response; |
| 164 | int level; |
| 165 | unsigned long flags; |
| 166 | |
| 167 | spin_lock_irqsave(&adapter->hba_dbf_lock, flags); |
| 168 | memset(rec, 0, sizeof(struct zfcp_hba_dbf_record)); |
| 169 | strncpy(rec->tag, "resp", ZFCP_DBF_TAG_SIZE); |
| 170 | |
| 171 | if ((qtcb->prefix.prot_status != FSF_PROT_GOOD) && |
| 172 | (qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) { |
| 173 | strncpy(rec->tag2, "perr", ZFCP_DBF_TAG_SIZE); |
| 174 | level = 1; |
| 175 | } else if (qtcb->header.fsf_status != FSF_GOOD) { |
| 176 | strncpy(rec->tag2, "ferr", ZFCP_DBF_TAG_SIZE); |
| 177 | level = 1; |
| 178 | } else if ((fsf_req->fsf_command == FSF_QTCB_OPEN_PORT_WITH_DID) || |
| 179 | (fsf_req->fsf_command == FSF_QTCB_OPEN_LUN)) { |
| 180 | strncpy(rec->tag2, "open", ZFCP_DBF_TAG_SIZE); |
| 181 | level = 4; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 182 | } else { |
| 183 | strncpy(rec->tag2, "norm", ZFCP_DBF_TAG_SIZE); |
| 184 | level = 6; |
| 185 | } |
| 186 | |
| 187 | response->fsf_command = fsf_req->fsf_command; |
| 188 | response->fsf_reqid = (unsigned long)fsf_req; |
| 189 | response->fsf_seqno = fsf_req->seq_no; |
| 190 | response->fsf_issued = fsf_req->issued; |
| 191 | response->fsf_prot_status = qtcb->prefix.prot_status; |
| 192 | response->fsf_status = qtcb->header.fsf_status; |
| 193 | memcpy(response->fsf_prot_status_qual, |
| 194 | prot_status_qual, FSF_PROT_STATUS_QUAL_SIZE); |
| 195 | memcpy(response->fsf_status_qual, |
| 196 | fsf_status_qual, FSF_STATUS_QUALIFIER_SIZE); |
| 197 | response->fsf_req_status = fsf_req->status; |
| 198 | response->sbal_first = fsf_req->sbal_first; |
| 199 | response->sbal_curr = fsf_req->sbal_curr; |
| 200 | response->sbal_last = fsf_req->sbal_last; |
| 201 | response->pool = fsf_req->pool != NULL; |
| 202 | response->erp_action = (unsigned long)fsf_req->erp_action; |
| 203 | |
| 204 | switch (fsf_req->fsf_command) { |
| 205 | case FSF_QTCB_FCP_CMND: |
| 206 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) |
| 207 | break; |
| 208 | scsi_cmnd = (struct scsi_cmnd *)fsf_req->data; |
| 209 | if (scsi_cmnd != NULL) { |
| 210 | response->data.send_fcp.scsi_cmnd |
| 211 | = (unsigned long)scsi_cmnd; |
| 212 | response->data.send_fcp.scsi_serial |
| 213 | = scsi_cmnd->serial_number; |
| 214 | } |
| 215 | break; |
| 216 | |
| 217 | case FSF_QTCB_OPEN_PORT_WITH_DID: |
| 218 | case FSF_QTCB_CLOSE_PORT: |
| 219 | case FSF_QTCB_CLOSE_PHYSICAL_PORT: |
| 220 | port = (struct zfcp_port *)fsf_req->data; |
| 221 | response->data.port.wwpn = port->wwpn; |
| 222 | response->data.port.d_id = port->d_id; |
| 223 | response->data.port.port_handle = qtcb->header.port_handle; |
| 224 | break; |
| 225 | |
| 226 | case FSF_QTCB_OPEN_LUN: |
| 227 | case FSF_QTCB_CLOSE_LUN: |
| 228 | unit = (struct zfcp_unit *)fsf_req->data; |
| 229 | port = unit->port; |
| 230 | response->data.unit.wwpn = port->wwpn; |
| 231 | response->data.unit.fcp_lun = unit->fcp_lun; |
| 232 | response->data.unit.port_handle = qtcb->header.port_handle; |
| 233 | response->data.unit.lun_handle = qtcb->header.lun_handle; |
| 234 | break; |
| 235 | |
| 236 | case FSF_QTCB_SEND_ELS: |
| 237 | send_els = (struct zfcp_send_els *)fsf_req->data; |
| 238 | response->data.send_els.d_id = qtcb->bottom.support.d_id; |
| 239 | response->data.send_els.ls_code = send_els->ls_code >> 24; |
| 240 | break; |
| 241 | |
| 242 | case FSF_QTCB_ABORT_FCP_CMND: |
| 243 | case FSF_QTCB_SEND_GENERIC: |
| 244 | case FSF_QTCB_EXCHANGE_CONFIG_DATA: |
| 245 | case FSF_QTCB_EXCHANGE_PORT_DATA: |
| 246 | case FSF_QTCB_DOWNLOAD_CONTROL_FILE: |
| 247 | case FSF_QTCB_UPLOAD_CONTROL_FILE: |
| 248 | break; |
| 249 | } |
| 250 | |
| 251 | debug_event(adapter->hba_dbf, level, |
| 252 | rec, sizeof(struct zfcp_hba_dbf_record)); |
| 253 | spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags); |
| 254 | } |
| 255 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 256 | void |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 257 | zfcp_hba_dbf_event_fsf_unsol(const char *tag, struct zfcp_adapter *adapter, |
| 258 | struct fsf_status_read_buffer *status_buffer) |
| 259 | { |
| 260 | struct zfcp_hba_dbf_record *rec = &adapter->hba_dbf_buf; |
| 261 | unsigned long flags; |
| 262 | |
| 263 | spin_lock_irqsave(&adapter->hba_dbf_lock, flags); |
| 264 | memset(rec, 0, sizeof(struct zfcp_hba_dbf_record)); |
| 265 | strncpy(rec->tag, "stat", ZFCP_DBF_TAG_SIZE); |
| 266 | strncpy(rec->tag2, tag, ZFCP_DBF_TAG_SIZE); |
| 267 | |
| 268 | rec->type.status.failed = adapter->status_read_failed; |
| 269 | if (status_buffer != NULL) { |
| 270 | rec->type.status.status_type = status_buffer->status_type; |
| 271 | rec->type.status.status_subtype = status_buffer->status_subtype; |
| 272 | memcpy(&rec->type.status.queue_designator, |
| 273 | &status_buffer->queue_designator, |
| 274 | sizeof(struct fsf_queue_designator)); |
| 275 | |
| 276 | switch (status_buffer->status_type) { |
| 277 | case FSF_STATUS_READ_SENSE_DATA_AVAIL: |
| 278 | rec->type.status.payload_size = |
| 279 | ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL; |
| 280 | break; |
| 281 | |
| 282 | case FSF_STATUS_READ_BIT_ERROR_THRESHOLD: |
| 283 | rec->type.status.payload_size = |
| 284 | ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD; |
| 285 | break; |
| 286 | |
| 287 | case FSF_STATUS_READ_LINK_DOWN: |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 288 | switch (status_buffer->status_subtype) { |
| 289 | case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK: |
| 290 | case FSF_STATUS_READ_SUB_FDISC_FAILED: |
| 291 | rec->type.status.payload_size = |
| 292 | sizeof(struct fsf_link_down_info); |
| 293 | } |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 294 | break; |
| 295 | |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 296 | case FSF_STATUS_READ_FEATURE_UPDATE_ALERT: |
| 297 | rec->type.status.payload_size = |
| 298 | ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT; |
| 299 | break; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 300 | } |
| 301 | memcpy(&rec->type.status.payload, |
| 302 | &status_buffer->payload, rec->type.status.payload_size); |
| 303 | } |
| 304 | |
| 305 | debug_event(adapter->hba_dbf, 2, |
| 306 | rec, sizeof(struct zfcp_hba_dbf_record)); |
| 307 | spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags); |
| 308 | } |
| 309 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 310 | void |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 311 | zfcp_hba_dbf_event_qdio(struct zfcp_adapter *adapter, unsigned int status, |
| 312 | unsigned int qdio_error, unsigned int siga_error, |
| 313 | int sbal_index, int sbal_count) |
| 314 | { |
| 315 | struct zfcp_hba_dbf_record *rec = &adapter->hba_dbf_buf; |
| 316 | unsigned long flags; |
| 317 | |
| 318 | spin_lock_irqsave(&adapter->hba_dbf_lock, flags); |
| 319 | memset(rec, 0, sizeof(struct zfcp_hba_dbf_record)); |
| 320 | strncpy(rec->tag, "qdio", ZFCP_DBF_TAG_SIZE); |
| 321 | rec->type.qdio.status = status; |
| 322 | rec->type.qdio.qdio_error = qdio_error; |
| 323 | rec->type.qdio.siga_error = siga_error; |
| 324 | rec->type.qdio.sbal_index = sbal_index; |
| 325 | rec->type.qdio.sbal_count = sbal_count; |
| 326 | debug_event(adapter->hba_dbf, 0, |
| 327 | rec, sizeof(struct zfcp_hba_dbf_record)); |
| 328 | spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags); |
| 329 | } |
| 330 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 331 | static int |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 332 | zfcp_hba_dbf_view_response(char *out_buf, |
| 333 | struct zfcp_hba_dbf_record_response *rec) |
| 334 | { |
| 335 | int len = 0; |
| 336 | |
| 337 | len += zfcp_dbf_view(out_buf + len, "fsf_command", "0x%08x", |
| 338 | rec->fsf_command); |
| 339 | len += zfcp_dbf_view(out_buf + len, "fsf_reqid", "0x%0Lx", |
| 340 | rec->fsf_reqid); |
| 341 | len += zfcp_dbf_view(out_buf + len, "fsf_seqno", "0x%08x", |
| 342 | rec->fsf_seqno); |
| 343 | len += zfcp_dbf_stck(out_buf + len, "fsf_issued", rec->fsf_issued); |
| 344 | len += zfcp_dbf_view(out_buf + len, "fsf_prot_status", "0x%08x", |
| 345 | rec->fsf_prot_status); |
| 346 | len += zfcp_dbf_view(out_buf + len, "fsf_status", "0x%08x", |
| 347 | rec->fsf_status); |
| 348 | len += zfcp_dbf_view_dump(out_buf + len, "fsf_prot_status_qual", |
| 349 | rec->fsf_prot_status_qual, |
| 350 | FSF_PROT_STATUS_QUAL_SIZE, |
| 351 | 0, FSF_PROT_STATUS_QUAL_SIZE); |
| 352 | len += zfcp_dbf_view_dump(out_buf + len, "fsf_status_qual", |
| 353 | rec->fsf_status_qual, |
| 354 | FSF_STATUS_QUALIFIER_SIZE, |
| 355 | 0, FSF_STATUS_QUALIFIER_SIZE); |
| 356 | len += zfcp_dbf_view(out_buf + len, "fsf_req_status", "0x%08x", |
| 357 | rec->fsf_req_status); |
| 358 | len += zfcp_dbf_view(out_buf + len, "sbal_first", "0x%02x", |
| 359 | rec->sbal_first); |
| 360 | len += zfcp_dbf_view(out_buf + len, "sbal_curr", "0x%02x", |
| 361 | rec->sbal_curr); |
| 362 | len += zfcp_dbf_view(out_buf + len, "sbal_last", "0x%02x", |
| 363 | rec->sbal_last); |
| 364 | len += zfcp_dbf_view(out_buf + len, "pool", "0x%02x", rec->pool); |
| 365 | |
| 366 | switch (rec->fsf_command) { |
| 367 | case FSF_QTCB_FCP_CMND: |
| 368 | if (rec->fsf_req_status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) |
| 369 | break; |
| 370 | len += zfcp_dbf_view(out_buf + len, "scsi_cmnd", "0x%0Lx", |
| 371 | rec->data.send_fcp.scsi_cmnd); |
| 372 | len += zfcp_dbf_view(out_buf + len, "scsi_serial", "0x%016Lx", |
| 373 | rec->data.send_fcp.scsi_serial); |
| 374 | break; |
| 375 | |
| 376 | case FSF_QTCB_OPEN_PORT_WITH_DID: |
| 377 | case FSF_QTCB_CLOSE_PORT: |
| 378 | case FSF_QTCB_CLOSE_PHYSICAL_PORT: |
| 379 | len += zfcp_dbf_view(out_buf + len, "wwpn", "0x%016Lx", |
| 380 | rec->data.port.wwpn); |
| 381 | len += zfcp_dbf_view(out_buf + len, "d_id", "0x%06x", |
| 382 | rec->data.port.d_id); |
| 383 | len += zfcp_dbf_view(out_buf + len, "port_handle", "0x%08x", |
| 384 | rec->data.port.port_handle); |
| 385 | break; |
| 386 | |
| 387 | case FSF_QTCB_OPEN_LUN: |
| 388 | case FSF_QTCB_CLOSE_LUN: |
| 389 | len += zfcp_dbf_view(out_buf + len, "wwpn", "0x%016Lx", |
| 390 | rec->data.unit.wwpn); |
| 391 | len += zfcp_dbf_view(out_buf + len, "fcp_lun", "0x%016Lx", |
| 392 | rec->data.unit.fcp_lun); |
| 393 | len += zfcp_dbf_view(out_buf + len, "port_handle", "0x%08x", |
| 394 | rec->data.unit.port_handle); |
| 395 | len += zfcp_dbf_view(out_buf + len, "lun_handle", "0x%08x", |
| 396 | rec->data.unit.lun_handle); |
| 397 | break; |
| 398 | |
| 399 | case FSF_QTCB_SEND_ELS: |
| 400 | len += zfcp_dbf_view(out_buf + len, "d_id", "0x%06x", |
| 401 | rec->data.send_els.d_id); |
| 402 | len += zfcp_dbf_view(out_buf + len, "ls_code", "0x%02x", |
| 403 | rec->data.send_els.ls_code); |
| 404 | break; |
| 405 | |
| 406 | case FSF_QTCB_ABORT_FCP_CMND: |
| 407 | case FSF_QTCB_SEND_GENERIC: |
| 408 | case FSF_QTCB_EXCHANGE_CONFIG_DATA: |
| 409 | case FSF_QTCB_EXCHANGE_PORT_DATA: |
| 410 | case FSF_QTCB_DOWNLOAD_CONTROL_FILE: |
| 411 | case FSF_QTCB_UPLOAD_CONTROL_FILE: |
| 412 | break; |
| 413 | } |
| 414 | |
| 415 | return len; |
| 416 | } |
| 417 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 418 | static int |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 419 | zfcp_hba_dbf_view_status(char *out_buf, struct zfcp_hba_dbf_record_status *rec) |
| 420 | { |
| 421 | int len = 0; |
| 422 | |
| 423 | len += zfcp_dbf_view(out_buf + len, "failed", "0x%02x", rec->failed); |
| 424 | len += zfcp_dbf_view(out_buf + len, "status_type", "0x%08x", |
| 425 | rec->status_type); |
| 426 | len += zfcp_dbf_view(out_buf + len, "status_subtype", "0x%08x", |
| 427 | rec->status_subtype); |
| 428 | len += zfcp_dbf_view_dump(out_buf + len, "queue_designator", |
| 429 | (char *)&rec->queue_designator, |
| 430 | sizeof(struct fsf_queue_designator), |
| 431 | 0, sizeof(struct fsf_queue_designator)); |
| 432 | len += zfcp_dbf_view_dump(out_buf + len, "payload", |
| 433 | (char *)&rec->payload, |
| 434 | rec->payload_size, 0, rec->payload_size); |
| 435 | |
| 436 | return len; |
| 437 | } |
| 438 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 439 | static int |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 440 | zfcp_hba_dbf_view_qdio(char *out_buf, struct zfcp_hba_dbf_record_qdio *rec) |
| 441 | { |
| 442 | int len = 0; |
| 443 | |
| 444 | len += zfcp_dbf_view(out_buf + len, "status", "0x%08x", rec->status); |
| 445 | len += zfcp_dbf_view(out_buf + len, "qdio_error", "0x%08x", |
| 446 | rec->qdio_error); |
| 447 | len += zfcp_dbf_view(out_buf + len, "siga_error", "0x%08x", |
| 448 | rec->siga_error); |
| 449 | len += zfcp_dbf_view(out_buf + len, "sbal_index", "0x%02x", |
| 450 | rec->sbal_index); |
| 451 | len += zfcp_dbf_view(out_buf + len, "sbal_count", "0x%02x", |
| 452 | rec->sbal_count); |
| 453 | |
| 454 | return len; |
| 455 | } |
| 456 | |
| 457 | static int |
| 458 | zfcp_hba_dbf_view_format(debug_info_t * id, struct debug_view *view, |
| 459 | char *out_buf, const char *in_buf) |
| 460 | { |
| 461 | struct zfcp_hba_dbf_record *rec = (struct zfcp_hba_dbf_record *)in_buf; |
| 462 | int len = 0; |
| 463 | |
| 464 | if (strncmp(rec->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0) |
| 465 | return 0; |
| 466 | |
| 467 | len += zfcp_dbf_tag(out_buf + len, "tag", rec->tag); |
| 468 | if (isalpha(rec->tag2[0])) |
| 469 | len += zfcp_dbf_tag(out_buf + len, "tag2", rec->tag2); |
| 470 | if (strncmp(rec->tag, "resp", ZFCP_DBF_TAG_SIZE) == 0) |
| 471 | len += zfcp_hba_dbf_view_response(out_buf + len, |
| 472 | &rec->type.response); |
| 473 | else if (strncmp(rec->tag, "stat", ZFCP_DBF_TAG_SIZE) == 0) |
| 474 | len += zfcp_hba_dbf_view_status(out_buf + len, |
| 475 | &rec->type.status); |
| 476 | else if (strncmp(rec->tag, "qdio", ZFCP_DBF_TAG_SIZE) == 0) |
| 477 | len += zfcp_hba_dbf_view_qdio(out_buf + len, &rec->type.qdio); |
| 478 | |
| 479 | len += sprintf(out_buf + len, "\n"); |
| 480 | |
| 481 | return len; |
| 482 | } |
| 483 | |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 484 | static struct debug_view zfcp_hba_dbf_view = { |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 485 | "structured", |
| 486 | NULL, |
| 487 | &zfcp_dbf_view_header, |
| 488 | &zfcp_hba_dbf_view_format, |
| 489 | NULL, |
| 490 | NULL |
| 491 | }; |
| 492 | |
Heiko Carstens | 763968e | 2007-05-10 15:45:46 +0200 | [diff] [blame] | 493 | static void |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 494 | _zfcp_san_dbf_event_common_ct(const char *tag, struct zfcp_fsf_req *fsf_req, |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 495 | u32 s_id, u32 d_id, void *buffer, int buflen) |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 496 | { |
| 497 | struct zfcp_send_ct *send_ct = (struct zfcp_send_ct *)fsf_req->data; |
| 498 | struct zfcp_port *port = send_ct->port; |
| 499 | struct zfcp_adapter *adapter = port->adapter; |
| 500 | struct ct_hdr *header = (struct ct_hdr *)buffer; |
| 501 | struct zfcp_san_dbf_record *rec = &adapter->san_dbf_buf; |
| 502 | struct zfcp_san_dbf_record_ct *ct = &rec->type.ct; |
| 503 | unsigned long flags; |
| 504 | |
| 505 | spin_lock_irqsave(&adapter->san_dbf_lock, flags); |
| 506 | memset(rec, 0, sizeof(struct zfcp_san_dbf_record)); |
| 507 | strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE); |
| 508 | rec->fsf_reqid = (unsigned long)fsf_req; |
| 509 | rec->fsf_seqno = fsf_req->seq_no; |
| 510 | rec->s_id = s_id; |
| 511 | rec->d_id = d_id; |
| 512 | if (strncmp(tag, "octc", ZFCP_DBF_TAG_SIZE) == 0) { |
| 513 | ct->type.request.cmd_req_code = header->cmd_rsp_code; |
| 514 | ct->type.request.revision = header->revision; |
| 515 | ct->type.request.gs_type = header->gs_type; |
| 516 | ct->type.request.gs_subtype = header->gs_subtype; |
| 517 | ct->type.request.options = header->options; |
| 518 | ct->type.request.max_res_size = header->max_res_size; |
| 519 | } else if (strncmp(tag, "rctc", ZFCP_DBF_TAG_SIZE) == 0) { |
| 520 | ct->type.response.cmd_rsp_code = header->cmd_rsp_code; |
| 521 | ct->type.response.revision = header->revision; |
| 522 | ct->type.response.reason_code = header->reason_code; |
| 523 | ct->type.response.reason_code_expl = header->reason_code_expl; |
| 524 | ct->type.response.vendor_unique = header->vendor_unique; |
| 525 | } |
| 526 | ct->payload_size = |
| 527 | min(buflen - (int)sizeof(struct ct_hdr), ZFCP_DBF_CT_PAYLOAD); |
| 528 | memcpy(ct->payload, buffer + sizeof(struct ct_hdr), ct->payload_size); |
| 529 | debug_event(adapter->san_dbf, 3, |
| 530 | rec, sizeof(struct zfcp_san_dbf_record)); |
| 531 | spin_unlock_irqrestore(&adapter->san_dbf_lock, flags); |
| 532 | } |
| 533 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 534 | void zfcp_san_dbf_event_ct_request(struct zfcp_fsf_req *fsf_req) |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 535 | { |
| 536 | struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data; |
| 537 | struct zfcp_port *port = ct->port; |
| 538 | struct zfcp_adapter *adapter = port->adapter; |
| 539 | |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 540 | _zfcp_san_dbf_event_common_ct("octc", fsf_req, |
| 541 | fc_host_port_id(adapter->scsi_host), |
| 542 | port->d_id, zfcp_sg_to_address(ct->req), |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 543 | ct->req->length); |
| 544 | } |
| 545 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 546 | void zfcp_san_dbf_event_ct_response(struct zfcp_fsf_req *fsf_req) |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 547 | { |
| 548 | struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data; |
| 549 | struct zfcp_port *port = ct->port; |
| 550 | struct zfcp_adapter *adapter = port->adapter; |
| 551 | |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 552 | _zfcp_san_dbf_event_common_ct("rctc", fsf_req, port->d_id, |
| 553 | fc_host_port_id(adapter->scsi_host), |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 554 | zfcp_sg_to_address(ct->resp), |
| 555 | ct->resp->length); |
| 556 | } |
| 557 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 558 | static void |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 559 | _zfcp_san_dbf_event_common_els(const char *tag, int level, |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 560 | struct zfcp_fsf_req *fsf_req, u32 s_id, |
| 561 | u32 d_id, u8 ls_code, void *buffer, int buflen) |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 562 | { |
| 563 | struct zfcp_adapter *adapter = fsf_req->adapter; |
| 564 | struct zfcp_san_dbf_record *rec = &adapter->san_dbf_buf; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 565 | unsigned long flags; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 566 | |
| 567 | spin_lock_irqsave(&adapter->san_dbf_lock, flags); |
Martin Peschke | 0f65e95 | 2008-03-27 14:21:56 +0100 | [diff] [blame^] | 568 | memset(rec, 0, sizeof(struct zfcp_san_dbf_record)); |
| 569 | strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE); |
| 570 | rec->fsf_reqid = (unsigned long)fsf_req; |
| 571 | rec->fsf_seqno = fsf_req->seq_no; |
| 572 | rec->s_id = s_id; |
| 573 | rec->d_id = d_id; |
| 574 | rec->type.els.ls_code = ls_code; |
| 575 | debug_event(adapter->san_dbf, level, rec, sizeof(*rec)); |
| 576 | zfcp_dbf_hexdump(adapter->san_dbf, rec, sizeof(*rec), level, |
| 577 | buffer, min(buflen, ZFCP_DBF_ELS_MAX_PAYLOAD)); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 578 | spin_unlock_irqrestore(&adapter->san_dbf_lock, flags); |
| 579 | } |
| 580 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 581 | void zfcp_san_dbf_event_els_request(struct zfcp_fsf_req *fsf_req) |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 582 | { |
| 583 | struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data; |
| 584 | |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 585 | _zfcp_san_dbf_event_common_els("oels", 2, fsf_req, |
| 586 | fc_host_port_id(els->adapter->scsi_host), |
| 587 | els->d_id, |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 588 | *(u8 *) zfcp_sg_to_address(els->req), |
| 589 | zfcp_sg_to_address(els->req), |
| 590 | els->req->length); |
| 591 | } |
| 592 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 593 | void zfcp_san_dbf_event_els_response(struct zfcp_fsf_req *fsf_req) |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 594 | { |
| 595 | struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data; |
| 596 | |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 597 | _zfcp_san_dbf_event_common_els("rels", 2, fsf_req, els->d_id, |
| 598 | fc_host_port_id(els->adapter->scsi_host), |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 599 | *(u8 *) zfcp_sg_to_address(els->req), |
| 600 | zfcp_sg_to_address(els->resp), |
| 601 | els->resp->length); |
| 602 | } |
| 603 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 604 | void zfcp_san_dbf_event_incoming_els(struct zfcp_fsf_req *fsf_req) |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 605 | { |
| 606 | struct zfcp_adapter *adapter = fsf_req->adapter; |
| 607 | struct fsf_status_read_buffer *status_buffer = |
| 608 | (struct fsf_status_read_buffer *)fsf_req->data; |
| 609 | int length = (int)status_buffer->length - |
| 610 | (int)((void *)&status_buffer->payload - (void *)status_buffer); |
| 611 | |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 612 | _zfcp_san_dbf_event_common_els("iels", 1, fsf_req, status_buffer->d_id, |
| 613 | fc_host_port_id(adapter->scsi_host), |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 614 | *(u8 *) status_buffer->payload, |
| 615 | (void *)status_buffer->payload, length); |
| 616 | } |
| 617 | |
| 618 | static int |
| 619 | zfcp_san_dbf_view_format(debug_info_t * id, struct debug_view *view, |
| 620 | char *out_buf, const char *in_buf) |
| 621 | { |
| 622 | struct zfcp_san_dbf_record *rec = (struct zfcp_san_dbf_record *)in_buf; |
| 623 | char *buffer = NULL; |
| 624 | int buflen = 0, total = 0; |
| 625 | int len = 0; |
| 626 | |
| 627 | if (strncmp(rec->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0) |
| 628 | return 0; |
| 629 | |
| 630 | len += zfcp_dbf_tag(out_buf + len, "tag", rec->tag); |
| 631 | len += zfcp_dbf_view(out_buf + len, "fsf_reqid", "0x%0Lx", |
| 632 | rec->fsf_reqid); |
| 633 | len += zfcp_dbf_view(out_buf + len, "fsf_seqno", "0x%08x", |
| 634 | rec->fsf_seqno); |
| 635 | len += zfcp_dbf_view(out_buf + len, "s_id", "0x%06x", rec->s_id); |
| 636 | len += zfcp_dbf_view(out_buf + len, "d_id", "0x%06x", rec->d_id); |
| 637 | |
| 638 | if (strncmp(rec->tag, "octc", ZFCP_DBF_TAG_SIZE) == 0) { |
| 639 | len += zfcp_dbf_view(out_buf + len, "cmd_req_code", "0x%04x", |
| 640 | rec->type.ct.type.request.cmd_req_code); |
| 641 | len += zfcp_dbf_view(out_buf + len, "revision", "0x%02x", |
| 642 | rec->type.ct.type.request.revision); |
| 643 | len += zfcp_dbf_view(out_buf + len, "gs_type", "0x%02x", |
| 644 | rec->type.ct.type.request.gs_type); |
| 645 | len += zfcp_dbf_view(out_buf + len, "gs_subtype", "0x%02x", |
| 646 | rec->type.ct.type.request.gs_subtype); |
| 647 | len += zfcp_dbf_view(out_buf + len, "options", "0x%02x", |
| 648 | rec->type.ct.type.request.options); |
| 649 | len += zfcp_dbf_view(out_buf + len, "max_res_size", "0x%04x", |
| 650 | rec->type.ct.type.request.max_res_size); |
| 651 | total = rec->type.ct.payload_size; |
| 652 | buffer = rec->type.ct.payload; |
| 653 | buflen = min(total, ZFCP_DBF_CT_PAYLOAD); |
| 654 | } else if (strncmp(rec->tag, "rctc", ZFCP_DBF_TAG_SIZE) == 0) { |
| 655 | len += zfcp_dbf_view(out_buf + len, "cmd_rsp_code", "0x%04x", |
| 656 | rec->type.ct.type.response.cmd_rsp_code); |
| 657 | len += zfcp_dbf_view(out_buf + len, "revision", "0x%02x", |
| 658 | rec->type.ct.type.response.revision); |
| 659 | len += zfcp_dbf_view(out_buf + len, "reason_code", "0x%02x", |
| 660 | rec->type.ct.type.response.reason_code); |
| 661 | len += |
| 662 | zfcp_dbf_view(out_buf + len, "reason_code_expl", "0x%02x", |
| 663 | rec->type.ct.type.response.reason_code_expl); |
| 664 | len += |
| 665 | zfcp_dbf_view(out_buf + len, "vendor_unique", "0x%02x", |
| 666 | rec->type.ct.type.response.vendor_unique); |
| 667 | total = rec->type.ct.payload_size; |
| 668 | buffer = rec->type.ct.payload; |
| 669 | buflen = min(total, ZFCP_DBF_CT_PAYLOAD); |
| 670 | } else if (strncmp(rec->tag, "oels", ZFCP_DBF_TAG_SIZE) == 0 || |
| 671 | strncmp(rec->tag, "rels", ZFCP_DBF_TAG_SIZE) == 0 || |
| 672 | strncmp(rec->tag, "iels", ZFCP_DBF_TAG_SIZE) == 0) { |
| 673 | len += zfcp_dbf_view(out_buf + len, "ls_code", "0x%02x", |
| 674 | rec->type.els.ls_code); |
| 675 | total = rec->type.els.payload_size; |
| 676 | buffer = rec->type.els.payload; |
| 677 | buflen = min(total, ZFCP_DBF_ELS_PAYLOAD); |
| 678 | } |
| 679 | |
| 680 | len += zfcp_dbf_view_dump(out_buf + len, "payload", |
| 681 | buffer, buflen, 0, total); |
| 682 | |
| 683 | if (buflen == total) |
| 684 | len += sprintf(out_buf + len, "\n"); |
| 685 | |
| 686 | return len; |
| 687 | } |
| 688 | |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 689 | static struct debug_view zfcp_san_dbf_view = { |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 690 | "structured", |
| 691 | NULL, |
| 692 | &zfcp_dbf_view_header, |
| 693 | &zfcp_san_dbf_view_format, |
| 694 | NULL, |
| 695 | NULL |
| 696 | }; |
| 697 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 698 | static void |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 699 | _zfcp_scsi_dbf_event_common(const char *tag, const char *tag2, int level, |
| 700 | struct zfcp_adapter *adapter, |
| 701 | struct scsi_cmnd *scsi_cmnd, |
Maxim Shchetynin | ed829ad | 2006-02-11 01:42:58 +0100 | [diff] [blame] | 702 | struct zfcp_fsf_req *fsf_req, |
Andreas Herrmann | 4eff4a3 | 2006-09-18 22:29:20 +0200 | [diff] [blame] | 703 | unsigned long old_req_id) |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 704 | { |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 705 | struct zfcp_scsi_dbf_record *rec = &adapter->scsi_dbf_buf; |
| 706 | struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)rec; |
| 707 | unsigned long flags; |
| 708 | struct fcp_rsp_iu *fcp_rsp; |
| 709 | char *fcp_rsp_info = NULL, *fcp_sns_info = NULL; |
| 710 | int offset = 0, buflen = 0; |
| 711 | |
| 712 | spin_lock_irqsave(&adapter->scsi_dbf_lock, flags); |
| 713 | do { |
| 714 | memset(rec, 0, sizeof(struct zfcp_scsi_dbf_record)); |
| 715 | if (offset == 0) { |
| 716 | strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE); |
| 717 | strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE); |
Maxim Shchetynin | ed829ad | 2006-02-11 01:42:58 +0100 | [diff] [blame] | 718 | if (scsi_cmnd != NULL) { |
| 719 | if (scsi_cmnd->device) { |
| 720 | rec->scsi_id = scsi_cmnd->device->id; |
| 721 | rec->scsi_lun = scsi_cmnd->device->lun; |
| 722 | } |
| 723 | rec->scsi_result = scsi_cmnd->result; |
| 724 | rec->scsi_cmnd = (unsigned long)scsi_cmnd; |
| 725 | rec->scsi_serial = scsi_cmnd->serial_number; |
| 726 | memcpy(rec->scsi_opcode, &scsi_cmnd->cmnd, |
| 727 | min((int)scsi_cmnd->cmd_len, |
| 728 | ZFCP_DBF_SCSI_OPCODE)); |
| 729 | rec->scsi_retries = scsi_cmnd->retries; |
| 730 | rec->scsi_allowed = scsi_cmnd->allowed; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 731 | } |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 732 | if (fsf_req != NULL) { |
| 733 | fcp_rsp = (struct fcp_rsp_iu *) |
| 734 | &(fsf_req->qtcb->bottom.io.fcp_rsp); |
| 735 | fcp_rsp_info = |
| 736 | zfcp_get_fcp_rsp_info_ptr(fcp_rsp); |
| 737 | fcp_sns_info = |
| 738 | zfcp_get_fcp_sns_info_ptr(fcp_rsp); |
| 739 | |
| 740 | rec->type.fcp.rsp_validity = |
| 741 | fcp_rsp->validity.value; |
| 742 | rec->type.fcp.rsp_scsi_status = |
| 743 | fcp_rsp->scsi_status; |
| 744 | rec->type.fcp.rsp_resid = fcp_rsp->fcp_resid; |
| 745 | if (fcp_rsp->validity.bits.fcp_rsp_len_valid) |
| 746 | rec->type.fcp.rsp_code = |
| 747 | *(fcp_rsp_info + 3); |
| 748 | if (fcp_rsp->validity.bits.fcp_sns_len_valid) { |
| 749 | buflen = min((int)fcp_rsp->fcp_sns_len, |
| 750 | ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO); |
| 751 | rec->type.fcp.sns_info_len = buflen; |
| 752 | memcpy(rec->type.fcp.sns_info, |
| 753 | fcp_sns_info, |
| 754 | min(buflen, |
| 755 | ZFCP_DBF_SCSI_FCP_SNS_INFO)); |
| 756 | offset += min(buflen, |
| 757 | ZFCP_DBF_SCSI_FCP_SNS_INFO); |
| 758 | } |
| 759 | |
| 760 | rec->fsf_reqid = (unsigned long)fsf_req; |
| 761 | rec->fsf_seqno = fsf_req->seq_no; |
| 762 | rec->fsf_issued = fsf_req->issued; |
| 763 | } |
Andreas Herrmann | 4eff4a3 | 2006-09-18 22:29:20 +0200 | [diff] [blame] | 764 | rec->type.old_fsf_reqid = old_req_id; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 765 | } else { |
| 766 | strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE); |
| 767 | dump->total_size = buflen; |
| 768 | dump->offset = offset; |
| 769 | dump->size = min(buflen - offset, |
| 770 | (int)sizeof(struct |
| 771 | zfcp_scsi_dbf_record) - |
| 772 | (int)sizeof(struct zfcp_dbf_dump)); |
| 773 | memcpy(dump->data, fcp_sns_info + offset, dump->size); |
| 774 | offset += dump->size; |
| 775 | } |
| 776 | debug_event(adapter->scsi_dbf, level, |
| 777 | rec, sizeof(struct zfcp_scsi_dbf_record)); |
| 778 | } while (offset < buflen); |
| 779 | spin_unlock_irqrestore(&adapter->scsi_dbf_lock, flags); |
| 780 | } |
| 781 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 782 | void |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 783 | zfcp_scsi_dbf_event_result(const char *tag, int level, |
| 784 | struct zfcp_adapter *adapter, |
Maxim Shchetynin | ed829ad | 2006-02-11 01:42:58 +0100 | [diff] [blame] | 785 | struct scsi_cmnd *scsi_cmnd, |
| 786 | struct zfcp_fsf_req *fsf_req) |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 787 | { |
Maxim Shchetynin | ed829ad | 2006-02-11 01:42:58 +0100 | [diff] [blame] | 788 | _zfcp_scsi_dbf_event_common("rslt", tag, level, |
Andreas Herrmann | 4eff4a3 | 2006-09-18 22:29:20 +0200 | [diff] [blame] | 789 | adapter, scsi_cmnd, fsf_req, 0); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 790 | } |
| 791 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 792 | void |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 793 | zfcp_scsi_dbf_event_abort(const char *tag, struct zfcp_adapter *adapter, |
| 794 | struct scsi_cmnd *scsi_cmnd, |
Maxim Shchetynin | ed829ad | 2006-02-11 01:42:58 +0100 | [diff] [blame] | 795 | struct zfcp_fsf_req *new_fsf_req, |
Andreas Herrmann | 4eff4a3 | 2006-09-18 22:29:20 +0200 | [diff] [blame] | 796 | unsigned long old_req_id) |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 797 | { |
Maxim Shchetynin | ed829ad | 2006-02-11 01:42:58 +0100 | [diff] [blame] | 798 | _zfcp_scsi_dbf_event_common("abrt", tag, 1, |
Andreas Herrmann | 4eff4a3 | 2006-09-18 22:29:20 +0200 | [diff] [blame] | 799 | adapter, scsi_cmnd, new_fsf_req, old_req_id); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 800 | } |
| 801 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 802 | void |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 803 | zfcp_scsi_dbf_event_devreset(const char *tag, u8 flag, struct zfcp_unit *unit, |
| 804 | struct scsi_cmnd *scsi_cmnd) |
| 805 | { |
| 806 | struct zfcp_adapter *adapter = unit->port->adapter; |
| 807 | |
| 808 | _zfcp_scsi_dbf_event_common(flag == FCP_TARGET_RESET ? "trst" : "lrst", |
Andreas Herrmann | 4eff4a3 | 2006-09-18 22:29:20 +0200 | [diff] [blame] | 809 | tag, 1, adapter, scsi_cmnd, NULL, 0); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | static int |
| 813 | zfcp_scsi_dbf_view_format(debug_info_t * id, struct debug_view *view, |
| 814 | char *out_buf, const char *in_buf) |
| 815 | { |
| 816 | struct zfcp_scsi_dbf_record *rec = |
| 817 | (struct zfcp_scsi_dbf_record *)in_buf; |
| 818 | int len = 0; |
| 819 | |
| 820 | if (strncmp(rec->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0) |
| 821 | return 0; |
| 822 | |
| 823 | len += zfcp_dbf_tag(out_buf + len, "tag", rec->tag); |
| 824 | len += zfcp_dbf_tag(out_buf + len, "tag2", rec->tag2); |
| 825 | len += zfcp_dbf_view(out_buf + len, "scsi_id", "0x%08x", rec->scsi_id); |
| 826 | len += zfcp_dbf_view(out_buf + len, "scsi_lun", "0x%08x", |
| 827 | rec->scsi_lun); |
| 828 | len += zfcp_dbf_view(out_buf + len, "scsi_result", "0x%08x", |
| 829 | rec->scsi_result); |
| 830 | len += zfcp_dbf_view(out_buf + len, "scsi_cmnd", "0x%0Lx", |
| 831 | rec->scsi_cmnd); |
| 832 | len += zfcp_dbf_view(out_buf + len, "scsi_serial", "0x%016Lx", |
| 833 | rec->scsi_serial); |
| 834 | len += zfcp_dbf_view_dump(out_buf + len, "scsi_opcode", |
| 835 | rec->scsi_opcode, |
| 836 | ZFCP_DBF_SCSI_OPCODE, |
| 837 | 0, ZFCP_DBF_SCSI_OPCODE); |
| 838 | len += zfcp_dbf_view(out_buf + len, "scsi_retries", "0x%02x", |
| 839 | rec->scsi_retries); |
| 840 | len += zfcp_dbf_view(out_buf + len, "scsi_allowed", "0x%02x", |
| 841 | rec->scsi_allowed); |
Maxim Shchetynin | ed829ad | 2006-02-11 01:42:58 +0100 | [diff] [blame] | 842 | if (strncmp(rec->tag, "abrt", ZFCP_DBF_TAG_SIZE) == 0) { |
| 843 | len += zfcp_dbf_view(out_buf + len, "old_fsf_reqid", "0x%0Lx", |
| 844 | rec->type.old_fsf_reqid); |
| 845 | } |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 846 | len += zfcp_dbf_view(out_buf + len, "fsf_reqid", "0x%0Lx", |
| 847 | rec->fsf_reqid); |
| 848 | len += zfcp_dbf_view(out_buf + len, "fsf_seqno", "0x%08x", |
| 849 | rec->fsf_seqno); |
| 850 | len += zfcp_dbf_stck(out_buf + len, "fsf_issued", rec->fsf_issued); |
| 851 | if (strncmp(rec->tag, "rslt", ZFCP_DBF_TAG_SIZE) == 0) { |
| 852 | len += |
| 853 | zfcp_dbf_view(out_buf + len, "fcp_rsp_validity", "0x%02x", |
| 854 | rec->type.fcp.rsp_validity); |
| 855 | len += |
| 856 | zfcp_dbf_view(out_buf + len, "fcp_rsp_scsi_status", |
| 857 | "0x%02x", rec->type.fcp.rsp_scsi_status); |
| 858 | len += |
| 859 | zfcp_dbf_view(out_buf + len, "fcp_rsp_resid", "0x%08x", |
| 860 | rec->type.fcp.rsp_resid); |
| 861 | len += |
| 862 | zfcp_dbf_view(out_buf + len, "fcp_rsp_code", "0x%08x", |
| 863 | rec->type.fcp.rsp_code); |
| 864 | len += |
| 865 | zfcp_dbf_view(out_buf + len, "fcp_sns_info_len", "0x%08x", |
| 866 | rec->type.fcp.sns_info_len); |
| 867 | len += |
| 868 | zfcp_dbf_view_dump(out_buf + len, "fcp_sns_info", |
| 869 | rec->type.fcp.sns_info, |
| 870 | min((int)rec->type.fcp.sns_info_len, |
| 871 | ZFCP_DBF_SCSI_FCP_SNS_INFO), 0, |
| 872 | rec->type.fcp.sns_info_len); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | len += sprintf(out_buf + len, "\n"); |
| 876 | |
| 877 | return len; |
| 878 | } |
| 879 | |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 880 | static struct debug_view zfcp_scsi_dbf_view = { |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 881 | "structured", |
| 882 | NULL, |
| 883 | &zfcp_dbf_view_header, |
| 884 | &zfcp_scsi_dbf_view_format, |
| 885 | NULL, |
| 886 | NULL |
| 887 | }; |
| 888 | |
| 889 | /** |
| 890 | * zfcp_adapter_debug_register - registers debug feature for an adapter |
| 891 | * @adapter: pointer to adapter for which debug features should be registered |
| 892 | * return: -ENOMEM on error, 0 otherwise |
| 893 | */ |
| 894 | int zfcp_adapter_debug_register(struct zfcp_adapter *adapter) |
| 895 | { |
| 896 | char dbf_name[DEBUG_MAX_NAME_LEN]; |
| 897 | |
| 898 | /* debug feature area which records recovery activity */ |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 899 | sprintf(dbf_name, "zfcp_%s_erp", zfcp_get_busid_by_adapter(adapter)); |
| 900 | adapter->erp_dbf = debug_register(dbf_name, dbfsize, 2, |
| 901 | sizeof(struct zfcp_erp_dbf_record)); |
| 902 | if (!adapter->erp_dbf) |
| 903 | goto failed; |
| 904 | debug_register_view(adapter->erp_dbf, &debug_hex_ascii_view); |
| 905 | debug_set_level(adapter->erp_dbf, 3); |
| 906 | |
| 907 | /* debug feature area which records HBA (FSF and QDIO) conditions */ |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 908 | sprintf(dbf_name, "zfcp_%s_hba", zfcp_get_busid_by_adapter(adapter)); |
| 909 | adapter->hba_dbf = debug_register(dbf_name, dbfsize, 1, |
| 910 | sizeof(struct zfcp_hba_dbf_record)); |
| 911 | if (!adapter->hba_dbf) |
| 912 | goto failed; |
| 913 | debug_register_view(adapter->hba_dbf, &debug_hex_ascii_view); |
| 914 | debug_register_view(adapter->hba_dbf, &zfcp_hba_dbf_view); |
| 915 | debug_set_level(adapter->hba_dbf, 3); |
| 916 | |
| 917 | /* debug feature area which records SAN command failures and recovery */ |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 918 | sprintf(dbf_name, "zfcp_%s_san", zfcp_get_busid_by_adapter(adapter)); |
| 919 | adapter->san_dbf = debug_register(dbf_name, dbfsize, 1, |
| 920 | sizeof(struct zfcp_san_dbf_record)); |
| 921 | if (!adapter->san_dbf) |
| 922 | goto failed; |
| 923 | debug_register_view(adapter->san_dbf, &debug_hex_ascii_view); |
| 924 | debug_register_view(adapter->san_dbf, &zfcp_san_dbf_view); |
| 925 | debug_set_level(adapter->san_dbf, 6); |
| 926 | |
| 927 | /* debug feature area which records SCSI command failures and recovery */ |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 928 | sprintf(dbf_name, "zfcp_%s_scsi", zfcp_get_busid_by_adapter(adapter)); |
| 929 | adapter->scsi_dbf = debug_register(dbf_name, dbfsize, 1, |
| 930 | sizeof(struct zfcp_scsi_dbf_record)); |
| 931 | if (!adapter->scsi_dbf) |
| 932 | goto failed; |
| 933 | debug_register_view(adapter->scsi_dbf, &debug_hex_ascii_view); |
| 934 | debug_register_view(adapter->scsi_dbf, &zfcp_scsi_dbf_view); |
| 935 | debug_set_level(adapter->scsi_dbf, 3); |
| 936 | |
| 937 | return 0; |
| 938 | |
| 939 | failed: |
| 940 | zfcp_adapter_debug_unregister(adapter); |
| 941 | |
| 942 | return -ENOMEM; |
| 943 | } |
| 944 | |
| 945 | /** |
| 946 | * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter |
| 947 | * @adapter: pointer to adapter for which debug features should be unregistered |
| 948 | */ |
| 949 | void zfcp_adapter_debug_unregister(struct zfcp_adapter *adapter) |
| 950 | { |
| 951 | debug_unregister(adapter->scsi_dbf); |
| 952 | debug_unregister(adapter->san_dbf); |
| 953 | debug_unregister(adapter->hba_dbf); |
| 954 | debug_unregister(adapter->erp_dbf); |
| 955 | adapter->scsi_dbf = NULL; |
| 956 | adapter->san_dbf = NULL; |
| 957 | adapter->hba_dbf = NULL; |
| 958 | adapter->erp_dbf = NULL; |
| 959 | } |
| 960 | |
| 961 | #undef ZFCP_LOG_AREA |