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