1 /*
2  *   libdi - scsipt SCSI Device Interface Library
3  *
4  *   Copyright (C) 1993-2004  Ti Kan
5  *   E-mail: xmcd@amb.org
6  *
7  *   This program is free software; you can redistribute it and/or modify
8  *   it under the terms of the GNU General Public License as published by
9  *   the Free Software Foundation; either version 2 of the License, or
10  *   (at your option) any later version.
11  *
12  *   This program is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with this program; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21 
22 /*
23  *   Linux support
24  *
25  *   This software fragment contains code that interfaces the
26  *   application to the Linux operating system.
27  */
28 #ifndef __OS_LINUX_H__
29 #define __OS_LINUX_H__
30 
31 #if defined(_LINUX) && \
32     (defined(DI_SCSIPT) || defined(CDDA_RD_SCSIPT)) && \
33     !defined(DEMO_ONLY)
34 
35 #ifndef lint
36 static char *_os_linux_h_ident_ = "@(#)os_linux.h	6.32 04/01/14";
37 #endif
38 
39 #include <sys/param.h>
40 #include <linux/major.h>
41 #include <linux/kdev_t.h>
42 #include <scsi/scsi.h>
43 #include <scsi/sg.h>
44 
45 /* Command result word macros */
46 #ifndef status_byte
47 #define status_byte(result)		(((result) >> 1) & 0xf)
48 #endif
49 #ifndef msg_byte
50 #define msg_byte(result)		(((result) >> 8) & 0xff)
51 #endif
52 #ifndef host_byte
53 #define host_byte(result)		(((result) >> 16) & 0xff)
54 #endif
55 #ifndef driver_byte
56 #define driver_byte(result)		(((result) >> 24) & 0xff)
57 #endif
58 
59 /* Linux SCSI ioctl commands */
60 #ifndef SCSI_IOCTL_SEND_COMMAND
61 #define SCSI_IOCTL_SEND_COMMAND		1
62 #endif
63 #ifndef SCSI_IOCTL_TEST_UNIT_READY
64 #define SCSI_IOCTL_TEST_UNIT_READY	2
65 #endif
66 #ifndef SCSI_IOCTL_GET_IDLUN
67 #define SCSI_IOCTL_GET_IDLUN		0x5382
68 #endif
69 #ifndef SCSI_IOCTL_GET_BUS_NUMBER
70 #define SCSI_IOCTL_GET_BUS_NUMBER	0x5386
71 #endif
72 
73 /* Maximum data transfer length for ioctl mode.  This should correspond
74  * to MAX_BUF in the Linux kernel drivers/scsi/scsi_ioctl.c file.
75  */
76 #define SCSI_IOCTL_MAX_BUF		4096
77 
78 /* Maximum data transfer length for SCSI generic mode.  This should be
79  * defined in <scsi/sg.h>, but for old kernels this may not be the case.
80  */
81 #ifndef SG_BIG_BUFF
82 #define SG_BIG_BUFF			32768
83 #endif
84 
85 /* Max number of SCSI generic devices supported */
86 #define MAX_SG_DEVS			26
87 
88 
89 /* Structure used with the SCSI_IOCTL_GET_IDLUN ioctl */
90 typedef struct scsi_idlun {
91 	int			four_in_one;
92 	int			host_unique_id;
93 } scsi_idlun_t;
94 
95 
96 /* SCSI Generic request and response structure */
97 typedef struct sg_request {
98 	struct sg_header	header;
99 	byte_t			bytes[SG_BIG_BUFF];
100 } sg_request_t;
101 
102 
103 #define OS_MODULE	/* Indicate that this is compiled on a supported OS */
104 #define SETUID_ROOT	/* Setuid root privilege is required */
105 
106 
107 /* Public function prototypes */
108 extern bool_t	pthru_send(di_dev_t *, int, byte_t *, size_t, byte_t *, size_t,
109 			   byte_t *, size_t, byte_t, int, bool_t);
110 extern di_dev_t	*pthru_open(char *);
111 extern void	pthru_close(di_dev_t *);
112 extern void	pthru_enable(di_dev_t *, int);
113 extern void	pthru_disable(di_dev_t *, int);
114 extern bool_t	pthru_is_enabled(di_dev_t *, int);
115 extern size_t	pthru_maxfer(di_dev_t *);
116 extern char	*pthru_vers(void);
117 
118 #endif	/* _LINUX DI_SCSIPT CDDA_RD_SCSIPT DEMO_ONLY */
119 
120 #endif	/* __OS_LINUX_H__ */
121 
122