~ubuntu-branches/ubuntu/karmic/linux-mvl-dove/karmic-proposed

« back to all changes in this revision

Viewing changes to ubuntu/iscsitarget/iscsi.h

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Bader
  • Date: 2010-03-10 22:24:12 UTC
  • mto: (15.1.2 karmic-security)
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20100310222412-k86m3r53jw0je7x1
Tags: upstream-2.6.31
ImportĀ upstreamĀ versionĀ 2.6.31

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2002-2003 Ardis Technolgies <roman@ardistech.com>
3
 
 *
4
 
 * Released under the terms of the GNU GPL v2.0.
5
 
 */
6
 
 
7
 
#ifndef __ISCSI_H__
8
 
#define __ISCSI_H__
9
 
 
10
 
#include <linux/pagemap.h>
11
 
#include <linux/seq_file.h>
12
 
#include <linux/mm.h>
13
 
#include <linux/crypto.h>
14
 
#include <linux/scatterlist.h>
15
 
#include <net/sock.h>
16
 
 
17
 
#include "iscsi_hdr.h"
18
 
#include "iet_u.h"
19
 
 
20
 
struct iscsi_sess_param {
21
 
        int initial_r2t;
22
 
        int immediate_data;
23
 
        int max_connections;
24
 
        int max_recv_data_length;
25
 
        int max_xmit_data_length;
26
 
        int max_burst_length;
27
 
        int first_burst_length;
28
 
        int default_wait_time;
29
 
        int default_retain_time;
30
 
        int max_outstanding_r2t;
31
 
        int data_pdu_inorder;
32
 
        int data_sequence_inorder;
33
 
        int error_recovery_level;
34
 
        int header_digest;
35
 
        int data_digest;
36
 
        int ofmarker;
37
 
        int ifmarker;
38
 
        int ofmarkint;
39
 
        int ifmarkint;
40
 
};
41
 
 
42
 
struct iscsi_trgt_param {
43
 
        int wthreads;
44
 
        int target_type;
45
 
        int queued_cmnds;
46
 
};
47
 
 
48
 
struct tio {
49
 
        u32 pg_cnt;
50
 
 
51
 
        pgoff_t idx;
52
 
        u32 offset;
53
 
        u32 size;
54
 
 
55
 
        struct page **pvec;
56
 
 
57
 
        atomic_t count;
58
 
};
59
 
 
60
 
struct network_thread_info {
61
 
        struct task_struct *task;
62
 
        unsigned long flags;
63
 
        struct list_head active_conns;
64
 
 
65
 
        spinlock_t nthread_lock;
66
 
 
67
 
        void (*old_state_change)(struct sock *);
68
 
        void (*old_data_ready)(struct sock *, int);
69
 
        void (*old_write_space)(struct sock *);
70
 
};
71
 
 
72
 
struct worker_thread_info;
73
 
 
74
 
struct worker_thread {
75
 
        struct task_struct *w_task;
76
 
        struct list_head w_list;
77
 
        struct worker_thread_info *w_info;
78
 
};
79
 
 
80
 
struct worker_thread_info {
81
 
        spinlock_t wthread_lock;
82
 
 
83
 
        u32 nr_running_wthreads;
84
 
 
85
 
        struct list_head wthread_list;
86
 
        struct list_head work_queue;
87
 
 
88
 
        wait_queue_head_t wthread_sleep;
89
 
};
90
 
 
91
 
struct iscsi_cmnd;
92
 
 
93
 
struct target_type {
94
 
        int id;
95
 
        int (*execute_cmnd) (struct iscsi_cmnd *);
96
 
};
97
 
 
98
 
enum iscsi_device_state {
99
 
        IDEV_RUNNING,
100
 
        IDEV_DEL,
101
 
};
102
 
 
103
 
struct iscsi_target {
104
 
        struct list_head t_list;
105
 
        u32 tid;
106
 
 
107
 
        char name[ISCSI_NAME_LEN];
108
 
 
109
 
        struct iscsi_sess_param sess_param;
110
 
        struct iscsi_trgt_param trgt_param;
111
 
 
112
 
        atomic_t nr_volumes;
113
 
        struct list_head volumes;
114
 
        struct list_head session_list;
115
 
 
116
 
        struct network_thread_info nthread_info;
117
 
        /* Points either to own list or global pool */
118
 
        struct worker_thread_info * wthread_info;
119
 
 
120
 
        struct semaphore target_sem;
121
 
};
122
 
 
123
 
struct iscsi_queue {
124
 
        spinlock_t queue_lock;
125
 
        struct iscsi_cmnd *ordered_cmnd;
126
 
        struct list_head wait_list;
127
 
        int active_cnt;
128
 
};
129
 
 
130
 
struct iet_volume {
131
 
        u32 lun;
132
 
 
133
 
        enum iscsi_device_state l_state;
134
 
        atomic_t l_count;
135
 
 
136
 
        struct iscsi_target *target;
137
 
        struct list_head list;
138
 
 
139
 
        struct iscsi_queue queue;
140
 
 
141
 
        u8 scsi_id[SCSI_ID_LEN];
142
 
        u8 scsi_sn[SCSI_SN_LEN];
143
 
 
144
 
        u32 blk_shift;
145
 
        u64 blk_cnt;
146
 
 
147
 
        u64 reserve_sid;
148
 
        spinlock_t reserve_lock;
149
 
 
150
 
        unsigned long flags;
151
 
 
152
 
        struct iotype *iotype;
153
 
        void *private;
154
 
};
155
 
 
156
 
enum lu_flags {
157
 
        LU_READONLY,
158
 
        LU_WCACHE,
159
 
        LU_RCACHE,
160
 
};
161
 
 
162
 
#define LUReadonly(lu) test_bit(LU_READONLY, &(lu)->flags)
163
 
#define SetLUReadonly(lu) set_bit(LU_READONLY, &(lu)->flags)
164
 
 
165
 
#define LUWCache(lu) test_bit(LU_WCACHE, &(lu)->flags)
166
 
#define SetLUWCache(lu) set_bit(LU_WCACHE, &(lu)->flags)
167
 
#define ClearLUWCache(lu) clear_bit(LU_WCACHE, &(lu)->flags)
168
 
 
169
 
#define LURCache(lu) test_bit(LU_RCACHE, &(lu)->flags)
170
 
#define SetLURCache(lu) set_bit(LU_RCACHE, &(lu)->flags)
171
 
#define ClearLURCache(lu) clear_bit(LU_RCACHE, &(lu)->flags)
172
 
 
173
 
#define IET_HASH_ORDER          8
174
 
#define cmnd_hashfn(itt)        hash_long((itt), IET_HASH_ORDER)
175
 
 
176
 
struct iscsi_session {
177
 
        struct list_head list;
178
 
        struct iscsi_target *target;
179
 
 
180
 
        char *initiator;
181
 
        u64 sid;
182
 
 
183
 
        u32 exp_cmd_sn;
184
 
        u32 max_cmd_sn;
185
 
 
186
 
        struct iscsi_sess_param param;
187
 
        u32 max_queued_cmnds;
188
 
 
189
 
        struct list_head conn_list;
190
 
 
191
 
        struct list_head pending_list;
192
 
 
193
 
        spinlock_t cmnd_hash_lock;
194
 
        struct list_head cmnd_hash[1 << IET_HASH_ORDER];
195
 
 
196
 
        u32 next_ttt;
197
 
};
198
 
 
199
 
enum connection_state_bit {
200
 
        CONN_ACTIVE,
201
 
        CONN_CLOSING,
202
 
        CONN_WSPACE_WAIT,
203
 
};
204
 
 
205
 
#define ISCSI_CONN_IOV_MAX      (((256 << 10) >> PAGE_SHIFT) + 1)
206
 
 
207
 
struct iscsi_conn {
208
 
        struct list_head list;                  /* list entry in session list */
209
 
        struct iscsi_session *session;          /* owning session */
210
 
 
211
 
        u16 cid;
212
 
        unsigned long state;
213
 
 
214
 
        u32 stat_sn;
215
 
        u32 exp_stat_sn;
216
 
 
217
 
        int hdigest_type;
218
 
        int ddigest_type;
219
 
 
220
 
        struct list_head poll_list;
221
 
 
222
 
        struct file *file;
223
 
        struct socket *sock;
224
 
        spinlock_t list_lock;
225
 
        atomic_t nr_cmnds;
226
 
        atomic_t nr_busy_cmnds;
227
 
        struct list_head pdu_list;              /* in/outcoming pdus */
228
 
        struct list_head write_list;            /* list of data pdus to be sent */
229
 
 
230
 
        struct iscsi_cmnd *read_cmnd;
231
 
        struct msghdr read_msg;
232
 
        struct iovec read_iov[ISCSI_CONN_IOV_MAX];
233
 
        u32 read_size;
234
 
        u32 read_overflow;
235
 
        int read_state;
236
 
 
237
 
        struct iscsi_cmnd *write_cmnd;
238
 
        struct iovec write_iov[ISCSI_CONN_IOV_MAX];
239
 
        struct iovec *write_iop;
240
 
        struct tio *write_tcmnd;
241
 
        u32 write_size;
242
 
        u32 write_offset;
243
 
        int write_state;
244
 
 
245
 
        struct hash_desc rx_hash;
246
 
        struct hash_desc tx_hash;
247
 
        struct scatterlist hash_sg[ISCSI_CONN_IOV_MAX];
248
 
};
249
 
 
250
 
struct iscsi_pdu {
251
 
        struct iscsi_hdr bhs;
252
 
        void *ahs;
253
 
        unsigned int ahssize;
254
 
        unsigned int datasize;
255
 
};
256
 
 
257
 
typedef void (iet_show_info_t)(struct seq_file *seq, struct iscsi_target *target);
258
 
 
259
 
struct iscsi_cmnd {
260
 
        struct list_head list;
261
 
        struct list_head conn_list;
262
 
        unsigned long flags;
263
 
        struct iscsi_conn *conn;
264
 
        struct iet_volume *lun;
265
 
 
266
 
        struct iscsi_pdu pdu;
267
 
        struct list_head pdu_list;
268
 
 
269
 
        struct list_head hash_list;
270
 
 
271
 
        struct tio *tio;
272
 
 
273
 
        u32 r2t_sn;
274
 
        u32 r2t_length;
275
 
        u32 is_unsolicited_data;
276
 
        u32 target_task_tag;
277
 
        u32 outstanding_r2t;
278
 
 
279
 
        u32 hdigest;
280
 
        u32 ddigest;
281
 
 
282
 
        struct iscsi_cmnd *req;
283
 
};
284
 
 
285
 
#define ISCSI_OP_SCSI_REJECT    ISCSI_OP_VENDOR1_CMD
286
 
#define ISCSI_OP_PDU_REJECT     ISCSI_OP_VENDOR2_CMD
287
 
#define ISCSI_OP_DATA_REJECT    ISCSI_OP_VENDOR3_CMD
288
 
#define ISCSI_OP_SCSI_ABORT     ISCSI_OP_VENDOR4_CMD
289
 
 
290
 
/* iscsi.c */
291
 
extern unsigned long worker_thread_pool_size;
292
 
extern struct iscsi_cmnd *cmnd_alloc(struct iscsi_conn *, int);
293
 
extern void cmnd_rx_start(struct iscsi_cmnd *);
294
 
extern void cmnd_rx_end(struct iscsi_cmnd *);
295
 
extern void cmnd_tx_start(struct iscsi_cmnd *);
296
 
extern void cmnd_tx_end(struct iscsi_cmnd *);
297
 
extern void cmnd_release(struct iscsi_cmnd *, int);
298
 
extern void send_data_rsp(struct iscsi_cmnd *, int (*)(struct iscsi_cmnd *));
299
 
extern void send_scsi_rsp(struct iscsi_cmnd *, int (*)(struct iscsi_cmnd *));
300
 
 
301
 
/* conn.c */
302
 
extern struct iscsi_conn *conn_lookup(struct iscsi_session *, u16);
303
 
extern int conn_add(struct iscsi_session *, struct conn_info *);
304
 
extern int conn_del(struct iscsi_session *, struct conn_info *);
305
 
extern int conn_free(struct iscsi_conn *);
306
 
extern void conn_close(struct iscsi_conn *);
307
 
extern void conn_info_show(struct seq_file *, struct iscsi_session *);
308
 
 
309
 
/* nthread.c */
310
 
extern int nthread_init(struct iscsi_target *);
311
 
extern int nthread_start(struct iscsi_target *);
312
 
extern int nthread_stop(struct iscsi_target *);
313
 
extern void __nthread_wakeup(struct network_thread_info *);
314
 
extern void nthread_wakeup(struct iscsi_target *);
315
 
 
316
 
/* wthread.c */
317
 
extern int wthread_init(struct worker_thread_info *info);
318
 
extern int wthread_start(struct worker_thread_info *info, int wthreads, u32 tid);
319
 
extern int wthread_stop(struct worker_thread_info *info);
320
 
extern void wthread_queue(struct iscsi_cmnd *);
321
 
extern struct target_type *target_type_array[];
322
 
extern int wthread_module_init(void);
323
 
extern void wthread_module_exit(void);
324
 
extern struct worker_thread_info *worker_thread_pool;
325
 
 
326
 
/* target.c */
327
 
extern int target_lock(struct iscsi_target *, int);
328
 
extern void target_unlock(struct iscsi_target *);
329
 
struct iscsi_target *target_lookup_by_id(u32);
330
 
extern int target_add(struct target_info *);
331
 
extern int target_del(u32 id);
332
 
extern struct seq_operations iet_seq_op;
333
 
 
334
 
/* config.c */
335
 
extern int iet_procfs_init(void);
336
 
extern void iet_procfs_exit(void);
337
 
extern int iet_info_show(struct seq_file *, iet_show_info_t *);
338
 
 
339
 
/* session.c */
340
 
extern struct file_operations session_seq_fops;
341
 
extern struct iscsi_session *session_lookup(struct iscsi_target *, u64);
342
 
extern int session_add(struct iscsi_target *, struct session_info *);
343
 
extern int session_del(struct iscsi_target *, u64);
344
 
 
345
 
/* volume.c */
346
 
extern struct file_operations volume_seq_fops;
347
 
extern int volume_add(struct iscsi_target *, struct volume_info *);
348
 
extern int iscsi_volume_del(struct iscsi_target *, struct volume_info *);
349
 
extern void iscsi_volume_destroy(struct iet_volume *);
350
 
extern struct iet_volume *volume_lookup(struct iscsi_target *, u32);
351
 
extern struct iet_volume *volume_get(struct iscsi_target *, u32);
352
 
extern void volume_put(struct iet_volume *);
353
 
extern int volume_reserve(struct iet_volume *volume, u64 sid);
354
 
extern int volume_release(struct iet_volume *volume, u64 sid, int force);
355
 
extern int is_volume_reserved(struct iet_volume *volume, u64 sid);
356
 
 
357
 
/* tio.c */
358
 
extern int tio_init(void);
359
 
extern void tio_exit(void);
360
 
extern struct tio *tio_alloc(int);
361
 
extern void tio_get(struct tio *);
362
 
extern void tio_put(struct tio *);
363
 
extern void tio_set(struct tio *, u32, loff_t);
364
 
extern int tio_read(struct iet_volume *, struct tio *);
365
 
extern int tio_write(struct iet_volume *, struct tio *);
366
 
extern int tio_sync(struct iet_volume *, struct tio *);
367
 
 
368
 
/* iotype.c */
369
 
extern struct iotype *get_iotype(const char *name);
370
 
extern void put_iotype(struct iotype *iot);
371
 
 
372
 
/* params.c */
373
 
extern int iscsi_param_set(struct iscsi_target *, struct iscsi_param_info *, int);
374
 
 
375
 
/* target_disk.c */
376
 
extern struct target_type disk_ops;
377
 
 
378
 
/* event.c */
379
 
extern int event_send(u32, u64, u32, u32, int);
380
 
extern int event_init(void);
381
 
extern void event_exit(void);
382
 
 
383
 
#define get_pgcnt(size, offset) ((((size) + ((offset) & ~PAGE_CACHE_MASK)) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT)
384
 
 
385
 
static inline void iscsi_cmnd_get_length(struct iscsi_pdu *pdu)
386
 
{
387
 
#if defined(__BIG_ENDIAN)
388
 
        pdu->ahssize = pdu->bhs.length.ahslength * 4;
389
 
        pdu->datasize = pdu->bhs.length.datalength;
390
 
#elif defined(__LITTLE_ENDIAN)
391
 
        pdu->ahssize = (pdu->bhs.length & 0xff) * 4;
392
 
        pdu->datasize = be32_to_cpu(pdu->bhs.length & ~0xff);
393
 
#else
394
 
#error
395
 
#endif
396
 
}
397
 
 
398
 
static inline void iscsi_cmnd_set_length(struct iscsi_pdu *pdu)
399
 
{
400
 
#if defined(__BIG_ENDIAN)
401
 
        pdu->bhs.length.ahslength = pdu->ahssize / 4;
402
 
        pdu->bhs.length.datalength = pdu->datasize;
403
 
#elif defined(__LITTLE_ENDIAN)
404
 
        pdu->bhs.length = cpu_to_be32(pdu->datasize) | (pdu->ahssize / 4);
405
 
#else
406
 
#error
407
 
#endif
408
 
}
409
 
 
410
 
#define cmnd_hdr(cmnd) ((struct iscsi_scsi_cmd_hdr *) (&((cmnd)->pdu.bhs)))
411
 
#define cmnd_ttt(cmnd) cpu_to_be32((cmnd)->pdu.bhs.ttt)
412
 
#define cmnd_itt(cmnd) cpu_to_be32((cmnd)->pdu.bhs.itt)
413
 
#define cmnd_opcode(cmnd) ((cmnd)->pdu.bhs.opcode & ISCSI_OPCODE_MASK)
414
 
#define cmnd_scsicode(cmnd) cmnd_hdr(cmnd)->scb[0]
415
 
 
416
 
#define SECTOR_SIZE_BITS        9
417
 
 
418
 
enum cmnd_flags {
419
 
        CMND_hashed,
420
 
        CMND_queued,
421
 
        CMND_final,
422
 
        CMND_waitio,
423
 
        CMND_close,
424
 
        CMND_lunit,
425
 
        CMND_pending,
426
 
        CMND_tmfabort,
427
 
        CMND_rxstart,
428
 
};
429
 
 
430
 
#define set_cmnd_hashed(cmnd)   set_bit(CMND_hashed, &(cmnd)->flags)
431
 
#define cmnd_hashed(cmnd)       test_bit(CMND_hashed, &(cmnd)->flags)
432
 
 
433
 
#define set_cmnd_queued(cmnd)   set_bit(CMND_queued, &(cmnd)->flags)
434
 
#define cmnd_queued(cmnd)       test_bit(CMND_queued, &(cmnd)->flags)
435
 
 
436
 
#define set_cmnd_final(cmnd)    set_bit(CMND_final, &(cmnd)->flags)
437
 
#define cmnd_final(cmnd)        test_bit(CMND_final, &(cmnd)->flags)
438
 
 
439
 
#define set_cmnd_waitio(cmnd)   set_bit(CMND_waitio, &(cmnd)->flags)
440
 
#define cmnd_waitio(cmnd)       test_bit(CMND_waitio, &(cmnd)->flags)
441
 
 
442
 
#define set_cmnd_close(cmnd)    set_bit(CMND_close, &(cmnd)->flags)
443
 
#define cmnd_close(cmnd)        test_bit(CMND_close, &(cmnd)->flags)
444
 
 
445
 
#define set_cmnd_lunit(cmnd)    set_bit(CMND_lunit, &(cmnd)->flags)
446
 
#define cmnd_lunit(cmnd)        test_bit(CMND_lunit, &(cmnd)->flags)
447
 
 
448
 
#define set_cmnd_pending(cmnd)  set_bit(CMND_pending, &(cmnd)->flags)
449
 
#define clear_cmnd_pending(cmnd)        clear_bit(CMND_pending, &(cmnd)->flags)
450
 
#define cmnd_pending(cmnd)      test_bit(CMND_pending, &(cmnd)->flags)
451
 
 
452
 
#define set_cmnd_tmfabort(cmnd) set_bit(CMND_tmfabort, &(cmnd)->flags)
453
 
#define cmnd_tmfabort(cmnd)     test_bit(CMND_tmfabort, &(cmnd)->flags)
454
 
 
455
 
#define set_cmnd_rxstart(cmnd)  set_bit(CMND_rxstart, &(cmnd)->flags)
456
 
#define cmnd_rxstart(cmnd)      test_bit(CMND_rxstart, &(cmnd)->flags)
457
 
 
458
 
#define VENDOR_ID       "IET"
459
 
#define PRODUCT_ID      "VIRTUAL-DISK"
460
 
#define PRODUCT_REV     "0"
461
 
 
462
 
#endif  /* __ISCSI_H__ */