1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * NVM Express device driver tracepoints 4 * Copyright (c) 2018 Johannes Thumshirn, SUSE Linux GmbH 5 */ 6 7 #include <linux/unaligned.h> 8 #include "trace.h" 9 10 static const char *nvme_trace_delete_sq(struct trace_seq *p, u8 *cdw10) 11 { 12 const char *ret = trace_seq_buffer_ptr(p); 13 u16 sqid = get_unaligned_le16(cdw10); 14 15 trace_seq_printf(p, "sqid=%u", sqid); 16 trace_seq_putc(p, 0); 17 18 return ret; 19 } 20 21 static const char *nvme_trace_create_sq(struct trace_seq *p, u8 *cdw10) 22 { 23 const char *ret = trace_seq_buffer_ptr(p); 24 u16 sqid = get_unaligned_le16(cdw10); 25 u16 qsize = get_unaligned_le16(cdw10 + 2); 26 u16 sq_flags = get_unaligned_le16(cdw10 + 4); 27 u16 cqid = get_unaligned_le16(cdw10 + 6); 28 29 30 trace_seq_printf(p, "sqid=%u, qsize=%u, sq_flags=0x%x, cqid=%u", 31 sqid, qsize, sq_flags, cqid); 32 trace_seq_putc(p, 0); 33 34 return ret; 35 } 36 37 static const char *nvme_trace_delete_cq(struct trace_seq *p, u8 *cdw10) 38 { 39 const char *ret = trace_seq_buffer_ptr(p); 40 u16 cqid = get_unaligned_le16(cdw10); 41 42 trace_seq_printf(p, "cqid=%u", cqid); 43 trace_seq_putc(p, 0); 44 45 return ret; 46 } 47 48 static const char *nvme_trace_create_cq(struct trace_seq *p, u8 *cdw10) 49 { 50 const char *ret = trace_seq_buffer_ptr(p); 51 u16 cqid = get_unaligned_le16(cdw10); 52 u16 qsize = get_unaligned_le16(cdw10 + 2); 53 u16 cq_flags = get_unaligned_le16(cdw10 + 4); 54 u16 irq_vector = get_unaligned_le16(cdw10 + 6); 55 56 trace_seq_printf(p, "cqid=%u, qsize=%u, cq_flags=0x%x, irq_vector=%u", 57 cqid, qsize, cq_flags, irq_vector); 58 trace_seq_putc(p, 0); 59 60 return ret; 61 } 62 63 static const char *nvme_trace_admin_identify(struct trace_seq *p, u8 *cdw10) 64 { 65 const char *ret = trace_seq_buffer_ptr(p); 66 u8 cns = cdw10[0]; 67 u16 ctrlid = get_unaligned_le16(cdw10 + 2); 68 69 trace_seq_printf(p, "cns=%u, ctrlid=%u", cns, ctrlid); 70 trace_seq_putc(p, 0); 71 72 return ret; 73 } 74 75 static const char *nvme_trace_admin_set_features(struct trace_seq *p, 76 u8 *cdw10) 77 { 78 const char *ret = trace_seq_buffer_ptr(p); 79 u8 fid = cdw10[0]; 80 u8 sv = cdw10[3] & 0x8; 81 u32 cdw11 = get_unaligned_le32(cdw10 + 4); 82 83 trace_seq_printf(p, "fid=0x%x, sv=0x%x, cdw11=0x%x", fid, sv, cdw11); 84 trace_seq_putc(p, 0); 85 86 return ret; 87 } 88 89 static const char *nvme_trace_admin_get_features(struct trace_seq *p, 90 u8 *cdw10) 91 { 92 const char *ret = trace_seq_buffer_ptr(p); 93 u8 fid = cdw10[0]; 94 u8 sel = cdw10[1] & 0x7; 95 u32 cdw11 = get_unaligned_le32(cdw10 + 4); 96 97 trace_seq_printf(p, "fid=0x%x, sel=0x%x, cdw11=0x%x", fid, sel, cdw11); 98 trace_seq_putc(p, 0); 99 100 return ret; 101 } 102 103 static const char *nvme_trace_get_lba_status(struct trace_seq *p, 104 u8 *cdw10) 105 { 106 const char *ret = trace_seq_buffer_ptr(p); 107 u64 slba = get_unaligned_le64(cdw10); 108 u32 mndw = get_unaligned_le32(cdw10 + 8); 109 u16 rl = get_unaligned_le16(cdw10 + 12); 110 u8 atype = cdw10[15]; 111 112 trace_seq_printf(p, "slba=0x%llx, mndw=0x%x, rl=0x%x, atype=%u", 113 slba, mndw, rl, atype); 114 trace_seq_putc(p, 0); 115 116 return ret; 117 } 118 119 static const char *nvme_trace_admin_format_nvm(struct trace_seq *p, u8 *cdw10) 120 { 121 const char *ret = trace_seq_buffer_ptr(p); 122 /* 123 * lbafu(bit 13:12) is already in the upper 4 bits, lbafl: bit 03:00. 124 */ 125 u8 lbaf = (cdw10[1] & 0x30) | (cdw10[0] & 0xF); 126 u8 mset = (cdw10[0] >> 4) & 0x1; 127 u8 pi = (cdw10[0] >> 5) & 0x7; 128 u8 pil = cdw10[1] & 0x1; 129 u8 ses = (cdw10[1] >> 1) & 0x7; 130 131 trace_seq_printf(p, "lbaf=%u, mset=%u, pi=%u, pil=%u, ses=%u", 132 lbaf, mset, pi, pil, ses); 133 134 trace_seq_putc(p, 0); 135 136 return ret; 137 } 138 139 static const char *nvme_trace_read_write(struct trace_seq *p, u8 *cdw10) 140 { 141 const char *ret = trace_seq_buffer_ptr(p); 142 u64 slba = get_unaligned_le64(cdw10); 143 u16 length = get_unaligned_le16(cdw10 + 8); 144 u16 control = get_unaligned_le16(cdw10 + 10); 145 u32 dsmgmt = get_unaligned_le32(cdw10 + 12); 146 u32 reftag = get_unaligned_le32(cdw10 + 16); 147 148 trace_seq_printf(p, 149 "slba=%llu, len=%u, ctrl=0x%x, dsmgmt=%u, reftag=%u", 150 slba, length, control, dsmgmt, reftag); 151 trace_seq_putc(p, 0); 152 153 return ret; 154 } 155 156 static const char *nvme_trace_dsm(struct trace_seq *p, u8 *cdw10) 157 { 158 const char *ret = trace_seq_buffer_ptr(p); 159 160 trace_seq_printf(p, "nr=%u, attributes=%u", 161 get_unaligned_le32(cdw10), 162 get_unaligned_le32(cdw10 + 4)); 163 trace_seq_putc(p, 0); 164 165 return ret; 166 } 167 168 static const char *nvme_trace_zone_mgmt_send(struct trace_seq *p, u8 *cdw10) 169 { 170 static const char * const zsa_strs[] = { 171 [0x01] = "close zone", 172 [0x02] = "finish zone", 173 [0x03] = "open zone", 174 [0x04] = "reset zone", 175 [0x05] = "offline zone", 176 [0x10] = "set zone descriptor extension" 177 }; 178 const char *ret = trace_seq_buffer_ptr(p); 179 u64 slba = get_unaligned_le64(cdw10); 180 const char *zsa_str; 181 u8 zsa = cdw10[12]; 182 u8 all = cdw10[13]; 183 184 if (zsa < ARRAY_SIZE(zsa_strs) && zsa_strs[zsa]) 185 zsa_str = zsa_strs[zsa]; 186 else 187 zsa_str = "reserved"; 188 189 trace_seq_printf(p, "slba=%llu, zsa=%u:%s, all=%u", 190 slba, zsa, zsa_str, all); 191 trace_seq_putc(p, 0); 192 193 return ret; 194 } 195 196 static const char *nvme_trace_zone_mgmt_recv(struct trace_seq *p, u8 *cdw10) 197 { 198 static const char * const zrasf_strs[] = { 199 [0x00] = "list all zones", 200 [0x01] = "list the zones in the ZSE: Empty state", 201 [0x02] = "list the zones in the ZSIO: Implicitly Opened state", 202 [0x03] = "list the zones in the ZSEO: Explicitly Opened state", 203 [0x04] = "list the zones in the ZSC: Closed state", 204 [0x05] = "list the zones in the ZSF: Full state", 205 [0x06] = "list the zones in the ZSRO: Read Only state", 206 [0x07] = "list the zones in the ZSO: Offline state", 207 [0x09] = "list the zones that have the zone attribute" 208 }; 209 const char *ret = trace_seq_buffer_ptr(p); 210 u64 slba = get_unaligned_le64(cdw10); 211 u32 numd = get_unaligned_le32(cdw10 + 8); 212 u8 zra = cdw10[12]; 213 u8 zrasf = cdw10[13]; 214 const char *zrasf_str; 215 u8 pr = cdw10[14]; 216 217 if (zrasf < ARRAY_SIZE(zrasf_strs) && zrasf_strs[zrasf]) 218 zrasf_str = zrasf_strs[zrasf]; 219 else 220 zrasf_str = "reserved"; 221 222 trace_seq_printf(p, "slba=%llu, numd=%u, zra=%u, zrasf=%u:%s, pr=%u", 223 slba, numd, zra, zrasf, zrasf_str, pr); 224 trace_seq_putc(p, 0); 225 226 return ret; 227 } 228 229 static const char *nvme_trace_resv_reg(struct trace_seq *p, u8 *cdw10) 230 { 231 static const char * const rrega_strs[] = { 232 [0x00] = "register", 233 [0x01] = "unregister", 234 [0x02] = "replace", 235 }; 236 const char *ret = trace_seq_buffer_ptr(p); 237 u8 rrega = cdw10[0] & 0x7; 238 u8 iekey = (cdw10[0] >> 3) & 0x1; 239 u8 ptpl = (cdw10[3] >> 6) & 0x3; 240 const char *rrega_str; 241 242 if (rrega < ARRAY_SIZE(rrega_strs) && rrega_strs[rrega]) 243 rrega_str = rrega_strs[rrega]; 244 else 245 rrega_str = "reserved"; 246 247 trace_seq_printf(p, "rrega=%u:%s, iekey=%u, ptpl=%u", 248 rrega, rrega_str, iekey, ptpl); 249 trace_seq_putc(p, 0); 250 251 return ret; 252 } 253 254 static const char * const rtype_strs[] = { 255 [0x00] = "reserved", 256 [0x01] = "write exclusive", 257 [0x02] = "exclusive access", 258 [0x03] = "write exclusive registrants only", 259 [0x04] = "exclusive access registrants only", 260 [0x05] = "write exclusive all registrants", 261 [0x06] = "exclusive access all registrants", 262 }; 263 264 static const char *nvme_trace_resv_acq(struct trace_seq *p, u8 *cdw10) 265 { 266 static const char * const racqa_strs[] = { 267 [0x00] = "acquire", 268 [0x01] = "preempt", 269 [0x02] = "preempt and abort", 270 }; 271 const char *ret = trace_seq_buffer_ptr(p); 272 u8 racqa = cdw10[0] & 0x7; 273 u8 iekey = (cdw10[0] >> 3) & 0x1; 274 u8 rtype = cdw10[1]; 275 const char *racqa_str = "reserved"; 276 const char *rtype_str = "reserved"; 277 278 if (racqa < ARRAY_SIZE(racqa_strs) && racqa_strs[racqa]) 279 racqa_str = racqa_strs[racqa]; 280 281 if (rtype < ARRAY_SIZE(rtype_strs) && rtype_strs[rtype]) 282 rtype_str = rtype_strs[rtype]; 283 284 trace_seq_printf(p, "racqa=%u:%s, iekey=%u, rtype=%u:%s", 285 racqa, racqa_str, iekey, rtype, rtype_str); 286 trace_seq_putc(p, 0); 287 288 return ret; 289 } 290 291 static const char *nvme_trace_resv_rel(struct trace_seq *p, u8 *cdw10) 292 { 293 static const char * const rrela_strs[] = { 294 [0x00] = "release", 295 [0x01] = "clear", 296 }; 297 const char *ret = trace_seq_buffer_ptr(p); 298 u8 rrela = cdw10[0] & 0x7; 299 u8 iekey = (cdw10[0] >> 3) & 0x1; 300 u8 rtype = cdw10[1]; 301 const char *rrela_str = "reserved"; 302 const char *rtype_str = "reserved"; 303 304 if (rrela < ARRAY_SIZE(rrela_strs) && rrela_strs[rrela]) 305 rrela_str = rrela_strs[rrela]; 306 307 if (rtype < ARRAY_SIZE(rtype_strs) && rtype_strs[rtype]) 308 rtype_str = rtype_strs[rtype]; 309 310 trace_seq_printf(p, "rrela=%u:%s, iekey=%u, rtype=%u:%s", 311 rrela, rrela_str, iekey, rtype, rtype_str); 312 trace_seq_putc(p, 0); 313 314 return ret; 315 } 316 317 static const char *nvme_trace_resv_report(struct trace_seq *p, u8 *cdw10) 318 { 319 const char *ret = trace_seq_buffer_ptr(p); 320 u32 numd = get_unaligned_le32(cdw10); 321 u8 eds = cdw10[4] & 0x1; 322 323 trace_seq_printf(p, "numd=%u, eds=%u", numd, eds); 324 trace_seq_putc(p, 0); 325 326 return ret; 327 } 328 329 static const char *nvme_trace_common(struct trace_seq *p, u8 *cdw10) 330 { 331 const char *ret = trace_seq_buffer_ptr(p); 332 333 trace_seq_printf(p, "cdw10=%*ph", 24, cdw10); 334 trace_seq_putc(p, 0); 335 336 return ret; 337 } 338 339 const char *nvme_trace_parse_admin_cmd(struct trace_seq *p, 340 u8 opcode, u8 *cdw10) 341 { 342 switch (opcode) { 343 case nvme_admin_delete_sq: 344 return nvme_trace_delete_sq(p, cdw10); 345 case nvme_admin_create_sq: 346 return nvme_trace_create_sq(p, cdw10); 347 case nvme_admin_delete_cq: 348 return nvme_trace_delete_cq(p, cdw10); 349 case nvme_admin_create_cq: 350 return nvme_trace_create_cq(p, cdw10); 351 case nvme_admin_identify: 352 return nvme_trace_admin_identify(p, cdw10); 353 case nvme_admin_set_features: 354 return nvme_trace_admin_set_features(p, cdw10); 355 case nvme_admin_get_features: 356 return nvme_trace_admin_get_features(p, cdw10); 357 case nvme_admin_get_lba_status: 358 return nvme_trace_get_lba_status(p, cdw10); 359 case nvme_admin_format_nvm: 360 return nvme_trace_admin_format_nvm(p, cdw10); 361 default: 362 return nvme_trace_common(p, cdw10); 363 } 364 } 365 366 const char *nvme_trace_parse_nvm_cmd(struct trace_seq *p, 367 u8 opcode, u8 *cdw10) 368 { 369 switch (opcode) { 370 case nvme_cmd_read: 371 case nvme_cmd_write: 372 case nvme_cmd_write_zeroes: 373 case nvme_cmd_zone_append: 374 return nvme_trace_read_write(p, cdw10); 375 case nvme_cmd_dsm: 376 return nvme_trace_dsm(p, cdw10); 377 case nvme_cmd_zone_mgmt_send: 378 return nvme_trace_zone_mgmt_send(p, cdw10); 379 case nvme_cmd_zone_mgmt_recv: 380 return nvme_trace_zone_mgmt_recv(p, cdw10); 381 case nvme_cmd_resv_register: 382 return nvme_trace_resv_reg(p, cdw10); 383 case nvme_cmd_resv_acquire: 384 return nvme_trace_resv_acq(p, cdw10); 385 case nvme_cmd_resv_release: 386 return nvme_trace_resv_rel(p, cdw10); 387 case nvme_cmd_resv_report: 388 return nvme_trace_resv_report(p, cdw10); 389 default: 390 return nvme_trace_common(p, cdw10); 391 } 392 } 393 394 static const char *nvme_trace_fabrics_property_set(struct trace_seq *p, u8 *spc) 395 { 396 const char *ret = trace_seq_buffer_ptr(p); 397 u8 attrib = spc[0]; 398 u32 ofst = get_unaligned_le32(spc + 4); 399 u64 value = get_unaligned_le64(spc + 8); 400 401 trace_seq_printf(p, "attrib=%u, ofst=0x%x, value=0x%llx", 402 attrib, ofst, value); 403 trace_seq_putc(p, 0); 404 return ret; 405 } 406 407 static const char *nvme_trace_fabrics_connect(struct trace_seq *p, u8 *spc) 408 { 409 const char *ret = trace_seq_buffer_ptr(p); 410 u16 recfmt = get_unaligned_le16(spc); 411 u16 qid = get_unaligned_le16(spc + 2); 412 u16 sqsize = get_unaligned_le16(spc + 4); 413 u8 cattr = spc[6]; 414 u32 kato = get_unaligned_le32(spc + 8); 415 416 trace_seq_printf(p, "recfmt=%u, qid=%u, sqsize=%u, cattr=%u, kato=%u", 417 recfmt, qid, sqsize, cattr, kato); 418 trace_seq_putc(p, 0); 419 return ret; 420 } 421 422 static const char *nvme_trace_fabrics_property_get(struct trace_seq *p, u8 *spc) 423 { 424 const char *ret = trace_seq_buffer_ptr(p); 425 u8 attrib = spc[0]; 426 u32 ofst = get_unaligned_le32(spc + 4); 427 428 trace_seq_printf(p, "attrib=%u, ofst=0x%x", attrib, ofst); 429 trace_seq_putc(p, 0); 430 return ret; 431 } 432 433 static const char *nvme_trace_fabrics_auth_send(struct trace_seq *p, u8 *spc) 434 { 435 const char *ret = trace_seq_buffer_ptr(p); 436 u8 spsp0 = spc[1]; 437 u8 spsp1 = spc[2]; 438 u8 secp = spc[3]; 439 u32 tl = get_unaligned_le32(spc + 4); 440 441 trace_seq_printf(p, "spsp0=%02x, spsp1=%02x, secp=%02x, tl=%u", 442 spsp0, spsp1, secp, tl); 443 trace_seq_putc(p, 0); 444 return ret; 445 } 446 447 static const char *nvme_trace_fabrics_auth_receive(struct trace_seq *p, u8 *spc) 448 { 449 const char *ret = trace_seq_buffer_ptr(p); 450 u8 spsp0 = spc[1]; 451 u8 spsp1 = spc[2]; 452 u8 secp = spc[3]; 453 u32 al = get_unaligned_le32(spc + 4); 454 455 trace_seq_printf(p, "spsp0=%02x, spsp1=%02x, secp=%02x, al=%u", 456 spsp0, spsp1, secp, al); 457 trace_seq_putc(p, 0); 458 return ret; 459 } 460 461 static const char *nvme_trace_fabrics_common(struct trace_seq *p, u8 *spc) 462 { 463 const char *ret = trace_seq_buffer_ptr(p); 464 465 trace_seq_printf(p, "specific=%*ph", 24, spc); 466 trace_seq_putc(p, 0); 467 return ret; 468 } 469 470 const char *nvme_trace_parse_fabrics_cmd(struct trace_seq *p, 471 u8 fctype, u8 *spc) 472 { 473 switch (fctype) { 474 case nvme_fabrics_type_property_set: 475 return nvme_trace_fabrics_property_set(p, spc); 476 case nvme_fabrics_type_connect: 477 return nvme_trace_fabrics_connect(p, spc); 478 case nvme_fabrics_type_property_get: 479 return nvme_trace_fabrics_property_get(p, spc); 480 case nvme_fabrics_type_auth_send: 481 return nvme_trace_fabrics_auth_send(p, spc); 482 case nvme_fabrics_type_auth_receive: 483 return nvme_trace_fabrics_auth_receive(p, spc); 484 default: 485 return nvme_trace_fabrics_common(p, spc); 486 } 487 } 488 489 const char *nvme_trace_disk_name(struct trace_seq *p, char *name) 490 { 491 const char *ret = trace_seq_buffer_ptr(p); 492 493 if (*name) 494 trace_seq_printf(p, "disk=%s, ", name); 495 trace_seq_putc(p, 0); 496 497 return ret; 498 } 499 500 EXPORT_TRACEPOINT_SYMBOL_GPL(nvme_sq); 501