zfcp_dbf.c 31 KB

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