Update to 3.4-final.
[linux-flexiantxendom0-3.2.10.git] / drivers / xen / scsifront / common.h
1 /*
2  * Xen SCSI frontend driver
3  *
4  * Copyright (c) 2008, FUJITSU Limited
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  */
30
31 #ifndef __XEN_DRIVERS_SCSIFRONT_H__
32 #define __XEN_DRIVERS_SCSIFRONT_H__
33
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>
59
60 #ifdef HAVE_XEN_PLATFORM_COMPAT_H
61 #include <xen/platform-compat.h>
62 #endif
63
64 #define VSCSI_IN_ABORT          1
65 #define VSCSI_IN_RESET          2
66
67 /* tuning point*/
68 #define VSCSIIF_DEFAULT_CMD_PER_LUN 10
69 #define VSCSIIF_MAX_TARGET          64
70 #define VSCSIIF_MAX_LUN             255
71
72 #define VSCSIIF_RING_SIZE       __CONST_RING_SIZE(vscsiif, PAGE_SIZE)
73 #define VSCSIIF_MAX_REQS        VSCSIIF_RING_SIZE
74
75 struct vscsifrnt_shadow {
76         uint16_t next_free;
77         
78         /* command between backend and frontend
79          * VSCSIIF_ACT_SCSI_CDB or VSCSIIF_ACT_SCSI_RESET */
80         unsigned char act;
81         
82         /* do reset function */
83         wait_queue_head_t wq_reset;     /* reset work queue           */
84         int wait_reset;                 /* reset work queue condition */
85         int32_t rslt_reset;             /* reset response status      */
86                                         /* (SUCESS or FAILED)         */
87
88         /* for DMA_TO_DEVICE(1), DMA_FROM_DEVICE(2), DMA_NONE(3) 
89            requests */
90         unsigned int sc_data_direction;
91         
92         /* Number of pieces of scatter-gather */
93         unsigned int nr_segments;
94
95         /* requested struct scsi_cmnd is stored from kernel */
96         unsigned long req_scsi_cmnd;
97         int gref[VSCSIIF_SG_TABLESIZE];
98 };
99
100 struct vscsifrnt_info {
101         struct xenbus_device *dev;
102
103         struct Scsi_Host *host;
104
105         spinlock_t io_lock;
106         spinlock_t shadow_lock;
107         unsigned int evtchn;
108         unsigned int irq;
109
110         grant_ref_t ring_ref;
111         struct vscsiif_front_ring ring;
112         struct vscsiif_response ring_res;
113
114         struct vscsifrnt_shadow shadow[VSCSIIF_MAX_REQS];
115         uint32_t shadow_free;
116
117         struct task_struct *kthread;
118         wait_queue_head_t wq;
119         unsigned int waiting_resp;
120
121 };
122
123 #define DPRINTK(_f, _a...)                              \
124         pr_debug("(file=%s, line=%d) " _f,      \
125                  __FILE__ , __LINE__ , ## _a )
126
127 int scsifront_xenbus_init(void);
128 void scsifront_xenbus_unregister(void);
129 int scsifront_schedule(void *data);
130 irqreturn_t scsifront_intr(int irq, void *dev_id);
131 int scsifront_cmd_done(struct vscsifrnt_info *info);
132
133
134 #endif /* __XEN_DRIVERS_SCSIFRONT_H__  */