xref: /illumos-gate/usr/src/uts/common/sys/scsi/scsi_resource.h (revision 69b1fd3f24d0ee2e682883606201c61f52085805)
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 2009 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 
30 #ifdef __lock_lint
31 #include <note.h>
32 #endif
33 #include <sys/scsi/scsi_types.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 /*
40  * SCSI Resource Function Declarations
41  */
42 
43 /*
44  * Defines for stating preferences in resource allocation
45  */
46 
47 #define	NULL_FUNC	((int (*)())0)
48 #define	SLEEP_FUNC	((int (*)())1)
49 
50 #ifdef	_KERNEL
51 /*
52  * Defines for the flags to scsi_init_pkt()
53  */
54 #define	PKT_CONSISTENT	0x0001		/* this is an 'iopb' packet */
55 #define	PKT_DMA_PARTIAL	0x040000	/* partial xfer ok */
56 #define	PKT_XARQ	0x080000	/* request for extra sense */
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 int		scsi_pkt_allocated_correctly(struct scsi_pkt *);
74 struct scsi_pkt	*scsi_dmaget(struct scsi_pkt *, opaque_t, int (*)(void));
75 void		scsi_dmafree(struct scsi_pkt *);
76 void		scsi_sync_pkt(struct scsi_pkt *);
77 
78 /*
79  * Private wrapper for scsi_pkt's allocated via scsi_init_cache_pkt()
80  */
81 struct scsi_pkt_cache_wrapper {
82 	struct scsi_pkt		 pcw_pkt;
83 	int			 pcw_magic;
84 	uint_t			 pcw_total_xfer;
85 	uint_t			 pcw_curwin;
86 	uint_t			 pcw_totalwin;
87 	uint_t			 pcw_granular;
88 	struct buf		*pcw_bp;
89 	ddi_dma_cookie_t	 pcw_cookie;
90 	uint_t			 pcw_flags;
91 };
92 
93 #ifdef __lock_lint
94 _NOTE(SCHEME_PROTECTS_DATA("unique per packet",
95 	scsi_pkt_cache_wrapper::pcw_bp
96 	scsi_pkt_cache_wrapper::pcw_curwin
97 	scsi_pkt_cache_wrapper::pcw_flags
98 	scsi_pkt_cache_wrapper::pcw_granular
99 	scsi_pkt_cache_wrapper::pcw_total_xfer
100 	scsi_pkt_cache_wrapper::pcw_totalwin))
101 #endif
102 struct buf	*scsi_pkt2bp(struct scsi_pkt *);
103 
104 #define	PCW_NEED_EXT_CDB	0x0001
105 #define	PCW_NEED_EXT_TGT	0x0002
106 #define	PCW_NEED_EXT_SCB	0x0004
107 #define	PCW_BOUND		0x0020
108 
109 /*
110  * Private defines i.e. not part of the DDI.
111  */
112 #define	DEFAULT_CDBLEN	16
113 #define	DEFAULT_PRIVLEN	0
114 #define	DEFAULT_SCBLEN	(sizeof (struct scsi_arq_status))
115 
116 /* Private functions */
117 size_t		scsi_pkt_size();
118 void		scsi_size_clean(dev_info_t *);
119 
120 /* Obsolete kernel functions: */
121 struct scsi_pkt	*scsi_pktalloc(struct scsi_address *, int, int, int (*)(void));
122 struct scsi_pkt	*scsi_resalloc(struct scsi_address *, int,
123 		    int, opaque_t, int (*)(void));
124 void		scsi_resfree(struct scsi_pkt *);
125 #define	scsi_pktfree	scsi_resfree
126 
127 #endif	/* _KERNEL */
128 
129 #ifdef	__cplusplus
130 }
131 #endif
132 
133 #endif	/* _SYS_SCSI_SCSI_RESOURCE_H */
134