blob: 46e5d0630440b797ff2b26b6933623898004c649 [file] [log] [blame]
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -04001/*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License version 2
4 * as published by the Free Software Foundation; or, when distributed
5 * separately from the Linux kernel or incorporated into other
6 * software packages, subject to the following license:
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this source file (the "Software"), to deal in the Software without
10 * restriction, including without limitation the rights to use, copy, modify,
11 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
12 * and to permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * IN THE SOFTWARE.
25 */
26
27#ifndef __BLKIF__BACKEND__COMMON_H__
28#define __BLKIF__BACKEND__COMMON_H__
29
30#include <linux/version.h>
31#include <linux/module.h>
32#include <linux/interrupt.h>
33#include <linux/slab.h>
34#include <linux/blkdev.h>
35#include <linux/vmalloc.h>
36#include <linux/wait.h>
Konrad Rzeszutek Wilk54893772011-04-14 17:21:50 -040037#include <linux/io.h>
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -040038#include <asm/setup.h>
39#include <asm/pgalloc.h>
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -040040#include <asm/hypervisor.h>
41#include <xen/blkif.h>
Jeremy Fitzhardinge88122932009-02-09 12:05:51 -080042#include <xen/grant_table.h>
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -040043#include <xen/xenbus.h>
44
Konrad Rzeszutek Wilk1afbd732011-05-11 16:15:24 -040045#define DPRINTK(fmt, args...) \
46 pr_debug("xen-blkback: (%s:%d) " fmt ".\n", \
47 __func__, __LINE__, ##args)
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -040048
49struct vbd {
Konrad Rzeszutek Wilk01f37f22011-05-11 15:57:09 -040050 /* What the domain refers to this vbd as. */
51 blkif_vdev_t handle;
52 /* Non-zero -> read-only */
53 unsigned char readonly;
54 /* VDISK_xxx */
55 unsigned char type;
56 /* phys device that this vbd maps to. */
57 u32 pdevice;
58 struct block_device *bdev;
59 /* Cached size parameter. */
60 sector_t size;
61 bool flush_support;
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -040062};
63
64struct backend_info;
65
Konrad Rzeszutek Wilk54893772011-04-14 17:21:50 -040066struct blkif_st {
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -040067 /* Unique identifier for this interface. */
Konrad Rzeszutek Wilk01f37f22011-05-11 15:57:09 -040068 domid_t domid;
69 unsigned int handle;
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -040070 /* Physical parameters of the comms window. */
Konrad Rzeszutek Wilk01f37f22011-05-11 15:57:09 -040071 unsigned int irq;
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -040072 /* Comms information. */
Konrad Rzeszutek Wilk01f37f22011-05-11 15:57:09 -040073 enum blkif_protocol blk_protocol;
74 union blkif_back_rings blk_rings;
75 struct vm_struct *blk_ring_area;
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -040076 /* The VBD attached to this interface. */
Konrad Rzeszutek Wilk01f37f22011-05-11 15:57:09 -040077 struct vbd vbd;
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -040078 /* Back pointer to the backend_info. */
Konrad Rzeszutek Wilk01f37f22011-05-11 15:57:09 -040079 struct backend_info *be;
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -040080 /* Private fields. */
Konrad Rzeszutek Wilk01f37f22011-05-11 15:57:09 -040081 spinlock_t blk_ring_lock;
82 atomic_t refcnt;
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -040083
Konrad Rzeszutek Wilk01f37f22011-05-11 15:57:09 -040084 wait_queue_head_t wq;
Konrad Rzeszutek Wilka1397fa2011-04-14 17:05:23 -040085 /* One thread per one blkif. */
Konrad Rzeszutek Wilk01f37f22011-05-11 15:57:09 -040086 struct task_struct *xenblkd;
87 unsigned int waiting_reqs;
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -040088
89 /* statistics */
Konrad Rzeszutek Wilk01f37f22011-05-11 15:57:09 -040090 unsigned long st_print;
91 int st_rd_req;
92 int st_wr_req;
93 int st_oo_req;
94 int st_f_req;
95 int st_rd_sect;
96 int st_wr_sect;
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -040097
Konrad Rzeszutek Wilk01f37f22011-05-11 15:57:09 -040098 wait_queue_head_t waiting_to_free;
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -040099
Konrad Rzeszutek Wilk01f37f22011-05-11 15:57:09 -0400100 grant_handle_t shmem_handle;
101 grant_ref_t shmem_ref;
Konrad Rzeszutek Wilk54893772011-04-14 17:21:50 -0400102};
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400103
Konrad Rzeszutek Wilk42c78412011-04-20 11:21:43 -0400104
105#define vbd_sz(_v) ((_v)->bdev->bd_part ? \
106 (_v)->bdev->bd_part->nr_sects : \
107 get_capacity((_v)->bdev->bd_disk))
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400108
Konrad Rzeszutek Wilk8b6bf742011-04-20 11:50:43 -0400109#define xen_blkif_get(_b) (atomic_inc(&(_b)->refcnt))
110#define xen_blkif_put(_b) \
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400111 do { \
112 if (atomic_dec_and_test(&(_b)->refcnt)) \
113 wake_up(&(_b)->waiting_to_free);\
114 } while (0)
115
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400116struct phys_req {
Konrad Rzeszutek Wilk01f37f22011-05-11 15:57:09 -0400117 unsigned short dev;
118 unsigned short nr_sects;
119 struct block_device *bdev;
120 blkif_sector_t sector_number;
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400121};
Konrad Rzeszutek Wilk8b6bf742011-04-20 11:50:43 -0400122int xen_blkif_interface_init(void);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400123
Konrad Rzeszutek Wilk8b6bf742011-04-20 11:50:43 -0400124int xen_blkif_xenbus_init(void);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400125
Konrad Rzeszutek Wilk8b6bf742011-04-20 11:50:43 -0400126irqreturn_t xen_blkif_be_int(int irq, void *dev_id);
127int xen_blkif_schedule(void *arg);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400128
Konrad Rzeszutek Wilk24f567f2011-05-04 17:07:27 -0400129int xen_blkbk_flush_diskcache(struct xenbus_transaction xbt,
130 struct backend_info *be, int state);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400131
Konrad Rzeszutek Wilk8b6bf742011-04-20 11:50:43 -0400132struct xenbus_device *xen_blkbk_xenbus(struct backend_info *be);
Jeremy Fitzhardinge98e036a2010-03-18 15:35:05 -0700133
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400134#endif /* __BLKIF__BACKEND__COMMON_H__ */