| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: cgd.c,v 1.132 2020/06/13 22:15:06 riastradh Exp $ */ | | 1 | /* $NetBSD: cgd.c,v 1.133 2020/06/13 22:15:57 riastradh Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2002 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2002 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Roland C. Dowdeswell. | | 8 | * by Roland C. Dowdeswell. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -20,27 +20,27 @@ | | | @@ -20,27 +20,27 @@ |
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 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 | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 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 | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 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 | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | __KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.132 2020/06/13 22:15:06 riastradh Exp $"); | | 33 | __KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.133 2020/06/13 22:15:57 riastradh Exp $"); |
34 | | | 34 | |
35 | #include <sys/types.h> | | 35 | #include <sys/types.h> |
36 | #include <sys/param.h> | | 36 | #include <sys/param.h> |
37 | #include <sys/buf.h> | | 37 | #include <sys/buf.h> |
38 | #include <sys/bufq.h> | | 38 | #include <sys/bufq.h> |
39 | #include <sys/conf.h> | | 39 | #include <sys/conf.h> |
40 | #include <sys/cpu.h> | | 40 | #include <sys/cpu.h> |
41 | #include <sys/device.h> | | 41 | #include <sys/device.h> |
42 | #include <sys/disk.h> | | 42 | #include <sys/disk.h> |
43 | #include <sys/disklabel.h> | | 43 | #include <sys/disklabel.h> |
44 | #include <sys/errno.h> | | 44 | #include <sys/errno.h> |
45 | #include <sys/fcntl.h> | | 45 | #include <sys/fcntl.h> |
46 | #include <sys/ioctl.h> | | 46 | #include <sys/ioctl.h> |
| @@ -376,27 +376,27 @@ static int cgd_destroy(device_t); | | | @@ -376,27 +376,27 @@ static int cgd_destroy(device_t); |
376 | static int cgd_diskstart(device_t, struct buf *); | | 376 | static int cgd_diskstart(device_t, struct buf *); |
377 | static void cgd_diskstart2(struct cgd_softc *, struct cgd_xfer *); | | 377 | static void cgd_diskstart2(struct cgd_softc *, struct cgd_xfer *); |
378 | static void cgdiodone(struct buf *); | | 378 | static void cgdiodone(struct buf *); |
379 | static void cgd_iodone2(struct cgd_softc *, struct cgd_xfer *); | | 379 | static void cgd_iodone2(struct cgd_softc *, struct cgd_xfer *); |
380 | static void cgd_enqueue(struct cgd_softc *, struct cgd_xfer *); | | 380 | static void cgd_enqueue(struct cgd_softc *, struct cgd_xfer *); |
381 | static void cgd_process(struct work *, void *); | | 381 | static void cgd_process(struct work *, void *); |
382 | static int cgd_dumpblocks(device_t, void *, daddr_t, int); | | 382 | static int cgd_dumpblocks(device_t, void *, daddr_t, int); |
383 | | | 383 | |
384 | static int cgd_ioctl_set(struct cgd_softc *, void *, struct lwp *); | | 384 | static int cgd_ioctl_set(struct cgd_softc *, void *, struct lwp *); |
385 | static int cgd_ioctl_clr(struct cgd_softc *, struct lwp *); | | 385 | static int cgd_ioctl_clr(struct cgd_softc *, struct lwp *); |
386 | static int cgd_ioctl_get(dev_t, void *, struct lwp *); | | 386 | static int cgd_ioctl_get(dev_t, void *, struct lwp *); |
387 | static int cgdinit(struct cgd_softc *, const char *, struct vnode *, | | 387 | static int cgdinit(struct cgd_softc *, const char *, struct vnode *, |
388 | struct lwp *); | | 388 | struct lwp *); |
389 | static void cgd_cipher(struct cgd_softc *, void *, void *, | | 389 | static void cgd_cipher(struct cgd_softc *, void *, const void *, |
390 | size_t, daddr_t, size_t, int); | | 390 | size_t, daddr_t, size_t, int); |
391 | | | 391 | |
392 | static void cgd_selftest(void); | | 392 | static void cgd_selftest(void); |
393 | | | 393 | |
394 | static const struct dkdriver cgddkdriver = { | | 394 | static const struct dkdriver cgddkdriver = { |
395 | .d_minphys = minphys, | | 395 | .d_minphys = minphys, |
396 | .d_open = cgdopen, | | 396 | .d_open = cgdopen, |
397 | .d_close = cgdclose, | | 397 | .d_close = cgdclose, |
398 | .d_strategy = cgdstrategy, | | 398 | .d_strategy = cgdstrategy, |
399 | .d_iosize = NULL, | | 399 | .d_iosize = NULL, |
400 | .d_diskstart = cgd_diskstart, | | 400 | .d_diskstart = cgd_diskstart, |
401 | .d_dumpblocks = cgd_dumpblocks, | | 401 | .d_dumpblocks = cgd_dumpblocks, |
402 | .d_lastclose = NULL | | 402 | .d_lastclose = NULL |
| @@ -1525,31 +1525,31 @@ cgd_process(struct work *wk, void *arg) | | | @@ -1525,31 +1525,31 @@ cgd_process(struct work *wk, void *arg) |
1525 | if (cx->cx_dir == CGD_CIPHER_ENCRYPT) { | | 1525 | if (cx->cx_dir == CGD_CIPHER_ENCRYPT) { |
1526 | cgd_diskstart2(sc, cx); | | 1526 | cgd_diskstart2(sc, cx); |
1527 | } else { | | 1527 | } else { |
1528 | cgd_iodone2(sc, cx); | | 1528 | cgd_iodone2(sc, cx); |
1529 | } | | 1529 | } |
1530 | | | 1530 | |
1531 | mutex_enter(&cw->cw_lock); | | 1531 | mutex_enter(&cw->cw_lock); |
1532 | if (cw->cw_busy > 0) | | 1532 | if (cw->cw_busy > 0) |
1533 | cw->cw_busy--; | | 1533 | cw->cw_busy--; |
1534 | mutex_exit(&cw->cw_lock); | | 1534 | mutex_exit(&cw->cw_lock); |
1535 | } | | 1535 | } |
1536 | | | 1536 | |
1537 | static void | | 1537 | static void |
1538 | cgd_cipher(struct cgd_softc *sc, void *dstv, void *srcv, | | 1538 | cgd_cipher(struct cgd_softc *sc, void *dstv, const void *srcv, |
1539 | size_t len, daddr_t blkno, size_t secsize, int dir) | | 1539 | size_t len, daddr_t blkno, size_t secsize, int dir) |
1540 | { | | 1540 | { |
1541 | char *dst = dstv; | | 1541 | char *dst = dstv; |
1542 | char *src = srcv; | | 1542 | const char *src = srcv; |
1543 | cfunc_cipher *cipher = sc->sc_cfuncs->cf_cipher; | | 1543 | cfunc_cipher *cipher = sc->sc_cfuncs->cf_cipher; |
1544 | size_t blocksize = sc->sc_cdata.cf_blocksize; | | 1544 | size_t blocksize = sc->sc_cdata.cf_blocksize; |
1545 | size_t todo; | | 1545 | size_t todo; |
1546 | char blkno_buf[CGD_MAXBLOCKSIZE]; | | 1546 | char blkno_buf[CGD_MAXBLOCKSIZE]; |
1547 | | | 1547 | |
1548 | DPRINTF_FOLLOW(("cgd_cipher() dir=%d\n", dir)); | | 1548 | DPRINTF_FOLLOW(("cgd_cipher() dir=%d\n", dir)); |
1549 | | | 1549 | |
1550 | KASSERT(len % blocksize == 0); | | 1550 | KASSERT(len % blocksize == 0); |
1551 | /* ensure that sizeof(daddr_t) <= blocksize (for encblkno IVing) */ | | 1551 | /* ensure that sizeof(daddr_t) <= blocksize (for encblkno IVing) */ |
1552 | KASSERT(sizeof(daddr_t) <= blocksize); | | 1552 | KASSERT(sizeof(daddr_t) <= blocksize); |
1553 | KASSERT(blocksize <= CGD_MAXBLOCKSIZE); | | 1553 | KASSERT(blocksize <= CGD_MAXBLOCKSIZE); |
1554 | | | 1554 | |
1555 | for (; len > 0; len -= todo) { | | 1555 | for (; len > 0; len -= todo) { |