zfcp_dbf.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192
  1. /*
  2. * zfcp device driver
  3. *
  4. * Debug traces for zfcp.
  5. *
  6. * Copyright IBM Corporation 2002, 2009
  7. */
  8. #define KMSG_COMPONENT "zfcp"
  9. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  10. #include <linux/ctype.h>
  11. #include <asm/debug.h>
  12. #include "zfcp_dbf.h"
  13. #include "zfcp_ext.h"
  14. static u32 dbfsize = 4;
  15. module_param(dbfsize, uint, 0400);
  16. MODULE_PARM_DESC(dbfsize,
  17. "number of pages for each debug feature area (default 4)");
  18. static void zfcp_dbf_hexdump(debug_info_t *dbf, void *to, int to_len,
  19. int level, char *from, int from_len)
  20. {
  21. int offset;
  22. struct zfcp_dbf_dump *dump = to;
  23. int room = to_len - sizeof(*dump);
  24. for (offset = 0; offset < from_len; offset += dump->size) {
  25. memset(to, 0, to_len);
  26. strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
  27. dump->total_size = from_len;
  28. dump->offset = offset;
  29. dump->size = min(from_len - offset, room);
  30. memcpy(dump->data, from + offset, dump->size);
  31. debug_event(dbf, level, dump, dump->size + sizeof(*dump));
  32. }
  33. }
  34. /* FIXME: this duplicate this code in s390 debug feature */
  35. static void zfcp_dbf_timestamp(unsigned long long stck, struct timespec *time)
  36. {
  37. unsigned long long sec;
  38. stck -= 0x8126d60e46000000LL - (0x3c26700LL * 1000000 * 4096);
  39. sec = stck >> 12;
  40. do_div(sec, 1000000);
  41. time->tv_sec = sec;
  42. stck -= (sec * 1000000) << 12;
  43. time->tv_nsec = ((stck * 1000) >> 12);
  44. }
  45. static void zfcp_dbf_tag(char **p, const char *label, const char *tag)
  46. {
  47. int i;
  48. *p += sprintf(*p, "%-24s", label);
  49. for (i = 0; i < ZFCP_DBF_TAG_SIZE; i++)
  50. *p += sprintf(*p, "%c", tag[i]);
  51. *p += sprintf(*p, "\n");
  52. }
  53. static void zfcp_dbf_outs(char **buf, const char *s1, const char *s2)
  54. {
  55. *buf += sprintf(*buf, "%-24s%s\n", s1, s2);
  56. }
  57. static void zfcp_dbf_out(char **buf, const char *s, const char *format, ...)
  58. {
  59. va_list arg;
  60. *buf += sprintf(*buf, "%-24s", s);
  61. va_start(arg, format);
  62. *buf += vsprintf(*buf, format, arg);
  63. va_end(arg);
  64. *buf += sprintf(*buf, "\n");
  65. }
  66. static void zfcp_dbf_outd(char **p, const char *label, char *buffer,
  67. int buflen, int offset, int total_size)
  68. {
  69. if (!offset)
  70. *p += sprintf(*p, "%-24s ", label);
  71. while (buflen--) {
  72. if (offset > 0) {
  73. if ((offset % 32) == 0)
  74. *p += sprintf(*p, "\n%-24c ", ' ');
  75. else if ((offset % 4) == 0)
  76. *p += sprintf(*p, " ");
  77. }
  78. *p += sprintf(*p, "%02x", *buffer++);
  79. if (++offset == total_size) {
  80. *p += sprintf(*p, "\n");
  81. break;
  82. }
  83. }
  84. if (!total_size)
  85. *p += sprintf(*p, "\n");
  86. }
  87. static int zfcp_dbf_view_header(debug_info_t *id, struct debug_view *view,
  88. int area, debug_entry_t *entry, char *out_buf)
  89. {
  90. struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)DEBUG_DATA(entry);
  91. struct timespec t;
  92. char *p = out_buf;
  93. if (strncmp(dump->tag, "dump", ZFCP_DBF_TAG_SIZE) != 0) {
  94. zfcp_dbf_timestamp(entry->id.stck, &t);
  95. zfcp_dbf_out(&p, "timestamp", "%011lu:%06lu",
  96. t.tv_sec, t.tv_nsec);
  97. zfcp_dbf_out(&p, "cpu", "%02i", entry->id.fields.cpuid);
  98. } else {
  99. zfcp_dbf_outd(&p, "", dump->data, dump->size, dump->offset,
  100. dump->total_size);
  101. if ((dump->offset + dump->size) == dump->total_size)
  102. p += sprintf(p, "\n");
  103. }
  104. return p - out_buf;
  105. }
  106. /**
  107. * zfcp_hba_dbf_event_fsf_response - trace event for request completion
  108. * @fsf_req: request that has been completed
  109. */
  110. void zfcp_hba_dbf_event_fsf_response(struct zfcp_fsf_req *fsf_req)
  111. {
  112. struct zfcp_adapter *adapter = fsf_req->adapter;
  113. struct zfcp_dbf *dbf = adapter->dbf;
  114. struct fsf_qtcb *qtcb = fsf_req->qtcb;
  115. union fsf_prot_status_qual *prot_status_qual =
  116. &qtcb->prefix.prot_status_qual;
  117. union fsf_status_qual *fsf_status_qual = &qtcb->header.fsf_status_qual;
  118. struct scsi_cmnd *scsi_cmnd;
  119. struct zfcp_port *port;
  120. struct zfcp_unit *unit;
  121. struct zfcp_send_els *send_els;
  122. struct zfcp_hba_dbf_record *rec = &dbf->hba_dbf_buf;
  123. struct zfcp_hba_dbf_record_response *response = &rec->u.response;
  124. int level;
  125. unsigned long flags;
  126. spin_lock_irqsave(&dbf->hba_dbf_lock, flags);
  127. memset(rec, 0, sizeof(*rec));
  128. strncpy(rec->tag, "resp", ZFCP_DBF_TAG_SIZE);
  129. if ((qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
  130. (qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
  131. strncpy(rec->tag2, "perr", ZFCP_DBF_TAG_SIZE);
  132. level = 1;
  133. } else if (qtcb->header.fsf_status != FSF_GOOD) {
  134. strncpy(rec->tag2, "ferr", ZFCP_DBF_TAG_SIZE);
  135. level = 1;
  136. } else if ((fsf_req->fsf_command == FSF_QTCB_OPEN_PORT_WITH_DID) ||
  137. (fsf_req->fsf_command == FSF_QTCB_OPEN_LUN)) {
  138. strncpy(rec->tag2, "open", ZFCP_DBF_TAG_SIZE);
  139. level = 4;
  140. } else if (qtcb->header.log_length) {
  141. strncpy(rec->tag2, "qtcb", ZFCP_DBF_TAG_SIZE);
  142. level = 5;
  143. } else {
  144. strncpy(rec->tag2, "norm", ZFCP_DBF_TAG_SIZE);
  145. level = 6;
  146. }
  147. response->fsf_command = fsf_req->fsf_command;
  148. response->fsf_reqid = fsf_req->req_id;
  149. response->fsf_seqno = fsf_req->seq_no;
  150. response->fsf_issued = fsf_req->issued;
  151. response->fsf_prot_status = qtcb->prefix.prot_status;
  152. response->fsf_status = qtcb->header.fsf_status;
  153. memcpy(response->fsf_prot_status_qual,
  154. prot_status_qual, FSF_PROT_STATUS_QUAL_SIZE);
  155. memcpy(response->fsf_status_qual,
  156. fsf_status_qual, FSF_STATUS_QUALIFIER_SIZE);
  157. response->fsf_req_status = fsf_req->status;
  158. response->sbal_first = fsf_req->sbal_first;
  159. response->sbal_last = fsf_req->sbal_last;
  160. response->sbal_response = fsf_req->sbal_response;
  161. response->pool = fsf_req->pool != NULL;
  162. response->erp_action = (unsigned long)fsf_req->erp_action;
  163. switch (fsf_req->fsf_command) {
  164. case FSF_QTCB_FCP_CMND:
  165. if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
  166. break;
  167. scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
  168. if (scsi_cmnd) {
  169. response->u.fcp.cmnd = (unsigned long)scsi_cmnd;
  170. response->u.fcp.serial = scsi_cmnd->serial_number;
  171. }
  172. break;
  173. case FSF_QTCB_OPEN_PORT_WITH_DID:
  174. case FSF_QTCB_CLOSE_PORT:
  175. case FSF_QTCB_CLOSE_PHYSICAL_PORT:
  176. port = (struct zfcp_port *)fsf_req->data;
  177. response->u.port.wwpn = port->wwpn;
  178. response->u.port.d_id = port->d_id;
  179. response->u.port.port_handle = qtcb->header.port_handle;
  180. break;
  181. case FSF_QTCB_OPEN_LUN:
  182. case FSF_QTCB_CLOSE_LUN:
  183. unit = (struct zfcp_unit *)fsf_req->data;
  184. port = unit->port;
  185. response->u.unit.wwpn = port->wwpn;
  186. response->u.unit.fcp_lun = unit->fcp_lun;
  187. response->u.unit.port_handle = qtcb->header.port_handle;
  188. response->u.unit.lun_handle = qtcb->header.lun_handle;
  189. break;
  190. case FSF_QTCB_SEND_ELS:
  191. send_els = (struct zfcp_send_els *)fsf_req->data;
  192. response->u.els.d_id = qtcb->bottom.support.d_id;
  193. response->u.els.ls_code = send_els->ls_code >> 24;
  194. break;
  195. case FSF_QTCB_ABORT_FCP_CMND:
  196. case FSF_QTCB_SEND_GENERIC:
  197. case FSF_QTCB_EXCHANGE_CONFIG_DATA:
  198. case FSF_QTCB_EXCHANGE_PORT_DATA:
  199. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  200. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  201. break;
  202. }
  203. debug_event(dbf->hba_dbf, level, rec, sizeof(*rec));
  204. /* have fcp channel microcode fixed to use as little as possible */
  205. if (fsf_req->fsf_command != FSF_QTCB_FCP_CMND) {
  206. /* adjust length skipping trailing zeros */
  207. char *buf = (char *)qtcb + qtcb->header.log_start;
  208. int len = qtcb->header.log_length;
  209. for (; len && !buf[len - 1]; len--);
  210. zfcp_dbf_hexdump(dbf->hba_dbf, rec, sizeof(*rec), level, buf,
  211. len);
  212. }
  213. spin_unlock_irqrestore(&dbf->hba_dbf_lock, flags);
  214. }
  215. /**
  216. * zfcp_hba_dbf_event_fsf_unsol - trace event for an unsolicited status buffer
  217. * @tag: tag indicating which kind of unsolicited status has been received
  218. * @adapter: adapter that has issued the unsolicited status buffer
  219. * @status_buffer: buffer containing payload of unsolicited status
  220. */
  221. void zfcp_hba_dbf_event_fsf_unsol(const char *tag, struct zfcp_adapter *adapter,
  222. struct fsf_status_read_buffer *status_buffer)
  223. {
  224. struct zfcp_dbf *dbf = adapter->dbf;
  225. struct zfcp_hba_dbf_record *rec = &dbf->hba_dbf_buf;
  226. unsigned long flags;
  227. spin_lock_irqsave(&dbf->hba_dbf_lock, flags);
  228. memset(rec, 0, sizeof(*rec));
  229. strncpy(rec->tag, "stat", ZFCP_DBF_TAG_SIZE);
  230. strncpy(rec->tag2, tag, ZFCP_DBF_TAG_SIZE);
  231. rec->u.status.failed = atomic_read(&adapter->stat_miss);
  232. if (status_buffer != NULL) {
  233. rec->u.status.status_type = status_buffer->status_type;
  234. rec->u.status.status_subtype = status_buffer->status_subtype;
  235. memcpy(&rec->u.status.queue_designator,
  236. &status_buffer->queue_designator,
  237. sizeof(struct fsf_queue_designator));
  238. switch (status_buffer->status_type) {
  239. case FSF_STATUS_READ_SENSE_DATA_AVAIL:
  240. rec->u.status.payload_size =
  241. ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL;
  242. break;
  243. case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
  244. rec->u.status.payload_size =
  245. ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD;
  246. break;
  247. case FSF_STATUS_READ_LINK_DOWN:
  248. switch (status_buffer->status_subtype) {
  249. case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
  250. case FSF_STATUS_READ_SUB_FDISC_FAILED:
  251. rec->u.status.payload_size =
  252. sizeof(struct fsf_link_down_info);
  253. }
  254. break;
  255. case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
  256. rec->u.status.payload_size =
  257. ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT;
  258. break;
  259. }
  260. memcpy(&rec->u.status.payload,
  261. &status_buffer->payload, rec->u.status.payload_size);
  262. }
  263. debug_event(dbf->hba_dbf, 2, rec, sizeof(*rec));
  264. spin_unlock_irqrestore(&dbf->hba_dbf_lock, flags);
  265. }
  266. /**
  267. * zfcp_hba_dbf_event_qdio - trace event for QDIO related failure
  268. * @adapter: adapter affected by this QDIO related event
  269. * @qdio_error: as passed by qdio module
  270. * @sbal_index: first buffer with error condition, as passed by qdio module
  271. * @sbal_count: number of buffers affected, as passed by qdio module
  272. */
  273. void zfcp_hba_dbf_event_qdio(struct zfcp_adapter *adapter,
  274. unsigned int qdio_error, int sbal_index,
  275. int sbal_count)
  276. {
  277. struct zfcp_dbf *dbf = adapter->dbf;
  278. struct zfcp_hba_dbf_record *r = &dbf->hba_dbf_buf;
  279. unsigned long flags;
  280. spin_lock_irqsave(&dbf->hba_dbf_lock, flags);
  281. memset(r, 0, sizeof(*r));
  282. strncpy(r->tag, "qdio", ZFCP_DBF_TAG_SIZE);
  283. r->u.qdio.qdio_error = qdio_error;
  284. r->u.qdio.sbal_index = sbal_index;
  285. r->u.qdio.sbal_count = sbal_count;
  286. debug_event(dbf->hba_dbf, 0, r, sizeof(*r));
  287. spin_unlock_irqrestore(&dbf->hba_dbf_lock, flags);
  288. }
  289. /**
  290. * zfcp_hba_dbf_event_berr - trace event for bit error threshold
  291. * @adapter: adapter affected by this QDIO related event
  292. * @req: fsf request
  293. */
  294. void zfcp_hba_dbf_event_berr(struct zfcp_adapter *adapter,
  295. struct zfcp_fsf_req *req)
  296. {
  297. struct zfcp_dbf *dbf = adapter->dbf;
  298. struct zfcp_hba_dbf_record *r = &dbf->hba_dbf_buf;
  299. struct fsf_status_read_buffer *sr_buf = req->data;
  300. struct fsf_bit_error_payload *err = &sr_buf->payload.bit_error;
  301. unsigned long flags;
  302. spin_lock_irqsave(&dbf->hba_dbf_lock, flags);
  303. memset(r, 0, sizeof(*r));
  304. strncpy(r->tag, "berr", ZFCP_DBF_TAG_SIZE);
  305. memcpy(&r->u.berr, err, sizeof(struct fsf_bit_error_payload));
  306. debug_event(dbf->hba_dbf, 0, r, sizeof(*r));
  307. spin_unlock_irqrestore(&dbf->hba_dbf_lock, flags);
  308. }
  309. static void zfcp_hba_dbf_view_response(char **p,
  310. struct zfcp_hba_dbf_record_response *r)
  311. {
  312. struct timespec t;
  313. zfcp_dbf_out(p, "fsf_command", "0x%08x", r->fsf_command);
  314. zfcp_dbf_out(p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
  315. zfcp_dbf_out(p, "fsf_seqno", "0x%08x", r->fsf_seqno);
  316. zfcp_dbf_timestamp(r->fsf_issued, &t);
  317. zfcp_dbf_out(p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
  318. zfcp_dbf_out(p, "fsf_prot_status", "0x%08x", r->fsf_prot_status);
  319. zfcp_dbf_out(p, "fsf_status", "0x%08x", r->fsf_status);
  320. zfcp_dbf_outd(p, "fsf_prot_status_qual", r->fsf_prot_status_qual,
  321. FSF_PROT_STATUS_QUAL_SIZE, 0, FSF_PROT_STATUS_QUAL_SIZE);
  322. zfcp_dbf_outd(p, "fsf_status_qual", r->fsf_status_qual,
  323. FSF_STATUS_QUALIFIER_SIZE, 0, FSF_STATUS_QUALIFIER_SIZE);
  324. zfcp_dbf_out(p, "fsf_req_status", "0x%08x", r->fsf_req_status);
  325. zfcp_dbf_out(p, "sbal_first", "0x%02x", r->sbal_first);
  326. zfcp_dbf_out(p, "sbal_last", "0x%02x", r->sbal_last);
  327. zfcp_dbf_out(p, "sbal_response", "0x%02x", r->sbal_response);
  328. zfcp_dbf_out(p, "pool", "0x%02x", r->pool);
  329. switch (r->fsf_command) {
  330. case FSF_QTCB_FCP_CMND:
  331. if (r->fsf_req_status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
  332. break;
  333. zfcp_dbf_out(p, "scsi_cmnd", "0x%0Lx", r->u.fcp.cmnd);
  334. zfcp_dbf_out(p, "scsi_serial", "0x%016Lx", r->u.fcp.serial);
  335. p += sprintf(*p, "\n");
  336. break;
  337. case FSF_QTCB_OPEN_PORT_WITH_DID:
  338. case FSF_QTCB_CLOSE_PORT:
  339. case FSF_QTCB_CLOSE_PHYSICAL_PORT:
  340. zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->u.port.wwpn);
  341. zfcp_dbf_out(p, "d_id", "0x%06x", r->u.port.d_id);
  342. zfcp_dbf_out(p, "port_handle", "0x%08x", r->u.port.port_handle);
  343. break;
  344. case FSF_QTCB_OPEN_LUN:
  345. case FSF_QTCB_CLOSE_LUN:
  346. zfcp_dbf_out(p, "wwpn", "0x%016Lx", r->u.unit.wwpn);
  347. zfcp_dbf_out(p, "fcp_lun", "0x%016Lx", r->u.unit.fcp_lun);
  348. zfcp_dbf_out(p, "port_handle", "0x%08x", r->u.unit.port_handle);
  349. zfcp_dbf_out(p, "lun_handle", "0x%08x", r->u.unit.lun_handle);
  350. break;
  351. case FSF_QTCB_SEND_ELS:
  352. zfcp_dbf_out(p, "d_id", "0x%06x", r->u.els.d_id);
  353. zfcp_dbf_out(p, "ls_code", "0x%02x", r->u.els.ls_code);
  354. break;
  355. case FSF_QTCB_ABORT_FCP_CMND:
  356. case FSF_QTCB_SEND_GENERIC:
  357. case FSF_QTCB_EXCHANGE_CONFIG_DATA:
  358. case FSF_QTCB_EXCHANGE_PORT_DATA:
  359. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  360. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  361. break;
  362. }
  363. }
  364. static void zfcp_hba_dbf_view_status(char **p,
  365. struct zfcp_hba_dbf_record_status *r)
  366. {
  367. zfcp_dbf_out(p, "failed", "0x%02x", r->failed);
  368. zfcp_dbf_out(p, "status_type", "0x%08x", r->status_type);
  369. zfcp_dbf_out(p, "status_subtype", "0x%08x", r->status_subtype);
  370. zfcp_dbf_outd(p, "queue_designator", (char *)&r->queue_designator,
  371. sizeof(struct fsf_queue_designator), 0,
  372. sizeof(struct fsf_queue_designator));
  373. zfcp_dbf_outd(p, "payload", (char *)&r->payload, r->payload_size, 0,
  374. r->payload_size);
  375. }
  376. static void zfcp_hba_dbf_view_qdio(char **p, struct zfcp_hba_dbf_record_qdio *r)
  377. {
  378. zfcp_dbf_out(p, "qdio_error", "0x%08x", r->qdio_error);
  379. zfcp_dbf_out(p, "sbal_index", "0x%02x", r->sbal_index);
  380. zfcp_dbf_out(p, "sbal_count", "0x%02x", r->sbal_count);
  381. }
  382. static void zfcp_hba_dbf_view_berr(char **p, struct fsf_bit_error_payload *r)
  383. {
  384. zfcp_dbf_out(p, "link_failures", "%d", r->link_failure_error_count);
  385. zfcp_dbf_out(p, "loss_of_sync_err", "%d", r->loss_of_sync_error_count);
  386. zfcp_dbf_out(p, "loss_of_sig_err", "%d", r->loss_of_signal_error_count);
  387. zfcp_dbf_out(p, "prim_seq_err", "%d",
  388. r->primitive_sequence_error_count);
  389. zfcp_dbf_out(p, "inval_trans_word_err", "%d",
  390. r->invalid_transmission_word_error_count);
  391. zfcp_dbf_out(p, "CRC_errors", "%d", r->crc_error_count);
  392. zfcp_dbf_out(p, "prim_seq_event_to", "%d",
  393. r->primitive_sequence_event_timeout_count);
  394. zfcp_dbf_out(p, "elast_buf_overrun_err", "%d",
  395. r->elastic_buffer_overrun_error_count);
  396. zfcp_dbf_out(p, "adv_rec_buf2buf_cred", "%d",
  397. r->advertised_receive_b2b_credit);
  398. zfcp_dbf_out(p, "curr_rec_buf2buf_cred", "%d",
  399. r->current_receive_b2b_credit);
  400. zfcp_dbf_out(p, "adv_trans_buf2buf_cred", "%d",
  401. r->advertised_transmit_b2b_credit);
  402. zfcp_dbf_out(p, "curr_trans_buf2buf_cred", "%d",
  403. r->current_transmit_b2b_credit);
  404. }
  405. static int zfcp_hba_dbf_view_format(debug_info_t *id, struct debug_view *view,
  406. char *out_buf, const char *in_buf)
  407. {
  408. struct zfcp_hba_dbf_record *r = (struct zfcp_hba_dbf_record *)in_buf;
  409. char *p = out_buf;
  410. if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
  411. return 0;
  412. zfcp_dbf_tag(&p, "tag", r->tag);
  413. if (isalpha(r->tag2[0]))
  414. zfcp_dbf_tag(&p, "tag2", r->tag2);
  415. if (strncmp(r->tag, "resp", ZFCP_DBF_TAG_SIZE) == 0)
  416. zfcp_hba_dbf_view_response(&p, &r->u.response);
  417. else if (strncmp(r->tag, "stat", ZFCP_DBF_TAG_SIZE) == 0)
  418. zfcp_hba_dbf_view_status(&p, &r->u.status);
  419. else if (strncmp(r->tag, "qdio", ZFCP_DBF_TAG_SIZE) == 0)
  420. zfcp_hba_dbf_view_qdio(&p, &r->u.qdio);
  421. else if (strncmp(r->tag, "berr", ZFCP_DBF_TAG_SIZE) == 0)
  422. zfcp_hba_dbf_view_berr(&p, &r->u.berr);
  423. if (strncmp(r->tag, "resp", ZFCP_DBF_TAG_SIZE) != 0)
  424. p += sprintf(p, "\n");
  425. return p - out_buf;
  426. }
  427. static struct debug_view zfcp_hba_dbf_view = {
  428. "structured",
  429. NULL,
  430. &zfcp_dbf_view_header,
  431. &zfcp_hba_dbf_view_format,
  432. NULL,
  433. NULL
  434. };
  435. static const char *zfcp_rec_dbf_tags[] = {
  436. [ZFCP_REC_DBF_ID_THREAD] = "thread",
  437. [ZFCP_REC_DBF_ID_TARGET] = "target",
  438. [ZFCP_REC_DBF_ID_TRIGGER] = "trigger",
  439. [ZFCP_REC_DBF_ID_ACTION] = "action",
  440. };
  441. static int zfcp_rec_dbf_view_format(debug_info_t *id, struct debug_view *view,
  442. char *buf, const char *_rec)
  443. {
  444. struct zfcp_rec_dbf_record *r = (struct zfcp_rec_dbf_record *)_rec;
  445. char *p = buf;
  446. char hint[ZFCP_DBF_ID_SIZE + 1];
  447. memcpy(hint, r->id2, ZFCP_DBF_ID_SIZE);
  448. hint[ZFCP_DBF_ID_SIZE] = 0;
  449. zfcp_dbf_outs(&p, "tag", zfcp_rec_dbf_tags[r->id]);
  450. zfcp_dbf_outs(&p, "hint", hint);
  451. switch (r->id) {
  452. case ZFCP_REC_DBF_ID_THREAD:
  453. zfcp_dbf_out(&p, "total", "%d", r->u.thread.total);
  454. zfcp_dbf_out(&p, "ready", "%d", r->u.thread.ready);
  455. zfcp_dbf_out(&p, "running", "%d", r->u.thread.running);
  456. break;
  457. case ZFCP_REC_DBF_ID_TARGET:
  458. zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.target.ref);
  459. zfcp_dbf_out(&p, "status", "0x%08x", r->u.target.status);
  460. zfcp_dbf_out(&p, "erp_count", "%d", r->u.target.erp_count);
  461. zfcp_dbf_out(&p, "d_id", "0x%06x", r->u.target.d_id);
  462. zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.target.wwpn);
  463. zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.target.fcp_lun);
  464. break;
  465. case ZFCP_REC_DBF_ID_TRIGGER:
  466. zfcp_dbf_out(&p, "reference", "0x%016Lx", r->u.trigger.ref);
  467. zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.trigger.action);
  468. zfcp_dbf_out(&p, "requested", "%d", r->u.trigger.want);
  469. zfcp_dbf_out(&p, "executed", "%d", r->u.trigger.need);
  470. zfcp_dbf_out(&p, "wwpn", "0x%016Lx", r->u.trigger.wwpn);
  471. zfcp_dbf_out(&p, "fcp_lun", "0x%016Lx", r->u.trigger.fcp_lun);
  472. zfcp_dbf_out(&p, "adapter_status", "0x%08x", r->u.trigger.as);
  473. zfcp_dbf_out(&p, "port_status", "0x%08x", r->u.trigger.ps);
  474. zfcp_dbf_out(&p, "unit_status", "0x%08x", r->u.trigger.us);
  475. break;
  476. case ZFCP_REC_DBF_ID_ACTION:
  477. zfcp_dbf_out(&p, "erp_action", "0x%016Lx", r->u.action.action);
  478. zfcp_dbf_out(&p, "fsf_req", "0x%016Lx", r->u.action.fsf_req);
  479. zfcp_dbf_out(&p, "status", "0x%08Lx", r->u.action.status);
  480. zfcp_dbf_out(&p, "step", "0x%08Lx", r->u.action.step);
  481. break;
  482. }
  483. p += sprintf(p, "\n");
  484. return p - buf;
  485. }
  486. static struct debug_view zfcp_rec_dbf_view = {
  487. "structured",
  488. NULL,
  489. &zfcp_dbf_view_header,
  490. &zfcp_rec_dbf_view_format,
  491. NULL,
  492. NULL
  493. };
  494. /**
  495. * zfcp_rec_dbf_event_thread - trace event related to recovery thread operation
  496. * @id2: identifier for event
  497. * @adapter: adapter
  498. * This function assumes that the caller is holding erp_lock.
  499. */
  500. void zfcp_rec_dbf_event_thread(char *id2, struct zfcp_adapter *adapter)
  501. {
  502. struct zfcp_dbf *dbf = adapter->dbf;
  503. struct zfcp_rec_dbf_record *r = &dbf->rec_dbf_buf;
  504. unsigned long flags = 0;
  505. struct list_head *entry;
  506. unsigned ready = 0, running = 0, total;
  507. list_for_each(entry, &adapter->erp_ready_head)
  508. ready++;
  509. list_for_each(entry, &adapter->erp_running_head)
  510. running++;
  511. total = adapter->erp_total_count;
  512. spin_lock_irqsave(&dbf->rec_dbf_lock, flags);
  513. memset(r, 0, sizeof(*r));
  514. r->id = ZFCP_REC_DBF_ID_THREAD;
  515. memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE);
  516. r->u.thread.total = total;
  517. r->u.thread.ready = ready;
  518. r->u.thread.running = running;
  519. debug_event(dbf->rec_dbf, 6, r, sizeof(*r));
  520. spin_unlock_irqrestore(&dbf->rec_dbf_lock, flags);
  521. }
  522. /**
  523. * zfcp_rec_dbf_event_thread - trace event related to recovery thread operation
  524. * @id2: identifier for event
  525. * @adapter: adapter
  526. * This function assumes that the caller does not hold erp_lock.
  527. */
  528. void zfcp_rec_dbf_event_thread_lock(char *id2, struct zfcp_adapter *adapter)
  529. {
  530. unsigned long flags;
  531. read_lock_irqsave(&adapter->erp_lock, flags);
  532. zfcp_rec_dbf_event_thread(id2, adapter);
  533. read_unlock_irqrestore(&adapter->erp_lock, flags);
  534. }
  535. static void zfcp_rec_dbf_event_target(char *id2, void *ref,
  536. struct zfcp_adapter *adapter,
  537. atomic_t *status, atomic_t *erp_count,
  538. u64 wwpn, u32 d_id, u64 fcp_lun)
  539. {
  540. struct zfcp_dbf *dbf = adapter->dbf;
  541. struct zfcp_rec_dbf_record *r = &dbf->rec_dbf_buf;
  542. unsigned long flags;
  543. spin_lock_irqsave(&dbf->rec_dbf_lock, flags);
  544. memset(r, 0, sizeof(*r));
  545. r->id = ZFCP_REC_DBF_ID_TARGET;
  546. memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE);
  547. r->u.target.ref = (unsigned long)ref;
  548. r->u.target.status = atomic_read(status);
  549. r->u.target.wwpn = wwpn;
  550. r->u.target.d_id = d_id;
  551. r->u.target.fcp_lun = fcp_lun;
  552. r->u.target.erp_count = atomic_read(erp_count);
  553. debug_event(dbf->rec_dbf, 3, r, sizeof(*r));
  554. spin_unlock_irqrestore(&dbf->rec_dbf_lock, flags);
  555. }
  556. /**
  557. * zfcp_rec_dbf_event_adapter - trace event for adapter state change
  558. * @id: identifier for trigger of state change
  559. * @ref: additional reference (e.g. request)
  560. * @adapter: adapter
  561. */
  562. void zfcp_rec_dbf_event_adapter(char *id, void *ref,
  563. struct zfcp_adapter *adapter)
  564. {
  565. zfcp_rec_dbf_event_target(id, ref, adapter, &adapter->status,
  566. &adapter->erp_counter, 0, 0, 0);
  567. }
  568. /**
  569. * zfcp_rec_dbf_event_port - trace event for port state change
  570. * @id: identifier for trigger of state change
  571. * @ref: additional reference (e.g. request)
  572. * @port: port
  573. */
  574. void zfcp_rec_dbf_event_port(char *id, void *ref, struct zfcp_port *port)
  575. {
  576. struct zfcp_adapter *adapter = port->adapter;
  577. zfcp_rec_dbf_event_target(id, ref, adapter, &port->status,
  578. &port->erp_counter, port->wwpn, port->d_id,
  579. 0);
  580. }
  581. /**
  582. * zfcp_rec_dbf_event_unit - trace event for unit state change
  583. * @id: identifier for trigger of state change
  584. * @ref: additional reference (e.g. request)
  585. * @unit: unit
  586. */
  587. void zfcp_rec_dbf_event_unit(char *id, void *ref, struct zfcp_unit *unit)
  588. {
  589. struct zfcp_port *port = unit->port;
  590. struct zfcp_adapter *adapter = port->adapter;
  591. zfcp_rec_dbf_event_target(id, ref, adapter, &unit->status,
  592. &unit->erp_counter, port->wwpn, port->d_id,
  593. unit->fcp_lun);
  594. }
  595. /**
  596. * zfcp_rec_dbf_event_trigger - trace event for triggered error recovery
  597. * @id2: identifier for error recovery trigger
  598. * @ref: additional reference (e.g. request)
  599. * @want: originally requested error recovery action
  600. * @need: error recovery action actually initiated
  601. * @action: address of error recovery action struct
  602. * @adapter: adapter
  603. * @port: port
  604. * @unit: unit
  605. */
  606. void zfcp_rec_dbf_event_trigger(char *id2, void *ref, u8 want, u8 need,
  607. void *action, struct zfcp_adapter *adapter,
  608. struct zfcp_port *port, struct zfcp_unit *unit)
  609. {
  610. struct zfcp_dbf *dbf = adapter->dbf;
  611. struct zfcp_rec_dbf_record *r = &dbf->rec_dbf_buf;
  612. unsigned long flags;
  613. spin_lock_irqsave(&dbf->rec_dbf_lock, flags);
  614. memset(r, 0, sizeof(*r));
  615. r->id = ZFCP_REC_DBF_ID_TRIGGER;
  616. memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE);
  617. r->u.trigger.ref = (unsigned long)ref;
  618. r->u.trigger.want = want;
  619. r->u.trigger.need = need;
  620. r->u.trigger.action = (unsigned long)action;
  621. r->u.trigger.as = atomic_read(&adapter->status);
  622. if (port) {
  623. r->u.trigger.ps = atomic_read(&port->status);
  624. r->u.trigger.wwpn = port->wwpn;
  625. }
  626. if (unit) {
  627. r->u.trigger.us = atomic_read(&unit->status);
  628. r->u.trigger.fcp_lun = unit->fcp_lun;
  629. }
  630. debug_event(dbf->rec_dbf, action ? 1 : 4, r, sizeof(*r));
  631. spin_unlock_irqrestore(&dbf->rec_dbf_lock, flags);
  632. }
  633. /**
  634. * zfcp_rec_dbf_event_action - trace event showing progress of recovery action
  635. * @id2: identifier
  636. * @erp_action: error recovery action struct pointer
  637. */
  638. void zfcp_rec_dbf_event_action(char *id2, struct zfcp_erp_action *erp_action)
  639. {
  640. struct zfcp_adapter *adapter = erp_action->adapter;
  641. struct zfcp_dbf *dbf = adapter->dbf;
  642. struct zfcp_rec_dbf_record *r = &dbf->rec_dbf_buf;
  643. unsigned long flags;
  644. spin_lock_irqsave(&dbf->rec_dbf_lock, flags);
  645. memset(r, 0, sizeof(*r));
  646. r->id = ZFCP_REC_DBF_ID_ACTION;
  647. memcpy(r->id2, id2, ZFCP_DBF_ID_SIZE);
  648. r->u.action.action = (unsigned long)erp_action;
  649. r->u.action.status = erp_action->status;
  650. r->u.action.step = erp_action->step;
  651. r->u.action.fsf_req = (unsigned long)erp_action->fsf_req;
  652. debug_event(dbf->rec_dbf, 5, r, sizeof(*r));
  653. spin_unlock_irqrestore(&dbf->rec_dbf_lock, flags);
  654. }
  655. /**
  656. * zfcp_san_dbf_event_ct_request - trace event for issued CT request
  657. * @fsf_req: request containing issued CT data
  658. */
  659. void zfcp_san_dbf_event_ct_request(struct zfcp_fsf_req *fsf_req)
  660. {
  661. struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data;
  662. struct zfcp_wka_port *wka_port = ct->wka_port;
  663. struct zfcp_adapter *adapter = wka_port->adapter;
  664. struct zfcp_dbf *dbf = adapter->dbf;
  665. struct ct_hdr *hdr = sg_virt(ct->req);
  666. struct zfcp_san_dbf_record *r = &dbf->san_dbf_buf;
  667. struct zfcp_san_dbf_record_ct_request *oct = &r->u.ct_req;
  668. int level = 3;
  669. unsigned long flags;
  670. spin_lock_irqsave(&dbf->san_dbf_lock, flags);
  671. memset(r, 0, sizeof(*r));
  672. strncpy(r->tag, "octc", ZFCP_DBF_TAG_SIZE);
  673. r->fsf_reqid = fsf_req->req_id;
  674. r->fsf_seqno = fsf_req->seq_no;
  675. r->s_id = fc_host_port_id(adapter->scsi_host);
  676. r->d_id = wka_port->d_id;
  677. oct->cmd_req_code = hdr->cmd_rsp_code;
  678. oct->revision = hdr->revision;
  679. oct->gs_type = hdr->gs_type;
  680. oct->gs_subtype = hdr->gs_subtype;
  681. oct->options = hdr->options;
  682. oct->max_res_size = hdr->max_res_size;
  683. oct->len = min((int)ct->req->length - (int)sizeof(struct ct_hdr),
  684. ZFCP_DBF_SAN_MAX_PAYLOAD);
  685. debug_event(dbf->san_dbf, level, r, sizeof(*r));
  686. zfcp_dbf_hexdump(dbf->san_dbf, r, sizeof(*r), level,
  687. (void *)hdr + sizeof(struct ct_hdr), oct->len);
  688. spin_unlock_irqrestore(&dbf->san_dbf_lock, flags);
  689. }
  690. /**
  691. * zfcp_san_dbf_event_ct_response - trace event for completion of CT request
  692. * @fsf_req: request containing CT response
  693. */
  694. void zfcp_san_dbf_event_ct_response(struct zfcp_fsf_req *fsf_req)
  695. {
  696. struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data;
  697. struct zfcp_wka_port *wka_port = ct->wka_port;
  698. struct zfcp_adapter *adapter = wka_port->adapter;
  699. struct ct_hdr *hdr = sg_virt(ct->resp);
  700. struct zfcp_dbf *dbf = adapter->dbf;
  701. struct zfcp_san_dbf_record *r = &dbf->san_dbf_buf;
  702. struct zfcp_san_dbf_record_ct_response *rct = &r->u.ct_resp;
  703. int level = 3;
  704. unsigned long flags;
  705. spin_lock_irqsave(&dbf->san_dbf_lock, flags);
  706. memset(r, 0, sizeof(*r));
  707. strncpy(r->tag, "rctc", ZFCP_DBF_TAG_SIZE);
  708. r->fsf_reqid = fsf_req->req_id;
  709. r->fsf_seqno = fsf_req->seq_no;
  710. r->s_id = wka_port->d_id;
  711. r->d_id = fc_host_port_id(adapter->scsi_host);
  712. rct->cmd_rsp_code = hdr->cmd_rsp_code;
  713. rct->revision = hdr->revision;
  714. rct->reason_code = hdr->reason_code;
  715. rct->expl = hdr->reason_code_expl;
  716. rct->vendor_unique = hdr->vendor_unique;
  717. rct->max_res_size = hdr->max_res_size;
  718. rct->len = min((int)ct->resp->length - (int)sizeof(struct ct_hdr),
  719. ZFCP_DBF_SAN_MAX_PAYLOAD);
  720. debug_event(dbf->san_dbf, level, r, sizeof(*r));
  721. zfcp_dbf_hexdump(dbf->san_dbf, r, sizeof(*r), level,
  722. (void *)hdr + sizeof(struct ct_hdr), rct->len);
  723. spin_unlock_irqrestore(&dbf->san_dbf_lock, flags);
  724. }
  725. static void zfcp_san_dbf_event_els(const char *tag, int level,
  726. struct zfcp_fsf_req *fsf_req, u32 s_id,
  727. u32 d_id, u8 ls_code, void *buffer,
  728. int buflen)
  729. {
  730. struct zfcp_adapter *adapter = fsf_req->adapter;
  731. struct zfcp_dbf *dbf = adapter->dbf;
  732. struct zfcp_san_dbf_record *rec = &dbf->san_dbf_buf;
  733. unsigned long flags;
  734. spin_lock_irqsave(&dbf->san_dbf_lock, flags);
  735. memset(rec, 0, sizeof(*rec));
  736. strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
  737. rec->fsf_reqid = fsf_req->req_id;
  738. rec->fsf_seqno = fsf_req->seq_no;
  739. rec->s_id = s_id;
  740. rec->d_id = d_id;
  741. rec->u.els.ls_code = ls_code;
  742. debug_event(dbf->san_dbf, level, rec, sizeof(*rec));
  743. zfcp_dbf_hexdump(dbf->san_dbf, rec, sizeof(*rec), level,
  744. buffer, min(buflen, ZFCP_DBF_SAN_MAX_PAYLOAD));
  745. spin_unlock_irqrestore(&dbf->san_dbf_lock, flags);
  746. }
  747. /**
  748. * zfcp_san_dbf_event_els_request - trace event for issued ELS
  749. * @fsf_req: request containing issued ELS
  750. */
  751. void zfcp_san_dbf_event_els_request(struct zfcp_fsf_req *fsf_req)
  752. {
  753. struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data;
  754. zfcp_san_dbf_event_els("oels", 2, fsf_req,
  755. fc_host_port_id(els->adapter->scsi_host),
  756. els->d_id, *(u8 *) sg_virt(els->req),
  757. sg_virt(els->req), els->req->length);
  758. }
  759. /**
  760. * zfcp_san_dbf_event_els_response - trace event for completed ELS
  761. * @fsf_req: request containing ELS response
  762. */
  763. void zfcp_san_dbf_event_els_response(struct zfcp_fsf_req *fsf_req)
  764. {
  765. struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data;
  766. zfcp_san_dbf_event_els("rels", 2, fsf_req, els->d_id,
  767. fc_host_port_id(els->adapter->scsi_host),
  768. *(u8 *)sg_virt(els->req), sg_virt(els->resp),
  769. els->resp->length);
  770. }
  771. /**
  772. * zfcp_san_dbf_event_incoming_els - trace event for incomig ELS
  773. * @fsf_req: request containing unsolicited status buffer with incoming ELS
  774. */
  775. void zfcp_san_dbf_event_incoming_els(struct zfcp_fsf_req *fsf_req)
  776. {
  777. struct zfcp_adapter *adapter = fsf_req->adapter;
  778. struct fsf_status_read_buffer *buf =
  779. (struct fsf_status_read_buffer *)fsf_req->data;
  780. int length = (int)buf->length -
  781. (int)((void *)&buf->payload - (void *)buf);
  782. zfcp_san_dbf_event_els("iels", 1, fsf_req, buf->d_id,
  783. fc_host_port_id(adapter->scsi_host),
  784. buf->payload.data[0], (void *)buf->payload.data,
  785. length);
  786. }
  787. static int zfcp_san_dbf_view_format(debug_info_t *id, struct debug_view *view,
  788. char *out_buf, const char *in_buf)
  789. {
  790. struct zfcp_san_dbf_record *r = (struct zfcp_san_dbf_record *)in_buf;
  791. char *p = out_buf;
  792. if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
  793. return 0;
  794. zfcp_dbf_tag(&p, "tag", r->tag);
  795. zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
  796. zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
  797. zfcp_dbf_out(&p, "s_id", "0x%06x", r->s_id);
  798. zfcp_dbf_out(&p, "d_id", "0x%06x", r->d_id);
  799. if (strncmp(r->tag, "octc", ZFCP_DBF_TAG_SIZE) == 0) {
  800. struct zfcp_san_dbf_record_ct_request *ct = &r->u.ct_req;
  801. zfcp_dbf_out(&p, "cmd_req_code", "0x%04x", ct->cmd_req_code);
  802. zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision);
  803. zfcp_dbf_out(&p, "gs_type", "0x%02x", ct->gs_type);
  804. zfcp_dbf_out(&p, "gs_subtype", "0x%02x", ct->gs_subtype);
  805. zfcp_dbf_out(&p, "options", "0x%02x", ct->options);
  806. zfcp_dbf_out(&p, "max_res_size", "0x%04x", ct->max_res_size);
  807. } else if (strncmp(r->tag, "rctc", ZFCP_DBF_TAG_SIZE) == 0) {
  808. struct zfcp_san_dbf_record_ct_response *ct = &r->u.ct_resp;
  809. zfcp_dbf_out(&p, "cmd_rsp_code", "0x%04x", ct->cmd_rsp_code);
  810. zfcp_dbf_out(&p, "revision", "0x%02x", ct->revision);
  811. zfcp_dbf_out(&p, "reason_code", "0x%02x", ct->reason_code);
  812. zfcp_dbf_out(&p, "reason_code_expl", "0x%02x", ct->expl);
  813. zfcp_dbf_out(&p, "vendor_unique", "0x%02x", ct->vendor_unique);
  814. zfcp_dbf_out(&p, "max_res_size", "0x%04x", ct->max_res_size);
  815. } else if (strncmp(r->tag, "oels", ZFCP_DBF_TAG_SIZE) == 0 ||
  816. strncmp(r->tag, "rels", ZFCP_DBF_TAG_SIZE) == 0 ||
  817. strncmp(r->tag, "iels", ZFCP_DBF_TAG_SIZE) == 0) {
  818. struct zfcp_san_dbf_record_els *els = &r->u.els;
  819. zfcp_dbf_out(&p, "ls_code", "0x%02x", els->ls_code);
  820. }
  821. return p - out_buf;
  822. }
  823. static struct debug_view zfcp_san_dbf_view = {
  824. "structured",
  825. NULL,
  826. &zfcp_dbf_view_header,
  827. &zfcp_san_dbf_view_format,
  828. NULL,
  829. NULL
  830. };
  831. static void zfcp_scsi_dbf_event(const char *tag, const char *tag2, int level,
  832. struct zfcp_adapter *adapter,
  833. struct scsi_cmnd *scsi_cmnd,
  834. struct zfcp_fsf_req *fsf_req,
  835. unsigned long old_req_id)
  836. {
  837. struct zfcp_dbf *dbf = adapter->dbf;
  838. struct zfcp_scsi_dbf_record *rec = &dbf->scsi_dbf_buf;
  839. struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)rec;
  840. unsigned long flags;
  841. struct fcp_rsp_iu *fcp_rsp;
  842. char *fcp_rsp_info = NULL, *fcp_sns_info = NULL;
  843. int offset = 0, buflen = 0;
  844. spin_lock_irqsave(&dbf->scsi_dbf_lock, flags);
  845. do {
  846. memset(rec, 0, sizeof(*rec));
  847. if (offset == 0) {
  848. strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
  849. strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE);
  850. if (scsi_cmnd != NULL) {
  851. if (scsi_cmnd->device) {
  852. rec->scsi_id = scsi_cmnd->device->id;
  853. rec->scsi_lun = scsi_cmnd->device->lun;
  854. }
  855. rec->scsi_result = scsi_cmnd->result;
  856. rec->scsi_cmnd = (unsigned long)scsi_cmnd;
  857. rec->scsi_serial = scsi_cmnd->serial_number;
  858. memcpy(rec->scsi_opcode, scsi_cmnd->cmnd,
  859. min((int)scsi_cmnd->cmd_len,
  860. ZFCP_DBF_SCSI_OPCODE));
  861. rec->scsi_retries = scsi_cmnd->retries;
  862. rec->scsi_allowed = scsi_cmnd->allowed;
  863. }
  864. if (fsf_req != NULL) {
  865. fcp_rsp = (struct fcp_rsp_iu *)
  866. &(fsf_req->qtcb->bottom.io.fcp_rsp);
  867. fcp_rsp_info = (unsigned char *) &fcp_rsp[1];
  868. fcp_sns_info =
  869. zfcp_get_fcp_sns_info_ptr(fcp_rsp);
  870. rec->rsp_validity = fcp_rsp->validity.value;
  871. rec->rsp_scsi_status = fcp_rsp->scsi_status;
  872. rec->rsp_resid = fcp_rsp->fcp_resid;
  873. if (fcp_rsp->validity.bits.fcp_rsp_len_valid)
  874. rec->rsp_code = *(fcp_rsp_info + 3);
  875. if (fcp_rsp->validity.bits.fcp_sns_len_valid) {
  876. buflen = min((int)fcp_rsp->fcp_sns_len,
  877. ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO);
  878. rec->sns_info_len = buflen;
  879. memcpy(rec->sns_info, fcp_sns_info,
  880. min(buflen,
  881. ZFCP_DBF_SCSI_FCP_SNS_INFO));
  882. offset += min(buflen,
  883. ZFCP_DBF_SCSI_FCP_SNS_INFO);
  884. }
  885. rec->fsf_reqid = fsf_req->req_id;
  886. rec->fsf_seqno = fsf_req->seq_no;
  887. rec->fsf_issued = fsf_req->issued;
  888. }
  889. rec->old_fsf_reqid = old_req_id;
  890. } else {
  891. strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
  892. dump->total_size = buflen;
  893. dump->offset = offset;
  894. dump->size = min(buflen - offset,
  895. (int)sizeof(struct
  896. zfcp_scsi_dbf_record) -
  897. (int)sizeof(struct zfcp_dbf_dump));
  898. memcpy(dump->data, fcp_sns_info + offset, dump->size);
  899. offset += dump->size;
  900. }
  901. debug_event(dbf->scsi_dbf, level, rec, sizeof(*rec));
  902. } while (offset < buflen);
  903. spin_unlock_irqrestore(&dbf->scsi_dbf_lock, flags);
  904. }
  905. /**
  906. * zfcp_scsi_dbf_event_result - trace event for SCSI command completion
  907. * @tag: tag indicating success or failure of SCSI command
  908. * @level: trace level applicable for this event
  909. * @adapter: adapter that has been used to issue the SCSI command
  910. * @scsi_cmnd: SCSI command pointer
  911. * @fsf_req: request used to issue SCSI command (might be NULL)
  912. */
  913. void zfcp_scsi_dbf_event_result(const char *tag, int level,
  914. struct zfcp_adapter *adapter,
  915. struct scsi_cmnd *scsi_cmnd,
  916. struct zfcp_fsf_req *fsf_req)
  917. {
  918. zfcp_scsi_dbf_event("rslt", tag, level, adapter, scsi_cmnd, fsf_req, 0);
  919. }
  920. /**
  921. * zfcp_scsi_dbf_event_abort - trace event for SCSI command abort
  922. * @tag: tag indicating success or failure of abort operation
  923. * @adapter: adapter thas has been used to issue SCSI command to be aborted
  924. * @scsi_cmnd: SCSI command to be aborted
  925. * @new_fsf_req: request containing abort (might be NULL)
  926. * @old_req_id: identifier of request containg SCSI command to be aborted
  927. */
  928. void zfcp_scsi_dbf_event_abort(const char *tag, struct zfcp_adapter *adapter,
  929. struct scsi_cmnd *scsi_cmnd,
  930. struct zfcp_fsf_req *new_fsf_req,
  931. unsigned long old_req_id)
  932. {
  933. zfcp_scsi_dbf_event("abrt", tag, 1, adapter, scsi_cmnd, new_fsf_req,
  934. old_req_id);
  935. }
  936. /**
  937. * zfcp_scsi_dbf_event_devreset - trace event for Logical Unit or Target Reset
  938. * @tag: tag indicating success or failure of reset operation
  939. * @flag: indicates type of reset (Target Reset, Logical Unit Reset)
  940. * @unit: unit that needs reset
  941. * @scsi_cmnd: SCSI command which caused this error recovery
  942. */
  943. void zfcp_scsi_dbf_event_devreset(const char *tag, u8 flag,
  944. struct zfcp_unit *unit,
  945. struct scsi_cmnd *scsi_cmnd)
  946. {
  947. zfcp_scsi_dbf_event(flag == FCP_TARGET_RESET ? "trst" : "lrst", tag, 1,
  948. unit->port->adapter, scsi_cmnd, NULL, 0);
  949. }
  950. static int zfcp_scsi_dbf_view_format(debug_info_t *id, struct debug_view *view,
  951. char *out_buf, const char *in_buf)
  952. {
  953. struct zfcp_scsi_dbf_record *r = (struct zfcp_scsi_dbf_record *)in_buf;
  954. struct timespec t;
  955. char *p = out_buf;
  956. if (strncmp(r->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
  957. return 0;
  958. zfcp_dbf_tag(&p, "tag", r->tag);
  959. zfcp_dbf_tag(&p, "tag2", r->tag2);
  960. zfcp_dbf_out(&p, "scsi_id", "0x%08x", r->scsi_id);
  961. zfcp_dbf_out(&p, "scsi_lun", "0x%08x", r->scsi_lun);
  962. zfcp_dbf_out(&p, "scsi_result", "0x%08x", r->scsi_result);
  963. zfcp_dbf_out(&p, "scsi_cmnd", "0x%0Lx", r->scsi_cmnd);
  964. zfcp_dbf_out(&p, "scsi_serial", "0x%016Lx", r->scsi_serial);
  965. zfcp_dbf_outd(&p, "scsi_opcode", r->scsi_opcode, ZFCP_DBF_SCSI_OPCODE,
  966. 0, ZFCP_DBF_SCSI_OPCODE);
  967. zfcp_dbf_out(&p, "scsi_retries", "0x%02x", r->scsi_retries);
  968. zfcp_dbf_out(&p, "scsi_allowed", "0x%02x", r->scsi_allowed);
  969. if (strncmp(r->tag, "abrt", ZFCP_DBF_TAG_SIZE) == 0)
  970. zfcp_dbf_out(&p, "old_fsf_reqid", "0x%0Lx", r->old_fsf_reqid);
  971. zfcp_dbf_out(&p, "fsf_reqid", "0x%0Lx", r->fsf_reqid);
  972. zfcp_dbf_out(&p, "fsf_seqno", "0x%08x", r->fsf_seqno);
  973. zfcp_dbf_timestamp(r->fsf_issued, &t);
  974. zfcp_dbf_out(&p, "fsf_issued", "%011lu:%06lu", t.tv_sec, t.tv_nsec);
  975. if (strncmp(r->tag, "rslt", ZFCP_DBF_TAG_SIZE) == 0) {
  976. zfcp_dbf_out(&p, "fcp_rsp_validity", "0x%02x", r->rsp_validity);
  977. zfcp_dbf_out(&p, "fcp_rsp_scsi_status", "0x%02x",
  978. r->rsp_scsi_status);
  979. zfcp_dbf_out(&p, "fcp_rsp_resid", "0x%08x", r->rsp_resid);
  980. zfcp_dbf_out(&p, "fcp_rsp_code", "0x%08x", r->rsp_code);
  981. zfcp_dbf_out(&p, "fcp_sns_info_len", "0x%08x", r->sns_info_len);
  982. zfcp_dbf_outd(&p, "fcp_sns_info", r->sns_info,
  983. min((int)r->sns_info_len,
  984. ZFCP_DBF_SCSI_FCP_SNS_INFO), 0,
  985. r->sns_info_len);
  986. }
  987. p += sprintf(p, "\n");
  988. return p - out_buf;
  989. }
  990. static struct debug_view zfcp_scsi_dbf_view = {
  991. "structured",
  992. NULL,
  993. &zfcp_dbf_view_header,
  994. &zfcp_scsi_dbf_view_format,
  995. NULL,
  996. NULL
  997. };
  998. static debug_info_t *zfcp_dbf_reg(const char *name, int level,
  999. struct debug_view *view, int size)
  1000. {
  1001. struct debug_info *d;
  1002. d = debug_register(name, dbfsize, level, size);
  1003. if (!d)
  1004. return NULL;
  1005. debug_register_view(d, &debug_hex_ascii_view);
  1006. debug_register_view(d, view);
  1007. debug_set_level(d, level);
  1008. return d;
  1009. }
  1010. /**
  1011. * zfcp_adapter_debug_register - registers debug feature for an adapter
  1012. * @adapter: pointer to adapter for which debug features should be registered
  1013. * return: -ENOMEM on error, 0 otherwise
  1014. */
  1015. int zfcp_adapter_debug_register(struct zfcp_adapter *adapter)
  1016. {
  1017. char dbf_name[DEBUG_MAX_NAME_LEN];
  1018. struct zfcp_dbf *dbf;
  1019. dbf = kmalloc(sizeof(struct zfcp_dbf), GFP_KERNEL);
  1020. if (!dbf)
  1021. return -ENOMEM;
  1022. spin_lock_init(&dbf->hba_dbf_lock);
  1023. spin_lock_init(&dbf->san_dbf_lock);
  1024. spin_lock_init(&dbf->scsi_dbf_lock);
  1025. spin_lock_init(&dbf->rec_dbf_lock);
  1026. /* debug feature area which records recovery activity */
  1027. sprintf(dbf_name, "zfcp_%s_rec", dev_name(&adapter->ccw_device->dev));
  1028. dbf->rec_dbf = zfcp_dbf_reg(dbf_name, 3, &zfcp_rec_dbf_view,
  1029. sizeof(struct zfcp_rec_dbf_record));
  1030. if (!dbf->rec_dbf)
  1031. goto fail_rec;
  1032. /* debug feature area which records HBA (FSF and QDIO) conditions */
  1033. sprintf(dbf_name, "zfcp_%s_hba", dev_name(&adapter->ccw_device->dev));
  1034. dbf->hba_dbf = zfcp_dbf_reg(dbf_name, 3, &zfcp_hba_dbf_view,
  1035. sizeof(struct zfcp_hba_dbf_record));
  1036. if (!dbf->hba_dbf)
  1037. goto fail_hba;
  1038. /* debug feature area which records SAN command failures and recovery */
  1039. sprintf(dbf_name, "zfcp_%s_san", dev_name(&adapter->ccw_device->dev));
  1040. dbf->san_dbf = zfcp_dbf_reg(dbf_name, 6, &zfcp_san_dbf_view,
  1041. sizeof(struct zfcp_san_dbf_record));
  1042. if (!dbf->san_dbf)
  1043. goto fail_san;
  1044. /* debug feature area which records SCSI command failures and recovery */
  1045. sprintf(dbf_name, "zfcp_%s_scsi", dev_name(&adapter->ccw_device->dev));
  1046. dbf->scsi_dbf = zfcp_dbf_reg(dbf_name, 3, &zfcp_scsi_dbf_view,
  1047. sizeof(struct zfcp_scsi_dbf_record));
  1048. if (!dbf->scsi_dbf)
  1049. goto fail_scsi;
  1050. adapter->dbf = dbf;
  1051. return 0;
  1052. fail_scsi:
  1053. debug_unregister(dbf->san_dbf);
  1054. fail_san:
  1055. debug_unregister(dbf->hba_dbf);
  1056. fail_hba:
  1057. debug_unregister(dbf->rec_dbf);
  1058. fail_rec:
  1059. kfree(dbf);
  1060. return -ENOMEM;
  1061. }
  1062. /**
  1063. * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
  1064. * @adapter: pointer to adapter for which debug features should be unregistered
  1065. */
  1066. void zfcp_adapter_debug_unregister(struct zfcp_adapter *adapter)
  1067. {
  1068. debug_unregister(adapter->dbf->scsi_dbf);
  1069. debug_unregister(adapter->dbf->san_dbf);
  1070. debug_unregister(adapter->dbf->hba_dbf);
  1071. debug_unregister(adapter->dbf->rec_dbf);
  1072. kfree(adapter->dbf);
  1073. adapter->dbf = NULL;
  1074. }