zfcp_dbf.c 42 KB

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