xref: /illumos-gate/usr/src/uts/common/sys/scsi/scsi_resource.h (revision f808c858fa61e7769218966759510a8b1190dfcf)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_SCSI_SCSI_RESOURCE_H
27 #define	_SYS_SCSI_SCSI_RESOURCE_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef __lock_lint
32 #include <note.h>
33 #endif
34 #include <sys/scsi/scsi_types.h>
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 /*
41  * SCSI Resource Function Declarations
42  */
43 
44 /*
45  * Defines for stating preferences in resource allocation
46  */
47 
48 #define	NULL_FUNC	((int (*)())0)
49 #define	SLEEP_FUNC	((int (*)())1)
50 
51 #ifdef	_KERNEL
52 /*
53  * Defines for the flags to scsi_init_pkt()
54  */
55 #define	PKT_CONSISTENT	0x0001		/* this is an 'iopb' packet */
56 #define	PKT_DMA_PARTIAL	0x040000	/* partial xfer ok */
57 
58 /*
59  * Old PKT_CONSISTENT value for binary compatibility with x86 2.1
60  */
61 #define	PKT_CONSISTENT_OLD	0x001000
62 
63 /*
64  * Kernel function declarations
65  */
66 struct buf	*scsi_alloc_consistent_buf(struct scsi_address *,
67 		    struct buf *, size_t, uint_t, int (*)(caddr_t), caddr_t);
68 struct scsi_pkt	*scsi_init_pkt(struct scsi_address *,
69 		    struct scsi_pkt *, struct buf *, int, int, int, int,
70 		    int (*)(caddr_t), caddr_t);
71 void		scsi_destroy_pkt(struct scsi_pkt *);
72 void		scsi_free_consistent_buf(struct buf *);
73 struct scsi_pkt	*scsi_resalloc(struct scsi_address *, int,
74 		    int, opaque_t, int (*)(void));
75 struct scsi_pkt	*scsi_pktalloc(struct scsi_address *, int, int, int (*)(void));
76 struct scsi_pkt	*scsi_dmaget(struct scsi_pkt *, opaque_t, int (*)(void));
77 void		scsi_dmafree(struct scsi_pkt *);
78 void		scsi_sync_pkt(struct scsi_pkt *);
79 void		scsi_resfree(struct scsi_pkt *);
80 
81 /*
82  * Private wrapper for scsi_pkt's allocated via scsi_init_cache_pkt()
83  */
84 struct scsi_pkt_cache_wrapper {
85 	struct scsi_pkt		 pcw_pkt;
86 	uint_t			 pcw_total_xfer;
87 	uint_t			 pcw_curwin;
88 	uint_t			 pcw_totalwin;
89 	uint_t			 pcw_granular;
90 	struct buf		*pcw_bp;
91 	ddi_dma_cookie_t	 pcw_cookie;
92 	void			(*pcw_orig_comp)(struct scsi_pkt *);
93 	uint_t			 pcw_flags;
94 };
95 
96 #ifdef __lock_lint
97 _NOTE(SCHEME_PROTECTS_DATA("unique per packet", \
98 	scsi_pkt_cache_wrapper::pcw_orig_comp))
99 #endif
100 struct buf	*scsi_pkt2bp(struct scsi_pkt *);
101 
102 #define	PCW_NEED_EXT_CDB	0x0001
103 #define	PCW_NEED_EXT_TGT	0x0002
104 #define	PCW_NEED_EXT_SCB	0x0004
105 #define	PCW_BOUND		0x0020
106 
107 /*
108  * Private defines i.e. not part of the DDI.
109  */
110 #define	DEFAULT_CDBLEN	16
111 #define	DEFAULT_PRIVLEN	0
112 #define	DEFAULT_SCBLEN	(sizeof (struct scsi_arq_status))
113 
114 /*
115  * Preliminary version of the SCSA specification
116  * mentioned a routine called scsi_pktfree, which
117  * turned out to be semantically equivialent to
118  * scsi_resfree.
119  */
120 #define	scsi_pktfree	scsi_resfree
121 
122 #endif	/* _KERNEL */
123 
124 #ifdef	__cplusplus
125 }
126 #endif
127 
128 #endif	/* _SYS_SCSI_SCSI_RESOURCE_H */
129