Imported Upstream version 3.1.0
[debian/amanda] / ndmp-src / smc.h
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
38 #define SMC_MAX_SENSE_DATA      127
39
40 /* carefully layed out so that 16-byte/line hex dumps look nice */
41 struct smc_scsi_req {
42         unsigned char   completion_status;
43         unsigned char   status_byte;
44         unsigned char   data_dir;
45         unsigned char   n_cmd;
46
47         unsigned char   cmd[12];
48
49         unsigned char * data;
50         unsigned        n_data_avail;
51         unsigned        n_data_done;
52         unsigned long   _pad;
53
54         unsigned char   n_sense_data;
55         unsigned char   sense_data[SMC_MAX_SENSE_DATA];
56 };
57
58 #define SMCSR_CS_GOOD   0
59 #define SMCSR_CS_FAIL   1
60 /* more? */
61
62 #define SMCSR_DD_NONE   0
63 #define SMCSR_DD_IN     1       /* adapter->app */
64 #define SMCSR_DD_OUT    2       /* app->adapter */
65
66
67
68 struct smc_volume_tag {
69         unsigned char   volume_id[32];
70         unsigned short  volume_seq;
71 };
72
73
74
75 struct smc_element_address_assignment {
76         unsigned        mte_addr;       /* media transport element */
77         unsigned        mte_count;
78
79         unsigned        se_addr;        /* storage element */
80         unsigned        se_count;
81
82         unsigned        iee_addr;       /* import/export element */
83         unsigned        iee_count;
84
85         unsigned        dte_addr;       /* data transfer element */
86         unsigned        dte_count;
87 };
88
89
90 #define SMC_ELEM_TYPE_ALL       0
91 #define SMC_ELEM_TYPE_MTE       1
92 #define SMC_ELEM_TYPE_SE        2
93 #define SMC_ELEM_TYPE_IEE       3
94 #define SMC_ELEM_TYPE_DTE       4
95
96 struct smc_element_descriptor {
97         unsigned char   element_type_code;
98         unsigned short  element_address;
99
100         /* Flags, use SCSI spec names for convenience */
101         unsigned        PVolTag : 1;    /* MSID primary vol tag info present */
102         unsigned        AVolTag : 1;    /* MSID alternate vol tag present */
103         unsigned        InEnab  : 1;    /* --I- supports import */
104         unsigned        ExEnab  : 1;    /* --I- supports export */
105         unsigned        Access  : 1;    /* -SID access by a MTE allowed */
106         unsigned        Except  : 1;    /* MSID element in abnormal state */
107         unsigned        ImpExp  : 1;    /* --I- placed by operator */
108         unsigned        Full    : 1;    /* MSID contains a unit of media */
109         unsigned        Not_bus : 1;    /* ---D if ID_valid, not same bus */
110         unsigned        ID_valid: 1;    /* ---D scsi_sid valid */
111         unsigned        LU_valid: 1;    /* ---D scsi_lun valid */
112         unsigned        SValid  : 1;    /* MSID src_se_addr and Invert valid */
113         unsigned        Invert  : 1;    /* MSID inverted by MOVE/EXCHANGE */
114
115         unsigned char   asc;            /* Additional sense code */
116         unsigned char   ascq;           /* Additional sense code qualifier */
117         unsigned short  src_se_addr;    /* if Svalid, last *STORAGE* element */
118
119         unsigned char   scsi_sid;       /* if ID_valid, SID of drive */
120         unsigned char   scsi_lun;       /* if LU_valid, LUN of drive */
121
122         struct smc_volume_tag primary_vol_tag;  /* if PVolTag */
123         struct smc_volume_tag alternate_vol_tag;/* if AVolTag */
124 };
125
126
127
128 #ifndef SMC_MAX_ELEMENT
129 #define SMC_MAX_ELEMENT         80
130 #endif
131
132 struct smc_ctrl_block {
133         unsigned char           ident[32];
134
135         unsigned char           valid_elem_aa;
136         unsigned char           valid_elem_desc;
137
138         struct smc_element_address_assignment
139                                 elem_aa;
140
141         struct smc_element_descriptor
142                                 elem_desc[SMC_MAX_ELEMENT];
143         unsigned                n_elem_desc;
144
145         struct smc_scsi_req     scsi_req;
146
147         int                     (*issue_scsi_req)(struct smc_ctrl_block *smc);
148         void *                  app_data;
149
150         int                     dont_ask_for_voltags;
151
152         char                    errmsg[64];
153 };
154
155
156 extern int      smc_inquire (struct smc_ctrl_block *smc);
157 extern int      smc_test_unit_ready (struct smc_ctrl_block *smc);
158 extern int      smc_get_elem_aa (struct smc_ctrl_block *smc);
159 extern int      smc_init_elem_status (struct smc_ctrl_block *smc);
160 extern int      smc_read_elem_status (struct smc_ctrl_block *smc);
161
162 extern int      smc_move (struct smc_ctrl_block *smc,
163                         unsigned from_addr, unsigned to_addr, int invert,
164                         unsigned chs_addr);
165 extern int      smc_position (struct smc_ctrl_block *smc,
166                         unsigned to_addr, int invert);
167
168 extern int      smc_handy_move_to_drive (struct smc_ctrl_block *smc,
169                         unsigned from_se_ix);
170 extern int      smc_handy_move_from_drive (struct smc_ctrl_block *smc,
171                         unsigned to_se_ix);
172
173 extern char *   smc_elem_type_code_to_str(int code);
174
175 extern int      smc_pp_element_address_assignments (
176                         struct smc_element_address_assignment *eaa,
177                         int lineno, char *buf);
178
179 extern int      smc_pp_element_descriptor (struct smc_element_descriptor *edp,
180                         int lineno, char *ret_buf);