Home | History | Annotate | Line # | Download | only in dmover
dmovervar.h revision 1.5.2.2
      1  1.5.2.1    skrll /*	$NetBSD: dmovervar.h,v 1.5.2.2 2004/09/18 14:45:39 skrll Exp $	*/
      2      1.1  thorpej 
      3      1.1  thorpej /*
      4  1.5.2.1    skrll  * Copyright (c) 2002, 2003 Wasabi Systems, Inc.
      5      1.1  thorpej  * All rights reserved.
      6      1.1  thorpej  *
      7      1.1  thorpej  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
      8      1.1  thorpej  *
      9      1.1  thorpej  * Redistribution and use in source and binary forms, with or without
     10      1.1  thorpej  * modification, are permitted provided that the following conditions
     11      1.1  thorpej  * are met:
     12      1.1  thorpej  * 1. Redistributions of source code must retain the above copyright
     13      1.1  thorpej  *    notice, this list of conditions and the following disclaimer.
     14      1.1  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     15      1.1  thorpej  *    notice, this list of conditions and the following disclaimer in the
     16      1.1  thorpej  *    documentation and/or other materials provided with the distribution.
     17      1.1  thorpej  * 3. All advertising materials mentioning features or use of this software
     18      1.1  thorpej  *    must display the following acknowledgement:
     19      1.1  thorpej  *	This product includes software developed for the NetBSD Project by
     20      1.1  thorpej  *	Wasabi Systems, Inc.
     21      1.1  thorpej  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22      1.1  thorpej  *    or promote products derived from this software without specific prior
     23      1.1  thorpej  *    written permission.
     24      1.1  thorpej  *
     25      1.1  thorpej  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26      1.1  thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27      1.1  thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28      1.1  thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29      1.1  thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30      1.1  thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31      1.1  thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32      1.1  thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33      1.1  thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34      1.1  thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35      1.1  thorpej  * POSSIBILITY OF SUCH DAMAGE.
     36      1.1  thorpej  */
     37      1.1  thorpej 
     38      1.1  thorpej #ifndef _DMOVER_DMOVERVAR_H_
     39      1.1  thorpej #define _DMOVER_DMOVERVAR_H_
     40      1.1  thorpej 
     41      1.1  thorpej #include <sys/lock.h>
     42      1.1  thorpej #include <sys/queue.h>
     43      1.1  thorpej 
     44      1.1  thorpej /*
     45      1.1  thorpej  * Types of buffers the dmover-api can handle.
     46      1.1  thorpej  */
     47      1.1  thorpej typedef enum {
     48  1.5.2.1    skrll 	DMOVER_BUF_NONE			= 0,
     49  1.5.2.1    skrll 	DMOVER_BUF_LINEAR		= 1,
     50  1.5.2.1    skrll 	DMOVER_BUF_UIO			= 2
     51      1.1  thorpej } dmover_buffer_type;
     52      1.1  thorpej 
     53      1.1  thorpej typedef struct {
     54      1.1  thorpej 	void *l_addr;
     55      1.1  thorpej 	size_t l_len;
     56      1.1  thorpej } dmover_buf_linear;
     57      1.1  thorpej 
     58      1.1  thorpej typedef union {
     59      1.1  thorpej 	dmover_buf_linear dmbuf_linear;
     60      1.1  thorpej 	struct uio *dmbuf_uio;
     61      1.1  thorpej } dmover_buffer;
     62      1.1  thorpej 
     63      1.1  thorpej /*
     64      1.1  thorpej  * dmover_algdesc:
     65      1.1  thorpej  *
     66      1.1  thorpej  *	This structure describes an dmover algorithm.
     67      1.1  thorpej  *
     68      1.1  thorpej  *	All members of this structure are public.
     69      1.1  thorpej  */
     70      1.1  thorpej struct dmover_algdesc {
     71      1.1  thorpej 	const char *dad_name;		/* algorithm name */
     72      1.1  thorpej 	void *dad_data;			/* opaque algorithm description */
     73      1.1  thorpej 	int dad_ninputs;		/* number of inputs */
     74      1.1  thorpej };
     75      1.1  thorpej 
     76      1.1  thorpej /*
     77      1.1  thorpej  * dmover_assignment:
     78      1.1  thorpej  *
     79      1.1  thorpej  *	This structure contains the information necessary to assign
     80      1.1  thorpej  *	a request to a back-end.
     81      1.1  thorpej  *
     82      1.1  thorpej  *	All members of this structure are public.
     83      1.1  thorpej  */
     84      1.1  thorpej struct dmover_assignment {
     85      1.1  thorpej 	struct dmover_backend *das_backend;
     86      1.1  thorpej 	const struct dmover_algdesc *das_algdesc;
     87      1.1  thorpej };
     88      1.1  thorpej 
     89      1.1  thorpej /*
     90      1.1  thorpej  * dmover_session:
     91      1.1  thorpej  *
     92      1.1  thorpej  *	State for a dmover session.
     93      1.1  thorpej  */
     94      1.1  thorpej struct dmover_session {
     95      1.1  thorpej 	/*
     96      1.1  thorpej 	 * PUBLIC MEMBERS
     97      1.1  thorpej 	 */
     98      1.1  thorpej 	void	*dses_cookie;		/* for client */
     99      1.1  thorpej 	int	dses_ninputs;		/* number of inputs for function */
    100      1.1  thorpej 
    101      1.1  thorpej 	/*
    102      1.1  thorpej 	 * PRIVATE MEMBERS
    103      1.1  thorpej 	 */
    104      1.1  thorpej 	LIST_ENTRY(dmover_session) __dses_list;
    105      1.1  thorpej 
    106      1.1  thorpej 	/*
    107      1.1  thorpej 	 * XXX Assignment is static when a session is
    108      1.1  thorpej 	 * XXX created, for now.
    109      1.1  thorpej 	 */
    110      1.1  thorpej 	struct dmover_assignment __dses_assignment;
    111      1.1  thorpej 
    112      1.1  thorpej 	/* List of active requests on this session. */
    113      1.1  thorpej 	TAILQ_HEAD(, dmover_request) __dses_pendreqs;
    114      1.1  thorpej 	int	__dses_npendreqs;
    115      1.1  thorpej };
    116      1.1  thorpej 
    117      1.1  thorpej #define	dmover_session_insque(dses, dreq)				\
    118      1.1  thorpej do {									\
    119      1.1  thorpej 	TAILQ_INSERT_TAIL(&(dses)->__dses_pendreqs, (dreq), dreq_sesq);	\
    120      1.1  thorpej 	(dses)->__dses_npendreqs++;					\
    121      1.1  thorpej } while (/*CONSTCOND*/0)
    122      1.1  thorpej 
    123      1.1  thorpej #define	dmover_session_remque(dses, dreq)				\
    124      1.1  thorpej do {									\
    125      1.1  thorpej 	TAILQ_REMOVE(&(dses)->__dses_pendreqs, (dreq), dreq_sesq);	\
    126      1.1  thorpej 	(dses)->__dses_npendreqs--;					\
    127      1.1  thorpej } while (/*CONSTCOND*/0)
    128      1.1  thorpej 
    129      1.1  thorpej /*
    130      1.1  thorpej  * dmover_request:
    131      1.1  thorpej  *
    132      1.1  thorpej  *	A data dmover request.
    133      1.1  thorpej  */
    134      1.1  thorpej struct dmover_request {
    135      1.1  thorpej 	/*
    136      1.1  thorpej 	 * PUBLIC MEMBERS
    137      1.1  thorpej 	 */
    138      1.1  thorpej 
    139      1.1  thorpej 	/* Links on session and back-end queues. */
    140      1.1  thorpej 	TAILQ_ENTRY(dmover_request) dreq_sesq;
    141      1.1  thorpej 	TAILQ_ENTRY(dmover_request) dreq_dmbq;
    142      1.1  thorpej 
    143      1.1  thorpej 	/* Pointer to our session. */
    144      1.1  thorpej 	struct dmover_session *dreq_session;
    145      1.1  thorpej 
    146      1.1  thorpej 	/* Our current back-end assignment. */
    147      1.1  thorpej 	struct dmover_assignment *dreq_assignment;
    148      1.1  thorpej 
    149      1.1  thorpej 	/* Function to call when processing is complete. */
    150      1.1  thorpej 	void	(*dreq_callback)(struct dmover_request *);
    151      1.1  thorpej 	void	*dreq_cookie;	/* for client */
    152      1.1  thorpej 
    153      1.1  thorpej 	__volatile int dreq_flags; /* flags; see below */
    154      1.1  thorpej 	int	dreq_error;	   /* valid if DMOVER_REQ_ERROR is set */
    155      1.1  thorpej 
    156      1.4  thorpej 	/*
    157      1.4  thorpej 	 * General purpose immediate value.  Can be used as an
    158      1.4  thorpej 	 * input, output, or both, depending on the function.
    159      1.4  thorpej 	 */
    160      1.4  thorpej 	uint8_t	dreq_immediate[8];
    161      1.4  thorpej 
    162      1.1  thorpej 	/* Output buffer. */
    163      1.1  thorpej 	dmover_buffer_type dreq_outbuf_type;
    164      1.1  thorpej 	dmover_buffer dreq_outbuf;
    165      1.1  thorpej 
    166      1.1  thorpej 	/* Input buffer. */
    167      1.1  thorpej 	dmover_buffer_type dreq_inbuf_type;
    168      1.5  thorpej 	dmover_buffer *dreq_inbuf;
    169      1.1  thorpej };
    170      1.1  thorpej 
    171      1.1  thorpej /* dreq_flags */
    172      1.1  thorpej #define	DMOVER_REQ_DONE		0x0001	/* request is completed */
    173      1.1  thorpej #define	DMOVER_REQ_ERROR	0x0002	/* error occurred */
    174      1.1  thorpej #define	DMOVER_REQ_RUNNING	0x0004	/* request is being executed */
    175      1.1  thorpej #define	DMOVER_REQ_WAIT		0x0008	/* wait for completion */
    176      1.1  thorpej 
    177      1.1  thorpej #define	__DMOVER_REQ_INBUF_FREE	0x01000000 /* need to free input buffer */
    178      1.1  thorpej 
    179      1.1  thorpej #define	__DMOVER_REQ_FLAGS_PRESERVE					\
    180      1.1  thorpej 	(DMOVER_REQ_WAIT | __DMOVER_REQ_INBUF_FREE)
    181      1.1  thorpej 
    182      1.1  thorpej /*
    183      1.1  thorpej  * dmover_backend:
    184      1.1  thorpej  *
    185      1.1  thorpej  *	Glue between the dmover-api middle layer and the dmover
    186      1.1  thorpej  *	backends.
    187      1.1  thorpej  *
    188      1.1  thorpej  *	All members of this structure are public.
    189      1.1  thorpej  */
    190      1.1  thorpej struct dmover_backend {
    191      1.1  thorpej 	TAILQ_ENTRY(dmover_backend) dmb_list;
    192      1.1  thorpej 
    193      1.1  thorpej 	const char *dmb_name;		/* name of back-end */
    194      1.1  thorpej 	u_int dmb_speed;		/* est. KB/s throughput */
    195      1.1  thorpej 
    196      1.1  thorpej 	void	*dmb_cookie;		/* for back-end */
    197      1.1  thorpej 
    198      1.1  thorpej 	/* List of algorithms this back-ends supports. */
    199      1.1  thorpej 	const struct dmover_algdesc *dmb_algdescs;
    200      1.1  thorpej 	int dmb_nalgdescs;
    201      1.1  thorpej 
    202      1.1  thorpej 	/* Back-end functions. */
    203      1.1  thorpej 	void	(*dmb_process)(struct dmover_backend *);
    204      1.1  thorpej 
    205      1.1  thorpej 	/* List of sessions currently on this back-end. */
    206      1.1  thorpej 	LIST_HEAD(, dmover_session) dmb_sessions;
    207      1.1  thorpej 	int	dmb_nsessions;		/* current number of sessions */
    208      1.1  thorpej 
    209      1.1  thorpej 	/* List of active requests on this back-end. */
    210      1.1  thorpej 	TAILQ_HEAD(, dmover_request) dmb_pendreqs;
    211      1.1  thorpej 	int	dmb_npendreqs;
    212      1.1  thorpej };
    213      1.1  thorpej 
    214      1.1  thorpej #define	dmover_backend_insque(dmb, dreq)				\
    215      1.1  thorpej do {									\
    216      1.1  thorpej 	TAILQ_INSERT_TAIL(&(dmb)->dmb_pendreqs, (dreq), dreq_dmbq);	\
    217      1.1  thorpej 	(dmb)->dmb_npendreqs++;						\
    218      1.1  thorpej } while (/*CONSTCOND*/0)
    219      1.1  thorpej 
    220      1.1  thorpej #define	dmover_backend_remque(dmb, dreq)				\
    221      1.1  thorpej do {									\
    222      1.1  thorpej 	TAILQ_REMOVE(&(dmb)->dmb_pendreqs, (dreq), dreq_dmbq);		\
    223      1.1  thorpej 	(dmb)->dmb_npendreqs--;						\
    224      1.1  thorpej } while (/*CONSTCOND*/0)
    225      1.1  thorpej 
    226      1.1  thorpej /*
    227      1.1  thorpej  * Well-known data mover functions.  Using these for the function name
    228      1.1  thorpej  * saves space.
    229      1.1  thorpej  */
    230      1.1  thorpej extern const char dmover_funcname_zero[];
    231      1.1  thorpej #define	DMOVER_FUNC_ZERO		dmover_funcname_zero
    232      1.1  thorpej 
    233      1.1  thorpej extern const char dmover_funcname_fill8[];
    234      1.1  thorpej #define	DMOVER_FUNC_FILL8		dmover_funcname_fill8
    235      1.1  thorpej 
    236      1.1  thorpej extern const char dmover_funcname_copy[];
    237      1.1  thorpej #define	DMOVER_FUNC_COPY		dmover_funcname_copy
    238      1.2  thorpej 
    239  1.5.2.1    skrll extern const char dmover_funcname_iscsi_crc32c[];
    240  1.5.2.1    skrll #define	DMOVER_FUNC_ISCSI_CRC32C	dmover_funcname_iscsi_crc32c
    241  1.5.2.1    skrll 
    242      1.2  thorpej extern const char dmover_funcname_xor2[];
    243      1.2  thorpej #define	DMOVER_FUNC_XOR2		dmover_funcname_xor2
    244      1.2  thorpej 
    245      1.2  thorpej extern const char dmover_funcname_xor3[];
    246      1.2  thorpej #define	DMOVER_FUNC_XOR3		dmover_funcname_xor3
    247      1.2  thorpej 
    248      1.2  thorpej extern const char dmover_funcname_xor4[];
    249      1.2  thorpej #define	DMOVER_FUNC_XOR4		dmover_funcname_xor4
    250      1.3  thorpej 
    251      1.3  thorpej extern const char dmover_funcname_xor5[];
    252      1.3  thorpej #define	DMOVER_FUNC_XOR5		dmover_funcname_xor5
    253      1.3  thorpej 
    254      1.3  thorpej extern const char dmover_funcname_xor6[];
    255      1.3  thorpej #define	DMOVER_FUNC_XOR6		dmover_funcname_xor6
    256      1.3  thorpej 
    257      1.3  thorpej extern const char dmover_funcname_xor7[];
    258      1.3  thorpej #define	DMOVER_FUNC_XOR7		dmover_funcname_xor7
    259      1.3  thorpej 
    260      1.3  thorpej extern const char dmover_funcname_xor8[];
    261      1.3  thorpej #define	DMOVER_FUNC_XOR8		dmover_funcname_xor8
    262      1.1  thorpej 
    263  1.5.2.1    skrll extern const char dmover_funcname_xor9[];
    264  1.5.2.1    skrll #define	DMOVER_FUNC_XOR9		dmover_funcname_xor9
    265  1.5.2.1    skrll 
    266  1.5.2.1    skrll extern const char dmover_funcname_xor10[];
    267  1.5.2.1    skrll #define	DMOVER_FUNC_XOR10		dmover_funcname_xor10
    268  1.5.2.1    skrll 
    269  1.5.2.1    skrll extern const char dmover_funcname_xor11[];
    270  1.5.2.1    skrll #define	DMOVER_FUNC_XOR11		dmover_funcname_xor11
    271  1.5.2.1    skrll 
    272  1.5.2.1    skrll extern const char dmover_funcname_xor12[];
    273  1.5.2.1    skrll #define	DMOVER_FUNC_XOR12		dmover_funcname_xor12
    274  1.5.2.1    skrll 
    275  1.5.2.1    skrll extern const char dmover_funcname_xor13[];
    276  1.5.2.1    skrll #define	DMOVER_FUNC_XOR13		dmover_funcname_xor13
    277  1.5.2.1    skrll 
    278  1.5.2.1    skrll extern const char dmover_funcname_xor14[];
    279  1.5.2.1    skrll #define	DMOVER_FUNC_XOR14		dmover_funcname_xor14
    280  1.5.2.1    skrll 
    281  1.5.2.1    skrll extern const char dmover_funcname_xor15[];
    282  1.5.2.1    skrll #define	DMOVER_FUNC_XOR15		dmover_funcname_xor15
    283  1.5.2.1    skrll 
    284  1.5.2.1    skrll extern const char dmover_funcname_xor16[];
    285  1.5.2.1    skrll #define	DMOVER_FUNC_XOR16		dmover_funcname_xor16
    286  1.5.2.1    skrll 
    287      1.1  thorpej /* Back-end management functions. */
    288      1.1  thorpej void	dmover_backend_register(struct dmover_backend *);
    289      1.1  thorpej void	dmover_backend_unregister(struct dmover_backend *);
    290      1.1  thorpej int	dmover_backend_alloc(struct dmover_session *, const char *);
    291      1.1  thorpej void	dmover_backend_release(struct dmover_session *);
    292      1.1  thorpej 
    293      1.1  thorpej /* Session management functions. */
    294      1.1  thorpej void	dmover_session_initialize(void);
    295      1.1  thorpej int	dmover_session_create(const char *, struct dmover_session **);
    296      1.1  thorpej void	dmover_session_destroy(struct dmover_session *);
    297      1.1  thorpej 
    298      1.1  thorpej /* Request management functions. */
    299      1.1  thorpej void	dmover_request_initialize(void);
    300      1.1  thorpej struct dmover_request *dmover_request_alloc(struct dmover_session *,
    301      1.1  thorpej 	    dmover_buffer *);
    302      1.1  thorpej void	dmover_request_free(struct dmover_request *);
    303      1.1  thorpej 
    304      1.1  thorpej /* Processing engine functions. */
    305      1.1  thorpej void	dmover_process_initialize(void);
    306      1.1  thorpej void	dmover_process(struct dmover_request *);
    307      1.1  thorpej void	dmover_done(struct dmover_request *);
    308      1.1  thorpej 
    309      1.1  thorpej /* Utility functions. */
    310      1.1  thorpej const struct dmover_algdesc *
    311      1.1  thorpej 	    dmover_algdesc_lookup(const struct dmover_algdesc *, int,
    312      1.1  thorpej 	    const char *);
    313      1.1  thorpej 
    314      1.1  thorpej #endif /* _DMOVER_DMOVERVAR_H_ */
    315