1 /* Copyright 2000 Enhanced Software Technologies Inc. (http://www.estinc.com)
2 Written by Eric Lee Green <eric@badtux.org>
4 $Date: 2007-03-04 15:27:11 -0800 (Sun, 04 Mar 2007) $
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.
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
18 /* This is the SCSI commands for FreeBSD */
19 DEVICE_TYPE SCSI_OpenDevice(char *DeviceName)
21 struct cam_device *DeviceFD = cam_open_pass(DeviceName, O_RDWR | O_EXCL, NULL);
23 FatalError("cannot open SCSI device '%s' - %m\n", DeviceName);
24 return (DEVICE_TYPE) DeviceFD;
28 void SCSI_CloseDevice(char *DeviceName, DEVICE_TYPE DeviceFD)
30 cam_close_device((struct cam_device *) DeviceFD);
33 #define PASS_HZ 1000*60
34 #define PASS_DEFAULT_TIMEOUT 5*PASS_HZ
35 static int pass_timeout = PASS_DEFAULT_TIMEOUT;
37 void SCSI_Set_Timeout(int secs)
39 pass_timeout=secs*PASS_HZ;
42 void SCSI_Default_Timeout(void) {
43 pass_timeout=5*PASS_HZ;
46 int SCSI_ExecuteCommand(DEVICE_TYPE DeviceFD,
47 Direction_T Direction,
52 RequestSense_T *RequestSense)
54 struct cam_device *dsp = (struct cam_device *) DeviceFD;
60 ccb = cam_getccb(dsp);
61 cdb = (CDB_T *) &ccb->csio.cdb_io.cdb_bytes; /* pointer to actual cdb. */
63 /* cam_getccb() zeros the CCB header only. So now clear the
64 * payload portion of the ccb.
66 bzero(&(&ccb->ccb_h)[1], sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr));
69 memcpy(cdb,CDB,CDB_Length);
71 /* set the command control block stuff.... the rather involved
72 * conditional expression sets the direction to NONE if there is no
73 * data to go in or out, and IN or OUT if we want data. Movement
74 * commands will have no data buffer, just a CDB, while INQUIRY and
75 * READ_ELEMENT_STATUS will have input data, and we don't have any
76 * stuff that outputs data -- yet -- but we may eventually.
78 cam_fill_csio( &ccb->csio,
82 (Direction == Input ? CAM_DIR_IN : CAM_DIR_OUT) :
83 CAM_DIR_NONE), /* flags */
84 MSG_SIMPLE_Q_TAG, /* tag action */
85 DataBuffer, /* data ptr */
86 DataBufferLength, /* xfer_len */
87 SSD_FULL_SIZE, /* sense_len */
88 CDB_Length, /* cdb_len */
89 pass_timeout /* timeout */ /* should be 5 minutes or more?! */
92 pass_timeout = PASS_DEFAULT_TIMEOUT; /* make sure it gets reset. */
93 memset(RequestSense, 0, sizeof(RequestSense_T)); /* clear sense buffer... */
95 if (Direction == Input)
97 memset(DataBuffer, 0, DataBufferLength);
100 Result = cam_send_ccb(DeviceFD,ccb);
102 (ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
104 /* copy our sense data, sigh... */
105 memcpy(RequestSense,(void *) &ccb->csio.sense_data,
106 min(sizeof(RequestSense_T), sizeof(struct scsi_sense_data)));
109 return -1; /* sorry! */
112 /* okay, we did good, maybe? */
114 return 0; /* and done? */