/*
* Copyright (c) 1988 Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Chris Torek.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)mscp.h 7.5 (Berkeley) 6/28/90
*/
/*
* Definitions for the Mass Storage Control Protocol
* I WISH I KNEW WHAT MORE OF THESE WERE. IT SURE WOULD BE NICE
* IF DEC SOLD DOCUMENTATION FOR THEIR OWN CONTROLLERS.
*/
/*
* Subcodes of M_ST_OFFLINE
*/
#define M_OFFLINE_UNKNOWN (0 << 5) /* unknown or on other ctlr */
#define M_OFFLINE_UNMOUNTED (1 << 5) /* unmounted or RUN/STOP at STOP */
#define M_OFFLINE_INOPERATIVE (2 << 5) /* inoperative? */
#define M_OFFLINE_DUPLICATE (4 << 5) /* duplicate unit number */
#define M_OFFLINE_INDIAGNOSTIC (8 << 5) /* disabled by FS or diagnostic */
/*
* An MSCP packet begins with a header giving the length of
* the entire packet (including the header itself)(?), two bytes
* of device specific data, and the a whole bunch of variants
* depending on message type.
*
* N.B.: In most cases we distinguish between a `command' and
* an `end' variant as well. The command variant is that which
* is given to the controller; the `end' variant is its response.
*/
/*
* Generic sequential message variant (command and response).
*/
struct mscpv_seq {
long seq_bytecount; /* byte count */
#define seq_rbn seq_bytecount /* aka RBN (replace) */
#define seq_outref seq_bytecount /* aka outref (abort/get cmd status) */
long seq_buffer; /* buffer descriptor */
long seq_mapbase; /* page map (first PTE) phys address */
long seq_xxx1; /* ? */ /* unused */
long seq_lbn; /* logical block number */
long seq_xxx2; /* ? */ /* unused */
long *seq_addr; /* pointer to cmd descriptor */
long seq_software[4]; /* reserved to software; unused */
};
/*
* Set Controller Characteristics command variant
*/
struct mscpv_sccc {
u_short sccc_version; /* MSCP version number */
u_short sccc_ctlrflags; /* controller flags */
u_short sccc_hosttimo; /* host timeout */
u_short sccc_usefrac; /* use fraction */
long sccc_time; /* time and date */
long sccc_time1; /* it's a quad field */
long sccc_errlgfl; /* ? */
short sccc_xxx2; /* ? */
short sccc_copyspd; /* ? */
};
/*
* Set Controller Characteristics end variant
*/
struct mscpv_scce {
u_short scce_version; /* MSCP version number */
u_short scce_ctlrflags; /* controller flags */
u_short scce_ctlrtimo; /* controller timeout */
u_short scce_ctlrcmdl; /* ??? */
quad_t scce_ctlrid; /* controller ID */
long scce_xxx[3]; /* ? */
long scce_volser; /* volume serial number */
};
/*
* On Line command variant
*/
struct mscpv_onlc {
long onlc_xxx1[4]; /* ? */
long onlc_errlgfl; /* error log flag? */
short onlc_xxx2; /* ? */
short onlc_copyspd; /* copy speed? */
};
/*
* On Line end variant
*/
struct mscpv_onle {
long onle_xxx1[3]; /* ? */
/*???*/ short onle_xxx2; /* ? */
u_char onle_drivetype; /* drive type index (same in guse) */
char onle_xxx3; /* ? */
long onle_mediaid; /* media type id (same in guse) */
long onle_xxx4; /* ? */
long onle_unitsize; /* unit size in sectors */
long onle_volser; /* volume serial number */
};
/*
* Get Unit Status end variant (and Avail Attn?)
*/
struct mscpv_guse {
u_short guse_multunit; /* multi-unit code */
u_short guse_unitflags; /* unit flags */
long guse_hostid; /* host id */
long guse_unitid0; /*???*/
short guse_unitid1; /*???*/
u_char guse_drivetype; /* drive type index */
u_char guse_unitid2; /*???*/
long guse_mediaid; /* media type id (encoded) */
short guse_shadowunit; /* shadow unit */
short guse_shadowstat; /* shadow status */
u_short guse_nspt; /* sectors per track */
u_short guse_group; /* track group size */
u_short guse_ngpc; /* groups per cylinder */
u_short guse_xxx; /* reserved */
u_short guse_rctsize; /* RCT size (sectors) */
u_char guse_nrpt; /* RBNs per track */
u_char guse_nrct; /* number of RCTs */
};
/*
* Macros to break up and build media IDs. An ID encodes the port
* type in the top 10 bits, and the drive type in the remaining 22.
* The 10 bits, and 15 of the 22, are in groups of 5, with the value
* 0 representing space and values 1..26 representing A..Z. The low
* 7 bits represent a number in 0..127. Hence an RA81 on a UDA50
* is <D><U><R><A>< >81, or 0x25641051. This encoding scheme is known
* in part in uda.c.
*
* The casts below are just to make pcc generate better code.
*/
#define MSCP_MEDIA_PORT(id) (((long)(id) >> 22) & 0x3ff) /* port */
#define MSCP_MEDIA_DRIVE(id) ((long)(id) & 0x003fffff) /* drive */
#define MSCP_MID_ECH(n, id) (((int)(id) >> ((n) * 5 + 7)) & 0x1f)
#define MSCP_MID_CHAR(n, id) \
(MSCP_MID_ECH(n, id) ? MSCP_MID_ECH(n, id) + '@' : ' ')
#define MSCP_MID_NUM(id) ((id) & 0x7f)
/* for, e.g., RA81 */
#define MSCP_MKDRIVE2(a, b, n) \
(((a) - '@') << 17 | ((b) - '@') << 12 | (n))
/* for, e.g., RRD50 */
#define MSCP_MKDRIVE3(a, b, c, n) \
(((a) - '@') << 17 | ((b) - '@') << 12 | ((c) - '@') << 7 | (n))
/*
* Error datagram variant.
*/
struct mscpv_erd {
quad_t erd_ctlrid; /* controller ID */
u_char erd_ctlrsoftware; /* controller software version */
u_char erd_ctlrhardware; /* controller hardware version */
u_short erd_multiunit; /* multi-unit code (?) */
union {
u_long un_busaddr; /* bus address, if mem access err */
quad_t un_unitid; /* unit id, otherwise */
} erd_un1;
#define erd_busaddr erd_un1.un_busaddr
#define erd_unitid erd_un1.un_unitid
u_char erd_unitsoftware; /* unit software version */
u_char erd_unithardware; /* unit hardware version */
union {
u_char un_b[2]; /* level, retry (if disk xfer err) */
u_short un_s; /* cylinder (if small disk error) */
} erd_un2;
#define erd_level erd_un2.un_b[0]
#define erd_retry erd_un2.un_b[1]
#define erd_sdecyl erd_un2.un_s
long erd_volser; /* volume serial number */
u_long erd_hdr; /* `header' (block number) */
u_char erd_sdistat[12]; /* SDI status information (?) */
};
/*
* I am making brash assumptions about the first four bytes of all
* MSCP packets. These appear to be true for both UDA50s and TMSCP
* devices (TU81, TA81, TK50). DEC claim that these four bytes are
* not part of MSCP itself, yet at least the length is necessary
* for, e.g., error checking.
*/
struct mscp {
u_short mscp_msglen; /* length in bytes */
u_char mscp_msgtc; /* type (high 4 bits) and credits */
u_char mscp_vcid; /* virtual circuit ID */
long mscp_cmdref; /* command reference number */
u_short mscp_unit; /* unit number */
u_short mscp_seqnum; /* sequence number */
u_char mscp_opcode; /* opcode */
#define mscp_format mscp_opcode /* aka format (datagrams) */
u_char mscp_flags; /* flags */
u_short mscp_modifier; /* modifier (commands) */
#define mscp_status mscp_modifier /* aka status (ends) */
#define mscp_event mscp_modifier /* aka event (datagrams) */
union {
struct mscpv_seq un_seq; /* generic sequential msg */
struct mscpv_sccc un_sccc; /* SCC command */
struct mscpv_scce un_scce; /* SCC end */
struct mscpv_onlc un_onlc; /* on line command */
struct mscpv_onle un_onle; /* on line end */
struct mscpv_guse un_guse; /* get unit status */
struct mscpv_erd un_erd; /* error datagram */
} mscp_un;
/*???*/ long mscp_xxx; /* pad to 64 bytes */
};
/*
* Define message length according to the DEC specifications by dropping
* the four byte header.
*/
#define MSCP_MSGLEN (sizeof (struct mscp) - 4)
/*
* Here begin more perhaps brash assumptions about MSCP devices...
*/
/*
* MSCP controllers have `command rings' and `response rings'. A
* command ring is a pool of MSCP packets that the host uses to give
* commands to the controller; a response ring is a pool of MSCP
* packets that the controller uses to give back responses. Entries
* in the command and response rings are `owned' by either the host
* or the controller; only the owner is allowed to alter any of the
* fields in the MSCP packet. Thus, free command packets are owned
* by the host, and free response packets by the controller. When
* the host gives a packet to the controller, it tells the controller
* by touching a device register; when the controller gives a response
* to the host, it generates an interrupt if enabled, and sets
* a device register as well.
*
* The pool is `described' by a set of pointers to the packets, along
* with the two flags below.
*/
#define MSCP_OWN 0x80000000 /* controller owns this packet */
#define MSCP_INT 0x40000000 /* controller should interrupt */