zfcp_dbf.c 44 KB

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