blob: 7901deb4ba89a11a20954e18775d24bc2019b035 [file] [log] [blame]
Christof Schmitt2b604c92008-03-31 11:15:28 +02001/*
Swen Schilliga54ca0f2010-12-02 15:16:14 +01002 * zfcp device driver
3 * debug feature declarations
Christof Schmitt2b604c92008-03-31 11:15:28 +02004 *
Steffen Maier4eeaa4f2016-08-10 18:30:46 +02005 * Copyright IBM Corp. 2008, 2015
Christof Schmitt2b604c92008-03-31 11:15:28 +02006 */
7
8#ifndef ZFCP_DBF_H
9#define ZFCP_DBF_H
10
Christof Schmitt4318e082009-11-24 16:54:08 +010011#include <scsi/fc/fc_fcp.h>
Christof Schmittdcd20e22009-08-18 15:43:08 +020012#include "zfcp_ext.h"
Christof Schmitt2b604c92008-03-31 11:15:28 +020013#include "zfcp_fsf.h"
Christof Schmittdcd20e22009-08-18 15:43:08 +020014#include "zfcp_def.h"
Christof Schmitt2b604c92008-03-31 11:15:28 +020015
Swen Schilligae0904f2010-12-02 15:16:12 +010016#define ZFCP_DBF_TAG_LEN 7
Christof Schmitt2b604c92008-03-31 11:15:28 +020017
Christof Schmittd21e9da2010-02-17 11:18:54 +010018#define ZFCP_DBF_INVALID_LUN 0xFFFFFFFFFFFFFFFFull
19
Steffen Maier4eeaa4f2016-08-10 18:30:46 +020020enum zfcp_dbf_pseudo_erp_act_type {
21 ZFCP_PSEUDO_ERP_ACTION_RPORT_ADD = 0xff,
22 ZFCP_PSEUDO_ERP_ACTION_RPORT_DEL = 0xfe,
23};
24
Swen Schilligae0904f2010-12-02 15:16:12 +010025/**
26 * struct zfcp_dbf_rec_trigger - trace record for triggered recovery action
27 * @ready: number of ready recovery actions
28 * @running: number of running recovery actions
29 * @want: wanted recovery action
30 * @need: needed recovery action
31 */
32struct zfcp_dbf_rec_trigger {
Christof Schmitt2b604c92008-03-31 11:15:28 +020033 u32 ready;
34 u32 running;
Christof Schmitt2b604c92008-03-31 11:15:28 +020035 u8 want;
36 u8 need;
Swen Schilligae0904f2010-12-02 15:16:12 +010037} __packed;
38
39/**
40 * struct zfcp_dbf_rec_running - trace record for running recovery
41 * @fsf_req_id: request id for fsf requests
42 * @rec_status: status of the fsf request
43 * @rec_step: current step of the recovery action
44 * rec_count: recovery counter
45 */
46struct zfcp_dbf_rec_running {
47 u64 fsf_req_id;
48 u32 rec_status;
49 u16 rec_step;
50 u8 rec_action;
51 u8 rec_count;
52} __packed;
53
54/**
55 * enum zfcp_dbf_rec_id - recovery trace record id
56 * @ZFCP_DBF_REC_TRIG: triggered recovery identifier
57 * @ZFCP_DBF_REC_RUN: running recovery identifier
58 */
59enum zfcp_dbf_rec_id {
60 ZFCP_DBF_REC_TRIG = 1,
61 ZFCP_DBF_REC_RUN = 2,
Martin Peschke73378912008-05-19 12:17:46 +020062};
Christof Schmitt2b604c92008-03-31 11:15:28 +020063
Swen Schilligae0904f2010-12-02 15:16:12 +010064/**
65 * struct zfcp_dbf_rec - trace record for error recovery actions
66 * @id: unique number of recovery record type
67 * @tag: identifier string specifying the location of initiation
68 * @lun: logical unit number
69 * @wwpn: word wide port number
70 * @d_id: destination ID
71 * @adapter_status: current status of the adapter
72 * @port_status: current status of the port
73 * @lun_status: current status of the lun
74 * @u.trig: structure zfcp_dbf_rec_trigger
75 * @u.run: structure zfcp_dbf_rec_running
76 */
77struct zfcp_dbf_rec {
Christof Schmitt2b604c92008-03-31 11:15:28 +020078 u8 id;
Swen Schilligae0904f2010-12-02 15:16:12 +010079 char tag[ZFCP_DBF_TAG_LEN];
80 u64 lun;
81 u64 wwpn;
82 u32 d_id;
83 u32 adapter_status;
84 u32 port_status;
85 u32 lun_status;
Christof Schmitt2b604c92008-03-31 11:15:28 +020086 union {
Swen Schilligae0904f2010-12-02 15:16:12 +010087 struct zfcp_dbf_rec_trigger trig;
88 struct zfcp_dbf_rec_running run;
Christof Schmitt2b604c92008-03-31 11:15:28 +020089 } u;
Swen Schilligae0904f2010-12-02 15:16:12 +010090} __packed;
Christof Schmitt2b604c92008-03-31 11:15:28 +020091
Swen Schillig2c55b752010-12-02 15:16:13 +010092/**
93 * enum zfcp_dbf_san_id - SAN trace record identifier
94 * @ZFCP_DBF_SAN_REQ: request trace record id
95 * @ZFCP_DBF_SAN_RES: response trace record id
96 * @ZFCP_DBF_SAN_ELS: extended link service record id
97 */
98enum zfcp_dbf_san_id {
99 ZFCP_DBF_SAN_REQ = 1,
100 ZFCP_DBF_SAN_RES = 2,
101 ZFCP_DBF_SAN_ELS = 3,
102};
103
104/** struct zfcp_dbf_san - trace record for SAN requests and responses
105 * @id: unique number of recovery record type
106 * @tag: identifier string specifying the location of initiation
107 * @fsf_req_id: request id for fsf requests
108 * @payload: unformatted information related to request/response
109 * @d_id: destination id
110 */
111struct zfcp_dbf_san {
112 u8 id;
113 char tag[ZFCP_DBF_TAG_LEN];
114 u64 fsf_req_id;
115 u32 d_id;
116#define ZFCP_DBF_SAN_MAX_PAYLOAD (FC_CT_HDR_LEN + 32)
117 char payload[ZFCP_DBF_SAN_MAX_PAYLOAD];
118} __packed;
119
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100120/**
121 * struct zfcp_dbf_hba_res - trace record for hba responses
122 * @req_issued: timestamp when request was issued
123 * @prot_status: protocol status
124 * @prot_status_qual: protocol status qualifier
125 * @fsf_status: fsf status
126 * @fsf_status_qual: fsf status qualifier
127 */
128struct zfcp_dbf_hba_res {
129 u64 req_issued;
130 u32 prot_status;
131 u8 prot_status_qual[FSF_PROT_STATUS_QUAL_SIZE];
Christof Schmitt2b604c92008-03-31 11:15:28 +0200132 u32 fsf_status;
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100133 u8 fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
134} __packed;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200135
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100136/**
137 * struct zfcp_dbf_hba_uss - trace record for unsolicited status
138 * @status_type: type of unsolicited status
139 * @status_subtype: subtype of unsolicited status
140 * @d_id: destination ID
141 * @lun: logical unit number
142 * @queue_designator: queue designator
143 */
144struct zfcp_dbf_hba_uss {
Christof Schmitt2b604c92008-03-31 11:15:28 +0200145 u32 status_type;
146 u32 status_subtype;
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100147 u32 d_id;
148 u64 lun;
149 u64 queue_designator;
150} __packed;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200151
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100152/**
153 * enum zfcp_dbf_hba_id - HBA trace record identifier
154 * @ZFCP_DBF_HBA_RES: response trace record
155 * @ZFCP_DBF_HBA_USS: unsolicited status trace record
156 * @ZFCP_DBF_HBA_BIT: bit error trace record
157 */
158enum zfcp_dbf_hba_id {
159 ZFCP_DBF_HBA_RES = 1,
160 ZFCP_DBF_HBA_USS = 2,
161 ZFCP_DBF_HBA_BIT = 3,
Steffen Maiercb4521492012-09-04 15:23:32 +0200162 ZFCP_DBF_HBA_BASIC = 4,
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100163};
Christof Schmitt2b604c92008-03-31 11:15:28 +0200164
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100165/**
166 * struct zfcp_dbf_hba - common trace record for HBA records
167 * @id: unique number of recovery record type
168 * @tag: identifier string specifying the location of initiation
169 * @fsf_req_id: request id for fsf requests
170 * @fsf_req_status: status of fsf request
171 * @fsf_cmd: fsf command
172 * @fsf_seq_no: fsf sequence number
173 * @pl_len: length of payload stored as zfcp_dbf_pay
174 * @u: record type specific data
175 */
176struct zfcp_dbf_hba {
177 u8 id;
178 char tag[ZFCP_DBF_TAG_LEN];
179 u64 fsf_req_id;
180 u32 fsf_req_status;
181 u32 fsf_cmd;
182 u32 fsf_seq_no;
183 u16 pl_len;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200184 union {
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100185 struct zfcp_dbf_hba_res res;
186 struct zfcp_dbf_hba_uss uss;
187 struct fsf_bit_error_payload be;
Martin Peschke6bc473d2008-03-31 11:15:29 +0200188 } u;
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100189} __packed;
190
191/**
Swen Schillig250a1352010-12-02 15:16:15 +0100192 * enum zfcp_dbf_scsi_id - scsi trace record identifier
193 * @ZFCP_DBF_SCSI_CMND: scsi command trace record
194 */
195enum zfcp_dbf_scsi_id {
196 ZFCP_DBF_SCSI_CMND = 1,
197};
198
199/**
200 * struct zfcp_dbf_scsi - common trace record for SCSI records
201 * @id: unique number of recovery record type
202 * @tag: identifier string specifying the location of initiation
203 * @scsi_id: scsi device id
204 * @scsi_lun: scsi device logical unit number
205 * @scsi_result: scsi result
206 * @scsi_retries: current retry number of scsi request
207 * @scsi_allowed: allowed retries
208 * @fcp_rsp_info: FCP response info
209 * @scsi_opcode: scsi opcode
210 * @fsf_req_id: request id of fsf request
211 * @host_scribble: LLD specific data attached to SCSI request
212 * @pl_len: length of paload stored as zfcp_dbf_pay
213 * @fsf_rsp: response for fsf request
214 */
215struct zfcp_dbf_scsi {
216 u8 id;
217 char tag[ZFCP_DBF_TAG_LEN];
218 u32 scsi_id;
219 u32 scsi_lun;
220 u32 scsi_result;
221 u8 scsi_retries;
222 u8 scsi_allowed;
223 u8 fcp_rsp_info;
224#define ZFCP_DBF_SCSI_OPCODE 16
225 u8 scsi_opcode[ZFCP_DBF_SCSI_OPCODE];
226 u64 fsf_req_id;
227 u64 host_scribble;
228 u16 pl_len;
229 struct fcp_resp_with_ext fcp_rsp;
230} __packed;
231
232/**
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100233 * struct zfcp_dbf_pay - trace record for unformatted payload information
234 * @area: area this record is originated from
235 * @counter: ascending record number
236 * @fsf_req_id: request id of fsf request
237 * @data: unformatted data
238 */
239struct zfcp_dbf_pay {
Swen Schilligea4a3a62010-12-02 15:16:16 +0100240 u8 counter;
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100241 char area[ZFCP_DBF_TAG_LEN];
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100242 u64 fsf_req_id;
243#define ZFCP_DBF_PAY_MAX_REC 0x100
244 char data[ZFCP_DBF_PAY_MAX_REC];
245} __packed;
Christof Schmitt2b604c92008-03-31 11:15:28 +0200246
Swen Schilligea4a3a62010-12-02 15:16:16 +0100247/**
248 * struct zfcp_dbf - main dbf trace structure
249 * @pay: reference to payload trace area
250 * @rec: reference to recovery trace area
251 * @hba: reference to hba trace area
252 * @san: reference to san trace area
253 * @scsi: reference to scsi trace area
254 * @pay_lock: lock protecting payload trace buffer
255 * @rec_lock: lock protecting recovery trace buffer
256 * @hba_lock: lock protecting hba trace buffer
257 * @san_lock: lock protecting san trace buffer
258 * @scsi_lock: lock protecting scsi trace buffer
259 * @pay_buf: pre-allocated buffer for payload
260 * @rec_buf: pre-allocated buffer for recovery
261 * @hba_buf: pre-allocated buffer for hba
262 * @san_buf: pre-allocated buffer for san
263 * @scsi_buf: pre-allocated buffer for scsi
264 */
Christof Schmittd46f3842009-08-18 15:43:07 +0200265struct zfcp_dbf {
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100266 debug_info_t *pay;
Swen Schillig57717102009-08-18 15:43:21 +0200267 debug_info_t *rec;
268 debug_info_t *hba;
269 debug_info_t *san;
270 debug_info_t *scsi;
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100271 spinlock_t pay_lock;
Swen Schillig57717102009-08-18 15:43:21 +0200272 spinlock_t rec_lock;
273 spinlock_t hba_lock;
274 spinlock_t san_lock;
275 spinlock_t scsi_lock;
Swen Schilligea4a3a62010-12-02 15:16:16 +0100276 struct zfcp_dbf_pay pay_buf;
Swen Schilligae0904f2010-12-02 15:16:12 +0100277 struct zfcp_dbf_rec rec_buf;
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100278 struct zfcp_dbf_hba hba_buf;
Swen Schillig2c55b752010-12-02 15:16:13 +0100279 struct zfcp_dbf_san san_buf;
Swen Schillig250a1352010-12-02 15:16:15 +0100280 struct zfcp_dbf_scsi scsi_buf;
Christof Schmittd46f3842009-08-18 15:43:07 +0200281};
282
Christof Schmittdcd20e22009-08-18 15:43:08 +0200283static inline
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100284void zfcp_dbf_hba_fsf_resp(char *tag, int level, struct zfcp_fsf_req *req)
Christof Schmitt2e261af2009-08-18 15:43:09 +0200285{
Hendrik Brueckner8e6a8282013-09-18 17:21:34 +0200286 if (debug_level_enabled(req->adapter->dbf->hba, level))
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100287 zfcp_dbf_hba_fsf_res(tag, req);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200288}
289
290/**
Swen Schillig57717102009-08-18 15:43:21 +0200291 * zfcp_dbf_hba_fsf_response - trace event for request completion
Swen Schillig250a1352010-12-02 15:16:15 +0100292 * @req: request that has been completed
Christof Schmitt2e261af2009-08-18 15:43:09 +0200293 */
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100294static inline
295void zfcp_dbf_hba_fsf_response(struct zfcp_fsf_req *req)
Christof Schmitt2e261af2009-08-18 15:43:09 +0200296{
Christof Schmitt2e261af2009-08-18 15:43:09 +0200297 struct fsf_qtcb *qtcb = req->qtcb;
298
299 if ((qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
300 (qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100301 zfcp_dbf_hba_fsf_resp("fs_perr", 1, req);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200302
303 } else if (qtcb->header.fsf_status != FSF_GOOD) {
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100304 zfcp_dbf_hba_fsf_resp("fs_ferr", 1, req);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200305
306 } else if ((req->fsf_command == FSF_QTCB_OPEN_PORT_WITH_DID) ||
307 (req->fsf_command == FSF_QTCB_OPEN_LUN)) {
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100308 zfcp_dbf_hba_fsf_resp("fs_open", 4, req);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200309
310 } else if (qtcb->header.log_length) {
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100311 zfcp_dbf_hba_fsf_resp("fs_qtcb", 5, req);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200312
313 } else {
Swen Schilliga54ca0f2010-12-02 15:16:14 +0100314 zfcp_dbf_hba_fsf_resp("fs_norm", 6, req);
Christof Schmitt2e261af2009-08-18 15:43:09 +0200315 }
Christof Schmitt2e261af2009-08-18 15:43:09 +0200316}
317
318static inline
Swen Schillig250a1352010-12-02 15:16:15 +0100319void _zfcp_dbf_scsi(char *tag, int level, struct scsi_cmnd *scmd,
320 struct zfcp_fsf_req *req)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200321{
Swen Schillig250a1352010-12-02 15:16:15 +0100322 struct zfcp_adapter *adapter = (struct zfcp_adapter *)
323 scmd->device->host->hostdata[0];
324
Hendrik Brueckner8e6a8282013-09-18 17:21:34 +0200325 if (debug_level_enabled(adapter->dbf->scsi, level))
Swen Schillig250a1352010-12-02 15:16:15 +0100326 zfcp_dbf_scsi(tag, scmd, req);
Christof Schmittdcd20e22009-08-18 15:43:08 +0200327}
328
329/**
Swen Schillig57717102009-08-18 15:43:21 +0200330 * zfcp_dbf_scsi_result - trace event for SCSI command completion
Christof Schmittdcd20e22009-08-18 15:43:08 +0200331 * @scmd: SCSI command pointer
Christof Schmittab725282010-02-17 11:18:57 +0100332 * @req: FSF request used to issue SCSI command
Christof Schmittdcd20e22009-08-18 15:43:08 +0200333 */
334static inline
Swen Schillig250a1352010-12-02 15:16:15 +0100335void zfcp_dbf_scsi_result(struct scsi_cmnd *scmd, struct zfcp_fsf_req *req)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200336{
Christof Schmittab725282010-02-17 11:18:57 +0100337 if (scmd->result != 0)
Swen Schillig250a1352010-12-02 15:16:15 +0100338 _zfcp_dbf_scsi("rsl_err", 3, scmd, req);
Christof Schmittab725282010-02-17 11:18:57 +0100339 else if (scmd->retries > 0)
Swen Schillig250a1352010-12-02 15:16:15 +0100340 _zfcp_dbf_scsi("rsl_ret", 4, scmd, req);
Christof Schmittab725282010-02-17 11:18:57 +0100341 else
Swen Schillig250a1352010-12-02 15:16:15 +0100342 _zfcp_dbf_scsi("rsl_nor", 6, scmd, req);
Christof Schmittab725282010-02-17 11:18:57 +0100343}
344
345/**
346 * zfcp_dbf_scsi_fail_send - trace event for failure to send SCSI command
Christof Schmittab725282010-02-17 11:18:57 +0100347 * @scmd: SCSI command pointer
348 */
349static inline
Swen Schillig250a1352010-12-02 15:16:15 +0100350void zfcp_dbf_scsi_fail_send(struct scsi_cmnd *scmd)
Christof Schmittab725282010-02-17 11:18:57 +0100351{
Swen Schillig250a1352010-12-02 15:16:15 +0100352 _zfcp_dbf_scsi("rsl_fai", 4, scmd, NULL);
Christof Schmittdcd20e22009-08-18 15:43:08 +0200353}
354
355/**
Swen Schillig57717102009-08-18 15:43:21 +0200356 * zfcp_dbf_scsi_abort - trace event for SCSI command abort
Christof Schmittdcd20e22009-08-18 15:43:08 +0200357 * @tag: tag indicating success or failure of abort operation
Christof Schmittdcd20e22009-08-18 15:43:08 +0200358 * @scmd: SCSI command to be aborted
Swen Schillig250a1352010-12-02 15:16:15 +0100359 * @fsf_req: request containing abort (might be NULL)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200360 */
361static inline
Swen Schillig250a1352010-12-02 15:16:15 +0100362void zfcp_dbf_scsi_abort(char *tag, struct scsi_cmnd *scmd,
363 struct zfcp_fsf_req *fsf_req)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200364{
Swen Schillig250a1352010-12-02 15:16:15 +0100365 _zfcp_dbf_scsi(tag, 1, scmd, fsf_req);
Christof Schmittdcd20e22009-08-18 15:43:08 +0200366}
367
368/**
Swen Schillig57717102009-08-18 15:43:21 +0200369 * zfcp_dbf_scsi_devreset - trace event for Logical Unit or Target Reset
Christof Schmittdcd20e22009-08-18 15:43:08 +0200370 * @tag: tag indicating success or failure of reset operation
Christof Schmittb62a8d92010-09-08 14:39:55 +0200371 * @scmnd: SCSI command which caused this error recovery
Christof Schmittdcd20e22009-08-18 15:43:08 +0200372 * @flag: indicates type of reset (Target Reset, Logical Unit Reset)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200373 */
374static inline
Swen Schillig250a1352010-12-02 15:16:15 +0100375void zfcp_dbf_scsi_devreset(char *tag, struct scsi_cmnd *scmnd, u8 flag)
Christof Schmittdcd20e22009-08-18 15:43:08 +0200376{
Swen Schillig250a1352010-12-02 15:16:15 +0100377 char tmp_tag[ZFCP_DBF_TAG_LEN];
Christof Schmittb62a8d92010-09-08 14:39:55 +0200378
Swen Schillig250a1352010-12-02 15:16:15 +0100379 if (flag == FCP_TMF_TGT_RESET)
380 memcpy(tmp_tag, "tr_", 3);
381 else
382 memcpy(tmp_tag, "lr_", 3);
383
384 memcpy(&tmp_tag[3], tag, 4);
385 _zfcp_dbf_scsi(tmp_tag, 1, scmnd, NULL);
Christof Schmittdcd20e22009-08-18 15:43:08 +0200386}
387
Christof Schmitt2b604c92008-03-31 11:15:28 +0200388#endif /* ZFCP_DBF_H */