/* $NetBSD: scsi_changer.h,v 1.11 1998/02/13 08:28:32 enami Exp $ */12/*-3* SPDX-License-Identifier: BSD-4-Clause4*5* Copyright (c) 1996 Jason R. Thorpe <[email protected]>6* All rights reserved.7*8* Partially based on an autochanger driver written by Stefan Grefen9* and on an autochanger driver written by the Systems Programming Group10* at the University of Utah Computer Science Department.11*12* Redistribution and use in source and binary forms, with or without13* modification, are permitted provided that the following conditions14* are met:15* 1. Redistributions of source code must retain the above copyright16* notice, this list of conditions and the following disclaimer.17* 2. Redistributions in binary form must reproduce the above copyright18* notice, this list of conditions and the following disclaimer in the19* documentation and/or other materials provided with the distribution.20* 3. All advertising materials mentioning features or use of this software21* must display the following acknowledgements:22* This product includes software developed by Jason R. Thorpe23* for And Communications, http://www.and.com/24* 4. The name of the author may not be used to endorse or promote products25* derived from this software without specific prior written permission.26*27* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR28* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES29* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.30* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,31* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,32* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;33* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED34* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,35* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY36* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF37* SUCH DAMAGE.38*/3940/*41* SCSI changer interface description42*/4344/*-45* Partially derived from software written by Stefan Grefen46* ([email protected] soon [email protected])47* based on the SCSI System by written Julian Elischer ([email protected])48* for TRW Financial Systems.49*50* TRW Financial Systems, in accordance with their agreement with Carnegie51* Mellon University, makes this software available to CMU to distribute52* or use in any manner that they see fit as long as this message is kept with53* the software. For this reason TFS also grants any other persons or54* organisations permission to use or modify this software.55*56* TFS supplies this software to be publicly redistributed57* on the understanding that TFS is not responsible for the correct58* functioning of this software in any circumstances.59*60* Ported to run under 386BSD by Julian Elischer ([email protected]) Sept 199261*/6263#ifndef _SCSI_SCSI_CH_H64#define _SCSI_SCSI_CH_H 1656667/*68* SCSI command format69*/7071/*72* Exchange the medium in the source element with the medium73* located at the destination element.74*/75struct scsi_exchange_medium {76uint8_t opcode;77#define EXCHANGE_MEDIUM 0xa678uint8_t byte2;79uint8_t tea[2]; /* transport element address */80uint8_t src[2]; /* source address */81uint8_t fdst[2]; /* first destination address */82uint8_t sdst[2]; /* second destination address */83uint8_t invert;84#define EXCHANGE_MEDIUM_INV1 0x0185#define EXCHANGE_MEDIUM_INV2 0x0286uint8_t control;87};8889/*90* Cause the medium changer to check all elements for medium and any91* other status relevant to the element.92*/93struct scsi_initialize_element_status {94uint8_t opcode;95#define INITIALIZE_ELEMENT_STATUS 0x0796uint8_t byte2;97uint8_t reserved[3];98uint8_t control;99};100101/*102* Request the changer to move a unit of media from the source element103* to the destination element.104*/105struct scsi_move_medium {106uint8_t opcode;107uint8_t byte2;108uint8_t tea[2]; /* transport element address */109uint8_t src[2]; /* source element address */110uint8_t dst[2]; /* destination element address */111uint8_t reserved[2];112uint8_t invert;113#define MOVE_MEDIUM_INVERT 0x01114uint8_t control;115};116117/*118* Position the specified transport element (picker) in front of119* the destination element specified.120*/121struct scsi_position_to_element {122uint8_t opcode;123uint8_t byte2;124uint8_t tea[2]; /* transport element address */125uint8_t dst[2]; /* destination element address */126uint8_t reserved[2];127uint8_t invert;128#define POSITION_TO_ELEMENT_INVERT 0x01129uint8_t control;130};131132/*133* Request that the changer report the status of its internal elements.134*/135struct scsi_read_element_status {136uint8_t opcode;137uint8_t byte2;138#define READ_ELEMENT_STATUS_VOLTAG 0x10 /* report volume tag info */139/* ...next 4 bits are an element type code... */140uint8_t sea[2]; /* starting element address */141uint8_t count[2]; /* number of elements */142uint8_t flags;143#define READ_ELEMENT_STATUS_DVCID 0x01 /* report device serial number */144#define READ_ELEMENT_STATUS_CURDATA 0x02 /* allow motion during command */145146uint8_t len[3]; /* length of data buffer */147uint8_t reserved1;148uint8_t control;149};150151struct scsi_request_volume_element_address {152uint8_t opcode;153uint8_t byte2;154#define REQUEST_VOLUME_ELEMENT_ADDRESS_VOLTAG 0x10155/* ...next 4 bits are an element type code... */156uint8_t eaddr[2]; /* element address */157uint8_t count[2]; /* number of elements */158uint8_t reserved0;159uint8_t len[3]; /* length of data buffer */160uint8_t reserved1;161uint8_t control;162};163164/* XXX scsi_release */165166/*167* Changer-specific mode page numbers.168*/169#define CH_ELEMENT_ADDR_ASSIGN_PAGE 0x1D170#define CH_TRANS_GEOM_PARAMS_PAGE 0x1E171#define CH_DEVICE_CAP_PAGE 0x1F172173/*174* Data returned by READ ELEMENT STATUS consists of an 8-byte header175* followed by one or more read_element_status_pages.176*/177struct read_element_status_header {178uint8_t fear[2]; /* first element address reported */179uint8_t count[2]; /* number of elements available */180uint8_t reserved;181uint8_t nbytes[3]; /* byte count of all pages */182};183184struct read_element_status_page_header {185uint8_t type; /* element type code; see type codes below */186uint8_t flags;187#define READ_ELEMENT_STATUS_AVOLTAG 0x40188#define READ_ELEMENT_STATUS_PVOLTAG 0x80189uint8_t edl[2]; /* element descriptor length */190uint8_t reserved;191uint8_t nbytes[3]; /* byte count of all descriptors */192};193194/*195* Format of a volume tag196*/197198struct volume_tag {199uint8_t vif[32]; /* volume identification field */200uint8_t reserved[2];201uint8_t vsn[2]; /* volume sequence number */202};203204struct read_element_status_device_id {205uint8_t prot_code_set;206#define READ_ELEMENT_STATUS_CODE_SET(p) ((p) & 0x0F)207#define READ_ELEMENT_STATUS_PROTOCOL_ID(p) ((p) >> 4)208209uint8_t piv_assoc_designator_type;210#define READ_ELEMENT_STATUS_PIV_SET 0x80211#define READ_ELEMENT_STATUS_ASSOCIATION(p) ((p) >> 4)212#define READ_ELEMENT_STATUS_DESIGNATOR_TYPE(p) ((p) & 0x0F)213214uint8_t reserved2;215uint8_t designator_length;216uint8_t designator[256]; /* Allocate max length */217};218219struct read_element_status_descriptor {220uint8_t eaddr[2]; /* element address */221uint8_t flags1;222223#define READ_ELEMENT_STATUS_FULL 0x01224#define READ_ELEMENT_STATUS_IMPEXP 0x02225#define READ_ELEMENT_STATUS_EXCEPT 0x04226#define READ_ELEMENT_STATUS_ACCESS 0x08227#define READ_ELEMENT_STATUS_EXENAB 0x10228#define READ_ELEMENT_STATUS_INENAB 0x20229230#define READ_ELEMENT_STATUS_MT_MASK1 0x05231#define READ_ELEMENT_STATUS_ST_MASK1 0x0c232#define READ_ELEMENT_STATUS_IE_MASK1 0x3f233#define READ_ELEMENT_STATUS_DT_MASK1 0x0c234235uint8_t reserved0;236uint8_t sense_code;237uint8_t sense_qual;238239union {240struct {241uint8_t dt_scsi_flags;242243#define READ_ELEMENT_STATUS_DT_LUNMASK 0x07244#define READ_ELEMENT_STATUS_DT_LUVALID 0x10245#define READ_ELEMENT_STATUS_DT_IDVALID 0x20246#define READ_ELEMENT_STATUS_DT_NOTBUS 0x80247248uint8_t dt_scsi_addr;249uint8_t reserved1;250} scsi_2;251252/* reserved and obsolete (as of SCSI-3) fields */253uint8_t reserved_or_obsolete[3];254} dt_or_obsolete;255256uint8_t flags2;257#define READ_ELEMENT_STATUS_INVERT 0x40258#define READ_ELEMENT_STATUS_SVALID 0x80259#define READ_ELEMENT_STATUS_ED 0x80260#define READ_ELEMENT_STATUS_MEDIA_TYPE_MASK 0x07261262uint8_t ssea[2]; /* source storage element address */263264union {265struct volume_tag pvoltag;266struct volume_tag voltag[2];267struct read_element_status_device_id devid;268struct {269struct volume_tag pvoltag;270struct read_element_status_device_id devid;271} pvol_and_devid;272struct {273struct volume_tag voltag[2];274struct read_element_status_device_id devid;275} vol_tags_and_devid;276} voltag_devid;277};278279/* XXX add data returned by REQUEST VOLUME ELEMENT ADDRESS */280281/* Element type codes */282#define ELEMENT_TYPE_MASK 0x0f /* Note: these aren't bits */283#define ELEMENT_TYPE_ALL 0x00284#define ELEMENT_TYPE_MT 0x01285#define ELEMENT_TYPE_ST 0x02286#define ELEMENT_TYPE_IE 0x03287#define ELEMENT_TYPE_DT 0x04288289/*290* XXX The following definitions should be common to all SCSI device types.291*/292#define PGCODE_MASK 0x3f /* valid page number bits in pg_code */293#define PGCODE_PS 0x80 /* indicates page is savable */294295/*296* Send volume tag information to the changer297*/298299struct scsi_send_volume_tag {300uint8_t opcode;301#define SEND_VOLUME_TAG 0xb6302uint8_t byte2;303uint8_t ea[2]; /* element address */304uint8_t reserved2;305uint8_t sac; /* send action code */306307#define SEND_VOLUME_TAG_ASSERT_PRIMARY 0x08308#define SEND_VOLUME_TAG_ASSERT_ALTERNATE 0x09309#define SEND_VOLUME_TAG_REPLACE_PRIMARY 0x0a310#define SEND_VOLUME_TAG_REPLACE_ALTERNATE 0x0b311#define SEND_VOLUME_TAG_UNDEFINED_PRIMARY 0x0c312#define SEND_VOLUME_TAG_UNDEFINED_ALTERNATE 0x0d313314uint8_t reserved4[2];315uint8_t pll[2]; /* parameter list length */316uint8_t reserved5;317uint8_t control;318};319320/*321* Parameter format for SEND VOLUME TAG322*/323324struct scsi_send_volume_tag_parameters {325uint8_t vitf[32]; /* volume tag identification template */326uint8_t reserved1[2];327uint8_t minvsn[2]; /* minimum volume sequence number */328uint8_t reserved2[2];329uint8_t maxvsn[2]; /* maximum volume sequence number */330};331332/*333* Device capabilities page.334*335* This page defines characteristics of the element types in the336* medium changer device.337*338* Note in the definitions below, the following abbreviations are339* used:340* MT Medium transport element (picker)341* ST Storage transport element (slot)342* IE Import/export element (portal)343* DT Data transfer element (tape/disk drive)344*/345struct page_device_capabilities {346uint8_t pg_code; /* page code (0x1f) */347uint8_t pg_length; /* page length (0x12) */348349/*350* The STOR_xx bits indicate that an element of a given351* type may provide independent storage for a unit of352* media. The top four bits of this value are reserved.353*/354uint8_t stor;355#define STOR_MT 0x01356#define STOR_ST 0x02357#define STOR_IE 0x04358#define STOR_DT 0x08359360uint8_t reserved0;361362/*363* The MOVE_TO_yy bits indicate the changer supports364* moving a unit of medium from an element of a given type to an365* element of type yy. This is used to determine if a given366* MOVE MEDIUM command is legal. The top four bits of each367* of these values are reserved.368*/369uint8_t move_from[CHET_MAX + 1];370#define MOVE_TO_MT 0x01371#define MOVE_TO_ST 0x02372#define MOVE_TO_IE 0x04373#define MOVE_TO_DT 0x08374375uint8_t reserved1[4];376377/*378* Similar to above, but for EXCHANGE MEDIUM.379*/380uint8_t exchange_with[CHET_MAX + 1];381#define EXCHANGE_WITH_MT 0x01382#define EXCHANGE_WITH_ST 0x02383#define EXCHANGE_WITH_IE 0x04384#define EXCHANGE_WITH_DT 0x08385};386387/*388* Medium changer elemement address assignment page.389*390* Some of these fields can be a little confusing, so an explanation391* is in order.392*393* Each component within a medium changer apparatus is called an394* "element".395*396* The "medium transport element address" is the address of the first397* picker (robotic arm). "Number of medium transport elements" tells398* us how many pickers exist in the changer.399*400* The "first storage element address" is the address of the first401* slot in the tape or disk magazine. "Number of storage elements" tells402* us how many slots exist in the changer.403*404* The "first import/export element address" is the address of the first405* medium portal accessible both by the medium changer and an outside406* human operator. This is where the changer might deposit tapes destined407* for some vault. The "number of import/export elements" tells us408* not many of these portals exist in the changer. NOTE: this number may409* be 0.410*411* The "first data transfer element address" is the address of the first412* tape or disk drive in the changer. "Number of data transfer elements"413* tells us how many drives exist in the changer.414*/415struct page_element_address_assignment {416uint8_t pg_code; /* page code (0x1d) */417uint8_t pg_length; /* page length (0x12) */418419/* Medium transport element address */420uint8_t mtea[2];421422/* Number of medium transport elements */423uint8_t nmte[2];424425/* First storage element address */426uint8_t fsea[2];427428/* Number of storage elements */429uint8_t nse[2];430431/* First import/export element address */432uint8_t fieea[2];433434/* Number of import/export elements */435uint8_t niee[2];436437/* First data transfer element address */438uint8_t fdtea[2];439440/* Number of data transfer elements */441uint8_t ndte[2];442443uint8_t reserved[2];444};445446/*447* Transport geometry parameters page.448*449* Defines whether each medium transport element is a member of a set of450* elements that share a common robotics subsystem and whether the element451* is capable of media rotation. One transport geometry descriptor is452* transferred for each medium transport element, beginning with the first453* medium transport element (other than the default transport element address454* of 0).455*/456struct page_transport_geometry_parameters {457uint8_t pg_code; /* page code (0x1e) */458uint8_t pg_length; /* page length; variable */459460/* Transport geometry descriptor(s) are here. */461462uint8_t misc;463#define CAN_ROTATE 0x01464465/* Member number in transport element set. */466uint8_t member;467};468469__BEGIN_DECLS470void scsi_move_medium(struct ccb_scsiio *csio, uint32_t retries,471void (*cbfcnp)(struct cam_periph *, union ccb *),472uint8_t tag_action, uint32_t tea, uint32_t src,473uint32_t dst, int invert, uint8_t sense_len,474uint32_t timeout);475476void scsi_exchange_medium(struct ccb_scsiio *csio, uint32_t retries,477void (*cbfcnp)(struct cam_periph *, union ccb *),478uint8_t tag_action, uint32_t tea, uint32_t src,479uint32_t dst1, uint32_t dst2, int invert1,480int invert2, uint8_t sense_len, uint32_t timeout);481482void scsi_position_to_element(struct ccb_scsiio *csio, uint32_t retries,483void (*cbfcnp)(struct cam_periph *, union ccb *),484uint8_t tag_action, uint32_t tea, uint32_t dst,485int invert, uint8_t sense_len,486uint32_t timeout);487488void scsi_read_element_status(struct ccb_scsiio *csio, uint32_t retries,489void (*cbfcnp)(struct cam_periph *, union ccb *),490uint8_t tag_action, int voltag, uint32_t sea,491int curdata, int dvcid,492uint32_t count, uint8_t *data_ptr,493uint32_t dxfer_len, uint8_t sense_len,494uint32_t timeout);495496void scsi_initialize_element_status(struct ccb_scsiio *csio, uint32_t retries,497void (*cbfcnp)(struct cam_periph *, union ccb *),498uint8_t tag_action, uint8_t sense_len,499uint32_t timeout);500void scsi_send_volume_tag(struct ccb_scsiio *csio, uint32_t retries,501void (*cbfcnp)(struct cam_periph *, union ccb *),502uint8_t tag_action,503uint16_t element_address,504uint8_t send_action_code,505struct scsi_send_volume_tag_parameters *parameters,506uint8_t sense_len, uint32_t timeout);507__END_DECLS508509#endif /* _SCSI_SCSI_CH_H */510511512