scsi_trace.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. /*
  2. * Copyright (C) 2010 FUJITSU LIMITED
  3. * Copyright (C) 2010 Tomohiro Kusumi <kusumi.tomohiro@jp.fujitsu.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/trace_seq.h>
  20. #include <asm/unaligned.h>
  21. #include <trace/events/scsi.h>
  22. #define SERVICE_ACTION16(cdb) (cdb[1] & 0x1f)
  23. #define SERVICE_ACTION32(cdb) (get_unaligned_be16(&cdb[8]))
  24. static const char *
  25. scsi_trace_misc(struct trace_seq *, unsigned char *, int);
  26. static const char *
  27. scsi_trace_rw6(struct trace_seq *p, unsigned char *cdb, int len)
  28. {
  29. const char *ret = trace_seq_buffer_ptr(p);
  30. u32 lba = 0, txlen;
  31. lba |= ((cdb[1] & 0x1F) << 16);
  32. lba |= (cdb[2] << 8);
  33. lba |= cdb[3];
  34. /*
  35. * From SBC-2: a TRANSFER LENGTH field set to zero specifies that 256
  36. * logical blocks shall be read (READ(6)) or written (WRITE(6)).
  37. */
  38. txlen = cdb[4] ? cdb[4] : 256;
  39. trace_seq_printf(p, "lba=%u txlen=%u", lba, txlen);
  40. trace_seq_putc(p, 0);
  41. return ret;
  42. }
  43. static const char *
  44. scsi_trace_rw10(struct trace_seq *p, unsigned char *cdb, int len)
  45. {
  46. const char *ret = trace_seq_buffer_ptr(p);
  47. u32 lba, txlen;
  48. lba = get_unaligned_be32(&cdb[2]);
  49. txlen = get_unaligned_be16(&cdb[7]);
  50. trace_seq_printf(p, "lba=%u txlen=%u protect=%u", lba, txlen,
  51. cdb[1] >> 5);
  52. if (cdb[0] == WRITE_SAME)
  53. trace_seq_printf(p, " unmap=%u", cdb[1] >> 3 & 1);
  54. trace_seq_putc(p, 0);
  55. return ret;
  56. }
  57. static const char *
  58. scsi_trace_rw12(struct trace_seq *p, unsigned char *cdb, int len)
  59. {
  60. const char *ret = trace_seq_buffer_ptr(p);
  61. u32 lba, txlen;
  62. lba = get_unaligned_be32(&cdb[2]);
  63. txlen = get_unaligned_be32(&cdb[6]);
  64. trace_seq_printf(p, "lba=%u txlen=%u protect=%u", lba, txlen,
  65. cdb[1] >> 5);
  66. trace_seq_putc(p, 0);
  67. return ret;
  68. }
  69. static const char *
  70. scsi_trace_rw16(struct trace_seq *p, unsigned char *cdb, int len)
  71. {
  72. const char *ret = trace_seq_buffer_ptr(p);
  73. u64 lba;
  74. u32 txlen;
  75. lba = get_unaligned_be64(&cdb[2]);
  76. txlen = get_unaligned_be32(&cdb[10]);
  77. trace_seq_printf(p, "lba=%llu txlen=%u protect=%u", lba, txlen,
  78. cdb[1] >> 5);
  79. if (cdb[0] == WRITE_SAME_16)
  80. trace_seq_printf(p, " unmap=%u", cdb[1] >> 3 & 1);
  81. trace_seq_putc(p, 0);
  82. return ret;
  83. }
  84. static const char *
  85. scsi_trace_rw32(struct trace_seq *p, unsigned char *cdb, int len)
  86. {
  87. const char *ret = trace_seq_buffer_ptr(p), *cmd;
  88. u64 lba;
  89. u32 ei_lbrt, txlen;
  90. switch (SERVICE_ACTION32(cdb)) {
  91. case READ_32:
  92. cmd = "READ";
  93. break;
  94. case VERIFY_32:
  95. cmd = "VERIFY";
  96. break;
  97. case WRITE_32:
  98. cmd = "WRITE";
  99. break;
  100. case WRITE_SAME_32:
  101. cmd = "WRITE_SAME";
  102. break;
  103. default:
  104. trace_seq_puts(p, "UNKNOWN");
  105. goto out;
  106. }
  107. lba = get_unaligned_be64(&cdb[12]);
  108. ei_lbrt = get_unaligned_be32(&cdb[20]);
  109. txlen = get_unaligned_be32(&cdb[28]);
  110. trace_seq_printf(p, "%s_32 lba=%llu txlen=%u protect=%u ei_lbrt=%u",
  111. cmd, lba, txlen, cdb[10] >> 5, ei_lbrt);
  112. if (SERVICE_ACTION32(cdb) == WRITE_SAME_32)
  113. trace_seq_printf(p, " unmap=%u", cdb[10] >> 3 & 1);
  114. out:
  115. trace_seq_putc(p, 0);
  116. return ret;
  117. }
  118. static const char *
  119. scsi_trace_unmap(struct trace_seq *p, unsigned char *cdb, int len)
  120. {
  121. const char *ret = trace_seq_buffer_ptr(p);
  122. unsigned int regions = get_unaligned_be16(&cdb[7]);
  123. trace_seq_printf(p, "regions=%u", (regions - 8) / 16);
  124. trace_seq_putc(p, 0);
  125. return ret;
  126. }
  127. static const char *
  128. scsi_trace_service_action_in(struct trace_seq *p, unsigned char *cdb, int len)
  129. {
  130. const char *ret = trace_seq_buffer_ptr(p), *cmd;
  131. u64 lba;
  132. u32 alloc_len;
  133. switch (SERVICE_ACTION16(cdb)) {
  134. case SAI_READ_CAPACITY_16:
  135. cmd = "READ_CAPACITY_16";
  136. break;
  137. case SAI_GET_LBA_STATUS:
  138. cmd = "GET_LBA_STATUS";
  139. break;
  140. default:
  141. trace_seq_puts(p, "UNKNOWN");
  142. goto out;
  143. }
  144. lba = get_unaligned_be64(&cdb[2]);
  145. alloc_len = get_unaligned_be32(&cdb[10]);
  146. trace_seq_printf(p, "%s lba=%llu alloc_len=%u", cmd, lba, alloc_len);
  147. out:
  148. trace_seq_putc(p, 0);
  149. return ret;
  150. }
  151. static const char *
  152. scsi_trace_maintenance_in(struct trace_seq *p, unsigned char *cdb, int len)
  153. {
  154. const char *ret = trace_seq_buffer_ptr(p), *cmd;
  155. u32 alloc_len;
  156. switch (SERVICE_ACTION16(cdb)) {
  157. case MI_REPORT_IDENTIFYING_INFORMATION:
  158. cmd = "REPORT_IDENTIFYING_INFORMATION";
  159. break;
  160. case MI_REPORT_TARGET_PGS:
  161. cmd = "REPORT_TARGET_PORT_GROUPS";
  162. break;
  163. case MI_REPORT_ALIASES:
  164. cmd = "REPORT_ALIASES";
  165. break;
  166. case MI_REPORT_SUPPORTED_OPERATION_CODES:
  167. cmd = "REPORT_SUPPORTED_OPERATION_CODES";
  168. break;
  169. case MI_REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS:
  170. cmd = "REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS";
  171. break;
  172. case MI_REPORT_PRIORITY:
  173. cmd = "REPORT_PRIORITY";
  174. break;
  175. case MI_REPORT_TIMESTAMP:
  176. cmd = "REPORT_TIMESTAMP";
  177. break;
  178. case MI_MANAGEMENT_PROTOCOL_IN:
  179. cmd = "MANAGEMENT_PROTOCOL_IN";
  180. break;
  181. default:
  182. trace_seq_puts(p, "UNKNOWN");
  183. goto out;
  184. }
  185. alloc_len = get_unaligned_be32(&cdb[6]);
  186. trace_seq_printf(p, "%s alloc_len=%u", cmd, alloc_len);
  187. out:
  188. trace_seq_putc(p, 0);
  189. return ret;
  190. }
  191. static const char *
  192. scsi_trace_maintenance_out(struct trace_seq *p, unsigned char *cdb, int len)
  193. {
  194. const char *ret = trace_seq_buffer_ptr(p), *cmd;
  195. u32 alloc_len;
  196. switch (SERVICE_ACTION16(cdb)) {
  197. case MO_SET_IDENTIFYING_INFORMATION:
  198. cmd = "SET_IDENTIFYING_INFORMATION";
  199. break;
  200. case MO_SET_TARGET_PGS:
  201. cmd = "SET_TARGET_PORT_GROUPS";
  202. break;
  203. case MO_CHANGE_ALIASES:
  204. cmd = "CHANGE_ALIASES";
  205. break;
  206. case MO_SET_PRIORITY:
  207. cmd = "SET_PRIORITY";
  208. break;
  209. case MO_SET_TIMESTAMP:
  210. cmd = "SET_TIMESTAMP";
  211. break;
  212. case MO_MANAGEMENT_PROTOCOL_OUT:
  213. cmd = "MANAGEMENT_PROTOCOL_OUT";
  214. break;
  215. default:
  216. trace_seq_puts(p, "UNKNOWN");
  217. goto out;
  218. }
  219. alloc_len = get_unaligned_be32(&cdb[6]);
  220. trace_seq_printf(p, "%s alloc_len=%u", cmd, alloc_len);
  221. out:
  222. trace_seq_putc(p, 0);
  223. return ret;
  224. }
  225. static const char *
  226. scsi_trace_zbc_in(struct trace_seq *p, unsigned char *cdb, int len)
  227. {
  228. const char *ret = trace_seq_buffer_ptr(p), *cmd;
  229. u64 zone_id;
  230. u32 alloc_len;
  231. u8 options;
  232. switch (SERVICE_ACTION16(cdb)) {
  233. case ZI_REPORT_ZONES:
  234. cmd = "REPORT_ZONES";
  235. break;
  236. default:
  237. trace_seq_puts(p, "UNKNOWN");
  238. goto out;
  239. }
  240. zone_id = get_unaligned_be64(&cdb[2]);
  241. alloc_len = get_unaligned_be32(&cdb[10]);
  242. options = cdb[14] & 0x3f;
  243. trace_seq_printf(p, "%s zone=%llu alloc_len=%u options=%u partial=%u",
  244. cmd, (unsigned long long)zone_id, alloc_len,
  245. options, (cdb[14] >> 7) & 1);
  246. out:
  247. trace_seq_putc(p, 0);
  248. return ret;
  249. }
  250. static const char *
  251. scsi_trace_zbc_out(struct trace_seq *p, unsigned char *cdb, int len)
  252. {
  253. const char *ret = trace_seq_buffer_ptr(p), *cmd;
  254. u64 zone_id;
  255. switch (SERVICE_ACTION16(cdb)) {
  256. case ZO_CLOSE_ZONE:
  257. cmd = "CLOSE_ZONE";
  258. break;
  259. case ZO_FINISH_ZONE:
  260. cmd = "FINISH_ZONE";
  261. break;
  262. case ZO_OPEN_ZONE:
  263. cmd = "OPEN_ZONE";
  264. break;
  265. case ZO_RESET_WRITE_POINTER:
  266. cmd = "RESET_WRITE_POINTER";
  267. break;
  268. default:
  269. trace_seq_puts(p, "UNKNOWN");
  270. goto out;
  271. }
  272. zone_id = get_unaligned_be64(&cdb[2]);
  273. trace_seq_printf(p, "%s zone=%llu all=%u", cmd,
  274. (unsigned long long)zone_id, cdb[14] & 1);
  275. out:
  276. trace_seq_putc(p, 0);
  277. return ret;
  278. }
  279. static const char *
  280. scsi_trace_varlen(struct trace_seq *p, unsigned char *cdb, int len)
  281. {
  282. switch (SERVICE_ACTION32(cdb)) {
  283. case READ_32:
  284. case VERIFY_32:
  285. case WRITE_32:
  286. case WRITE_SAME_32:
  287. return scsi_trace_rw32(p, cdb, len);
  288. default:
  289. return scsi_trace_misc(p, cdb, len);
  290. }
  291. }
  292. static const char *
  293. scsi_trace_misc(struct trace_seq *p, unsigned char *cdb, int len)
  294. {
  295. const char *ret = trace_seq_buffer_ptr(p);
  296. trace_seq_putc(p, '-');
  297. trace_seq_putc(p, 0);
  298. return ret;
  299. }
  300. const char *
  301. scsi_trace_parse_cdb(struct trace_seq *p, unsigned char *cdb, int len)
  302. {
  303. switch (cdb[0]) {
  304. case READ_6:
  305. case WRITE_6:
  306. return scsi_trace_rw6(p, cdb, len);
  307. case READ_10:
  308. case VERIFY:
  309. case WRITE_10:
  310. case WRITE_SAME:
  311. return scsi_trace_rw10(p, cdb, len);
  312. case READ_12:
  313. case VERIFY_12:
  314. case WRITE_12:
  315. return scsi_trace_rw12(p, cdb, len);
  316. case READ_16:
  317. case VERIFY_16:
  318. case WRITE_16:
  319. case WRITE_SAME_16:
  320. return scsi_trace_rw16(p, cdb, len);
  321. case UNMAP:
  322. return scsi_trace_unmap(p, cdb, len);
  323. case SERVICE_ACTION_IN_16:
  324. return scsi_trace_service_action_in(p, cdb, len);
  325. case VARIABLE_LENGTH_CMD:
  326. return scsi_trace_varlen(p, cdb, len);
  327. case MAINTENANCE_IN:
  328. return scsi_trace_maintenance_in(p, cdb, len);
  329. case MAINTENANCE_OUT:
  330. return scsi_trace_maintenance_out(p, cdb, len);
  331. case ZBC_IN:
  332. return scsi_trace_zbc_in(p, cdb, len);
  333. case ZBC_OUT:
  334. return scsi_trace_zbc_out(p, cdb, len);
  335. default:
  336. return scsi_trace_misc(p, cdb, len);
  337. }
  338. }