zfcp_dbf.c 42 KB

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