1 /* 2 * 3 * Copyright (c) 2009, Microsoft Corporation. 4 * 5 * This program is free software; you can redistribute it and/or modify it 6 * under the terms and conditions of the GNU General Public License, 7 * version 2, as published by the Free Software Foundation. 8 * 9 * This program is distributed in the hope it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 * more details. 13 * 14 * You should have received a copy of the GNU General Public License along with 15 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple 16 * Place - Suite 330, Boston, MA 02111-1307 USA. 17 * 18 * Authors: 19 * Haiyang Zhang <haiyangz@microsoft.com> 20 * Hank Janssen <hjanssen@microsoft.com> 21 * 22 */ 23 24 25 #ifndef _VMBUS_PRIVATE_H_ 26 #define _VMBUS_PRIVATE_H_ 27 28 #include "hv.h" 29 #include "vmbus_api.h" 30 #include "channel.h" 31 #include "channel_mgmt.h" 32 #include "ring_buffer.h" 33 #include <linux/list.h> 34 #include <asm/sync_bitops.h> 35 36 37 /* 38 * Maximum channels is determined by the size of the interrupt page 39 * which is PAGE_SIZE. 1/2 of PAGE_SIZE is for send endpoint interrupt 40 * and the other is receive endpoint interrupt 41 */ 42 #define MAX_NUM_CHANNELS ((PAGE_SIZE >> 1) << 3) /* 16348 channels */ 43 44 /* The value here must be in multiple of 32 */ 45 /* TODO: Need to make this configurable */ 46 #define MAX_NUM_CHANNELS_SUPPORTED 256 47 48 49 enum vmbus_connect_state { 50 DISCONNECTED, 51 CONNECTING, 52 CONNECTED, 53 DISCONNECTING 54 }; 55 56 #define MAX_SIZE_CHANNEL_MESSAGE HV_MESSAGE_PAYLOAD_BYTE_COUNT 57 58 struct vmbus_connection { 59 enum vmbus_connect_state conn_state; 60 61 atomic_t next_gpadl_handle; 62 63 /* 64 * Represents channel interrupts. Each bit position represents a 65 * channel. When a channel sends an interrupt via VMBUS, it finds its 66 * bit in the sendInterruptPage, set it and calls Hv to generate a port 67 * event. The other end receives the port event and parse the 68 * recvInterruptPage to see which bit is set 69 */ 70 void *int_page; 71 void *send_int_page; 72 void *recv_int_page; 73 74 /* 75 * 2 pages - 1st page for parent->child notification and 2nd 76 * is child->parent notification 77 */ 78 void *monitor_pages; 79 struct list_head chn_msg_list; 80 spinlock_t channelmsg_lock; 81 82 /* List of channels */ 83 struct list_head chn_list; 84 spinlock_t channel_lock; 85 86 struct workqueue_struct *work_queue; 87 }; 88 89 90 struct vmbus_msginfo { 91 /* Bookkeeping stuff */ 92 struct list_head msglist_entry; 93 94 /* Synchronize the request/response if needed */ 95 int wait_condition; 96 wait_queue_head_t wait_event; 97 98 /* The message itself */ 99 unsigned char msg[0]; 100 }; 101 102 103 extern struct vmbus_connection vmbus_connection; 104 105 /* General vmbus interface */ 106 107 struct hv_device *vmbus_child_device_create(struct hv_guid *type, 108 struct hv_guid *instance, 109 struct vmbus_channel *channel); 110 111 int vmbus_child_device_register(struct hv_device *child_device_obj); 112 void vmbus_child_device_unregister(struct hv_device *device_obj); 113 114 /* static void */ 115 /* VmbusChildDeviceDestroy( */ 116 /* struct hv_device *); */ 117 118 struct vmbus_channel *relid2channel(u32 relid); 119 120 121 /* Connection interface */ 122 123 int vmbus_connect(void); 124 125 int vmbus_disconnect(void); 126 127 int vmbus_post_msg(void *buffer, size_t buflen); 128 129 int vmbus_set_event(u32 child_relid); 130 131 void vmbus_on_event(unsigned long data); 132 133 134 #endif /* _VMBUS_PRIVATE_H_ */ 135