zfcp_dbf.c 26 KB

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