zfcp: restore tracing of handle for port and LUN with HBA records
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / s390 / scsi / zfcp_dbf.h
... / ...
CommitLineData
1/*
2 * zfcp device driver
3 * debug feature declarations
4 *
5 * Copyright IBM Corp. 2008, 2015
6 */
7
8#ifndef ZFCP_DBF_H
9#define ZFCP_DBF_H
10
11#include <scsi/fc/fc_fcp.h>
12#include "zfcp_ext.h"
13#include "zfcp_fsf.h"
14#include "zfcp_def.h"
15
16#define ZFCP_DBF_TAG_LEN 7
17
18#define ZFCP_DBF_INVALID_LUN 0xFFFFFFFFFFFFFFFFull
19
20enum zfcp_dbf_pseudo_erp_act_type {
21 ZFCP_PSEUDO_ERP_ACTION_RPORT_ADD = 0xff,
22 ZFCP_PSEUDO_ERP_ACTION_RPORT_DEL = 0xfe,
23};
24
25/**
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 {
33 u32 ready;
34 u32 running;
35 u8 want;
36 u8 need;
37} __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,
62};
63
64/**
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 {
78 u8 id;
79 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;
86 union {
87 struct zfcp_dbf_rec_trigger trig;
88 struct zfcp_dbf_rec_running run;
89 } u;
90} __packed;
91
92/**
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
120/**
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];
132 u32 fsf_status;
133 u8 fsf_status_qual[FSF_STATUS_QUALIFIER_SIZE];
134 u32 port_handle;
135 u32 lun_handle;
136} __packed;
137
138/**
139 * struct zfcp_dbf_hba_uss - trace record for unsolicited status
140 * @status_type: type of unsolicited status
141 * @status_subtype: subtype of unsolicited status
142 * @d_id: destination ID
143 * @lun: logical unit number
144 * @queue_designator: queue designator
145 */
146struct zfcp_dbf_hba_uss {
147 u32 status_type;
148 u32 status_subtype;
149 u32 d_id;
150 u64 lun;
151 u64 queue_designator;
152} __packed;
153
154/**
155 * enum zfcp_dbf_hba_id - HBA trace record identifier
156 * @ZFCP_DBF_HBA_RES: response trace record
157 * @ZFCP_DBF_HBA_USS: unsolicited status trace record
158 * @ZFCP_DBF_HBA_BIT: bit error trace record
159 */
160enum zfcp_dbf_hba_id {
161 ZFCP_DBF_HBA_RES = 1,
162 ZFCP_DBF_HBA_USS = 2,
163 ZFCP_DBF_HBA_BIT = 3,
164 ZFCP_DBF_HBA_BASIC = 4,
165};
166
167/**
168 * struct zfcp_dbf_hba - common trace record for HBA records
169 * @id: unique number of recovery record type
170 * @tag: identifier string specifying the location of initiation
171 * @fsf_req_id: request id for fsf requests
172 * @fsf_req_status: status of fsf request
173 * @fsf_cmd: fsf command
174 * @fsf_seq_no: fsf sequence number
175 * @pl_len: length of payload stored as zfcp_dbf_pay
176 * @u: record type specific data
177 */
178struct zfcp_dbf_hba {
179 u8 id;
180 char tag[ZFCP_DBF_TAG_LEN];
181 u64 fsf_req_id;
182 u32 fsf_req_status;
183 u32 fsf_cmd;
184 u32 fsf_seq_no;
185 u16 pl_len;
186 union {
187 struct zfcp_dbf_hba_res res;
188 struct zfcp_dbf_hba_uss uss;
189 struct fsf_bit_error_payload be;
190 } u;
191} __packed;
192
193/**
194 * enum zfcp_dbf_scsi_id - scsi trace record identifier
195 * @ZFCP_DBF_SCSI_CMND: scsi command trace record
196 */
197enum zfcp_dbf_scsi_id {
198 ZFCP_DBF_SCSI_CMND = 1,
199};
200
201/**
202 * struct zfcp_dbf_scsi - common trace record for SCSI records
203 * @id: unique number of recovery record type
204 * @tag: identifier string specifying the location of initiation
205 * @scsi_id: scsi device id
206 * @scsi_lun: scsi device logical unit number
207 * @scsi_result: scsi result
208 * @scsi_retries: current retry number of scsi request
209 * @scsi_allowed: allowed retries
210 * @fcp_rsp_info: FCP response info
211 * @scsi_opcode: scsi opcode
212 * @fsf_req_id: request id of fsf request
213 * @host_scribble: LLD specific data attached to SCSI request
214 * @pl_len: length of paload stored as zfcp_dbf_pay
215 * @fsf_rsp: response for fsf request
216 */
217struct zfcp_dbf_scsi {
218 u8 id;
219 char tag[ZFCP_DBF_TAG_LEN];
220 u32 scsi_id;
221 u32 scsi_lun;
222 u32 scsi_result;
223 u8 scsi_retries;
224 u8 scsi_allowed;
225 u8 fcp_rsp_info;
226#define ZFCP_DBF_SCSI_OPCODE 16
227 u8 scsi_opcode[ZFCP_DBF_SCSI_OPCODE];
228 u64 fsf_req_id;
229 u64 host_scribble;
230 u16 pl_len;
231 struct fcp_resp_with_ext fcp_rsp;
232} __packed;
233
234/**
235 * struct zfcp_dbf_pay - trace record for unformatted payload information
236 * @area: area this record is originated from
237 * @counter: ascending record number
238 * @fsf_req_id: request id of fsf request
239 * @data: unformatted data
240 */
241struct zfcp_dbf_pay {
242 u8 counter;
243 char area[ZFCP_DBF_TAG_LEN];
244 u64 fsf_req_id;
245#define ZFCP_DBF_PAY_MAX_REC 0x100
246 char data[ZFCP_DBF_PAY_MAX_REC];
247} __packed;
248
249/**
250 * struct zfcp_dbf - main dbf trace structure
251 * @pay: reference to payload trace area
252 * @rec: reference to recovery trace area
253 * @hba: reference to hba trace area
254 * @san: reference to san trace area
255 * @scsi: reference to scsi trace area
256 * @pay_lock: lock protecting payload trace buffer
257 * @rec_lock: lock protecting recovery trace buffer
258 * @hba_lock: lock protecting hba trace buffer
259 * @san_lock: lock protecting san trace buffer
260 * @scsi_lock: lock protecting scsi trace buffer
261 * @pay_buf: pre-allocated buffer for payload
262 * @rec_buf: pre-allocated buffer for recovery
263 * @hba_buf: pre-allocated buffer for hba
264 * @san_buf: pre-allocated buffer for san
265 * @scsi_buf: pre-allocated buffer for scsi
266 */
267struct zfcp_dbf {
268 debug_info_t *pay;
269 debug_info_t *rec;
270 debug_info_t *hba;
271 debug_info_t *san;
272 debug_info_t *scsi;
273 spinlock_t pay_lock;
274 spinlock_t rec_lock;
275 spinlock_t hba_lock;
276 spinlock_t san_lock;
277 spinlock_t scsi_lock;
278 struct zfcp_dbf_pay pay_buf;
279 struct zfcp_dbf_rec rec_buf;
280 struct zfcp_dbf_hba hba_buf;
281 struct zfcp_dbf_san san_buf;
282 struct zfcp_dbf_scsi scsi_buf;
283};
284
285static inline
286void zfcp_dbf_hba_fsf_resp(char *tag, int level, struct zfcp_fsf_req *req)
287{
288 if (level <= req->adapter->dbf->hba->level)
289 zfcp_dbf_hba_fsf_res(tag, level, req);
290}
291
292/**
293 * zfcp_dbf_hba_fsf_response - trace event for request completion
294 * @req: request that has been completed
295 */
296static inline
297void zfcp_dbf_hba_fsf_response(struct zfcp_fsf_req *req)
298{
299 struct fsf_qtcb *qtcb = req->qtcb;
300
301 if ((qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
302 (qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
303 zfcp_dbf_hba_fsf_resp("fs_perr", 1, req);
304
305 } else if (qtcb->header.fsf_status != FSF_GOOD) {
306 zfcp_dbf_hba_fsf_resp("fs_ferr", 1, req);
307
308 } else if ((req->fsf_command == FSF_QTCB_OPEN_PORT_WITH_DID) ||
309 (req->fsf_command == FSF_QTCB_OPEN_LUN)) {
310 zfcp_dbf_hba_fsf_resp("fs_open", 4, req);
311
312 } else if (qtcb->header.log_length) {
313 zfcp_dbf_hba_fsf_resp("fs_qtcb", 5, req);
314
315 } else {
316 zfcp_dbf_hba_fsf_resp("fs_norm", 6, req);
317 }
318}
319
320static inline
321void _zfcp_dbf_scsi(char *tag, int level, struct scsi_cmnd *scmd,
322 struct zfcp_fsf_req *req)
323{
324 struct zfcp_adapter *adapter = (struct zfcp_adapter *)
325 scmd->device->host->hostdata[0];
326
327 if (level <= adapter->dbf->scsi->level)
328 zfcp_dbf_scsi(tag, level, scmd, req);
329}
330
331/**
332 * zfcp_dbf_scsi_result - trace event for SCSI command completion
333 * @scmd: SCSI command pointer
334 * @req: FSF request used to issue SCSI command
335 */
336static inline
337void zfcp_dbf_scsi_result(struct scsi_cmnd *scmd, struct zfcp_fsf_req *req)
338{
339 if (scmd->result != 0)
340 _zfcp_dbf_scsi("rsl_err", 3, scmd, req);
341 else if (scmd->retries > 0)
342 _zfcp_dbf_scsi("rsl_ret", 4, scmd, req);
343 else
344 _zfcp_dbf_scsi("rsl_nor", 6, scmd, req);
345}
346
347/**
348 * zfcp_dbf_scsi_fail_send - trace event for failure to send SCSI command
349 * @scmd: SCSI command pointer
350 */
351static inline
352void zfcp_dbf_scsi_fail_send(struct scsi_cmnd *scmd)
353{
354 _zfcp_dbf_scsi("rsl_fai", 4, scmd, NULL);
355}
356
357/**
358 * zfcp_dbf_scsi_abort - trace event for SCSI command abort
359 * @tag: tag indicating success or failure of abort operation
360 * @scmd: SCSI command to be aborted
361 * @fsf_req: request containing abort (might be NULL)
362 */
363static inline
364void zfcp_dbf_scsi_abort(char *tag, struct scsi_cmnd *scmd,
365 struct zfcp_fsf_req *fsf_req)
366{
367 _zfcp_dbf_scsi(tag, 1, scmd, fsf_req);
368}
369
370/**
371 * zfcp_dbf_scsi_devreset - trace event for Logical Unit or Target Reset
372 * @tag: tag indicating success or failure of reset operation
373 * @scmnd: SCSI command which caused this error recovery
374 * @flag: indicates type of reset (Target Reset, Logical Unit Reset)
375 */
376static inline
377void zfcp_dbf_scsi_devreset(char *tag, struct scsi_cmnd *scmnd, u8 flag)
378{
379 char tmp_tag[ZFCP_DBF_TAG_LEN];
380
381 if (flag == FCP_TMF_TGT_RESET)
382 memcpy(tmp_tag, "tr_", 3);
383 else
384 memcpy(tmp_tag, "lr_", 3);
385
386 memcpy(&tmp_tag[3], tag, 4);
387 _zfcp_dbf_scsi(tmp_tag, 1, scmnd, NULL);
388}
389
390#endif /* ZFCP_DBF_H */