zfcp_dbf.c 42 KB

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