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