master
  1/* $NetBSD: cgdvar.h,v 1.21 2020/06/13 22:15:58 riastradh Exp $ */
  2
  3/*-
  4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
  5 * All rights reserved.
  6 *
  7 * This code is derived from software contributed to The NetBSD Foundation
  8 * by Roland C. Dowdeswell.
  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
 32#ifndef _DEV_CGDVAR_H_
 33#define	_DEV_CGDVAR_H_
 34
 35#include <sys/ioccom.h>
 36
 37/* ioctl(2) code: used by CGDIOCSET and CGDIOCCLR */
 38struct cgd_ioctl {
 39	const char	*ci_disk;
 40	int		 ci_flags;
 41	int		 ci_unit;
 42	size_t		 ci_size;
 43	const char	*ci_alg;
 44	const char	*ci_ivmethod;
 45	size_t		 ci_keylen;
 46	const char	*ci_key;
 47	size_t		 ci_blocksize;
 48};
 49
 50/* ioctl(2) code: used by CGDIOCGET */
 51struct cgd_user {
 52	int		cgu_unit;	/* which cgd unit */
 53	dev_t		cgu_dev;	/* target device */
 54	char		cgu_alg[32];	/* algorithm name */
 55	size_t		cgu_blocksize;	/* block size (in bytes) */
 56	int		cgu_mode;	/* Cipher Mode and IV Gen method */
 57#define CGD_CIPHER_CBC_ENCBLKNO8 1	/* CBC Mode w/ Enc Block Number
 58					 * 8 passes (compat only)
 59					 */
 60#define CGD_CIPHER_CBC_ENCBLKNO1 2	/* CBC Mode w/ Enc Block Number
 61					 * 1 pass (default)
 62					 */
 63	int		cgu_keylen;	/* keylength */
 64};
 65
 66#ifdef _KERNEL
 67
 68#include <dev/cgd_crypto.h>
 69#include <dev/dkvar.h>
 70
 71/* This cryptdata structure is here rather than cgd_crypto.h, since
 72 * it stores local state which will not be generalised beyond the
 73 * cgd driver.
 74 */
 75
 76struct cryptdata {
 77	size_t		 cf_blocksize;	/* block size (in bytes) */
 78	int		 cf_keylen;	/* key length */
 79	int		 cf_mode;	/* Cipher Mode and IV Gen method
 80					 * (see cgu_mode above for defines) */
 81	void		*cf_priv;	/* enc alg private data */
 82};
 83
 84struct cgd_xfer {
 85	struct work		 cx_work;
 86	struct cgd_softc	*cx_sc;
 87	struct buf		*cx_obp;
 88	struct buf		*cx_nbp;
 89	void			*cx_dstv;
 90	const void		*cx_srcv;
 91	size_t			 cx_len;
 92	daddr_t			 cx_blkno;
 93	size_t			 cx_secsize;
 94	int			 cx_dir;
 95};
 96
 97struct cgd_worker {
 98	struct workqueue	*cw_wq;		/* work queue */
 99	struct pool		*cw_cpool;	/* cgd_xfer contexts */
100	u_int		 	 cw_busy;	/* number of busy contexts */
101	u_int			 cw_last;	/* index of last CPU used */
102	kmutex_t		 cw_lock;
103};
104
105struct cgd_softc {
106	struct dk_softc		 sc_dksc;	/* generic disk interface */
107	struct vnode		*sc_tvn;	/* target device's vnode */
108	dev_t			 sc_tdev;	/* target device */
109	char			*sc_tpath;	/* target device's path */
110	void			*sc_data;	/* emergency buffer */
111	bool			 sc_data_used;	/* Really lame, we'll change */
112	size_t			 sc_tpathlen;	/* length of prior string */
113	struct cryptdata	 sc_cdata;	/* crypto data */
114	const struct cryptfuncs	*sc_cfuncs;	/* encryption functions */
115	kmutex_t		 sc_lock;
116	kcondvar_t		 sc_cv;
117	bool			 sc_busy;
118	struct cgd_worker	*sc_worker;	/* shared worker data */
119};
120#endif
121
122/* XXX XAX XXX elric:  check these out properly. */
123#define CGDIOCSET	_IOWR('F', 18, struct cgd_ioctl)
124#define CGDIOCCLR	_IOW('F', 19, struct cgd_ioctl)
125#define CGDIOCGET	_IOWR('F', 20, struct cgd_user)
126
127/* Maximum block sized to be used by the ciphers */
128#define CGD_MAXBLOCKSIZE	128
129
130#endif /* _DEV_CGDVAR_H_ */