zfcp_dbf.c 43 KB

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