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 | * |
Steffen Maier | aceeffb | 2016-08-10 18:30:53 +0200 | [diff] [blame] | 6 | * Copyright IBM Corp. 2002, 2016 |
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 | |
Heiko Carstens | 3a4c5d5 | 2011-07-30 09:25:15 +0200 | [diff] [blame] | 12 | #include <linux/module.h> |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 13 | #include <linux/ctype.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 14 | #include <linux/slab.h> |
Heiko Carstens | 364c855 | 2007-10-12 16:11:35 +0200 | [diff] [blame] | 15 | #include <asm/debug.h> |
Christof Schmitt | d46f384 | 2009-08-18 15:43:07 +0200 | [diff] [blame] | 16 | #include "zfcp_dbf.h" |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 17 | #include "zfcp_ext.h" |
Christof Schmitt | bd0072e | 2009-11-24 16:54:11 +0100 | [diff] [blame] | 18 | #include "zfcp_fc.h" |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 19 | |
| 20 | static u32 dbfsize = 4; |
| 21 | |
| 22 | module_param(dbfsize, uint, 0400); |
| 23 | MODULE_PARM_DESC(dbfsize, |
| 24 | "number of pages for each debug feature area (default 4)"); |
| 25 | |
Steffen Maier | bf3ea3a | 2013-04-26 16:13:53 +0200 | [diff] [blame] | 26 | static u32 dbflevel = 3; |
| 27 | |
| 28 | module_param(dbflevel, uint, 0400); |
| 29 | MODULE_PARM_DESC(dbflevel, |
| 30 | "log level for each debug feature area " |
| 31 | "(default 3, range 0..6)"); |
| 32 | |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 33 | static inline unsigned int zfcp_dbf_plen(unsigned int offset) |
Martin Peschke | c15450e | 2008-03-27 14:21:55 +0100 | [diff] [blame] | 34 | { |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 35 | return sizeof(struct zfcp_dbf_pay) + offset - ZFCP_DBF_PAY_MAX_REC; |
| 36 | } |
Martin Peschke | c15450e | 2008-03-27 14:21:55 +0100 | [diff] [blame] | 37 | |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 38 | static inline |
| 39 | void zfcp_dbf_pl_write(struct zfcp_dbf *dbf, void *data, u16 length, char *area, |
| 40 | u64 req_id) |
| 41 | { |
| 42 | struct zfcp_dbf_pay *pl = &dbf->pay_buf; |
| 43 | u16 offset = 0, rec_length; |
| 44 | |
| 45 | spin_lock(&dbf->pay_lock); |
| 46 | memset(pl, 0, sizeof(*pl)); |
| 47 | pl->fsf_req_id = req_id; |
| 48 | memcpy(pl->area, area, ZFCP_DBF_TAG_LEN); |
| 49 | |
| 50 | while (offset < length) { |
| 51 | rec_length = min((u16) ZFCP_DBF_PAY_MAX_REC, |
| 52 | (u16) (length - offset)); |
| 53 | memcpy(pl->data, data + offset, rec_length); |
| 54 | debug_event(dbf->pay, 1, pl, zfcp_dbf_plen(rec_length)); |
| 55 | |
| 56 | offset += rec_length; |
| 57 | pl->counter++; |
Martin Peschke | c15450e | 2008-03-27 14:21:55 +0100 | [diff] [blame] | 58 | } |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 59 | |
| 60 | spin_unlock(&dbf->pay_lock); |
Martin Peschke | c15450e | 2008-03-27 14:21:55 +0100 | [diff] [blame] | 61 | } |
| 62 | |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 63 | /** |
| 64 | * zfcp_dbf_hba_fsf_res - trace event for fsf responses |
| 65 | * @tag: tag indicating which kind of unsolicited status has been received |
| 66 | * @req: request for which a response was received |
| 67 | */ |
Steffen Maier | 35f040d | 2016-08-10 18:30:47 +0200 | [diff] [blame] | 68 | void zfcp_dbf_hba_fsf_res(char *tag, int level, struct zfcp_fsf_req *req) |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 69 | { |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 70 | struct zfcp_dbf *dbf = req->adapter->dbf; |
| 71 | struct fsf_qtcb_prefix *q_pref = &req->qtcb->prefix; |
| 72 | struct fsf_qtcb_header *q_head = &req->qtcb->header; |
| 73 | struct zfcp_dbf_hba *rec = &dbf->hba_buf; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 74 | unsigned long flags; |
| 75 | |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 76 | spin_lock_irqsave(&dbf->hba_lock, flags); |
Martin Peschke | 6bc473d | 2008-03-31 11:15:29 +0200 | [diff] [blame] | 77 | memset(rec, 0, sizeof(*rec)); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 78 | |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 79 | memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN); |
| 80 | rec->id = ZFCP_DBF_HBA_RES; |
| 81 | rec->fsf_req_id = req->req_id; |
| 82 | rec->fsf_req_status = req->status; |
| 83 | rec->fsf_cmd = req->fsf_command; |
| 84 | rec->fsf_seq_no = req->seq_no; |
| 85 | rec->u.res.req_issued = req->issued; |
| 86 | rec->u.res.prot_status = q_pref->prot_status; |
| 87 | rec->u.res.fsf_status = q_head->fsf_status; |
Steffen Maier | 7c964ff | 2016-08-10 18:30:50 +0200 | [diff] [blame] | 88 | rec->u.res.port_handle = q_head->port_handle; |
| 89 | rec->u.res.lun_handle = q_head->lun_handle; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 90 | |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 91 | memcpy(rec->u.res.prot_status_qual, &q_pref->prot_status_qual, |
| 92 | FSF_PROT_STATUS_QUAL_SIZE); |
| 93 | memcpy(rec->u.res.fsf_status_qual, &q_head->fsf_status_qual, |
| 94 | FSF_STATUS_QUALIFIER_SIZE); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 95 | |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 96 | if (req->fsf_command != FSF_QTCB_FCP_CMND) { |
| 97 | rec->pl_len = q_head->log_length; |
| 98 | zfcp_dbf_pl_write(dbf, (char *)q_pref + q_head->log_start, |
| 99 | rec->pl_len, "fsf_res", req->req_id); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 100 | } |
| 101 | |
Steffen Maier | 35f040d | 2016-08-10 18:30:47 +0200 | [diff] [blame] | 102 | debug_event(dbf->hba, level, rec, sizeof(*rec)); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 103 | spin_unlock_irqrestore(&dbf->hba_lock, flags); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 104 | } |
| 105 | |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 106 | /** |
| 107 | * zfcp_dbf_hba_fsf_uss - trace event for an unsolicited status buffer |
| 108 | * @tag: tag indicating which kind of unsolicited status has been received |
| 109 | * @req: request providing the unsolicited status |
| 110 | */ |
| 111 | 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] | 112 | { |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 113 | struct zfcp_dbf *dbf = req->adapter->dbf; |
| 114 | struct fsf_status_read_buffer *srb = req->data; |
| 115 | struct zfcp_dbf_hba *rec = &dbf->hba_buf; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 116 | unsigned long flags; |
| 117 | |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 118 | spin_lock_irqsave(&dbf->hba_lock, flags); |
Martin Peschke | 6bc473d | 2008-03-31 11:15:29 +0200 | [diff] [blame] | 119 | memset(rec, 0, sizeof(*rec)); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 120 | |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 121 | memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN); |
| 122 | rec->id = ZFCP_DBF_HBA_USS; |
| 123 | rec->fsf_req_id = req->req_id; |
| 124 | rec->fsf_req_status = req->status; |
| 125 | rec->fsf_cmd = req->fsf_command; |
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 | if (!srb) |
| 128 | goto log; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 129 | |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 130 | rec->u.uss.status_type = srb->status_type; |
| 131 | rec->u.uss.status_subtype = srb->status_subtype; |
| 132 | rec->u.uss.d_id = ntoh24(srb->d_id); |
| 133 | rec->u.uss.lun = srb->fcp_lun; |
| 134 | memcpy(&rec->u.uss.queue_designator, &srb->queue_designator, |
| 135 | sizeof(rec->u.uss.queue_designator)); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 136 | |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 137 | /* status read buffer payload length */ |
| 138 | rec->pl_len = (!srb->length) ? 0 : srb->length - |
| 139 | offsetof(struct fsf_status_read_buffer, payload); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 140 | |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 141 | if (rec->pl_len) |
| 142 | zfcp_dbf_pl_write(dbf, srb->payload.data, rec->pl_len, |
| 143 | "fsf_uss", req->req_id); |
| 144 | log: |
| 145 | debug_event(dbf->hba, 2, rec, sizeof(*rec)); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 146 | spin_unlock_irqrestore(&dbf->hba_lock, flags); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 147 | } |
| 148 | |
Martin Peschke | bfab163 | 2008-03-31 11:15:31 +0200 | [diff] [blame] | 149 | /** |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 150 | * zfcp_dbf_hba_bit_err - trace event for bit error conditions |
| 151 | * @tag: tag indicating which kind of unsolicited status has been received |
| 152 | * @req: request which caused the bit_error condition |
Martin Peschke | bfab163 | 2008-03-31 11:15:31 +0200 | [diff] [blame] | 153 | */ |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 154 | 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] | 155 | { |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 156 | struct zfcp_dbf *dbf = req->adapter->dbf; |
| 157 | struct zfcp_dbf_hba *rec = &dbf->hba_buf; |
Swen Schillig | 5706938 | 2008-10-01 12:42:21 +0200 | [diff] [blame] | 158 | struct fsf_status_read_buffer *sr_buf = req->data; |
Swen Schillig | 5706938 | 2008-10-01 12:42:21 +0200 | [diff] [blame] | 159 | unsigned long flags; |
| 160 | |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 161 | spin_lock_irqsave(&dbf->hba_lock, flags); |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 162 | memset(rec, 0, sizeof(*rec)); |
| 163 | |
| 164 | memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN); |
| 165 | rec->id = ZFCP_DBF_HBA_BIT; |
| 166 | rec->fsf_req_id = req->req_id; |
| 167 | rec->fsf_req_status = req->status; |
| 168 | rec->fsf_cmd = req->fsf_command; |
| 169 | memcpy(&rec->u.be, &sr_buf->payload.bit_error, |
| 170 | sizeof(struct fsf_bit_error_payload)); |
| 171 | |
| 172 | debug_event(dbf->hba, 1, rec, sizeof(*rec)); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 173 | spin_unlock_irqrestore(&dbf->hba_lock, flags); |
Swen Schillig | 5706938 | 2008-10-01 12:42:21 +0200 | [diff] [blame] | 174 | } |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 175 | |
Swen Schillig | 86a9668 | 2011-08-15 14:40:32 +0200 | [diff] [blame] | 176 | /** |
| 177 | * zfcp_dbf_hba_def_err - trace event for deferred error messages |
| 178 | * @adapter: pointer to struct zfcp_adapter |
| 179 | * @req_id: request id which caused the deferred error message |
| 180 | * @scount: number of sbals incl. the signaling sbal |
| 181 | * @pl: array of all involved sbals |
| 182 | */ |
| 183 | void zfcp_dbf_hba_def_err(struct zfcp_adapter *adapter, u64 req_id, u16 scount, |
| 184 | void **pl) |
| 185 | { |
| 186 | struct zfcp_dbf *dbf = adapter->dbf; |
| 187 | struct zfcp_dbf_pay *payload = &dbf->pay_buf; |
| 188 | unsigned long flags; |
| 189 | u16 length; |
| 190 | |
| 191 | if (!pl) |
| 192 | return; |
| 193 | |
| 194 | spin_lock_irqsave(&dbf->pay_lock, flags); |
| 195 | memset(payload, 0, sizeof(*payload)); |
| 196 | |
| 197 | memcpy(payload->area, "def_err", 7); |
| 198 | payload->fsf_req_id = req_id; |
| 199 | payload->counter = 0; |
| 200 | length = min((u16)sizeof(struct qdio_buffer), |
| 201 | (u16)ZFCP_DBF_PAY_MAX_REC); |
| 202 | |
Steffen Maier | 01e6052 | 2012-09-04 15:23:31 +0200 | [diff] [blame] | 203 | while (payload->counter < scount && (char *)pl[payload->counter]) { |
Swen Schillig | 86a9668 | 2011-08-15 14:40:32 +0200 | [diff] [blame] | 204 | memcpy(payload->data, (char *)pl[payload->counter], length); |
| 205 | debug_event(dbf->pay, 1, payload, zfcp_dbf_plen(length)); |
| 206 | payload->counter++; |
| 207 | } |
| 208 | |
| 209 | spin_unlock_irqrestore(&dbf->pay_lock, flags); |
| 210 | } |
| 211 | |
Steffen Maier | cb452149 | 2012-09-04 15:23:32 +0200 | [diff] [blame] | 212 | /** |
| 213 | * zfcp_dbf_hba_basic - trace event for basic adapter events |
| 214 | * @adapter: pointer to struct zfcp_adapter |
| 215 | */ |
| 216 | void zfcp_dbf_hba_basic(char *tag, struct zfcp_adapter *adapter) |
| 217 | { |
| 218 | struct zfcp_dbf *dbf = adapter->dbf; |
| 219 | struct zfcp_dbf_hba *rec = &dbf->hba_buf; |
| 220 | unsigned long flags; |
| 221 | |
| 222 | spin_lock_irqsave(&dbf->hba_lock, flags); |
| 223 | memset(rec, 0, sizeof(*rec)); |
| 224 | |
| 225 | memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN); |
| 226 | rec->id = ZFCP_DBF_HBA_BASIC; |
| 227 | |
| 228 | debug_event(dbf->hba, 1, rec, sizeof(*rec)); |
| 229 | spin_unlock_irqrestore(&dbf->hba_lock, flags); |
| 230 | } |
| 231 | |
Swen Schillig | ae0904f | 2010-12-02 15:16:12 +0100 | [diff] [blame] | 232 | static void zfcp_dbf_set_common(struct zfcp_dbf_rec *rec, |
| 233 | struct zfcp_adapter *adapter, |
| 234 | struct zfcp_port *port, |
| 235 | struct scsi_device *sdev) |
Martin Peschke | d79a83d | 2008-03-27 14:22:00 +0100 | [diff] [blame] | 236 | { |
Swen Schillig | ae0904f | 2010-12-02 15:16:12 +0100 | [diff] [blame] | 237 | rec->adapter_status = atomic_read(&adapter->status); |
| 238 | if (port) { |
| 239 | rec->port_status = atomic_read(&port->status); |
| 240 | rec->wwpn = port->wwpn; |
| 241 | rec->d_id = port->d_id; |
Martin Peschke | d79a83d | 2008-03-27 14:22:00 +0100 | [diff] [blame] | 242 | } |
Swen Schillig | ae0904f | 2010-12-02 15:16:12 +0100 | [diff] [blame] | 243 | if (sdev) { |
| 244 | rec->lun_status = atomic_read(&sdev_to_zfcp(sdev)->status); |
| 245 | rec->lun = zfcp_scsi_dev_lun(sdev); |
Steffen Maier | 0102a30 | 2016-08-10 18:30:48 +0200 | [diff] [blame] | 246 | } else |
| 247 | rec->lun = ZFCP_DBF_INVALID_LUN; |
Martin Peschke | 348447e | 2008-03-27 14:22:01 +0100 | [diff] [blame] | 248 | } |
| 249 | |
Christof Schmitt | aa0fec6 | 2008-05-19 12:17:47 +0200 | [diff] [blame] | 250 | /** |
Swen Schillig | ae0904f | 2010-12-02 15:16:12 +0100 | [diff] [blame] | 251 | * zfcp_dbf_rec_trig - trace event related to triggered recovery |
| 252 | * @tag: identifier for event |
| 253 | * @adapter: adapter on which the erp_action should run |
| 254 | * @port: remote port involved in the erp_action |
| 255 | * @sdev: scsi device involved in the erp_action |
| 256 | * @want: wanted erp_action |
| 257 | * @need: required erp_action |
| 258 | * |
| 259 | * The adapter->erp_lock has to be held. |
Christof Schmitt | aa0fec6 | 2008-05-19 12:17:47 +0200 | [diff] [blame] | 260 | */ |
Swen Schillig | ae0904f | 2010-12-02 15:16:12 +0100 | [diff] [blame] | 261 | void zfcp_dbf_rec_trig(char *tag, struct zfcp_adapter *adapter, |
| 262 | struct zfcp_port *port, struct scsi_device *sdev, |
| 263 | u8 want, u8 need) |
Martin Peschke | 9467a9b | 2008-03-27 14:22:03 +0100 | [diff] [blame] | 264 | { |
Christof Schmitt | d46f384 | 2009-08-18 15:43:07 +0200 | [diff] [blame] | 265 | struct zfcp_dbf *dbf = adapter->dbf; |
Swen Schillig | ae0904f | 2010-12-02 15:16:12 +0100 | [diff] [blame] | 266 | struct zfcp_dbf_rec *rec = &dbf->rec_buf; |
| 267 | struct list_head *entry; |
Martin Peschke | 9467a9b | 2008-03-27 14:22:03 +0100 | [diff] [blame] | 268 | unsigned long flags; |
| 269 | |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 270 | spin_lock_irqsave(&dbf->rec_lock, flags); |
Swen Schillig | ae0904f | 2010-12-02 15:16:12 +0100 | [diff] [blame] | 271 | memset(rec, 0, sizeof(*rec)); |
| 272 | |
| 273 | rec->id = ZFCP_DBF_REC_TRIG; |
| 274 | memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN); |
| 275 | zfcp_dbf_set_common(rec, adapter, port, sdev); |
| 276 | |
| 277 | list_for_each(entry, &adapter->erp_ready_head) |
| 278 | rec->u.trig.ready++; |
| 279 | |
| 280 | list_for_each(entry, &adapter->erp_running_head) |
| 281 | rec->u.trig.running++; |
| 282 | |
| 283 | rec->u.trig.want = want; |
| 284 | rec->u.trig.need = need; |
| 285 | |
| 286 | debug_event(dbf->rec, 1, rec, sizeof(*rec)); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 287 | spin_unlock_irqrestore(&dbf->rec_lock, flags); |
Martin Peschke | 9467a9b | 2008-03-27 14:22:03 +0100 | [diff] [blame] | 288 | } |
| 289 | |
Swen Schillig | ae0904f | 2010-12-02 15:16:12 +0100 | [diff] [blame] | 290 | |
Martin Peschke | 6f4f365 | 2008-03-27 14:22:04 +0100 | [diff] [blame] | 291 | /** |
Swen Schillig | ae0904f | 2010-12-02 15:16:12 +0100 | [diff] [blame] | 292 | * zfcp_dbf_rec_run - trace event related to running recovery |
| 293 | * @tag: identifier for event |
| 294 | * @erp: erp_action running |
Martin Peschke | 6f4f365 | 2008-03-27 14:22:04 +0100 | [diff] [blame] | 295 | */ |
Swen Schillig | ae0904f | 2010-12-02 15:16:12 +0100 | [diff] [blame] | 296 | void zfcp_dbf_rec_run(char *tag, struct zfcp_erp_action *erp) |
Martin Peschke | 6f4f365 | 2008-03-27 14:22:04 +0100 | [diff] [blame] | 297 | { |
Swen Schillig | ae0904f | 2010-12-02 15:16:12 +0100 | [diff] [blame] | 298 | struct zfcp_dbf *dbf = erp->adapter->dbf; |
| 299 | struct zfcp_dbf_rec *rec = &dbf->rec_buf; |
Martin Peschke | 6f4f365 | 2008-03-27 14:22:04 +0100 | [diff] [blame] | 300 | unsigned long flags; |
| 301 | |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 302 | spin_lock_irqsave(&dbf->rec_lock, flags); |
Swen Schillig | ae0904f | 2010-12-02 15:16:12 +0100 | [diff] [blame] | 303 | memset(rec, 0, sizeof(*rec)); |
| 304 | |
| 305 | rec->id = ZFCP_DBF_REC_RUN; |
| 306 | memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN); |
| 307 | zfcp_dbf_set_common(rec, erp->adapter, erp->port, erp->sdev); |
| 308 | |
| 309 | rec->u.run.fsf_req_id = erp->fsf_req_id; |
| 310 | rec->u.run.rec_status = erp->status; |
| 311 | rec->u.run.rec_step = erp->step; |
| 312 | rec->u.run.rec_action = erp->action; |
| 313 | |
| 314 | if (erp->sdev) |
| 315 | rec->u.run.rec_count = |
| 316 | atomic_read(&sdev_to_zfcp(erp->sdev)->erp_counter); |
| 317 | else if (erp->port) |
| 318 | rec->u.run.rec_count = atomic_read(&erp->port->erp_counter); |
| 319 | else |
| 320 | rec->u.run.rec_count = atomic_read(&erp->adapter->erp_counter); |
| 321 | |
| 322 | debug_event(dbf->rec, 1, rec, sizeof(*rec)); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 323 | spin_unlock_irqrestore(&dbf->rec_lock, flags); |
Martin Peschke | 6f4f365 | 2008-03-27 14:22:04 +0100 | [diff] [blame] | 324 | } |
| 325 | |
Steffen Maier | d27a7cb | 2016-08-10 18:30:49 +0200 | [diff] [blame] | 326 | /** |
| 327 | * zfcp_dbf_rec_run_wka - trace wka port event with info like running recovery |
| 328 | * @tag: identifier for event |
| 329 | * @wka_port: well known address port |
| 330 | * @req_id: request ID to correlate with potential HBA trace record |
| 331 | */ |
| 332 | void zfcp_dbf_rec_run_wka(char *tag, struct zfcp_fc_wka_port *wka_port, |
| 333 | u64 req_id) |
| 334 | { |
| 335 | struct zfcp_dbf *dbf = wka_port->adapter->dbf; |
| 336 | struct zfcp_dbf_rec *rec = &dbf->rec_buf; |
| 337 | unsigned long flags; |
| 338 | |
| 339 | spin_lock_irqsave(&dbf->rec_lock, flags); |
| 340 | memset(rec, 0, sizeof(*rec)); |
| 341 | |
| 342 | rec->id = ZFCP_DBF_REC_RUN; |
| 343 | memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN); |
| 344 | rec->port_status = wka_port->status; |
| 345 | rec->d_id = wka_port->d_id; |
| 346 | rec->lun = ZFCP_DBF_INVALID_LUN; |
| 347 | |
| 348 | rec->u.run.fsf_req_id = req_id; |
| 349 | rec->u.run.rec_status = ~0; |
| 350 | rec->u.run.rec_step = ~0; |
| 351 | rec->u.run.rec_action = ~0; |
| 352 | rec->u.run.rec_count = ~0; |
| 353 | |
| 354 | debug_event(dbf->rec, 1, rec, sizeof(*rec)); |
| 355 | spin_unlock_irqrestore(&dbf->rec_lock, flags); |
| 356 | } |
| 357 | |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 358 | static inline |
Steffen Maier | aceeffb | 2016-08-10 18:30:53 +0200 | [diff] [blame] | 359 | void zfcp_dbf_san(char *tag, struct zfcp_dbf *dbf, |
| 360 | char *paytag, struct scatterlist *sg, u8 id, u16 len, |
| 361 | u64 req_id, u32 d_id, u16 cap_len) |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 362 | { |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 363 | struct zfcp_dbf_san *rec = &dbf->san_buf; |
| 364 | u16 rec_len; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 365 | unsigned long flags; |
Steffen Maier | aceeffb | 2016-08-10 18:30:53 +0200 | [diff] [blame] | 366 | struct zfcp_dbf_pay *payload = &dbf->pay_buf; |
| 367 | u16 pay_sum = 0; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 368 | |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 369 | spin_lock_irqsave(&dbf->san_lock, flags); |
Martin Peschke | 6bc473d | 2008-03-31 11:15:29 +0200 | [diff] [blame] | 370 | memset(rec, 0, sizeof(*rec)); |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 371 | |
| 372 | rec->id = id; |
| 373 | rec->fsf_req_id = req_id; |
| 374 | rec->d_id = d_id; |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 375 | memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN); |
Steffen Maier | aceeffb | 2016-08-10 18:30:53 +0200 | [diff] [blame] | 376 | rec->pl_len = len; /* full length even if we cap pay below */ |
| 377 | if (!sg) |
| 378 | goto out; |
| 379 | rec_len = min_t(unsigned int, sg->length, ZFCP_DBF_SAN_MAX_PAYLOAD); |
| 380 | memcpy(rec->payload, sg_virt(sg), rec_len); /* part of 1st sg entry */ |
| 381 | if (len <= rec_len) |
| 382 | goto out; /* skip pay record if full content in rec->payload */ |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 383 | |
Steffen Maier | aceeffb | 2016-08-10 18:30:53 +0200 | [diff] [blame] | 384 | /* if (len > rec_len): |
| 385 | * dump data up to cap_len ignoring small duplicate in rec->payload |
| 386 | */ |
Dan Carpenter | e7cb08e | 2016-10-14 16:18:39 -0400 | [diff] [blame^] | 387 | spin_lock(&dbf->pay_lock); |
Steffen Maier | aceeffb | 2016-08-10 18:30:53 +0200 | [diff] [blame] | 388 | memset(payload, 0, sizeof(*payload)); |
| 389 | memcpy(payload->area, paytag, ZFCP_DBF_TAG_LEN); |
| 390 | payload->fsf_req_id = req_id; |
| 391 | payload->counter = 0; |
| 392 | for (; sg && pay_sum < cap_len; sg = sg_next(sg)) { |
| 393 | u16 pay_len, offset = 0; |
| 394 | |
| 395 | while (offset < sg->length && pay_sum < cap_len) { |
| 396 | pay_len = min((u16)ZFCP_DBF_PAY_MAX_REC, |
| 397 | (u16)(sg->length - offset)); |
| 398 | /* cap_len <= pay_sum < cap_len+ZFCP_DBF_PAY_MAX_REC */ |
| 399 | memcpy(payload->data, sg_virt(sg) + offset, pay_len); |
| 400 | debug_event(dbf->pay, 1, payload, |
| 401 | zfcp_dbf_plen(pay_len)); |
| 402 | payload->counter++; |
| 403 | offset += pay_len; |
| 404 | pay_sum += pay_len; |
| 405 | } |
| 406 | } |
| 407 | spin_unlock(&dbf->pay_lock); |
| 408 | |
| 409 | out: |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 410 | debug_event(dbf->san, 1, rec, sizeof(*rec)); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 411 | spin_unlock_irqrestore(&dbf->san_lock, flags); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 412 | } |
| 413 | |
Martin Peschke | bfab163 | 2008-03-31 11:15:31 +0200 | [diff] [blame] | 414 | /** |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 415 | * zfcp_dbf_san_req - trace event for issued SAN request |
Maxime Jayat | 3f79410 | 2013-10-12 01:29:46 +0200 | [diff] [blame] | 416 | * @tag: identifier for event |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 417 | * @fsf_req: request containing issued CT data |
| 418 | * d_id: destination ID |
Martin Peschke | bfab163 | 2008-03-31 11:15:31 +0200 | [diff] [blame] | 419 | */ |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 420 | 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] | 421 | { |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 422 | struct zfcp_dbf *dbf = fsf->adapter->dbf; |
| 423 | struct zfcp_fsf_ct_els *ct_els = fsf->data; |
| 424 | u16 length; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 425 | |
Steffen Maier | aceeffb | 2016-08-10 18:30:53 +0200 | [diff] [blame] | 426 | length = (u16)zfcp_qdio_real_bytes(ct_els->req); |
| 427 | zfcp_dbf_san(tag, dbf, "san_req", ct_els->req, ZFCP_DBF_SAN_REQ, |
| 428 | length, fsf->req_id, d_id, length); |
| 429 | } |
| 430 | |
| 431 | static u16 zfcp_dbf_san_res_cap_len_if_gpn_ft(char *tag, |
| 432 | struct zfcp_fsf_req *fsf, |
| 433 | u16 len) |
| 434 | { |
| 435 | struct zfcp_fsf_ct_els *ct_els = fsf->data; |
| 436 | struct fc_ct_hdr *reqh = sg_virt(ct_els->req); |
| 437 | struct fc_ns_gid_ft *reqn = (struct fc_ns_gid_ft *)(reqh + 1); |
| 438 | struct scatterlist *resp_entry = ct_els->resp; |
| 439 | struct fc_gpn_ft_resp *acc; |
| 440 | int max_entries, x, last = 0; |
| 441 | |
| 442 | if (!(memcmp(tag, "fsscth2", 7) == 0 |
| 443 | && ct_els->d_id == FC_FID_DIR_SERV |
| 444 | && reqh->ct_rev == FC_CT_REV |
| 445 | && reqh->ct_in_id[0] == 0 |
| 446 | && reqh->ct_in_id[1] == 0 |
| 447 | && reqh->ct_in_id[2] == 0 |
| 448 | && reqh->ct_fs_type == FC_FST_DIR |
| 449 | && reqh->ct_fs_subtype == FC_NS_SUBTYPE |
| 450 | && reqh->ct_options == 0 |
| 451 | && reqh->_ct_resvd1 == 0 |
| 452 | && reqh->ct_cmd == FC_NS_GPN_FT |
| 453 | /* reqh->ct_mr_size can vary so do not match but read below */ |
| 454 | && reqh->_ct_resvd2 == 0 |
| 455 | && reqh->ct_reason == 0 |
| 456 | && reqh->ct_explan == 0 |
| 457 | && reqh->ct_vendor == 0 |
| 458 | && reqn->fn_resvd == 0 |
| 459 | && reqn->fn_domain_id_scope == 0 |
| 460 | && reqn->fn_area_id_scope == 0 |
| 461 | && reqn->fn_fc4_type == FC_TYPE_FCP)) |
| 462 | return len; /* not GPN_FT response so do not cap */ |
| 463 | |
| 464 | acc = sg_virt(resp_entry); |
| 465 | max_entries = (reqh->ct_mr_size * 4 / sizeof(struct fc_gpn_ft_resp)) |
| 466 | + 1 /* zfcp_fc_scan_ports: bytes correct, entries off-by-one |
| 467 | * to account for header as 1st pseudo "entry" */; |
| 468 | |
| 469 | /* the basic CT_IU preamble is the same size as one entry in the GPN_FT |
| 470 | * response, allowing us to skip special handling for it - just skip it |
| 471 | */ |
| 472 | for (x = 1; x < max_entries && !last; x++) { |
| 473 | if (x % (ZFCP_FC_GPN_FT_ENT_PAGE + 1)) |
| 474 | acc++; |
| 475 | else |
| 476 | acc = sg_virt(++resp_entry); |
| 477 | |
| 478 | last = acc->fp_flags & FC_NS_FID_LAST; |
| 479 | } |
| 480 | len = min(len, (u16)(x * sizeof(struct fc_gpn_ft_resp))); |
| 481 | return len; /* cap after last entry */ |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 482 | } |
| 483 | |
Martin Peschke | bfab163 | 2008-03-31 11:15:31 +0200 | [diff] [blame] | 484 | /** |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 485 | * zfcp_dbf_san_res - trace event for received SAN request |
Maxime Jayat | 3f79410 | 2013-10-12 01:29:46 +0200 | [diff] [blame] | 486 | * @tag: identifier for event |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 487 | * @fsf_req: request containing issued CT data |
Martin Peschke | bfab163 | 2008-03-31 11:15:31 +0200 | [diff] [blame] | 488 | */ |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 489 | void zfcp_dbf_san_res(char *tag, struct zfcp_fsf_req *fsf) |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 490 | { |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 491 | struct zfcp_dbf *dbf = fsf->adapter->dbf; |
| 492 | struct zfcp_fsf_ct_els *ct_els = fsf->data; |
| 493 | u16 length; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 494 | |
Steffen Maier | aceeffb | 2016-08-10 18:30:53 +0200 | [diff] [blame] | 495 | length = (u16)zfcp_qdio_real_bytes(ct_els->resp); |
| 496 | zfcp_dbf_san(tag, dbf, "san_res", ct_els->resp, ZFCP_DBF_SAN_RES, |
| 497 | length, fsf->req_id, ct_els->d_id, |
| 498 | zfcp_dbf_san_res_cap_len_if_gpn_ft(tag, fsf, length)); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 499 | } |
| 500 | |
Martin Peschke | bfab163 | 2008-03-31 11:15:31 +0200 | [diff] [blame] | 501 | /** |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 502 | * zfcp_dbf_san_in_els - trace event for incoming ELS |
Maxime Jayat | 3f79410 | 2013-10-12 01:29:46 +0200 | [diff] [blame] | 503 | * @tag: identifier for event |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 504 | * @fsf_req: request containing issued CT data |
Martin Peschke | bfab163 | 2008-03-31 11:15:31 +0200 | [diff] [blame] | 505 | */ |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 506 | 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] | 507 | { |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 508 | struct zfcp_dbf *dbf = fsf->adapter->dbf; |
| 509 | struct fsf_status_read_buffer *srb = |
| 510 | (struct fsf_status_read_buffer *) fsf->data; |
| 511 | u16 length; |
Steffen Maier | aceeffb | 2016-08-10 18:30:53 +0200 | [diff] [blame] | 512 | struct scatterlist sg; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 513 | |
Swen Schillig | 2c55b75 | 2010-12-02 15:16:13 +0100 | [diff] [blame] | 514 | length = (u16)(srb->length - |
| 515 | offsetof(struct fsf_status_read_buffer, payload)); |
Steffen Maier | aceeffb | 2016-08-10 18:30:53 +0200 | [diff] [blame] | 516 | sg_init_one(&sg, srb->payload.data, length); |
| 517 | zfcp_dbf_san(tag, dbf, "san_els", &sg, ZFCP_DBF_SAN_ELS, length, |
| 518 | fsf->req_id, ntoh24(srb->d_id), length); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 519 | } |
| 520 | |
Swen Schillig | 250a135 | 2010-12-02 15:16:15 +0100 | [diff] [blame] | 521 | /** |
| 522 | * zfcp_dbf_scsi - trace event for scsi commands |
| 523 | * @tag: identifier for event |
| 524 | * @sc: pointer to struct scsi_cmnd |
| 525 | * @fsf: pointer to struct zfcp_fsf_req |
| 526 | */ |
Steffen Maier | 35f040d | 2016-08-10 18:30:47 +0200 | [diff] [blame] | 527 | void zfcp_dbf_scsi(char *tag, int level, struct scsi_cmnd *sc, |
| 528 | struct zfcp_fsf_req *fsf) |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 529 | { |
Swen Schillig | 250a135 | 2010-12-02 15:16:15 +0100 | [diff] [blame] | 530 | struct zfcp_adapter *adapter = |
| 531 | (struct zfcp_adapter *) sc->device->host->hostdata[0]; |
| 532 | struct zfcp_dbf *dbf = adapter->dbf; |
| 533 | struct zfcp_dbf_scsi *rec = &dbf->scsi_buf; |
Christof Schmitt | 4318e08 | 2009-11-24 16:54:08 +0100 | [diff] [blame] | 534 | struct fcp_resp_with_ext *fcp_rsp; |
Swen Schillig | 250a135 | 2010-12-02 15:16:15 +0100 | [diff] [blame] | 535 | struct fcp_resp_rsp_info *fcp_rsp_info; |
| 536 | unsigned long flags; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 537 | |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 538 | spin_lock_irqsave(&dbf->scsi_lock, flags); |
Swen Schillig | 250a135 | 2010-12-02 15:16:15 +0100 | [diff] [blame] | 539 | memset(rec, 0, sizeof(*rec)); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 540 | |
Swen Schillig | 250a135 | 2010-12-02 15:16:15 +0100 | [diff] [blame] | 541 | memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN); |
| 542 | rec->id = ZFCP_DBF_SCSI_CMND; |
| 543 | rec->scsi_result = sc->result; |
| 544 | rec->scsi_retries = sc->retries; |
| 545 | rec->scsi_allowed = sc->allowed; |
| 546 | rec->scsi_id = sc->device->id; |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 547 | /* struct zfcp_dbf_scsi needs to be updated to handle 64bit LUNs */ |
| 548 | rec->scsi_lun = (u32)sc->device->lun; |
Swen Schillig | 250a135 | 2010-12-02 15:16:15 +0100 | [diff] [blame] | 549 | rec->host_scribble = (unsigned long)sc->host_scribble; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 550 | |
Swen Schillig | 250a135 | 2010-12-02 15:16:15 +0100 | [diff] [blame] | 551 | memcpy(rec->scsi_opcode, sc->cmnd, |
| 552 | min((int)sc->cmd_len, ZFCP_DBF_SCSI_OPCODE)); |
| 553 | |
| 554 | if (fsf) { |
| 555 | rec->fsf_req_id = fsf->req_id; |
| 556 | fcp_rsp = (struct fcp_resp_with_ext *) |
| 557 | &(fsf->qtcb->bottom.io.fcp_rsp); |
| 558 | memcpy(&rec->fcp_rsp, fcp_rsp, FCP_RESP_WITH_EXT); |
| 559 | if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL) { |
| 560 | fcp_rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1]; |
| 561 | rec->fcp_rsp_info = fcp_rsp_info->rsp_code; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 562 | } |
Swen Schillig | 250a135 | 2010-12-02 15:16:15 +0100 | [diff] [blame] | 563 | if (fcp_rsp->resp.fr_flags & FCP_SNS_LEN_VAL) { |
| 564 | rec->pl_len = min((u16)SCSI_SENSE_BUFFERSIZE, |
| 565 | (u16)ZFCP_DBF_PAY_MAX_REC); |
| 566 | zfcp_dbf_pl_write(dbf, sc->sense_buffer, rec->pl_len, |
| 567 | "fcp_sns", fsf->req_id); |
| 568 | } |
| 569 | } |
| 570 | |
Steffen Maier | 35f040d | 2016-08-10 18:30:47 +0200 | [diff] [blame] | 571 | debug_event(dbf->scsi, level, rec, sizeof(*rec)); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 572 | spin_unlock_irqrestore(&dbf->scsi_lock, flags); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 573 | } |
| 574 | |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 575 | 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] | 576 | { |
| 577 | struct debug_info *d; |
| 578 | |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 579 | d = debug_register(name, size, 1, rec_size); |
Christof Schmitt | d46f384 | 2009-08-18 15:43:07 +0200 | [diff] [blame] | 580 | if (!d) |
| 581 | return NULL; |
| 582 | |
| 583 | debug_register_view(d, &debug_hex_ascii_view); |
Steffen Maier | bf3ea3a | 2013-04-26 16:13:53 +0200 | [diff] [blame] | 584 | debug_set_level(d, dbflevel); |
Christof Schmitt | d46f384 | 2009-08-18 15:43:07 +0200 | [diff] [blame] | 585 | |
| 586 | return d; |
| 587 | } |
| 588 | |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 589 | static void zfcp_dbf_unregister(struct zfcp_dbf *dbf) |
| 590 | { |
| 591 | if (!dbf) |
| 592 | return; |
| 593 | |
| 594 | debug_unregister(dbf->scsi); |
| 595 | debug_unregister(dbf->san); |
| 596 | debug_unregister(dbf->hba); |
| 597 | debug_unregister(dbf->pay); |
| 598 | debug_unregister(dbf->rec); |
| 599 | kfree(dbf); |
| 600 | } |
| 601 | |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 602 | /** |
| 603 | * zfcp_adapter_debug_register - registers debug feature for an adapter |
| 604 | * @adapter: pointer to adapter for which debug features should be registered |
| 605 | * return: -ENOMEM on error, 0 otherwise |
| 606 | */ |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 607 | int zfcp_dbf_adapter_register(struct zfcp_adapter *adapter) |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 608 | { |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 609 | char name[DEBUG_MAX_NAME_LEN]; |
Christof Schmitt | d46f384 | 2009-08-18 15:43:07 +0200 | [diff] [blame] | 610 | struct zfcp_dbf *dbf; |
| 611 | |
Swen Schillig | d23948e | 2010-07-16 15:37:40 +0200 | [diff] [blame] | 612 | dbf = kzalloc(sizeof(struct zfcp_dbf), GFP_KERNEL); |
Christof Schmitt | d46f384 | 2009-08-18 15:43:07 +0200 | [diff] [blame] | 613 | if (!dbf) |
| 614 | return -ENOMEM; |
| 615 | |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 616 | spin_lock_init(&dbf->pay_lock); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 617 | spin_lock_init(&dbf->hba_lock); |
| 618 | spin_lock_init(&dbf->san_lock); |
| 619 | spin_lock_init(&dbf->scsi_lock); |
| 620 | spin_lock_init(&dbf->rec_lock); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 621 | |
| 622 | /* debug feature area which records recovery activity */ |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 623 | sprintf(name, "zfcp_%s_rec", dev_name(&adapter->ccw_device->dev)); |
| 624 | dbf->rec = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_rec)); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 625 | if (!dbf->rec) |
| 626 | goto err_out; |
Martin Peschke | d79a83d | 2008-03-27 14:22:00 +0100 | [diff] [blame] | 627 | |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 628 | /* debug feature area which records HBA (FSF and QDIO) conditions */ |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 629 | sprintf(name, "zfcp_%s_hba", dev_name(&adapter->ccw_device->dev)); |
| 630 | dbf->hba = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_hba)); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 631 | if (!dbf->hba) |
| 632 | goto err_out; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 633 | |
Swen Schillig | a54ca0f | 2010-12-02 15:16:14 +0100 | [diff] [blame] | 634 | /* debug feature area which records payload info */ |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 635 | sprintf(name, "zfcp_%s_pay", dev_name(&adapter->ccw_device->dev)); |
| 636 | 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] | 637 | if (!dbf->pay) |
| 638 | goto err_out; |
| 639 | |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 640 | /* debug feature area which records SAN command failures and recovery */ |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 641 | sprintf(name, "zfcp_%s_san", dev_name(&adapter->ccw_device->dev)); |
| 642 | dbf->san = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_san)); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 643 | if (!dbf->san) |
| 644 | goto err_out; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 645 | |
| 646 | /* debug feature area which records SCSI command failures and recovery */ |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 647 | sprintf(name, "zfcp_%s_scsi", dev_name(&adapter->ccw_device->dev)); |
| 648 | dbf->scsi = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_scsi)); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 649 | if (!dbf->scsi) |
| 650 | goto err_out; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 651 | |
Christof Schmitt | d46f384 | 2009-08-18 15:43:07 +0200 | [diff] [blame] | 652 | adapter->dbf = dbf; |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 653 | |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 654 | return 0; |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 655 | err_out: |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 656 | zfcp_dbf_unregister(dbf); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 657 | return -ENOMEM; |
| 658 | } |
| 659 | |
| 660 | /** |
| 661 | * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 662 | * @adapter: pointer to adapter for which debug features should be unregistered |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 663 | */ |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 664 | void zfcp_dbf_adapter_unregister(struct zfcp_adapter *adapter) |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 665 | { |
Swen Schillig | ea4a3a6 | 2010-12-02 15:16:16 +0100 | [diff] [blame] | 666 | struct zfcp_dbf *dbf = adapter->dbf; |
| 667 | |
| 668 | adapter->dbf = NULL; |
| 669 | zfcp_dbf_unregister(dbf); |
Maxim Shchetynin | 8a36e45 | 2005-09-13 21:50:38 +0200 | [diff] [blame] | 670 | } |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 671 | |