zfcp_dbf.c 42 KB

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