zfcp_dbf.c 13 KB

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