Imported Debian patch 1.3.11-1
[debian/mtx] / scsi_sgi.c
1 /* Copyright 1997, 1998 Leonard Zubkoff <lnz@dandelion.com>
2    Changes copyright 2000 Eric Green <eric@badtux.org>
3
4 $Date: 2007-03-04 15:27:11 -0800 (Sun, 04 Mar 2007) $
5 $Revision: 164 $
6
7   This program is free software; you may redistribute and/or modify it under
8   the terms of the GNU General Public License Version 2 as published by the
9   Free Software Foundation.
10
11   This program is distributed in the hope that it will be useful, but
12   WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
13   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14   for complete details.
15
16 */
17
18 /* This is the SCSI commands for SGI Iris */
19 DEVICE_TYPE SCSI_OpenDevice(char *DeviceName)
20 {
21         dsreq_t *DeviceFD = dsopen(DeviceName, O_RDWR | O_EXCL);
22         if (DeviceFD == 0)
23                 FatalError("cannot open SCSI device '%s' - %m\n", DeviceName);
24         return (DEVICE_TYPE) DeviceFD;
25 }
26
27
28 void SCSI_CloseDevice(char *DeviceName, DEVICE_TYPE DeviceFD)
29 {
30         dsclose((dsreq_t *) DeviceFD);
31 }
32
33 #define MTX_HZ 1000 
34 #define MTX_DEFAULT_SCSI_TIMEOUT 60*5*MTX_HZ /* 5 minutes! */
35
36 static int mtx_default_timeout = MTX_DEFAULT_SCSI_TIMEOUT ;
37 void SCSI_Set_Timeout(int sec)
38 {
39         mtx_default_timeout=sec*MTX_HZ;
40 }
41
42 void SCSI_Default_Timeout()
43 {
44         mtx_default_timeout=MTX_DEFAULT_SCSI_TIMEOUT;
45 }
46
47 int SCSI_ExecuteCommand(DEVICE_TYPE DeviceFD,
48                                                 Direction_T Direction,
49                                                 CDB_T *CDB,
50                                                 int CDB_Length,
51                                                 void *DataBuffer,
52                                                 int DataBufferLength,
53                                                 RequestSense_T *RequestSense)
54 {
55         dsreq_t *dsp = (dsreq_t *) DeviceFD;
56         int Result;
57         memset(RequestSense, 0, sizeof(RequestSense_T));
58         memcpy(CMDBUF(dsp), CDB, CDB_Length);
59
60         if (Direction == Input)
61         {
62                 memset(DataBuffer, 0, DataBufferLength);
63                 filldsreq(dsp, (unsigned char *) DataBuffer, DataBufferLength, DSRQ_READ | DSRQ_SENSE);
64         }
65         else
66                 filldsreq(dsp, (unsigned char *) DataBuffer, DataBufferLength, DSRQ_WRITE | DSRQ_SENSE);
67
68         /* Set 5 minute timeout. */
69         /* TIME(dsp) = 300 * 1000; */
70         TIME(dsp) = mtx_default_timeout;
71         Result = doscsireq(getfd((dsp)), dsp);
72         
73         if (SENSESENT(dsp) > 0)
74         {
75                 memcpy(RequestSense, SENSEBUF(dsp), min(sizeof(RequestSense_T), SENSESENT(dsp)));
76         }
77
78         SCSI_Default_Timeout(); /* reset the mtx default timeout */
79         return Result;
80 }