16f52b16cSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2607ca46eSDavid Howells #ifndef _UAPIBLKTRACE_H
3607ca46eSDavid Howells #define _UAPIBLKTRACE_H
4607ca46eSDavid Howells 
5607ca46eSDavid Howells #include <linux/types.h>
6607ca46eSDavid Howells 
7607ca46eSDavid Howells /*
8607ca46eSDavid Howells  * Trace categories
9607ca46eSDavid Howells  */
10607ca46eSDavid Howells enum blktrace_cat {
11607ca46eSDavid Howells 	BLK_TC_READ	= 1 << 0,	/* reads */
12607ca46eSDavid Howells 	BLK_TC_WRITE	= 1 << 1,	/* writes */
13607ca46eSDavid Howells 	BLK_TC_FLUSH	= 1 << 2,	/* flush */
14607ca46eSDavid Howells 	BLK_TC_SYNC	= 1 << 3,	/* sync IO */
15607ca46eSDavid Howells 	BLK_TC_SYNCIO	= BLK_TC_SYNC,
16607ca46eSDavid Howells 	BLK_TC_QUEUE	= 1 << 4,	/* queueing/merging */
17607ca46eSDavid Howells 	BLK_TC_REQUEUE	= 1 << 5,	/* requeueing */
18607ca46eSDavid Howells 	BLK_TC_ISSUE	= 1 << 6,	/* issue */
19607ca46eSDavid Howells 	BLK_TC_COMPLETE	= 1 << 7,	/* completions */
20607ca46eSDavid Howells 	BLK_TC_FS	= 1 << 8,	/* fs requests */
21607ca46eSDavid Howells 	BLK_TC_PC	= 1 << 9,	/* pc requests */
22607ca46eSDavid Howells 	BLK_TC_NOTIFY	= 1 << 10,	/* special message */
23607ca46eSDavid Howells 	BLK_TC_AHEAD	= 1 << 11,	/* readahead */
24607ca46eSDavid Howells 	BLK_TC_META	= 1 << 12,	/* metadata */
25607ca46eSDavid Howells 	BLK_TC_DISCARD	= 1 << 13,	/* discard requests */
26607ca46eSDavid Howells 	BLK_TC_DRV_DATA	= 1 << 14,	/* binary per-driver data */
27607ca46eSDavid Howells 	BLK_TC_FUA	= 1 << 15,	/* fua requests */
28607ca46eSDavid Howells 
29607ca46eSDavid Howells 	BLK_TC_END	= 1 << 15,	/* we've run out of bits! */
30607ca46eSDavid Howells };
31607ca46eSDavid Howells 
32607ca46eSDavid Howells #define BLK_TC_SHIFT		(16)
33607ca46eSDavid Howells #define BLK_TC_ACT(act)		((act) << BLK_TC_SHIFT)
34607ca46eSDavid Howells 
35607ca46eSDavid Howells /*
36607ca46eSDavid Howells  * Basic trace actions
37607ca46eSDavid Howells  */
38607ca46eSDavid Howells enum blktrace_act {
39607ca46eSDavid Howells 	__BLK_TA_QUEUE = 1,		/* queued */
40607ca46eSDavid Howells 	__BLK_TA_BACKMERGE,		/* back merged to existing rq */
41607ca46eSDavid Howells 	__BLK_TA_FRONTMERGE,		/* front merge to existing rq */
42607ca46eSDavid Howells 	__BLK_TA_GETRQ,			/* allocated new request */
43607ca46eSDavid Howells 	__BLK_TA_SLEEPRQ,		/* sleeping on rq allocation */
44607ca46eSDavid Howells 	__BLK_TA_REQUEUE,		/* request requeued */
45607ca46eSDavid Howells 	__BLK_TA_ISSUE,			/* sent to driver */
46607ca46eSDavid Howells 	__BLK_TA_COMPLETE,		/* completed by driver */
47607ca46eSDavid Howells 	__BLK_TA_PLUG,			/* queue was plugged */
48607ca46eSDavid Howells 	__BLK_TA_UNPLUG_IO,		/* queue was unplugged by io */
49607ca46eSDavid Howells 	__BLK_TA_UNPLUG_TIMER,		/* queue was unplugged by timer */
50607ca46eSDavid Howells 	__BLK_TA_INSERT,		/* insert request */
51607ca46eSDavid Howells 	__BLK_TA_SPLIT,			/* bio was split */
52607ca46eSDavid Howells 	__BLK_TA_BOUNCE,		/* bio was bounced */
53607ca46eSDavid Howells 	__BLK_TA_REMAP,			/* bio was remapped */
54607ca46eSDavid Howells 	__BLK_TA_ABORT,			/* request aborted */
55607ca46eSDavid Howells 	__BLK_TA_DRV_DATA,		/* driver-specific binary data */
56ca1136c9SShaohua Li 	__BLK_TA_CGROUP = 1 << 8,	/* from a cgroup*/
57607ca46eSDavid Howells };
58607ca46eSDavid Howells 
59607ca46eSDavid Howells /*
60607ca46eSDavid Howells  * Notify events.
61607ca46eSDavid Howells  */
62607ca46eSDavid Howells enum blktrace_notify {
63607ca46eSDavid Howells 	__BLK_TN_PROCESS = 0,		/* establish pid/name mapping */
64607ca46eSDavid Howells 	__BLK_TN_TIMESTAMP,		/* include system clock */
65607ca46eSDavid Howells 	__BLK_TN_MESSAGE,		/* Character string message */
66ca1136c9SShaohua Li 	__BLK_TN_CGROUP = __BLK_TA_CGROUP, /* from a cgroup */
67607ca46eSDavid Howells };
68607ca46eSDavid Howells 
69607ca46eSDavid Howells 
70607ca46eSDavid Howells /*
71607ca46eSDavid Howells  * Trace actions in full. Additionally, read or write is masked
72607ca46eSDavid Howells  */
73607ca46eSDavid Howells #define BLK_TA_QUEUE		(__BLK_TA_QUEUE | BLK_TC_ACT(BLK_TC_QUEUE))
74607ca46eSDavid Howells #define BLK_TA_BACKMERGE	(__BLK_TA_BACKMERGE | BLK_TC_ACT(BLK_TC_QUEUE))
75607ca46eSDavid Howells #define BLK_TA_FRONTMERGE	(__BLK_TA_FRONTMERGE | BLK_TC_ACT(BLK_TC_QUEUE))
76607ca46eSDavid Howells #define	BLK_TA_GETRQ		(__BLK_TA_GETRQ | BLK_TC_ACT(BLK_TC_QUEUE))
77607ca46eSDavid Howells #define	BLK_TA_SLEEPRQ		(__BLK_TA_SLEEPRQ | BLK_TC_ACT(BLK_TC_QUEUE))
78607ca46eSDavid Howells #define	BLK_TA_REQUEUE		(__BLK_TA_REQUEUE | BLK_TC_ACT(BLK_TC_REQUEUE))
79607ca46eSDavid Howells #define BLK_TA_ISSUE		(__BLK_TA_ISSUE | BLK_TC_ACT(BLK_TC_ISSUE))
80607ca46eSDavid Howells #define BLK_TA_COMPLETE		(__BLK_TA_COMPLETE| BLK_TC_ACT(BLK_TC_COMPLETE))
81607ca46eSDavid Howells #define BLK_TA_PLUG		(__BLK_TA_PLUG | BLK_TC_ACT(BLK_TC_QUEUE))
82607ca46eSDavid Howells #define BLK_TA_UNPLUG_IO	(__BLK_TA_UNPLUG_IO | BLK_TC_ACT(BLK_TC_QUEUE))
83607ca46eSDavid Howells #define BLK_TA_UNPLUG_TIMER	(__BLK_TA_UNPLUG_TIMER | BLK_TC_ACT(BLK_TC_QUEUE))
84607ca46eSDavid Howells #define BLK_TA_INSERT		(__BLK_TA_INSERT | BLK_TC_ACT(BLK_TC_QUEUE))
85607ca46eSDavid Howells #define BLK_TA_SPLIT		(__BLK_TA_SPLIT)
86607ca46eSDavid Howells #define BLK_TA_BOUNCE		(__BLK_TA_BOUNCE)
87607ca46eSDavid Howells #define BLK_TA_REMAP		(__BLK_TA_REMAP | BLK_TC_ACT(BLK_TC_QUEUE))
88607ca46eSDavid Howells #define BLK_TA_ABORT		(__BLK_TA_ABORT | BLK_TC_ACT(BLK_TC_QUEUE))
89607ca46eSDavid Howells #define BLK_TA_DRV_DATA	(__BLK_TA_DRV_DATA | BLK_TC_ACT(BLK_TC_DRV_DATA))
90607ca46eSDavid Howells 
91607ca46eSDavid Howells #define BLK_TN_PROCESS		(__BLK_TN_PROCESS | BLK_TC_ACT(BLK_TC_NOTIFY))
92607ca46eSDavid Howells #define BLK_TN_TIMESTAMP	(__BLK_TN_TIMESTAMP | BLK_TC_ACT(BLK_TC_NOTIFY))
93607ca46eSDavid Howells #define BLK_TN_MESSAGE		(__BLK_TN_MESSAGE | BLK_TC_ACT(BLK_TC_NOTIFY))
94607ca46eSDavid Howells 
95607ca46eSDavid Howells #define BLK_IO_TRACE_MAGIC	0x65617400
96607ca46eSDavid Howells #define BLK_IO_TRACE_VERSION	0x07
97607ca46eSDavid Howells 
98607ca46eSDavid Howells /*
99607ca46eSDavid Howells  * The trace itself
100607ca46eSDavid Howells  */
101607ca46eSDavid Howells struct blk_io_trace {
102607ca46eSDavid Howells 	__u32 magic;		/* MAGIC << 8 | version */
103607ca46eSDavid Howells 	__u32 sequence;		/* event number */
104a5040c2dSSouvik Banerjee 	__u64 time;		/* in nanoseconds */
105607ca46eSDavid Howells 	__u64 sector;		/* disk offset */
106607ca46eSDavid Howells 	__u32 bytes;		/* transfer length */
107607ca46eSDavid Howells 	__u32 action;		/* what happened */
108607ca46eSDavid Howells 	__u32 pid;		/* who did it */
109607ca46eSDavid Howells 	__u32 device;		/* device number */
110607ca46eSDavid Howells 	__u32 cpu;		/* on what cpu did it happen */
111607ca46eSDavid Howells 	__u16 error;		/* completion error */
112607ca46eSDavid Howells 	__u16 pdu_len;		/* length of data after this trace */
113ca1136c9SShaohua Li 	/* cgroup id will be stored here if exists */
114607ca46eSDavid Howells };
115607ca46eSDavid Howells 
116607ca46eSDavid Howells /*
117607ca46eSDavid Howells  * The remap event
118607ca46eSDavid Howells  */
119607ca46eSDavid Howells struct blk_io_trace_remap {
120607ca46eSDavid Howells 	__be32 device_from;
121607ca46eSDavid Howells 	__be32 device_to;
122607ca46eSDavid Howells 	__be64 sector_from;
123607ca46eSDavid Howells };
124607ca46eSDavid Howells 
125607ca46eSDavid Howells enum {
126607ca46eSDavid Howells 	Blktrace_setup = 1,
127607ca46eSDavid Howells 	Blktrace_running,
128607ca46eSDavid Howells 	Blktrace_stopped,
129607ca46eSDavid Howells };
130607ca46eSDavid Howells 
131607ca46eSDavid Howells #define BLKTRACE_BDEV_SIZE	32
132607ca46eSDavid Howells 
133607ca46eSDavid Howells /*
1349c722588SEric Biggers  * User setup structure passed with BLKTRACESETUP
135607ca46eSDavid Howells  */
136607ca46eSDavid Howells struct blk_user_trace_setup {
137607ca46eSDavid Howells 	char name[BLKTRACE_BDEV_SIZE];	/* output */
138607ca46eSDavid Howells 	__u16 act_mask;			/* input */
139607ca46eSDavid Howells 	__u32 buf_size;			/* input */
140607ca46eSDavid Howells 	__u32 buf_nr;			/* input */
141607ca46eSDavid Howells 	__u64 start_lba;
142607ca46eSDavid Howells 	__u64 end_lba;
143607ca46eSDavid Howells 	__u32 pid;
144607ca46eSDavid Howells };
145607ca46eSDavid Howells 
146607ca46eSDavid Howells #endif /* _UAPIBLKTRACE_H */
147