Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1 | /* |
| 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 Wilk | 5489377 | 2011-04-14 17:21:50 -0400 | [diff] [blame] | 37 | #include <linux/io.h> |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 38 | #include <asm/setup.h> |
| 39 | #include <asm/pgalloc.h> |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 40 | #include <asm/hypervisor.h> |
| 41 | #include <xen/blkif.h> |
Jeremy Fitzhardinge | 8812293 | 2009-02-09 12:05:51 -0800 | [diff] [blame] | 42 | #include <xen/grant_table.h> |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 43 | #include <xen/xenbus.h> |
| 44 | |
| 45 | #define DPRINTK(_f, _a...) \ |
| 46 | pr_debug("(file=%s, line=%d) " _f, \ |
Konrad Rzeszutek Wilk | 5489377 | 2011-04-14 17:21:50 -0400 | [diff] [blame] | 47 | __FILE__ , __LINE__ , ## _a) |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 48 | |
| 49 | struct vbd { |
| 50 | blkif_vdev_t handle; /* what the domain refers to this vbd as */ |
| 51 | unsigned char readonly; /* Non-zero -> read-only */ |
| 52 | unsigned char type; /* VDISK_xxx */ |
| 53 | u32 pdevice; /* phys device that this vbd maps to */ |
| 54 | struct block_device *bdev; |
K. Y. Srinivasan | 2ccbfe2 | 2010-03-11 13:39:50 -0800 | [diff] [blame] | 55 | sector_t size; /* Cached size parameter */ |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | struct backend_info; |
| 59 | |
Konrad Rzeszutek Wilk | 5489377 | 2011-04-14 17:21:50 -0400 | [diff] [blame] | 60 | struct blkif_st { |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 61 | /* Unique identifier for this interface. */ |
| 62 | domid_t domid; |
| 63 | unsigned int handle; |
| 64 | /* Physical parameters of the comms window. */ |
| 65 | unsigned int irq; |
| 66 | /* Comms information. */ |
| 67 | enum blkif_protocol blk_protocol; |
Jeremy Fitzhardinge | 8812293 | 2009-02-09 12:05:51 -0800 | [diff] [blame] | 68 | union blkif_back_rings blk_rings; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 69 | struct vm_struct *blk_ring_area; |
| 70 | /* The VBD attached to this interface. */ |
| 71 | struct vbd vbd; |
| 72 | /* Back pointer to the backend_info. */ |
| 73 | struct backend_info *be; |
| 74 | /* Private fields. */ |
| 75 | spinlock_t blk_ring_lock; |
| 76 | atomic_t refcnt; |
| 77 | |
| 78 | wait_queue_head_t wq; |
Konrad Rzeszutek Wilk | a1397fa | 2011-04-14 17:05:23 -0400 | [diff] [blame] | 79 | /* One thread per one blkif. */ |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 80 | struct task_struct *xenblkd; |
| 81 | unsigned int waiting_reqs; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 82 | |
| 83 | /* statistics */ |
| 84 | unsigned long st_print; |
| 85 | int st_rd_req; |
| 86 | int st_wr_req; |
| 87 | int st_oo_req; |
| 88 | int st_br_req; |
| 89 | int st_rd_sect; |
| 90 | int st_wr_sect; |
| 91 | |
| 92 | wait_queue_head_t waiting_to_free; |
| 93 | |
| 94 | grant_handle_t shmem_handle; |
| 95 | grant_ref_t shmem_ref; |
Konrad Rzeszutek Wilk | 5489377 | 2011-04-14 17:21:50 -0400 | [diff] [blame] | 96 | }; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 97 | |
Konrad Rzeszutek Wilk | 42c7841 | 2011-04-20 11:21:43 -0400 | [diff] [blame^] | 98 | |
| 99 | #define vbd_sz(_v) ((_v)->bdev->bd_part ? \ |
| 100 | (_v)->bdev->bd_part->nr_sects : \ |
| 101 | get_capacity((_v)->bdev->bd_disk)) |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 102 | |
| 103 | #define blkif_get(_b) (atomic_inc(&(_b)->refcnt)) |
| 104 | #define blkif_put(_b) \ |
| 105 | do { \ |
| 106 | if (atomic_dec_and_test(&(_b)->refcnt)) \ |
| 107 | wake_up(&(_b)->waiting_to_free);\ |
| 108 | } while (0) |
| 109 | |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 110 | struct phys_req { |
| 111 | unsigned short dev; |
| 112 | unsigned short nr_sects; |
| 113 | struct block_device *bdev; |
| 114 | blkif_sector_t sector_number; |
| 115 | }; |
Konrad Rzeszutek Wilk | 8770b26 | 2009-10-08 13:23:09 -0400 | [diff] [blame] | 116 | int blkif_interface_init(void); |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 117 | |
Konrad Rzeszutek Wilk | 8770b26 | 2009-10-08 13:23:09 -0400 | [diff] [blame] | 118 | int blkif_xenbus_init(void); |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 119 | |
Jeremy Fitzhardinge | 8812293 | 2009-02-09 12:05:51 -0800 | [diff] [blame] | 120 | irqreturn_t blkif_be_int(int irq, void *dev_id); |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 121 | int blkif_schedule(void *arg); |
| 122 | |
| 123 | int blkback_barrier(struct xenbus_transaction xbt, |
| 124 | struct backend_info *be, int state); |
| 125 | |
Jeremy Fitzhardinge | 98e036a | 2010-03-18 15:35:05 -0700 | [diff] [blame] | 126 | struct xenbus_device *blkback_xenbus(struct backend_info *be); |
| 127 | |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 128 | #endif /* __BLKIF__BACKEND__COMMON_H__ */ |