2 * Copyright (c) 2008, FUJITSU Limited
4 * Based on the blkback driver code.
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:
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:
19 * The above copyright notice and this permission notice shall be included in
20 * all copies or substantial portions of the Software.
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
31 #ifndef __SCSIIF__BACKEND__COMMON_H__
32 #define __SCSIIF__BACKEND__COMMON_H__
34 #include <linux/module.h>
35 #include <linux/interrupt.h>
36 #include <linux/slab.h>
37 #include <linux/wait.h>
38 #include <linux/sched.h>
39 #include <linux/kthread.h>
40 #include <linux/blkdev.h>
41 #include <linux/list.h>
42 #include <linux/kthread.h>
43 #include <scsi/scsi.h>
44 #include <scsi/scsi_cmnd.h>
45 #include <scsi/scsi_host.h>
46 #include <scsi/scsi_device.h>
47 #include <scsi/scsi_dbg.h>
48 #include <scsi/scsi_eh.h>
49 #include <asm/hypervisor.h>
50 #include <xen/xenbus.h>
51 #include <xen/interface/io/ring.h>
52 #include <xen/interface/io/vscsiif.h>
55 #define DPRINTK(_f, _a...) \
56 pr_debug("(file=%s, line=%d) " _f, \
57 __FILE__ , __LINE__ , ## _a )
60 unsigned int hst; /* host */
61 unsigned int chn; /* channel */
62 unsigned int tgt; /* target */
63 unsigned int lun; /* LUN */
67 struct ids_tuple v; /* translate from */
68 struct scsi_device *sdev; /* translate to */
73 struct xenbus_device *dev;
81 struct vscsiif_back_ring ring;
82 struct vm_struct *ring_area;
85 atomic_t nr_unreplied_reqs;
88 struct list_head v2p_entry_lists;
90 struct task_struct *kthread;
91 wait_queue_head_t waiting_to_free;
93 unsigned int waiting_reqs;
94 struct page **mmap_pages;
100 struct vscsibk_info *info;
101 struct scsi_device *sdev;
105 uint16_t v_chn, v_tgt;
108 uint8_t cmnd[VSCSIIF_MAX_COMMAND_SIZE];
111 uint8_t sc_data_direction;
112 uint16_t timeout_per_command;
114 uint32_t request_bufflen;
115 struct scatterlist *sgl;
116 grant_ref_t gref[VSCSIIF_SG_TABLESIZE];
120 uint8_t sense_buffer[VSCSIIF_SENSE_BUFFERSIZE];
122 struct list_head free_list;
127 #define scsiback_get(_b) (atomic_inc(&(_b)->nr_unreplied_reqs))
128 #define scsiback_put(_b) \
130 if (atomic_dec_and_test(&(_b)->nr_unreplied_reqs)) \
131 wake_up(&(_b)->waiting_to_free);\
134 #define VSCSIIF_TIMEOUT (900*HZ)
136 #define VSCSI_TYPE_HOST 1
138 irqreturn_t scsiback_intr(int, void *);
139 int scsiback_init_sring(struct vscsibk_info *, grant_ref_t, evtchn_port_t);
140 int scsiback_schedule(void *data);
143 struct vscsibk_info *vscsibk_info_alloc(domid_t domid);
144 void scsiback_free(struct vscsibk_info *info);
145 void scsiback_disconnect(struct vscsibk_info *);
146 int __init scsiback_interface_init(void);
147 void scsiback_interface_exit(void);
148 int scsiback_xenbus_init(void);
149 void scsiback_xenbus_unregister(void);
151 void scsiback_init_translation_table(struct vscsibk_info *info);
153 int scsiback_add_translation_entry(struct vscsibk_info *info,
154 struct scsi_device *sdev, struct ids_tuple *v);
156 int scsiback_del_translation_entry(struct vscsibk_info *info,
157 struct ids_tuple *v);
158 struct scsi_device *scsiback_do_translation(struct vscsibk_info *info,
159 struct ids_tuple *v);
160 void scsiback_release_translation_entry(struct vscsibk_info *info);
163 void scsiback_cmd_exec(pending_req_t *pending_req);
164 void scsiback_do_resp_with_sense(char *sense_buffer, int32_t result,
165 uint32_t resid, pending_req_t *pending_req);
166 void scsiback_fast_flush_area(pending_req_t *req);
168 void scsiback_rsp_emulation(pending_req_t *pending_req);
169 void scsiback_req_emulation_or_cmdexec(pending_req_t *pending_req);
170 void scsiback_emulation_init(void);
173 #endif /* __SCSIIF__BACKEND__COMMON_H__ */