ia64/linux-2.6.18-xen.hg

view drivers/xen/scsiback/common.h @ 562:66faefe721eb

pvSCSI backend driver

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 Mon Jun 02 09:58:27 2008 +0100 (2008-06-02)
parents
children 3b045d92c4c0
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>
66 #define DPRINTK(_f, _a...) \
67 pr_debug("(file=%s, line=%d) " _f, \
68 __FILE__ , __LINE__ , ## _a )
70 struct ids_tuple {
71 unsigned int hst; /* host */
72 unsigned int chn; /* channel */
73 unsigned int tgt; /* target */
74 unsigned int lun; /* LUN */
75 };
77 struct v2p_entry {
78 struct ids_tuple v; /* translate from */
79 struct scsi_device *sdev; /* translate to */
80 struct list_head l;
81 };
83 struct vscsibk_info {
84 struct xenbus_device *dev;
86 domid_t domid;
87 unsigned int evtchn;
88 unsigned int irq;
90 struct vscsiif_back_ring ring;
91 struct vm_struct *ring_area;
92 grant_handle_t shmem_handle;
93 grant_ref_t shmem_ref;
95 spinlock_t ring_lock;
96 atomic_t refcnt;
98 spinlock_t v2p_lock;
99 struct list_head v2p_entry_lists;
101 struct task_struct *kthread;
102 wait_queue_head_t waiting_to_free;
103 wait_queue_head_t wq;
104 unsigned int waiting_reqs;
105 struct page **mmap_pages;
107 };
109 typedef struct {
110 unsigned char act;
111 struct vscsibk_info *info;
112 struct scsi_device *sdev;
114 uint16_t rqid;
116 vscsiif_request_t *ring_req;
118 uint8_t nr_segments;
119 uint8_t cmnd[VSCSIIF_MAX_COMMAND_SIZE];
120 uint8_t cmd_len;
122 uint8_t sc_data_direction;
123 uint16_t timeout_per_command;
125 uint32_t request_bufflen;
126 struct scatterlist *sgl;
127 grant_ref_t gref[VSCSIIF_SENSE_BUFFERSIZE];
129 int32_t rslt;
130 uint8_t sense_buffer[VSCSIIF_SENSE_BUFFERSIZE];
132 struct list_head free_list;
133 } pending_req_t;
137 #define scsiback_get(_b) (atomic_inc(&(_b)->refcnt))
138 #define scsiback_put(_b) \
139 do { \
140 if (atomic_dec_and_test(&(_b)->refcnt)) \
141 wake_up(&(_b)->waiting_to_free);\
142 } while (0)
144 #define VSCSIIF_TIMEOUT (900*HZ)
147 irqreturn_t scsiback_intr(int, void *, struct pt_regs *);
148 int scsiback_init_sring(struct vscsibk_info *info,
149 unsigned long ring_ref, unsigned int evtchn);
150 int scsiback_schedule(void *data);
153 struct vscsibk_info *vscsibk_info_alloc(domid_t domid);
154 void scsiback_free(struct vscsibk_info *info);
155 void scsiback_disconnect(struct vscsibk_info *info);
156 int __init scsiback_interface_init(void);
157 void __exit scsiback_interface_exit(void);
158 int scsiback_xenbus_init(void);
159 void scsiback_xenbus_unregister(void);
161 void scsiback_init_translation_table(struct vscsibk_info *info);
163 int scsiback_add_translation_entry(struct vscsibk_info *info,
164 struct scsi_device *sdev, struct ids_tuple *v);
166 int scsiback_del_translation_entry(struct vscsibk_info *info,
167 struct ids_tuple *v);
168 struct scsi_device *scsiback_do_translation(struct vscsibk_info *info,
169 struct ids_tuple *v);
170 void scsiback_release_translation_entry(struct vscsibk_info *info);
173 void scsiback_cmd_exec(pending_req_t *pending_req);
175 #if 0 /*SAMPLE CODING(tentative)*//*emulation*/
176 void scsiback_dispatch_emulation_cmdexec(vscsiif_request_t *ring_req,
177 pending_req_t *pending_req);
178 #endif
181 #endif /* __SCSIIF__BACKEND__COMMON_H__ */