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