1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * NVM Express target device driver tracepoints 4 * Copyright (c) 2018 Johannes Thumshirn, SUSE Linux GmbH 5 * 6 * This is entirely based on drivers/nvme/host/trace.h 7 */ 8 9 #undef TRACE_SYSTEM 10 #define TRACE_SYSTEM nvmet 11 12 #if !defined(_TRACE_NVMET_H) || defined(TRACE_HEADER_MULTI_READ) 13 #define _TRACE_NVMET_H 14 15 #include <linux/nvme.h> 16 #include <linux/tracepoint.h> 17 #include <linux/trace_seq.h> 18 19 #include "nvmet.h" 20 21 const char *nvmet_trace_parse_admin_cmd(struct trace_seq *p, u8 opcode, 22 u8 *cdw10); 23 const char *nvmet_trace_parse_nvm_cmd(struct trace_seq *p, u8 opcode, 24 u8 *cdw10); 25 const char *nvmet_trace_parse_fabrics_cmd(struct trace_seq *p, u8 fctype, 26 u8 *spc); 27 28 #define parse_nvme_cmd(qid, opcode, fctype, cdw10) \ 29 ((opcode) == nvme_fabrics_command ? \ 30 nvmet_trace_parse_fabrics_cmd(p, fctype, cdw10) : \ 31 (qid ? \ 32 nvmet_trace_parse_nvm_cmd(p, opcode, cdw10) : \ 33 nvmet_trace_parse_admin_cmd(p, opcode, cdw10))) 34 35 const char *nvmet_trace_ctrl_name(struct trace_seq *p, struct nvmet_ctrl *ctrl); 36 #define __print_ctrl_name(ctrl) \ 37 nvmet_trace_ctrl_name(p, ctrl) 38 39 const char *nvmet_trace_disk_name(struct trace_seq *p, char *name); 40 #define __print_disk_name(name) \ 41 nvmet_trace_disk_name(p, name) 42 43 #ifndef TRACE_HEADER_MULTI_READ 44 static inline struct nvmet_ctrl *nvmet_req_to_ctrl(struct nvmet_req *req) 45 { 46 return req->sq->ctrl; 47 } 48 49 static inline void __assign_req_name(char *name, struct nvmet_req *req) 50 { 51 if (!req->ns) { 52 memset(name, 0, DISK_NAME_LEN); 53 return; 54 } 55 56 strncpy(name, req->ns->device_path, 57 min_t(size_t, DISK_NAME_LEN, strlen(req->ns->device_path))); 58 } 59 #endif 60 61 TRACE_EVENT(nvmet_req_init, 62 TP_PROTO(struct nvmet_req *req, struct nvme_command *cmd), 63 TP_ARGS(req, cmd), 64 TP_STRUCT__entry( 65 __field(struct nvme_command *, cmd) 66 __field(struct nvmet_ctrl *, ctrl) 67 __array(char, disk, DISK_NAME_LEN) 68 __field(int, qid) 69 __field(u16, cid) 70 __field(u8, opcode) 71 __field(u8, fctype) 72 __field(u8, flags) 73 __field(u32, nsid) 74 __field(u64, metadata) 75 __array(u8, cdw10, 24) 76 ), 77 TP_fast_assign( 78 __entry->cmd = cmd; 79 __entry->ctrl = nvmet_req_to_ctrl(req); 80 __assign_req_name(__entry->disk, req); 81 __entry->qid = req->sq->qid; 82 __entry->cid = cmd->common.command_id; 83 __entry->opcode = cmd->common.opcode; 84 __entry->fctype = cmd->fabrics.fctype; 85 __entry->flags = cmd->common.flags; 86 __entry->nsid = le32_to_cpu(cmd->common.nsid); 87 __entry->metadata = le64_to_cpu(cmd->common.metadata); 88 memcpy(__entry->cdw10, &cmd->common.cdw10, 89 sizeof(__entry->cdw10)); 90 ), 91 TP_printk("nvmet%s: %sqid=%d, cmdid=%u, nsid=%u, flags=%#x, " 92 "meta=%#llx, cmd=(%s, %s)", 93 __print_ctrl_name(__entry->ctrl), 94 __print_disk_name(__entry->disk), 95 __entry->qid, __entry->cid, __entry->nsid, 96 __entry->flags, __entry->metadata, 97 show_opcode_name(__entry->qid, __entry->opcode, 98 __entry->fctype), 99 parse_nvme_cmd(__entry->qid, __entry->opcode, 100 __entry->fctype, __entry->cdw10)) 101 ); 102 103 TRACE_EVENT(nvmet_req_complete, 104 TP_PROTO(struct nvmet_req *req), 105 TP_ARGS(req), 106 TP_STRUCT__entry( 107 __field(struct nvmet_ctrl *, ctrl) 108 __array(char, disk, DISK_NAME_LEN) 109 __field(int, qid) 110 __field(int, cid) 111 __field(u64, result) 112 __field(u16, status) 113 ), 114 TP_fast_assign( 115 __entry->ctrl = nvmet_req_to_ctrl(req); 116 __entry->qid = req->cq->qid; 117 __entry->cid = req->cqe->command_id; 118 __entry->result = le64_to_cpu(req->cqe->result.u64); 119 __entry->status = le16_to_cpu(req->cqe->status) >> 1; 120 __assign_req_name(__entry->disk, req); 121 ), 122 TP_printk("nvmet%s: %sqid=%d, cmdid=%u, res=%#llx, status=%#x", 123 __print_ctrl_name(__entry->ctrl), 124 __print_disk_name(__entry->disk), 125 __entry->qid, __entry->cid, __entry->result, __entry->status) 126 127 ); 128 129 #define aer_name(aer) { aer, #aer } 130 131 TRACE_EVENT(nvmet_async_event, 132 TP_PROTO(struct nvmet_ctrl *ctrl, __le32 result), 133 TP_ARGS(ctrl, result), 134 TP_STRUCT__entry( 135 __field(int, ctrl_id) 136 __field(u32, result) 137 ), 138 TP_fast_assign( 139 __entry->ctrl_id = ctrl->cntlid; 140 __entry->result = (le32_to_cpu(result) & 0xff00) >> 8; 141 ), 142 TP_printk("nvmet%d: NVME_AEN=%#08x [%s]", 143 __entry->ctrl_id, __entry->result, 144 __print_symbolic(__entry->result, 145 aer_name(NVME_AER_NOTICE_NS_CHANGED), 146 aer_name(NVME_AER_NOTICE_ANA), 147 aer_name(NVME_AER_NOTICE_FW_ACT_STARTING), 148 aer_name(NVME_AER_NOTICE_DISC_CHANGED), 149 aer_name(NVME_AER_ERROR), 150 aer_name(NVME_AER_SMART), 151 aer_name(NVME_AER_CSS), 152 aer_name(NVME_AER_VS)) 153 ) 154 ); 155 #undef aer_name 156 157 #endif /* _TRACE_NVMET_H */ 158 159 #undef TRACE_INCLUDE_PATH 160 #define TRACE_INCLUDE_PATH . 161 #undef TRACE_INCLUDE_FILE 162 #define TRACE_INCLUDE_FILE trace 163 164 /* This part must be outside protection */ 165 #include <trace/define_trace.h> 166