/* ps_driver.h
 *
 * SCSI Generic Driver Interfaces
 *
 * $Header: /smsa/bsd:include/dev/ps_driver.h:bsd  1.9  $
 * $Source: /smsa/bsd:include/dev/ps_driver.h: $
 *
 * Copyright (c) 1989 Acorn Computers Ltd., Cambridge, England
 */

#ifndef __dev_ps_driver_h
#define __dev_ps_driver_h

#ifndef __dev_ps_device_h
#include "ps_device.h"
#endif
#ifndef __dev_ps_scsi_h
#include "ps_scsi.h"
#endif

/* SCSI Device Classes */
#define DC_GENERIC                (-1)
#define DC_DIRECT_ACCESS           (0)
#define DC_SEQUENTIAL_ACCESS       (1)
#define DC_PRINTER                 (2)
#define DC_PROCESSOR               (3)
#define DC_WRITE_ONCE              (4)
#define DC_READ_ONLY               (5)
#define DC_OPTICAL_MEMORY	   (7)

/* SCSI Extended Sense Keys */
#define K_NO_SENSE             (0x00)
#define K_RECOVERED_ERROR      (0x01)
#define K_NOT_READY            (0x02)
#define K_MEDIA_ERROR          (0x03)
#define K_HARDWARE_ERROR       (0x04)
#define K_ILLEGAL_REQUEST      (0x05)
#define K_UNIT_ATTENTION       (0x06)
#define K_DATA_PROTECT         (0x07)
#define K_BLANK_CHECK          (0x08)
#define K_VENDOR_UNIQUE        (0x09)
#define K_COPY_ABORTED         (0x0A)
#define K_ABORTED_COMMAND      (0x0B)
#define K_EQUAL                (0x0C)
#define K_VOLUME_OVERFLOW      (0x0D)
#define K_MISCOMPARE           (0x0E)
#define K_RESERVED             (0x0F)

/* Discriminants for the two types of entry */
#define D_BLOCK        1
#define D_RAW          2

/* Actions required of the (*dev_strategy)() routines */
#define VALIDATE       (0)
#define CALCULATE      (1)

/* Useful Macros */
#define LUN(n)         (((n) >> 5) & 0x07)
#define DC_BITS(n)     ((n) & 0x07)

/* Sundry Constants */
#define INVALID_LUN  (-1)


/* Exported Procedures */
extern void setup_cdb( /* int cmd, SCSI_Context *con, int type,
			  int lun, int size, int lba, int timeout */);
extern void make_cmd( /* SCSI_System s, SCSI_Context *c, int t_id,
			 int minor, int size, char *addr, int rw,
			 Callback_fn callback */);

extern void enqueue_bp( /* SCSI_System s, int t_id, int lun, struct buf *bp */);
extern SCSI_Cmd *get_ic( /* SCSI_System s, int t_id, int lun */ );
extern void free_ic( /* SCSI_System s, int t_id, int lun */ ); 

extern int do_command( /* SCSI_System s, int t_id, int lun, SCSI_Cmd *cmd */);

extern void strategy_callback( /* SCSI_Context *context */);
extern void ioctl_callback( /* SCSI_Context *context */);
extern void no_callback( /* SCSI_Context *context */);

extern SCSI_Info *find_info_rec( /* SCSI_System s, int t_id, int lun, int must */ );
#define MUST_EXIST         (1)
#define LOOKUP             (0)

/*
 * The SCSI_Info Record data field is divided into blocksize and
 * flags. These fields are:
 * bits  0-15: block size
 * bits 16-23: generic device flags
 * bits 24-31: device class specific flags
 */
#define BLOCK_SIZE         (0x0000ffff)
#define DEVICE_OPENED      (1<<16)
#define WRITE_PROTECTED    (1<<17)
#define OFFLINE            (1<<18)

extern int convert_bigendian( /* char *blocksize, int length */ );
extern int a_power_of_2( /* int number */ );

#endif/*__dev_ps_driver_h*/

/* EOF ps_driver.h */
