1 1.24 maya /* $NetBSD: scsipi_base.h,v 1.24 2017/02/26 10:58:47 maya Exp $ */ 2 1.2 bouyer 3 1.8 mycroft /*- 4 1.15 mycroft * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc. 5 1.8 mycroft * All rights reserved. 6 1.8 mycroft * 7 1.8 mycroft * This code is derived from software contributed to The NetBSD Foundation 8 1.8 mycroft * by Charles M. Hannum. 9 1.2 bouyer * 10 1.2 bouyer * Redistribution and use in source and binary forms, with or without 11 1.2 bouyer * modification, are permitted provided that the following conditions 12 1.2 bouyer * are met: 13 1.2 bouyer * 1. Redistributions of source code must retain the above copyright 14 1.2 bouyer * notice, this list of conditions and the following disclaimer. 15 1.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright 16 1.2 bouyer * notice, this list of conditions and the following disclaimer in the 17 1.2 bouyer * documentation and/or other materials provided with the distribution. 18 1.2 bouyer * 19 1.8 mycroft * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.8 mycroft * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.8 mycroft * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.8 mycroft * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.8 mycroft * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.8 mycroft * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.8 mycroft * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.8 mycroft * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.8 mycroft * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.8 mycroft * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.8 mycroft * POSSIBILITY OF SUCH DAMAGE. 30 1.2 bouyer */ 31 1.2 bouyer 32 1.13 matt #ifndef _DEV_SCSIPI_SCSIPI_BASE_H_ 33 1.13 matt #define _DEV_SCSIPI_SCSIPI_BASE_H_ 34 1.13 matt 35 1.14 thorpej struct scsipi_xfer *scsipi_get_xs(struct scsipi_periph *, int); 36 1.14 thorpej void scsipi_put_xs(struct scsipi_xfer *); 37 1.2 bouyer 38 1.23 mlelstv static __inline struct scsipi_xfer *scsipi_make_xs_internal(struct scsipi_periph *, 39 1.23 mlelstv struct scsipi_generic *, int cmdlen, u_char *data_addr, 40 1.23 mlelstv int datalen, int retries, int timeout, struct buf *, 41 1.23 mlelstv int flags) __unused; 42 1.23 mlelstv 43 1.23 mlelstv static __inline struct scsipi_xfer *scsipi_make_xs_unlocked(struct scsipi_periph *, 44 1.23 mlelstv struct scsipi_generic *, int cmdlen, u_char *data_addr, 45 1.23 mlelstv int datalen, int retries, int timeout, struct buf *, 46 1.23 mlelstv int flags) __unused; 47 1.23 mlelstv 48 1.23 mlelstv static __inline struct scsipi_xfer *scsipi_make_xs_locked(struct scsipi_periph *, 49 1.17 reinoud struct scsipi_generic *, int cmdlen, u_char *data_addr, 50 1.3 cgd int datalen, int retries, int timeout, struct buf *, 51 1.14 thorpej int flags) __unused; 52 1.2 bouyer 53 1.2 bouyer /* 54 1.2 bouyer * Make a scsipi_xfer, and return a pointer to it. 55 1.2 bouyer */ 56 1.2 bouyer 57 1.21 christos static __inline struct scsipi_xfer * 58 1.23 mlelstv scsipi_make_xs_internal(struct scsipi_periph *periph, struct scsipi_generic *cmd, 59 1.17 reinoud int cmdlen, u_char *data_addr, int datalen, int retries, int timeout, 60 1.14 thorpej struct buf *bp, int flags) 61 1.2 bouyer { 62 1.2 bouyer struct scsipi_xfer *xs; 63 1.2 bouyer 64 1.11 bouyer if ((xs = scsipi_get_xs(periph, flags)) == NULL) 65 1.4 enami return (NULL); 66 1.2 bouyer 67 1.2 bouyer /* 68 1.2 bouyer * Fill out the scsipi_xfer structure. We don't know whose context 69 1.2 bouyer * the cmd is in, so copy it. 70 1.2 bouyer */ 71 1.15 mycroft memcpy(&xs->cmdstore, cmd, cmdlen); 72 1.2 bouyer xs->cmd = &xs->cmdstore; 73 1.2 bouyer xs->cmdlen = cmdlen; 74 1.2 bouyer xs->data = data_addr; 75 1.2 bouyer xs->datalen = datalen; 76 1.11 bouyer xs->xs_retries = retries; 77 1.2 bouyer xs->timeout = timeout; 78 1.2 bouyer xs->bp = bp; 79 1.2 bouyer 80 1.4 enami return (xs); 81 1.2 bouyer } 82 1.13 matt 83 1.23 mlelstv static __inline struct scsipi_xfer * 84 1.23 mlelstv scsipi_make_xs_unlocked(struct scsipi_periph *periph, struct scsipi_generic *cmd, 85 1.23 mlelstv int cmdlen, u_char *data_addr, int datalen, int retries, int timeout, 86 1.23 mlelstv struct buf *bp, int flags) 87 1.23 mlelstv { 88 1.23 mlelstv 89 1.23 mlelstv return scsipi_make_xs_internal(periph, cmd, cmdlen, data_addr, 90 1.23 mlelstv datalen, retries, timeout, bp, flags & ~XS_CTL_NOSLEEP); 91 1.23 mlelstv } 92 1.23 mlelstv 93 1.23 mlelstv static __inline struct scsipi_xfer * 94 1.23 mlelstv scsipi_make_xs_locked(struct scsipi_periph *periph, struct scsipi_generic *cmd, 95 1.23 mlelstv int cmdlen, u_char *data_addr, int datalen, int retries, int timeout, 96 1.23 mlelstv struct buf *bp, int flags) 97 1.23 mlelstv { 98 1.23 mlelstv 99 1.24 maya KDASSERT(mutex_owned(chan_mtx(periph->periph_channel))); 100 1.23 mlelstv return scsipi_make_xs_internal(periph, cmd, cmdlen, data_addr, 101 1.23 mlelstv datalen, retries, timeout, bp, flags | XS_CTL_NOSLEEP); 102 1.23 mlelstv } 103 1.23 mlelstv 104 1.13 matt #endif /* _DEV_SCSIPI_SCSIPI_BASE_H_ */ 105