zfcp_dbf.c 44 KB

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