1/*	$NetBSD: iscsi_perf.h,v 1.2 2011/06/09 22:08:19 riz Exp $	*/
2
3/*-
4 * Copyright (c) 2005,2006,2011 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Wasabi Systems, Inc.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32typedef enum
33{
34	PERF_BEGIN_COMMAND,			/* start of command */
35	PERF_END_COMMAND,			/* end of command */
36	PERF_BEGIN_PDUWRITECMD,		/* start of write of command PDU */
37	PERF_END_PDUWRITECMD,		/* end of write of command PDU */
38	PERF_BEGIN_PDUWRITEDATA,	/* start of first data PDU write (write only) */
39	PERF_END_PDUWRITEDATA,		/* end of last data PDU write */
40	PERF_BEGIN_PDURCVDATA,		/* start of first data PDU receive (read only) */
41	PERF_END_PDURCVDATA,		/* end of last data PDU receive */
42	PERF_PDURCVSTS,				/* receive of status PDU */
43	PERF_NUM_PERFPOINTS
44} perfpoint_t;
45
46
47#define PERF_FLG_READ      0x10000000	/* this is a read command */
48#define PERF_FLG_NOWAIT    0x20000000	/* this command was non-waiting */
49#define PERF_FLG_COMPLETE  0x80000000	/* command completed */
50
51
52typedef struct
53{
54	uint64_t pctr[PERF_NUM_PERFPOINTS];
55	uint32_t datalen;			/* data transfer size */
56	uint32_t status;			/* Result of command (lower 16 bits) + flags */
57} command_perf_t;
58
59
60/*
61   Perfdata_Start:
62      Allocates data buffer in driver with given number of command_perf
63      elements. If a buffer of larger or equal size already exists, it is
64      not reallocated.
65      Resets indices and clears the buffer.
66
67   Perfdata_Stop:
68      Stops data collection, waits (up to 5 seconds) for completion.
69      Returns the number of data points collected.
70*/
71
72typedef struct
73{
74	int num_elements;			/* start: IN number of elements to allocate */
75								/* stop: OUT number of elements used */
76	uint32_t status;			/* out: status */
77} iscsi_perf_startstop_parameters_t;
78
79
80#define ISCSI_PERFDATA_START _IOWR (0, 90, iscsi_perf_startstop_parameters_t)
81#define ISCSI_PERFDATA_STOP  _IOWR (0, 91, iscsi_perf_startstop_parameters_t)
82
83
84/*
85   Perfdata_Get:
86      Retrieves the current data. Note that this may be called while data
87      collection is still active, it does not automatically stop collection.
88      It will not reset collection or release  any buffers.
89
90      To determine the required buffer size, call with buffersize set to zero.
91      In that case, no data is transferred, the buffersize field is set to the
92      required size in bytes, and num_elements is set to the corresponding
93      number of data points.
94
95      If buffersize is nonzero, the number of data points that will fit into
96      the buffer, or the number of data points collected so far, will be
97      copied into the buffer, whichever is smallest. num_elements is set to
98      the number of elements copied.
99
100      ticks_per_100ms is the approximate conversion base to convert the CPU
101      cycle counter values collected into time units. This value is determined
102      by measuring the cycles for a delay(100) five times and taking the
103      average.
104*/
105
106typedef struct
107{
108	void *buffer;				/* in: buffer pointer */
109	uint32_t buffersize;		/* in: size of buffer in bytes (0 to query size) */
110	uint32_t status;			/* out: status */
111	int num_elements;			/* out: number of elements written */
112	uint64_t ticks_per_100us;	/* out: ticks per 100 usec */
113} iscsi_perf_get_parameters_t;
114
115
116#define ISCSI_PERFDATA_GET   _IOWR (0, 92, iscsi_perf_get_parameters_t)
117