1 /*
2  * Copyright (c) 1998,1999,2000
3  *      Traakan, Inc., Los Altos, CA
4  *      All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice unmodified, this list of conditions, and the following
11  *    disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 /*
30  * Project:  NDMJOB
31  * Ident:    $Id: $
32  *
33  * Description:
34  *
35  */
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 /*
42  * 17.1 Medium-changer device model
43  *
44  * Medium changer devices mechanize the movement of media to and from
45  * primary devices (such as disk or tape drives) and other locations
46  * within the range of the medium changer. The medium changer command set
47  * is based on a physical model of this functionality.
48  *
49  * This command set supports varied physical implementations of the medium
50  * changer function. Most of these variations are hidden from the
51  * initiator by the high level of function provided by the MOVE MEDIUM and
52  * EXCHANGE MEDIUM commands and by the generalized nature of the element
53  * addressing scheme. However, initiators may need to be aware of the
54  * capabilities of the particular medium changer device. These
55  * characteristics and capabilities are conveyed via MODE SENSE pages.
56  *
57  * 17.1.1 Medium-changer elements
58  *
59  * The medium-changer command set uses as its address space the set of
60  * physical locations and mechanisms within the scope of a medium changer
61  * device. The term element is used throughout this clause to refer to one
62  * member of the medium changer address space. Each element is a discrete
63  * physical entity that may hold zero or one physical unit of media - one
64  * disk cartridge, one spool of tape, etc. Element addresses do not extend
65  * across multiple physical units of media. Likewise, element addresses
66  * are independent of any logical partitioning that the primary device may
67  * support within a physical unit of media.
68  *
69  * A medium changer is viewed as a set of addressable elements, each of
70  * which may contain a unit of media or be used to move a unit of media.
71  * Each medium changer element has a unique 16 bit element address. Each
72  * element is an instance of one of four classes or element types.
73  *
74  *    a)     MEDIUM TRANSPORT ELEMENT
75  *    b)     STORAGE ELEMENT
76  *    c)     IMPORT EXPORT ELEMENT
77  *    d)     DATA TRANSFER ELEMENT
78  *
79  * Units of media (cartridges, cassettes, caddies, etc.) are referred to
80  * only indirectly by this device model.  Units of media can be moved to
81  * or from any of the elements of the medium changer device.  The presence
82  * of media at the various elements in a medium changer can be sensed.  In
83  * order to ensure exclusive access to a unit of media, the element where
84  * the unit of media is located (the element address) must be reserved.
85  *
86  * Elements of the medium transport, import export and (rarely) data
87  * transport types may not provide independent storage for medium.  The
88  * capabilities of a particular medium changer in this respect can be
89  * sensed via the device capabilities page of the mode sense data. The
90  * following hypothetical medium changer implementation illustrates one
91  * case of an element not providing independent storage for medium.
92  * Consider a medium changer which has a carousel style storage for
93  * medium. The import export function could be provided by a port which
94  * allows operator access to one of the storage elements.  In such a
95  * device, the MOVE ELEMENT command from storage element to import export
96  * element would rotate the carousel to align the addressed storage
97  * element to the import export position. In this case the import export
98  * element does not provide independent storage but rather access to one
99  * of the storage elements.
100  *
101  * 17.1.1.1 Medium transport elements
102  *
103  * Medium transport elements address the functions of the medium changer
104  * device that perform the movement of units of media. Where a medium
105  * transport element can serve (even temporarily) as a storage location
106  * for medium, the location of each unit of media must have a separate
107  * element address.
108  *
109  * In larger medium changer devices, the medium movement functions may be
110  * performed by multiple independent robotics subsystems. Each of these
111  * may have a number of medium transport element addresses. The element
112  * addresses within each subsystem shall be contiguous. Any of the element
113  * addresses within a subsystem may be used interchangeably in the medium
114  * transport element address field of MOVE MEDIUM and EXCHANGE MEDIUM
115  * commands. An initiator may determine the capabilities of the medium
116  * movement facilities of a medium changer device via the transport
117  * geometry MODE SENSE page, see 17.3.3.3.
118  *
119  * Element address zero is reserved for use in the medium transport
120  * element address field of MOVE MEDIUM and EXCHANGE MEDIUM commands to
121  * direct the medium changer to use a default or medium changer selected
122  * medium transport element.
123  *
124  * In some implementations, medium transport elements may be source and/or
125  * destination addresses in MOVE MEDIUM and EXCHANGE MEDIUM commands.
126  * They may or may not provide independent storage of a unit of media.
127  * See the device capabilities MODE SENSE page, see 17.3.3.
128  *
129  * 17.1.1.2 Storage elements
130  *
131  * Storage elements are locations of units of media while not in some
132  * other element type.  Medium in storage elements is available for access
133  * by medium transport elements.
134  *
135  * Storage elements may be source and/or destination addresses in MOVE
136  * MEDIUM and EXCHANGE MEDIUM commands.
137  *
138  * 17.1.1.3 Import export elements
139  *
140  * Import export elements are locations of units of media which are being
141  * inserted into or withdrawn from the medium changer device.  Medium in
142  * these elements is accessible by both medium transport elements, by the
143  * operator, or by another independent medium changer device.
144  *
145  * Import export elements may be source and/or destination addresses in
146  * MOVE MEDIUM and EXCHANGE MEDIUM commands. They may or may not provide
147  * independent storage of a unit of media, see the device capabilities
148  * MODE SENSE page, see 17.3.3.
149  *
150  * Particular import export elements may be capable of either import
151  * actions, export actions, both or neither (if an element is not
152  * present).
153  *
154  * 17.1.1.4 Data transfer element
155  *
156  * Data transfer elements are locations of the primary devices which are
157  * capable of reading or writing the medium. Data transfer elements may
158  * also be viewed as medium changer element addresses of units of media
159  * loaded in or available for loading in or removal from primary devices
160  * such as disk or tape drives. Note that the medium changer function
161  * specified in this clause does not control the primary device. That is
162  * the responsibility of the system.
163  *
164  * Data transfer elements may be source and/or destination addresses in
165  * MOVE MEDIUM and EXCHANGE MEDIUM commands. They may or may not provide
166  * independent storage of a unit of media, see the device capabilities
167  * MODE SENSE page, see 17.3.3.
168  */
169 
170 /*
171  *                        Table 333 - Element type code
172  *     +=============-===================================================+
173  *     |    Code     |  Description                                      |
174  *     |-------------+---------------------------------------------------|
175  *     |      0h     |  All element types reported, (valid in CDB only)  |
176  *     |      1h     |  Medium transport element                         |
177  *     |      2h     |  Storage element                                  |
178  *     |      3h     |  Import export element                            |
179  *     |      4h     |  Data transfer element                            |
180  *     |   5h - Fh   |  Reserved                                         |
181  *     +=================================================================+
182  */
183 
184 #define SMC_ELEM_TYPE_ALL 0
185 #define SMC_ELEM_TYPE_MTE 1
186 #define SMC_ELEM_TYPE_SE 2
187 #define SMC_ELEM_TYPE_IEE 3
188 #define SMC_ELEM_TYPE_DTE 4
189 
190 
191 /*
192  * 17.1.5 Volume tags
193  *
194  * The read element status descriptor format for all element types
195  * includes two sets of fields that contain volume tag information. These
196  * optional fields are used to report media identification information
197  * that the medium changer has acquired either by reading an external
198  * label (e.g. bar code labels), by a SEND VOLUME TAG command or by other
199  * means which may be vendor unique. The same volume tag information shall
200  * be available to all initiators whether assigned by that initiator, by
201  * some other initiator or by the media changer itself.
202  *
203  * Volume tag information provides a means to confirm the identity of a
204  * unit of media that resides in a medium changer element. This command
205  * set does not define any direct addressing of units of media based on
206  * these fields. However, commands are defined that provide translation
207  * between volume tag information and the element address where that unit
208  * of media currently resides.
209  *
210  * The medium changer command set definition does not impose the
211  * requirement that volume tag information be unique over the units of
212  * media within the scope of the changer device.
213  *
214  * The following commands support the optional volume tag functionality:
215  *    a)     SEND VOLUME TAG - either as a translation request or to associate
216  *           a volume tag with the unit of media currently residing at an
217  *           element address.
218  *    b)     REQUEST VOLUME ELEMENT ADDRESS - return the element address
219  *           currently associated with the volume tag information transferred
220  *           with the last send volume tag command.
221  *    c)     READ ELEMENT STATUS - optionally reports volume tag information
222  *           for all element types.
223  *    d)     MOVE MEDIUM and EXCHANGE MEDIUM commands - if volume tags are
224  *           implemented, these commands must retain the association between
225  *           volume tag information and units of media as they are moved from
226  *           element to element.
227  *
228  * 17.1.5.1 Volume tag format
229  *
230  * Volume tag information consists of a volume identifier field of 32
231  * bytes plus a volume sequence number field of 2 bytes. The volume
232  * identifier shall consist of a left justified sequence of ASCII
233  * characters. Unused positions shall be blank (20h) filled.  In order for
234  * the SEND VOLUME TAG translate with template to work the characters '*'
235  * and'?' (2Ah and 3Fh) must not appear in volume identification data and
236  * there must be no blanks (20h) within the significant part of the volume
237  * identifier. If volume tag information for a particular element is
238  * undefined, the volume identifier field shall be zero.
239  *
240  * The volume sequence number is a 2 byte integer field. If the volume
241  * sequence number is not used this field shall be zero.  The volume tag
242  * contents are independent of the volume identification information
243  * recorded on the media.
244  *
245  *  NOTE 199 For compatibility with the volume identifier defined by volume
246  *  and file structure standards, it is recommended that the characters in the
247  *  significant non-blank portion of the volume identifier field be restricted
248  *  to the set: '0'..'9', 'A'..'Z', and '_' (30h .. 39h, 41h .. 5Ah, 5Fh).
249  *  Specific systems may have differing requirements that may take precedence
250  *  over this recommendation.
251  *
252  * Table 326 defines the fields within the 36 byte primary and alternate
253  * volume tag information fields found in READ ELEMENT STATUS descriptors
254  * and in the data format for the SEND VOLUME TAG command.
255  *
256  *                   Table 326 - Volume tag information format
257  * +=====-=======-=======-=======-========-========-========-=======-========+
258  * |  Bit|   7   |   6   |   5   |   4    |   3    |   2    |   1   |   0    |
259  * |Byte |       |       |       |        |        |        |       |        |
260  * |=====+===================================================================|
261  * | 0   |                                                                   |
262  * |- - -+---                Volume identification field                  ---|
263  * | 31  |                                                                   |
264  * |-----+-------------------------------------------------------------------|
265  * | 32  |                                                                   |
266  * |- - -+---                         Reserved                            ---|
267  * | 33  |                                                                   |
268  * |-----+-------------------------------------------------------------------|
269  * | 34  | (MSB)                                                             |
270  * |-----+---                  Volume sequence number                     ---|
271  * | 35  |                                                             (LSB) |
272  * +=========================================================================+
273  *
274  *
275  * 17.1.5.2 Primary and alternate volume tag information
276  *
277  * Element status descriptors as reported by the READ ELEMENT STATUS
278  * command define a primary volume tag and an alternate volume tag.
279  * Alternate volume tag information provides a means for a system to use
280  * different volume identification information for each side of double
281  * sided media. In such a system, the primary volume tag information
282  * refers to the logical medium accessible via a MOVE MEDIUM command
283  * without the invert bit set. The alternate volume tag information refers
284  * to the other side of the media, i.e. the side that would be accessed
285  * via a MOVE MEDIUM command with the invert bit set.
286  */
287 
288 #define SMC_VOL_TAG_LEN 36
289 
290 struct smc_raw_volume_tag {
291   unsigned char volume_id[32];
292   unsigned char resv32[2];
293   unsigned char volume_seq[2];
294 };
295 
296 
297 /*
298  * 17.1.4 Element status maintenance requirements
299  *
300  * If the medium changer device chooses to implement the READ ELEMENT
301  * STATUS command, the medium changer device must be capable of reporting
302  * the various data (i.e. full, error, etc.) required by each page type.
303  * The medium changer may maintain this information at all times or
304  * regenerate it in response to the READ ELEMENT STATUS command. The
305  * INITIALIZE ELEMENT STATUS command can be used to force regeneration of
306  * this information.
307  */
308 
309 /*
310  * 17.2.5 READ ELEMENT STATUS command
311  *
312  * The READ ELEMENT STATUS command (see table 332) requests that the
313  * target report the status of its internal elements to the initiator.
314  *
315  *                    Table 332 - READ ELEMENT STATUS command
316  * +====-=======-========-========-========-========-========-========-=======+
317  * | Bit|  7    |   6    |   5    |   4    |   3    |   2    |   1    |   0   |
318  * |Byte|       |        |        |        |        |        |        |       |
319  * |====+=====================================================================|
320  * | 0  |                          Operation code (B8h)                       |
321  * |----+---------------------------------------------------------------------|
322  * | 1  |Logical unit number      | VolTag |        Element type code         |
323  * |----+---------------------------------------------------------------------|
324  * | 2  |(MSB)                                                                |
325  * |----+--                        Starting element address                 --|
326  * | 3  |                                                                (LSB)|
327  * |----+---------------------------------------------------------------------|
328  * | 4  |(MSB)                                                                |
329  * |----+--                        Number of elements                       --|
330  * | 5  |                                                                (LSB)|
331  * |----+---------------------------------------------------------------------|
332  * | 6  |                          Reserved                                   |
333  * |----+---------------------------------------------------------------------|
334  * | 7  |(MSB)                                                                |
335  * |----+--                                                                 --|
336  * | 8  |                          Allocation length                          |
337  * |----+--                                                                 --|
338  * | 9  |                                                                (LSB)|
339  * |----+---------------------------------------------------------------------|
340  * |10  |                          Reserved                                   |
341  * |----+---------------------------------------------------------------------|
342  * |11  |                          Control                                    |
343  * +==========================================================================+
344  *
345  *
346  * A volume tag (VolTag) bit of one indicates that the target shall report
347  * volume tag information if this feature is supported. A value of zero
348  * indicates that volume tag information shall not be reported. If the
349  * volume tag feature is not supported this field shall be treated as
350  * reserved.
351  *
352  * The element type code field specifies the particular element type(s)
353  * selected for reporting by this command.  A value of zero specifies that
354  * status for all element types shall be reported.  The element type codes
355  * are defined in table 333.
356  *
357  *                         Table 333 - Element type code
358  *      (SEE ABOVE)
359  *
360  * The starting element address specifies the minimum element address to
361  * report. Only elements with an element type code permitted by the
362  * element type code specification, and an element address greater than or
363  * equal to the starting element address shall be reported. Element
364  * descriptor blocks are not generated for undefined element addresses.
365  *
366  * The number of elements specifies the maximum number of element
367  * descriptors to be created by the target for this command. The value
368  * specified by this field is not the range of element addresses to be
369  * considered for reporting but rather the number of defined elements to
370  * report. If the allocation length is not sufficient to transfer all the
371  * element descriptors, the target shall transfer all those descriptors
372  * that can be completely transferred and this shall not be considered an
373  * error.
374  *
375  * 17.2.5.1 Element status data
376  *
377  * The data returned by the READ ELEMENT STATUS command is defined in
378  * table 334 and 17.2.5.3 through 17.2.5.6.  Element status data consists
379  * of an eight-byte header, (see table 334) followed by one or more
380  * element status pages.
381  *
382  *                        Table 334 - Element status data
383  * +====-=======-========-========-========-========-========-========-=======+
384  * | Bit|  7    |   6    |   5    |   4    |   3    |   2    |   1    |   0   |
385  * |Byte|       |        |        |        |        |        |        |       |
386  * |====+=====================================================================|
387  * | 0  |(MSB)                                                                |
388  * |----+--                  First element address reported                 --|
389  * | 1  |                                                                (LSB)|
390  * |----+---------------------------------------------------------------------|
391  * | 2  |(MSB)                                                                |
392  * |----+--                    Number of elements available                 --|
393  * | 3  |                                                                (LSB)|
394  * |----+---------------------------------------------------------------------|
395  * | 4  |                             Reserved                                |
396  * |----+---------------------------------------------------------------------|
397  * | 5  |(MSB)                                                                |
398  * |----+--                                                                 --|
399  * | 6  |                    Byte count of report available                   |
400  * |----+--                        (all pages, n - 7 )                      --|
401  * | 7  |                                                                (LSB)|
402  * |====+=====================================================================|
403  * | 8  |                                                                     |
404  * |- - +--                     Element status page(s)                      --|
405  * | n  |                                                                     |
406  * +==========================================================================+
407  *
408  *
409  * The first element address reported field indicates the element address
410  * of the element with the smallest element address found to meet the CDB
411  * request.
412  *
413  * The number of elements available field indicates the number of elements
414  * meeting the request in the command descriptor block.  The status for
415  * these elements is returned if sufficient allocation length was
416  * specified.
417  *
418  * The byte count of report available field indicates the number of bytes
419  * of element status page data available for all elements meeting the
420  * request in the command descriptor block.  This value shall not be
421  * adjusted to match the allocation length available.
422  *
423  *    NOTE 202 - The READ ELEMENT STATUS command can be issued with an
424  *    allocation length of eight bytes in order to determine the allocation
425  *    length required to transfer all the element status data specified by the
426  *    command.
427  *
428  * Figure 28 provides an illustration of the element status data
429  * structure.
430  *
431  *           Figure 28 - Illustration of element status data structure
432  *
433  *
434  * 17.2.5.2 Element status page
435  *
436  * The element status page is defined in table 335.  Each element status
437  * page includes an eight-byte header followed by one or more element
438  * descriptor blocks.  The header includes the element type code, the
439  * length of each descriptor block and the number of bytes of element
440  * descriptor information that follow the header for this element type.
441  *
442  *                        Table 335 - Element status page
443  * +====-=======-========-========-========-========-========-========-=======+
444  * | Bit|  7    |   6    |   5    |   4    |   3    |   2    |   1    |   0   |
445  * |Byte|       |        |        |        |        |        |        |       |
446  * |====+=====================================================================|
447  * | 0  |                          Element type code                          |
448  * |----+---------------------------------------------------------------------|
449  * | 1  |PVolTag| AVolTag|                      Reserved                      |
450  * |----+---------------------------------------------------------------------|
451  * | 2  |(MSB)                                                                |
452  * |----+--                    Element descriptor length                    --|
453  * | 3  |                                                                (LSB)|
454  * |----+---------------------------------------------------------------------|
455  * | 4  |                             Reserved                                |
456  * |----+---------------------------------------------------------------------|
457  * | 5  |(MSB)                                                                |
458  * |----+--                                                                 --|
459  * | 6  |               Byte count of descriptor data available               |
460  * |----+--                      (this page, n - 7)                         --|
461  * | 7  |                                                                (LSB)|
462  * |====+=====================================================================|
463  * | 8  |                                                                     |
464  * |- - +--                     Element descriptor(s)                       --|
465  * | n  |                                                                     |
466  * +==========================================================================+
467  *
468  *
469  * The element type code field indicates the element type reported by this
470  * page.
471  *
472  * A primary volume tag (PVolTag) bit of one indicates that the primary
473  * volume tag information field is present in each of the following
474  * element descriptor blocks. A value of zero indicates that these bytes
475  * are omitted from the element descriptors that follow.
476  *
477  * An alternate volume tag (AVolTag) bit of one indicates that the
478  * alternate volume tag information field is present in each of the
479  * following element descriptor blocks. A value of zero indicates that
480  * these bytes are omitted from the element descriptors that follow.
481  *
482  * The element descriptor length field indicates the number of bytes in
483  * each element descriptor.
484  *
485  * The byte count of descriptor data available field indicates the number
486  * of bytes of element descriptor data available for elements of this
487  * element type meeting the request in the CDB. This value shall not be
488  * adjusted to match the allocation length available.
489  *
490  * Each element descriptor includes the element address and status flags;
491  * it may also contain sense code information as well as other information
492  * depending on the element type (see 17.2.5.3 through 17.2.5.6).
493  *
494  * 17.2.5.3 Medium transport element descriptor
495  *
496  * Table 336 defines the medium transport element descriptor.
497  *
498  *                Table 336 - Medium transport element descriptor
499  * +====-======-========-========-========-========-========-========-=======+
500  * | Bit|  7   |   6    |   5    |   4    |   3    |   2    |   1    |   0   |
501  * |Byte|      |        |        |        |        |        |        |       |
502  * |====+====================================================================|
503  * | 0  |(MSB)                                                               |
504  * |----+--                     Element address                            --|
505  * | 1  |                                                               (LSB)|
506  * |----+--------------------------------------------------------------------|
507  * | 2  |          Reserved                        | Except |Reserved|  Full |
508  * |----+--------------------------------------------------------------------|
509  * | 3  |                          Reserved                                  |
510  * |----+--------------------------------------------------------------------|
511  * | 4  |                    Additional sense code                           |
512  * |----+--------------------------------------------------------------------|
513  * | 5  |                Additional sense code qualifier                     |
514  * |----+--------------------------------------------------------------------|
515  * | 6  |                                                                    |
516  * | - -+--                        Reserved                                --|
517  * | 8  |                                                                    |
518  * |----+--------------------------------------------------------------------|
519  * | 9  |SValid| Invert |                      Reserved                      |
520  * |----+--------------------------------------------------------------------|
521  * |10  |(MSB)                                                               |
522  * |----+--               Source storage element address                   --|
523  * |11  |                                                              (LSB) |
524  * |----+--------------------------------------------------------------------|
525  * |12  |                                                                    |
526  * | - -+--               Primary volume tag information                   --|
527  * |47  |                 (Field omitted if PVolTag = 0)                     |
528  * |----+--------------------------------------------------------------------|
529  * |48  |                                                                    |
530  * | - -+--              Alternate volume tag information                  --|
531  * |83  |                 (Field omitted if AVolTag = 0)                     |
532  * |----+--------------------------------------------------------------------|
533  * |84  |                                                                    |
534  * | - -+--                         Reserved                               --|
535  * |87  |  (Field moved up if volume tag information field(s) are omitted.)  |
536  * |----+--------------------------------------------------------------------|
537  * |88  |                                                                    |
538  * | - -+--                       Vendor-specific                          --|
539  * |z-1 |  (Field moved up if volume tag information field(s) are omitted.)  |
540  * +=========================================================================+
541  *
542  *
543  * The element address field gives the address of the medium changer
544  * element whose status is reported by this element descriptor block.
545  *
546  * An exception (Except) bit of one indicates the element is in an
547  * abnormal state.  An exception bit of zero indicates the element is in a
548  * normal state.  If this bit is one, information on the abnormal state
549  * may be available in the additional sense code and additional sense code
550  * qualifier bytes.
551  *
552  * A full bit value of one indicates that the element contains a unit of
553  * media.  A value of zero indicates that the element does not contain a
554  * unit of media.
555  *
556  * The additional sense code field may provide specific information on an
557  * abnormal element state.  The values in this field are as defined for
558  * the additional sense code of the REQUEST SENSE data (see 8.2.14.3).
559  *
560  * The additional sense code qualifier field may provide more detailed
561  * information on an abnormal element state.  The values in this field are
562  * as defined for the additional sense code qualifier of the REQUEST SENSE
563  * data (see 8.2.14.4).
564  *
565  * A source valid (SValid) bit value of one indicates that the source
566  * storage element address field and the invert bit information are valid.
567  * A value of zero indicates that the values in these fields are not
568  * valid.
569  *
570  * An invert bit value of one indicates that the unit of media now in this
571  * element was inverted by MOVE MEDIUM or EXCHANGE MEDIUM operations since
572  * it was last in the source storage element.  A value of zero indicates
573  * that no inversion occurred during the operation.
574  *
575  * The source storage element address field provides the address of the
576  * last storage element this unit of media was moved.  This field is valid
577  * only if the SValid bit is one.
578  *
579  * The primary and alternate volume tag information fields provide for
580  * identifying the unit of media residing in this element (see 17.1.5.).
581  * Either or both of these fields may be omitted for all the element
582  * descriptor blocks that comprise an element status page as indicated by
583  * the PVolTag and AVolTag bits in the element status page header.
584  *
585  * 17.2.5.4 Storage element descriptor
586  *
587  * Table 337 defines the storage element descriptor.
588  *
589  *                     Table 337 - Storage element descriptor
590  * +=====-======-========-========-========-========-========-========-=======+
591  * | Bit|  7   |   6    |   5    |   4    |   3    |   2    |   1    |   0   |
592  * |Byte|      |        |        |        |        |        |        |       |
593  * |====+====================================================================|
594  * | 0  |(MSB)                                                               |
595  * |----+--                     Element address                            --|
596  * | 1  |                                                               (LSB)|
597  * |----+--------------------------------------------------------------------|
598  * | 2  |          Reserved               | Access | Except |Reserved|  Full |
599  * |----+--------------------------------------------------------------------|
600  * | 3  |                          Reserved                                  |
601  * |----+--------------------------------------------------------------------|
602  * | 4  |                     Additional sense code                          |
603  * |----+--------------------------------------------------------------------|
604  * | 5  |                 Additional sense code qualifier                    |
605  * |----+--------------------------------------------------------------------|
606  * | 6  |                                                                    |
607  * | - -+--                        Reserved                                --|
608  * | 8  |                                                                    |
609  * |----+--------------------------------------------------------------------|
610  * | 9  |SValid| Invert |                      Reserved                      |
611  * |----+--------------------------------------------------------------------|
612  * |10  |(MSB)                                                               |
613  * |----+--                   Source element address                       --|
614  * |11  |                                                              (LSB) |
615  * |----+--------------------------------------------------------------------|
616  * |12  |                                                                    |
617  * | - -+--                Primary volume tag information                  --|
618  * |47  |                  (Field omitted if PVolTag = 0)                    |
619  * |----+--------------------------------------------------------------------|
620  * |48  |                                                                    |
621  * | - -+--               Alternate volume tag information                 --|
622  * |83  |                  (Field omitted if PVolTag = 0)                    |
623  * |----+--------------------------------------------------------------------|
624  * |84  |                                                                    |
625  * | - -+--                        Reserved                                --|
626  * |87  |  (Field moved up if volume tag information field(s) are omitted.)  |
627  * |----+--------------------------------------------------------------------|
628  * |88  |                                                                    |
629  * | - -+--                     Vendor unique                              --|
630  * |z-1 |  (Field moved up if volume tag information field(s) are omitted.)  |
631  * +=========================================================================+
632  *
633  *
634  * An access bit value of one indicates that access to the element by a
635  * medium transport element is allowed.  An access bit of zero indicates
636  * that access to the element by the medium transport element is denied.
637  *
638  * The source storage element address field provides the address of the
639  * last storage element this unit of media was moved from. This element
640  * address value may or may not be the same as this element. This field is
641  * valid only if the SValid bit is one.
642  *
643  * For fields not defined in this subclause, see 17.2.5.3.
644  *
645  * 17.2.5.5 Import export element descriptor
646  *
647  * Table 338 defines the import export element descriptor.
648  *
649  *                  Table 338 - Import export element descriptor
650  * +====-======-========-========-========-========-========-========-=======+
651  * | Bit|  7   |   6    |   5    |   4    |   3    |   2    |   1    |   0   |
652  * |Byte|      |        |        |        |        |        |        |       |
653  * |====+====================================================================|
654  * | 0  |(MSB)                                                               |
655  * |----+--                       Element address                          --|
656  * | 1  |                                                               (LSB)|
657  * |----+--------------------------------------------------------------------|
658  * | 2  |   Reserved    | InEnab | ExEnab | Access | Except | ImpExp |  Full |
659  * |----+--------------------------------------------------------------------|
660  * | 3  |                           Reserved                                 |
661  * |----+--------------------------------------------------------------------|
662  * | 4  |                      Additional sense code                         |
663  * |----+--------------------------------------------------------------------|
664  * | 5  |                  Additional sense code qualifier                   |
665  * |----+--------------------------------------------------------------------|
666  * | 6  |                                                                    |
667  * |----+--                         Reserved                               --|
668  * | 8  |                                                                    |
669  * |----+--------------------------------------------------------------------|
670  * | 9  |SValid| Invert |                      Reserved                      |
671  * |----+--------------------------------------------------------------------|
672  * |10  |(MSB)                                                               |
673  * |----+--                 Source storage element address                 --|
674  * |11  |                                                              (LSB) |
675  * |----+--------------------------------------------------------------------|
676  * |12  |                                                                    |
677  * | - -+--                 Primary volume tag information                 --|
678  * |47  |                   (Field omitted if PVolTag = 0)                   |
679  * |----+--------------------------------------------------------------------|
680  * |48  |                                                                    |
681  * | - -+--                Alternate volume tag information                --|
682  * |83  |                   (Field omitted if PVolTag = 0)                   |
683  * |----+--------------------------------------------------------------------|
684  * |84  |                                                                    |
685  * | - -+--                         Reserved                               --|
686  * |87  |   (Field moved up if volume tag information field(s) are omitted.) |
687  * |----+--------------------------------------------------------------------|
688  * |88  |                                                                    |
689  * | - -+--                        Vendor unique                           --|
690  * |z-1 |  (Field moved up if volume tag information field(s) are omitted.)  |
691  * +=========================================================================+
692  *
693  *
694  * An import enable (InEnab) bit of one indicates that the import export
695  * element supports movement of media into the scope of the medium changer
696  * device.  An InEnab bit of zero indicates that this element does not
697  * support import actions.
698  *
699  * An export enable (ExEnab) bit of one indicates that the import export
700  * element supports movement of media out of the scope of the medium
701  * changer device. An ExEnab bit of zero indicates that this element does
702  * not support export actions.
703  *
704  * An access bit of one indicates that access to the import export element
705  * by a medium transport element is allowed.  An access bit of zero
706  * indicates access to the import export element by medium transport
707  * elements is denied.
708  *
709  *    NOTE 203 An example of when access would be denied is when the operator
710  *    has exclusive access to the import export element.
711  *
712  * An import export (ImpExp) bit of one indicates the unit of media in the
713  * import export element was placed there by an operator.  An ImpExp bit
714  * of zero indicates the unit of media in the import export element was
715  * placed there by the medium transport element.
716  *
717  * For fields not defined in this clause, see 17.2.5.3.
718  *
719  * 17.2.5.6 Data transfer element descriptor
720  *
721  * Table 339 defines the data transfer element descriptor.
722  *
723  *                  Table 339 - Data transfer element descriptor
724  * +====-=======-========-========-========-========-========-========-=======+
725  * | Bit|  7    |   6    |   5    |   4    |   3    |   2    |   1    |   0   |
726  * |Byte|       |        |        |        |        |        |        |       |
727  * |====+=====================================================================|
728  * | 0  |(MSB)                                                                |
729  * |----+--                      Element address                            --|
730  * | 1  |                                                                (LSB)|
731  * |----+---------------------------------------------------------------------|
732  * | 2  |           Reserved               | Access | Except |Reserved|  Full |
733  * |----+---------------------------------------------------------------------|
734  * | 3  |                           Reserved                                  |
735  * |----+---------------------------------------------------------------------|
736  * | 4  |                      Additional sense code                          |
737  * |----+---------------------------------------------------------------------|
738  * | 5  |                  Additional sense code qualifier                    |
739  * |----+---------------------------------------------------------------------|
740  * | 6  Not bus|Reserved|ID valid|LU valid|Reserved|    Logical unit number   |
741  * |----+---------------------------------------------------------------------|
742  * | 7  |                        SCSI bus address                             |
743  * |----+---------------------------------------------------------------------|
744  * | 8  |                            Reserved                                 |
745  * |----+---------------------------------------------------------------------|
746  * | 9  |SValid | Invert |                      Reserved                      |
747  * |----+---------------------------------------------------------------------|
748  * |10  |(MSB)                                                                |
749  * |----+--              Source storage element address                     --|
750  * |11  |                                                               (LSB) |
751  * |----+---------------------------------------------------------------------|
752  * |12  |                                                                     |
753  * | - -+--                 Primary volume tag information                  --|
754  * |47  |                   (Field omitted if PVolTag = 0)                    |
755  * |----+---------------------------------------------------------------------|
756  * |48  |                                                                     |
757  * | - -+--                Alternate volume tag information                 --|
758  * |83  |                   (Field omitted if PVolTag = 0)                    |
759  * |----+---------------------------------------------------------------------|
760  * |84  |                                                                     |
761  * | - -+--                         Reserved                                --|
762  * |87  |   (Field moved up if volume tag information field(s) are omitted.)  |
763  * |----+---------------------------------------------------------------------|
764  * |88  |                                                                     |
765  * | - -+--                        Vendor unique                            --|
766  * |z-1 |   (Field moved up if volume tag information field(s) are omitted.)  |
767  * +==========================================================================+
768  *
769  *
770  * An access bit value of one indicates access to the data transfer
771  * element by the medium transport element is allowed.  A value of zero
772  * indicates access to the data transfer element by a medium transport
773  * element is denied.
774  *
775  *    NOTE 204 Access to the data transfer element by medium transport elements
776  *    might be denied if a data transfer operation was under way. Note that a
777  *    one value in this bit may not be sufficient to ensure a successful
778  *   operation. This bit can only reflect the best information available to the
779  *    medium changer device, which may not accurately reflect the state of the
780  *    primary (data transfer) device.
781  *
782  * A not this bus (not bus) bit value of one indicates that the SCSI bus
783  * address and logical unit number values are not valid for the SCSI bus
784  * used to select the medium changer device. A not bus bit value of zero
785  * indicates that the SCSI address and logical unit values, if valid, are
786  * on the same bus as the medium changer device.
787  *
788  * An ID Valid bit value of one indicates that the SCSI bus address field
789  * contains valid information. An LU Valid bit value of one indicates that
790  * the logical unit number field contains valid information.
791  *
792  * The SCSI bus address field, if valid, provides the SCSI address (binary
793  * representation) of the primary device served by the medium changer at
794  * this element address.
795  *
796  * The logical unit number field, if valid, provides the logical unit
797  * number within the SCSI bus device of the primary device served by the
798  * medium changer at this element address.
799  *
800  * For fields not defined in this clause, see 17.2.5.3.
801  */
802 
803 struct smc_raw_element_status_data_header {
804   unsigned char first_elem[2];
805   unsigned char n_elem[2];
806   unsigned char resv4;
807   unsigned char byte_count[3];
808 };
809 
810 struct smc_raw_element_status_page_header {
811   unsigned char element_type;
812   unsigned char flag1;
813 #define SMC_RAW_ESP_F1_PVolTag 0x80
814 #define SMC_RAW_ESP_F1_AVolTag 0x40
815   unsigned char elem_desc_len[2];
816   unsigned char resv4;
817   unsigned char byte_count[3];
818 };
819 
820 struct smc_raw_element_descriptor {
821   unsigned char element_address[2];
822   unsigned char flags2;
823 #define SMC_RAW_ED_F2_Full 0x01
824 #define SMC_RAW_ED_F2_ImpExp 0x02
825 #define SMC_RAW_ED_F2_Except 0x04
826 #define SMC_RAW_ED_F2_Access 0x08
827 #define SMC_RAW_ED_F2_ExEnab 0x10
828 #define SMC_RAW_ED_F2_InEnab 0x20
829 
830   unsigned char resv3;
831   unsigned char asc;
832   unsigned char ascq;
833   unsigned char flags6;
834 #define SMC_RAW_ED_F6_LUN 0x07
835 #define SMC_RAW_ED_F6_LU_valid 0x10
836 #define SMC_RAW_ED_F6_ID_valid 0x20
837 #define SMC_RAW_ED_F6_Not_bus 0x80
838 
839   unsigned char scsi_sid;
840 
841   unsigned char resv8;
842 
843   unsigned char flags9;
844 #define SMC_RAW_ED_F9_Invert 0x40
845 #define SMC_RAW_ED_F9_SValid 0x80
846 
847   unsigned char src_se_addr[2];
848 
849   /*
850    * primary_vol_tag (optional)
851    * alternate_vol_tag (optional)
852    * resv84
853    * vendor_specific
854    */
855   unsigned char data[SMC_VOL_TAG_LEN + SMC_VOL_TAG_LEN + 4 + 4];
856 };
857 
858 
859 /*
860  * 17.3.3.2 Element address assignment page
861  *
862  * The element address assignment page (see table 352) is used to assign
863  * addresses to the elements of the medium changer (MODE SELECT) and to
864  * report those assignments (MODE SENSE). This page also defines the
865  * number of each type of element present.
866  *
867  *                  Table 352 - Element address assignment page
868  * +====-=======-========-========-========-========-========-========-=======+
869  * | Bit|  7    |   6    |   5    |   4    |   3    |   2    |   1    |   0   |
870  * |Byte|       |        |        |        |        |        |        |       |
871  * |====+=======+========+====================================================|
872  * | 0  |  PS   |Reserved|         Page code (1Dh)                            |
873  * |----+---------------------------------------------------------------------|
874  * | 1  |                          Parameter length (12h)                     |
875  * |----+---------------------------------------------------------------------|
876  * | 2  |(MSB)                                                                |
877  * |----+--                        Medium transport element address         --|
878  * | 3  |                                                                (LSB)|
879  * |----+---------------------------------------------------------------------|
880  * | 4  |(MSB)                                                                |
881  * |----+--                        Number of medium transport elements      --|
882  * | 5  |                                                                (LSB)|
883  * |----+---------------------------------------------------------------------|
884  * | 6  |(MSB)                                                                |
885  * |----+--                        First storage element address            --|
886  * | 7  |                                                                (LSB)|
887  * |----+---------------------------------------------------------------------|
888  * | 8  |(MSB)                                                                |
889  * |----+--                        Number of storage elements               --|
890  * | 9  |                                                                (LSB)|
891  * |----+---------------------------------------------------------------------|
892  * | 10 |(MSB)                                                                |
893  * |----+--                        First import export element address      --|
894  * | 11 |                                                                (LSB)|
895  * |----+---------------------------------------------------------------------|
896  * | 12 |(MSB)                                                                |
897  * |----+--                        Number of import export elements         --|
898  * | 13 |                                                                (LSB)|
899  * |----+---------------------------------------------------------------------|
900  * | 14 |(MSB)                                                                |
901  * |----+--                        First data transfer element address      --|
902  * | 15 |                                                                (LSB)|
903  * |----+---------------------------------------------------------------------|
904  * | 16 |(MSB)                                                                |
905  * |----+--                        Number of data transfer elements         --|
906  * | 17 |                                                                (LSB)|
907  * |----+---------------------------------------------------------------------|
908  * | 18 |                                                                     |
909  * |----+--                        Reserved                                 --|
910  * | 19 |                                                                     |
911  * +==========================================================================+
912  *
913  *
914  * The parameters savable (PS) bit is only used with the MODE SENSE
915  * command.  This bit is reserved with the MODE SELECT command.  A PS bit
916  * of one indicates that the target is capable of saving the page in a
917  * non-volatile vendor-specific location.
918  *
919  * The first medium transport element address field identifies the first
920  * medium transport element contained in the medium changer (other than
921  * the default medium transport address of zero). The number of medium
922  * transport elements field defines the total number of medium transport
923  * elements contained in the medium changer. If the number of medium
924  * transport elements field in a MODE SELECT command is greater than the
925  * default value returned in the MODE SENSE parameter data, the target
926  * shall return CHECK CONDITION status and set the sense key to ILLEGAL
927  * REQUEST.
928  *
929  * The first storage element address field identifies the first medium
930  * storage element contained in the medium changer.  The number of storage
931  * elements field defines the total number of medium storage elements
932  * contained in the medium changer. If the number of medium storage
933  * elements field in a MODE SELECT command is greater than the default
934  * value returned in the MODE SENSE parameter data, the target shall
935  * return CHECK CONDITION status and set the sense key to ILLEGAL REQUEST.
936  *
937  * The first import export element address field identifies the first
938  * medium portal that is accessible both by the medium transport devices
939  * and also by an operator from outside the medium changer. The number of
940  * import export elements field defines the total number of import export
941  * elements contained in the medium changer and accessible to the medium
942  * transport elements. If the number of import export elements field in a
943  * MODE SELECT command is greater than the default value returned in the
944  * MODE SENSE parameter data, the target shall return CHECK CONDITION
945  * status and set the sense key to ILLEGAL REQUEST .
946  *
947  *    NOTE 207 The number of import export elements may be zero.
948  *
949  * The first data transfer element address field identifies the first data
950  * transfer element contained in the medium changer.  The data transfer
951  * elements may be either read/write or read-only devices.  The number of
952  * data transfer field defines the total number of data transfer elements
953  * contained within the medium changer and accessible to the medium
954  * transport elements.  If the number of data transfer elements field in a
955  * MODE SELECT command is greater than the default value returned in the
956  * MODE SENSE parameter data, the target shall return CHECK CONDITION
957  * status and set the sense key to ILLEGAL REQUEST .
958  *
959  * Each element in the medium changer must have a unique address. If the
960  * address ranges defined for any of the element types overlap, the target
961  * shall return CHECK CONDITION status and set the sense key to ILLEGAL
962  * REQUEST.
963  */
964 
965 struct smc_raw_element_address_assignment_page {
966   unsigned char page_code; /* 0x1D */
967 #define SMC_RAW_EA_PC_PS 0x80
968   unsigned char param_length; /* 0x12 */
969   unsigned char mte_addr[2];
970   unsigned char mte_count[2];
971   unsigned char se_addr[2];
972   unsigned char se_count[2];
973   unsigned char iee_addr[2];
974   unsigned char iee_count[2];
975   unsigned char dte_addr[2];
976   unsigned char dte_count[2];
977   unsigned char resv18[2];
978 };
979 
980 
981 #define SMC_GET2(VEC) \
982   (uint16_t)((((unsigned char)(VEC)[0] << 8)) + (((unsigned char)(VEC)[1])))
983 
984 #define SMC_PUT2(VEC, VAL) \
985   ((VEC)[0] = (unsigned char)((VAL) >> 8), (VEC)[1] = (unsigned char)((VAL)))
986 
987 #define SMC_GET3(VEC)                            \
988   (uint32_t)((((unsigned char)(VEC)[0] << 16)) + \
989              (((unsigned char)(VEC)[1] << 8)) + ((unsigned char)(VEC)[2]))
990 
991 #define SMC_PUT3(VEC, VAL)                  \
992   ((VEC)[0] = (unsigned char)((VAL) >> 16), \
993    (VEC)[1] = (unsigned char)((VAL) >> 8), (VEC)[2] = (unsigned char)((VAL)))
994 
995 #define SMC_GET4(VEC)                            \
996   (uint32_t)((((unsigned char)(VEC)[0] << 24)) + \
997              (((unsigned char)(VEC)[1] << 16)) + \
998              (((unsigned char)(VEC)[2] << 8)) + ((unsigned char)(VEC)[3]))
999 
1000 #define SMC_PUT4(VEC, VAL)                  \
1001   ((VEC)[0] = (unsigned char)((VAL) >> 24), \
1002    (VEC)[1] = (unsigned char)((VAL) >> 16), \
1003    (VEC)[2] = (unsigned char)((VAL) >> 8), (VEC)[3] = (unsigned char)((VAL)))
1004 
1005 #ifdef __cplusplus
1006 }
1007 #endif
1008