zfcp_dbf.c 41 KB

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