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; |
| 565 | struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)rec; |
| 566 | unsigned long flags; |
| 567 | int offset = 0; |
| 568 | |
| 569 | spin_lock_irqsave(&adapter->san_dbf_lock, flags); |
| 570 | do { |
| 571 | memset(rec, 0, sizeof(struct zfcp_san_dbf_record)); |
| 572 | if (offset == 0) { |
| 573 | strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE); |
| 574 | rec->fsf_reqid = (unsigned long)fsf_req; |
| 575 | rec->fsf_seqno = fsf_req->seq_no; |
| 576 | rec->s_id = s_id; |
| 577 | rec->d_id = d_id; |
| 578 | rec->type.els.ls_code = ls_code; |
| 579 | buflen = min(buflen, ZFCP_DBF_ELS_MAX_PAYLOAD); |
| 580 | rec->type.els.payload_size = buflen; |
| 581 | memcpy(rec->type.els.payload, |
| 582 | buffer, min(buflen, ZFCP_DBF_ELS_PAYLOAD)); |
| 583 | offset += min(buflen, ZFCP_DBF_ELS_PAYLOAD); |
| 584 | } else { |
| 585 | strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE); |
| 586 | dump->total_size = buflen; |
| 587 | dump->offset = offset; |
| 588 | dump->size = min(buflen - offset, |
| 589 | (int)sizeof(struct zfcp_san_dbf_record) |
| 590 | - (int)sizeof(struct zfcp_dbf_dump)); |
| 591 | memcpy(dump->data, buffer + offset, dump->size); |
| 592 | offset += dump->size; |
| 593 | } |
| 594 | debug_event(adapter->san_dbf, level, |
| 595 | rec, sizeof(struct zfcp_san_dbf_record)); |
| 596 | } while (offset < buflen); |
| 597 | spin_unlock_irqrestore(&adapter->san_dbf_lock, flags); |
| 598 | } |
| 599 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 600 | 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] | 601 | { |
| 602 | struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data; |
| 603 | |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 604 | _zfcp_san_dbf_event_common_els("oels", 2, fsf_req, |
| 605 | fc_host_port_id(els->adapter->scsi_host), |
| 606 | els->d_id, |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 607 | *(u8 *) zfcp_sg_to_address(els->req), |
| 608 | zfcp_sg_to_address(els->req), |
| 609 | els->req->length); |
| 610 | } |
| 611 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 612 | 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] | 613 | { |
| 614 | struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data; |
| 615 | |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 616 | _zfcp_san_dbf_event_common_els("rels", 2, fsf_req, els->d_id, |
| 617 | fc_host_port_id(els->adapter->scsi_host), |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 618 | *(u8 *) zfcp_sg_to_address(els->req), |
| 619 | zfcp_sg_to_address(els->resp), |
| 620 | els->resp->length); |
| 621 | } |
| 622 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 623 | 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] | 624 | { |
| 625 | struct zfcp_adapter *adapter = fsf_req->adapter; |
| 626 | struct fsf_status_read_buffer *status_buffer = |
| 627 | (struct fsf_status_read_buffer *)fsf_req->data; |
| 628 | int length = (int)status_buffer->length - |
| 629 | (int)((void *)&status_buffer->payload - (void *)status_buffer); |
| 630 | |
Andreas Herrmann | 13e1e1f | 2005-09-19 16:56:17 +0200 | [diff] [blame] | 631 | _zfcp_san_dbf_event_common_els("iels", 1, fsf_req, status_buffer->d_id, |
| 632 | fc_host_port_id(adapter->scsi_host), |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 633 | *(u8 *) status_buffer->payload, |
| 634 | (void *)status_buffer->payload, length); |
| 635 | } |
| 636 | |
| 637 | static int |
| 638 | zfcp_san_dbf_view_format(debug_info_t * id, struct debug_view *view, |
| 639 | char *out_buf, const char *in_buf) |
| 640 | { |
| 641 | struct zfcp_san_dbf_record *rec = (struct zfcp_san_dbf_record *)in_buf; |
| 642 | char *buffer = NULL; |
| 643 | int buflen = 0, total = 0; |
| 644 | int len = 0; |
| 645 | |
| 646 | if (strncmp(rec->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0) |
| 647 | return 0; |
| 648 | |
| 649 | len += zfcp_dbf_tag(out_buf + len, "tag", rec->tag); |
| 650 | len += zfcp_dbf_view(out_buf + len, "fsf_reqid", "0x%0Lx", |
| 651 | rec->fsf_reqid); |
| 652 | len += zfcp_dbf_view(out_buf + len, "fsf_seqno", "0x%08x", |
| 653 | rec->fsf_seqno); |
| 654 | len += zfcp_dbf_view(out_buf + len, "s_id", "0x%06x", rec->s_id); |
| 655 | len += zfcp_dbf_view(out_buf + len, "d_id", "0x%06x", rec->d_id); |
| 656 | |
| 657 | if (strncmp(rec->tag, "octc", ZFCP_DBF_TAG_SIZE) == 0) { |
| 658 | len += zfcp_dbf_view(out_buf + len, "cmd_req_code", "0x%04x", |
| 659 | rec->type.ct.type.request.cmd_req_code); |
| 660 | len += zfcp_dbf_view(out_buf + len, "revision", "0x%02x", |
| 661 | rec->type.ct.type.request.revision); |
| 662 | len += zfcp_dbf_view(out_buf + len, "gs_type", "0x%02x", |
| 663 | rec->type.ct.type.request.gs_type); |
| 664 | len += zfcp_dbf_view(out_buf + len, "gs_subtype", "0x%02x", |
| 665 | rec->type.ct.type.request.gs_subtype); |
| 666 | len += zfcp_dbf_view(out_buf + len, "options", "0x%02x", |
| 667 | rec->type.ct.type.request.options); |
| 668 | len += zfcp_dbf_view(out_buf + len, "max_res_size", "0x%04x", |
| 669 | rec->type.ct.type.request.max_res_size); |
| 670 | total = rec->type.ct.payload_size; |
| 671 | buffer = rec->type.ct.payload; |
| 672 | buflen = min(total, ZFCP_DBF_CT_PAYLOAD); |
| 673 | } else if (strncmp(rec->tag, "rctc", ZFCP_DBF_TAG_SIZE) == 0) { |
| 674 | len += zfcp_dbf_view(out_buf + len, "cmd_rsp_code", "0x%04x", |
| 675 | rec->type.ct.type.response.cmd_rsp_code); |
| 676 | len += zfcp_dbf_view(out_buf + len, "revision", "0x%02x", |
| 677 | rec->type.ct.type.response.revision); |
| 678 | len += zfcp_dbf_view(out_buf + len, "reason_code", "0x%02x", |
| 679 | rec->type.ct.type.response.reason_code); |
| 680 | len += |
| 681 | zfcp_dbf_view(out_buf + len, "reason_code_expl", "0x%02x", |
| 682 | rec->type.ct.type.response.reason_code_expl); |
| 683 | len += |
| 684 | zfcp_dbf_view(out_buf + len, "vendor_unique", "0x%02x", |
| 685 | rec->type.ct.type.response.vendor_unique); |
| 686 | total = rec->type.ct.payload_size; |
| 687 | buffer = rec->type.ct.payload; |
| 688 | buflen = min(total, ZFCP_DBF_CT_PAYLOAD); |
| 689 | } else if (strncmp(rec->tag, "oels", ZFCP_DBF_TAG_SIZE) == 0 || |
| 690 | strncmp(rec->tag, "rels", ZFCP_DBF_TAG_SIZE) == 0 || |
| 691 | strncmp(rec->tag, "iels", ZFCP_DBF_TAG_SIZE) == 0) { |
| 692 | len += zfcp_dbf_view(out_buf + len, "ls_code", "0x%02x", |
| 693 | rec->type.els.ls_code); |
| 694 | total = rec->type.els.payload_size; |
| 695 | buffer = rec->type.els.payload; |
| 696 | buflen = min(total, ZFCP_DBF_ELS_PAYLOAD); |
| 697 | } |
| 698 | |
| 699 | len += zfcp_dbf_view_dump(out_buf + len, "payload", |
| 700 | buffer, buflen, 0, total); |
| 701 | |
| 702 | if (buflen == total) |
| 703 | len += sprintf(out_buf + len, "\n"); |
| 704 | |
| 705 | return len; |
| 706 | } |
| 707 | |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 708 | static struct debug_view zfcp_san_dbf_view = { |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 709 | "structured", |
| 710 | NULL, |
| 711 | &zfcp_dbf_view_header, |
| 712 | &zfcp_san_dbf_view_format, |
| 713 | NULL, |
| 714 | NULL |
| 715 | }; |
| 716 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 717 | static void |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 718 | _zfcp_scsi_dbf_event_common(const char *tag, const char *tag2, int level, |
| 719 | struct zfcp_adapter *adapter, |
| 720 | struct scsi_cmnd *scsi_cmnd, |
Maxim Shchetynin | ed829ad | 2006-02-11 01:42:58 +0100 | [diff] [blame] | 721 | struct zfcp_fsf_req *fsf_req, |
Andreas Herrmann | 4eff4a3 | 2006-09-18 22:29:20 +0200 | [diff] [blame] | 722 | unsigned long old_req_id) |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 723 | { |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 724 | struct zfcp_scsi_dbf_record *rec = &adapter->scsi_dbf_buf; |
| 725 | struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)rec; |
| 726 | unsigned long flags; |
| 727 | struct fcp_rsp_iu *fcp_rsp; |
| 728 | char *fcp_rsp_info = NULL, *fcp_sns_info = NULL; |
| 729 | int offset = 0, buflen = 0; |
| 730 | |
| 731 | spin_lock_irqsave(&adapter->scsi_dbf_lock, flags); |
| 732 | do { |
| 733 | memset(rec, 0, sizeof(struct zfcp_scsi_dbf_record)); |
| 734 | if (offset == 0) { |
| 735 | strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE); |
| 736 | strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE); |
Maxim Shchetynin | ed829ad | 2006-02-11 01:42:58 +0100 | [diff] [blame] | 737 | if (scsi_cmnd != NULL) { |
| 738 | if (scsi_cmnd->device) { |
| 739 | rec->scsi_id = scsi_cmnd->device->id; |
| 740 | rec->scsi_lun = scsi_cmnd->device->lun; |
| 741 | } |
| 742 | rec->scsi_result = scsi_cmnd->result; |
| 743 | rec->scsi_cmnd = (unsigned long)scsi_cmnd; |
| 744 | rec->scsi_serial = scsi_cmnd->serial_number; |
| 745 | memcpy(rec->scsi_opcode, &scsi_cmnd->cmnd, |
| 746 | min((int)scsi_cmnd->cmd_len, |
| 747 | ZFCP_DBF_SCSI_OPCODE)); |
| 748 | rec->scsi_retries = scsi_cmnd->retries; |
| 749 | rec->scsi_allowed = scsi_cmnd->allowed; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 750 | } |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 751 | if (fsf_req != NULL) { |
| 752 | fcp_rsp = (struct fcp_rsp_iu *) |
| 753 | &(fsf_req->qtcb->bottom.io.fcp_rsp); |
| 754 | fcp_rsp_info = |
| 755 | zfcp_get_fcp_rsp_info_ptr(fcp_rsp); |
| 756 | fcp_sns_info = |
| 757 | zfcp_get_fcp_sns_info_ptr(fcp_rsp); |
| 758 | |
| 759 | rec->type.fcp.rsp_validity = |
| 760 | fcp_rsp->validity.value; |
| 761 | rec->type.fcp.rsp_scsi_status = |
| 762 | fcp_rsp->scsi_status; |
| 763 | rec->type.fcp.rsp_resid = fcp_rsp->fcp_resid; |
| 764 | if (fcp_rsp->validity.bits.fcp_rsp_len_valid) |
| 765 | rec->type.fcp.rsp_code = |
| 766 | *(fcp_rsp_info + 3); |
| 767 | if (fcp_rsp->validity.bits.fcp_sns_len_valid) { |
| 768 | buflen = min((int)fcp_rsp->fcp_sns_len, |
| 769 | ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO); |
| 770 | rec->type.fcp.sns_info_len = buflen; |
| 771 | memcpy(rec->type.fcp.sns_info, |
| 772 | fcp_sns_info, |
| 773 | min(buflen, |
| 774 | ZFCP_DBF_SCSI_FCP_SNS_INFO)); |
| 775 | offset += min(buflen, |
| 776 | ZFCP_DBF_SCSI_FCP_SNS_INFO); |
| 777 | } |
| 778 | |
| 779 | rec->fsf_reqid = (unsigned long)fsf_req; |
| 780 | rec->fsf_seqno = fsf_req->seq_no; |
| 781 | rec->fsf_issued = fsf_req->issued; |
| 782 | } |
Andreas Herrmann | 4eff4a3 | 2006-09-18 22:29:20 +0200 | [diff] [blame] | 783 | rec->type.old_fsf_reqid = old_req_id; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 784 | } else { |
| 785 | strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE); |
| 786 | dump->total_size = buflen; |
| 787 | dump->offset = offset; |
| 788 | dump->size = min(buflen - offset, |
| 789 | (int)sizeof(struct |
| 790 | zfcp_scsi_dbf_record) - |
| 791 | (int)sizeof(struct zfcp_dbf_dump)); |
| 792 | memcpy(dump->data, fcp_sns_info + offset, dump->size); |
| 793 | offset += dump->size; |
| 794 | } |
| 795 | debug_event(adapter->scsi_dbf, level, |
| 796 | rec, sizeof(struct zfcp_scsi_dbf_record)); |
| 797 | } while (offset < buflen); |
| 798 | spin_unlock_irqrestore(&adapter->scsi_dbf_lock, flags); |
| 799 | } |
| 800 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 801 | void |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 802 | zfcp_scsi_dbf_event_result(const char *tag, int level, |
| 803 | struct zfcp_adapter *adapter, |
Maxim Shchetynin | ed829ad | 2006-02-11 01:42:58 +0100 | [diff] [blame] | 804 | struct scsi_cmnd *scsi_cmnd, |
| 805 | struct zfcp_fsf_req *fsf_req) |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 806 | { |
Maxim Shchetynin | ed829ad | 2006-02-11 01:42:58 +0100 | [diff] [blame] | 807 | _zfcp_scsi_dbf_event_common("rslt", tag, level, |
Andreas Herrmann | 4eff4a3 | 2006-09-18 22:29:20 +0200 | [diff] [blame] | 808 | adapter, scsi_cmnd, fsf_req, 0); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 809 | } |
| 810 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 811 | void |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 812 | zfcp_scsi_dbf_event_abort(const char *tag, struct zfcp_adapter *adapter, |
| 813 | struct scsi_cmnd *scsi_cmnd, |
Maxim Shchetynin | ed829ad | 2006-02-11 01:42:58 +0100 | [diff] [blame] | 814 | struct zfcp_fsf_req *new_fsf_req, |
Andreas Herrmann | 4eff4a3 | 2006-09-18 22:29:20 +0200 | [diff] [blame] | 815 | unsigned long old_req_id) |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 816 | { |
Maxim Shchetynin | ed829ad | 2006-02-11 01:42:58 +0100 | [diff] [blame] | 817 | _zfcp_scsi_dbf_event_common("abrt", tag, 1, |
Andreas Herrmann | 4eff4a3 | 2006-09-18 22:29:20 +0200 | [diff] [blame] | 818 | adapter, scsi_cmnd, new_fsf_req, old_req_id); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 819 | } |
| 820 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 821 | void |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 822 | zfcp_scsi_dbf_event_devreset(const char *tag, u8 flag, struct zfcp_unit *unit, |
| 823 | struct scsi_cmnd *scsi_cmnd) |
| 824 | { |
| 825 | struct zfcp_adapter *adapter = unit->port->adapter; |
| 826 | |
| 827 | _zfcp_scsi_dbf_event_common(flag == FCP_TARGET_RESET ? "trst" : "lrst", |
Andreas Herrmann | 4eff4a3 | 2006-09-18 22:29:20 +0200 | [diff] [blame] | 828 | tag, 1, adapter, scsi_cmnd, NULL, 0); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | static int |
| 832 | zfcp_scsi_dbf_view_format(debug_info_t * id, struct debug_view *view, |
| 833 | char *out_buf, const char *in_buf) |
| 834 | { |
| 835 | struct zfcp_scsi_dbf_record *rec = |
| 836 | (struct zfcp_scsi_dbf_record *)in_buf; |
| 837 | int len = 0; |
| 838 | |
| 839 | if (strncmp(rec->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0) |
| 840 | return 0; |
| 841 | |
| 842 | len += zfcp_dbf_tag(out_buf + len, "tag", rec->tag); |
| 843 | len += zfcp_dbf_tag(out_buf + len, "tag2", rec->tag2); |
| 844 | len += zfcp_dbf_view(out_buf + len, "scsi_id", "0x%08x", rec->scsi_id); |
| 845 | len += zfcp_dbf_view(out_buf + len, "scsi_lun", "0x%08x", |
| 846 | rec->scsi_lun); |
| 847 | len += zfcp_dbf_view(out_buf + len, "scsi_result", "0x%08x", |
| 848 | rec->scsi_result); |
| 849 | len += zfcp_dbf_view(out_buf + len, "scsi_cmnd", "0x%0Lx", |
| 850 | rec->scsi_cmnd); |
| 851 | len += zfcp_dbf_view(out_buf + len, "scsi_serial", "0x%016Lx", |
| 852 | rec->scsi_serial); |
| 853 | len += zfcp_dbf_view_dump(out_buf + len, "scsi_opcode", |
| 854 | rec->scsi_opcode, |
| 855 | ZFCP_DBF_SCSI_OPCODE, |
| 856 | 0, ZFCP_DBF_SCSI_OPCODE); |
| 857 | len += zfcp_dbf_view(out_buf + len, "scsi_retries", "0x%02x", |
| 858 | rec->scsi_retries); |
| 859 | len += zfcp_dbf_view(out_buf + len, "scsi_allowed", "0x%02x", |
| 860 | rec->scsi_allowed); |
Maxim Shchetynin | ed829ad | 2006-02-11 01:42:58 +0100 | [diff] [blame] | 861 | if (strncmp(rec->tag, "abrt", ZFCP_DBF_TAG_SIZE) == 0) { |
| 862 | len += zfcp_dbf_view(out_buf + len, "old_fsf_reqid", "0x%0Lx", |
| 863 | rec->type.old_fsf_reqid); |
| 864 | } |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 865 | len += zfcp_dbf_view(out_buf + len, "fsf_reqid", "0x%0Lx", |
| 866 | rec->fsf_reqid); |
| 867 | len += zfcp_dbf_view(out_buf + len, "fsf_seqno", "0x%08x", |
| 868 | rec->fsf_seqno); |
| 869 | len += zfcp_dbf_stck(out_buf + len, "fsf_issued", rec->fsf_issued); |
| 870 | if (strncmp(rec->tag, "rslt", ZFCP_DBF_TAG_SIZE) == 0) { |
| 871 | len += |
| 872 | zfcp_dbf_view(out_buf + len, "fcp_rsp_validity", "0x%02x", |
| 873 | rec->type.fcp.rsp_validity); |
| 874 | len += |
| 875 | zfcp_dbf_view(out_buf + len, "fcp_rsp_scsi_status", |
| 876 | "0x%02x", rec->type.fcp.rsp_scsi_status); |
| 877 | len += |
| 878 | zfcp_dbf_view(out_buf + len, "fcp_rsp_resid", "0x%08x", |
| 879 | rec->type.fcp.rsp_resid); |
| 880 | len += |
| 881 | zfcp_dbf_view(out_buf + len, "fcp_rsp_code", "0x%08x", |
| 882 | rec->type.fcp.rsp_code); |
| 883 | len += |
| 884 | zfcp_dbf_view(out_buf + len, "fcp_sns_info_len", "0x%08x", |
| 885 | rec->type.fcp.sns_info_len); |
| 886 | len += |
| 887 | zfcp_dbf_view_dump(out_buf + len, "fcp_sns_info", |
| 888 | rec->type.fcp.sns_info, |
| 889 | min((int)rec->type.fcp.sns_info_len, |
| 890 | ZFCP_DBF_SCSI_FCP_SNS_INFO), 0, |
| 891 | rec->type.fcp.sns_info_len); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | len += sprintf(out_buf + len, "\n"); |
| 895 | |
| 896 | return len; |
| 897 | } |
| 898 | |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 899 | static struct debug_view zfcp_scsi_dbf_view = { |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 900 | "structured", |
| 901 | NULL, |
| 902 | &zfcp_dbf_view_header, |
| 903 | &zfcp_scsi_dbf_view_format, |
| 904 | NULL, |
| 905 | NULL |
| 906 | }; |
| 907 | |
| 908 | /** |
| 909 | * zfcp_adapter_debug_register - registers debug feature for an adapter |
| 910 | * @adapter: pointer to adapter for which debug features should be registered |
| 911 | * return: -ENOMEM on error, 0 otherwise |
| 912 | */ |
| 913 | int zfcp_adapter_debug_register(struct zfcp_adapter *adapter) |
| 914 | { |
| 915 | char dbf_name[DEBUG_MAX_NAME_LEN]; |
| 916 | |
| 917 | /* debug feature area which records recovery activity */ |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 918 | sprintf(dbf_name, "zfcp_%s_erp", zfcp_get_busid_by_adapter(adapter)); |
| 919 | adapter->erp_dbf = debug_register(dbf_name, dbfsize, 2, |
| 920 | sizeof(struct zfcp_erp_dbf_record)); |
| 921 | if (!adapter->erp_dbf) |
| 922 | goto failed; |
| 923 | debug_register_view(adapter->erp_dbf, &debug_hex_ascii_view); |
| 924 | debug_set_level(adapter->erp_dbf, 3); |
| 925 | |
| 926 | /* debug feature area which records HBA (FSF and QDIO) conditions */ |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 927 | sprintf(dbf_name, "zfcp_%s_hba", zfcp_get_busid_by_adapter(adapter)); |
| 928 | adapter->hba_dbf = debug_register(dbf_name, dbfsize, 1, |
| 929 | sizeof(struct zfcp_hba_dbf_record)); |
| 930 | if (!adapter->hba_dbf) |
| 931 | goto failed; |
| 932 | debug_register_view(adapter->hba_dbf, &debug_hex_ascii_view); |
| 933 | debug_register_view(adapter->hba_dbf, &zfcp_hba_dbf_view); |
| 934 | debug_set_level(adapter->hba_dbf, 3); |
| 935 | |
| 936 | /* debug feature area which records SAN command failures and recovery */ |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 937 | sprintf(dbf_name, "zfcp_%s_san", zfcp_get_busid_by_adapter(adapter)); |
| 938 | adapter->san_dbf = debug_register(dbf_name, dbfsize, 1, |
| 939 | sizeof(struct zfcp_san_dbf_record)); |
| 940 | if (!adapter->san_dbf) |
| 941 | goto failed; |
| 942 | debug_register_view(adapter->san_dbf, &debug_hex_ascii_view); |
| 943 | debug_register_view(adapter->san_dbf, &zfcp_san_dbf_view); |
| 944 | debug_set_level(adapter->san_dbf, 6); |
| 945 | |
| 946 | /* debug feature area which records SCSI command failures and recovery */ |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 947 | sprintf(dbf_name, "zfcp_%s_scsi", zfcp_get_busid_by_adapter(adapter)); |
| 948 | adapter->scsi_dbf = debug_register(dbf_name, dbfsize, 1, |
| 949 | sizeof(struct zfcp_scsi_dbf_record)); |
| 950 | if (!adapter->scsi_dbf) |
| 951 | goto failed; |
| 952 | debug_register_view(adapter->scsi_dbf, &debug_hex_ascii_view); |
| 953 | debug_register_view(adapter->scsi_dbf, &zfcp_scsi_dbf_view); |
| 954 | debug_set_level(adapter->scsi_dbf, 3); |
| 955 | |
| 956 | return 0; |
| 957 | |
| 958 | failed: |
| 959 | zfcp_adapter_debug_unregister(adapter); |
| 960 | |
| 961 | return -ENOMEM; |
| 962 | } |
| 963 | |
| 964 | /** |
| 965 | * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter |
| 966 | * @adapter: pointer to adapter for which debug features should be unregistered |
| 967 | */ |
| 968 | void zfcp_adapter_debug_unregister(struct zfcp_adapter *adapter) |
| 969 | { |
| 970 | debug_unregister(adapter->scsi_dbf); |
| 971 | debug_unregister(adapter->san_dbf); |
| 972 | debug_unregister(adapter->hba_dbf); |
| 973 | debug_unregister(adapter->erp_dbf); |
| 974 | adapter->scsi_dbf = NULL; |
| 975 | adapter->san_dbf = NULL; |
| 976 | adapter->hba_dbf = NULL; |
| 977 | adapter->erp_dbf = NULL; |
| 978 | } |
| 979 | |
| 980 | #undef ZFCP_LOG_AREA |