zfcp_dbf.c 44 KB

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