scsi_trace.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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) ((cdb[8] << 8) | cdb[9])
  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. sector_t lba = 0, txlen = 0;
  31. lba |= ((cdb[1] & 0x1F) << 16);
  32. lba |= (cdb[2] << 8);
  33. lba |= cdb[3];
  34. txlen = cdb[4];
  35. trace_seq_printf(p, "lba=%llu txlen=%llu",
  36. (unsigned long long)lba, (unsigned long long)txlen);
  37. trace_seq_putc(p, 0);
  38. return ret;
  39. }
  40. static const char *
  41. scsi_trace_rw10(struct trace_seq *p, unsigned char *cdb, int len)
  42. {
  43. const char *ret = trace_seq_buffer_ptr(p);
  44. sector_t lba = 0, txlen = 0;
  45. lba |= (cdb[2] << 24);
  46. lba |= (cdb[3] << 16);
  47. lba |= (cdb[4] << 8);
  48. lba |= cdb[5];
  49. txlen |= (cdb[7] << 8);
  50. txlen |= cdb[8];
  51. trace_seq_printf(p, "lba=%llu txlen=%llu protect=%u",
  52. (unsigned long long)lba, (unsigned long long)txlen,
  53. cdb[1] >> 5);
  54. if (cdb[0] == WRITE_SAME)
  55. trace_seq_printf(p, " unmap=%u", cdb[1] >> 3 & 1);
  56. trace_seq_putc(p, 0);
  57. return ret;
  58. }
  59. static const char *
  60. scsi_trace_rw12(struct trace_seq *p, unsigned char *cdb, int len)
  61. {
  62. const char *ret = trace_seq_buffer_ptr(p);
  63. sector_t lba = 0, txlen = 0;
  64. lba |= (cdb[2] << 24);
  65. lba |= (cdb[3] << 16);
  66. lba |= (cdb[4] << 8);
  67. lba |= cdb[5];
  68. txlen |= (cdb[6] << 24);
  69. txlen |= (cdb[7] << 16);
  70. txlen |= (cdb[8] << 8);
  71. txlen |= cdb[9];
  72. trace_seq_printf(p, "lba=%llu txlen=%llu protect=%u",
  73. (unsigned long long)lba, (unsigned long long)txlen,
  74. cdb[1] >> 5);
  75. trace_seq_putc(p, 0);
  76. return ret;
  77. }
  78. static const char *
  79. scsi_trace_rw16(struct trace_seq *p, unsigned char *cdb, int len)
  80. {
  81. const char *ret = trace_seq_buffer_ptr(p);
  82. sector_t lba = 0, txlen = 0;
  83. lba |= ((u64)cdb[2] << 56);
  84. lba |= ((u64)cdb[3] << 48);
  85. lba |= ((u64)cdb[4] << 40);
  86. lba |= ((u64)cdb[5] << 32);
  87. lba |= (cdb[6] << 24);
  88. lba |= (cdb[7] << 16);
  89. lba |= (cdb[8] << 8);
  90. lba |= cdb[9];
  91. txlen |= (cdb[10] << 24);
  92. txlen |= (cdb[11] << 16);
  93. txlen |= (cdb[12] << 8);
  94. txlen |= cdb[13];
  95. trace_seq_printf(p, "lba=%llu txlen=%llu protect=%u",
  96. (unsigned long long)lba, (unsigned long long)txlen,
  97. cdb[1] >> 5);
  98. if (cdb[0] == WRITE_SAME_16)
  99. trace_seq_printf(p, " unmap=%u", cdb[1] >> 3 & 1);
  100. trace_seq_putc(p, 0);
  101. return ret;
  102. }
  103. static const char *
  104. scsi_trace_rw32(struct trace_seq *p, unsigned char *cdb, int len)
  105. {
  106. const char *ret = trace_seq_buffer_ptr(p), *cmd;
  107. sector_t lba = 0, txlen = 0;
  108. u32 ei_lbrt = 0;
  109. switch (SERVICE_ACTION32(cdb)) {
  110. case READ_32:
  111. cmd = "READ";
  112. break;
  113. case VERIFY_32:
  114. cmd = "VERIFY";
  115. break;
  116. case WRITE_32:
  117. cmd = "WRITE";
  118. break;
  119. case WRITE_SAME_32:
  120. cmd = "WRITE_SAME";
  121. break;
  122. default:
  123. trace_seq_puts(p, "UNKNOWN");
  124. goto out;
  125. }
  126. lba |= ((u64)cdb[12] << 56);
  127. lba |= ((u64)cdb[13] << 48);
  128. lba |= ((u64)cdb[14] << 40);
  129. lba |= ((u64)cdb[15] << 32);
  130. lba |= (cdb[16] << 24);
  131. lba |= (cdb[17] << 16);
  132. lba |= (cdb[18] << 8);
  133. lba |= cdb[19];
  134. ei_lbrt |= (cdb[20] << 24);
  135. ei_lbrt |= (cdb[21] << 16);
  136. ei_lbrt |= (cdb[22] << 8);
  137. ei_lbrt |= cdb[23];
  138. txlen |= (cdb[28] << 24);
  139. txlen |= (cdb[29] << 16);
  140. txlen |= (cdb[30] << 8);
  141. txlen |= cdb[31];
  142. trace_seq_printf(p, "%s_32 lba=%llu txlen=%llu protect=%u ei_lbrt=%u",
  143. cmd, (unsigned long long)lba,
  144. (unsigned long long)txlen, cdb[10] >> 5, ei_lbrt);
  145. if (SERVICE_ACTION32(cdb) == WRITE_SAME_32)
  146. trace_seq_printf(p, " unmap=%u", cdb[10] >> 3 & 1);
  147. out:
  148. trace_seq_putc(p, 0);
  149. return ret;
  150. }
  151. static const char *
  152. scsi_trace_unmap(struct trace_seq *p, unsigned char *cdb, int len)
  153. {
  154. const char *ret = trace_seq_buffer_ptr(p);
  155. unsigned int regions = cdb[7] << 8 | cdb[8];
  156. trace_seq_printf(p, "regions=%u", (regions - 8) / 16);
  157. trace_seq_putc(p, 0);
  158. return ret;
  159. }
  160. static const char *
  161. scsi_trace_service_action_in(struct trace_seq *p, unsigned char *cdb, int len)
  162. {
  163. const char *ret = trace_seq_buffer_ptr(p), *cmd;
  164. sector_t lba = 0;
  165. u32 alloc_len = 0;
  166. switch (SERVICE_ACTION16(cdb)) {
  167. case SAI_READ_CAPACITY_16:
  168. cmd = "READ_CAPACITY_16";
  169. break;
  170. case SAI_GET_LBA_STATUS:
  171. cmd = "GET_LBA_STATUS";
  172. break;
  173. default:
  174. trace_seq_puts(p, "UNKNOWN");
  175. goto out;
  176. }
  177. lba |= ((u64)cdb[2] << 56);
  178. lba |= ((u64)cdb[3] << 48);
  179. lba |= ((u64)cdb[4] << 40);
  180. lba |= ((u64)cdb[5] << 32);
  181. lba |= (cdb[6] << 24);
  182. lba |= (cdb[7] << 16);
  183. lba |= (cdb[8] << 8);
  184. lba |= cdb[9];
  185. alloc_len |= (cdb[10] << 24);
  186. alloc_len |= (cdb[11] << 16);
  187. alloc_len |= (cdb[12] << 8);
  188. alloc_len |= cdb[13];
  189. trace_seq_printf(p, "%s lba=%llu alloc_len=%u", cmd,
  190. (unsigned long long)lba, alloc_len);
  191. out:
  192. trace_seq_putc(p, 0);
  193. return ret;
  194. }
  195. static const char *
  196. scsi_trace_maintenance_in(struct trace_seq *p, unsigned char *cdb, int len)
  197. {
  198. const char *ret = trace_seq_buffer_ptr(p), *cmd;
  199. u32 alloc_len;
  200. switch (SERVICE_ACTION16(cdb)) {
  201. case MI_REPORT_IDENTIFYING_INFORMATION:
  202. cmd = "REPORT_IDENTIFYING_INFORMATION";
  203. break;
  204. case MI_REPORT_TARGET_PGS:
  205. cmd = "REPORT_TARGET_PORT_GROUPS";
  206. break;
  207. case MI_REPORT_ALIASES:
  208. cmd = "REPORT_ALIASES";
  209. break;
  210. case MI_REPORT_SUPPORTED_OPERATION_CODES:
  211. cmd = "REPORT_SUPPORTED_OPERATION_CODES";
  212. break;
  213. case MI_REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS:
  214. cmd = "REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS";
  215. break;
  216. case MI_REPORT_PRIORITY:
  217. cmd = "REPORT_PRIORITY";
  218. break;
  219. case MI_REPORT_TIMESTAMP:
  220. cmd = "REPORT_TIMESTAMP";
  221. break;
  222. case MI_MANAGEMENT_PROTOCOL_IN:
  223. cmd = "MANAGEMENT_PROTOCOL_IN";
  224. break;
  225. default:
  226. trace_seq_puts(p, "UNKNOWN");
  227. goto out;
  228. }
  229. alloc_len = get_unaligned_be32(&cdb[6]);
  230. trace_seq_printf(p, "%s alloc_len=%u", cmd, alloc_len);
  231. out:
  232. trace_seq_putc(p, 0);
  233. return ret;
  234. }
  235. static const char *
  236. scsi_trace_maintenance_out(struct trace_seq *p, unsigned char *cdb, int len)
  237. {
  238. const char *ret = trace_seq_buffer_ptr(p), *cmd;
  239. u32 alloc_len;
  240. switch (SERVICE_ACTION16(cdb)) {
  241. case MO_SET_IDENTIFYING_INFORMATION:
  242. cmd = "SET_IDENTIFYING_INFORMATION";
  243. break;
  244. case MO_SET_TARGET_PGS:
  245. cmd = "SET_TARGET_PORT_GROUPS";
  246. break;
  247. case MO_CHANGE_ALIASES:
  248. cmd = "CHANGE_ALIASES";
  249. break;
  250. case MO_SET_PRIORITY:
  251. cmd = "SET_PRIORITY";
  252. break;
  253. case MO_SET_TIMESTAMP:
  254. cmd = "SET_TIMESTAMP";
  255. break;
  256. case MO_MANAGEMENT_PROTOCOL_OUT:
  257. cmd = "MANAGEMENT_PROTOCOL_OUT";
  258. break;
  259. default:
  260. trace_seq_puts(p, "UNKNOWN");
  261. goto out;
  262. }
  263. alloc_len = get_unaligned_be32(&cdb[6]);
  264. trace_seq_printf(p, "%s alloc_len=%u", cmd, alloc_len);
  265. out:
  266. trace_seq_putc(p, 0);
  267. return ret;
  268. }
  269. static const char *
  270. scsi_trace_zbc_in(struct trace_seq *p, unsigned char *cdb, int len)
  271. {
  272. const char *ret = trace_seq_buffer_ptr(p), *cmd;
  273. u64 zone_id;
  274. u32 alloc_len;
  275. u8 options;
  276. switch (SERVICE_ACTION16(cdb)) {
  277. case ZI_REPORT_ZONES:
  278. cmd = "REPORT_ZONES";
  279. break;
  280. default:
  281. trace_seq_puts(p, "UNKNOWN");
  282. goto out;
  283. }
  284. zone_id = get_unaligned_be64(&cdb[2]);
  285. alloc_len = get_unaligned_be32(&cdb[10]);
  286. options = cdb[14] & 0x3f;
  287. trace_seq_printf(p, "%s zone=%llu alloc_len=%u options=%u partial=%u",
  288. cmd, (unsigned long long)zone_id, alloc_len,
  289. options, (cdb[14] >> 7) & 1);
  290. out:
  291. trace_seq_putc(p, 0);
  292. return ret;
  293. }
  294. static const char *
  295. scsi_trace_zbc_out(struct trace_seq *p, unsigned char *cdb, int len)
  296. {
  297. const char *ret = trace_seq_buffer_ptr(p), *cmd;
  298. u64 zone_id;
  299. switch (SERVICE_ACTION16(cdb)) {
  300. case ZO_CLOSE_ZONE:
  301. cmd = "CLOSE_ZONE";
  302. break;
  303. case ZO_FINISH_ZONE:
  304. cmd = "FINISH_ZONE";
  305. break;
  306. case ZO_OPEN_ZONE:
  307. cmd = "OPEN_ZONE";
  308. break;
  309. case ZO_RESET_WRITE_POINTER:
  310. cmd = "RESET_WRITE_POINTER";
  311. break;
  312. default:
  313. trace_seq_puts(p, "UNKNOWN");
  314. goto out;
  315. }
  316. zone_id = get_unaligned_be64(&cdb[2]);
  317. trace_seq_printf(p, "%s zone=%llu all=%u", cmd,
  318. (unsigned long long)zone_id, cdb[14] & 1);
  319. out:
  320. trace_seq_putc(p, 0);
  321. return ret;
  322. }
  323. static const char *
  324. scsi_trace_varlen(struct trace_seq *p, unsigned char *cdb, int len)
  325. {
  326. switch (SERVICE_ACTION32(cdb)) {
  327. case READ_32:
  328. case VERIFY_32:
  329. case WRITE_32:
  330. case WRITE_SAME_32:
  331. return scsi_trace_rw32(p, cdb, len);
  332. default:
  333. return scsi_trace_misc(p, cdb, len);
  334. }
  335. }
  336. static const char *
  337. scsi_trace_misc(struct trace_seq *p, unsigned char *cdb, int len)
  338. {
  339. const char *ret = trace_seq_buffer_ptr(p);
  340. trace_seq_putc(p, '-');
  341. trace_seq_putc(p, 0);
  342. return ret;
  343. }
  344. const char *
  345. scsi_trace_parse_cdb(struct trace_seq *p, unsigned char *cdb, int len)
  346. {
  347. switch (cdb[0]) {
  348. case READ_6:
  349. case WRITE_6:
  350. return scsi_trace_rw6(p, cdb, len);
  351. case READ_10:
  352. case VERIFY:
  353. case WRITE_10:
  354. case WRITE_SAME:
  355. return scsi_trace_rw10(p, cdb, len);
  356. case READ_12:
  357. case VERIFY_12:
  358. case WRITE_12:
  359. return scsi_trace_rw12(p, cdb, len);
  360. case READ_16:
  361. case VERIFY_16:
  362. case WRITE_16:
  363. case WRITE_SAME_16:
  364. return scsi_trace_rw16(p, cdb, len);
  365. case UNMAP:
  366. return scsi_trace_unmap(p, cdb, len);
  367. case SERVICE_ACTION_IN_16:
  368. return scsi_trace_service_action_in(p, cdb, len);
  369. case VARIABLE_LENGTH_CMD:
  370. return scsi_trace_varlen(p, cdb, len);
  371. case MAINTENANCE_IN:
  372. return scsi_trace_maintenance_in(p, cdb, len);
  373. case MAINTENANCE_OUT:
  374. return scsi_trace_maintenance_out(p, cdb, len);
  375. case ZBC_IN:
  376. return scsi_trace_zbc_in(p, cdb, len);
  377. case ZBC_OUT:
  378. return scsi_trace_zbc_out(p, cdb, len);
  379. default:
  380. return scsi_trace_misc(p, cdb, len);
  381. }
  382. }