1 /* Copyright 2000 Enhanced Software Technologies Inc. (http://www.estinc.com)
2 Copyright 2007-2008 by Robert Nelson <robertn@the-nelsons.org>
3 Written by Eric Lee Green <eric@badtux.org>
5 $Date: 2008-08-19 03:03:38 -0700 (Tue, 19 Aug 2008) $
8 This program is free software; you may redistribute and/or modify it under
9 the terms of the GNU General Public License Version 2 as published by the
10 Free Software Foundation.
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 /* This is the SCSI commands for FreeBSD */
20 DEVICE_TYPE SCSI_OpenDevice(char *DeviceName)
22 struct cam_device *DeviceFD = cam_open_pass(DeviceName, O_RDWR | O_EXCL, NULL);
24 FatalError("cannot open SCSI device '%s' - %m\n", DeviceName);
25 return (DEVICE_TYPE) DeviceFD;
29 void SCSI_CloseDevice(char *DeviceName, DEVICE_TYPE DeviceFD)
31 cam_close_device((struct cam_device *) DeviceFD);
34 #define PASS_HZ 1000*60
35 #define PASS_DEFAULT_TIMEOUT 5*PASS_HZ
36 static int pass_timeout = PASS_DEFAULT_TIMEOUT;
38 void SCSI_Set_Timeout(int secs)
40 pass_timeout=secs*PASS_HZ;
43 void SCSI_Default_Timeout(void) {
44 pass_timeout=5*PASS_HZ;
47 int SCSI_ExecuteCommand(DEVICE_TYPE DeviceFD,
48 Direction_T Direction,
53 RequestSense_T *RequestSense)
55 struct cam_device *dsp = (struct cam_device *) DeviceFD;
61 ccb = cam_getccb(dsp);
62 cdb = (CDB_T *) &ccb->csio.cdb_io.cdb_bytes; /* pointer to actual cdb. */
64 /* cam_getccb() zeros the CCB header only. So now clear the
65 * payload portion of the ccb.
67 bzero(&(&ccb->ccb_h)[1], sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr));
70 memcpy(cdb,CDB,CDB_Length);
72 /* set the command control block stuff.... the rather involved
73 * conditional expression sets the direction to NONE if there is no
74 * data to go in or out, and IN or OUT if we want data. Movement
75 * commands will have no data buffer, just a CDB, while INQUIRY and
76 * READ_ELEMENT_STATUS will have input data, and we don't have any
77 * stuff that outputs data -- yet -- but we may eventually.
79 cam_fill_csio( &ccb->csio,
83 (Direction == Input ? CAM_DIR_IN : CAM_DIR_OUT) :
84 CAM_DIR_NONE), /* flags */
85 MSG_SIMPLE_Q_TAG, /* tag action */
86 DataBuffer, /* data ptr */
87 DataBufferLength, /* xfer_len */
88 SSD_FULL_SIZE, /* sense_len */
89 CDB_Length, /* cdb_len */
90 pass_timeout /* timeout */ /* should be 5 minutes or more?! */
93 pass_timeout = PASS_DEFAULT_TIMEOUT; /* make sure it gets reset. */
94 memset(RequestSense, 0, sizeof(RequestSense_T)); /* clear sense buffer... */
96 if (Direction == Input)
98 memset(DataBuffer, 0, DataBufferLength);
101 Result = cam_send_ccb(DeviceFD,ccb);
103 (ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
105 /* copy our sense data, sigh... */
106 memcpy(RequestSense,(void *) &ccb->csio.sense_data,
107 min(sizeof(RequestSense_T), sizeof(struct scsi_sense_data)));
110 return -1; /* sorry! */
113 /* okay, we did good, maybe? */
115 return 0; /* and done? */