ia64/linux-2.6.18-xen.hg

view drivers/xen/scsiback/common.h @ 794:be85b1d7a52b

pvSCSI: add new device assignment mode

Add a new device assignment mode, which assigns whole HBA
(SCSI host) to guest domain. Current implementation requires SCSI
command emulation on backend driver, and it causes limitations for
some SCSI commands. (Please see
"http://www.xen.org/files/xensummit_tokyo/24_Hitoshi%20Matsumoto_en.pdf"
for detail about why we need the new assignment mode.

SCSI command emulation on backend driver is bypassed when "host" mode
is specified.

Signed-off-by: Tomonari Horikoshi <t.horikoshi@jp.fujitsu.com>
Signed-off-by: Jun Kamada <kama@jp.fujitsu.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Feb 17 11:17:11 2009 +0000 (2009-02-17)
parents eccc622d03af
children
line source
1 /*
2 * Copyright (c) 2008, FUJITSU Limited
3 *
4 * Based on the blkback driver code.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version 2
8 * as published by the Free Software Foundation; or, when distributed
9 * separately from the Linux kernel or incorporated into other
10 * software packages, subject to the following license:
11 *
12 * Permission is hereby granted, free of charge, to any person obtaining a copy
13 * of this source file (the "Software"), to deal in the Software without
14 * restriction, including without limitation the rights to use, copy, modify,
15 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
16 * and to permit persons to whom the Software is furnished to do so, subject to
17 * the following conditions:
18 *
19 * The above copyright notice and this permission notice shall be included in
20 * all copies or substantial portions of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28 * IN THE SOFTWARE.
29 */
31 #ifndef __SCSIIF__BACKEND__COMMON_H__
32 #define __SCSIIF__BACKEND__COMMON_H__
34 #include <linux/version.h>
35 #include <linux/module.h>
36 #include <linux/interrupt.h>
37 #include <linux/slab.h>
38 #include <linux/vmalloc.h>
39 #include <linux/wait.h>
40 #include <linux/sched.h>
41 #include <linux/kthread.h>
42 #include <linux/blkdev.h>
43 #include <linux/list.h>
44 #include <linux/kthread.h>
45 #include <scsi/scsi.h>
46 #include <scsi/scsi_cmnd.h>
47 #include <scsi/scsi_host.h>
48 #include <scsi/scsi_device.h>
49 #include <scsi/scsi_dbg.h>
50 #include <scsi/scsi_eh.h>
51 #include <asm/io.h>
52 #include <asm/setup.h>
53 #include <asm/pgalloc.h>
54 #include <asm/delay.h>
55 #include <xen/evtchn.h>
56 #include <asm/hypervisor.h>
57 #include <xen/gnttab.h>
58 #include <xen/driver_util.h>
59 #include <xen/xenbus.h>
60 #include <xen/interface/io/ring.h>
61 #include <xen/interface/grant_table.h>
62 #include <xen/interface/io/vscsiif.h>
65 #define DPRINTK(_f, _a...) \
66 pr_debug("(file=%s, line=%d) " _f, \
67 __FILE__ , __LINE__ , ## _a )
69 struct ids_tuple {
70 unsigned int hst; /* host */
71 unsigned int chn; /* channel */
72 unsigned int tgt; /* target */
73 unsigned int lun; /* LUN */
74 };
76 struct v2p_entry {
77 struct ids_tuple v; /* translate from */
78 struct scsi_device *sdev; /* translate to */
79 struct list_head l;
80 };
82 struct vscsibk_info {
83 struct xenbus_device *dev;
85 domid_t domid;
86 unsigned int evtchn;
87 unsigned int irq;
89 int feature;
91 struct vscsiif_back_ring ring;
92 struct vm_struct *ring_area;
93 grant_handle_t shmem_handle;
94 grant_ref_t shmem_ref;
96 spinlock_t ring_lock;
97 atomic_t nr_unreplied_reqs;
99 spinlock_t v2p_lock;
100 struct list_head v2p_entry_lists;
102 struct task_struct *kthread;
103 wait_queue_head_t waiting_to_free;
104 wait_queue_head_t wq;
105 unsigned int waiting_reqs;
106 struct page **mmap_pages;
108 };
110 typedef struct {
111 unsigned char act;
112 struct vscsibk_info *info;
113 struct scsi_device *sdev;
115 uint16_t rqid;
117 uint16_t v_chn, v_tgt;
119 uint8_t nr_segments;
120 uint8_t cmnd[VSCSIIF_MAX_COMMAND_SIZE];
121 uint8_t cmd_len;
123 uint8_t sc_data_direction;
124 uint16_t timeout_per_command;
126 uint32_t request_bufflen;
127 struct scatterlist *sgl;
128 grant_ref_t gref[VSCSIIF_SG_TABLESIZE];
130 int32_t rslt;
131 uint32_t resid;
132 uint8_t sense_buffer[VSCSIIF_SENSE_BUFFERSIZE];
134 struct list_head free_list;
135 } pending_req_t;
139 #define scsiback_get(_b) (atomic_inc(&(_b)->nr_unreplied_reqs))
140 #define scsiback_put(_b) \
141 do { \
142 if (atomic_dec_and_test(&(_b)->nr_unreplied_reqs)) \
143 wake_up(&(_b)->waiting_to_free);\
144 } while (0)
146 #define VSCSIIF_TIMEOUT (900*HZ)
148 #define VSCSI_TYPE_HOST 1
150 irqreturn_t scsiback_intr(int, void *, struct pt_regs *);
151 int scsiback_init_sring(struct vscsibk_info *info,
152 unsigned long ring_ref, unsigned int evtchn);
153 int scsiback_schedule(void *data);
156 struct vscsibk_info *vscsibk_info_alloc(domid_t domid);
157 void scsiback_free(struct vscsibk_info *info);
158 void scsiback_disconnect(struct vscsibk_info *info);
159 int __init scsiback_interface_init(void);
160 void scsiback_interface_exit(void);
161 int scsiback_xenbus_init(void);
162 void scsiback_xenbus_unregister(void);
164 void scsiback_init_translation_table(struct vscsibk_info *info);
166 int scsiback_add_translation_entry(struct vscsibk_info *info,
167 struct scsi_device *sdev, struct ids_tuple *v);
169 int scsiback_del_translation_entry(struct vscsibk_info *info,
170 struct ids_tuple *v);
171 struct scsi_device *scsiback_do_translation(struct vscsibk_info *info,
172 struct ids_tuple *v);
173 void scsiback_release_translation_entry(struct vscsibk_info *info);
176 void scsiback_cmd_exec(pending_req_t *pending_req);
177 void scsiback_do_resp_with_sense(char *sense_buffer, int32_t result,
178 uint32_t resid, pending_req_t *pending_req);
179 void scsiback_fast_flush_area(pending_req_t *req);
181 void scsiback_rsp_emulation(pending_req_t *pending_req);
182 void scsiback_req_emulation_or_cmdexec(pending_req_t *pending_req);
183 void scsiback_emulation_init(void);
186 #endif /* __SCSIIF__BACKEND__COMMON_H__ */