zfcp_dbf.c 44 KB

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