zfcp_dbf.c 44 KB

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