1 /*
2  *   toscsi.h
3  *
4  *   SCSI access functions for tosha.
5  *
6  *   Oliver Fromme  <olli@fromme.com>
7  *
8  *   Copyright (C) 1997,1998,1999
9  *        Oliver Fromme.  All rights reserved.
10  *
11  *   Redistribution and use in source and binary forms, with or without
12  *   modification, are permitted provided that the following conditions
13  *   are met:
14  *   1. Redistributions of source code must retain the above copyright
15  *      notice, this list of conditions and the following disclaimer.
16  *   2. Redistributions in binary form must reproduce the above copyright
17  *      notice, this list of conditions and the following disclaimer in the
18  *      documentation and/or other materials provided with the distribution.
19  *   3. Neither the name of the author nor the names of any co-contributors
20  *      may be used to endorse or promote products derived from this software
21  *      without specific prior written permission.
22  *
23  *   THIS SOFTWARE IS PROVIDED BY OLIVER FROMME AND CONTRIBUTORS ``AS IS'' AND
24  *   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  *   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  *   ARE DISCLAIMED.  IN NO EVENT SHALL OLIVER FROMME OR CONTRIBUTORS BE LIABLE
27  *   FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  *   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  *   OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  *   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  *   LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  *   OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  *   SUCH DAMAGE.
34  *
35  *   @(#)$Id: toscsi.h,v 1.2 1999/01/01 23:32:02 olli Exp $
36  */
37 
38 static const char cvsid_toscsi_h[]
39     = "@(#)$Id: toscsi.h,v 1.2 1999/01/01 23:32:02 olli Exp $";
40 
41 #ifdef CAM
42 #	include <bus/cam/cam.h>
43 #	include <bus/cam/cam_ccb.h>
44 #	include <bus/cam/scsi/scsi_all.h>
45 #	include <bus/cam/scsi/scsi_da.h>
46 #	include <bus/cam/scsi/scsi_pass.h>
47 #	include <bus/cam/scsi/scsi_message.h>
48 #	include <camlib.h>
49 #else
50 #	include <sys/scsiio.h>
51 #	include <scsi.h>
52 #endif
53 
54 /*
55  *   The controller returns a non-zero code sometimes, even
56  *   though everything seems to be alright (at least with my
57  *   hardware and software), therefore we redefine the SCSIREQ-
58  *   ERROR macro here without that conroller return code.
59  *   I'm aware of the fact that this is a dirty hack, but I
60  *   wasn't able to find a better solution.
61  */
62 
63 #ifndef CAM
64 #	undef SCSIREQ_ERROR
copy_le2(unsigned char * buf,unsigned int x)65 #	define SCSIREQ_ERROR(SR) (\
66 		0 \
67 		|| SR->senselen_used	/* Sent sense */ \
68 		|| SR->retsts      	/* SCSI transfer status */ \
69 		|| SR->error       	/* copy of errno */ \
70 	)
71 #endif
72 
73 #ifdef CAM
74 #	define TOSCSI_READ  CAM_DIR_IN  | CAM_DEV_QFRZDIS
75 #	define TOSCSI_WRITE CAM_DIR_OUT | CAM_DEV_QFRZDIS
76 	typedef struct {
77 		union ccb *ccb;
78 		struct cam_device *cam_dev;
79 	} toscsi_handle;
80 #else
81 #	define TOSCSI_READ  SCCMD_READ
82 #	define TOSCSI_WRITE SCCMD_WRITE
83 	typedef struct {
84 		struct scsireq *sreq;	/* SCSI device request structure */
85 		int scsifd;		/* SCSI device file descriptor */
copy_be4(unsigned char * buf,unsigned int x)86 	} toscsi_handle;
87 #endif
88 
89 
90 toscsi_handle *toscsi_open (const char *devname);
91 int toscsi_request    (toscsi_handle *hdl, ulong size, ulong flags, char *cmd);
92 int toscsi_readsectors(toscsi_handle *hdl, int start, int endpp, int outfd);
93 int toscsi_readmode   (toscsi_handle *hdl, int sector);
94 void toscsi_close     (toscsi_handle *hdl);
95 
96 /* EOF */
97