scsi_trace.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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 <trace/events/scsi.h>
  21. #define SERVICE_ACTION16(cdb) (cdb[1] & 0x1f)
  22. #define SERVICE_ACTION32(cdb) ((cdb[8] << 8) | cdb[9])
  23. static const char *
  24. scsi_trace_misc(struct trace_seq *, unsigned char *, int);
  25. static const char *
  26. scsi_trace_rw6(struct trace_seq *p, unsigned char *cdb, int len)
  27. {
  28. const char *ret = trace_seq_buffer_ptr(p);
  29. sector_t lba = 0, txlen = 0;
  30. lba |= ((cdb[1] & 0x1F) << 16);
  31. lba |= (cdb[2] << 8);
  32. lba |= cdb[3];
  33. txlen = cdb[4];
  34. trace_seq_printf(p, "lba=%llu txlen=%llu",
  35. (unsigned long long)lba, (unsigned long long)txlen);
  36. trace_seq_putc(p, 0);
  37. return ret;
  38. }
  39. static const char *
  40. scsi_trace_rw10(struct trace_seq *p, unsigned char *cdb, int len)
  41. {
  42. const char *ret = trace_seq_buffer_ptr(p);
  43. sector_t lba = 0, txlen = 0;
  44. lba |= (cdb[2] << 24);
  45. lba |= (cdb[3] << 16);
  46. lba |= (cdb[4] << 8);
  47. lba |= cdb[5];
  48. txlen |= (cdb[7] << 8);
  49. txlen |= cdb[8];
  50. trace_seq_printf(p, "lba=%llu txlen=%llu protect=%u",
  51. (unsigned long long)lba, (unsigned long long)txlen,
  52. cdb[1] >> 5);
  53. if (cdb[0] == WRITE_SAME)
  54. trace_seq_printf(p, " unmap=%u", cdb[1] >> 3 & 1);
  55. trace_seq_putc(p, 0);
  56. return ret;
  57. }
  58. static const char *
  59. scsi_trace_rw12(struct trace_seq *p, unsigned char *cdb, int len)
  60. {
  61. const char *ret = trace_seq_buffer_ptr(p);
  62. sector_t lba = 0, txlen = 0;
  63. lba |= (cdb[2] << 24);
  64. lba |= (cdb[3] << 16);
  65. lba |= (cdb[4] << 8);
  66. lba |= cdb[5];
  67. txlen |= (cdb[6] << 24);
  68. txlen |= (cdb[7] << 16);
  69. txlen |= (cdb[8] << 8);
  70. txlen |= cdb[9];
  71. trace_seq_printf(p, "lba=%llu txlen=%llu protect=%u",
  72. (unsigned long long)lba, (unsigned long long)txlen,
  73. cdb[1] >> 5);
  74. trace_seq_putc(p, 0);
  75. return ret;
  76. }
  77. static const char *
  78. scsi_trace_rw16(struct trace_seq *p, unsigned char *cdb, int len)
  79. {
  80. const char *ret = trace_seq_buffer_ptr(p);
  81. sector_t lba = 0, txlen = 0;
  82. lba |= ((u64)cdb[2] << 56);
  83. lba |= ((u64)cdb[3] << 48);
  84. lba |= ((u64)cdb[4] << 40);
  85. lba |= ((u64)cdb[5] << 32);
  86. lba |= (cdb[6] << 24);
  87. lba |= (cdb[7] << 16);
  88. lba |= (cdb[8] << 8);
  89. lba |= cdb[9];
  90. txlen |= (cdb[10] << 24);
  91. txlen |= (cdb[11] << 16);
  92. txlen |= (cdb[12] << 8);
  93. txlen |= cdb[13];
  94. trace_seq_printf(p, "lba=%llu txlen=%llu protect=%u",
  95. (unsigned long long)lba, (unsigned long long)txlen,
  96. cdb[1] >> 5);
  97. if (cdb[0] == WRITE_SAME_16)
  98. trace_seq_printf(p, " unmap=%u", cdb[1] >> 3 & 1);
  99. trace_seq_putc(p, 0);
  100. return ret;
  101. }
  102. static const char *
  103. scsi_trace_rw32(struct trace_seq *p, unsigned char *cdb, int len)
  104. {
  105. const char *ret = trace_seq_buffer_ptr(p), *cmd;
  106. sector_t lba = 0, txlen = 0;
  107. u32 ei_lbrt = 0;
  108. switch (SERVICE_ACTION32(cdb)) {
  109. case READ_32:
  110. cmd = "READ";
  111. break;
  112. case VERIFY_32:
  113. cmd = "VERIFY";
  114. break;
  115. case WRITE_32:
  116. cmd = "WRITE";
  117. break;
  118. case WRITE_SAME_32:
  119. cmd = "WRITE_SAME";
  120. break;
  121. default:
  122. trace_seq_puts(p, "UNKNOWN");
  123. goto out;
  124. }
  125. lba |= ((u64)cdb[12] << 56);
  126. lba |= ((u64)cdb[13] << 48);
  127. lba |= ((u64)cdb[14] << 40);
  128. lba |= ((u64)cdb[15] << 32);
  129. lba |= (cdb[16] << 24);
  130. lba |= (cdb[17] << 16);
  131. lba |= (cdb[18] << 8);
  132. lba |= cdb[19];
  133. ei_lbrt |= (cdb[20] << 24);
  134. ei_lbrt |= (cdb[21] << 16);
  135. ei_lbrt |= (cdb[22] << 8);
  136. ei_lbrt |= cdb[23];
  137. txlen |= (cdb[28] << 24);
  138. txlen |= (cdb[29] << 16);
  139. txlen |= (cdb[30] << 8);
  140. txlen |= cdb[31];
  141. trace_seq_printf(p, "%s_32 lba=%llu txlen=%llu protect=%u ei_lbrt=%u",
  142. cmd, (unsigned long long)lba,
  143. (unsigned long long)txlen, cdb[10] >> 5, ei_lbrt);
  144. if (SERVICE_ACTION32(cdb) == WRITE_SAME_32)
  145. trace_seq_printf(p, " unmap=%u", cdb[10] >> 3 & 1);
  146. out:
  147. trace_seq_putc(p, 0);
  148. return ret;
  149. }
  150. static const char *
  151. scsi_trace_unmap(struct trace_seq *p, unsigned char *cdb, int len)
  152. {
  153. const char *ret = trace_seq_buffer_ptr(p);
  154. unsigned int regions = cdb[7] << 8 | cdb[8];
  155. trace_seq_printf(p, "regions=%u", (regions - 8) / 16);
  156. trace_seq_putc(p, 0);
  157. return ret;
  158. }
  159. static const char *
  160. scsi_trace_service_action_in(struct trace_seq *p, unsigned char *cdb, int len)
  161. {
  162. const char *ret = trace_seq_buffer_ptr(p), *cmd;
  163. sector_t lba = 0;
  164. u32 alloc_len = 0;
  165. switch (SERVICE_ACTION16(cdb)) {
  166. case SAI_READ_CAPACITY_16:
  167. cmd = "READ_CAPACITY_16";
  168. break;
  169. case SAI_GET_LBA_STATUS:
  170. cmd = "GET_LBA_STATUS";
  171. break;
  172. default:
  173. trace_seq_puts(p, "UNKNOWN");
  174. goto out;
  175. }
  176. lba |= ((u64)cdb[2] << 56);
  177. lba |= ((u64)cdb[3] << 48);
  178. lba |= ((u64)cdb[4] << 40);
  179. lba |= ((u64)cdb[5] << 32);
  180. lba |= (cdb[6] << 24);
  181. lba |= (cdb[7] << 16);
  182. lba |= (cdb[8] << 8);
  183. lba |= cdb[9];
  184. alloc_len |= (cdb[10] << 24);
  185. alloc_len |= (cdb[11] << 16);
  186. alloc_len |= (cdb[12] << 8);
  187. alloc_len |= cdb[13];
  188. trace_seq_printf(p, "%s lba=%llu alloc_len=%u", cmd,
  189. (unsigned long long)lba, alloc_len);
  190. out:
  191. trace_seq_putc(p, 0);
  192. return ret;
  193. }
  194. static const char *
  195. scsi_trace_varlen(struct trace_seq *p, unsigned char *cdb, int len)
  196. {
  197. switch (SERVICE_ACTION32(cdb)) {
  198. case READ_32:
  199. case VERIFY_32:
  200. case WRITE_32:
  201. case WRITE_SAME_32:
  202. return scsi_trace_rw32(p, cdb, len);
  203. default:
  204. return scsi_trace_misc(p, cdb, len);
  205. }
  206. }
  207. static const char *
  208. scsi_trace_misc(struct trace_seq *p, unsigned char *cdb, int len)
  209. {
  210. const char *ret = trace_seq_buffer_ptr(p);
  211. trace_seq_putc(p, '-');
  212. trace_seq_putc(p, 0);
  213. return ret;
  214. }
  215. const char *
  216. scsi_trace_parse_cdb(struct trace_seq *p, unsigned char *cdb, int len)
  217. {
  218. switch (cdb[0]) {
  219. case READ_6:
  220. case WRITE_6:
  221. return scsi_trace_rw6(p, cdb, len);
  222. case READ_10:
  223. case VERIFY:
  224. case WRITE_10:
  225. case WRITE_SAME:
  226. return scsi_trace_rw10(p, cdb, len);
  227. case READ_12:
  228. case VERIFY_12:
  229. case WRITE_12:
  230. return scsi_trace_rw12(p, cdb, len);
  231. case READ_16:
  232. case VERIFY_16:
  233. case WRITE_16:
  234. case WRITE_SAME_16:
  235. return scsi_trace_rw16(p, cdb, len);
  236. case UNMAP:
  237. return scsi_trace_unmap(p, cdb, len);
  238. case SERVICE_ACTION_IN_16:
  239. return scsi_trace_service_action_in(p, cdb, len);
  240. case VARIABLE_LENGTH_CMD:
  241. return scsi_trace_varlen(p, cdb, len);
  242. default:
  243. return scsi_trace_misc(p, cdb, len);
  244. }
  245. }