zfcp_dbf.c 22 KB

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