zfcp_dbf.c 22 KB

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