130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* 	pg.h (c) 1998  Grant R. Guenther <grant@torque.net>
230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng 		       Under the terms of the GNU General Public License
330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	pg.h defines the user interface to the generic ATAPI packet
630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng        command driver for parallel port ATAPI devices (pg). The
730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	driver is loosely modelled after the generic SCSI driver, sg,
830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	although the actual interface is different.
930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
1030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	The pg driver provides a simple character device interface for
1130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng        sending ATAPI commands to a device.  With the exception of the
1230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	ATAPI reset operation, all operations are performed by a pair
1330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng        of read and write operations to the appropriate /dev/pgN device.
1430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	A write operation delivers a command and any outbound data in
1530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng        a single buffer.  Normally, the write will succeed unless the
1630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng        device is offline or malfunctioning, or there is already another
1730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	command pending.  If the write succeeds, it should be followed
1830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng        immediately by a read operation, to obtain any returned data and
1930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng        status information.  A read will fail if there is no operation
2030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng        in progress.
2130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
2230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	As a special case, the device can be reset with a write operation,
2330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng        and in this case, no following read is expected, or permitted.
2430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
2530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	There are no ioctl() operations.  Any single operation
2630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	may transfer at most PG_MAX_DATA bytes.  Note that the driver must
2730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng        copy the data through an internal buffer.  In keeping with all
2830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	current ATAPI devices, command packets are assumed to be exactly
2930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	12 bytes in length.
3030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
3130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	To permit future changes to this interface, the headers in the
3230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	read and write buffers contain a single character "magic" flag.
3330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng        Currently this flag must be the character "P".
3430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
3530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng*/
3630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
3730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PG_MAGIC	'P'
3830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PG_RESET	'Z'
3930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PG_COMMAND	'C'
4030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
4130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PG_MAX_DATA	32768
4230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
4330692c65c4174412c90e79489e98ab85c1a7412fBen Chengstruct pg_write_hdr {
4430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
4530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	char	magic;		/* == PG_MAGIC */
4630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	char	func;		/* PG_RESET or PG_COMMAND */
4730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	int     dlen;		/* number of bytes expected to transfer */
4830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	int     timeout;	/* number of seconds before timeout */
4930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	char	packet[12];	/* packet command */
5030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
5130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng};
5230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
5330692c65c4174412c90e79489e98ab85c1a7412fBen Chengstruct pg_read_hdr {
5430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
5530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	char	magic;		/* == PG_MAGIC */
5630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	char	scsi;		/* "scsi" status == sense key */
5730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	int	dlen;		/* size of device transfer request */
5830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	int     duration;	/* time in seconds command took */
5930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	char    pad[12];	/* not used */
6030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
6130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng};
6230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
6330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* end of pg.h */
64