2 * Xen SCSI frontend driver
4 * Copyright (c) 2008, FUJITSU Limited
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 __XEN_DRIVERS_SCSIFRONT_H__
32 #define __XEN_DRIVERS_SCSIFRONT_H__
34 #include <linux/version.h>
35 #include <linux/module.h>
36 #include <linux/kernel.h>
37 #include <linux/device.h>
38 #include <linux/kthread.h>
39 #include <linux/wait.h>
40 #include <linux/interrupt.h>
41 #include <linux/spinlock.h>
42 #include <linux/sched.h>
43 #include <linux/blkdev.h>
44 #include <scsi/scsi_cmnd.h>
45 #include <scsi/scsi_device.h>
46 #include <scsi/scsi.h>
47 #include <scsi/scsi_host.h>
48 #include <xen/xenbus.h>
49 #include <xen/gnttab.h>
50 #include <xen/evtchn.h>
51 #include <xen/interface/xen.h>
52 #include <xen/interface/io/ring.h>
53 #include <xen/interface/io/vscsiif.h>
54 #include <xen/interface/grant_table.h>
55 #include <xen/interface/io/protocols.h>
56 #include <asm/delay.h>
57 #include <asm/hypervisor.h>
58 #include <asm/maddr.h>
60 #ifdef HAVE_XEN_PLATFORM_COMPAT_H
61 #include <xen/platform-compat.h>
64 #define GRANT_INVALID_REF 0
65 #define VSCSI_IN_ABORT 1
66 #define VSCSI_IN_RESET 2
69 #define VSCSIIF_DEFAULT_CMD_PER_LUN 10
70 #define VSCSIIF_MAX_TARGET 64
71 #define VSCSIIF_MAX_LUN 255
73 #define VSCSIIF_RING_SIZE __CONST_RING_SIZE(vscsiif, PAGE_SIZE)
74 #define VSCSIIF_MAX_REQS VSCSIIF_RING_SIZE
76 struct vscsifrnt_shadow {
79 /* command between backend and frontend
80 * VSCSIIF_ACT_SCSI_CDB or VSCSIIF_ACT_SCSI_RESET */
83 /* do reset function */
84 wait_queue_head_t wq_reset; /* reset work queue */
85 int wait_reset; /* reset work queue condition */
86 int32_t rslt_reset; /* reset response status */
87 /* (SUCESS or FAILED) */
89 /* for DMA_TO_DEVICE(1), DMA_FROM_DEVICE(2), DMA_NONE(3)
91 unsigned int sc_data_direction;
93 /* Number of pieces of scatter-gather */
94 unsigned int nr_segments;
96 /* requested struct scsi_cmnd is stored from kernel */
97 unsigned long req_scsi_cmnd;
98 int gref[VSCSIIF_SG_TABLESIZE];
101 struct vscsifrnt_info {
102 struct xenbus_device *dev;
104 struct Scsi_Host *host;
107 spinlock_t shadow_lock;
111 grant_ref_t ring_ref;
112 struct vscsiif_front_ring ring;
113 struct vscsiif_response ring_res;
115 struct vscsifrnt_shadow shadow[VSCSIIF_MAX_REQS];
116 uint32_t shadow_free;
118 struct task_struct *kthread;
119 wait_queue_head_t wq;
120 unsigned int waiting_resp;
124 #define DPRINTK(_f, _a...) \
125 pr_debug("(file=%s, line=%d) " _f, \
126 __FILE__ , __LINE__ , ## _a )
128 int scsifront_xenbus_init(void);
129 void scsifront_xenbus_unregister(void);
130 int scsifront_schedule(void *data);
131 irqreturn_t scsifront_intr(int irq, void *dev_id);
132 int scsifront_cmd_done(struct vscsifrnt_info *info);
135 #endif /* __XEN_DRIVERS_SCSIFRONT_H__ */