Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 1 | /* |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 2 | * zfcp device driver |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 3 | * |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 4 | * Debug traces for zfcp. |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 5 | * |
Swen Schillig | 250a135 | 2010-12-02 15:16:15 +0100 | [diff] [blame] | 6 | * Copyright IBM Corporation 2002, 2010 |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
Christof Schmitt | ecf39d4 | 2008-12-25 13:39:53 +0100 | [diff] [blame] | 9 | #define KMSG_COMPONENT "zfcp" |
| 10 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 11 | |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 12 | #include <linux/ctype.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 13 | #include <linux/slab.h> |
Heiko Carstens | 364c855 | 2007-10-12 16:11:35 +0200 | [diff] [blame] | 14 | #include <asm/debug.h> |
Christof Schmitt | d46f384 | 2009-08-18 15:43:07 +0200 | [diff] [blame] | 15 | #include "zfcp_dbf.h" |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 16 | #include "zfcp_ext.h" |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 17 | #include "zfcp_fc.h" |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 18 | |
| 19 | static u32 dbfsize = 4; |
| 20 | |
| 21 | module_param(dbfsize, uint, 0400); |
| 22 | MODULE_PARM_DESC(dbfsize, |
| 23 | "number of pages for each debug feature area (default 4)"); |
| 24 | |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 25 | static inline unsigned int zfcp_dbf_plen(unsigned int offset) |
Martin Peschke | c15450e | 2008-03-27 14:21:55 +0100 | [diff] [blame] | 26 | { |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 27 | return sizeof(struct zfcp_dbf_pay) + offset - ZFCP_DBF_PAY_MAX_REC; |
| 28 | } |
Martin Peschke | c15450e | 2008-03-27 14:21:55 +0100 | [diff] [blame] | 29 | |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 30 | static inline |
| 31 | void zfcp_dbf_pl_write(struct zfcp_dbf *dbf, void *data, u16 length, char *area, |
| 32 | u64 req_id) |
| 33 | { |
| 34 | struct zfcp_dbf_pay *pl = &dbf->pay_buf; |
| 35 | u16 offset = 0, rec_length; |
| 36 | |
| 37 | spin_lock(&dbf->pay_lock); |
| 38 | memset(pl, 0, sizeof(*pl)); |
| 39 | pl->fsf_req_id = req_id; |
| 40 | memcpy(pl->area, area, ZFCP_DBF_TAG_LEN); |
| 41 | |
| 42 | while (offset < length) { |
| 43 | rec_length = min((u16) ZFCP_DBF_PAY_MAX_REC, |
| 44 | (u16) (length - offset)); |
| 45 | memcpy(pl->data, data + offset, rec_length); |
| 46 | debug_event(dbf->pay, 1, pl, zfcp_dbf_plen(rec_length)); |
| 47 | |
| 48 | offset += rec_length; |
| 49 | pl->counter++; |
Martin Peschke | c15450e | 2008-03-27 14:21:55 +0100 | [diff] [blame] | 50 | } |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 51 | |
| 52 | spin_unlock(&dbf->pay_lock); |
Martin Peschke | c15450e | 2008-03-27 14:21:55 +0100 | [diff] [blame] | 53 | } |
| 54 | |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 55 | /** |
| 56 | * zfcp_dbf_hba_fsf_res - trace event for fsf responses |
| 57 | * @tag: tag indicating which kind of unsolicited status has been received |
| 58 | * @req: request for which a response was received |
| 59 | */ |
| 60 | void zfcp_dbf_hba_fsf_res(char *tag, struct zfcp_fsf_req *req) |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 61 | { |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 62 | struct zfcp_dbf *dbf = req->adapter->dbf; |
| 63 | struct fsf_qtcb_prefix *q_pref = &req->qtcb->prefix; |
| 64 | struct fsf_qtcb_header *q_head = &req->qtcb->header; |
| 65 | struct zfcp_dbf_hba *rec = &dbf->hba_buf; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 66 | unsigned long flags; |
| 67 | |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 68 | spin_lock_irqsave(&dbf->hba_lock, flags); |
Martin Peschke | 6bc473d | 2008-03-31 11:15:29 +0200 | [diff] [blame] | 69 | memset(rec, 0, sizeof(*rec)); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 70 | |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 71 | memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN); |
| 72 | rec->id = ZFCP_DBF_HBA_RES; |
| 73 | rec->fsf_req_id = req->req_id; |
| 74 | rec->fsf_req_status = req->status; |
| 75 | rec->fsf_cmd = req->fsf_command; |
| 76 | rec->fsf_seq_no = req->seq_no; |
| 77 | rec->u.res.req_issued = req->issued; |
| 78 | rec->u.res.prot_status = q_pref->prot_status; |
| 79 | rec->u.res.fsf_status = q_head->fsf_status; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 80 | |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 81 | memcpy(rec->u.res.prot_status_qual, &q_pref->prot_status_qual, |
| 82 | FSF_PROT_STATUS_QUAL_SIZE); |
| 83 | memcpy(rec->u.res.fsf_status_qual, &q_head->fsf_status_qual, |
| 84 | FSF_STATUS_QUALIFIER_SIZE); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 85 | |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 86 | if (req->fsf_command != FSF_QTCB_FCP_CMND) { |
| 87 | rec->pl_len = q_head->log_length; |
| 88 | zfcp_dbf_pl_write(dbf, (char *)q_pref + q_head->log_start, |
| 89 | rec->pl_len, "fsf_res", req->req_id); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 90 | } |
| 91 | |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 92 | debug_event(dbf->hba, 1, rec, sizeof(*rec)); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 93 | spin_unlock_irqrestore(&dbf->hba_lock, flags); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 94 | } |
| 95 | |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 96 | /** |
| 97 | * zfcp_dbf_hba_fsf_uss - trace event for an unsolicited status buffer |
| 98 | * @tag: tag indicating which kind of unsolicited status has been received |
| 99 | * @req: request providing the unsolicited status |
| 100 | */ |
| 101 | void zfcp_dbf_hba_fsf_uss(char *tag, struct zfcp_fsf_req *req) |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 102 | { |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 103 | struct zfcp_dbf *dbf = req->adapter->dbf; |
| 104 | struct fsf_status_read_buffer *srb = req->data; |
| 105 | struct zfcp_dbf_hba *rec = &dbf->hba_buf; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 106 | unsigned long flags; |
| 107 | |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 108 | spin_lock_irqsave(&dbf->hba_lock, flags); |
Martin Peschke | 6bc473d | 2008-03-31 11:15:29 +0200 | [diff] [blame] | 109 | memset(rec, 0, sizeof(*rec)); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 110 | |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 111 | memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN); |
| 112 | rec->id = ZFCP_DBF_HBA_USS; |
| 113 | rec->fsf_req_id = req->req_id; |
| 114 | rec->fsf_req_status = req->status; |
| 115 | rec->fsf_cmd = req->fsf_command; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 116 | |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 117 | if (!srb) |
| 118 | goto log; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 119 | |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 120 | rec->u.uss.status_type = srb->status_type; |
| 121 | rec->u.uss.status_subtype = srb->status_subtype; |
| 122 | rec->u.uss.d_id = ntoh24(srb->d_id); |
| 123 | rec->u.uss.lun = srb->fcp_lun; |
| 124 | memcpy(&rec->u.uss.queue_designator, &srb->queue_designator, |
| 125 | sizeof(rec->u.uss.queue_designator)); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 126 | |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 127 | /* status read buffer payload length */ |
| 128 | rec->pl_len = (!srb->length) ? 0 : srb->length - |
| 129 | offsetof(struct fsf_status_read_buffer, payload); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 130 | |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 131 | if (rec->pl_len) |
| 132 | zfcp_dbf_pl_write(dbf, srb->payload.data, rec->pl_len, |
| 133 | "fsf_uss", req->req_id); |
| 134 | log: |
| 135 | debug_event(dbf->hba, 2, rec, sizeof(*rec)); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 136 | spin_unlock_irqrestore(&dbf->hba_lock, flags); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 137 | } |
| 138 | |
Martin Peschke | bfab163 | 2008-03-31 11:15:31 +0200 | [diff] [blame] | 139 | /** |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 140 | * zfcp_dbf_hba_bit_err - trace event for bit error conditions |
| 141 | * @tag: tag indicating which kind of unsolicited status has been received |
| 142 | * @req: request which caused the bit_error condition |
Martin Peschke | bfab163 | 2008-03-31 11:15:31 +0200 | [diff] [blame] | 143 | */ |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 144 | void zfcp_dbf_hba_bit_err(char *tag, struct zfcp_fsf_req *req) |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 145 | { |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 146 | struct zfcp_dbf *dbf = req->adapter->dbf; |
| 147 | struct zfcp_dbf_hba *rec = &dbf->hba_buf; |
Swen Schillig | 5706938 | 2008-10-01 12:42:21 +0200 | [diff] [blame] | 148 | struct fsf_status_read_buffer *sr_buf = req->data; |
Swen Schillig | 5706938 | 2008-10-01 12:42:21 +0200 | [diff] [blame] | 149 | unsigned long flags; |
| 150 | |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 151 | spin_lock_irqsave(&dbf->hba_lock, flags); |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 152 | memset(rec, 0, sizeof(*rec)); |
| 153 | |
| 154 | memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN); |
| 155 | rec->id = ZFCP_DBF_HBA_BIT; |
| 156 | rec->fsf_req_id = req->req_id; |
| 157 | rec->fsf_req_status = req->status; |
| 158 | rec->fsf_cmd = req->fsf_command; |
| 159 | memcpy(&rec->u.be, &sr_buf->payload.bit_error, |
| 160 | sizeof(struct fsf_bit_error_payload)); |
| 161 | |
| 162 | debug_event(dbf->hba, 1, rec, sizeof(*rec)); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 163 | spin_unlock_irqrestore(&dbf->hba_lock, flags); |
Swen Schillig | 5706938 | 2008-10-01 12:42:21 +0200 | [diff] [blame] | 164 | } |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 165 | |
Swen Schillig | 86a9668 | 2011-08-15 14:40:32 +0200 | [diff] [blame^] | 166 | /** |
| 167 | * zfcp_dbf_hba_def_err - trace event for deferred error messages |
| 168 | * @adapter: pointer to struct zfcp_adapter |
| 169 | * @req_id: request id which caused the deferred error message |
| 170 | * @scount: number of sbals incl. the signaling sbal |
| 171 | * @pl: array of all involved sbals |
| 172 | */ |
| 173 | void zfcp_dbf_hba_def_err(struct zfcp_adapter *adapter, u64 req_id, u16 scount, |
| 174 | void **pl) |
| 175 | { |
| 176 | struct zfcp_dbf *dbf = adapter->dbf; |
| 177 | struct zfcp_dbf_pay *payload = &dbf->pay_buf; |
| 178 | unsigned long flags; |
| 179 | u16 length; |
| 180 | |
| 181 | if (!pl) |
| 182 | return; |
| 183 | |
| 184 | spin_lock_irqsave(&dbf->pay_lock, flags); |
| 185 | memset(payload, 0, sizeof(*payload)); |
| 186 | |
| 187 | memcpy(payload->area, "def_err", 7); |
| 188 | payload->fsf_req_id = req_id; |
| 189 | payload->counter = 0; |
| 190 | length = min((u16)sizeof(struct qdio_buffer), |
| 191 | (u16)ZFCP_DBF_PAY_MAX_REC); |
| 192 | |
| 193 | while ((char *)pl[payload->counter] && payload->counter < scount) { |
| 194 | memcpy(payload->data, (char *)pl[payload->counter], length); |
| 195 | debug_event(dbf->pay, 1, payload, zfcp_dbf_plen(length)); |
| 196 | payload->counter++; |
| 197 | } |
| 198 | |
| 199 | spin_unlock_irqrestore(&dbf->pay_lock, flags); |
| 200 | } |
| 201 | |
Swen Schillig | ae0904f | 2010-12-02 15:16:12 +0100 | [diff] [blame] | 202 | static void zfcp_dbf_set_common(struct zfcp_dbf_rec *rec, |
| 203 | struct zfcp_adapter *adapter, |
| 204 | struct zfcp_port *port, |
| 205 | struct scsi_device *sdev) |
Martin Peschke | d79a83d | 2008-03-27 14:22:00 +0100 | [diff] [blame] | 206 | { |
Swen Schillig | ae0904f | 2010-12-02 15:16:12 +0100 | [diff] [blame] | 207 | rec->adapter_status = atomic_read(&adapter->status); |
| 208 | if (port) { |
| 209 | rec->port_status = atomic_read(&port->status); |
| 210 | rec->wwpn = port->wwpn; |
| 211 | rec->d_id = port->d_id; |
Martin Peschke | d79a83d | 2008-03-27 14:22:00 +0100 | [diff] [blame] | 212 | } |
Swen Schillig | ae0904f | 2010-12-02 15:16:12 +0100 | [diff] [blame] | 213 | if (sdev) { |
| 214 | rec->lun_status = atomic_read(&sdev_to_zfcp(sdev)->status); |
| 215 | rec->lun = zfcp_scsi_dev_lun(sdev); |
| 216 | } |
Martin Peschke | 348447e | 2008-03-27 14:22:01 +0100 | [diff] [blame] | 217 | } |
| 218 | |
Christof Schmitt | aa0fec6 | 2008-05-19 12:17:47 +0200 | [diff] [blame] | 219 | /** |
Swen Schillig | ae0904f | 2010-12-02 15:16:12 +0100 | [diff] [blame] | 220 | * zfcp_dbf_rec_trig - trace event related to triggered recovery |
| 221 | * @tag: identifier for event |
| 222 | * @adapter: adapter on which the erp_action should run |
| 223 | * @port: remote port involved in the erp_action |
| 224 | * @sdev: scsi device involved in the erp_action |
| 225 | * @want: wanted erp_action |
| 226 | * @need: required erp_action |
| 227 | * |
| 228 | * The adapter->erp_lock has to be held. |
Christof Schmitt | aa0fec6 | 2008-05-19 12:17:47 +0200 | [diff] [blame] | 229 | */ |
Swen Schillig | ae0904f | 2010-12-02 15:16:12 +0100 | [diff] [blame] | 230 | void zfcp_dbf_rec_trig(char *tag, struct zfcp_adapter *adapter, |
| 231 | struct zfcp_port *port, struct scsi_device *sdev, |
| 232 | u8 want, u8 need) |
Martin Peschke | 9467a9b | 2008-03-27 14:22:03 +0100 | [diff] [blame] | 233 | { |
Christof Schmitt | d46f384 | 2009-08-18 15:43:07 +0200 | [diff] [blame] | 234 | struct zfcp_dbf *dbf = adapter->dbf; |
Swen Schillig | ae0904f | 2010-12-02 15:16:12 +0100 | [diff] [blame] | 235 | struct zfcp_dbf_rec *rec = &dbf->rec_buf; |
| 236 | struct list_head *entry; |
Martin Peschke | 9467a9b | 2008-03-27 14:22:03 +0100 | [diff] [blame] | 237 | unsigned long flags; |
| 238 | |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 239 | spin_lock_irqsave(&dbf->rec_lock, flags); |
Swen Schillig | ae0904f | 2010-12-02 15:16:12 +0100 | [diff] [blame] | 240 | memset(rec, 0, sizeof(*rec)); |
| 241 | |
| 242 | rec->id = ZFCP_DBF_REC_TRIG; |
| 243 | memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN); |
| 244 | zfcp_dbf_set_common(rec, adapter, port, sdev); |
| 245 | |
| 246 | list_for_each(entry, &adapter->erp_ready_head) |
| 247 | rec->u.trig.ready++; |
| 248 | |
| 249 | list_for_each(entry, &adapter->erp_running_head) |
| 250 | rec->u.trig.running++; |
| 251 | |
| 252 | rec->u.trig.want = want; |
| 253 | rec->u.trig.need = need; |
| 254 | |
| 255 | debug_event(dbf->rec, 1, rec, sizeof(*rec)); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 256 | spin_unlock_irqrestore(&dbf->rec_lock, flags); |
Martin Peschke | 9467a9b | 2008-03-27 14:22:03 +0100 | [diff] [blame] | 257 | } |
| 258 | |
Swen Schillig | ae0904f | 2010-12-02 15:16:12 +0100 | [diff] [blame] | 259 | |
Martin Peschke | 6f4f365 | 2008-03-27 14:22:04 +0100 | [diff] [blame] | 260 | /** |
Swen Schillig | ae0904f | 2010-12-02 15:16:12 +0100 | [diff] [blame] | 261 | * zfcp_dbf_rec_run - trace event related to running recovery |
| 262 | * @tag: identifier for event |
| 263 | * @erp: erp_action running |
Martin Peschke | 6f4f365 | 2008-03-27 14:22:04 +0100 | [diff] [blame] | 264 | */ |
Swen Schillig | ae0904f | 2010-12-02 15:16:12 +0100 | [diff] [blame] | 265 | void zfcp_dbf_rec_run(char *tag, struct zfcp_erp_action *erp) |
Martin Peschke | 6f4f365 | 2008-03-27 14:22:04 +0100 | [diff] [blame] | 266 | { |
Swen Schillig | ae0904f | 2010-12-02 15:16:12 +0100 | [diff] [blame] | 267 | struct zfcp_dbf *dbf = erp->adapter->dbf; |
| 268 | struct zfcp_dbf_rec *rec = &dbf->rec_buf; |
Martin Peschke | 6f4f365 | 2008-03-27 14:22:04 +0100 | [diff] [blame] | 269 | unsigned long flags; |
| 270 | |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 271 | spin_lock_irqsave(&dbf->rec_lock, flags); |
Swen Schillig | ae0904f | 2010-12-02 15:16:12 +0100 | [diff] [blame] | 272 | memset(rec, 0, sizeof(*rec)); |
| 273 | |
| 274 | rec->id = ZFCP_DBF_REC_RUN; |
| 275 | memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN); |
| 276 | zfcp_dbf_set_common(rec, erp->adapter, erp->port, erp->sdev); |
| 277 | |
| 278 | rec->u.run.fsf_req_id = erp->fsf_req_id; |
| 279 | rec->u.run.rec_status = erp->status; |
| 280 | rec->u.run.rec_step = erp->step; |
| 281 | rec->u.run.rec_action = erp->action; |
| 282 | |
| 283 | if (erp->sdev) |
| 284 | rec->u.run.rec_count = |
| 285 | atomic_read(&sdev_to_zfcp(erp->sdev)->erp_counter); |
| 286 | else if (erp->port) |
| 287 | rec->u.run.rec_count = atomic_read(&erp->port->erp_counter); |
| 288 | else |
| 289 | rec->u.run.rec_count = atomic_read(&erp->adapter->erp_counter); |
| 290 | |
| 291 | debug_event(dbf->rec, 1, rec, sizeof(*rec)); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 292 | spin_unlock_irqrestore(&dbf->rec_lock, flags); |
Martin Peschke | 6f4f365 | 2008-03-27 14:22:04 +0100 | [diff] [blame] | 293 | } |
| 294 | |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 295 | static inline |
| 296 | void zfcp_dbf_san(char *tag, struct zfcp_dbf *dbf, void *data, u8 id, u16 len, |
| 297 | u64 req_id, u32 d_id) |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 298 | { |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 299 | struct zfcp_dbf_san *rec = &dbf->san_buf; |
| 300 | u16 rec_len; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 301 | unsigned long flags; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 302 | |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 303 | spin_lock_irqsave(&dbf->san_lock, flags); |
Martin Peschke | 6bc473d | 2008-03-31 11:15:29 +0200 | [diff] [blame] | 304 | memset(rec, 0, sizeof(*rec)); |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 305 | |
| 306 | rec->id = id; |
| 307 | rec->fsf_req_id = req_id; |
| 308 | rec->d_id = d_id; |
| 309 | rec_len = min(len, (u16)ZFCP_DBF_SAN_MAX_PAYLOAD); |
| 310 | memcpy(rec->payload, data, rec_len); |
| 311 | memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN); |
| 312 | |
| 313 | debug_event(dbf->san, 1, rec, sizeof(*rec)); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 314 | spin_unlock_irqrestore(&dbf->san_lock, flags); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 315 | } |
| 316 | |
Martin Peschke | bfab163 | 2008-03-31 11:15:31 +0200 | [diff] [blame] | 317 | /** |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 318 | * zfcp_dbf_san_req - trace event for issued SAN request |
| 319 | * @tag: indentifier for event |
| 320 | * @fsf_req: request containing issued CT data |
| 321 | * d_id: destination ID |
Martin Peschke | bfab163 | 2008-03-31 11:15:31 +0200 | [diff] [blame] | 322 | */ |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 323 | void zfcp_dbf_san_req(char *tag, struct zfcp_fsf_req *fsf, u32 d_id) |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 324 | { |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 325 | struct zfcp_dbf *dbf = fsf->adapter->dbf; |
| 326 | struct zfcp_fsf_ct_els *ct_els = fsf->data; |
| 327 | u16 length; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 328 | |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 329 | length = (u16)(ct_els->req->length + FC_CT_HDR_LEN); |
| 330 | zfcp_dbf_san(tag, dbf, sg_virt(ct_els->req), ZFCP_DBF_SAN_REQ, length, |
| 331 | fsf->req_id, d_id); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 332 | } |
| 333 | |
Martin Peschke | bfab163 | 2008-03-31 11:15:31 +0200 | [diff] [blame] | 334 | /** |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 335 | * zfcp_dbf_san_res - trace event for received SAN request |
| 336 | * @tag: indentifier for event |
| 337 | * @fsf_req: request containing issued CT data |
Martin Peschke | bfab163 | 2008-03-31 11:15:31 +0200 | [diff] [blame] | 338 | */ |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 339 | void zfcp_dbf_san_res(char *tag, struct zfcp_fsf_req *fsf) |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 340 | { |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 341 | struct zfcp_dbf *dbf = fsf->adapter->dbf; |
| 342 | struct zfcp_fsf_ct_els *ct_els = fsf->data; |
| 343 | u16 length; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 344 | |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 345 | length = (u16)(ct_els->resp->length + FC_CT_HDR_LEN); |
| 346 | zfcp_dbf_san(tag, dbf, sg_virt(ct_els->resp), ZFCP_DBF_SAN_RES, length, |
| 347 | fsf->req_id, 0); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 348 | } |
| 349 | |
Martin Peschke | bfab163 | 2008-03-31 11:15:31 +0200 | [diff] [blame] | 350 | /** |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 351 | * zfcp_dbf_san_in_els - trace event for incoming ELS |
| 352 | * @tag: indentifier for event |
| 353 | * @fsf_req: request containing issued CT data |
Martin Peschke | bfab163 | 2008-03-31 11:15:31 +0200 | [diff] [blame] | 354 | */ |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 355 | void zfcp_dbf_san_in_els(char *tag, struct zfcp_fsf_req *fsf) |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 356 | { |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 357 | struct zfcp_dbf *dbf = fsf->adapter->dbf; |
| 358 | struct fsf_status_read_buffer *srb = |
| 359 | (struct fsf_status_read_buffer *) fsf->data; |
| 360 | u16 length; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 361 | |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 362 | length = (u16)(srb->length - |
| 363 | offsetof(struct fsf_status_read_buffer, payload)); |
| 364 | zfcp_dbf_san(tag, dbf, srb->payload.data, ZFCP_DBF_SAN_ELS, length, |
| 365 | fsf->req_id, ntoh24(srb->d_id)); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 366 | } |
| 367 | |
Swen Schillig | 250a135 | 2010-12-02 15:16:15 +0100 | [diff] [blame] | 368 | /** |
| 369 | * zfcp_dbf_scsi - trace event for scsi commands |
| 370 | * @tag: identifier for event |
| 371 | * @sc: pointer to struct scsi_cmnd |
| 372 | * @fsf: pointer to struct zfcp_fsf_req |
| 373 | */ |
| 374 | void zfcp_dbf_scsi(char *tag, struct scsi_cmnd *sc, struct zfcp_fsf_req *fsf) |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 375 | { |
Swen Schillig | 250a135 | 2010-12-02 15:16:15 +0100 | [diff] [blame] | 376 | struct zfcp_adapter *adapter = |
| 377 | (struct zfcp_adapter *) sc->device->host->hostdata[0]; |
| 378 | struct zfcp_dbf *dbf = adapter->dbf; |
| 379 | struct zfcp_dbf_scsi *rec = &dbf->scsi_buf; |
Christof Schmitt | 4318e08 | 2009-11-24 16:54:08 +0100 | [diff] [blame] | 380 | struct fcp_resp_with_ext *fcp_rsp; |
Swen Schillig | 250a135 | 2010-12-02 15:16:15 +0100 | [diff] [blame] | 381 | struct fcp_resp_rsp_info *fcp_rsp_info; |
| 382 | unsigned long flags; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 383 | |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 384 | spin_lock_irqsave(&dbf->scsi_lock, flags); |
Swen Schillig | 250a135 | 2010-12-02 15:16:15 +0100 | [diff] [blame] | 385 | memset(rec, 0, sizeof(*rec)); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 386 | |
Swen Schillig | 250a135 | 2010-12-02 15:16:15 +0100 | [diff] [blame] | 387 | memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN); |
| 388 | rec->id = ZFCP_DBF_SCSI_CMND; |
| 389 | rec->scsi_result = sc->result; |
| 390 | rec->scsi_retries = sc->retries; |
| 391 | rec->scsi_allowed = sc->allowed; |
| 392 | rec->scsi_id = sc->device->id; |
| 393 | rec->scsi_lun = sc->device->lun; |
| 394 | rec->host_scribble = (unsigned long)sc->host_scribble; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 395 | |
Swen Schillig | 250a135 | 2010-12-02 15:16:15 +0100 | [diff] [blame] | 396 | memcpy(rec->scsi_opcode, sc->cmnd, |
| 397 | min((int)sc->cmd_len, ZFCP_DBF_SCSI_OPCODE)); |
| 398 | |
| 399 | if (fsf) { |
| 400 | rec->fsf_req_id = fsf->req_id; |
| 401 | fcp_rsp = (struct fcp_resp_with_ext *) |
| 402 | &(fsf->qtcb->bottom.io.fcp_rsp); |
| 403 | memcpy(&rec->fcp_rsp, fcp_rsp, FCP_RESP_WITH_EXT); |
| 404 | if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL) { |
| 405 | fcp_rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1]; |
| 406 | rec->fcp_rsp_info = fcp_rsp_info->rsp_code; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 407 | } |
Swen Schillig | 250a135 | 2010-12-02 15:16:15 +0100 | [diff] [blame] | 408 | if (fcp_rsp->resp.fr_flags & FCP_SNS_LEN_VAL) { |
| 409 | rec->pl_len = min((u16)SCSI_SENSE_BUFFERSIZE, |
| 410 | (u16)ZFCP_DBF_PAY_MAX_REC); |
| 411 | zfcp_dbf_pl_write(dbf, sc->sense_buffer, rec->pl_len, |
| 412 | "fcp_sns", fsf->req_id); |
| 413 | } |
| 414 | } |
| 415 | |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 416 | debug_event(dbf->scsi, 1, rec, sizeof(*rec)); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 417 | spin_unlock_irqrestore(&dbf->scsi_lock, flags); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 418 | } |
| 419 | |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 420 | static debug_info_t *zfcp_dbf_reg(const char *name, int size, int rec_size) |
Christof Schmitt | d46f384 | 2009-08-18 15:43:07 +0200 | [diff] [blame] | 421 | { |
| 422 | struct debug_info *d; |
| 423 | |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 424 | d = debug_register(name, size, 1, rec_size); |
Christof Schmitt | d46f384 | 2009-08-18 15:43:07 +0200 | [diff] [blame] | 425 | if (!d) |
| 426 | return NULL; |
| 427 | |
| 428 | debug_register_view(d, &debug_hex_ascii_view); |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 429 | debug_set_level(d, 3); |
Christof Schmitt | d46f384 | 2009-08-18 15:43:07 +0200 | [diff] [blame] | 430 | |
| 431 | return d; |
| 432 | } |
| 433 | |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 434 | static void zfcp_dbf_unregister(struct zfcp_dbf *dbf) |
| 435 | { |
| 436 | if (!dbf) |
| 437 | return; |
| 438 | |
| 439 | debug_unregister(dbf->scsi); |
| 440 | debug_unregister(dbf->san); |
| 441 | debug_unregister(dbf->hba); |
| 442 | debug_unregister(dbf->pay); |
| 443 | debug_unregister(dbf->rec); |
| 444 | kfree(dbf); |
| 445 | } |
| 446 | |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 447 | /** |
| 448 | * zfcp_adapter_debug_register - registers debug feature for an adapter |
| 449 | * @adapter: pointer to adapter for which debug features should be registered |
| 450 | * return: -ENOMEM on error, 0 otherwise |
| 451 | */ |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 452 | int zfcp_dbf_adapter_register(struct zfcp_adapter *adapter) |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 453 | { |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 454 | char name[DEBUG_MAX_NAME_LEN]; |
Christof Schmitt | d46f384 | 2009-08-18 15:43:07 +0200 | [diff] [blame] | 455 | struct zfcp_dbf *dbf; |
| 456 | |
Swen Schillig | d23948e | 2010-07-16 15:37:40 +0200 | [diff] [blame] | 457 | dbf = kzalloc(sizeof(struct zfcp_dbf), GFP_KERNEL); |
Christof Schmitt | d46f384 | 2009-08-18 15:43:07 +0200 | [diff] [blame] | 458 | if (!dbf) |
| 459 | return -ENOMEM; |
| 460 | |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 461 | spin_lock_init(&dbf->pay_lock); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 462 | spin_lock_init(&dbf->hba_lock); |
| 463 | spin_lock_init(&dbf->san_lock); |
| 464 | spin_lock_init(&dbf->scsi_lock); |
| 465 | spin_lock_init(&dbf->rec_lock); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 466 | |
| 467 | /* debug feature area which records recovery activity */ |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 468 | sprintf(name, "zfcp_%s_rec", dev_name(&adapter->ccw_device->dev)); |
| 469 | dbf->rec = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_rec)); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 470 | if (!dbf->rec) |
| 471 | goto err_out; |
Martin Peschke | d79a83d | 2008-03-27 14:22:00 +0100 | [diff] [blame] | 472 | |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 473 | /* debug feature area which records HBA (FSF and QDIO) conditions */ |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 474 | sprintf(name, "zfcp_%s_hba", dev_name(&adapter->ccw_device->dev)); |
| 475 | dbf->hba = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_hba)); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 476 | if (!dbf->hba) |
| 477 | goto err_out; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 478 | |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 479 | /* debug feature area which records payload info */ |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 480 | sprintf(name, "zfcp_%s_pay", dev_name(&adapter->ccw_device->dev)); |
| 481 | dbf->pay = zfcp_dbf_reg(name, dbfsize * 2, sizeof(struct zfcp_dbf_pay)); |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 482 | if (!dbf->pay) |
| 483 | goto err_out; |
| 484 | |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 485 | /* debug feature area which records SAN command failures and recovery */ |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 486 | sprintf(name, "zfcp_%s_san", dev_name(&adapter->ccw_device->dev)); |
| 487 | dbf->san = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_san)); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 488 | if (!dbf->san) |
| 489 | goto err_out; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 490 | |
| 491 | /* debug feature area which records SCSI command failures and recovery */ |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 492 | sprintf(name, "zfcp_%s_scsi", dev_name(&adapter->ccw_device->dev)); |
| 493 | dbf->scsi = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_scsi)); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 494 | if (!dbf->scsi) |
| 495 | goto err_out; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 496 | |
Christof Schmitt | d46f384 | 2009-08-18 15:43:07 +0200 | [diff] [blame] | 497 | adapter->dbf = dbf; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 498 | |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 499 | return 0; |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 500 | err_out: |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 501 | zfcp_dbf_unregister(dbf); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 502 | return -ENOMEM; |
| 503 | } |
| 504 | |
| 505 | /** |
| 506 | * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 507 | * @adapter: pointer to adapter for which debug features should be unregistered |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 508 | */ |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 509 | void zfcp_dbf_adapter_unregister(struct zfcp_adapter *adapter) |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 510 | { |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 511 | struct zfcp_dbf *dbf = adapter->dbf; |
| 512 | |
| 513 | adapter->dbf = NULL; |
| 514 | zfcp_dbf_unregister(dbf); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 515 | } |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 516 | |