zfcp_dbf.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. /*
  2. * zfcp device driver
  3. *
  4. * Debug traces for zfcp.
  5. *
  6. * Copyright IBM Corp. 2002, 2017
  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_run_lvl - trace event related to running recovery
  244. * @level: trace level to be used for event
  245. * @tag: identifier for event
  246. * @erp: erp_action running
  247. */
  248. void zfcp_dbf_rec_run_lvl(int level, char *tag, struct zfcp_erp_action *erp)
  249. {
  250. struct zfcp_dbf *dbf = erp->adapter->dbf;
  251. struct zfcp_dbf_rec *rec = &dbf->rec_buf;
  252. unsigned long flags;
  253. spin_lock_irqsave(&dbf->rec_lock, flags);
  254. memset(rec, 0, sizeof(*rec));
  255. rec->id = ZFCP_DBF_REC_RUN;
  256. memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
  257. zfcp_dbf_set_common(rec, erp->adapter, erp->port, erp->sdev);
  258. rec->u.run.fsf_req_id = erp->fsf_req_id;
  259. rec->u.run.rec_status = erp->status;
  260. rec->u.run.rec_step = erp->step;
  261. rec->u.run.rec_action = erp->action;
  262. if (erp->sdev)
  263. rec->u.run.rec_count =
  264. atomic_read(&sdev_to_zfcp(erp->sdev)->erp_counter);
  265. else if (erp->port)
  266. rec->u.run.rec_count = atomic_read(&erp->port->erp_counter);
  267. else
  268. rec->u.run.rec_count = atomic_read(&erp->adapter->erp_counter);
  269. debug_event(dbf->rec, level, rec, sizeof(*rec));
  270. spin_unlock_irqrestore(&dbf->rec_lock, flags);
  271. }
  272. /**
  273. * zfcp_dbf_rec_run - trace event related to running recovery
  274. * @tag: identifier for event
  275. * @erp: erp_action running
  276. */
  277. void zfcp_dbf_rec_run(char *tag, struct zfcp_erp_action *erp)
  278. {
  279. zfcp_dbf_rec_run_lvl(1, tag, erp);
  280. }
  281. /**
  282. * zfcp_dbf_rec_run_wka - trace wka port event with info like running recovery
  283. * @tag: identifier for event
  284. * @wka_port: well known address port
  285. * @req_id: request ID to correlate with potential HBA trace record
  286. */
  287. void zfcp_dbf_rec_run_wka(char *tag, struct zfcp_fc_wka_port *wka_port,
  288. u64 req_id)
  289. {
  290. struct zfcp_dbf *dbf = wka_port->adapter->dbf;
  291. struct zfcp_dbf_rec *rec = &dbf->rec_buf;
  292. unsigned long flags;
  293. spin_lock_irqsave(&dbf->rec_lock, flags);
  294. memset(rec, 0, sizeof(*rec));
  295. rec->id = ZFCP_DBF_REC_RUN;
  296. memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
  297. rec->port_status = wka_port->status;
  298. rec->d_id = wka_port->d_id;
  299. rec->lun = ZFCP_DBF_INVALID_LUN;
  300. rec->u.run.fsf_req_id = req_id;
  301. rec->u.run.rec_status = ~0;
  302. rec->u.run.rec_step = ~0;
  303. rec->u.run.rec_action = ~0;
  304. rec->u.run.rec_count = ~0;
  305. debug_event(dbf->rec, 1, rec, sizeof(*rec));
  306. spin_unlock_irqrestore(&dbf->rec_lock, flags);
  307. }
  308. static inline
  309. void zfcp_dbf_san(char *tag, struct zfcp_dbf *dbf,
  310. char *paytag, struct scatterlist *sg, u8 id, u16 len,
  311. u64 req_id, u32 d_id, u16 cap_len)
  312. {
  313. struct zfcp_dbf_san *rec = &dbf->san_buf;
  314. u16 rec_len;
  315. unsigned long flags;
  316. struct zfcp_dbf_pay *payload = &dbf->pay_buf;
  317. u16 pay_sum = 0;
  318. spin_lock_irqsave(&dbf->san_lock, flags);
  319. memset(rec, 0, sizeof(*rec));
  320. rec->id = id;
  321. rec->fsf_req_id = req_id;
  322. rec->d_id = d_id;
  323. memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
  324. rec->pl_len = len; /* full length even if we cap pay below */
  325. if (!sg)
  326. goto out;
  327. rec_len = min_t(unsigned int, sg->length, ZFCP_DBF_SAN_MAX_PAYLOAD);
  328. memcpy(rec->payload, sg_virt(sg), rec_len); /* part of 1st sg entry */
  329. if (len <= rec_len)
  330. goto out; /* skip pay record if full content in rec->payload */
  331. /* if (len > rec_len):
  332. * dump data up to cap_len ignoring small duplicate in rec->payload
  333. */
  334. spin_lock(&dbf->pay_lock);
  335. memset(payload, 0, sizeof(*payload));
  336. memcpy(payload->area, paytag, ZFCP_DBF_TAG_LEN);
  337. payload->fsf_req_id = req_id;
  338. payload->counter = 0;
  339. for (; sg && pay_sum < cap_len; sg = sg_next(sg)) {
  340. u16 pay_len, offset = 0;
  341. while (offset < sg->length && pay_sum < cap_len) {
  342. pay_len = min((u16)ZFCP_DBF_PAY_MAX_REC,
  343. (u16)(sg->length - offset));
  344. /* cap_len <= pay_sum < cap_len+ZFCP_DBF_PAY_MAX_REC */
  345. memcpy(payload->data, sg_virt(sg) + offset, pay_len);
  346. debug_event(dbf->pay, 1, payload,
  347. zfcp_dbf_plen(pay_len));
  348. payload->counter++;
  349. offset += pay_len;
  350. pay_sum += pay_len;
  351. }
  352. }
  353. spin_unlock(&dbf->pay_lock);
  354. out:
  355. debug_event(dbf->san, 1, rec, sizeof(*rec));
  356. spin_unlock_irqrestore(&dbf->san_lock, flags);
  357. }
  358. /**
  359. * zfcp_dbf_san_req - trace event for issued SAN request
  360. * @tag: identifier for event
  361. * @fsf_req: request containing issued CT data
  362. * d_id: destination ID
  363. */
  364. void zfcp_dbf_san_req(char *tag, struct zfcp_fsf_req *fsf, u32 d_id)
  365. {
  366. struct zfcp_dbf *dbf = fsf->adapter->dbf;
  367. struct zfcp_fsf_ct_els *ct_els = fsf->data;
  368. u16 length;
  369. length = (u16)zfcp_qdio_real_bytes(ct_els->req);
  370. zfcp_dbf_san(tag, dbf, "san_req", ct_els->req, ZFCP_DBF_SAN_REQ,
  371. length, fsf->req_id, d_id, length);
  372. }
  373. static u16 zfcp_dbf_san_res_cap_len_if_gpn_ft(char *tag,
  374. struct zfcp_fsf_req *fsf,
  375. u16 len)
  376. {
  377. struct zfcp_fsf_ct_els *ct_els = fsf->data;
  378. struct fc_ct_hdr *reqh = sg_virt(ct_els->req);
  379. struct fc_ns_gid_ft *reqn = (struct fc_ns_gid_ft *)(reqh + 1);
  380. struct scatterlist *resp_entry = ct_els->resp;
  381. struct fc_ct_hdr *resph;
  382. struct fc_gpn_ft_resp *acc;
  383. int max_entries, x, last = 0;
  384. if (!(memcmp(tag, "fsscth2", 7) == 0
  385. && ct_els->d_id == FC_FID_DIR_SERV
  386. && reqh->ct_rev == FC_CT_REV
  387. && reqh->ct_in_id[0] == 0
  388. && reqh->ct_in_id[1] == 0
  389. && reqh->ct_in_id[2] == 0
  390. && reqh->ct_fs_type == FC_FST_DIR
  391. && reqh->ct_fs_subtype == FC_NS_SUBTYPE
  392. && reqh->ct_options == 0
  393. && reqh->_ct_resvd1 == 0
  394. && reqh->ct_cmd == FC_NS_GPN_FT
  395. /* reqh->ct_mr_size can vary so do not match but read below */
  396. && reqh->_ct_resvd2 == 0
  397. && reqh->ct_reason == 0
  398. && reqh->ct_explan == 0
  399. && reqh->ct_vendor == 0
  400. && reqn->fn_resvd == 0
  401. && reqn->fn_domain_id_scope == 0
  402. && reqn->fn_area_id_scope == 0
  403. && reqn->fn_fc4_type == FC_TYPE_FCP))
  404. return len; /* not GPN_FT response so do not cap */
  405. acc = sg_virt(resp_entry);
  406. /* cap all but accept CT responses to at least the CT header */
  407. resph = (struct fc_ct_hdr *)acc;
  408. if ((ct_els->status) ||
  409. (resph->ct_cmd != cpu_to_be16(FC_FS_ACC)))
  410. return max(FC_CT_HDR_LEN, ZFCP_DBF_SAN_MAX_PAYLOAD);
  411. max_entries = (reqh->ct_mr_size * 4 / sizeof(struct fc_gpn_ft_resp))
  412. + 1 /* zfcp_fc_scan_ports: bytes correct, entries off-by-one
  413. * to account for header as 1st pseudo "entry" */;
  414. /* the basic CT_IU preamble is the same size as one entry in the GPN_FT
  415. * response, allowing us to skip special handling for it - just skip it
  416. */
  417. for (x = 1; x < max_entries && !last; x++) {
  418. if (x % (ZFCP_FC_GPN_FT_ENT_PAGE + 1))
  419. acc++;
  420. else
  421. acc = sg_virt(++resp_entry);
  422. last = acc->fp_flags & FC_NS_FID_LAST;
  423. }
  424. len = min(len, (u16)(x * sizeof(struct fc_gpn_ft_resp)));
  425. return len; /* cap after last entry */
  426. }
  427. /**
  428. * zfcp_dbf_san_res - trace event for received SAN request
  429. * @tag: identifier for event
  430. * @fsf_req: request containing issued CT data
  431. */
  432. void zfcp_dbf_san_res(char *tag, struct zfcp_fsf_req *fsf)
  433. {
  434. struct zfcp_dbf *dbf = fsf->adapter->dbf;
  435. struct zfcp_fsf_ct_els *ct_els = fsf->data;
  436. u16 length;
  437. length = (u16)zfcp_qdio_real_bytes(ct_els->resp);
  438. zfcp_dbf_san(tag, dbf, "san_res", ct_els->resp, ZFCP_DBF_SAN_RES,
  439. length, fsf->req_id, ct_els->d_id,
  440. zfcp_dbf_san_res_cap_len_if_gpn_ft(tag, fsf, length));
  441. }
  442. /**
  443. * zfcp_dbf_san_in_els - trace event for incoming ELS
  444. * @tag: identifier for event
  445. * @fsf_req: request containing issued CT data
  446. */
  447. void zfcp_dbf_san_in_els(char *tag, struct zfcp_fsf_req *fsf)
  448. {
  449. struct zfcp_dbf *dbf = fsf->adapter->dbf;
  450. struct fsf_status_read_buffer *srb =
  451. (struct fsf_status_read_buffer *) fsf->data;
  452. u16 length;
  453. struct scatterlist sg;
  454. length = (u16)(srb->length -
  455. offsetof(struct fsf_status_read_buffer, payload));
  456. sg_init_one(&sg, srb->payload.data, length);
  457. zfcp_dbf_san(tag, dbf, "san_els", &sg, ZFCP_DBF_SAN_ELS, length,
  458. fsf->req_id, ntoh24(srb->d_id), length);
  459. }
  460. /**
  461. * zfcp_dbf_scsi - trace event for scsi commands
  462. * @tag: identifier for event
  463. * @sc: pointer to struct scsi_cmnd
  464. * @fsf: pointer to struct zfcp_fsf_req
  465. */
  466. void zfcp_dbf_scsi(char *tag, int level, struct scsi_cmnd *sc,
  467. struct zfcp_fsf_req *fsf)
  468. {
  469. struct zfcp_adapter *adapter =
  470. (struct zfcp_adapter *) sc->device->host->hostdata[0];
  471. struct zfcp_dbf *dbf = adapter->dbf;
  472. struct zfcp_dbf_scsi *rec = &dbf->scsi_buf;
  473. struct fcp_resp_with_ext *fcp_rsp;
  474. struct fcp_resp_rsp_info *fcp_rsp_info;
  475. unsigned long flags;
  476. spin_lock_irqsave(&dbf->scsi_lock, flags);
  477. memset(rec, 0, sizeof(*rec));
  478. memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
  479. rec->id = ZFCP_DBF_SCSI_CMND;
  480. rec->scsi_result = sc->result;
  481. rec->scsi_retries = sc->retries;
  482. rec->scsi_allowed = sc->allowed;
  483. rec->scsi_id = sc->device->id;
  484. rec->scsi_lun = (u32)sc->device->lun;
  485. rec->scsi_lun_64_hi = (u32)(sc->device->lun >> 32);
  486. rec->host_scribble = (unsigned long)sc->host_scribble;
  487. memcpy(rec->scsi_opcode, sc->cmnd,
  488. min((int)sc->cmd_len, ZFCP_DBF_SCSI_OPCODE));
  489. if (fsf) {
  490. rec->fsf_req_id = fsf->req_id;
  491. rec->pl_len = FCP_RESP_WITH_EXT;
  492. fcp_rsp = (struct fcp_resp_with_ext *)
  493. &(fsf->qtcb->bottom.io.fcp_rsp);
  494. /* mandatory parts of FCP_RSP IU in this SCSI record */
  495. memcpy(&rec->fcp_rsp, fcp_rsp, FCP_RESP_WITH_EXT);
  496. if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL) {
  497. fcp_rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
  498. rec->fcp_rsp_info = fcp_rsp_info->rsp_code;
  499. rec->pl_len += be32_to_cpu(fcp_rsp->ext.fr_rsp_len);
  500. }
  501. if (fcp_rsp->resp.fr_flags & FCP_SNS_LEN_VAL) {
  502. rec->pl_len += be32_to_cpu(fcp_rsp->ext.fr_sns_len);
  503. }
  504. /* complete FCP_RSP IU in associated PAYload record
  505. * but only if there are optional parts
  506. */
  507. if (fcp_rsp->resp.fr_flags != 0)
  508. zfcp_dbf_pl_write(
  509. dbf, fcp_rsp,
  510. /* at least one full PAY record
  511. * but not beyond hardware response field
  512. */
  513. min_t(u16, max_t(u16, rec->pl_len,
  514. ZFCP_DBF_PAY_MAX_REC),
  515. FSF_FCP_RSP_SIZE),
  516. "fcp_riu", fsf->req_id);
  517. }
  518. debug_event(dbf->scsi, level, rec, sizeof(*rec));
  519. spin_unlock_irqrestore(&dbf->scsi_lock, flags);
  520. }
  521. static debug_info_t *zfcp_dbf_reg(const char *name, int size, int rec_size)
  522. {
  523. struct debug_info *d;
  524. d = debug_register(name, size, 1, rec_size);
  525. if (!d)
  526. return NULL;
  527. debug_register_view(d, &debug_hex_ascii_view);
  528. debug_set_level(d, dbflevel);
  529. return d;
  530. }
  531. static void zfcp_dbf_unregister(struct zfcp_dbf *dbf)
  532. {
  533. if (!dbf)
  534. return;
  535. debug_unregister(dbf->scsi);
  536. debug_unregister(dbf->san);
  537. debug_unregister(dbf->hba);
  538. debug_unregister(dbf->pay);
  539. debug_unregister(dbf->rec);
  540. kfree(dbf);
  541. }
  542. /**
  543. * zfcp_adapter_debug_register - registers debug feature for an adapter
  544. * @adapter: pointer to adapter for which debug features should be registered
  545. * return: -ENOMEM on error, 0 otherwise
  546. */
  547. int zfcp_dbf_adapter_register(struct zfcp_adapter *adapter)
  548. {
  549. char name[DEBUG_MAX_NAME_LEN];
  550. struct zfcp_dbf *dbf;
  551. dbf = kzalloc(sizeof(struct zfcp_dbf), GFP_KERNEL);
  552. if (!dbf)
  553. return -ENOMEM;
  554. spin_lock_init(&dbf->pay_lock);
  555. spin_lock_init(&dbf->hba_lock);
  556. spin_lock_init(&dbf->san_lock);
  557. spin_lock_init(&dbf->scsi_lock);
  558. spin_lock_init(&dbf->rec_lock);
  559. /* debug feature area which records recovery activity */
  560. sprintf(name, "zfcp_%s_rec", dev_name(&adapter->ccw_device->dev));
  561. dbf->rec = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_rec));
  562. if (!dbf->rec)
  563. goto err_out;
  564. /* debug feature area which records HBA (FSF and QDIO) conditions */
  565. sprintf(name, "zfcp_%s_hba", dev_name(&adapter->ccw_device->dev));
  566. dbf->hba = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_hba));
  567. if (!dbf->hba)
  568. goto err_out;
  569. /* debug feature area which records payload info */
  570. sprintf(name, "zfcp_%s_pay", dev_name(&adapter->ccw_device->dev));
  571. dbf->pay = zfcp_dbf_reg(name, dbfsize * 2, sizeof(struct zfcp_dbf_pay));
  572. if (!dbf->pay)
  573. goto err_out;
  574. /* debug feature area which records SAN command failures and recovery */
  575. sprintf(name, "zfcp_%s_san", dev_name(&adapter->ccw_device->dev));
  576. dbf->san = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_san));
  577. if (!dbf->san)
  578. goto err_out;
  579. /* debug feature area which records SCSI command failures and recovery */
  580. sprintf(name, "zfcp_%s_scsi", dev_name(&adapter->ccw_device->dev));
  581. dbf->scsi = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_scsi));
  582. if (!dbf->scsi)
  583. goto err_out;
  584. adapter->dbf = dbf;
  585. return 0;
  586. err_out:
  587. zfcp_dbf_unregister(dbf);
  588. return -ENOMEM;
  589. }
  590. /**
  591. * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
  592. * @adapter: pointer to adapter for which debug features should be unregistered
  593. */
  594. void zfcp_dbf_adapter_unregister(struct zfcp_adapter *adapter)
  595. {
  596. struct zfcp_dbf *dbf = adapter->dbf;
  597. adapter->dbf = NULL;
  598. zfcp_dbf_unregister(dbf);
  599. }