zfcp_dbf.c 19 KB

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