xref: /titanic_51/usr/src/uts/common/sys/scsi/scsi_resource.h (revision 1c9de0c9325f9f5d3540e19a4ad3691e6d50c0f8)
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 #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 #define	PKT_XARQ	0x080000	/* request for extra sense */
58 
59 /*
60  * Old PKT_CONSISTENT value for binary compatibility with x86 2.1
61  */
62 #define	PKT_CONSISTENT_OLD	0x001000
63 
64 /*
65  * Kernel function declarations
66  */
67 struct buf	*scsi_alloc_consistent_buf(struct scsi_address *,
68 		    struct buf *, size_t, uint_t, int (*)(caddr_t), caddr_t);
69 struct scsi_pkt	*scsi_init_pkt(struct scsi_address *,
70 		    struct scsi_pkt *, struct buf *, int, int, int, int,
71 		    int (*)(caddr_t), caddr_t);
72 void		scsi_destroy_pkt(struct scsi_pkt *);
73 void		scsi_free_consistent_buf(struct buf *);
74 int		scsi_pkt_allocated_correctly(struct scsi_pkt *);
75 struct scsi_pkt	*scsi_dmaget(struct scsi_pkt *, opaque_t, int (*)(void));
76 void		scsi_dmafree(struct scsi_pkt *);
77 void		scsi_sync_pkt(struct scsi_pkt *);
78 
79 /*
80  * Private wrapper for scsi_pkt's allocated via scsi_init_cache_pkt()
81  */
82 struct scsi_pkt_cache_wrapper {
83 	struct scsi_pkt		 pcw_pkt;
84 	int			 pcw_magic;
85 	uint_t			 pcw_total_xfer;
86 	uint_t			 pcw_curwin;
87 	uint_t			 pcw_totalwin;
88 	uint_t			 pcw_granular;
89 	struct buf		*pcw_bp;
90 	ddi_dma_cookie_t	 pcw_cookie;
91 	void			(*pcw_orig_comp)(struct scsi_pkt *);
92 	uint_t			 pcw_flags;
93 };
94 
95 #ifdef __lock_lint
96 _NOTE(SCHEME_PROTECTS_DATA("unique per packet", \
97 	scsi_pkt_cache_wrapper::pcw_orig_comp))
98 #endif
99 struct buf	*scsi_pkt2bp(struct scsi_pkt *);
100 
101 #define	PCW_NEED_EXT_CDB	0x0001
102 #define	PCW_NEED_EXT_TGT	0x0002
103 #define	PCW_NEED_EXT_SCB	0x0004
104 #define	PCW_BOUND		0x0020
105 
106 /*
107  * Private defines i.e. not part of the DDI.
108  */
109 #define	DEFAULT_CDBLEN	16
110 #define	DEFAULT_PRIVLEN	0
111 #define	DEFAULT_SCBLEN	(sizeof (struct scsi_arq_status))
112 
113 /* Private functions */
114 size_t		scsi_pkt_size();
115 void		scsi_size_clean(dev_info_t *);
116 
117 /* Obsolete kernel functions: */
118 struct scsi_pkt	*scsi_pktalloc(struct scsi_address *, int, int, int (*)(void));
119 struct scsi_pkt	*scsi_resalloc(struct scsi_address *, int,
120 		    int, opaque_t, int (*)(void));
121 void		scsi_resfree(struct scsi_pkt *);
122 #define	scsi_pktfree	scsi_resfree
123 
124 #endif	/* _KERNEL */
125 
126 #ifdef	__cplusplus
127 }
128 #endif
129 
130 #endif	/* _SYS_SCSI_SCSI_RESOURCE_H */
131