1 /* $FreeBSD: src/sys/cam/scsi/scsi_ch.h,v 1.2.6.1 2000/08/03 00:50:59 peter Exp $ */ 2 /* $DragonFly: src/sys/bus/cam/scsi/scsi_ch.h,v 1.3 2007/11/25 17:59:22 pavalos Exp $ */ 3 /* $NetBSD: scsi_changer.h,v 1.11 1998/02/13 08:28:32 enami Exp $ */ 4 5 /* 6 * Copyright (c) 1996 Jason R. Thorpe <thorpej@and.com> 7 * All rights reserved. 8 * 9 * Partially based on an autochanger driver written by Stefan Grefen 10 * and on an autochanger driver written by the Systems Programming Group 11 * at the University of Utah Computer Science Department. 12 * 13 * Redistribution and use in source and binary forms, with or without 14 * modification, are permitted provided that the following conditions 15 * are met: 16 * 1. Redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer. 18 * 2. Redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution. 21 * 3. All advertising materials mentioning features or use of this software 22 * must display the following acknowledgements: 23 * This product includes software developed by Jason R. Thorpe 24 * for And Communications, http://www.and.com/ 25 * 4. The name of the author may not be used to endorse or promote products 26 * derived from this software without specific prior written permission. 27 * 28 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 29 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 31 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 35 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 36 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 38 * SUCH DAMAGE. 39 */ 40 41 /* 42 * SCSI changer interface description 43 */ 44 45 /* 46 * Partially derived from software written by Stefan Grefen 47 * (grefen@goofy.zdv.uni-mainz.de soon grefen@convex.com) 48 * based on the SCSI System by written Julian Elischer (julian@tfs.com) 49 * for TRW Financial Systems. 50 * 51 * TRW Financial Systems, in accordance with their agreement with Carnegie 52 * Mellon University, makes this software available to CMU to distribute 53 * or use in any manner that they see fit as long as this message is kept with 54 * the software. For this reason TFS also grants any other persons or 55 * organisations permission to use or modify this software. 56 * 57 * TFS supplies this software to be publicly redistributed 58 * on the understanding that TFS is not responsible for the correct 59 * functioning of this software in any circumstances. 60 * 61 * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 62 */ 63 64 #ifndef _SCSI_SCSI_CH_H 65 #define _SCSI_SCSI_CH_H 1 66 67 #include <sys/cdefs.h> 68 #include <sys/chio.h> 69 70 /* 71 * SCSI command format 72 */ 73 74 /* 75 * Exchange the medium in the source element with the medium 76 * located at the destination element. 77 */ 78 struct scsi_exchange_medium { 79 u_int8_t opcode; 80 #define EXCHANGE_MEDIUM 0xa6 81 u_int8_t byte2; 82 u_int8_t tea[2]; /* transport element address */ 83 u_int8_t src[2]; /* source address */ 84 u_int8_t fdst[2]; /* first destination address */ 85 u_int8_t sdst[2]; /* second destination address */ 86 u_int8_t invert; 87 #define EXCHANGE_MEDIUM_INV1 0x01 88 #define EXCHANGE_MEDIUM_INV2 0x02 89 u_int8_t control; 90 }; 91 92 /* 93 * Cause the medium changer to check all elements for medium and any 94 * other status relevant to the element. 95 */ 96 struct scsi_initialize_element_status { 97 u_int8_t opcode; 98 #define INITIALIZE_ELEMENT_STATUS 0x07 99 u_int8_t byte2; 100 u_int8_t reserved[3]; 101 u_int8_t control; 102 }; 103 104 /* 105 * Request the changer to move a unit of media from the source element 106 * to the destination element. 107 */ 108 struct scsi_move_medium { 109 u_int8_t opcode; 110 #define MOVE_MEDIUM 0xa5 111 u_int8_t byte2; 112 u_int8_t tea[2]; /* transport element address */ 113 u_int8_t src[2]; /* source element address */ 114 u_int8_t dst[2]; /* destination element address */ 115 u_int8_t reserved[2]; 116 u_int8_t invert; 117 #define MOVE_MEDIUM_INVERT 0x01 118 u_int8_t control; 119 }; 120 121 /* 122 * Position the specified transport element (picker) in front of 123 * the destination element specified. 124 */ 125 struct scsi_position_to_element { 126 u_int8_t opcode; 127 #define POSITION_TO_ELEMENT 0x2b 128 u_int8_t byte2; 129 u_int8_t tea[2]; /* transport element address */ 130 u_int8_t dst[2]; /* destination element address */ 131 u_int8_t reserved[2]; 132 u_int8_t invert; 133 #define POSITION_TO_ELEMENT_INVERT 0x01 134 u_int8_t control; 135 }; 136 137 /* 138 * Request that the changer report the status of its internal elements. 139 */ 140 struct scsi_read_element_status { 141 u_int8_t opcode; 142 #define READ_ELEMENT_STATUS 0xb8 143 u_int8_t byte2; 144 #define READ_ELEMENT_STATUS_VOLTAG 0x10 /* report volume tag info */ 145 /* ...next 4 bits are an element type code... */ 146 u_int8_t sea[2]; /* starting element address */ 147 u_int8_t count[2]; /* number of elements */ 148 u_int8_t reserved0; 149 u_int8_t len[3]; /* length of data buffer */ 150 u_int8_t reserved1; 151 u_int8_t control; 152 }; 153 154 struct scsi_request_volume_element_address { 155 u_int8_t opcode; 156 #define REQUEST_VOLUME_ELEMENT_ADDRESS 0xb5 157 u_int8_t byte2; 158 #define REQUEST_VOLUME_ELEMENT_ADDRESS_VOLTAG 0x10 159 /* ...next 4 bits are an element type code... */ 160 u_int8_t eaddr[2]; /* element address */ 161 u_int8_t count[2]; /* number of elements */ 162 u_int8_t reserved0; 163 u_int8_t len[3]; /* length of data buffer */ 164 u_int8_t reserved1; 165 u_int8_t control; 166 }; 167 168 /* XXX scsi_release */ 169 170 /* 171 * Changer-specific mode page numbers. 172 */ 173 #define CH_ELEMENT_ADDR_ASSIGN_PAGE 0x1D 174 #define CH_TRANS_GEOM_PARAMS_PAGE 0x1E 175 #define CH_DEVICE_CAP_PAGE 0x1F 176 177 /* 178 * Data returned by READ ELEMENT STATUS consists of an 8-byte header 179 * followed by one or more read_element_status_pages. 180 */ 181 struct read_element_status_header { 182 u_int8_t fear[2]; /* first element address reported */ 183 u_int8_t count[2]; /* number of elements available */ 184 u_int8_t reserved; 185 u_int8_t nbytes[3]; /* byte count of all pages */ 186 }; 187 188 struct read_element_status_page_header { 189 u_int8_t type; /* element type code; see type codes below */ 190 u_int8_t flags; 191 #define READ_ELEMENT_STATUS_AVOLTAG 0x40 192 #define READ_ELEMENT_STATUS_PVOLTAG 0x80 193 u_int8_t edl[2]; /* element descriptor length */ 194 u_int8_t reserved; 195 u_int8_t nbytes[3]; /* byte count of all descriptors */ 196 }; 197 198 /* 199 * Format of a volume tag 200 */ 201 202 struct volume_tag { 203 u_int8_t vif[32]; /* volume identification field */ 204 u_int8_t reserved[2]; 205 u_int8_t vsn[2]; /* volume sequence number */ 206 }; 207 208 struct read_element_status_descriptor { 209 u_int8_t eaddr[2]; /* element address */ 210 u_int8_t flags1; 211 212 #define READ_ELEMENT_STATUS_FULL 0x01 213 #define READ_ELEMENT_STATUS_IMPEXP 0x02 214 #define READ_ELEMENT_STATUS_EXCEPT 0x04 215 #define READ_ELEMENT_STATUS_ACCESS 0x08 216 #define READ_ELEMENT_STATUS_EXENAB 0x10 217 #define READ_ELEMENT_STATUS_INENAB 0x20 218 219 #define READ_ELEMENT_STATUS_MT_MASK1 0x05 220 #define READ_ELEMENT_STATUS_ST_MASK1 0x0c 221 #define READ_ELEMENT_STATUS_IE_MASK1 0x3f 222 #define READ_ELEMENT_STATUS_DT_MASK1 0x0c 223 224 u_int8_t reserved0; 225 u_int8_t sense_code; 226 u_int8_t sense_qual; 227 228 /* 229 * dt_scsi_flags and dt_scsi_addr are valid only on data transport 230 * elements. These bytes are undefined for all other element types. 231 */ 232 u_int8_t dt_scsi_flags; 233 234 #define READ_ELEMENT_STATUS_DT_LUNMASK 0x07 235 #define READ_ELEMENT_STATUS_DT_LUVALID 0x10 236 #define READ_ELEMENT_STATUS_DT_IDVALID 0x20 237 #define READ_ELEMENT_STATUS_DT_NOTBUS 0x80 238 239 u_int8_t dt_scsi_addr; 240 241 u_int8_t reserved1; 242 243 u_int8_t flags2; 244 #define READ_ELEMENT_STATUS_INVERT 0x40 245 #define READ_ELEMENT_STATUS_SVALID 0x80 246 u_int8_t ssea[2]; /* source storage element address */ 247 248 struct volume_tag pvoltag; /* omitted if PVOLTAG == 0 */ 249 struct volume_tag avoltag; /* omitted if AVOLTAG == 0 */ 250 251 /* Other data may follow */ 252 }; 253 254 /* XXX add data returned by REQUEST VOLUME ELEMENT ADDRESS */ 255 256 /* Element type codes */ 257 #define ELEMENT_TYPE_MASK 0x0f /* Note: these aren't bits */ 258 #define ELEMENT_TYPE_ALL 0x00 259 #define ELEMENT_TYPE_MT 0x01 260 #define ELEMENT_TYPE_ST 0x02 261 #define ELEMENT_TYPE_IE 0x03 262 #define ELEMENT_TYPE_DT 0x04 263 264 /* 265 * XXX The following definitions should be common to all SCSI device types. 266 */ 267 #define PGCODE_MASK 0x3f /* valid page number bits in pg_code */ 268 #define PGCODE_PS 0x80 /* indicates page is savable */ 269 270 /* 271 * Send volume tag information to the changer 272 */ 273 274 struct scsi_send_volume_tag { 275 u_int8_t opcode; 276 #define SEND_VOLUME_TAG 0xb6 277 u_int8_t byte2; 278 u_int8_t ea[2]; /* element address */ 279 u_int8_t reserved2; 280 u_int8_t sac; /* send action code */ 281 282 #define SEND_VOLUME_TAG_ASSERT_PRIMARY 0x08 283 #define SEND_VOLUME_TAG_ASSERT_ALTERNATE 0x09 284 #define SEND_VOLUME_TAG_REPLACE_PRIMARY 0x0a 285 #define SEND_VOLUME_TAG_REPLACE_ALTERNATE 0x0b 286 #define SEND_VOLUME_TAG_UNDEFINED_PRIMARY 0x0c 287 #define SEND_VOLUME_TAG_UNDEFINED_ALTERNATE 0x0d 288 289 u_int8_t reserved4[2]; 290 u_int8_t pll[2]; /* parameter list length */ 291 u_int8_t reserved5; 292 u_int8_t control; 293 }; 294 295 /* 296 * Parameter format for SEND VOLUME TAG 297 */ 298 299 struct scsi_send_volume_tag_parameters { 300 u_int8_t vitf[32]; /* volume tag identification template */ 301 u_int8_t reserved1[2]; 302 u_int8_t minvsn[2]; /* minimum volume sequence number */ 303 u_int8_t reserved2[2]; 304 u_int8_t maxvsn[2]; /* maximum volume sequence number */ 305 }; 306 307 /* 308 * Device capabilities page. 309 * 310 * This page defines characteristics of the elemenet types in the 311 * medium changer device. 312 * 313 * Note in the definitions below, the following abbreviations are 314 * used: 315 * MT Medium transport element (picker) 316 * ST Storage transport element (slot) 317 * IE Import/export element (portal) 318 * DT Data tranfer element (tape/disk drive) 319 */ 320 struct page_device_capabilities { 321 u_int8_t pg_code; /* page code (0x1f) */ 322 u_int8_t pg_length; /* page length (0x12) */ 323 324 /* 325 * The STOR_xx bits indicate that an element of a given 326 * type may provide independent storage for a unit of 327 * media. The top four bits of this value are reserved. 328 */ 329 u_int8_t stor; 330 #define STOR_MT 0x01 331 #define STOR_ST 0x02 332 #define STOR_IE 0x04 333 #define STOR_DT 0x08 334 335 u_int8_t reserved0; 336 337 /* 338 * The MOVE_TO_yy bits indicate the changer supports 339 * moving a unit of medium from an element of a given type to an 340 * element of type yy. This is used to determine if a given 341 * MOVE MEDIUM command is legal. The top four bits of each 342 * of these values are reserved. 343 */ 344 u_int8_t move_from[CHET_MAX + 1]; 345 #define MOVE_TO_MT 0x01 346 #define MOVE_TO_ST 0x02 347 #define MOVE_TO_IE 0x04 348 #define MOVE_TO_DT 0x08 349 350 u_int8_t reserved1[4]; 351 352 /* 353 * Similar to above, but for EXCHANGE MEDIUM. 354 */ 355 u_int8_t exchange_with[CHET_MAX + 1]; 356 #define EXCHANGE_WITH_MT 0x01 357 #define EXCHANGE_WITH_ST 0x02 358 #define EXCHANGE_WITH_IE 0x04 359 #define EXCHANGE_WITH_DT 0x08 360 }; 361 362 /* 363 * Medium changer elemement address assignment page. 364 * 365 * Some of these fields can be a little confusing, so an explanation 366 * is in order. 367 * 368 * Each component within a a medium changer apparatus is called an 369 * "element". 370 * 371 * The "medium transport element address" is the address of the first 372 * picker (robotic arm). "Number of medium transport elements" tells 373 * us how many pickers exist in the changer. 374 * 375 * The "first storage element address" is the address of the first 376 * slot in the tape or disk magazine. "Number of storage elements" tells 377 * us how many slots exist in the changer. 378 * 379 * The "first import/export element address" is the address of the first 380 * medium portal accessible both by the medium changer and an outside 381 * human operator. This is where the changer might deposit tapes destined 382 * for some vault. The "number of import/export elements" tells us 383 * not many of these portals exist in the changer. NOTE: this number may 384 * be 0. 385 * 386 * The "first data transfer element address" is the address of the first 387 * tape or disk drive in the changer. "Number of data transfer elements" 388 * tells us how many drives exist in the changer. 389 */ 390 struct page_element_address_assignment { 391 u_int8_t pg_code; /* page code (0x1d) */ 392 u_int8_t pg_length; /* page length (0x12) */ 393 394 /* Medium transport element address */ 395 u_int8_t mtea[2]; 396 397 /* Number of medium transport elements */ 398 u_int8_t nmte[2]; 399 400 /* First storage element address */ 401 u_int8_t fsea[2]; 402 403 /* Number of storage elements */ 404 u_int8_t nse[2]; 405 406 /* First import/export element address */ 407 u_int8_t fieea[2]; 408 409 /* Number of import/export elements */ 410 u_int8_t niee[2]; 411 412 /* First data transfer element address */ 413 u_int8_t fdtea[2]; 414 415 /* Number of data trafer elements */ 416 u_int8_t ndte[2]; 417 418 u_int8_t reserved[2]; 419 }; 420 421 /* 422 * Transport geometry parameters page. 423 * 424 * Defines whether each medium transport element is a member of a set of 425 * elements that share a common robotics subsystem and whether the element 426 * is capable of media rotation. One transport geometry descriptor is 427 * transferred for each medium transport element, beginning with the first 428 * medium transport element (other than the default transport element address 429 * of 0). 430 */ 431 struct page_transport_geometry_parameters { 432 u_int8_t pg_code; /* page code (0x1e) */ 433 u_int8_t pg_length; /* page length; variable */ 434 435 /* Transport geometry descriptor(s) are here. */ 436 437 u_int8_t misc; 438 #define CAN_ROTATE 0x01 439 440 /* Member number in transport element set. */ 441 u_int8_t member; 442 }; 443 444 __BEGIN_DECLS 445 void scsi_move_medium(struct ccb_scsiio *csio, u_int32_t retries, 446 void (*cbfcnp)(struct cam_periph *, union ccb *), 447 u_int8_t tag_action, u_int32_t tea, u_int32_t src, 448 u_int32_t dst, int invert, u_int8_t sense_len, 449 u_int32_t timeout); 450 451 void scsi_exchange_medium(struct ccb_scsiio *csio, u_int32_t retries, 452 void (*cbfcnp)(struct cam_periph *, union ccb *), 453 u_int8_t tag_action, u_int32_t tea, u_int32_t src, 454 u_int32_t dst1, u_int32_t dst2, int invert1, 455 int invert2, u_int8_t sense_len, u_int32_t timeout); 456 457 void scsi_position_to_element(struct ccb_scsiio *csio, u_int32_t retries, 458 void (*cbfcnp)(struct cam_periph *, union ccb *), 459 u_int8_t tag_action, u_int32_t tea, u_int32_t dst, 460 int invert, u_int8_t sense_len, 461 u_int32_t timeout); 462 463 void scsi_read_element_status(struct ccb_scsiio *csio, u_int32_t retries, 464 void (*cbfcnp)(struct cam_periph *, union ccb *), 465 u_int8_t tag_action, int voltag, u_int32_t sea, 466 u_int32_t count, u_int8_t *data_ptr, 467 u_int32_t dxfer_len, u_int8_t sense_len, 468 u_int32_t timeout); 469 470 void scsi_initialize_element_status(struct ccb_scsiio *csio, u_int32_t retries, 471 void (*cbfcnp)(struct cam_periph *, union ccb *), 472 u_int8_t tag_action, u_int8_t sense_len, 473 u_int32_t timeout); 474 void scsi_send_volume_tag(struct ccb_scsiio *csio, u_int32_t retries, 475 void (*cbfcnp)(struct cam_periph *, union ccb *), 476 u_int8_t tag_action, 477 u_int16_t element_address, 478 u_int8_t send_action_code, 479 struct scsi_send_volume_tag_parameters *parameters, 480 u_int8_t sense_len, u_int32_t timeout); 481 __END_DECLS 482 483 #endif /* _SCSI_SCSI_CH_H */ 484