zfcp_dbf.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961
  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. static int
  46. zfcp_dbf_stck(char *out_buf, const char *label, unsigned long long stck)
  47. {
  48. unsigned long long sec;
  49. struct timespec dbftime;
  50. int len = 0;
  51. stck -= 0x8126d60e46000000LL - (0x3c26700LL * 1000000 * 4096);
  52. sec = stck >> 12;
  53. do_div(sec, 1000000);
  54. dbftime.tv_sec = sec;
  55. stck -= (sec * 1000000) << 12;
  56. dbftime.tv_nsec = ((stck * 1000) >> 12);
  57. len += sprintf(out_buf + len, "%-24s%011lu:%06lu\n",
  58. label, dbftime.tv_sec, dbftime.tv_nsec);
  59. return len;
  60. }
  61. static int zfcp_dbf_tag(char *out_buf, const char *label, const char *tag)
  62. {
  63. int len = 0, i;
  64. len += sprintf(out_buf + len, "%-24s", label);
  65. for (i = 0; i < ZFCP_DBF_TAG_SIZE; i++)
  66. len += sprintf(out_buf + len, "%c", tag[i]);
  67. len += sprintf(out_buf + len, "\n");
  68. return len;
  69. }
  70. static int
  71. zfcp_dbf_view(char *out_buf, const char *label, const char *format, ...)
  72. {
  73. va_list arg;
  74. int len = 0;
  75. len += sprintf(out_buf + len, "%-24s", label);
  76. va_start(arg, format);
  77. len += vsprintf(out_buf + len, format, arg);
  78. va_end(arg);
  79. len += sprintf(out_buf + len, "\n");
  80. return len;
  81. }
  82. static int
  83. zfcp_dbf_view_dump(char *out_buf, const char *label,
  84. char *buffer, int buflen, int offset, int total_size)
  85. {
  86. int len = 0;
  87. if (offset == 0)
  88. len += sprintf(out_buf + len, "%-24s ", label);
  89. while (buflen--) {
  90. if (offset > 0) {
  91. if ((offset % 32) == 0)
  92. len += sprintf(out_buf + len, "\n%-24c ", ' ');
  93. else if ((offset % 4) == 0)
  94. len += sprintf(out_buf + len, " ");
  95. }
  96. len += sprintf(out_buf + len, "%02x", *buffer++);
  97. if (++offset == total_size) {
  98. len += sprintf(out_buf + len, "\n");
  99. break;
  100. }
  101. }
  102. if (total_size == 0)
  103. len += sprintf(out_buf + len, "\n");
  104. return len;
  105. }
  106. static int
  107. zfcp_dbf_view_header(debug_info_t * id, struct debug_view *view, int area,
  108. debug_entry_t * entry, char *out_buf)
  109. {
  110. struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)DEBUG_DATA(entry);
  111. int len = 0;
  112. if (strncmp(dump->tag, "dump", ZFCP_DBF_TAG_SIZE) != 0) {
  113. len += zfcp_dbf_stck(out_buf + len, "timestamp",
  114. entry->id.stck);
  115. len += zfcp_dbf_view(out_buf + len, "cpu", "%02i",
  116. entry->id.fields.cpuid);
  117. } else {
  118. len += zfcp_dbf_view_dump(out_buf + len, NULL,
  119. dump->data,
  120. dump->size,
  121. dump->offset, dump->total_size);
  122. if ((dump->offset + dump->size) == dump->total_size)
  123. len += sprintf(out_buf + len, "\n");
  124. }
  125. return len;
  126. }
  127. void zfcp_hba_dbf_event_fsf_response(struct zfcp_fsf_req *fsf_req)
  128. {
  129. struct zfcp_adapter *adapter = fsf_req->adapter;
  130. struct fsf_qtcb *qtcb = fsf_req->qtcb;
  131. union fsf_prot_status_qual *prot_status_qual =
  132. &qtcb->prefix.prot_status_qual;
  133. union fsf_status_qual *fsf_status_qual = &qtcb->header.fsf_status_qual;
  134. struct scsi_cmnd *scsi_cmnd;
  135. struct zfcp_port *port;
  136. struct zfcp_unit *unit;
  137. struct zfcp_send_els *send_els;
  138. struct zfcp_hba_dbf_record *rec = &adapter->hba_dbf_buf;
  139. struct zfcp_hba_dbf_record_response *response = &rec->type.response;
  140. int level;
  141. unsigned long flags;
  142. spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
  143. memset(rec, 0, sizeof(struct zfcp_hba_dbf_record));
  144. strncpy(rec->tag, "resp", ZFCP_DBF_TAG_SIZE);
  145. if ((qtcb->prefix.prot_status != FSF_PROT_GOOD) &&
  146. (qtcb->prefix.prot_status != FSF_PROT_FSF_STATUS_PRESENTED)) {
  147. strncpy(rec->tag2, "perr", ZFCP_DBF_TAG_SIZE);
  148. level = 1;
  149. } else if (qtcb->header.fsf_status != FSF_GOOD) {
  150. strncpy(rec->tag2, "ferr", ZFCP_DBF_TAG_SIZE);
  151. level = 1;
  152. } else if ((fsf_req->fsf_command == FSF_QTCB_OPEN_PORT_WITH_DID) ||
  153. (fsf_req->fsf_command == FSF_QTCB_OPEN_LUN)) {
  154. strncpy(rec->tag2, "open", ZFCP_DBF_TAG_SIZE);
  155. level = 4;
  156. } else {
  157. strncpy(rec->tag2, "norm", ZFCP_DBF_TAG_SIZE);
  158. level = 6;
  159. }
  160. response->fsf_command = fsf_req->fsf_command;
  161. response->fsf_reqid = (unsigned long)fsf_req;
  162. response->fsf_seqno = fsf_req->seq_no;
  163. response->fsf_issued = fsf_req->issued;
  164. response->fsf_prot_status = qtcb->prefix.prot_status;
  165. response->fsf_status = qtcb->header.fsf_status;
  166. memcpy(response->fsf_prot_status_qual,
  167. prot_status_qual, FSF_PROT_STATUS_QUAL_SIZE);
  168. memcpy(response->fsf_status_qual,
  169. fsf_status_qual, FSF_STATUS_QUALIFIER_SIZE);
  170. response->fsf_req_status = fsf_req->status;
  171. response->sbal_first = fsf_req->sbal_first;
  172. response->sbal_curr = fsf_req->sbal_curr;
  173. response->sbal_last = fsf_req->sbal_last;
  174. response->pool = fsf_req->pool != NULL;
  175. response->erp_action = (unsigned long)fsf_req->erp_action;
  176. switch (fsf_req->fsf_command) {
  177. case FSF_QTCB_FCP_CMND:
  178. if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
  179. break;
  180. scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
  181. if (scsi_cmnd != NULL) {
  182. response->data.send_fcp.scsi_cmnd
  183. = (unsigned long)scsi_cmnd;
  184. response->data.send_fcp.scsi_serial
  185. = scsi_cmnd->serial_number;
  186. }
  187. break;
  188. case FSF_QTCB_OPEN_PORT_WITH_DID:
  189. case FSF_QTCB_CLOSE_PORT:
  190. case FSF_QTCB_CLOSE_PHYSICAL_PORT:
  191. port = (struct zfcp_port *)fsf_req->data;
  192. response->data.port.wwpn = port->wwpn;
  193. response->data.port.d_id = port->d_id;
  194. response->data.port.port_handle = qtcb->header.port_handle;
  195. break;
  196. case FSF_QTCB_OPEN_LUN:
  197. case FSF_QTCB_CLOSE_LUN:
  198. unit = (struct zfcp_unit *)fsf_req->data;
  199. port = unit->port;
  200. response->data.unit.wwpn = port->wwpn;
  201. response->data.unit.fcp_lun = unit->fcp_lun;
  202. response->data.unit.port_handle = qtcb->header.port_handle;
  203. response->data.unit.lun_handle = qtcb->header.lun_handle;
  204. break;
  205. case FSF_QTCB_SEND_ELS:
  206. send_els = (struct zfcp_send_els *)fsf_req->data;
  207. response->data.send_els.d_id = qtcb->bottom.support.d_id;
  208. response->data.send_els.ls_code = send_els->ls_code >> 24;
  209. break;
  210. case FSF_QTCB_ABORT_FCP_CMND:
  211. case FSF_QTCB_SEND_GENERIC:
  212. case FSF_QTCB_EXCHANGE_CONFIG_DATA:
  213. case FSF_QTCB_EXCHANGE_PORT_DATA:
  214. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  215. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  216. break;
  217. }
  218. debug_event(adapter->hba_dbf, level,
  219. rec, sizeof(struct zfcp_hba_dbf_record));
  220. spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
  221. }
  222. void
  223. zfcp_hba_dbf_event_fsf_unsol(const char *tag, struct zfcp_adapter *adapter,
  224. struct fsf_status_read_buffer *status_buffer)
  225. {
  226. struct zfcp_hba_dbf_record *rec = &adapter->hba_dbf_buf;
  227. unsigned long flags;
  228. spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
  229. memset(rec, 0, sizeof(struct zfcp_hba_dbf_record));
  230. strncpy(rec->tag, "stat", ZFCP_DBF_TAG_SIZE);
  231. strncpy(rec->tag2, tag, ZFCP_DBF_TAG_SIZE);
  232. rec->type.status.failed = adapter->status_read_failed;
  233. if (status_buffer != NULL) {
  234. rec->type.status.status_type = status_buffer->status_type;
  235. rec->type.status.status_subtype = status_buffer->status_subtype;
  236. memcpy(&rec->type.status.queue_designator,
  237. &status_buffer->queue_designator,
  238. sizeof(struct fsf_queue_designator));
  239. switch (status_buffer->status_type) {
  240. case FSF_STATUS_READ_SENSE_DATA_AVAIL:
  241. rec->type.status.payload_size =
  242. ZFCP_DBF_UNSOL_PAYLOAD_SENSE_DATA_AVAIL;
  243. break;
  244. case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
  245. rec->type.status.payload_size =
  246. ZFCP_DBF_UNSOL_PAYLOAD_BIT_ERROR_THRESHOLD;
  247. break;
  248. case FSF_STATUS_READ_LINK_DOWN:
  249. switch (status_buffer->status_subtype) {
  250. case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
  251. case FSF_STATUS_READ_SUB_FDISC_FAILED:
  252. rec->type.status.payload_size =
  253. sizeof(struct fsf_link_down_info);
  254. }
  255. break;
  256. case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
  257. rec->type.status.payload_size =
  258. ZFCP_DBF_UNSOL_PAYLOAD_FEATURE_UPDATE_ALERT;
  259. break;
  260. }
  261. memcpy(&rec->type.status.payload,
  262. &status_buffer->payload, rec->type.status.payload_size);
  263. }
  264. debug_event(adapter->hba_dbf, 2,
  265. rec, sizeof(struct zfcp_hba_dbf_record));
  266. spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
  267. }
  268. void
  269. zfcp_hba_dbf_event_qdio(struct zfcp_adapter *adapter, unsigned int status,
  270. unsigned int qdio_error, unsigned int siga_error,
  271. int sbal_index, int sbal_count)
  272. {
  273. struct zfcp_hba_dbf_record *rec = &adapter->hba_dbf_buf;
  274. unsigned long flags;
  275. spin_lock_irqsave(&adapter->hba_dbf_lock, flags);
  276. memset(rec, 0, sizeof(struct zfcp_hba_dbf_record));
  277. strncpy(rec->tag, "qdio", ZFCP_DBF_TAG_SIZE);
  278. rec->type.qdio.status = status;
  279. rec->type.qdio.qdio_error = qdio_error;
  280. rec->type.qdio.siga_error = siga_error;
  281. rec->type.qdio.sbal_index = sbal_index;
  282. rec->type.qdio.sbal_count = sbal_count;
  283. debug_event(adapter->hba_dbf, 0,
  284. rec, sizeof(struct zfcp_hba_dbf_record));
  285. spin_unlock_irqrestore(&adapter->hba_dbf_lock, flags);
  286. }
  287. static int
  288. zfcp_hba_dbf_view_response(char *out_buf,
  289. struct zfcp_hba_dbf_record_response *rec)
  290. {
  291. int len = 0;
  292. len += zfcp_dbf_view(out_buf + len, "fsf_command", "0x%08x",
  293. rec->fsf_command);
  294. len += zfcp_dbf_view(out_buf + len, "fsf_reqid", "0x%0Lx",
  295. rec->fsf_reqid);
  296. len += zfcp_dbf_view(out_buf + len, "fsf_seqno", "0x%08x",
  297. rec->fsf_seqno);
  298. len += zfcp_dbf_stck(out_buf + len, "fsf_issued", rec->fsf_issued);
  299. len += zfcp_dbf_view(out_buf + len, "fsf_prot_status", "0x%08x",
  300. rec->fsf_prot_status);
  301. len += zfcp_dbf_view(out_buf + len, "fsf_status", "0x%08x",
  302. rec->fsf_status);
  303. len += zfcp_dbf_view_dump(out_buf + len, "fsf_prot_status_qual",
  304. rec->fsf_prot_status_qual,
  305. FSF_PROT_STATUS_QUAL_SIZE,
  306. 0, FSF_PROT_STATUS_QUAL_SIZE);
  307. len += zfcp_dbf_view_dump(out_buf + len, "fsf_status_qual",
  308. rec->fsf_status_qual,
  309. FSF_STATUS_QUALIFIER_SIZE,
  310. 0, FSF_STATUS_QUALIFIER_SIZE);
  311. len += zfcp_dbf_view(out_buf + len, "fsf_req_status", "0x%08x",
  312. rec->fsf_req_status);
  313. len += zfcp_dbf_view(out_buf + len, "sbal_first", "0x%02x",
  314. rec->sbal_first);
  315. len += zfcp_dbf_view(out_buf + len, "sbal_curr", "0x%02x",
  316. rec->sbal_curr);
  317. len += zfcp_dbf_view(out_buf + len, "sbal_last", "0x%02x",
  318. rec->sbal_last);
  319. len += zfcp_dbf_view(out_buf + len, "pool", "0x%02x", rec->pool);
  320. switch (rec->fsf_command) {
  321. case FSF_QTCB_FCP_CMND:
  322. if (rec->fsf_req_status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
  323. break;
  324. len += zfcp_dbf_view(out_buf + len, "scsi_cmnd", "0x%0Lx",
  325. rec->data.send_fcp.scsi_cmnd);
  326. len += zfcp_dbf_view(out_buf + len, "scsi_serial", "0x%016Lx",
  327. rec->data.send_fcp.scsi_serial);
  328. break;
  329. case FSF_QTCB_OPEN_PORT_WITH_DID:
  330. case FSF_QTCB_CLOSE_PORT:
  331. case FSF_QTCB_CLOSE_PHYSICAL_PORT:
  332. len += zfcp_dbf_view(out_buf + len, "wwpn", "0x%016Lx",
  333. rec->data.port.wwpn);
  334. len += zfcp_dbf_view(out_buf + len, "d_id", "0x%06x",
  335. rec->data.port.d_id);
  336. len += zfcp_dbf_view(out_buf + len, "port_handle", "0x%08x",
  337. rec->data.port.port_handle);
  338. break;
  339. case FSF_QTCB_OPEN_LUN:
  340. case FSF_QTCB_CLOSE_LUN:
  341. len += zfcp_dbf_view(out_buf + len, "wwpn", "0x%016Lx",
  342. rec->data.unit.wwpn);
  343. len += zfcp_dbf_view(out_buf + len, "fcp_lun", "0x%016Lx",
  344. rec->data.unit.fcp_lun);
  345. len += zfcp_dbf_view(out_buf + len, "port_handle", "0x%08x",
  346. rec->data.unit.port_handle);
  347. len += zfcp_dbf_view(out_buf + len, "lun_handle", "0x%08x",
  348. rec->data.unit.lun_handle);
  349. break;
  350. case FSF_QTCB_SEND_ELS:
  351. len += zfcp_dbf_view(out_buf + len, "d_id", "0x%06x",
  352. rec->data.send_els.d_id);
  353. len += zfcp_dbf_view(out_buf + len, "ls_code", "0x%02x",
  354. rec->data.send_els.ls_code);
  355. break;
  356. case FSF_QTCB_ABORT_FCP_CMND:
  357. case FSF_QTCB_SEND_GENERIC:
  358. case FSF_QTCB_EXCHANGE_CONFIG_DATA:
  359. case FSF_QTCB_EXCHANGE_PORT_DATA:
  360. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  361. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  362. break;
  363. }
  364. return len;
  365. }
  366. static int
  367. zfcp_hba_dbf_view_status(char *out_buf, struct zfcp_hba_dbf_record_status *rec)
  368. {
  369. int len = 0;
  370. len += zfcp_dbf_view(out_buf + len, "failed", "0x%02x", rec->failed);
  371. len += zfcp_dbf_view(out_buf + len, "status_type", "0x%08x",
  372. rec->status_type);
  373. len += zfcp_dbf_view(out_buf + len, "status_subtype", "0x%08x",
  374. rec->status_subtype);
  375. len += zfcp_dbf_view_dump(out_buf + len, "queue_designator",
  376. (char *)&rec->queue_designator,
  377. sizeof(struct fsf_queue_designator),
  378. 0, sizeof(struct fsf_queue_designator));
  379. len += zfcp_dbf_view_dump(out_buf + len, "payload",
  380. (char *)&rec->payload,
  381. rec->payload_size, 0, rec->payload_size);
  382. return len;
  383. }
  384. static int
  385. zfcp_hba_dbf_view_qdio(char *out_buf, struct zfcp_hba_dbf_record_qdio *rec)
  386. {
  387. int len = 0;
  388. len += zfcp_dbf_view(out_buf + len, "status", "0x%08x", rec->status);
  389. len += zfcp_dbf_view(out_buf + len, "qdio_error", "0x%08x",
  390. rec->qdio_error);
  391. len += zfcp_dbf_view(out_buf + len, "siga_error", "0x%08x",
  392. rec->siga_error);
  393. len += zfcp_dbf_view(out_buf + len, "sbal_index", "0x%02x",
  394. rec->sbal_index);
  395. len += zfcp_dbf_view(out_buf + len, "sbal_count", "0x%02x",
  396. rec->sbal_count);
  397. return len;
  398. }
  399. static int
  400. zfcp_hba_dbf_view_format(debug_info_t * id, struct debug_view *view,
  401. char *out_buf, const char *in_buf)
  402. {
  403. struct zfcp_hba_dbf_record *rec = (struct zfcp_hba_dbf_record *)in_buf;
  404. int len = 0;
  405. if (strncmp(rec->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
  406. return 0;
  407. len += zfcp_dbf_tag(out_buf + len, "tag", rec->tag);
  408. if (isalpha(rec->tag2[0]))
  409. len += zfcp_dbf_tag(out_buf + len, "tag2", rec->tag2);
  410. if (strncmp(rec->tag, "resp", ZFCP_DBF_TAG_SIZE) == 0)
  411. len += zfcp_hba_dbf_view_response(out_buf + len,
  412. &rec->type.response);
  413. else if (strncmp(rec->tag, "stat", ZFCP_DBF_TAG_SIZE) == 0)
  414. len += zfcp_hba_dbf_view_status(out_buf + len,
  415. &rec->type.status);
  416. else if (strncmp(rec->tag, "qdio", ZFCP_DBF_TAG_SIZE) == 0)
  417. len += zfcp_hba_dbf_view_qdio(out_buf + len, &rec->type.qdio);
  418. len += sprintf(out_buf + len, "\n");
  419. return len;
  420. }
  421. static struct debug_view zfcp_hba_dbf_view = {
  422. "structured",
  423. NULL,
  424. &zfcp_dbf_view_header,
  425. &zfcp_hba_dbf_view_format,
  426. NULL,
  427. NULL
  428. };
  429. static void
  430. _zfcp_san_dbf_event_common_ct(const char *tag, struct zfcp_fsf_req *fsf_req,
  431. u32 s_id, u32 d_id, void *buffer, int buflen)
  432. {
  433. struct zfcp_send_ct *send_ct = (struct zfcp_send_ct *)fsf_req->data;
  434. struct zfcp_port *port = send_ct->port;
  435. struct zfcp_adapter *adapter = port->adapter;
  436. struct ct_hdr *header = (struct ct_hdr *)buffer;
  437. struct zfcp_san_dbf_record *rec = &adapter->san_dbf_buf;
  438. struct zfcp_san_dbf_record_ct *ct = &rec->type.ct;
  439. unsigned long flags;
  440. spin_lock_irqsave(&adapter->san_dbf_lock, flags);
  441. memset(rec, 0, sizeof(struct zfcp_san_dbf_record));
  442. strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
  443. rec->fsf_reqid = (unsigned long)fsf_req;
  444. rec->fsf_seqno = fsf_req->seq_no;
  445. rec->s_id = s_id;
  446. rec->d_id = d_id;
  447. if (strncmp(tag, "octc", ZFCP_DBF_TAG_SIZE) == 0) {
  448. ct->type.request.cmd_req_code = header->cmd_rsp_code;
  449. ct->type.request.revision = header->revision;
  450. ct->type.request.gs_type = header->gs_type;
  451. ct->type.request.gs_subtype = header->gs_subtype;
  452. ct->type.request.options = header->options;
  453. ct->type.request.max_res_size = header->max_res_size;
  454. } else if (strncmp(tag, "rctc", ZFCP_DBF_TAG_SIZE) == 0) {
  455. ct->type.response.cmd_rsp_code = header->cmd_rsp_code;
  456. ct->type.response.revision = header->revision;
  457. ct->type.response.reason_code = header->reason_code;
  458. ct->type.response.reason_code_expl = header->reason_code_expl;
  459. ct->type.response.vendor_unique = header->vendor_unique;
  460. }
  461. ct->payload_size =
  462. min(buflen - (int)sizeof(struct ct_hdr), ZFCP_DBF_CT_PAYLOAD);
  463. memcpy(ct->payload, buffer + sizeof(struct ct_hdr), ct->payload_size);
  464. debug_event(adapter->san_dbf, 3,
  465. rec, sizeof(struct zfcp_san_dbf_record));
  466. spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
  467. }
  468. void zfcp_san_dbf_event_ct_request(struct zfcp_fsf_req *fsf_req)
  469. {
  470. struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data;
  471. struct zfcp_port *port = ct->port;
  472. struct zfcp_adapter *adapter = port->adapter;
  473. _zfcp_san_dbf_event_common_ct("octc", fsf_req,
  474. fc_host_port_id(adapter->scsi_host),
  475. port->d_id, zfcp_sg_to_address(ct->req),
  476. ct->req->length);
  477. }
  478. void zfcp_san_dbf_event_ct_response(struct zfcp_fsf_req *fsf_req)
  479. {
  480. struct zfcp_send_ct *ct = (struct zfcp_send_ct *)fsf_req->data;
  481. struct zfcp_port *port = ct->port;
  482. struct zfcp_adapter *adapter = port->adapter;
  483. _zfcp_san_dbf_event_common_ct("rctc", fsf_req, port->d_id,
  484. fc_host_port_id(adapter->scsi_host),
  485. zfcp_sg_to_address(ct->resp),
  486. ct->resp->length);
  487. }
  488. static void
  489. _zfcp_san_dbf_event_common_els(const char *tag, int level,
  490. struct zfcp_fsf_req *fsf_req, u32 s_id,
  491. u32 d_id, u8 ls_code, void *buffer, int buflen)
  492. {
  493. struct zfcp_adapter *adapter = fsf_req->adapter;
  494. struct zfcp_san_dbf_record *rec = &adapter->san_dbf_buf;
  495. unsigned long flags;
  496. spin_lock_irqsave(&adapter->san_dbf_lock, flags);
  497. memset(rec, 0, sizeof(struct zfcp_san_dbf_record));
  498. strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
  499. rec->fsf_reqid = (unsigned long)fsf_req;
  500. rec->fsf_seqno = fsf_req->seq_no;
  501. rec->s_id = s_id;
  502. rec->d_id = d_id;
  503. rec->type.els.ls_code = ls_code;
  504. debug_event(adapter->san_dbf, level, rec, sizeof(*rec));
  505. zfcp_dbf_hexdump(adapter->san_dbf, rec, sizeof(*rec), level,
  506. buffer, min(buflen, ZFCP_DBF_ELS_MAX_PAYLOAD));
  507. spin_unlock_irqrestore(&adapter->san_dbf_lock, flags);
  508. }
  509. void zfcp_san_dbf_event_els_request(struct zfcp_fsf_req *fsf_req)
  510. {
  511. struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data;
  512. _zfcp_san_dbf_event_common_els("oels", 2, fsf_req,
  513. fc_host_port_id(els->adapter->scsi_host),
  514. els->d_id,
  515. *(u8 *) zfcp_sg_to_address(els->req),
  516. zfcp_sg_to_address(els->req),
  517. els->req->length);
  518. }
  519. void zfcp_san_dbf_event_els_response(struct zfcp_fsf_req *fsf_req)
  520. {
  521. struct zfcp_send_els *els = (struct zfcp_send_els *)fsf_req->data;
  522. _zfcp_san_dbf_event_common_els("rels", 2, fsf_req, els->d_id,
  523. fc_host_port_id(els->adapter->scsi_host),
  524. *(u8 *) zfcp_sg_to_address(els->req),
  525. zfcp_sg_to_address(els->resp),
  526. els->resp->length);
  527. }
  528. void zfcp_san_dbf_event_incoming_els(struct zfcp_fsf_req *fsf_req)
  529. {
  530. struct zfcp_adapter *adapter = fsf_req->adapter;
  531. struct fsf_status_read_buffer *status_buffer =
  532. (struct fsf_status_read_buffer *)fsf_req->data;
  533. int length = (int)status_buffer->length -
  534. (int)((void *)&status_buffer->payload - (void *)status_buffer);
  535. _zfcp_san_dbf_event_common_els("iels", 1, fsf_req, status_buffer->d_id,
  536. fc_host_port_id(adapter->scsi_host),
  537. *(u8 *) status_buffer->payload,
  538. (void *)status_buffer->payload, length);
  539. }
  540. static int
  541. zfcp_san_dbf_view_format(debug_info_t * id, struct debug_view *view,
  542. char *out_buf, const char *in_buf)
  543. {
  544. struct zfcp_san_dbf_record *rec = (struct zfcp_san_dbf_record *)in_buf;
  545. char *buffer = NULL;
  546. int buflen = 0, total = 0;
  547. int len = 0;
  548. if (strncmp(rec->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
  549. return 0;
  550. len += zfcp_dbf_tag(out_buf + len, "tag", rec->tag);
  551. len += zfcp_dbf_view(out_buf + len, "fsf_reqid", "0x%0Lx",
  552. rec->fsf_reqid);
  553. len += zfcp_dbf_view(out_buf + len, "fsf_seqno", "0x%08x",
  554. rec->fsf_seqno);
  555. len += zfcp_dbf_view(out_buf + len, "s_id", "0x%06x", rec->s_id);
  556. len += zfcp_dbf_view(out_buf + len, "d_id", "0x%06x", rec->d_id);
  557. if (strncmp(rec->tag, "octc", ZFCP_DBF_TAG_SIZE) == 0) {
  558. len += zfcp_dbf_view(out_buf + len, "cmd_req_code", "0x%04x",
  559. rec->type.ct.type.request.cmd_req_code);
  560. len += zfcp_dbf_view(out_buf + len, "revision", "0x%02x",
  561. rec->type.ct.type.request.revision);
  562. len += zfcp_dbf_view(out_buf + len, "gs_type", "0x%02x",
  563. rec->type.ct.type.request.gs_type);
  564. len += zfcp_dbf_view(out_buf + len, "gs_subtype", "0x%02x",
  565. rec->type.ct.type.request.gs_subtype);
  566. len += zfcp_dbf_view(out_buf + len, "options", "0x%02x",
  567. rec->type.ct.type.request.options);
  568. len += zfcp_dbf_view(out_buf + len, "max_res_size", "0x%04x",
  569. rec->type.ct.type.request.max_res_size);
  570. total = rec->type.ct.payload_size;
  571. buffer = rec->type.ct.payload;
  572. buflen = min(total, ZFCP_DBF_CT_PAYLOAD);
  573. } else if (strncmp(rec->tag, "rctc", ZFCP_DBF_TAG_SIZE) == 0) {
  574. len += zfcp_dbf_view(out_buf + len, "cmd_rsp_code", "0x%04x",
  575. rec->type.ct.type.response.cmd_rsp_code);
  576. len += zfcp_dbf_view(out_buf + len, "revision", "0x%02x",
  577. rec->type.ct.type.response.revision);
  578. len += zfcp_dbf_view(out_buf + len, "reason_code", "0x%02x",
  579. rec->type.ct.type.response.reason_code);
  580. len +=
  581. zfcp_dbf_view(out_buf + len, "reason_code_expl", "0x%02x",
  582. rec->type.ct.type.response.reason_code_expl);
  583. len +=
  584. zfcp_dbf_view(out_buf + len, "vendor_unique", "0x%02x",
  585. rec->type.ct.type.response.vendor_unique);
  586. total = rec->type.ct.payload_size;
  587. buffer = rec->type.ct.payload;
  588. buflen = min(total, ZFCP_DBF_CT_PAYLOAD);
  589. } else if (strncmp(rec->tag, "oels", ZFCP_DBF_TAG_SIZE) == 0 ||
  590. strncmp(rec->tag, "rels", ZFCP_DBF_TAG_SIZE) == 0 ||
  591. strncmp(rec->tag, "iels", ZFCP_DBF_TAG_SIZE) == 0) {
  592. len += zfcp_dbf_view(out_buf + len, "ls_code", "0x%02x",
  593. rec->type.els.ls_code);
  594. total = rec->type.els.payload_size;
  595. buffer = rec->type.els.payload;
  596. buflen = min(total, ZFCP_DBF_ELS_PAYLOAD);
  597. }
  598. len += zfcp_dbf_view_dump(out_buf + len, "payload",
  599. buffer, buflen, 0, total);
  600. if (buflen == total)
  601. len += sprintf(out_buf + len, "\n");
  602. return len;
  603. }
  604. static struct debug_view zfcp_san_dbf_view = {
  605. "structured",
  606. NULL,
  607. &zfcp_dbf_view_header,
  608. &zfcp_san_dbf_view_format,
  609. NULL,
  610. NULL
  611. };
  612. static void
  613. _zfcp_scsi_dbf_event_common(const char *tag, const char *tag2, int level,
  614. struct zfcp_adapter *adapter,
  615. struct scsi_cmnd *scsi_cmnd,
  616. struct zfcp_fsf_req *fsf_req,
  617. unsigned long old_req_id)
  618. {
  619. struct zfcp_scsi_dbf_record *rec = &adapter->scsi_dbf_buf;
  620. struct zfcp_dbf_dump *dump = (struct zfcp_dbf_dump *)rec;
  621. unsigned long flags;
  622. struct fcp_rsp_iu *fcp_rsp;
  623. char *fcp_rsp_info = NULL, *fcp_sns_info = NULL;
  624. int offset = 0, buflen = 0;
  625. spin_lock_irqsave(&adapter->scsi_dbf_lock, flags);
  626. do {
  627. memset(rec, 0, sizeof(struct zfcp_scsi_dbf_record));
  628. if (offset == 0) {
  629. strncpy(rec->tag, tag, ZFCP_DBF_TAG_SIZE);
  630. strncpy(rec->tag2, tag2, ZFCP_DBF_TAG_SIZE);
  631. if (scsi_cmnd != NULL) {
  632. if (scsi_cmnd->device) {
  633. rec->scsi_id = scsi_cmnd->device->id;
  634. rec->scsi_lun = scsi_cmnd->device->lun;
  635. }
  636. rec->scsi_result = scsi_cmnd->result;
  637. rec->scsi_cmnd = (unsigned long)scsi_cmnd;
  638. rec->scsi_serial = scsi_cmnd->serial_number;
  639. memcpy(rec->scsi_opcode, &scsi_cmnd->cmnd,
  640. min((int)scsi_cmnd->cmd_len,
  641. ZFCP_DBF_SCSI_OPCODE));
  642. rec->scsi_retries = scsi_cmnd->retries;
  643. rec->scsi_allowed = scsi_cmnd->allowed;
  644. }
  645. if (fsf_req != NULL) {
  646. fcp_rsp = (struct fcp_rsp_iu *)
  647. &(fsf_req->qtcb->bottom.io.fcp_rsp);
  648. fcp_rsp_info =
  649. zfcp_get_fcp_rsp_info_ptr(fcp_rsp);
  650. fcp_sns_info =
  651. zfcp_get_fcp_sns_info_ptr(fcp_rsp);
  652. rec->type.fcp.rsp_validity =
  653. fcp_rsp->validity.value;
  654. rec->type.fcp.rsp_scsi_status =
  655. fcp_rsp->scsi_status;
  656. rec->type.fcp.rsp_resid = fcp_rsp->fcp_resid;
  657. if (fcp_rsp->validity.bits.fcp_rsp_len_valid)
  658. rec->type.fcp.rsp_code =
  659. *(fcp_rsp_info + 3);
  660. if (fcp_rsp->validity.bits.fcp_sns_len_valid) {
  661. buflen = min((int)fcp_rsp->fcp_sns_len,
  662. ZFCP_DBF_SCSI_MAX_FCP_SNS_INFO);
  663. rec->type.fcp.sns_info_len = buflen;
  664. memcpy(rec->type.fcp.sns_info,
  665. fcp_sns_info,
  666. min(buflen,
  667. ZFCP_DBF_SCSI_FCP_SNS_INFO));
  668. offset += min(buflen,
  669. ZFCP_DBF_SCSI_FCP_SNS_INFO);
  670. }
  671. rec->fsf_reqid = (unsigned long)fsf_req;
  672. rec->fsf_seqno = fsf_req->seq_no;
  673. rec->fsf_issued = fsf_req->issued;
  674. }
  675. rec->type.old_fsf_reqid = old_req_id;
  676. } else {
  677. strncpy(dump->tag, "dump", ZFCP_DBF_TAG_SIZE);
  678. dump->total_size = buflen;
  679. dump->offset = offset;
  680. dump->size = min(buflen - offset,
  681. (int)sizeof(struct
  682. zfcp_scsi_dbf_record) -
  683. (int)sizeof(struct zfcp_dbf_dump));
  684. memcpy(dump->data, fcp_sns_info + offset, dump->size);
  685. offset += dump->size;
  686. }
  687. debug_event(adapter->scsi_dbf, level,
  688. rec, sizeof(struct zfcp_scsi_dbf_record));
  689. } while (offset < buflen);
  690. spin_unlock_irqrestore(&adapter->scsi_dbf_lock, flags);
  691. }
  692. void
  693. zfcp_scsi_dbf_event_result(const char *tag, int level,
  694. struct zfcp_adapter *adapter,
  695. struct scsi_cmnd *scsi_cmnd,
  696. struct zfcp_fsf_req *fsf_req)
  697. {
  698. _zfcp_scsi_dbf_event_common("rslt", tag, level,
  699. adapter, scsi_cmnd, fsf_req, 0);
  700. }
  701. void
  702. zfcp_scsi_dbf_event_abort(const char *tag, struct zfcp_adapter *adapter,
  703. struct scsi_cmnd *scsi_cmnd,
  704. struct zfcp_fsf_req *new_fsf_req,
  705. unsigned long old_req_id)
  706. {
  707. _zfcp_scsi_dbf_event_common("abrt", tag, 1,
  708. adapter, scsi_cmnd, new_fsf_req, old_req_id);
  709. }
  710. void
  711. zfcp_scsi_dbf_event_devreset(const char *tag, u8 flag, struct zfcp_unit *unit,
  712. struct scsi_cmnd *scsi_cmnd)
  713. {
  714. struct zfcp_adapter *adapter = unit->port->adapter;
  715. _zfcp_scsi_dbf_event_common(flag == FCP_TARGET_RESET ? "trst" : "lrst",
  716. tag, 1, adapter, scsi_cmnd, NULL, 0);
  717. }
  718. static int
  719. zfcp_scsi_dbf_view_format(debug_info_t * id, struct debug_view *view,
  720. char *out_buf, const char *in_buf)
  721. {
  722. struct zfcp_scsi_dbf_record *rec =
  723. (struct zfcp_scsi_dbf_record *)in_buf;
  724. int len = 0;
  725. if (strncmp(rec->tag, "dump", ZFCP_DBF_TAG_SIZE) == 0)
  726. return 0;
  727. len += zfcp_dbf_tag(out_buf + len, "tag", rec->tag);
  728. len += zfcp_dbf_tag(out_buf + len, "tag2", rec->tag2);
  729. len += zfcp_dbf_view(out_buf + len, "scsi_id", "0x%08x", rec->scsi_id);
  730. len += zfcp_dbf_view(out_buf + len, "scsi_lun", "0x%08x",
  731. rec->scsi_lun);
  732. len += zfcp_dbf_view(out_buf + len, "scsi_result", "0x%08x",
  733. rec->scsi_result);
  734. len += zfcp_dbf_view(out_buf + len, "scsi_cmnd", "0x%0Lx",
  735. rec->scsi_cmnd);
  736. len += zfcp_dbf_view(out_buf + len, "scsi_serial", "0x%016Lx",
  737. rec->scsi_serial);
  738. len += zfcp_dbf_view_dump(out_buf + len, "scsi_opcode",
  739. rec->scsi_opcode,
  740. ZFCP_DBF_SCSI_OPCODE,
  741. 0, ZFCP_DBF_SCSI_OPCODE);
  742. len += zfcp_dbf_view(out_buf + len, "scsi_retries", "0x%02x",
  743. rec->scsi_retries);
  744. len += zfcp_dbf_view(out_buf + len, "scsi_allowed", "0x%02x",
  745. rec->scsi_allowed);
  746. if (strncmp(rec->tag, "abrt", ZFCP_DBF_TAG_SIZE) == 0) {
  747. len += zfcp_dbf_view(out_buf + len, "old_fsf_reqid", "0x%0Lx",
  748. rec->type.old_fsf_reqid);
  749. }
  750. len += zfcp_dbf_view(out_buf + len, "fsf_reqid", "0x%0Lx",
  751. rec->fsf_reqid);
  752. len += zfcp_dbf_view(out_buf + len, "fsf_seqno", "0x%08x",
  753. rec->fsf_seqno);
  754. len += zfcp_dbf_stck(out_buf + len, "fsf_issued", rec->fsf_issued);
  755. if (strncmp(rec->tag, "rslt", ZFCP_DBF_TAG_SIZE) == 0) {
  756. len +=
  757. zfcp_dbf_view(out_buf + len, "fcp_rsp_validity", "0x%02x",
  758. rec->type.fcp.rsp_validity);
  759. len +=
  760. zfcp_dbf_view(out_buf + len, "fcp_rsp_scsi_status",
  761. "0x%02x", rec->type.fcp.rsp_scsi_status);
  762. len +=
  763. zfcp_dbf_view(out_buf + len, "fcp_rsp_resid", "0x%08x",
  764. rec->type.fcp.rsp_resid);
  765. len +=
  766. zfcp_dbf_view(out_buf + len, "fcp_rsp_code", "0x%08x",
  767. rec->type.fcp.rsp_code);
  768. len +=
  769. zfcp_dbf_view(out_buf + len, "fcp_sns_info_len", "0x%08x",
  770. rec->type.fcp.sns_info_len);
  771. len +=
  772. zfcp_dbf_view_dump(out_buf + len, "fcp_sns_info",
  773. rec->type.fcp.sns_info,
  774. min((int)rec->type.fcp.sns_info_len,
  775. ZFCP_DBF_SCSI_FCP_SNS_INFO), 0,
  776. rec->type.fcp.sns_info_len);
  777. }
  778. len += sprintf(out_buf + len, "\n");
  779. return len;
  780. }
  781. static struct debug_view zfcp_scsi_dbf_view = {
  782. "structured",
  783. NULL,
  784. &zfcp_dbf_view_header,
  785. &zfcp_scsi_dbf_view_format,
  786. NULL,
  787. NULL
  788. };
  789. /**
  790. * zfcp_adapter_debug_register - registers debug feature for an adapter
  791. * @adapter: pointer to adapter for which debug features should be registered
  792. * return: -ENOMEM on error, 0 otherwise
  793. */
  794. int zfcp_adapter_debug_register(struct zfcp_adapter *adapter)
  795. {
  796. char dbf_name[DEBUG_MAX_NAME_LEN];
  797. /* debug feature area which records recovery activity */
  798. sprintf(dbf_name, "zfcp_%s_erp", zfcp_get_busid_by_adapter(adapter));
  799. adapter->erp_dbf = debug_register(dbf_name, dbfsize, 2,
  800. sizeof(struct zfcp_erp_dbf_record));
  801. if (!adapter->erp_dbf)
  802. goto failed;
  803. debug_register_view(adapter->erp_dbf, &debug_hex_ascii_view);
  804. debug_set_level(adapter->erp_dbf, 3);
  805. /* debug feature area which records HBA (FSF and QDIO) conditions */
  806. sprintf(dbf_name, "zfcp_%s_hba", zfcp_get_busid_by_adapter(adapter));
  807. adapter->hba_dbf = debug_register(dbf_name, dbfsize, 1,
  808. sizeof(struct zfcp_hba_dbf_record));
  809. if (!adapter->hba_dbf)
  810. goto failed;
  811. debug_register_view(adapter->hba_dbf, &debug_hex_ascii_view);
  812. debug_register_view(adapter->hba_dbf, &zfcp_hba_dbf_view);
  813. debug_set_level(adapter->hba_dbf, 3);
  814. /* debug feature area which records SAN command failures and recovery */
  815. sprintf(dbf_name, "zfcp_%s_san", zfcp_get_busid_by_adapter(adapter));
  816. adapter->san_dbf = debug_register(dbf_name, dbfsize, 1,
  817. sizeof(struct zfcp_san_dbf_record));
  818. if (!adapter->san_dbf)
  819. goto failed;
  820. debug_register_view(adapter->san_dbf, &debug_hex_ascii_view);
  821. debug_register_view(adapter->san_dbf, &zfcp_san_dbf_view);
  822. debug_set_level(adapter->san_dbf, 6);
  823. /* debug feature area which records SCSI command failures and recovery */
  824. sprintf(dbf_name, "zfcp_%s_scsi", zfcp_get_busid_by_adapter(adapter));
  825. adapter->scsi_dbf = debug_register(dbf_name, dbfsize, 1,
  826. sizeof(struct zfcp_scsi_dbf_record));
  827. if (!adapter->scsi_dbf)
  828. goto failed;
  829. debug_register_view(adapter->scsi_dbf, &debug_hex_ascii_view);
  830. debug_register_view(adapter->scsi_dbf, &zfcp_scsi_dbf_view);
  831. debug_set_level(adapter->scsi_dbf, 3);
  832. return 0;
  833. failed:
  834. zfcp_adapter_debug_unregister(adapter);
  835. return -ENOMEM;
  836. }
  837. /**
  838. * zfcp_adapter_debug_unregister - unregisters debug feature for an adapter
  839. * @adapter: pointer to adapter for which debug features should be unregistered
  840. */
  841. void zfcp_adapter_debug_unregister(struct zfcp_adapter *adapter)
  842. {
  843. debug_unregister(adapter->scsi_dbf);
  844. debug_unregister(adapter->san_dbf);
  845. debug_unregister(adapter->hba_dbf);
  846. debug_unregister(adapter->erp_dbf);
  847. adapter->scsi_dbf = NULL;
  848. adapter->san_dbf = NULL;
  849. adapter->hba_dbf = NULL;
  850. adapter->erp_dbf = NULL;
  851. }
  852. #undef ZFCP_LOG_AREA