#include "mcdp.h"

/**
 * Copyright (C) 2001-2006 Tino Reichardt
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License Version 2, as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/*
 * author:         Tino Reichardt <milky-mcdp@mcmilk.de>
 * status:         unknown
 *
 * details:
 * - for the Sun USCSI interface
 *
 * todo:
 * - is untestet
 * - just an implementation with prev. reading of the include files :)
 */

#if WANT_SUN_USCSI
int cmd_sun_uscsi(scmd_t *cmd)
{
	struct uscsi_cmd io;
	int r;
#if DEBUG_CDB
	char *file="SUN-uscsi.log";
#endif

	if (isset(cd->flags, F_CANT_SEND_CMD)) return -1;
	byte_zero(&io, sizeof(io));

	set(io.uscsi_flags, USCSI_RQENABLE);
	if isset(d, D_READ)  set(io.uscsi_flags, USCSI_READ);
	if isset(d, D_WRITE) set(io.uscsi_flags, USCSI_WRITE);

	uscsi_cdb    = (caddr_t)cmb->cmb.s;     /* cdb to send to target */
	uscsi_cdblen = (uchar_t)cmb->cmblen;    /* # of valid cdb bytes */
	uscsi_bufaddr= (caddr_t)cmb->buf.s;     /* i/o source/destination */
	uscsi_buflen = (size_t)cmb->buflen;     /* size of i/o to take place */
	uscsi_rqbuf  = (caddr_t)cmb->sense.s;   /* request sense buffer */
	uscsi_rqlen  = (uchar_t)MCDP_MAX_SENSE; /* size of uscsi_rqbuf */

#if DEBUG_CDB
	cmd_debug(file, CDB_BEFORE);
#endif

	r=ioctl(cd->fd, SG_IO, &io);

#if DEBUG_CDB
	cmd_debug(file, CDB_AFTER);
#endif

	return r;
}
#endif

#if 0
/* definition for user-scsi command structure */
struct uscsi_cmd {
	int		uscsi_flags;	/* read, write, etc. see below */
	short		uscsi_status;	/* resulting status  */
	short		uscsi_timeout;	/* Command Timeout */
	caddr_t		uscsi_cdb;	/* cdb to send to target */
	caddr_t		uscsi_bufaddr;	/* i/o source/destination */
	size_t		uscsi_buflen;	/* size of i/o to take place */
	size_t		uscsi_resid;	/* resid from i/o operation */
	uchar_t		uscsi_cdblen;	/* # of valid cdb bytes */
	uchar_t		uscsi_rqlen;	/* size of uscsi_rqbuf */
	uchar_t		uscsi_rqstatus;	/* status of request sense cmd */
	uchar_t		uscsi_rqresid;	/* resid of request sense cmd */
	caddr_t		uscsi_rqbuf;	/* request sense buffer */
	void		*uscsi_reserved_5;	/* Reserved for Future Use */
};

/*
 * generic flags
 */
#define	USCSI_WRITE	0x00000	/* send data to device */
#define	USCSI_SILENT	0x00001	/* no error messages */
#define	USCSI_DIAGNOSE	0x00002	/* fail if any error occurs */
#define	USCSI_ISOLATE	0x00004	/* isolate from normal commands */
#define	USCSI_READ	0x00008	/* get data from device */
#define	USCSI_RESET	0x04000	/* Reset target */
#define	USCSI_RESET_ALL	0x08000	/* Reset all targets */
#define	USCSI_RQENABLE	0x10000	/* Enable Request Sense extensions */

#endif

