zfcp_dbf.c 43 KB

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