141480Smckusick /* 2*63151Sbostic * Copyright (c) 1990, 1993 3*63151Sbostic * The Regents of the University of California. All rights reserved. 441480Smckusick * 541480Smckusick * This code is derived from software contributed to Berkeley by 641480Smckusick * Van Jacobson of Lawrence Berkeley Laboratory. 741480Smckusick * 841480Smckusick * %sccs.include.redist.c% 941480Smckusick * 10*63151Sbostic * @(#)scsireg.h 8.1 (Berkeley) 06/10/93 1141480Smckusick */ 1241480Smckusick 1341480Smckusick /* 1441480Smckusick * HP 98265A SCSI Interface Hardware Description. 1541480Smckusick */ 1641480Smckusick 1741480Smckusick struct scsidevice { 1841480Smckusick u_char p0, scsi_id; 1941480Smckusick #define ID_MASK 0x1f 2041480Smckusick #define SCSI_ID 0x07 2141480Smckusick #define ID_WORD_DMA 0x20 2241480Smckusick u_char p2, scsi_csr; 2341480Smckusick #define CSR_IE 0x80 2441480Smckusick #define CSR_IR 0x40 2541480Smckusick #define SCSI_IPL(csr) ((((csr)>>4)&3)+3) 2641480Smckusick #define CSR_DMA32 0x08 2741480Smckusick #define CSR_DMAIN 0x04 2841480Smckusick #define CSR_DE1 0x02 2941480Smckusick #define CSR_DE0 0x01 3041480Smckusick u_char p4, scsi_wrap; 3141480Smckusick #define WRAP_REQ 0x80 3241480Smckusick #define WRAP_ACK 0x40 3341480Smckusick #define WRAP_BSY 0x08 3441480Smckusick #define WRAP_MSG 0x04 3541480Smckusick #define WRAP_CD 0x02 3641480Smckusick #define WRAP_IO 0x01 3741480Smckusick u_char p6, scsi_hconf; 3841480Smckusick #define HCONF_TP 0x80 3941480Smckusick #define SCSI_SYNC_XFER(hconf) (((hconf)>>5)&3) 4041480Smckusick #define HCONF_SD 0x10 4141480Smckusick #define HCONF_PARITY 0x08 4241480Smckusick u_char p8[24]; 4341480Smckusick u_char p32, scsi_bdid; 4441480Smckusick u_char p34, scsi_sctl; 4541480Smckusick #define SCTL_DISABLE 0x80 4641480Smckusick #define SCTL_CTRLRST 0x40 4741480Smckusick #define SCTL_DIAG 0x20 4841480Smckusick #define SCTL_ABRT_ENAB 0x10 4941480Smckusick #define SCTL_PARITY_ENAB 0x08 5041480Smckusick #define SCTL_SEL_ENAB 0x04 5141480Smckusick #define SCTL_RESEL_ENAB 0x02 5241480Smckusick #define SCTL_INTR_ENAB 0x01 5341480Smckusick u_char p36, scsi_scmd; 5441480Smckusick #define SCMD_RST 0x10 5541480Smckusick #define SCMD_ICPT_XFR 0x08 5641480Smckusick #define SCMD_PROG_XFR 0x04 5741480Smckusick #define SCMD_PAD 0x01 /* if initiator */ 5841480Smckusick #define SCMD_PERR_STOP 0x01 /* if target */ 5941480Smckusick /* command codes */ 6041480Smckusick #define SCMD_BUS_REL 0x00 6141480Smckusick #define SCMD_SELECT 0x20 6241480Smckusick #define SCMD_RST_ATN 0x40 6341480Smckusick #define SCMD_SET_ATN 0x60 6441480Smckusick #define SCMD_XFR 0x80 6541480Smckusick #define SCMD_XFR_PAUSE 0xa0 6641480Smckusick #define SCMD_RST_ACK 0xc0 6741480Smckusick #define SCMD_SET_ACK 0xe0 6841480Smckusick u_char p38, scsi_tmod; 6941480Smckusick #define TMOD_SYNC 0x80 7041480Smckusick u_char p40, scsi_ints; 7141480Smckusick #define INTS_SEL 0x80 7241480Smckusick #define INTS_RESEL 0x40 7341480Smckusick #define INTS_DISCON 0x20 7441480Smckusick #define INTS_CMD_DONE 0x10 7541480Smckusick #define INTS_SRV_REQ 0x08 7641480Smckusick #define INTS_TIMEOUT 0x04 7741480Smckusick #define INTS_HARD_ERR 0x02 7841480Smckusick #define INTS_RST 0x01 7941480Smckusick u_char p42, scsi_psns; 8041480Smckusick #define PSNS_REQ 0x80 8141480Smckusick #define PSNS_ACK 0x40 8241480Smckusick #define PSNS_ATN 0x20 8341480Smckusick #define PSNS_SEL 0x10 8441480Smckusick #define PSNS_BSY 0x08 8541480Smckusick u_char p44, scsi_ssts; 8641480Smckusick #define SSTS_INITIATOR 0x80 8741480Smckusick #define SSTS_TARGET 0x40 8841480Smckusick #define SSTS_BUSY 0x20 8941480Smckusick #define SSTS_XFR 0x10 9041480Smckusick #define SSTS_ACTIVE (SSTS_INITIATOR|SSTS_XFR) 9141480Smckusick #define SSTS_RST 0x08 9241480Smckusick #define SSTS_TCZERO 0x04 9341480Smckusick #define SSTS_DREG_FULL 0x02 9441480Smckusick #define SSTS_DREG_EMPTY 0x01 9541480Smckusick u_char p46, scsi_serr; 9641480Smckusick #define SERR_SCSI_PAR 0x80 9741480Smckusick #define SERR_SPC_PAR 0x40 9841480Smckusick #define SERR_TC_PAR 0x08 9941480Smckusick #define SERR_PHASE_ERR 0x04 10041480Smckusick #define SERR_SHORT_XFR 0x02 10141480Smckusick #define SERR_OFFSET 0x01 10241480Smckusick u_char p48, scsi_pctl; 10341480Smckusick #define PCTL_BFINT_ENAB 0x80 10441480Smckusick u_char p50, scsi_mbc; 10541480Smckusick u_char p52, scsi_dreg; 10641480Smckusick u_char p54, scsi_temp; 10741480Smckusick u_char p56, scsi_tch; 10841480Smckusick u_char p58, scsi_tcm; 10941480Smckusick u_char p60, scsi_tcl; 11041480Smckusick u_char p62, scsi_exbf; 11141480Smckusick }; 11241480Smckusick 11341480Smckusick /* psns/pctl phase lines as bits */ 11441480Smckusick #define PHASE_MSG 0x04 11541480Smckusick #define PHASE_CD 0x02 /* =1 if 'command' */ 11641480Smckusick #define PHASE_IO 0x01 /* =1 if data inbound */ 11741480Smckusick /* Phase lines as values */ 11841480Smckusick #define PHASE 0x07 /* mask for psns/pctl phase */ 11941480Smckusick #define DATA_OUT_PHASE 0x00 12041480Smckusick #define DATA_IN_PHASE 0x01 12141480Smckusick #define CMD_PHASE 0x02 12241480Smckusick #define STATUS_PHASE 0x03 12341480Smckusick #define BUS_FREE_PHASE 0x04 12441480Smckusick #define ARB_SEL_PHASE 0x05 /* Fuji chip combines arbitration with sel. */ 12541480Smckusick #define MESG_OUT_PHASE 0x06 12641480Smckusick #define MESG_IN_PHASE 0x07 12741480Smckusick 12841480Smckusick /* SCSI Messages */ 12941480Smckusick 13041480Smckusick #define MSG_CMD_COMPLETE 0x00 13141480Smckusick #define MSG_EXT_MESSAGE 0x01 13241480Smckusick #define MSG_SAVE_DATA_PTR 0x02 13341480Smckusick #define MSG_RESTORE_PTR 0x03 13441480Smckusick #define MSG_DISCONNECT 0x04 13541480Smckusick #define MSG_INIT_DETECT_ERROR 0x05 13641480Smckusick #define MSG_ABORT 0x06 13741480Smckusick #define MSG_REJECT 0x07 13841480Smckusick #define MSG_NOOP 0x08 13941480Smckusick #define MSG_PARITY_ERROR 0x09 14041480Smckusick #define MSG_BUS_DEVICE_RESET 0x0C 14141480Smckusick #define MSG_IDENTIFY 0x80 14241480Smckusick #define MSG_IDENTIFY_DR 0xc0 /* (disconnect/reconnect allowed) */ 14341480Smckusick #define MSG_SYNC_REQ 0x01 14441480Smckusick 14541480Smckusick /* SCSI Commands */ 14641480Smckusick 14741480Smckusick #define CMD_TEST_UNIT_READY 0x00 14841480Smckusick #define CMD_REQUEST_SENSE 0x03 14941480Smckusick #define CMD_INQUIRY 0x12 15041480Smckusick #define CMD_SEND_DIAGNOSTIC 0x1D 15141480Smckusick 15246285Smckusick #define CMD_REWIND 0x01 15353930Shibler #define CMD_REZERO 0x01 15441480Smckusick #define CMD_FORMAT_UNIT 0x04 15546285Smckusick #define CMD_READ_BLOCK_LIMITS 0x05 15641480Smckusick #define CMD_REASSIGN_BLOCKS 0x07 15741480Smckusick #define CMD_READ 0x08 15841480Smckusick #define CMD_WRITE 0x0A 15946285Smckusick #define CMD_WRITE_FILEMARK 0x10 16046285Smckusick #define CMD_SPACE 0x11 16141480Smckusick #define CMD_MODE_SELECT 0x15 16241480Smckusick #define CMD_RELEASE_UNIT 0x17 16346285Smckusick #define CMD_ERASE 0x19 16441480Smckusick #define CMD_MODE_SENSE 0x1A 16546285Smckusick #define CMD_LOADUNLOAD 0x1B 16646285Smckusick #define CMD_RECEIVE_DIAG 0x1C 16741480Smckusick #define CMD_SEND_DIAG 0x1D 16846285Smckusick #define CMD_P_A_MEDIA_REMOVAL 0x1E 16941480Smckusick #define CMD_READ_CAPACITY 0x25 17041480Smckusick #define CMD_READ_EXT 0x28 17141480Smckusick #define CMD_WRITE_EXT 0x2A 17241480Smckusick #define CMD_READ_DEFECT_DATA 0x37 17341480Smckusick #define SD_MANUFAC_DEFECTS 0x14000000 17441480Smckusick #define SD_GROWN_DEFECTS 0x0c000000 17541480Smckusick #define CMD_READ_BUFFER 0x3B 17641480Smckusick #define CMD_WRITE_BUFFER 0x3C 17741480Smckusick #define CMD_READ_FULL 0xF0 17841480Smckusick #define CMD_MEDIA_TEST 0xF1 17941480Smckusick #define CMD_ACCESS_LOG 0xF2 18041480Smckusick #define CMD_WRITE_FULL 0xFC 18141480Smckusick #define CMD_MANAGE_PRIMARY 0xFD 18241480Smckusick #define CMD_EXECUTE_DATA 0xFE 18341480Smckusick 18441480Smckusick /* SCSI status bits */ 18541480Smckusick 18641480Smckusick #define STS_CHECKCOND 0x02 /* Check Condition (ie., read sense) */ 18741480Smckusick #define STS_CONDMET 0x04 /* Condition Met (ie., search worked) */ 18841480Smckusick #define STS_BUSY 0x08 18941480Smckusick #define STS_INTERMED 0x10 /* Intermediate status sent */ 19041480Smckusick #define STS_EXT 0x80 /* Extended status valid */ 19141480Smckusick 19241480Smckusick /* command descriptor blocks */ 19341480Smckusick 19441480Smckusick struct scsi_cdb6 { 19541480Smckusick u_char cmd; /* command code */ 19641480Smckusick u_char lun: 3, /* logical unit on ctlr */ 19741480Smckusick lbah: 5; /* msb of read/write logical block addr */ 19841480Smckusick u_char lbam; /* middle byte of l.b.a. */ 19941480Smckusick u_char lbal; /* lsb of l.b.a. */ 20041480Smckusick u_char len; /* transfer length */ 20141480Smckusick u_char xtra; 20241480Smckusick }; 20341480Smckusick 20441480Smckusick struct scsi_cdb10 { 20541480Smckusick u_char cmd; /* command code */ 20641480Smckusick u_char lun: 3, /* logical unit on ctlr */ 20741480Smckusick : 4, 20841480Smckusick rel: 1; /* l.b.a. is relative addr if =1 */ 20941480Smckusick u_char lbah; /* msb of read/write logical block addr */ 21041480Smckusick u_char lbahm; /* high middle byte of l.b.a. */ 21141480Smckusick u_char lbalm; /* low middle byte of l.b.a. */ 21241480Smckusick u_char lbal; /* lsb of l.b.a. */ 21341480Smckusick u_char reserved; 21441480Smckusick u_char lenh; /* msb transfer length */ 21541480Smckusick u_char lenl; /* lsb transfer length */ 21641480Smckusick u_char xtra; 21741480Smckusick }; 21841480Smckusick 21941480Smckusick /* basic sense data */ 22041480Smckusick 22141480Smckusick struct scsi_sense { 22241480Smckusick u_char valid: 1, /* l.b.a. is valid */ 22341480Smckusick class: 3, 22441480Smckusick code: 4; 22541480Smckusick u_char vu: 4, /* vendor unique */ 22641480Smckusick lbah: 4; 22741480Smckusick u_char lbam; 22841480Smckusick u_char lbal; 22941480Smckusick }; 23041480Smckusick 23141480Smckusick struct scsi_xsense { 23241480Smckusick u_char valid: 1, /* l.b.a. is valid */ 23341480Smckusick class: 3, 23441480Smckusick code: 4; 23541480Smckusick u_char segment; 23641480Smckusick u_char filemark: 1, 23741480Smckusick eom: 1, 23841480Smckusick ili: 1, /* illegal length indicator */ 23941480Smckusick rsvd: 1, 24041480Smckusick key: 4; 24141480Smckusick u_char info1; 24241480Smckusick u_char info2; 24341480Smckusick u_char info3; 24441480Smckusick u_char info4; 24541480Smckusick u_char len; /* additional sense length */ 24641480Smckusick }; 24741480Smckusick 24841480Smckusick /* inquiry data */ 24941480Smckusick struct scsi_inquiry { 25041480Smckusick u_char type; 25141480Smckusick u_char qual; 25241480Smckusick u_char version; 25341480Smckusick u_char rsvd; 25441480Smckusick u_char len; 25541480Smckusick char class[3]; 25641480Smckusick char vendor_id[8]; 25741480Smckusick char product_id[16]; 25841480Smckusick char rev[4]; 25941480Smckusick }; 26041480Smckusick 26141480Smckusick struct scsi_format_parms { /* physical BFI format */ 26241480Smckusick u_short reserved; 26341480Smckusick u_short list_len; 26441480Smckusick struct defect { 26541480Smckusick unsigned cyl : 24; 26641480Smckusick unsigned head : 8; 26741480Smckusick long bytes_from_index; 26841480Smckusick } defect[127]; 26941480Smckusick } format_parms; 27041480Smckusick 27141480Smckusick struct scsi_reassign_parms { 27241480Smckusick u_short reserved; 27341480Smckusick u_short list_len; /* length in bytes of defects only */ 27441480Smckusick struct new_defect { 27541480Smckusick unsigned lba; /* logical block address */ 27641480Smckusick } new_defect[2]; 27741480Smckusick } reassign_parms; 27841480Smckusick 27941480Smckusick struct scsi_modesel_hdr { 28041480Smckusick u_char rsvd1; 28141480Smckusick u_char media_type; 28241480Smckusick u_char rsvd2; 28341480Smckusick u_char block_desc_len; 28441480Smckusick u_int density : 8; 28541480Smckusick u_int number_blocks :24; 28641480Smckusick u_int rsvd3 : 8; 28741480Smckusick u_int block_length :24; 28841480Smckusick }; 28941480Smckusick 29041480Smckusick struct scsi_modesense_hdr { 29141480Smckusick u_char len; 29241480Smckusick u_char media_type; 29341480Smckusick u_char wp : 1; 29441480Smckusick u_char rsvd1 : 7; 29541480Smckusick u_char block_desc_len; 29641480Smckusick u_int density : 8; 29741480Smckusick u_int number_blocks :24; 29841480Smckusick u_int rsvd2 : 8; 29941480Smckusick u_int block_length :24; 30041480Smckusick }; 30141480Smckusick 30241480Smckusick /* 30341480Smckusick * Mode Select / Mode sense "pages" 30441480Smckusick */ 30541480Smckusick 30641480Smckusick /* 30741480Smckusick * Page One - Error Recovery Parameters 30841480Smckusick */ 30941480Smckusick struct scsi_err_recovery { 31041480Smckusick u_char page_savable : 1; /* save parameters */ 31141480Smckusick u_char reserved : 1; 31241480Smckusick u_char page_code : 6; /* = 0x01 */ 31341480Smckusick u_char page_length; /* = 6 */ 31441480Smckusick u_char awre : 1; /* auto write realloc enabled */ 31541480Smckusick u_char arre : 1; /* auto read realloc enabled */ 31641480Smckusick u_char tb : 1; /* transfer block */ 31741480Smckusick u_char rc : 1; /* read continuous */ 31841480Smckusick u_char eec : 1; /* enable early correction */ 31941480Smckusick u_char per : 1; /* post error */ 32041480Smckusick u_char dte : 1; /* disable transfer on error */ 32141480Smckusick u_char dcr : 1; /* disable correction */ 32241480Smckusick u_char retry_count; 32341480Smckusick u_char correction_span; 32441480Smckusick u_char head_offset_count; 32541480Smckusick u_char strobe_offset_count; 32641480Smckusick u_char recovery_time_limit; 32741480Smckusick }; 32841480Smckusick 32941480Smckusick /* 33041480Smckusick * Page Two - Disconnect / Reconnect Control Parameters 33141480Smckusick */ 33241480Smckusick struct scsi_disco_reco { 33341480Smckusick u_char page_savable : 1; /* save parameters */ 33441480Smckusick u_char rsvd : 1; 33541480Smckusick u_char page_code : 6; /* = 0x02 */ 33641480Smckusick u_char page_length; /* = 10 */ 33741480Smckusick u_char buffer_full_ratio; /* write, how full before reconnect? */ 33841480Smckusick u_char buffer_empty_ratio; /* read, how full before reconnect? */ 33941480Smckusick 34041480Smckusick u_short bus_inactivity_limit; /* how much bus time for busy */ 34141480Smckusick u_short disconnect_time_limit; /* min to remain disconnected */ 34241480Smckusick u_short connect_time_limit; /* min to remain connected */ 34341480Smckusick u_short reserved_1; 34441480Smckusick }; 34541480Smckusick 34641480Smckusick /* 34741480Smckusick * Page Three - Direct Access Device Format Parameters 34841480Smckusick */ 34941480Smckusick struct scsi_format { 35041480Smckusick u_char page_savable : 1; /* save parameters */ 35141480Smckusick u_char rsvd : 1; 35241480Smckusick u_char page_code : 6; /* = 0x03 */ 35341480Smckusick u_char page_length; /* = 22 */ 35441480Smckusick u_short tracks_per_zone; /* Handling of Defects Fields */ 35541480Smckusick u_short alt_sect_zone; 35641480Smckusick u_short alt_tracks_zone; 35741480Smckusick u_short alt_tracks_vol; 35841480Smckusick u_short sect_track; /* Track Format Field */ 35941480Smckusick u_short data_sect; /* Sector Format Fields */ 36041480Smckusick u_short interleave; 36141480Smckusick u_short track_skew_factor; 36241480Smckusick u_short cyl_skew_factor; 36341480Smckusick u_char ssec : 1; /* Drive Type Field */ 36441480Smckusick u_char hsec : 1; 36541480Smckusick u_char rmb : 1; 36641480Smckusick u_char surf : 1; 36741480Smckusick u_char ins : 1; 36841480Smckusick u_char reserved_1 : 3; 36941480Smckusick u_char reserved_2; 37041480Smckusick u_char reserved_3; 37141480Smckusick u_char reserved_4; 37241480Smckusick }; 37341480Smckusick 37441480Smckusick /* 37541480Smckusick * Page Four - Rigid Disk Drive Geometry Parameters 37641480Smckusick */ 37741480Smckusick struct scsi_geometry { 37841480Smckusick u_char page_savable : 1; /* save parameters */ 37941480Smckusick u_char rsvd : 1; 38041480Smckusick u_char page_code : 6; /* = 0x04 */ 38141480Smckusick u_char page_length; /* = 18 */ 38241480Smckusick u_char cyl_ub; /* number of cylinders */ 38341480Smckusick u_char cyl_mb; 38441480Smckusick u_char cyl_lb; 38541480Smckusick u_char heads; /* number of heads */ 38641480Smckusick u_char precomp_cyl_ub; /* cylinder to start precomp */ 38741480Smckusick u_char precomp_cyl_mb; 38841480Smckusick u_char precomp_cyl_lb; 38941480Smckusick u_char current_cyl_ub; /* cyl to start reduced current */ 39041480Smckusick u_char current_cyl_mb; 39141480Smckusick u_char current_cyl_lb; 39241480Smckusick u_short step_rate; /* drive step rate */ 39341480Smckusick u_char landing_cyl_ub; /* landing zone cylinder */ 39441480Smckusick u_char landing_cyl_mb; 39541480Smckusick u_char landing_cyl_lb; 39641480Smckusick u_char reserved_1; 39741480Smckusick u_char reserved_2; 39841480Smckusick u_char reserved_3; 39941480Smckusick }; 40041480Smckusick 40141480Smckusick /* 40241480Smckusick * Page 0x38 - Cache Control Parameters 40341480Smckusick */ 40441480Smckusick struct scsi_cache { 40541480Smckusick u_char page_savable : 1; /* save parameters */ 40641480Smckusick u_char rsvd : 1; 40741480Smckusick u_char page_code : 6; /* = 0x38 */ 40841480Smckusick u_char page_length; /* = 14 */ 40941480Smckusick u_char rsvd_1 : 1; 41041480Smckusick u_char wie : 1; /* write index enable */ 41141480Smckusick u_char rsvd_2 : 1; 41241480Smckusick u_char ce : 1; /* cache enable */ 41341480Smckusick u_char table_size : 4; 41441480Smckusick u_char prefetch_threshold; 41541480Smckusick u_char maximum_threshold; 41641480Smckusick u_char maximumprefetch_multiplier; 41741480Smckusick u_char minimum_threshold; 41841480Smckusick u_char minimum_prefetch_multiplier; 41941480Smckusick u_char reserved[8]; 42041480Smckusick }; 42141480Smckusick 42241480Smckusick /* 42341480Smckusick * Control for SCSI "format" mode. 42441480Smckusick * 42541480Smckusick * "Format" mode allows a privileged process to issue direct SCSI 42641480Smckusick * commands to a drive (it is intended primarily to allow on-line 42741480Smckusick * formatting). SDIOCSFORMAT with a non-zero arg will put the drive 42841480Smckusick * into format mode; a zero arg will take it out. When in format 42941480Smckusick * mode, only the process that issued the SDIOCFORMAT can read or 43041480Smckusick * write the drive. 43141480Smckusick * 43241480Smckusick * In format mode, process is expected to 43341480Smckusick * - do SDIOCSCSICOMMAND to supply cdb for next SCSI op 43441480Smckusick * - do read or write as appropriate for cdb 43541480Smckusick * - if i/o error, optionally do SDIOCSENSE to get completion 43641480Smckusick * status and sense data from last scsi operation. 43741480Smckusick */ 43841480Smckusick 43941480Smckusick struct scsi_fmt_cdb { 44041480Smckusick int len; /* cdb length (in bytes) */ 44141480Smckusick u_char cdb[28]; /* cdb to use on next read/write */ 44241480Smckusick }; 44341480Smckusick 44441480Smckusick struct scsi_fmt_sense { 44541480Smckusick u_int status; /* completion status of last op */ 44641480Smckusick u_char sense[28]; /* sense data (if any) from last op */ 44741480Smckusick }; 44841480Smckusick 44941480Smckusick #define SDIOCSFORMAT _IOW('S', 0x1, int) 45041480Smckusick #define SDIOCGFORMAT _IOR('S', 0x2, int) 45141480Smckusick #define SDIOCSCSICOMMAND _IOW('S', 0x3, struct scsi_fmt_cdb) 45241480Smckusick #define SDIOCSENSE _IOR('S', 0x4, struct scsi_fmt_sense) 453