zfcp_dbf.c 39 KB

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