zfcp_dbf.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. /*
  2. * zfcp device driver
  3. *
  4. * Debug traces for zfcp.
  5. *
  6. * Copyright IBM Corporation 2002, 2010
  7. */
  8. #define KMSG_COMPONENT "zfcp"
  9. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  10. #include <linux/module.h>
  11. #include <linux/ctype.h>
  12. #include <linux/slab.h>
  13. #include <asm/debug.h>
  14. #include "zfcp_dbf.h"
  15. #include "zfcp_ext.h"
  16. #include "zfcp_fc.h"
  17. static u32 dbfsize = 4;
  18. module_param(dbfsize, uint, 0400);
  19. MODULE_PARM_DESC(dbfsize,
  20. "number of pages for each debug feature area (default 4)");
  21. static inline unsigned int zfcp_dbf_plen(unsigned int offset)
  22. {
  23. return sizeof(struct zfcp_dbf_pay) + offset - ZFCP_DBF_PAY_MAX_REC;
  24. }
  25. static inline
  26. void zfcp_dbf_pl_write(struct zfcp_dbf *dbf, void *data, u16 length, char *area,
  27. u64 req_id)
  28. {
  29. struct zfcp_dbf_pay *pl = &dbf->pay_buf;
  30. u16 offset = 0, rec_length;
  31. spin_lock(&dbf->pay_lock);
  32. memset(pl, 0, sizeof(*pl));
  33. pl->fsf_req_id = req_id;
  34. memcpy(pl->area, area, ZFCP_DBF_TAG_LEN);
  35. while (offset < length) {
  36. rec_length = min((u16) ZFCP_DBF_PAY_MAX_REC,
  37. (u16) (length - offset));
  38. memcpy(pl->data, data + offset, rec_length);
  39. debug_event(dbf->pay, 1, pl, zfcp_dbf_plen(rec_length));
  40. offset += rec_length;
  41. pl->counter++;
  42. }
  43. spin_unlock(&dbf->pay_lock);
  44. }
  45. /**
  46. * zfcp_dbf_hba_fsf_res - trace event for fsf responses
  47. * @tag: tag indicating which kind of unsolicited status has been received
  48. * @req: request for which a response was received
  49. */
  50. void zfcp_dbf_hba_fsf_res(char *tag, struct zfcp_fsf_req *req)
  51. {
  52. struct zfcp_dbf *dbf = req->adapter->dbf;
  53. struct fsf_qtcb_prefix *q_pref = &req->qtcb->prefix;
  54. struct fsf_qtcb_header *q_head = &req->qtcb->header;
  55. struct zfcp_dbf_hba *rec = &dbf->hba_buf;
  56. unsigned long flags;
  57. spin_lock_irqsave(&dbf->hba_lock, flags);
  58. memset(rec, 0, sizeof(*rec));
  59. memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
  60. rec->id = ZFCP_DBF_HBA_RES;
  61. rec->fsf_req_id = req->req_id;
  62. rec->fsf_req_status = req->status;
  63. rec->fsf_cmd = req->fsf_command;
  64. rec->fsf_seq_no = req->seq_no;
  65. rec->u.res.req_issued = req->issued;
  66. rec->u.res.prot_status = q_pref->prot_status;
  67. rec->u.res.fsf_status = q_head->fsf_status;
  68. memcpy(rec->u.res.prot_status_qual, &q_pref->prot_status_qual,
  69. FSF_PROT_STATUS_QUAL_SIZE);
  70. memcpy(rec->u.res.fsf_status_qual, &q_head->fsf_status_qual,
  71. FSF_STATUS_QUALIFIER_SIZE);
  72. if (req->fsf_command != FSF_QTCB_FCP_CMND) {
  73. rec->pl_len = q_head->log_length;
  74. zfcp_dbf_pl_write(dbf, (char *)q_pref + q_head->log_start,
  75. rec->pl_len, "fsf_res", req->req_id);
  76. }
  77. debug_event(dbf->hba, 1, rec, sizeof(*rec));
  78. spin_unlock_irqrestore(&dbf->hba_lock, flags);
  79. }
  80. /**
  81. * zfcp_dbf_hba_fsf_uss - trace event for an unsolicited status buffer
  82. * @tag: tag indicating which kind of unsolicited status has been received
  83. * @req: request providing the unsolicited status
  84. */
  85. void zfcp_dbf_hba_fsf_uss(char *tag, struct zfcp_fsf_req *req)
  86. {
  87. struct zfcp_dbf *dbf = req->adapter->dbf;
  88. struct fsf_status_read_buffer *srb = req->data;
  89. struct zfcp_dbf_hba *rec = &dbf->hba_buf;
  90. unsigned long flags;
  91. spin_lock_irqsave(&dbf->hba_lock, flags);
  92. memset(rec, 0, sizeof(*rec));
  93. memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
  94. rec->id = ZFCP_DBF_HBA_USS;
  95. rec->fsf_req_id = req->req_id;
  96. rec->fsf_req_status = req->status;
  97. rec->fsf_cmd = req->fsf_command;
  98. if (!srb)
  99. goto log;
  100. rec->u.uss.status_type = srb->status_type;
  101. rec->u.uss.status_subtype = srb->status_subtype;
  102. rec->u.uss.d_id = ntoh24(srb->d_id);
  103. rec->u.uss.lun = srb->fcp_lun;
  104. memcpy(&rec->u.uss.queue_designator, &srb->queue_designator,
  105. sizeof(rec->u.uss.queue_designator));
  106. /* status read buffer payload length */
  107. rec->pl_len = (!srb->length) ? 0 : srb->length -
  108. offsetof(struct fsf_status_read_buffer, payload);
  109. if (rec->pl_len)
  110. zfcp_dbf_pl_write(dbf, srb->payload.data, rec->pl_len,
  111. "fsf_uss", req->req_id);
  112. log:
  113. debug_event(dbf->hba, 2, rec, sizeof(*rec));
  114. spin_unlock_irqrestore(&dbf->hba_lock, flags);
  115. }
  116. /**
  117. * zfcp_dbf_hba_bit_err - trace event for bit error conditions
  118. * @tag: tag indicating which kind of unsolicited status has been received
  119. * @req: request which caused the bit_error condition
  120. */
  121. void zfcp_dbf_hba_bit_err(char *tag, struct zfcp_fsf_req *req)
  122. {
  123. struct zfcp_dbf *dbf = req->adapter->dbf;
  124. struct zfcp_dbf_hba *rec = &dbf->hba_buf;
  125. struct fsf_status_read_buffer *sr_buf = req->data;
  126. unsigned long flags;
  127. spin_lock_irqsave(&dbf->hba_lock, flags);
  128. memset(rec, 0, sizeof(*rec));
  129. memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
  130. rec->id = ZFCP_DBF_HBA_BIT;
  131. rec->fsf_req_id = req->req_id;
  132. rec->fsf_req_status = req->status;
  133. rec->fsf_cmd = req->fsf_command;
  134. memcpy(&rec->u.be, &sr_buf->payload.bit_error,
  135. sizeof(struct fsf_bit_error_payload));
  136. debug_event(dbf->hba, 1, rec, sizeof(*rec));
  137. spin_unlock_irqrestore(&dbf->hba_lock, flags);
  138. }
  139. /**
  140. * zfcp_dbf_hba_def_err - trace event for deferred error messages
  141. * @adapter: pointer to struct zfcp_adapter
  142. * @req_id: request id which caused the deferred error message
  143. * @scount: number of sbals incl. the signaling sbal
  144. * @pl: array of all involved sbals
  145. */
  146. void zfcp_dbf_hba_def_err(struct zfcp_adapter *adapter, u64 req_id, u16 scount,
  147. void **pl)
  148. {
  149. struct zfcp_dbf *dbf = adapter->dbf;
  150. struct zfcp_dbf_pay *payload = &dbf->pay_buf;
  151. unsigned long flags;
  152. u16 length;
  153. if (!pl)
  154. return;
  155. spin_lock_irqsave(&dbf->pay_lock, flags);
  156. memset(payload, 0, sizeof(*payload));
  157. memcpy(payload->area, "def_err", 7);
  158. payload->fsf_req_id = req_id;
  159. payload->counter = 0;
  160. length = min((u16)sizeof(struct qdio_buffer),
  161. (u16)ZFCP_DBF_PAY_MAX_REC);
  162. while (payload->counter < scount && (char *)pl[payload->counter]) {
  163. memcpy(payload->data, (char *)pl[payload->counter], length);
  164. debug_event(dbf->pay, 1, payload, zfcp_dbf_plen(length));
  165. payload->counter++;
  166. }
  167. spin_unlock_irqrestore(&dbf->pay_lock, flags);
  168. }
  169. /**
  170. * zfcp_dbf_hba_basic - trace event for basic adapter events
  171. * @adapter: pointer to struct zfcp_adapter
  172. */
  173. void zfcp_dbf_hba_basic(char *tag, struct zfcp_adapter *adapter)
  174. {
  175. struct zfcp_dbf *dbf = adapter->dbf;
  176. struct zfcp_dbf_hba *rec = &dbf->hba_buf;
  177. unsigned long flags;
  178. spin_lock_irqsave(&dbf->hba_lock, flags);
  179. memset(rec, 0, sizeof(*rec));
  180. memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
  181. rec->id = ZFCP_DBF_HBA_BASIC;
  182. debug_event(dbf->hba, 1, rec, sizeof(*rec));
  183. spin_unlock_irqrestore(&dbf->hba_lock, flags);
  184. }
  185. static void zfcp_dbf_set_common(struct zfcp_dbf_rec *rec,
  186. struct zfcp_adapter *adapter,
  187. struct zfcp_port *port,
  188. struct scsi_device *sdev)
  189. {
  190. rec->adapter_status = atomic_read(&adapter->status);
  191. if (port) {
  192. rec->port_status = atomic_read(&port->status);
  193. rec->wwpn = port->wwpn;
  194. rec->d_id = port->d_id;
  195. }
  196. if (sdev) {
  197. rec->lun_status = atomic_read(&sdev_to_zfcp(sdev)->status);
  198. rec->lun = zfcp_scsi_dev_lun(sdev);
  199. }
  200. }
  201. /**
  202. * zfcp_dbf_rec_trig - trace event related to triggered recovery
  203. * @tag: identifier for event
  204. * @adapter: adapter on which the erp_action should run
  205. * @port: remote port involved in the erp_action
  206. * @sdev: scsi device involved in the erp_action
  207. * @want: wanted erp_action
  208. * @need: required erp_action
  209. *
  210. * The adapter->erp_lock has to be held.
  211. */
  212. void zfcp_dbf_rec_trig(char *tag, struct zfcp_adapter *adapter,
  213. struct zfcp_port *port, struct scsi_device *sdev,
  214. u8 want, u8 need)
  215. {
  216. struct zfcp_dbf *dbf = adapter->dbf;
  217. struct zfcp_dbf_rec *rec = &dbf->rec_buf;
  218. struct list_head *entry;
  219. unsigned long flags;
  220. spin_lock_irqsave(&dbf->rec_lock, flags);
  221. memset(rec, 0, sizeof(*rec));
  222. rec->id = ZFCP_DBF_REC_TRIG;
  223. memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
  224. zfcp_dbf_set_common(rec, adapter, port, sdev);
  225. list_for_each(entry, &adapter->erp_ready_head)
  226. rec->u.trig.ready++;
  227. list_for_each(entry, &adapter->erp_running_head)
  228. rec->u.trig.running++;
  229. rec->u.trig.want = want;
  230. rec->u.trig.need = need;
  231. debug_event(dbf->rec, 1, rec, sizeof(*rec));
  232. spin_unlock_irqrestore(&dbf->rec_lock, flags);
  233. }
  234. /**
  235. * zfcp_dbf_rec_run - trace event related to running recovery
  236. * @tag: identifier for event
  237. * @erp: erp_action running
  238. */
  239. void zfcp_dbf_rec_run(char *tag, struct zfcp_erp_action *erp)
  240. {
  241. struct zfcp_dbf *dbf = erp->adapter->dbf;
  242. struct zfcp_dbf_rec *rec = &dbf->rec_buf;
  243. unsigned long flags;
  244. spin_lock_irqsave(&dbf->rec_lock, flags);
  245. memset(rec, 0, sizeof(*rec));
  246. rec->id = ZFCP_DBF_REC_RUN;
  247. memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
  248. zfcp_dbf_set_common(rec, erp->adapter, erp->port, erp->sdev);
  249. rec->u.run.fsf_req_id = erp->fsf_req_id;
  250. rec->u.run.rec_status = erp->status;
  251. rec->u.run.rec_step = erp->step;
  252. rec->u.run.rec_action = erp->action;
  253. if (erp->sdev)
  254. rec->u.run.rec_count =
  255. atomic_read(&sdev_to_zfcp(erp->sdev)->erp_counter);
  256. else if (erp->port)
  257. rec->u.run.rec_count = atomic_read(&erp->port->erp_counter);
  258. else
  259. rec->u.run.rec_count = atomic_read(&erp->adapter->erp_counter);
  260. debug_event(dbf->rec, 1, rec, sizeof(*rec));
  261. spin_unlock_irqrestore(&dbf->rec_lock, flags);
  262. }
  263. static inline
  264. void zfcp_dbf_san(char *tag, struct zfcp_dbf *dbf, void *data, u8 id, u16 len,
  265. u64 req_id, u32 d_id)
  266. {
  267. struct zfcp_dbf_san *rec = &dbf->san_buf;
  268. u16 rec_len;
  269. unsigned long flags;
  270. spin_lock_irqsave(&dbf->san_lock, flags);
  271. memset(rec, 0, sizeof(*rec));
  272. rec->id = id;
  273. rec->fsf_req_id = req_id;
  274. rec->d_id = d_id;
  275. rec_len = min(len, (u16)ZFCP_DBF_SAN_MAX_PAYLOAD);
  276. memcpy(rec->payload, data, rec_len);
  277. memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
  278. debug_event(dbf->san, 1, rec, sizeof(*rec));
  279. spin_unlock_irqrestore(&dbf->san_lock, flags);
  280. }
  281. /**
  282. * zfcp_dbf_san_req - trace event for issued SAN request
  283. * @tag: indentifier for event
  284. * @fsf_req: request containing issued CT data
  285. * d_id: destination ID
  286. */
  287. void zfcp_dbf_san_req(char *tag, struct zfcp_fsf_req *fsf, u32 d_id)
  288. {
  289. struct zfcp_dbf *dbf = fsf->adapter->dbf;
  290. struct zfcp_fsf_ct_els *ct_els = fsf->data;
  291. u16 length;
  292. length = (u16)(ct_els->req->length + FC_CT_HDR_LEN);
  293. zfcp_dbf_san(tag, dbf, sg_virt(ct_els->req), ZFCP_DBF_SAN_REQ, length,
  294. fsf->req_id, d_id);
  295. }
  296. /**
  297. * zfcp_dbf_san_res - trace event for received SAN request
  298. * @tag: indentifier for event
  299. * @fsf_req: request containing issued CT data
  300. */
  301. void zfcp_dbf_san_res(char *tag, struct zfcp_fsf_req *fsf)
  302. {
  303. struct zfcp_dbf *dbf = fsf->adapter->dbf;
  304. struct zfcp_fsf_ct_els *ct_els = fsf->data;
  305. u16 length;
  306. length = (u16)(ct_els->resp->length + FC_CT_HDR_LEN);
  307. zfcp_dbf_san(tag, dbf, sg_virt(ct_els->resp), ZFCP_DBF_SAN_RES, length,
  308. fsf->req_id, 0);
  309. }
  310. /**
  311. * zfcp_dbf_san_in_els - trace event for incoming ELS
  312. * @tag: indentifier for event
  313. * @fsf_req: request containing issued CT data
  314. */
  315. void zfcp_dbf_san_in_els(char *tag, struct zfcp_fsf_req *fsf)
  316. {
  317. struct zfcp_dbf *dbf = fsf->adapter->dbf;
  318. struct fsf_status_read_buffer *srb =
  319. (struct fsf_status_read_buffer *) fsf->data;
  320. u16 length;
  321. length = (u16)(srb->length -
  322. offsetof(struct fsf_status_read_buffer, payload));
  323. zfcp_dbf_san(tag, dbf, srb->payload.data, ZFCP_DBF_SAN_ELS, length,
  324. fsf->req_id, ntoh24(srb->d_id));
  325. }
  326. /**
  327. * zfcp_dbf_scsi - trace event for scsi commands
  328. * @tag: identifier for event
  329. * @sc: pointer to struct scsi_cmnd
  330. * @fsf: pointer to struct zfcp_fsf_req
  331. */
  332. void zfcp_dbf_scsi(char *tag, struct scsi_cmnd *sc, struct zfcp_fsf_req *fsf)
  333. {
  334. struct zfcp_adapter *adapter =
  335. (struct zfcp_adapter *) sc->device->host->hostdata[0];
  336. struct zfcp_dbf *dbf = adapter->dbf;
  337. struct zfcp_dbf_scsi *rec = &dbf->scsi_buf;
  338. struct fcp_resp_with_ext *fcp_rsp;
  339. struct fcp_resp_rsp_info *fcp_rsp_info;
  340. unsigned long flags;
  341. spin_lock_irqsave(&dbf->scsi_lock, flags);
  342. memset(rec, 0, sizeof(*rec));
  343. memcpy(rec->tag, tag, ZFCP_DBF_TAG_LEN);
  344. rec->id = ZFCP_DBF_SCSI_CMND;
  345. rec->scsi_result = sc->result;
  346. rec->scsi_retries = sc->retries;
  347. rec->scsi_allowed = sc->allowed;
  348. rec->scsi_id = sc->device->id;
  349. rec->scsi_lun = sc->device->lun;
  350. rec->host_scribble = (unsigned long)sc->host_scribble;
  351. memcpy(rec->scsi_opcode, sc->cmnd,
  352. min((int)sc->cmd_len, ZFCP_DBF_SCSI_OPCODE));
  353. if (fsf) {
  354. rec->fsf_req_id = fsf->req_id;
  355. fcp_rsp = (struct fcp_resp_with_ext *)
  356. &(fsf->qtcb->bottom.io.fcp_rsp);
  357. memcpy(&rec->fcp_rsp, fcp_rsp, FCP_RESP_WITH_EXT);
  358. if (fcp_rsp->resp.fr_flags & FCP_RSP_LEN_VAL) {
  359. fcp_rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
  360. rec->fcp_rsp_info = fcp_rsp_info->rsp_code;
  361. }
  362. if (fcp_rsp->resp.fr_flags & FCP_SNS_LEN_VAL) {
  363. rec->pl_len = min((u16)SCSI_SENSE_BUFFERSIZE,
  364. (u16)ZFCP_DBF_PAY_MAX_REC);
  365. zfcp_dbf_pl_write(dbf, sc->sense_buffer, rec->pl_len,
  366. "fcp_sns", fsf->req_id);
  367. }
  368. }
  369. debug_event(dbf->scsi, 1, rec, sizeof(*rec));
  370. spin_unlock_irqrestore(&dbf->scsi_lock, flags);
  371. }
  372. static debug_info_t *zfcp_dbf_reg(const char *name, int size, int rec_size)
  373. {
  374. struct debug_info *d;
  375. d = debug_register(name, size, 1, rec_size);
  376. if (!d)
  377. return NULL;
  378. debug_register_view(d, &debug_hex_ascii_view);
  379. debug_set_level(d, 3);
  380. return d;
  381. }
  382. static void zfcp_dbf_unregister(struct zfcp_dbf *dbf)
  383. {
  384. if (!dbf)
  385. return;
  386. debug_unregister(dbf->scsi);
  387. debug_unregister(dbf->san);
  388. debug_unregister(dbf->hba);
  389. debug_unregister(dbf->pay);
  390. debug_unregister(dbf->rec);
  391. kfree(dbf);
  392. }
  393. /**
  394. * zfcp_adapter_debug_register - registers debug feature for an adapter
  395. * @adapter: pointer to adapter for which debug features should be registered
  396. * return: -ENOMEM on error, 0 otherwise
  397. */
  398. int zfcp_dbf_adapter_register(struct zfcp_adapter *adapter)
  399. {
  400. char name[DEBUG_MAX_NAME_LEN];
  401. struct zfcp_dbf *dbf;
  402. dbf = kzalloc(sizeof(struct zfcp_dbf), GFP_KERNEL);
  403. if (!dbf)
  404. return -ENOMEM;
  405. spin_lock_init(&dbf->pay_lock);
  406. spin_lock_init(&dbf->hba_lock);
  407. spin_lock_init(&dbf->san_lock);
  408. spin_lock_init(&dbf->scsi_lock);
  409. spin_lock_init(&dbf->rec_lock);
  410. /* debug feature area which records recovery activity */
  411. sprintf(name, "zfcp_%s_rec", dev_name(&adapter->ccw_device->dev));
  412. dbf->rec = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_rec));
  413. if (!dbf->rec)
  414. goto err_out;
  415. /* debug feature area which records HBA (FSF and QDIO) conditions */
  416. sprintf(name, "zfcp_%s_hba", dev_name(&adapter->ccw_device->dev));
  417. dbf->hba = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_hba));
  418. if (!dbf->hba)
  419. goto err_out;
  420. /* debug feature area which records payload info */
  421. sprintf(name, "zfcp_%s_pay", dev_name(&adapter->ccw_device->dev));
  422. dbf->pay = zfcp_dbf_reg(name, dbfsize * 2, sizeof(struct zfcp_dbf_pay));
  423. if (!dbf->pay)
  424. goto err_out;
  425. /* debug feature area which records SAN command failures and recovery */
  426. sprintf(name, "zfcp_%s_san", dev_name(&adapter->ccw_device->dev));
  427. dbf->san = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_san));
  428. if (!dbf->san)
  429. goto err_out;
  430. /* debug feature area which records SCSI command failures and recovery */
  431. sprintf(name, "zfcp_%s_scsi", dev_name(&adapter->ccw_device->dev));
  432. dbf->scsi = zfcp_dbf_reg(name, dbfsize, sizeof(struct zfcp_dbf_scsi));
  433. if (!dbf->scsi)
  434. goto err_out;
  435. adapter->dbf = dbf;
  436. return 0;
  437. err_out:
  438. zfcp_dbf_unregister(dbf);
  439. return -ENOMEM;
  440. }
  441. /**
  442. * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
  443. * @adapter: pointer to adapter for which debug features should be unregistered
  444. */
  445. void zfcp_dbf_adapter_unregister(struct zfcp_adapter *adapter)
  446. {
  447. struct zfcp_dbf *dbf = adapter->dbf;
  448. adapter->dbf = NULL;
  449. zfcp_dbf_unregister(dbf);
  450. }