zfcp_dbf.c 43 KB

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