1 /* $NetBSD: dmovervar.h,v 1.9 2005/12/11 12:21:20 christos Exp $ */
4 * Copyright (c) 2002, 2003 Wasabi Systems, Inc.
7 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed for the NetBSD Project by
20 * Wasabi Systems, Inc.
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 * or promote products derived from this software without specific prior
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
38 #ifndef _DMOVER_DMOVERVAR_H_
39 #define _DMOVER_DMOVERVAR_H_
42 #include <sys/queue.h>
45 * Types of buffers the dmover-api can handle.
49 DMOVER_BUF_LINEAR
= 1,
59 dmover_buf_linear dmbuf_linear
;
60 struct uio
*dmbuf_uio
;
66 * This structure describes an dmover algorithm.
68 * All members of this structure are public.
70 struct dmover_algdesc
{
71 const char *dad_name
; /* algorithm name */
72 void *dad_data
; /* opaque algorithm description */
73 int dad_ninputs
; /* number of inputs */
79 * This structure contains the information necessary to assign
80 * a request to a back-end.
82 * All members of this structure are public.
84 struct dmover_assignment
{
85 struct dmover_backend
*das_backend
;
86 const struct dmover_algdesc
*das_algdesc
;
92 * State for a dmover session.
94 struct dmover_session
{
98 void *dses_cookie
; /* for client */
99 int dses_ninputs
; /* number of inputs for function */
104 LIST_ENTRY(dmover_session
) __dses_list
;
107 * XXX Assignment is static when a session is
108 * XXX created, for now.
110 struct dmover_assignment __dses_assignment
;
112 /* List of active requests on this session. */
113 TAILQ_HEAD(, dmover_request
) __dses_pendreqs
;
114 int __dses_npendreqs
;
117 #define dmover_session_insque(dses, dreq) \
119 TAILQ_INSERT_TAIL(&(dses)->__dses_pendreqs, (dreq), dreq_sesq); \
120 (dses)->__dses_npendreqs++; \
121 } while (/*CONSTCOND*/0)
123 #define dmover_session_remque(dses, dreq) \
125 TAILQ_REMOVE(&(dses)->__dses_pendreqs, (dreq), dreq_sesq); \
126 (dses)->__dses_npendreqs--; \
127 } while (/*CONSTCOND*/0)
132 * A data dmover request.
134 struct dmover_request
{
139 /* Links on session and back-end queues. */
140 TAILQ_ENTRY(dmover_request
) dreq_sesq
;
141 TAILQ_ENTRY(dmover_request
) dreq_dmbq
;
143 /* Pointer to our session. */
144 struct dmover_session
*dreq_session
;
146 /* Our current back-end assignment. */
147 struct dmover_assignment
*dreq_assignment
;
149 /* Function to call when processing is complete. */
150 void (*dreq_callback
)(struct dmover_request
*);
151 void *dreq_cookie
; /* for client */
153 volatile int dreq_flags
; /* flags; see below */
154 int dreq_error
; /* valid if DMOVER_REQ_ERROR is set */
157 * General purpose immediate value. Can be used as an
158 * input, output, or both, depending on the function.
160 uint8_t dreq_immediate
[8];
163 dmover_buffer_type dreq_outbuf_type
;
164 dmover_buffer dreq_outbuf
;
167 dmover_buffer_type dreq_inbuf_type
;
168 dmover_buffer
*dreq_inbuf
;
172 #define DMOVER_REQ_DONE 0x0001 /* request is completed */
173 #define DMOVER_REQ_ERROR 0x0002 /* error occurred */
174 #define DMOVER_REQ_RUNNING 0x0004 /* request is being executed */
175 #define DMOVER_REQ_WAIT 0x0008 /* wait for completion */
177 #define __DMOVER_REQ_INBUF_FREE 0x01000000 /* need to free input buffer */
179 #define __DMOVER_REQ_FLAGS_PRESERVE \
180 (DMOVER_REQ_WAIT | __DMOVER_REQ_INBUF_FREE)
185 * Glue between the dmover-api middle layer and the dmover
188 * All members of this structure are public.
190 struct dmover_backend
{
191 TAILQ_ENTRY(dmover_backend
) dmb_list
;
193 const char *dmb_name
; /* name of back-end */
194 u_int dmb_speed
; /* est. KB/s throughput */
196 void *dmb_cookie
; /* for back-end */
198 /* List of algorithms this back-ends supports. */
199 const struct dmover_algdesc
*dmb_algdescs
;
202 /* Back-end functions. */
203 void (*dmb_process
)(struct dmover_backend
*);
205 /* List of sessions currently on this back-end. */
206 LIST_HEAD(, dmover_session
) dmb_sessions
;
207 int dmb_nsessions
; /* current number of sessions */
209 /* List of active requests on this back-end. */
210 TAILQ_HEAD(, dmover_request
) dmb_pendreqs
;
214 #define dmover_backend_insque(dmb, dreq) \
216 TAILQ_INSERT_TAIL(&(dmb)->dmb_pendreqs, (dreq), dreq_dmbq); \
217 (dmb)->dmb_npendreqs++; \
218 } while (/*CONSTCOND*/0)
220 #define dmover_backend_remque(dmb, dreq) \
222 TAILQ_REMOVE(&(dmb)->dmb_pendreqs, (dreq), dreq_dmbq); \
223 (dmb)->dmb_npendreqs--; \
224 } while (/*CONSTCOND*/0)
227 * Well-known data mover functions. Using these for the function name
230 extern const char dmover_funcname_zero
[];
231 #define DMOVER_FUNC_ZERO dmover_funcname_zero
233 extern const char dmover_funcname_fill8
[];
234 #define DMOVER_FUNC_FILL8 dmover_funcname_fill8
236 extern const char dmover_funcname_copy
[];
237 #define DMOVER_FUNC_COPY dmover_funcname_copy
239 extern const char dmover_funcname_iscsi_crc32c
[];
240 #define DMOVER_FUNC_ISCSI_CRC32C dmover_funcname_iscsi_crc32c
242 extern const char dmover_funcname_xor2
[];
243 #define DMOVER_FUNC_XOR2 dmover_funcname_xor2
245 extern const char dmover_funcname_xor3
[];
246 #define DMOVER_FUNC_XOR3 dmover_funcname_xor3
248 extern const char dmover_funcname_xor4
[];
249 #define DMOVER_FUNC_XOR4 dmover_funcname_xor4
251 extern const char dmover_funcname_xor5
[];
252 #define DMOVER_FUNC_XOR5 dmover_funcname_xor5
254 extern const char dmover_funcname_xor6
[];
255 #define DMOVER_FUNC_XOR6 dmover_funcname_xor6
257 extern const char dmover_funcname_xor7
[];
258 #define DMOVER_FUNC_XOR7 dmover_funcname_xor7
260 extern const char dmover_funcname_xor8
[];
261 #define DMOVER_FUNC_XOR8 dmover_funcname_xor8
263 extern const char dmover_funcname_xor9
[];
264 #define DMOVER_FUNC_XOR9 dmover_funcname_xor9
266 extern const char dmover_funcname_xor10
[];
267 #define DMOVER_FUNC_XOR10 dmover_funcname_xor10
269 extern const char dmover_funcname_xor11
[];
270 #define DMOVER_FUNC_XOR11 dmover_funcname_xor11
272 extern const char dmover_funcname_xor12
[];
273 #define DMOVER_FUNC_XOR12 dmover_funcname_xor12
275 extern const char dmover_funcname_xor13
[];
276 #define DMOVER_FUNC_XOR13 dmover_funcname_xor13
278 extern const char dmover_funcname_xor14
[];
279 #define DMOVER_FUNC_XOR14 dmover_funcname_xor14
281 extern const char dmover_funcname_xor15
[];
282 #define DMOVER_FUNC_XOR15 dmover_funcname_xor15
284 extern const char dmover_funcname_xor16
[];
285 #define DMOVER_FUNC_XOR16 dmover_funcname_xor16
287 /* Back-end management functions. */
288 void dmover_backend_register(struct dmover_backend
*);
289 void dmover_backend_unregister(struct dmover_backend
*);
290 int dmover_backend_alloc(struct dmover_session
*, const char *);
291 void dmover_backend_release(struct dmover_session
*);
293 /* Session management functions. */
294 void dmover_session_initialize(void);
295 int dmover_session_create(const char *, struct dmover_session
**);
296 void dmover_session_destroy(struct dmover_session
*);
298 /* Request management functions. */
299 void dmover_request_initialize(void);
300 struct dmover_request
*dmover_request_alloc(struct dmover_session
*,
302 void dmover_request_free(struct dmover_request
*);
304 /* Processing engine functions. */
305 void dmover_process_initialize(void);
306 void dmover_process(struct dmover_request
*);
307 void dmover_done(struct dmover_request
*);
309 /* Utility functions. */
310 const struct dmover_algdesc
*
311 dmover_algdesc_lookup(const struct dmover_algdesc
*, int,
314 #endif /* _DMOVER_DMOVERVAR_H_ */