zfcp_dbf.c 42 KB

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