zfcp_dbf.c 26 KB

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