1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #ifndef __H_IBMVSCSI_TGT
18 #define __H_IBMVSCSI_TGT
19
20 #include <linux/interrupt.h>
21 #include "libsrp.h"
22
23 #define SYS_ID_NAME_LEN 64
24 #define PARTITION_NAMELEN 96
25 #define IBMVSCSIS_NAMELEN 32
26
27 #define MSG_HI 0
28 #define MSG_LOW 1
29
30 #define MAX_CMD_Q_PAGES 4
31 #define CRQ_PER_PAGE (PAGE_SIZE / sizeof(struct viosrp_crq))
32
33 #define DEFAULT_CMD_Q_SIZE CRQ_PER_PAGE
34 #define MAX_CMD_Q_SIZE (DEFAULT_CMD_Q_SIZE * MAX_CMD_Q_PAGES)
35
36 #define SRP_VIOLATION 0x102
37
38
39
40
41 #define SUPPORTED_FORMATS ((SRP_DATA_DESC_DIRECT << 1) | \
42 (SRP_DATA_DESC_INDIRECT << 1))
43
44 #define SCSI_LUN_ADDR_METHOD_FLAT 1
45
46 struct dma_window {
47 u32 liobn;
48 u64 tce_base;
49 u64 tce_size;
50 };
51
52 struct target_dds {
53 u64 unit_id;
54 #define NUM_DMA_WINDOWS 2
55 #define LOCAL 0
56 #define REMOTE 1
57 struct dma_window window[NUM_DMA_WINDOWS];
58
59
60 uint partition_num;
61 char partition_name[PARTITION_NAMELEN];
62 };
63
64 #define MAX_NUM_PORTS 1
65 #define MAX_H_COPY_RDMA (128 * 1024)
66
67 #define MAX_EYE 64
68
69
70 #define ADAPT_SUCCESS 0L
71
72 #define ERROR -40L
73
74 struct format_code {
75 u8 reserved;
76 u8 buffers;
77 };
78
79 struct client_info {
80 #define SRP_VERSION "16.a"
81 char srp_version[8];
82
83 char partition_name[PARTITION_NAMELEN];
84
85 u32 partition_number;
86
87 u32 mad_version;
88 u32 os_type;
89 };
90
91
92
93
94
95 #define SECONDS_TO_CONSIDER_FAILED 30
96
97
98
99
100 #define WAIT_SECONDS 1
101 #define WAIT_NANO_SECONDS 5000
102 #define MAX_TIMER_POPS ((1000000 / WAIT_NANO_SECONDS) * \
103 SECONDS_TO_CONSIDER_FAILED)
104
105
106
107
108 struct timer_cb {
109 struct hrtimer timer;
110
111
112
113
114
115
116 int timer_pops;
117
118 bool started;
119 };
120
121 struct cmd_queue {
122
123 struct viosrp_crq *base_addr;
124 dma_addr_t crq_token;
125
126 uint mask;
127
128 uint index;
129 int size;
130 };
131
132 #define SCSOLNT_RESP_SHIFT 1
133 #define UCSOLNT_RESP_SHIFT 2
134
135 #define SCSOLNT BIT(SCSOLNT_RESP_SHIFT)
136 #define UCSOLNT BIT(UCSOLNT_RESP_SHIFT)
137
138 enum cmd_type {
139 SCSI_CDB = 0x01,
140 TASK_MANAGEMENT = 0x02,
141
142 ADAPTER_MAD = 0x04,
143 UNSET_TYPE = 0x08,
144 };
145
146 struct iu_rsp {
147 u8 format;
148 u8 sol_not;
149 u16 len;
150
151 u64 tag;
152 };
153
154 struct ibmvscsis_cmd {
155 struct list_head list;
156
157 struct se_cmd se_cmd;
158 struct iu_entry *iue;
159 struct iu_rsp rsp;
160 struct work_struct work;
161 struct scsi_info *adapter;
162 struct ibmvscsis_cmd *abort_cmd;
163
164 unsigned char sense_buf[TRANSPORT_SENSE_BUFFER];
165 u64 init_time;
166 #define CMD_FAST_FAIL BIT(0)
167 #define DELAY_SEND BIT(1)
168 u32 flags;
169 char type;
170 };
171
172 struct ibmvscsis_nexus {
173 struct se_session *se_sess;
174 };
175
176 struct ibmvscsis_tport {
177
178 u8 tport_proto_id;
179
180 char tport_name[IBMVSCSIS_NAMELEN];
181
182 struct se_wwn tport_wwn;
183
184 struct se_portal_group se_tpg;
185
186 u16 tport_tpgt;
187
188 struct ibmvscsis_nexus *ibmv_nexus;
189 bool enabled;
190 bool releasing;
191 };
192
193 struct scsi_info {
194 struct list_head list;
195 char eye[MAX_EYE];
196
197
198 struct list_head waiting_rsp;
199 #define NO_QUEUE 0x00
200 #define WAIT_ENABLED 0X01
201 #define WAIT_CONNECTION 0x04
202
203 #define CONNECTED 0x08
204
205 #define SRP_PROCESSING 0x10
206
207 #define UNCONFIGURING 0x20
208
209 #define WAIT_IDLE 0x40
210
211 #define ERR_DISCONNECT 0x80
212
213 #define ERR_DISCONNECT_RECONNECT 0x100
214
215 #define ERR_DISCONNECTED 0x200
216
217 #define UNDEFINED 0x400
218 u16 state;
219 int fast_fail;
220 struct target_dds dds;
221 char *cmd_pool;
222
223 struct list_head free_cmd;
224
225 struct list_head schedule_q;
226
227 struct list_head active_q;
228 caddr_t *map_buf;
229
230 dma_addr_t map_ioba;
231
232 int request_limit;
233
234 int credit;
235
236 int debit;
237
238
239 #define PROCESSING_MAD 0x00002
240
241 #define WAIT_FOR_IDLE 0x00004
242
243 #define CRQ_CLOSED 0x00010
244
245 #define CLIENT_FAILED 0x00040
246
247 #define TRANS_EVENT 0x00080
248
249 #define RESPONSE_Q_DOWN 0x00100
250
251 #define SCHEDULE_DISCONNECT 0x00400
252
253 #define DISCONNECT_SCHEDULED 0x00800
254
255 #define CFG_SLEEPING 0x01000
256
257 #define PREP_FOR_SUSPEND_ENABLED 0x02000
258
259 #define PREP_FOR_SUSPEND_PENDING 0x04000
260
261 #define PREP_FOR_SUSPEND_ABORTED 0x08000
262
263 #define PREP_FOR_SUSPEND_OVERWRITE 0x10000
264 u32 flags;
265
266 spinlock_t intr_lock;
267
268 struct cmd_queue cmd_q;
269
270 u64 empty_iu_id;
271
272 u64 empty_iu_tag;
273 uint new_state;
274 uint resume_state;
275
276 struct timer_cb rsp_q_timer;
277
278 struct client_info client_data;
279
280 u32 client_cap;
281
282
283
284
285
286
287
288 u16 phyp_acr_state;
289 u32 phyp_acr_flags;
290
291 struct workqueue_struct *work_q;
292 struct completion wait_idle;
293 struct completion unconfig;
294 struct device dev;
295 struct vio_dev *dma_dev;
296 struct srp_target target;
297 struct ibmvscsis_tport tport;
298 struct tasklet_struct work_task;
299 struct work_struct proc_work;
300 };
301
302
303
304
305
306 #define IS_DISCONNECTING (UNCONFIGURING | ERR_DISCONNECT_RECONNECT | \
307 ERR_DISCONNECT)
308
309
310
311
312
313
314 #define DONT_PROCESS_STATE (IS_DISCONNECTING | UNDEFINED | \
315 ERR_DISCONNECTED | WAIT_IDLE)
316
317
318
319
320
321 #define BLOCK (DISCONNECT_SCHEDULED)
322
323
324 #define TARGET_STOP(VSCSI) (long)(((VSCSI)->state & DONT_PROCESS_STATE) | \
325 ((VSCSI)->flags & BLOCK))
326
327 #define PREP_FOR_SUSPEND_FLAGS (PREP_FOR_SUSPEND_ENABLED | \
328 PREP_FOR_SUSPEND_PENDING | \
329 PREP_FOR_SUSPEND_ABORTED | \
330 PREP_FOR_SUSPEND_OVERWRITE)
331
332
333 #define PRESERVE_FLAG_FIELDS (PREP_FOR_SUSPEND_FLAGS)
334
335 #define vio_iu(IUE) ((union viosrp_iu *)((IUE)->sbuf->buf))
336
337 #define READ_CMD(cdb) (((cdb)[0] & 0x1F) == 8)
338 #define WRITE_CMD(cdb) (((cdb)[0] & 0x1F) == 0xA)
339
340 #ifndef H_GET_PARTNER_INFO
341 #define H_GET_PARTNER_INFO 0x0000000000000008LL
342 #endif
343 #ifndef H_ENABLE_PREPARE_FOR_SUSPEND
344 #define H_ENABLE_PREPARE_FOR_SUSPEND 0x000000000000001DLL
345 #endif
346 #ifndef H_READY_FOR_SUSPEND
347 #define H_READY_FOR_SUSPEND 0x000000000000001ELL
348 #endif
349
350
351 #define h_copy_rdma(l, sa, sb, da, db) \
352 plpar_hcall_norets(H_COPY_RDMA, l, sa, sb, da, db)
353 #define h_vioctl(u, o, a, u1, u2, u3, u4) \
354 plpar_hcall_norets(H_VIOCTL, u, o, a, u1, u2)
355 #define h_reg_crq(ua, tok, sz) \
356 plpar_hcall_norets(H_REG_CRQ, ua, tok, sz)
357 #define h_free_crq(ua) \
358 plpar_hcall_norets(H_FREE_CRQ, ua)
359 #define h_send_crq(ua, d1, d2) \
360 plpar_hcall_norets(H_SEND_CRQ, ua, d1, d2)
361
362 #endif