zfcp_dbf.c 35 KB

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