Update to 3.4-final.
[linux-flexiantxendom0-3.2.10.git] / drivers / xen / blkfront / block.h
1 /******************************************************************************
2  * block.h
3  * 
4  * Shared definitions between all levels of XenLinux Virtual block devices.
5  * 
6  * Copyright (c) 2003-2004, Keir Fraser & Steve Hand
7  * Modifications by Mark A. Williamson are (c) Intel Research Cambridge
8  * Copyright (c) 2004-2005, Christian Limpach
9  * 
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License version 2
12  * as published by the Free Software Foundation; or, when distributed
13  * separately from the Linux kernel or incorporated into other
14  * software packages, subject to the following license:
15  * 
16  * Permission is hereby granted, free of charge, to any person obtaining a copy
17  * of this source file (the "Software"), to deal in the Software without
18  * restriction, including without limitation the rights to use, copy, modify,
19  * merge, publish, distribute, sublicense, and/or sell copies of the Software,
20  * and to permit persons to whom the Software is furnished to do so, subject to
21  * the following conditions:
22  * 
23  * The above copyright notice and this permission notice shall be included in
24  * all copies or substantial portions of the Software.
25  * 
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
31  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
32  * IN THE SOFTWARE.
33  */
34
35 #ifndef __XEN_DRIVERS_BLOCK_H__
36 #define __XEN_DRIVERS_BLOCK_H__
37
38 #include <linux/version.h>
39 #include <linux/module.h>
40 #include <linux/kernel.h>
41 #include <linux/sched.h>
42 #include <linux/slab.h>
43 #include <linux/string.h>
44 #include <linux/atomic.h>
45 #include <linux/errno.h>
46 #include <linux/fs.h>
47 #include <linux/hdreg.h>
48 #include <linux/blkdev.h>
49 #include <linux/major.h>
50 #include <linux/mutex.h>
51 #include <asm/hypervisor.h>
52 #include <xen/xenbus.h>
53 #include <xen/gnttab.h>
54 #include <xen/interface/xen.h>
55 #include <xen/interface/io/blkif.h>
56 #include <xen/interface/io/ring.h>
57 #include <asm/io.h>
58 #include <asm/uaccess.h>
59
60 #define DPRINTK(_f, _a...) pr_debug(_f, ## _a)
61
62 #if 0
63 #define DPRINTK_IOCTL(_f, _a...) pr_alert(_f, ## _a)
64 #else
65 #define DPRINTK_IOCTL(_f, _a...) ((void)0)
66 #endif
67
68 struct xlbd_major_info
69 {
70         int major;
71         int index;
72         int usage;
73         const struct xlbd_type_info *type;
74         struct xlbd_minor_state *minors;
75 };
76
77 struct blk_shadow {
78         blkif_request_t req;
79         struct request *request;
80         unsigned long frame[BLKIF_MAX_SEGMENTS_PER_REQUEST];
81 };
82
83 #define BLK_RING_SIZE __CONST_RING_SIZE(blkif, PAGE_SIZE)
84
85 /*
86  * We have one of these per vbd, whether ide, scsi or 'other'.  They
87  * hang in private_data off the gendisk structure. We may end up
88  * putting all kinds of interesting stuff here :-)
89  */
90 struct blkfront_info
91 {
92         struct xenbus_device *xbdev;
93         struct gendisk *gd;
94         struct mutex mutex;
95         int vdevice;
96         blkif_vdev_t handle;
97         int connected;
98         int ring_ref;
99         blkif_front_ring_t ring;
100         spinlock_t io_lock;
101         struct scatterlist sg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
102         unsigned int irq;
103         struct xlbd_major_info *mi;
104         struct request_queue *rq;
105         struct work_struct work;
106         struct gnttab_free_callback callback;
107         struct blk_shadow shadow[BLK_RING_SIZE];
108         unsigned long shadow_free;
109         unsigned int feature_flush;
110         unsigned int flush_op;
111         bool feature_discard;
112         bool feature_secdiscard;
113         unsigned int discard_granularity;
114         unsigned int discard_alignment;
115         int is_ready;
116 };
117
118 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
119 extern int blkif_open(struct inode *inode, struct file *filep);
120 extern int blkif_release(struct inode *inode, struct file *filep);
121 extern int blkif_ioctl(struct inode *inode, struct file *filep,
122                        unsigned command, unsigned long argument);
123 #else
124 extern int blkif_open(struct block_device *bdev, fmode_t mode);
125 extern int blkif_release(struct gendisk *disk, fmode_t mode);
126 extern int blkif_ioctl(struct block_device *bdev, fmode_t mode,
127                        unsigned command, unsigned long argument);
128 #endif
129 extern int blkif_getgeo(struct block_device *, struct hd_geometry *);
130 extern int blkif_check(dev_t dev);
131 extern int blkif_revalidate(dev_t dev);
132 extern void do_blkif_request (struct request_queue *rq);
133
134 /* Virtual block-device subsystem. */
135 /* Note that xlvbd_add doesn't call add_disk for you: you're expected
136    to call add_disk on info->gd once the disk is properly connected
137    up. */
138 int xlvbd_add(blkif_sector_t capacity, int device,
139               u16 vdisk_info, u16 sector_size, struct blkfront_info *info);
140 void xlvbd_del(struct blkfront_info *info);
141 void xlvbd_flush(struct blkfront_info *info);
142
143 #ifdef CONFIG_SYSFS
144 int xlvbd_sysfs_addif(struct blkfront_info *info);
145 void xlvbd_sysfs_delif(struct blkfront_info *info);
146 #else
147 static inline int xlvbd_sysfs_addif(struct blkfront_info *info)
148 {
149         return 0;
150 }
151
152 static inline void xlvbd_sysfs_delif(struct blkfront_info *info)
153 {
154         ;
155 }
156 #endif
157
158 void xlbd_release_major_info(void);
159
160 /* Virtual cdrom block-device */
161 #ifdef CONFIG_XEN
162 extern void register_vcd(struct blkfront_info *info);
163 extern void unregister_vcd(struct blkfront_info *info);
164 #else
165 static inline void register_vcd(struct blkfront_info *info) {}
166 static inline void unregister_vcd(struct blkfront_info *info) {}
167 #endif
168
169 #endif /* __XEN_DRIVERS_BLOCK_H__ */