zfcp_dbf.c 43 KB

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