xref: /titanic_52/usr/src/uts/common/sys/scsi/scsi_resource.h (revision 71269a2275bf5a143dad6461eee2710a344e7261)
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 2008 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 	void			(*pcw_orig_comp)(struct scsi_pkt *);
91 	uint_t			 pcw_flags;
92 };
93 
94 #ifdef __lock_lint
95 _NOTE(SCHEME_PROTECTS_DATA("unique per packet",
96 	scsi_pkt_cache_wrapper::pcw_orig_comp
97 	scsi_pkt_cache_wrapper::pcw_bp
98 	scsi_pkt_cache_wrapper::pcw_curwin
99 	scsi_pkt_cache_wrapper::pcw_flags
100 	scsi_pkt_cache_wrapper::pcw_granular
101 	scsi_pkt_cache_wrapper::pcw_total_xfer
102 	scsi_pkt_cache_wrapper::pcw_totalwin))
103 #endif
104 struct buf	*scsi_pkt2bp(struct scsi_pkt *);
105 
106 #define	PCW_NEED_EXT_CDB	0x0001
107 #define	PCW_NEED_EXT_TGT	0x0002
108 #define	PCW_NEED_EXT_SCB	0x0004
109 #define	PCW_BOUND		0x0020
110 
111 /*
112  * Private defines i.e. not part of the DDI.
113  */
114 #define	DEFAULT_CDBLEN	16
115 #define	DEFAULT_PRIVLEN	0
116 #define	DEFAULT_SCBLEN	(sizeof (struct scsi_arq_status))
117 
118 /* Private functions */
119 size_t		scsi_pkt_size();
120 void		scsi_size_clean(dev_info_t *);
121 
122 /* Obsolete kernel functions: */
123 struct scsi_pkt	*scsi_pktalloc(struct scsi_address *, int, int, int (*)(void));
124 struct scsi_pkt	*scsi_resalloc(struct scsi_address *, int,
125 		    int, opaque_t, int (*)(void));
126 void		scsi_resfree(struct scsi_pkt *);
127 #define	scsi_pktfree	scsi_resfree
128 
129 #endif	/* _KERNEL */
130 
131 #ifdef	__cplusplus
132 }
133 #endif
134 
135 #endif	/* _SYS_SCSI_SCSI_RESOURCE_H */
136