1 /* @(#)scsitransp.h	1.58 16/01/21 Copyright 1995-2016 J. Schilling */
2 /*
3  *	Definitions for commands that use functions from scsitransp.c
4  *
5  *	Copyright (c) 1995-2016 J. Schilling
6  */
7 /*
8  * The contents of this file are subject to the terms of the
9  * Common Development and Distribution License, Version 1.0 only
10  * (the "License").  You may not use this file except in compliance
11  * with the License.
12  *
13  * See the file CDDL.Schily.txt in this distribution for details.
14  * A copy of the CDDL is also available via the Internet at
15  * http://www.opensource.org/licenses/cddl1.txt
16  *
17  * The following exceptions apply:
18  * CDDL �3.6 needs to be replaced by: "You may create a Larger Work by
19  * combining Covered Software with other code if all other code is governed by
20  * the terms of a license that is OSI approved (see www.opensource.org) and
21  * you may distribute the Larger Work as a single product. In such a case,
22  * You must make sure the requirements of this License are fulfilled for
23  * the Covered Software."
24  *
25  * When distributing Covered Code, include this CDDL HEADER in each
26  * file and include the License file CDDL.Schily.txt from this distribution.
27  */
28 
29 #ifndef	_SCG_SCSITRANSP_H
30 #define	_SCG_SCSITRANSP_H
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 typedef	struct scg_scsi	SCSI;
37 
38 typedef struct {
39 	int	scsibus;	/* SCSI bus #    for next I/O		*/
40 	int	target;		/* SCSI target # for next I/O		*/
41 	int	lun;		/* SCSI lun #    for next I/O		*/
42 } scg_addr_t;
43 
44 #ifndef	_SCG_SCGOPS_H
45 #include <scg/scgops.h>
46 #endif
47 
48 typedef	int	(*scg_cb_t)	__PR((void *));
49 
50 struct scg_scsi {
51 	scg_ops_t *ops;		/* Ptr to low level SCSI transport ops	*/
52 	int	fd;		/* File descriptor for next I/O		*/
53 	scg_addr_t	addr;	/* SCSI address for next I/O		*/
54 	int	flags;		/* Libscg flags (see below)		*/
55 	int	dflags;		/* Drive specific flags (see below)	*/
56 	int	kdebug;		/* Kernel debug value for next I/O	*/
57 	int	debug;		/* Debug value for SCSI library		*/
58 	int	silent;		/* Be silent if value > 0		*/
59 	int	verbose;	/* Be verbose if value > 0		*/
60 	int	overbose;	/* Be verbose in open() if value > 0	*/
61 	int	disre_disable;
62 	int	deftimeout;
63 	int	noparity;	/* Do not use SCSI parity fo next I/O	*/
64 	int	dev;		/* from scsi_cdr.c			*/
65 	struct scg_cmd *scmd;
66 	char	*cmdname;
67 	char	*curcmdname;
68 	BOOL	running;
69 	int	error;		/* libscg error number			*/
70 
71 	long	maxdma;		/* Max DMA limit for this open instance	*/
72 	long	maxbuf;		/* Cur DMA buffer limit for this inst.	*/
73 				/* This is the size behind bufptr	*/
74 	struct timeval	*cmdstart;
75 	struct timeval	*cmdstop;
76 	const char	**nonstderrs;
77 	void	*local;		/* Local data from the low level code	*/
78 	void	*bufbase;	/* needed for scsi_freebuf()		*/
79 	void	*bufptr;	/* DMA buffer pointer for appl. use	*/
80 	char	*errstr;	/* Error string for scsi_open/sendmcd	*/
81 	char	*errbeg;	/* Pointer to begin of not flushed data	*/
82 	char	*errptr;	/* Actual write pointer into errstr	*/
83 	void	*errfile;	/* FILE to write errors to. NULL for not*/
84 				/* writing and leaving errs in errstr	*/
85 	scg_cb_t cb_fun;
86 	void	*cb_arg;
87 
88 	struct scsi_inquiry *inq;
89 	struct scsi_capacity *cap;
90 };
91 
92 /*
93  * Macros for accessing members of the scg address structure.
94  * scg_settarget() is the only function that is allowed to modify
95  * the values of the SCSI address.
96  */
97 #define	scg_scsibus(scgp)	(scgp)->addr.scsibus
98 #define	scg_target(scgp)	(scgp)->addr.target
99 #define	scg_lun(scgp)		(scgp)->addr.lun
100 
101 /*
102  * Flags for struct SCSI:
103  */
104 #define	SCGF_PERM_EXIT	0x01		/* Exit on permission problems */
105 #define	SCGF_PERM_PRINT	0x02		/* Print msg on permission problems */
106 #define	SCGF_IGN_RESID	0x04		/* Ignore DMA residual count	*/
107 
108 #define	SCGF_USER_FLAGS	0x04		/* All user definable flags */
109 
110 /*
111  * Drive specific flags for struct SCSI:
112  */
113 #define	DRF_MODE_DMA_OVR	0x0001		/* Drive gives DMA overrun */
114 						/* on mode sense	   */
115 
116 #define	SCSI_ERRSTR_SIZE	4096
117 
118 /*
119  * Libscg error codes:
120  */
121 #define	SCG_ERRBASE		1000000
122 #define	SCG_NOMEM		1000001
123 
124 /*
125  * Function codes for scg_version():
126  */
127 #define	SCG_VERSION		0	/* libscg or transport version */
128 #define	SCG_AUTHOR		1	/* Author of above */
129 #define	SCG_SCCS_ID		2	/* SCCS id of above */
130 #define	SCG_RVERSION		10	/* Remote transport version */
131 #define	SCG_RAUTHOR		11	/* Remote transport author */
132 #define	SCG_RSCCS_ID		12	/* Remote transport SCCS ID */
133 #define	SCG_KVERSION		20	/* Kernel transport version */
134 
135 /*
136  * Function codes for scg_reset():
137  */
138 #define	SCG_RESET_NOP		0	/* Test if reset is supported */
139 #define	SCG_RESET_TGT		1	/* Reset Target only */
140 #define	SCG_RESET_BUS		2	/* Reset complete SCSI Bus */
141 
142 /*
143  * Helpers for the error buffer in SCSI*
144  */
145 #define	scg_errsize(scgp)	((scgp)->errptr - (scgp)->errstr)
146 #define	scg_errrsize(scgp)	(SCSI_ERRSTR_SIZE - scg_errsize(scgp))
147 
148 /*
149  * From scsitransp.c:
150  */
151 extern	char	*scg_version		__PR((SCSI *scgp, int what));
152 extern	int	scg__open		__PR((SCSI *scgp, char *device));
153 extern	int	scg__close		__PR((SCSI *scgp));
154 extern	int	scg_numbus		__PR((SCSI *scgp));
155 extern	BOOL	scg_havebus		__PR((SCSI *scgp, int));
156 extern	int	scg_initiator_id	__PR((SCSI *scgp));
157 extern	int	scg_isatapi		__PR((SCSI *scgp));
158 extern	int	scg_reset		__PR((SCSI *scgp, int what));
159 extern	void	*scg_getbuf		__PR((SCSI *scgp, long));
160 extern	void	scg_freebuf		__PR((SCSI *scgp));
161 extern	long	scg_bufsize		__PR((SCSI *scgp, long));
162 extern	void	scg_setnonstderrs	__PR((SCSI *scgp, const char **));
163 extern	BOOL	scg_yes			__PR((char *));
164 extern	int	scg_cmd			__PR((SCSI *scgp));
165 extern	void	scg_vhead		__PR((SCSI *scgp));
166 extern	int	scg_svhead		__PR((SCSI *scgp, char *buf, int maxcnt));
167 extern	int	scg_vtail		__PR((SCSI *scgp));
168 extern	int	scg_svtail		__PR((SCSI *scgp, int *retp, char *buf, int maxcnt));
169 extern	void	scg_vsetup		__PR((SCSI *scgp));
170 extern	int	scg_getresid		__PR((SCSI *scgp));
171 extern	int	scg_getdmacnt		__PR((SCSI *scgp));
172 extern	BOOL	scg_cmd_err		__PR((SCSI *scgp));
173 extern	void	scg_printerr		__PR((SCSI *scgp));
174 #ifdef	EOF	/* stdio.h has been included */
175 extern	void	scg_fprinterr		__PR((SCSI *scgp, FILE *f));
176 #endif
177 extern	int	scg_sprinterr		__PR((SCSI *scgp, char *buf, int maxcnt));
178 extern	int	scg__sprinterr		__PR((SCSI *scgp, char *buf, int maxcnt));
179 extern	void	scg_printcdb		__PR((SCSI *scgp));
180 extern	int	scg_sprintcdb		__PR((SCSI *scgp, char *buf, int maxcnt));
181 extern	void	scg_printwdata		__PR((SCSI *scgp));
182 extern	int	scg_sprintwdata		__PR((SCSI *scgp, char *buf, int maxcnt));
183 extern	void	scg_printrdata		__PR((SCSI *scgp));
184 extern	int	scg_sprintrdata		__PR((SCSI *scgp, char *buf, int maxcnt));
185 extern	void	scg_printresult		__PR((SCSI *scgp));
186 extern	int	scg_sprintresult 	__PR((SCSI *scgp, char *buf, int maxcnt));
187 extern	void	scg_printstatus		__PR((SCSI *scgp));
188 extern	int	scg_sprintstatus 	__PR((SCSI *scgp, char *buf, int maxcnt));
189 #ifdef	EOF	/* stdio.h has been included */
190 extern	void	scg_fprbytes		__PR((FILE *, char *, unsigned char *, int));
191 extern	void	scg_fprascii		__PR((FILE *, char *, unsigned char *, int));
192 #endif
193 extern	void	scg_prbytes		__PR((char *, unsigned char *, int));
194 extern	void	scg_prascii		__PR((char *, unsigned char *, int));
195 extern	int	scg_sprbytes		__PR((char *buf, int maxcnt, char *, unsigned char *, int));
196 extern	int	scg_sprascii		__PR((char *buf, int maxcnt, char *, unsigned char *, int));
197 #ifdef	EOF	/* stdio.h has been included */
198 extern	void	scg_fprsense		__PR((FILE *f, unsigned char *, int));
199 #endif
200 extern	void	scg_prsense		__PR((unsigned char *, int));
201 extern	int	scg_sprsense		__PR((char *buf, int maxcnt, unsigned char *, int));
202 extern	int	scg_cmd_status		__PR((SCSI *scgp));
203 extern	int	scg_sense_key		__PR((SCSI *scgp));
204 extern	int	scg_sense_code		__PR((SCSI *scgp));
205 extern	int	scg_sense_qual		__PR((SCSI *scgp));
206 #ifdef	_SCG_SCSIREG_H
207 #ifdef	EOF	/* stdio.h has been included */
208 extern	void	scg_fprintdev		__PR((FILE *, struct scsi_inquiry *));
209 #endif
210 extern	void	scg_printdev		__PR((struct scsi_inquiry *));
211 #endif
212 extern	int	scg_printf		__PR((SCSI *scgp, const char *form, ...));
213 extern	int	scg_errflush		__PR((SCSI *scgp));
214 #ifdef	EOF	/* stdio.h has been included */
215 extern	int	scg_errfflush		__PR((SCSI *scgp, FILE *f));
216 #endif
217 
218 /*
219  * From scsierrmsg.c:
220  */
221 extern	const char	*scg_sensemsg	__PR((int, int, int,
222 						const char **, char *, int maxcnt));
223 #ifdef	_SCG_SCSISENSE_H
224 extern	int		scg__errmsg	__PR((SCSI *scgp, char *obuf, int maxcnt,
225 						struct scsi_sense *,
226 						struct scsi_status *,
227 						int));
228 #endif
229 
230 /*
231  * From scsiopen.c:
232  */
233 #ifdef	EOF	/* stdio.h has been included */
234 extern	int	scg_help	__PR((FILE *f));
235 #endif
236 extern	SCSI	*scg_open	__PR((char *scsidev, char *errs, int slen, int odebug, int be_verbose));
237 extern	int	scg_close	__PR((SCSI * scgp));
238 extern	void	scg_settimeout	__PR((SCSI * scgp, int timeout));
239 extern	SCSI	*scg_smalloc	__PR((void));
240 extern	void	scg_sfree	__PR((SCSI *scgp));
241 
242 /*
243  * From scsiopts.c:
244  */
245 extern	int	scg_opts	__PR((SCSI *scgp, const char *scgoptions));
246 
247 /*
248  * From scgsettarget.c:
249  */
250 extern	int	scg_settarget		__PR((SCSI *scgp, int scsibus, int target, int lun));
251 
252 /*
253  * From scsi-remote.c:
254  */
255 extern	scg_ops_t *scg_remote	__PR((void));
256 
257 /*
258  * From scsihelp.c:
259  */
260 #ifdef	EOF	/* stdio.h has been included */
261 extern	void	__scg_help	__PR((FILE *f, char *name, char *tcomment,
262 					char *tind,
263 					char *tspec,
264 					char *texample,
265 					BOOL mayscan,
266 					BOOL bydev));
267 #endif
268 
269 #ifdef	__cplusplus
270 }
271 #endif
272 
273 #endif	/* _SCG_SCSITRANSP_H */
274