diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/staging/hv/vmbus_drv.c | 946 |
1 files changed, 405 insertions, 541 deletions
diff --git a/drivers/staging/hv/vmbus_drv.c b/drivers/staging/hv/vmbus_drv.c index cc81ffd7e8a..b0d2481f544 100644 --- a/drivers/staging/hv/vmbus_drv.c +++ b/drivers/staging/hv/vmbus_drv.c | |||
@@ -1,5 +1,4 @@ | |||
1 | /* | 1 | /* |
2 | * | ||
3 | * Copyright (c) 2009, Microsoft Corporation. | 2 | * Copyright (c) 2009, Microsoft Corporation. |
4 | * | 3 | * |
5 | * This program is free software; you can redistribute it and/or modify it | 4 | * This program is free software; you can redistribute it and/or modify it |
@@ -18,10 +17,7 @@ | |||
18 | * Authors: | 17 | * Authors: |
19 | * Haiyang Zhang <haiyangz@microsoft.com> | 18 | * Haiyang Zhang <haiyangz@microsoft.com> |
20 | * Hank Janssen <hjanssen@microsoft.com> | 19 | * Hank Janssen <hjanssen@microsoft.com> |
21 | * | ||
22 | */ | 20 | */ |
23 | |||
24 | |||
25 | #include <linux/init.h> | 21 | #include <linux/init.h> |
26 | #include <linux/module.h> | 22 | #include <linux/module.h> |
27 | #include <linux/device.h> | 23 | #include <linux/device.h> |
@@ -33,35 +29,27 @@ | |||
33 | #include "vmbus.h" | 29 | #include "vmbus.h" |
34 | 30 | ||
35 | 31 | ||
36 | /* Defines */ | ||
37 | |||
38 | |||
39 | /* FIXME! We need to do this dynamically for PIC and APIC system */ | 32 | /* FIXME! We need to do this dynamically for PIC and APIC system */ |
40 | #define VMBUS_IRQ 0x5 | 33 | #define VMBUS_IRQ 0x5 |
41 | #define VMBUS_IRQ_VECTOR IRQ5_VECTOR | 34 | #define VMBUS_IRQ_VECTOR IRQ5_VECTOR |
42 | |||
43 | /* Data types */ | ||
44 | |||
45 | 35 | ||
46 | /* Main vmbus driver data structure */ | 36 | /* Main vmbus driver data structure */ |
47 | struct vmbus_driver_context { | 37 | struct vmbus_driver_context { |
48 | /* !! These must be the first 2 fields !! */ | 38 | /* !! These must be the first 2 fields !! */ |
39 | /* FIXME, this is a bug */ | ||
49 | /* The driver field is not used in here. Instead, the bus field is */ | 40 | /* The driver field is not used in here. Instead, the bus field is */ |
50 | /* used to represent the driver */ | 41 | /* used to represent the driver */ |
51 | struct driver_context drv_ctx; | 42 | struct driver_context drv_ctx; |
52 | struct vmbus_driver drv_obj; | 43 | struct vmbus_driver drv_obj; |
53 | 44 | ||
54 | struct bus_type bus; | 45 | struct bus_type bus; |
55 | struct tasklet_struct msg_dpc; | 46 | struct tasklet_struct msg_dpc; |
56 | struct tasklet_struct event_dpc; | 47 | struct tasklet_struct event_dpc; |
57 | 48 | ||
58 | /* The bus root device */ | 49 | /* The bus root device */ |
59 | struct device_context device_ctx; | 50 | struct device_context device_ctx; |
60 | }; | 51 | }; |
61 | 52 | ||
62 | |||
63 | /* Static decl */ | ||
64 | |||
65 | static int vmbus_match(struct device *device, struct device_driver *driver); | 53 | static int vmbus_match(struct device *device, struct device_driver *driver); |
66 | static int vmbus_probe(struct device *device); | 54 | static int vmbus_probe(struct device *device); |
67 | static int vmbus_remove(struct device *device); | 55 | static int vmbus_remove(struct device *device); |
@@ -70,40 +58,33 @@ static int vmbus_uevent(struct device *device, struct kobj_uevent_env *env); | |||
70 | static void vmbus_msg_dpc(unsigned long data); | 58 | static void vmbus_msg_dpc(unsigned long data); |
71 | static void vmbus_event_dpc(unsigned long data); | 59 | static void vmbus_event_dpc(unsigned long data); |
72 | 60 | ||
73 | static irqreturn_t vmbus_isr(int irq, void* dev_id); | 61 | static irqreturn_t vmbus_isr(int irq, void *dev_id); |
74 | 62 | ||
75 | static void vmbus_device_release(struct device *device); | 63 | static void vmbus_device_release(struct device *device); |
76 | static void vmbus_bus_release(struct device *device); | 64 | static void vmbus_bus_release(struct device *device); |
77 | 65 | ||
78 | static struct hv_device *vmbus_child_device_create(struct hv_guid *type, struct hv_guid *instance, void *context); | 66 | static struct hv_device *vmbus_child_device_create(struct hv_guid *type, |
67 | struct hv_guid *instance, | ||
68 | void *context); | ||
79 | static void vmbus_child_device_destroy(struct hv_device *device_obj); | 69 | static void vmbus_child_device_destroy(struct hv_device *device_obj); |
80 | static int vmbus_child_device_register(struct hv_device *root_device_obj, struct hv_device *child_device_obj); | 70 | static int vmbus_child_device_register(struct hv_device *root_device_obj, |
71 | struct hv_device *child_device_obj); | ||
81 | static void vmbus_child_device_unregister(struct hv_device *child_device_obj); | 72 | static void vmbus_child_device_unregister(struct hv_device *child_device_obj); |
82 | static void vmbus_child_device_get_info(struct hv_device *device_obj, struct hv_device_info *device_info); | 73 | static void vmbus_child_device_get_info(struct hv_device *device_obj, |
74 | struct hv_device_info *device_info); | ||
75 | static ssize_t vmbus_show_device_attr(struct device *dev, | ||
76 | struct device_attribute *dev_attr, | ||
77 | char *buf); | ||
83 | 78 | ||
84 | /* static ssize_t vmbus_show_class_id(struct device *dev, struct device_attribute *attr, char *buf); */ | ||
85 | /* static ssize_t vmbus_show_device_id(struct device *dev, struct device_attribute *attr, char *buf); */ | ||
86 | 79 | ||
87 | static ssize_t vmbus_show_device_attr(struct device *dev, struct device_attribute *dev_attr, char *buf); | 80 | unsigned int vmbus_loglevel = (ALL_MODULES << 16 | INFO_LVL); |
88 | |||
89 | |||
90 | /* Global */ | ||
91 | |||
92 | |||
93 | /* Global logging setting */ | ||
94 | |||
95 | /* unsigned int vmbus_loglevel= (((VMBUS | VMBUS_DRV)<<16) | DEBUG_LVL_ENTEREXIT); */ | ||
96 | /* unsigned int vmbus_loglevel= (ALL_MODULES << 16 | DEBUG_LVL_ENTEREXIT); */ | ||
97 | unsigned int vmbus_loglevel= (ALL_MODULES << 16 | INFO_LVL); | ||
98 | EXPORT_SYMBOL(vmbus_loglevel); | 81 | EXPORT_SYMBOL(vmbus_loglevel); |
82 | /* (ALL_MODULES << 16 | DEBUG_LVL_ENTEREXIT); */ | ||
83 | /* (((VMBUS | VMBUS_DRV)<<16) | DEBUG_LVL_ENTEREXIT); */ | ||
99 | 84 | ||
100 | static int vmbus_irq = VMBUS_IRQ; | 85 | static int vmbus_irq = VMBUS_IRQ; |
101 | 86 | ||
102 | /* Setup /proc/sys/bus/vmbus/vmbus_loglevel */ | ||
103 | /* Allow usage of sysctl cmd to set the logging level */ | ||
104 | |||
105 | /* Set up per device attributes in /sys/bus/vmbus/devices/<bus device> */ | 87 | /* Set up per device attributes in /sys/bus/vmbus/devices/<bus device> */ |
106 | |||
107 | static struct device_attribute vmbus_device_attrs[] = { | 88 | static struct device_attribute vmbus_device_attrs[] = { |
108 | __ATTR(id, S_IRUGO, vmbus_show_device_attr, NULL), | 89 | __ATTR(id, S_IRUGO, vmbus_show_device_attr, NULL), |
109 | __ATTR(state, S_IRUGO, vmbus_show_device_attr, NULL), | 90 | __ATTR(state, S_IRUGO, vmbus_show_device_attr, NULL), |
@@ -134,29 +115,25 @@ static struct device_attribute vmbus_device_attrs[] = { | |||
134 | }; | 115 | }; |
135 | 116 | ||
136 | /* The one and only one */ | 117 | /* The one and only one */ |
137 | static struct vmbus_driver_context g_vmbus_drv={ | 118 | static struct vmbus_driver_context g_vmbus_drv = { |
138 | .bus.name = "vmbus", | 119 | .bus.name = "vmbus", |
139 | .bus.match = vmbus_match, | 120 | .bus.match = vmbus_match, |
140 | .bus.shutdown = vmbus_shutdown, | 121 | .bus.shutdown = vmbus_shutdown, |
141 | .bus.remove = vmbus_remove, | 122 | .bus.remove = vmbus_remove, |
142 | .bus.probe = vmbus_probe, | 123 | .bus.probe = vmbus_probe, |
143 | .bus.uevent = vmbus_uevent, | 124 | .bus.uevent = vmbus_uevent, |
144 | .bus.dev_attrs = vmbus_device_attrs, | 125 | .bus.dev_attrs = vmbus_device_attrs, |
145 | }; | 126 | }; |
146 | 127 | ||
147 | 128 | /** | |
148 | /* Routines */ | 129 | * vmbus_show_device_attr - Show the device attribute in sysfs. |
149 | 130 | * | |
150 | 131 | * This is invoked when user does a | |
151 | 132 | * "cat /sys/bus/vmbus/devices/<busdevice>/<attr name>" | |
152 | /*++ | 133 | */ |
153 | 134 | static ssize_t vmbus_show_device_attr(struct device *dev, | |
154 | Name: vmbus_show_device_attr() | 135 | struct device_attribute *dev_attr, |
155 | 136 | char *buf) | |
156 | Desc: Show the device attribute in sysfs. This is invoked when user does a "cat /sys/bus/vmbus/devices/<bus device>/<attr name>" | ||
157 | |||
158 | --*/ | ||
159 | static ssize_t vmbus_show_device_attr(struct device *dev, struct device_attribute *dev_attr, char *buf) | ||
160 | { | 137 | { |
161 | struct device_context *device_ctx = device_to_device_context(dev); | 138 | struct device_context *device_ctx = device_to_device_context(dev); |
162 | struct hv_device_info device_info; | 139 | struct hv_device_info device_info; |
@@ -165,173 +142,119 @@ static ssize_t vmbus_show_device_attr(struct device *dev, struct device_attribut | |||
165 | 142 | ||
166 | vmbus_child_device_get_info(&device_ctx->device_obj, &device_info); | 143 | vmbus_child_device_get_info(&device_ctx->device_obj, &device_info); |
167 | 144 | ||
168 | if (!strcmp(dev_attr->attr.name, "class_id")) | 145 | if (!strcmp(dev_attr->attr.name, "class_id")) { |
169 | { | 146 | return sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-" |
170 | return sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}\n", | 147 | "%02x%02x%02x%02x%02x%02x%02x%02x}\n", |
171 | device_info.ChannelType.data[3], device_info.ChannelType.data[2], | 148 | device_info.ChannelType.data[3], |
172 | device_info.ChannelType.data[1], device_info.ChannelType.data[0], | 149 | device_info.ChannelType.data[2], |
173 | device_info.ChannelType.data[5], device_info.ChannelType.data[4], | 150 | device_info.ChannelType.data[1], |
174 | device_info.ChannelType.data[7], device_info.ChannelType.data[6], | 151 | device_info.ChannelType.data[0], |
175 | device_info.ChannelType.data[8], device_info.ChannelType.data[9], | 152 | device_info.ChannelType.data[5], |
176 | device_info.ChannelType.data[10], device_info.ChannelType.data[11], | 153 | device_info.ChannelType.data[4], |
177 | device_info.ChannelType.data[12], device_info.ChannelType.data[13], | 154 | device_info.ChannelType.data[7], |
178 | device_info.ChannelType.data[14], device_info.ChannelType.data[15]); | 155 | device_info.ChannelType.data[6], |
179 | 156 | device_info.ChannelType.data[8], | |
180 | } | 157 | device_info.ChannelType.data[9], |
181 | else if (!strcmp(dev_attr->attr.name, "device_id")) | 158 | device_info.ChannelType.data[10], |
182 | { | 159 | device_info.ChannelType.data[11], |
183 | return sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}\n", | 160 | device_info.ChannelType.data[12], |
184 | device_info.ChannelInstance.data[3], device_info.ChannelInstance.data[2], | 161 | device_info.ChannelType.data[13], |
185 | device_info.ChannelInstance.data[1], device_info.ChannelInstance.data[0], | 162 | device_info.ChannelType.data[14], |
186 | device_info.ChannelInstance.data[5], device_info.ChannelInstance.data[4], | 163 | device_info.ChannelType.data[15]); |
187 | device_info.ChannelInstance.data[7], device_info.ChannelInstance.data[6], | 164 | } else if (!strcmp(dev_attr->attr.name, "device_id")) { |
188 | device_info.ChannelInstance.data[8], device_info.ChannelInstance.data[9], | 165 | return sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-" |
189 | device_info.ChannelInstance.data[10], device_info.ChannelInstance.data[11], | 166 | "%02x%02x%02x%02x%02x%02x%02x%02x}\n", |
190 | device_info.ChannelInstance.data[12], device_info.ChannelInstance.data[13], | 167 | device_info.ChannelInstance.data[3], |
191 | device_info.ChannelInstance.data[14], device_info.ChannelInstance.data[15]); | 168 | device_info.ChannelInstance.data[2], |
192 | } | 169 | device_info.ChannelInstance.data[1], |
193 | else if (!strcmp(dev_attr->attr.name, "state")) | 170 | device_info.ChannelInstance.data[0], |
194 | { | 171 | device_info.ChannelInstance.data[5], |
172 | device_info.ChannelInstance.data[4], | ||
173 | device_info.ChannelInstance.data[7], | ||
174 | device_info.ChannelInstance.data[6], | ||
175 | device_info.ChannelInstance.data[8], | ||
176 | device_info.ChannelInstance.data[9], | ||
177 | device_info.ChannelInstance.data[10], | ||
178 | device_info.ChannelInstance.data[11], | ||
179 | device_info.ChannelInstance.data[12], | ||
180 | device_info.ChannelInstance.data[13], | ||
181 | device_info.ChannelInstance.data[14], | ||
182 | device_info.ChannelInstance.data[15]); | ||
183 | } else if (!strcmp(dev_attr->attr.name, "state")) { | ||
195 | return sprintf(buf, "%d\n", device_info.ChannelState); | 184 | return sprintf(buf, "%d\n", device_info.ChannelState); |
196 | } | 185 | } else if (!strcmp(dev_attr->attr.name, "id")) { |
197 | else if (!strcmp(dev_attr->attr.name, "id")) | ||
198 | { | ||
199 | return sprintf(buf, "%d\n", device_info.ChannelId); | 186 | return sprintf(buf, "%d\n", device_info.ChannelId); |
200 | } | 187 | } else if (!strcmp(dev_attr->attr.name, "out_intr_mask")) { |
201 | else if (!strcmp(dev_attr->attr.name, "out_intr_mask")) | ||
202 | { | ||
203 | return sprintf(buf, "%d\n", device_info.Outbound.InterruptMask); | 188 | return sprintf(buf, "%d\n", device_info.Outbound.InterruptMask); |
204 | } | 189 | } else if (!strcmp(dev_attr->attr.name, "out_read_index")) { |
205 | else if (!strcmp(dev_attr->attr.name, "out_read_index")) | ||
206 | { | ||
207 | return sprintf(buf, "%d\n", device_info.Outbound.ReadIndex); | 190 | return sprintf(buf, "%d\n", device_info.Outbound.ReadIndex); |
208 | } | 191 | } else if (!strcmp(dev_attr->attr.name, "out_write_index")) { |
209 | else if (!strcmp(dev_attr->attr.name, "out_write_index")) | ||
210 | { | ||
211 | return sprintf(buf, "%d\n", device_info.Outbound.WriteIndex); | 192 | return sprintf(buf, "%d\n", device_info.Outbound.WriteIndex); |
212 | } | 193 | } else if (!strcmp(dev_attr->attr.name, "out_read_bytes_avail")) { |
213 | else if (!strcmp(dev_attr->attr.name, "out_read_bytes_avail")) | 194 | return sprintf(buf, "%d\n", |
214 | { | 195 | device_info.Outbound.BytesAvailToRead); |
215 | return sprintf(buf, "%d\n", device_info.Outbound.BytesAvailToRead); | 196 | } else if (!strcmp(dev_attr->attr.name, "out_write_bytes_avail")) { |
216 | } | 197 | return sprintf(buf, "%d\n", |
217 | else if (!strcmp(dev_attr->attr.name, "out_write_bytes_avail")) | 198 | device_info.Outbound.BytesAvailToWrite); |
218 | { | 199 | } else if (!strcmp(dev_attr->attr.name, "in_intr_mask")) { |
219 | return sprintf(buf, "%d\n", device_info.Outbound.BytesAvailToWrite); | ||
220 | } | ||
221 | else if (!strcmp(dev_attr->attr.name, "in_intr_mask")) | ||
222 | { | ||
223 | return sprintf(buf, "%d\n", device_info.Inbound.InterruptMask); | 200 | return sprintf(buf, "%d\n", device_info.Inbound.InterruptMask); |
224 | } | 201 | } else if (!strcmp(dev_attr->attr.name, "in_read_index")) { |
225 | else if (!strcmp(dev_attr->attr.name, "in_read_index")) | ||
226 | { | ||
227 | return sprintf(buf, "%d\n", device_info.Inbound.ReadIndex); | 202 | return sprintf(buf, "%d\n", device_info.Inbound.ReadIndex); |
228 | } | 203 | } else if (!strcmp(dev_attr->attr.name, "in_write_index")) { |
229 | else if (!strcmp(dev_attr->attr.name, "in_write_index")) | ||
230 | { | ||
231 | return sprintf(buf, "%d\n", device_info.Inbound.WriteIndex); | 204 | return sprintf(buf, "%d\n", device_info.Inbound.WriteIndex); |
232 | } | 205 | } else if (!strcmp(dev_attr->attr.name, "in_read_bytes_avail")) { |
233 | else if (!strcmp(dev_attr->attr.name, "in_read_bytes_avail")) | 206 | return sprintf(buf, "%d\n", |
234 | { | 207 | device_info.Inbound.BytesAvailToRead); |
235 | return sprintf(buf, "%d\n", device_info.Inbound.BytesAvailToRead); | 208 | } else if (!strcmp(dev_attr->attr.name, "in_write_bytes_avail")) { |
236 | } | 209 | return sprintf(buf, "%d\n", |
237 | else if (!strcmp(dev_attr->attr.name, "in_write_bytes_avail")) | 210 | device_info.Inbound.BytesAvailToWrite); |
238 | { | 211 | } else if (!strcmp(dev_attr->attr.name, "monitor_id")) { |
239 | return sprintf(buf, "%d\n", device_info.Inbound.BytesAvailToWrite); | ||
240 | } | ||
241 | else if (!strcmp(dev_attr->attr.name, "monitor_id")) | ||
242 | { | ||
243 | return sprintf(buf, "%d\n", device_info.MonitorId); | 212 | return sprintf(buf, "%d\n", device_info.MonitorId); |
244 | } | 213 | } else if (!strcmp(dev_attr->attr.name, "server_monitor_pending")) { |
245 | else if (!strcmp(dev_attr->attr.name, "server_monitor_pending")) | ||
246 | { | ||
247 | return sprintf(buf, "%d\n", device_info.ServerMonitorPending); | 214 | return sprintf(buf, "%d\n", device_info.ServerMonitorPending); |
248 | } | 215 | } else if (!strcmp(dev_attr->attr.name, "server_monitor_latency")) { |
249 | else if (!strcmp(dev_attr->attr.name, "server_monitor_latency")) | ||
250 | { | ||
251 | return sprintf(buf, "%d\n", device_info.ServerMonitorLatency); | 216 | return sprintf(buf, "%d\n", device_info.ServerMonitorLatency); |
252 | } | 217 | } else if (!strcmp(dev_attr->attr.name, "server_monitor_conn_id")) { |
253 | else if (!strcmp(dev_attr->attr.name, "server_monitor_conn_id")) | 218 | return sprintf(buf, "%d\n", |
254 | { | 219 | device_info.ServerMonitorConnectionId); |
255 | return sprintf(buf, "%d\n", device_info.ServerMonitorConnectionId); | 220 | } else if (!strcmp(dev_attr->attr.name, "client_monitor_pending")) { |
256 | } | ||
257 | else if (!strcmp(dev_attr->attr.name, "client_monitor_pending")) | ||
258 | { | ||
259 | return sprintf(buf, "%d\n", device_info.ClientMonitorPending); | 221 | return sprintf(buf, "%d\n", device_info.ClientMonitorPending); |
260 | } | 222 | } else if (!strcmp(dev_attr->attr.name, "client_monitor_latency")) { |
261 | else if (!strcmp(dev_attr->attr.name, "client_monitor_latency")) | ||
262 | { | ||
263 | return sprintf(buf, "%d\n", device_info.ClientMonitorLatency); | 223 | return sprintf(buf, "%d\n", device_info.ClientMonitorLatency); |
264 | } | 224 | } else if (!strcmp(dev_attr->attr.name, "client_monitor_conn_id")) { |
265 | else if (!strcmp(dev_attr->attr.name, "client_monitor_conn_id")) | 225 | return sprintf(buf, "%d\n", |
266 | { | 226 | device_info.ClientMonitorConnectionId); |
267 | return sprintf(buf, "%d\n", device_info.ClientMonitorConnectionId); | 227 | } else { |
268 | } | ||
269 | else | ||
270 | { | ||
271 | return 0; | 228 | return 0; |
272 | } | 229 | } |
273 | } | 230 | } |
274 | 231 | ||
275 | /*++ | 232 | /** |
276 | 233 | * vmbus_bus_init -Main vmbus driver initialization routine. | |
277 | Name: vmbus_show_class_id() | 234 | * |
278 | 235 | * Here, we | |
279 | Desc: Show the device class id in sysfs | 236 | * - initialize the vmbus driver context |
280 | 237 | * - setup various driver entry points | |
281 | --*/ | 238 | * - invoke the vmbus hv main init routine |
282 | /* static ssize_t vmbus_show_class_id(struct device *dev, struct device_attribute *attr, char *buf) */ | 239 | * - get the irq resource |
283 | /* { */ | 240 | * - invoke the vmbus to add the vmbus root device |
284 | /* struct device_context *device_ctx = device_to_device_context(dev); */ | 241 | * - setup the vmbus root device |
285 | /* return sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}\n", */ | 242 | * - retrieve the channel offers |
286 | /* device_ctx->class_id[3], device_ctx->class_id[2], device_ctx->class_id[1], device_ctx->class_id[0], */ | 243 | */ |
287 | /* device_ctx->class_id[5], device_ctx->class_id[4], */ | ||
288 | /* device_ctx->class_id[7], device_ctx->class_id[6], */ | ||
289 | /* device_ctx->class_id[8], device_ctx->class_id[9], device_ctx->class_id[10], device_ctx->class_id[11], device_ctx->class_id[12], device_ctx->class_id[13], device_ctx->class_id[14], device_ctx->class_id[15]); */ | ||
290 | /* } */ | ||
291 | |||
292 | /*++ | ||
293 | |||
294 | Name: vmbus_show_device_id() | ||
295 | |||
296 | Desc: Show the device instance id in sysfs | ||
297 | |||
298 | --*/ | ||
299 | /* static ssize_t vmbus_show_device_id(struct device *dev, struct device_attribute *attr, char *buf) */ | ||
300 | /* { */ | ||
301 | /* struct device_context *device_ctx = device_to_device_context(dev); */ | ||
302 | /* return sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}\n", */ | ||
303 | /* device_ctx->device_id[3], device_ctx->device_id[2], device_ctx->device_id[1], device_ctx->device_id[0], */ | ||
304 | /* device_ctx->device_id[5], device_ctx->device_id[4], */ | ||
305 | /* device_ctx->device_id[7], device_ctx->device_id[6], */ | ||
306 | /* device_ctx->device_id[8], device_ctx->device_id[9], device_ctx->device_id[10], device_ctx->device_id[11], device_ctx->device_id[12], device_ctx->device_id[13], device_ctx->device_id[14], device_ctx->device_id[15]); */ | ||
307 | /* } */ | ||
308 | |||
309 | /*++ | ||
310 | |||
311 | Name: vmbus_bus_init() | ||
312 | |||
313 | Desc: Main vmbus driver initialization routine. Here, we | ||
314 | - initialize the vmbus driver context | ||
315 | - setup various driver entry points | ||
316 | - invoke the vmbus hv main init routine | ||
317 | - get the irq resource | ||
318 | - invoke the vmbus to add the vmbus root device | ||
319 | - setup the vmbus root device | ||
320 | - retrieve the channel offers | ||
321 | --*/ | ||
322 | static int vmbus_bus_init(PFN_DRIVERINITIALIZE pfn_drv_init) | 244 | static int vmbus_bus_init(PFN_DRIVERINITIALIZE pfn_drv_init) |
323 | { | 245 | { |
324 | int ret=0; | 246 | struct vmbus_driver_context *vmbus_drv_ctx = &g_vmbus_drv; |
325 | unsigned int vector=0; | ||
326 | |||
327 | struct vmbus_driver_context *vmbus_drv_ctx=&g_vmbus_drv; | ||
328 | struct vmbus_driver *vmbus_drv_obj = &g_vmbus_drv.drv_obj; | 247 | struct vmbus_driver *vmbus_drv_obj = &g_vmbus_drv.drv_obj; |
329 | 248 | struct device_context *dev_ctx = &g_vmbus_drv.device_ctx; | |
330 | struct device_context *dev_ctx=&g_vmbus_drv.device_ctx; | 249 | int ret; |
250 | unsigned int vector; | ||
331 | 251 | ||
332 | DPRINT_ENTER(VMBUS_DRV); | 252 | DPRINT_ENTER(VMBUS_DRV); |
333 | 253 | ||
334 | /* Set this up to allow lower layer to callback to add/remove child devices on the bus */ | 254 | /* |
255 | * Set this up to allow lower layer to callback to add/remove child | ||
256 | * devices on the bus | ||
257 | */ | ||
335 | vmbus_drv_obj->OnChildDeviceCreate = vmbus_child_device_create; | 258 | vmbus_drv_obj->OnChildDeviceCreate = vmbus_child_device_create; |
336 | vmbus_drv_obj->OnChildDeviceDestroy = vmbus_child_device_destroy; | 259 | vmbus_drv_obj->OnChildDeviceDestroy = vmbus_child_device_destroy; |
337 | vmbus_drv_obj->OnChildDeviceAdd = vmbus_child_device_register; | 260 | vmbus_drv_obj->OnChildDeviceAdd = vmbus_child_device_register; |
@@ -339,15 +262,13 @@ static int vmbus_bus_init(PFN_DRIVERINITIALIZE pfn_drv_init) | |||
339 | 262 | ||
340 | /* Call to bus driver to initialize */ | 263 | /* Call to bus driver to initialize */ |
341 | ret = pfn_drv_init(&vmbus_drv_obj->Base); | 264 | ret = pfn_drv_init(&vmbus_drv_obj->Base); |
342 | if (ret != 0) | 265 | if (ret != 0) { |
343 | { | ||
344 | DPRINT_ERR(VMBUS_DRV, "Unable to initialize vmbus (%d)", ret); | 266 | DPRINT_ERR(VMBUS_DRV, "Unable to initialize vmbus (%d)", ret); |
345 | goto cleanup; | 267 | goto cleanup; |
346 | } | 268 | } |
347 | 269 | ||
348 | /* Sanity checks */ | 270 | /* Sanity checks */ |
349 | if (!vmbus_drv_obj->Base.OnDeviceAdd) | 271 | if (!vmbus_drv_obj->Base.OnDeviceAdd) { |
350 | { | ||
351 | DPRINT_ERR(VMBUS_DRV, "OnDeviceAdd() routine not set"); | 272 | DPRINT_ERR(VMBUS_DRV, "OnDeviceAdd() routine not set"); |
352 | ret = -1; | 273 | ret = -1; |
353 | goto cleanup; | 274 | goto cleanup; |
@@ -356,27 +277,25 @@ static int vmbus_bus_init(PFN_DRIVERINITIALIZE pfn_drv_init) | |||
356 | vmbus_drv_ctx->bus.name = vmbus_drv_obj->Base.name; | 277 | vmbus_drv_ctx->bus.name = vmbus_drv_obj->Base.name; |
357 | 278 | ||
358 | /* Initialize the bus context */ | 279 | /* Initialize the bus context */ |
359 | tasklet_init(&vmbus_drv_ctx->msg_dpc, vmbus_msg_dpc, (unsigned long)vmbus_drv_obj); | 280 | tasklet_init(&vmbus_drv_ctx->msg_dpc, vmbus_msg_dpc, |
360 | tasklet_init(&vmbus_drv_ctx->event_dpc, vmbus_event_dpc, (unsigned long)vmbus_drv_obj); | 281 | (unsigned long)vmbus_drv_obj); |
282 | tasklet_init(&vmbus_drv_ctx->event_dpc, vmbus_event_dpc, | ||
283 | (unsigned long)vmbus_drv_obj); | ||
361 | 284 | ||
362 | /* Now, register the bus driver with LDM */ | 285 | /* Now, register the bus driver with LDM */ |
363 | ret = bus_register(&vmbus_drv_ctx->bus); | 286 | ret = bus_register(&vmbus_drv_ctx->bus); |
364 | if (ret) | 287 | if (ret) { |
365 | { | ||
366 | ret = -1; | 288 | ret = -1; |
367 | goto cleanup; | 289 | goto cleanup; |
368 | } | 290 | } |
369 | 291 | ||
370 | /* Get the interrupt resource */ | 292 | /* Get the interrupt resource */ |
371 | ret = request_irq(vmbus_irq, | 293 | ret = request_irq(vmbus_irq, vmbus_isr, IRQF_SAMPLE_RANDOM, |
372 | vmbus_isr, | 294 | vmbus_drv_obj->Base.name, NULL); |
373 | IRQF_SAMPLE_RANDOM, | ||
374 | vmbus_drv_obj->Base.name, | ||
375 | NULL); | ||
376 | 295 | ||
377 | if (ret != 0) | 296 | if (ret != 0) { |
378 | { | 297 | DPRINT_ERR(VMBUS_DRV, "ERROR - Unable to request IRQ %d", |
379 | DPRINT_ERR(VMBUS_DRV, "ERROR - Unable to request IRQ %d", vmbus_irq); | 298 | vmbus_irq); |
380 | 299 | ||
381 | bus_unregister(&vmbus_drv_ctx->bus); | 300 | bus_unregister(&vmbus_drv_ctx->bus); |
382 | 301 | ||
@@ -391,9 +310,9 @@ static int vmbus_bus_init(PFN_DRIVERINITIALIZE pfn_drv_init) | |||
391 | memset(dev_ctx, 0, sizeof(struct device_context)); | 310 | memset(dev_ctx, 0, sizeof(struct device_context)); |
392 | 311 | ||
393 | ret = vmbus_drv_obj->Base.OnDeviceAdd(&dev_ctx->device_obj, &vector); | 312 | ret = vmbus_drv_obj->Base.OnDeviceAdd(&dev_ctx->device_obj, &vector); |
394 | if (ret != 0) | 313 | if (ret != 0) { |
395 | { | 314 | DPRINT_ERR(VMBUS_DRV, |
396 | DPRINT_ERR(VMBUS_DRV, "ERROR - Unable to add vmbus root device"); | 315 | "ERROR - Unable to add vmbus root device"); |
397 | 316 | ||
398 | free_irq(vmbus_irq, NULL); | 317 | free_irq(vmbus_irq, NULL); |
399 | 318 | ||
@@ -404,21 +323,24 @@ static int vmbus_bus_init(PFN_DRIVERINITIALIZE pfn_drv_init) | |||
404 | } | 323 | } |
405 | /* strcpy(dev_ctx->device.bus_id, dev_ctx->device_obj.name); */ | 324 | /* strcpy(dev_ctx->device.bus_id, dev_ctx->device_obj.name); */ |
406 | dev_set_name(&dev_ctx->device, "vmbus_0_0"); | 325 | dev_set_name(&dev_ctx->device, "vmbus_0_0"); |
407 | memcpy(&dev_ctx->class_id, &dev_ctx->device_obj.deviceType, sizeof(struct hv_guid)); | 326 | memcpy(&dev_ctx->class_id, &dev_ctx->device_obj.deviceType, |
408 | memcpy(&dev_ctx->device_id, &dev_ctx->device_obj.deviceInstance, sizeof(struct hv_guid)); | 327 | sizeof(struct hv_guid)); |
328 | memcpy(&dev_ctx->device_id, &dev_ctx->device_obj.deviceInstance, | ||
329 | sizeof(struct hv_guid)); | ||
409 | 330 | ||
410 | /* No need to bind a driver to the root device. */ | 331 | /* No need to bind a driver to the root device. */ |
411 | dev_ctx->device.parent = NULL; | 332 | dev_ctx->device.parent = NULL; |
412 | dev_ctx->device.bus = &vmbus_drv_ctx->bus; /* NULL; vmbus_remove() does not get invoked */ | 333 | /* NULL; vmbus_remove() does not get invoked */ |
334 | dev_ctx->device.bus = &vmbus_drv_ctx->bus; | ||
413 | 335 | ||
414 | /* Setup the device dispatch table */ | 336 | /* Setup the device dispatch table */ |
415 | dev_ctx->device.release = vmbus_bus_release; | 337 | dev_ctx->device.release = vmbus_bus_release; |
416 | 338 | ||
417 | /* Setup the bus as root device */ | 339 | /* Setup the bus as root device */ |
418 | ret = device_register(&dev_ctx->device); | 340 | ret = device_register(&dev_ctx->device); |
419 | if (ret) | 341 | if (ret) { |
420 | { | 342 | DPRINT_ERR(VMBUS_DRV, |
421 | DPRINT_ERR(VMBUS_DRV, "ERROR - Unable to register vmbus root device"); | 343 | "ERROR - Unable to register vmbus root device"); |
422 | 344 | ||
423 | free_irq(vmbus_irq, NULL); | 345 | free_irq(vmbus_irq, NULL); |
424 | bus_unregister(&vmbus_drv_ctx->bus); | 346 | bus_unregister(&vmbus_drv_ctx->bus); |
@@ -436,20 +358,17 @@ cleanup: | |||
436 | return ret; | 358 | return ret; |
437 | } | 359 | } |
438 | 360 | ||
439 | 361 | /** | |
440 | /*++ | 362 | * vmbus_bus_exit - Terminate the vmbus driver. |
441 | 363 | * | |
442 | Name: vmbus_bus_exit() | 364 | * This routine is opposite of vmbus_bus_init() |
443 | 365 | */ | |
444 | Desc: Terminate the vmbus driver. This routine is opposite of vmbus_bus_init() | ||
445 | |||
446 | --*/ | ||
447 | static void vmbus_bus_exit(void) | 366 | static void vmbus_bus_exit(void) |
448 | { | 367 | { |
449 | struct vmbus_driver *vmbus_drv_obj = &g_vmbus_drv.drv_obj; | 368 | struct vmbus_driver *vmbus_drv_obj = &g_vmbus_drv.drv_obj; |
450 | struct vmbus_driver_context *vmbus_drv_ctx=&g_vmbus_drv; | 369 | struct vmbus_driver_context *vmbus_drv_ctx = &g_vmbus_drv; |
451 | 370 | ||
452 | struct device_context *dev_ctx=&g_vmbus_drv.device_ctx; | 371 | struct device_context *dev_ctx = &g_vmbus_drv.device_ctx; |
453 | 372 | ||
454 | DPRINT_ENTER(VMBUS_DRV); | 373 | DPRINT_ENTER(VMBUS_DRV); |
455 | 374 | ||
@@ -475,21 +394,18 @@ static void vmbus_bus_exit(void) | |||
475 | return; | 394 | return; |
476 | } | 395 | } |
477 | 396 | ||
478 | /*++ | 397 | /** |
479 | 398 | * vmbus_child_driver_register - Register a vmbus's child driver | |
480 | Name: vmbus_child_driver_register() | 399 | */ |
481 | 400 | int vmbus_child_driver_register(struct driver_context *driver_ctx) | |
482 | Desc: Register a vmbus's child driver | ||
483 | |||
484 | --*/ | ||
485 | int vmbus_child_driver_register(struct driver_context* driver_ctx) | ||
486 | { | 401 | { |
487 | struct vmbus_driver *vmbus_drv_obj = &g_vmbus_drv.drv_obj; | 402 | struct vmbus_driver *vmbus_drv_obj = &g_vmbus_drv.drv_obj; |
488 | int ret; | 403 | int ret; |
489 | 404 | ||
490 | DPRINT_ENTER(VMBUS_DRV); | 405 | DPRINT_ENTER(VMBUS_DRV); |
491 | 406 | ||
492 | DPRINT_INFO(VMBUS_DRV, "child driver (%p) registering - name %s", driver_ctx, driver_ctx->driver.name); | 407 | DPRINT_INFO(VMBUS_DRV, "child driver (%p) registering - name %s", |
408 | driver_ctx, driver_ctx->driver.name); | ||
493 | 409 | ||
494 | /* The child driver on this vmbus */ | 410 | /* The child driver on this vmbus */ |
495 | driver_ctx->driver.bus = &g_vmbus_drv.bus; | 411 | driver_ctx->driver.bus = &g_vmbus_drv.bus; |
@@ -502,21 +418,17 @@ int vmbus_child_driver_register(struct driver_context* driver_ctx) | |||
502 | 418 | ||
503 | return ret; | 419 | return ret; |
504 | } | 420 | } |
505 | |||
506 | EXPORT_SYMBOL(vmbus_child_driver_register); | 421 | EXPORT_SYMBOL(vmbus_child_driver_register); |
507 | 422 | ||
508 | /*++ | 423 | /** |
509 | 424 | * vmbus_child_driver_unregister Unregister a vmbus's child driver | |
510 | Name: vmbus_child_driver_unregister() | 425 | */ |
511 | 426 | void vmbus_child_driver_unregister(struct driver_context *driver_ctx) | |
512 | Desc: Unregister a vmbus's child driver | ||
513 | |||
514 | --*/ | ||
515 | void vmbus_child_driver_unregister(struct driver_context* driver_ctx) | ||
516 | { | 427 | { |
517 | DPRINT_ENTER(VMBUS_DRV); | 428 | DPRINT_ENTER(VMBUS_DRV); |
518 | 429 | ||
519 | DPRINT_INFO(VMBUS_DRV, "child driver (%p) unregistering - name %s", driver_ctx, driver_ctx->driver.name); | 430 | DPRINT_INFO(VMBUS_DRV, "child driver (%p) unregistering - name %s", |
431 | driver_ctx, driver_ctx->driver.name); | ||
520 | 432 | ||
521 | driver_unregister(&driver_ctx->driver); | 433 | driver_unregister(&driver_ctx->driver); |
522 | 434 | ||
@@ -524,47 +436,37 @@ void vmbus_child_driver_unregister(struct driver_context* driver_ctx) | |||
524 | 436 | ||
525 | DPRINT_EXIT(VMBUS_DRV); | 437 | DPRINT_EXIT(VMBUS_DRV); |
526 | } | 438 | } |
527 | |||
528 | EXPORT_SYMBOL(vmbus_child_driver_unregister); | 439 | EXPORT_SYMBOL(vmbus_child_driver_unregister); |
529 | 440 | ||
530 | /*++ | 441 | /** |
531 | 442 | * vmbus_get_interface - Get the vmbus channel interface. | |
532 | Name: vmbus_get_interface() | 443 | * |
533 | 444 | * This is invoked by child/client driver that sits above vmbus | |
534 | Desc: Get the vmbus channel interface. This is invoked by child/client driver that sits | 445 | */ |
535 | above vmbus | ||
536 | --*/ | ||
537 | void vmbus_get_interface(struct vmbus_channel_interface *interface) | 446 | void vmbus_get_interface(struct vmbus_channel_interface *interface) |
538 | { | 447 | { |
539 | struct vmbus_driver *vmbus_drv_obj = &g_vmbus_drv.drv_obj; | 448 | struct vmbus_driver *vmbus_drv_obj = &g_vmbus_drv.drv_obj; |
540 | 449 | ||
541 | vmbus_drv_obj->GetChannelInterface(interface); | 450 | vmbus_drv_obj->GetChannelInterface(interface); |
542 | } | 451 | } |
543 | |||
544 | EXPORT_SYMBOL(vmbus_get_interface); | 452 | EXPORT_SYMBOL(vmbus_get_interface); |
545 | 453 | ||
546 | 454 | /** | |
547 | /*++ | 455 | * vmbus_child_device_get_info - Get the vmbus child device info. |
548 | 456 | * | |
549 | Name: vmbus_child_device_get_info() | 457 | * This is invoked to display various device attributes in sysfs. |
550 | 458 | */ | |
551 | Desc: Get the vmbus child device info. This is invoked to display various device attributes in sysfs. | 459 | static void vmbus_child_device_get_info(struct hv_device *device_obj, |
552 | --*/ | 460 | struct hv_device_info *device_info) |
553 | static void vmbus_child_device_get_info(struct hv_device *device_obj, struct hv_device_info *device_info) | ||
554 | { | 461 | { |
555 | struct vmbus_driver *vmbus_drv_obj = &g_vmbus_drv.drv_obj; | 462 | struct vmbus_driver *vmbus_drv_obj = &g_vmbus_drv.drv_obj; |
556 | 463 | ||
557 | vmbus_drv_obj->GetChannelInfo(device_obj, device_info); | 464 | vmbus_drv_obj->GetChannelInfo(device_obj, device_info); |
558 | } | 465 | } |
559 | 466 | ||
560 | 467 | /** | |
561 | /*++ | 468 | * vmbus_child_device_create - Creates and registers a new child device on the vmbus. |
562 | 469 | */ | |
563 | Name: vmbus_child_device_create() | ||
564 | |||
565 | Desc: Creates and registers a new child device on the vmbus. | ||
566 | |||
567 | --*/ | ||
568 | static struct hv_device *vmbus_child_device_create(struct hv_guid *type, | 470 | static struct hv_device *vmbus_child_device_create(struct hv_guid *type, |
569 | struct hv_guid *instance, | 471 | struct hv_guid *instance, |
570 | void *context) | 472 | void *context) |
@@ -576,31 +478,38 @@ static struct hv_device *vmbus_child_device_create(struct hv_guid *type, | |||
576 | 478 | ||
577 | /* Allocate the new child device */ | 479 | /* Allocate the new child device */ |
578 | child_device_ctx = kzalloc(sizeof(struct device_context), GFP_KERNEL); | 480 | child_device_ctx = kzalloc(sizeof(struct device_context), GFP_KERNEL); |
579 | if (!child_device_ctx) | 481 | if (!child_device_ctx) { |
580 | { | 482 | DPRINT_ERR(VMBUS_DRV, |
581 | DPRINT_ERR(VMBUS_DRV, "unable to allocate device_context for child device"); | 483 | "unable to allocate device_context for child device"); |
582 | DPRINT_EXIT(VMBUS_DRV); | 484 | DPRINT_EXIT(VMBUS_DRV); |
583 | 485 | ||
584 | return NULL; | 486 | return NULL; |
585 | } | 487 | } |
586 | 488 | ||
587 | DPRINT_DBG(VMBUS_DRV, "child device (%p) allocated - " | 489 | DPRINT_DBG(VMBUS_DRV, "child device (%p) allocated - " |
588 | "type {%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}," | 490 | "type {%02x%02x%02x%02x-%02x%02x-%02x%02x-" |
589 | "id {%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}", | 491 | "%02x%02x%02x%02x%02x%02x%02x%02x}," |
492 | "id {%02x%02x%02x%02x-%02x%02x-%02x%02x-" | ||
493 | "%02x%02x%02x%02x%02x%02x%02x%02x}", | ||
590 | &child_device_ctx->device, | 494 | &child_device_ctx->device, |
591 | type->data[3], type->data[2], type->data[1], type->data[0], | 495 | type->data[3], type->data[2], type->data[1], type->data[0], |
592 | type->data[5], type->data[4], type->data[7], type->data[6], | 496 | type->data[5], type->data[4], type->data[7], type->data[6], |
593 | type->data[8], type->data[9], type->data[10], type->data[11], | 497 | type->data[8], type->data[9], type->data[10], type->data[11], |
594 | type->data[12], type->data[13], type->data[14], type->data[15], | 498 | type->data[12], type->data[13], type->data[14], type->data[15], |
595 | instance->data[3], instance->data[2], instance->data[1], instance->data[0], | 499 | instance->data[3], instance->data[2], |
596 | instance->data[5], instance->data[4], instance->data[7], instance->data[6], | 500 | instance->data[1], instance->data[0], |
597 | instance->data[8], instance->data[9], instance->data[10], instance->data[11], | 501 | instance->data[5], instance->data[4], |
598 | instance->data[12], instance->data[13], instance->data[14], instance->data[15]); | 502 | instance->data[7], instance->data[6], |
503 | instance->data[8], instance->data[9], | ||
504 | instance->data[10], instance->data[11], | ||
505 | instance->data[12], instance->data[13], | ||
506 | instance->data[14], instance->data[15]); | ||
599 | 507 | ||
600 | child_device_obj = &child_device_ctx->device_obj; | 508 | child_device_obj = &child_device_ctx->device_obj; |
601 | child_device_obj->context = context; | 509 | child_device_obj->context = context; |
602 | memcpy(&child_device_obj->deviceType, &type, sizeof(struct hv_guid)); | 510 | memcpy(&child_device_obj->deviceType, &type, sizeof(struct hv_guid)); |
603 | memcpy(&child_device_obj->deviceInstance, &instance, sizeof(struct hv_guid)); | 511 | memcpy(&child_device_obj->deviceInstance, &instance, |
512 | sizeof(struct hv_guid)); | ||
604 | 513 | ||
605 | memcpy(&child_device_ctx->class_id, &type, sizeof(struct hv_guid)); | 514 | memcpy(&child_device_ctx->class_id, &type, sizeof(struct hv_guid)); |
606 | memcpy(&child_device_ctx->device_id, &instance, sizeof(struct hv_guid)); | 515 | memcpy(&child_device_ctx->device_id, &instance, sizeof(struct hv_guid)); |
@@ -610,53 +519,59 @@ static struct hv_device *vmbus_child_device_create(struct hv_guid *type, | |||
610 | return child_device_obj; | 519 | return child_device_obj; |
611 | } | 520 | } |
612 | 521 | ||
613 | /*++ | 522 | /** |
614 | 523 | * vmbus_child_device_register - Register the child device on the specified bus | |
615 | Name: vmbus_child_device_register() | 524 | */ |
616 | 525 | static int vmbus_child_device_register(struct hv_device *root_device_obj, | |
617 | Desc: Register the child device on the specified bus | 526 | struct hv_device *child_device_obj) |
618 | |||
619 | --*/ | ||
620 | static int vmbus_child_device_register(struct hv_device *root_device_obj, struct hv_device *child_device_obj) | ||
621 | { | 527 | { |
622 | int ret=0; | 528 | int ret = 0; |
623 | struct device_context *root_device_ctx = to_device_context(root_device_obj); | 529 | struct device_context *root_device_ctx = |
624 | struct device_context *child_device_ctx = to_device_context(child_device_obj); | 530 | to_device_context(root_device_obj); |
531 | struct device_context *child_device_ctx = | ||
532 | to_device_context(child_device_obj); | ||
625 | static atomic_t device_num = ATOMIC_INIT(0); | 533 | static atomic_t device_num = ATOMIC_INIT(0); |
626 | 534 | ||
627 | DPRINT_ENTER(VMBUS_DRV); | 535 | DPRINT_ENTER(VMBUS_DRV); |
628 | 536 | ||
629 | DPRINT_DBG(VMBUS_DRV, "child device (%p) registering", child_device_ctx); | 537 | DPRINT_DBG(VMBUS_DRV, "child device (%p) registering", |
538 | child_device_ctx); | ||
630 | 539 | ||
631 | /* Make sure we are not registered already */ | 540 | /* Make sure we are not registered already */ |
632 | 541 | if (strlen(dev_name(&child_device_ctx->device)) != 0) { | |
633 | if (strlen(dev_name(&child_device_ctx->device)) != 0) | 542 | DPRINT_ERR(VMBUS_DRV, |
634 | { | 543 | "child device (%p) already registered - busid %s", |
635 | DPRINT_ERR(VMBUS_DRV, "child device (%p) already registered - busid %s", child_device_ctx, dev_name(&child_device_ctx->device)); | 544 | child_device_ctx, |
545 | dev_name(&child_device_ctx->device)); | ||
636 | 546 | ||
637 | ret = -1; | 547 | ret = -1; |
638 | goto Cleanup; | 548 | goto Cleanup; |
639 | } | 549 | } |
640 | 550 | ||
641 | /* Set the device bus id. Otherwise, device_register()will fail. */ | 551 | /* Set the device bus id. Otherwise, device_register()will fail. */ |
642 | dev_set_name(&child_device_ctx->device, "vmbus_0_%d", atomic_inc_return(&device_num)); | 552 | dev_set_name(&child_device_ctx->device, "vmbus_0_%d", |
553 | atomic_inc_return(&device_num)); | ||
643 | 554 | ||
644 | /* The new device belongs to this bus */ | 555 | /* The new device belongs to this bus */ |
645 | child_device_ctx->device.bus = &g_vmbus_drv.bus; /* device->dev.bus; */ | 556 | child_device_ctx->device.bus = &g_vmbus_drv.bus; /* device->dev.bus; */ |
646 | child_device_ctx->device.parent = &root_device_ctx->device; | 557 | child_device_ctx->device.parent = &root_device_ctx->device; |
647 | child_device_ctx->device.release = vmbus_device_release; | 558 | child_device_ctx->device.release = vmbus_device_release; |
648 | 559 | ||
649 | /* Register with the LDM. This will kick off the driver/device binding...which will */ | 560 | /* |
650 | /* eventually call vmbus_match() and vmbus_probe() */ | 561 | * Register with the LDM. This will kick off the driver/device |
562 | * binding...which will eventually call vmbus_match() and vmbus_probe() | ||
563 | */ | ||
651 | ret = device_register(&child_device_ctx->device); | 564 | ret = device_register(&child_device_ctx->device); |
652 | 565 | ||
653 | /* vmbus_probe() error does not get propergate to device_register(). */ | 566 | /* vmbus_probe() error does not get propergate to device_register(). */ |
654 | ret = child_device_ctx->probe_error; | 567 | ret = child_device_ctx->probe_error; |
655 | 568 | ||
656 | if (ret) | 569 | if (ret) |
657 | DPRINT_ERR(VMBUS_DRV, "unable to register child device (%p)", &child_device_ctx->device); | 570 | DPRINT_ERR(VMBUS_DRV, "unable to register child device (%p)", |
571 | &child_device_ctx->device); | ||
658 | else | 572 | else |
659 | DPRINT_INFO(VMBUS_DRV, "child device (%p) registered", &child_device_ctx->device); | 573 | DPRINT_INFO(VMBUS_DRV, "child device (%p) registered", |
574 | &child_device_ctx->device); | ||
660 | 575 | ||
661 | Cleanup: | 576 | Cleanup: |
662 | DPRINT_EXIT(VMBUS_DRV); | 577 | DPRINT_EXIT(VMBUS_DRV); |
@@ -664,38 +579,33 @@ Cleanup: | |||
664 | return ret; | 579 | return ret; |
665 | } | 580 | } |
666 | 581 | ||
667 | /*++ | 582 | /** |
668 | 583 | * vmbus_child_device_unregister - Remove the specified child device from the vmbus. | |
669 | Name: vmbus_child_device_unregister() | 584 | */ |
670 | |||
671 | Desc: Remove the specified child device from the vmbus. | ||
672 | |||
673 | --*/ | ||
674 | static void vmbus_child_device_unregister(struct hv_device *device_obj) | 585 | static void vmbus_child_device_unregister(struct hv_device *device_obj) |
675 | { | 586 | { |
676 | struct device_context *device_ctx = to_device_context(device_obj); | 587 | struct device_context *device_ctx = to_device_context(device_obj); |
677 | 588 | ||
678 | DPRINT_ENTER(VMBUS_DRV); | 589 | DPRINT_ENTER(VMBUS_DRV); |
679 | 590 | ||
680 | DPRINT_INFO(VMBUS_DRV, "unregistering child device (%p)", &device_ctx->device); | 591 | DPRINT_INFO(VMBUS_DRV, "unregistering child device (%p)", |
592 | &device_ctx->device); | ||
681 | 593 | ||
682 | /* Kick off the process of unregistering the device. */ | 594 | /* |
683 | /* This will call vmbus_remove() and eventually vmbus_device_release() */ | 595 | * Kick off the process of unregistering the device. |
596 | * This will call vmbus_remove() and eventually vmbus_device_release() | ||
597 | */ | ||
684 | device_unregister(&device_ctx->device); | 598 | device_unregister(&device_ctx->device); |
685 | 599 | ||
686 | DPRINT_INFO(VMBUS_DRV, "child device (%p) unregistered", &device_ctx->device); | 600 | DPRINT_INFO(VMBUS_DRV, "child device (%p) unregistered", |
601 | &device_ctx->device); | ||
687 | 602 | ||
688 | DPRINT_EXIT(VMBUS_DRV); | 603 | DPRINT_EXIT(VMBUS_DRV); |
689 | } | 604 | } |
690 | 605 | ||
691 | 606 | /** | |
692 | /*++ | 607 | * vmbus_child_device_destroy - Destroy the specified child device on the vmbus. |
693 | 608 | */ | |
694 | Name: vmbus_child_device_destroy() | ||
695 | |||
696 | Desc: Destroy the specified child device on the vmbus. | ||
697 | |||
698 | --*/ | ||
699 | static void vmbus_child_device_destroy(struct hv_device *device_obj) | 609 | static void vmbus_child_device_destroy(struct hv_device *device_obj) |
700 | { | 610 | { |
701 | DPRINT_ENTER(VMBUS_DRV); | 611 | DPRINT_ENTER(VMBUS_DRV); |
@@ -703,66 +613,83 @@ static void vmbus_child_device_destroy(struct hv_device *device_obj) | |||
703 | DPRINT_EXIT(VMBUS_DRV); | 613 | DPRINT_EXIT(VMBUS_DRV); |
704 | } | 614 | } |
705 | 615 | ||
706 | /*++ | 616 | /** |
707 | 617 | * vmbus_uevent - add uevent for our device | |
708 | Name: vmbus_uevent() | 618 | * |
709 | 619 | * This routine is invoked when a device is added or removed on the vmbus to | |
710 | Desc: This routine is invoked when a device is added or removed on the vmbus to generate a uevent to udev in the | 620 | * generate a uevent to udev in the userspace. The udev will then look at its |
711 | userspace. The udev will then look at its rule and the uevent generated here to load the appropriate driver | 621 | * rule and the uevent generated here to load the appropriate driver |
712 | 622 | */ | |
713 | --*/ | ||
714 | static int vmbus_uevent(struct device *device, struct kobj_uevent_env *env) | 623 | static int vmbus_uevent(struct device *device, struct kobj_uevent_env *env) |
715 | { | 624 | { |
716 | struct device_context *device_ctx = device_to_device_context(device); | 625 | struct device_context *device_ctx = device_to_device_context(device); |
717 | int i=0; | 626 | int i = 0; |
718 | int len=0; | 627 | int len = 0; |
719 | int ret; | 628 | int ret; |
720 | 629 | ||
721 | DPRINT_ENTER(VMBUS_DRV); | 630 | DPRINT_ENTER(VMBUS_DRV); |
722 | 631 | ||
723 | DPRINT_INFO(VMBUS_DRV, "generating uevent - VMBUS_DEVICE_CLASS_GUID={%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}", | 632 | DPRINT_INFO(VMBUS_DRV, "generating uevent - VMBUS_DEVICE_CLASS_GUID={" |
724 | device_ctx->class_id.data[3], device_ctx->class_id.data[2], | 633 | "%02x%02x%02x%02x-%02x%02x-%02x%02x-" |
725 | device_ctx->class_id.data[1], device_ctx->class_id.data[0], | 634 | "%02x%02x%02x%02x%02x%02x%02x%02x}", |
726 | device_ctx->class_id.data[5], device_ctx->class_id.data[4], | 635 | device_ctx->class_id.data[3], device_ctx->class_id.data[2], |
727 | device_ctx->class_id.data[7], device_ctx->class_id.data[6], | 636 | device_ctx->class_id.data[1], device_ctx->class_id.data[0], |
728 | device_ctx->class_id.data[8], device_ctx->class_id.data[9], | 637 | device_ctx->class_id.data[5], device_ctx->class_id.data[4], |
729 | device_ctx->class_id.data[10], device_ctx->class_id.data[11], | 638 | device_ctx->class_id.data[7], device_ctx->class_id.data[6], |
730 | device_ctx->class_id.data[12], device_ctx->class_id.data[13], | 639 | device_ctx->class_id.data[8], device_ctx->class_id.data[9], |
731 | device_ctx->class_id.data[14], device_ctx->class_id.data[15]); | 640 | device_ctx->class_id.data[10], |
641 | device_ctx->class_id.data[11], | ||
642 | device_ctx->class_id.data[12], | ||
643 | device_ctx->class_id.data[13], | ||
644 | device_ctx->class_id.data[14], | ||
645 | device_ctx->class_id.data[15]); | ||
732 | 646 | ||
733 | env->envp_idx = i; | 647 | env->envp_idx = i; |
734 | env->buflen = len; | 648 | env->buflen = len; |
735 | ret = add_uevent_var(env, | 649 | ret = add_uevent_var(env, "VMBUS_DEVICE_CLASS_GUID={" |
736 | "VMBUS_DEVICE_CLASS_GUID={%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}", | 650 | "%02x%02x%02x%02x-%02x%02x-%02x%02x-" |
737 | device_ctx->class_id.data[3], device_ctx->class_id.data[2], | 651 | "%02x%02x%02x%02x%02x%02x%02x%02x}", |
738 | device_ctx->class_id.data[1], device_ctx->class_id.data[0], | 652 | device_ctx->class_id.data[3], |
739 | device_ctx->class_id.data[5], device_ctx->class_id.data[4], | 653 | device_ctx->class_id.data[2], |
740 | device_ctx->class_id.data[7], device_ctx->class_id.data[6], | 654 | device_ctx->class_id.data[1], |
741 | device_ctx->class_id.data[8], device_ctx->class_id.data[9], | 655 | device_ctx->class_id.data[0], |
742 | device_ctx->class_id.data[10], device_ctx->class_id.data[11], | 656 | device_ctx->class_id.data[5], |
743 | device_ctx->class_id.data[12], device_ctx->class_id.data[13], | 657 | device_ctx->class_id.data[4], |
744 | device_ctx->class_id.data[14], device_ctx->class_id.data[15]); | 658 | device_ctx->class_id.data[7], |
659 | device_ctx->class_id.data[6], | ||
660 | device_ctx->class_id.data[8], | ||
661 | device_ctx->class_id.data[9], | ||
662 | device_ctx->class_id.data[10], | ||
663 | device_ctx->class_id.data[11], | ||
664 | device_ctx->class_id.data[12], | ||
665 | device_ctx->class_id.data[13], | ||
666 | device_ctx->class_id.data[14], | ||
667 | device_ctx->class_id.data[15]); | ||
745 | 668 | ||
746 | if (ret) | 669 | if (ret) |
747 | { | ||
748 | return ret; | 670 | return ret; |
749 | } | ||
750 | |||
751 | ret = add_uevent_var(env, | ||
752 | "VMBUS_DEVICE_DEVICE_GUID={%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}", | ||
753 | device_ctx->device_id.data[3], device_ctx->device_id.data[2], | ||
754 | device_ctx->device_id.data[1], device_ctx->device_id.data[0], | ||
755 | device_ctx->device_id.data[5], device_ctx->device_id.data[4], | ||
756 | device_ctx->device_id.data[7], device_ctx->device_id.data[6], | ||
757 | device_ctx->device_id.data[8], device_ctx->device_id.data[9], | ||
758 | device_ctx->device_id.data[10], device_ctx->device_id.data[11], | ||
759 | device_ctx->device_id.data[12], device_ctx->device_id.data[13], | ||
760 | device_ctx->device_id.data[14], device_ctx->device_id.data[15]); | ||
761 | 671 | ||
672 | ret = add_uevent_var(env, "VMBUS_DEVICE_DEVICE_GUID={" | ||
673 | "%02x%02x%02x%02x-%02x%02x-%02x%02x-" | ||
674 | "%02x%02x%02x%02x%02x%02x%02x%02x}", | ||
675 | device_ctx->device_id.data[3], | ||
676 | device_ctx->device_id.data[2], | ||
677 | device_ctx->device_id.data[1], | ||
678 | device_ctx->device_id.data[0], | ||
679 | device_ctx->device_id.data[5], | ||
680 | device_ctx->device_id.data[4], | ||
681 | device_ctx->device_id.data[7], | ||
682 | device_ctx->device_id.data[6], | ||
683 | device_ctx->device_id.data[8], | ||
684 | device_ctx->device_id.data[9], | ||
685 | device_ctx->device_id.data[10], | ||
686 | device_ctx->device_id.data[11], | ||
687 | device_ctx->device_id.data[12], | ||
688 | device_ctx->device_id.data[13], | ||
689 | device_ctx->device_id.data[14], | ||
690 | device_ctx->device_id.data[15]); | ||
762 | if (ret) | 691 | if (ret) |
763 | { | ||
764 | return ret; | 692 | return ret; |
765 | } | ||
766 | 693 | ||
767 | env->envp[env->envp_idx] = NULL; | 694 | env->envp[env->envp_idx] = NULL; |
768 | 695 | ||
@@ -771,29 +698,32 @@ static int vmbus_uevent(struct device *device, struct kobj_uevent_env *env) | |||
771 | return 0; | 698 | return 0; |
772 | } | 699 | } |
773 | 700 | ||
774 | /*++ | 701 | /** |
775 | 702 | * vmbus_match - Attempt to match the specified device to the specified driver | |
776 | Name: vmbus_match() | 703 | */ |
777 | |||
778 | Desc: Attempt to match the specified device to the specified driver | ||
779 | |||
780 | --*/ | ||
781 | static int vmbus_match(struct device *device, struct device_driver *driver) | 704 | static int vmbus_match(struct device *device, struct device_driver *driver) |
782 | { | 705 | { |
783 | int match=0; | 706 | int match = 0; |
784 | struct driver_context *driver_ctx = driver_to_driver_context(driver); | 707 | struct driver_context *driver_ctx = driver_to_driver_context(driver); |
785 | struct device_context *device_ctx = device_to_device_context(device); | 708 | struct device_context *device_ctx = device_to_device_context(device); |
786 | 709 | ||
787 | DPRINT_ENTER(VMBUS_DRV); | 710 | DPRINT_ENTER(VMBUS_DRV); |
788 | 711 | ||
789 | /* We found our driver ? */ | 712 | /* We found our driver ? */ |
790 | if (memcmp(&device_ctx->class_id, &driver_ctx->class_id, sizeof(struct hv_guid)) == 0) | 713 | if (memcmp(&device_ctx->class_id, &driver_ctx->class_id, |
791 | { | 714 | sizeof(struct hv_guid)) == 0) { |
792 | /* !! NOTE: The driver_ctx is not a vmbus_drv_ctx. We typecast it here to access the */ | 715 | /* |
793 | /* struct hv_driver field */ | 716 | * !! NOTE: The driver_ctx is not a vmbus_drv_ctx. We typecast |
794 | struct vmbus_driver_context *vmbus_drv_ctx = (struct vmbus_driver_context*)driver_ctx; | 717 | * it here to access the struct hv_driver field |
718 | */ | ||
719 | struct vmbus_driver_context *vmbus_drv_ctx = | ||
720 | (struct vmbus_driver_context *)driver_ctx; | ||
721 | |||
795 | device_ctx->device_obj.Driver = &vmbus_drv_ctx->drv_obj.Base; | 722 | device_ctx->device_obj.Driver = &vmbus_drv_ctx->drv_obj.Base; |
796 | DPRINT_INFO(VMBUS_DRV, "device object (%p) set to driver object (%p)", &device_ctx->device_obj, device_ctx->device_obj.Driver); | 723 | DPRINT_INFO(VMBUS_DRV, |
724 | "device object (%p) set to driver object (%p)", | ||
725 | &device_ctx->device_obj, | ||
726 | device_ctx->device_obj.Driver); | ||
797 | 727 | ||
798 | match = 1; | 728 | match = 1; |
799 | } | 729 | } |
@@ -803,62 +733,58 @@ static int vmbus_match(struct device *device, struct device_driver *driver) | |||
803 | return match; | 733 | return match; |
804 | } | 734 | } |
805 | 735 | ||
806 | 736 | /** | |
807 | /*++ | 737 | * vmbus_probe_failed_cb - Callback when a driver probe failed in vmbus_probe() |
808 | 738 | * | |
809 | Name: vmbus_probe_failed_cb() | 739 | * We need a callback because we cannot invoked device_unregister() inside |
810 | 740 | * vmbus_probe() since vmbus_probe() may be invoked inside device_register() | |
811 | Desc: Callback when a driver probe failed in vmbus_probe(). We need a callback because | 741 | * i.e. we cannot call device_unregister() inside device_register() |
812 | we cannot invoked device_unregister() inside vmbus_probe() since vmbus_probe() may be | 742 | */ |
813 | invoked inside device_register() i.e. we cannot call device_unregister() inside | ||
814 | device_register() | ||
815 | --*/ | ||
816 | static void vmbus_probe_failed_cb(struct work_struct *context) | 743 | static void vmbus_probe_failed_cb(struct work_struct *context) |
817 | { | 744 | { |
818 | struct device_context *device_ctx = (struct device_context*)context; | 745 | struct device_context *device_ctx = (struct device_context *)context; |
819 | |||
820 | 746 | ||
821 | DPRINT_ENTER(VMBUS_DRV); | 747 | DPRINT_ENTER(VMBUS_DRV); |
822 | 748 | ||
823 | /* Kick off the process of unregistering the device. */ | 749 | /* |
824 | /* This will call vmbus_remove() and eventually vmbus_device_release() */ | 750 | * Kick off the process of unregistering the device. |
751 | * This will call vmbus_remove() and eventually vmbus_device_release() | ||
752 | */ | ||
825 | device_unregister(&device_ctx->device); | 753 | device_unregister(&device_ctx->device); |
826 | 754 | ||
827 | /* put_device(&device_ctx->device); */ | 755 | /* put_device(&device_ctx->device); */ |
828 | DPRINT_EXIT(VMBUS_DRV); | 756 | DPRINT_EXIT(VMBUS_DRV); |
829 | } | 757 | } |
830 | 758 | ||
831 | 759 | /** | |
832 | /*++ | 760 | * vmbus_probe - Add the new vmbus's child device |
833 | 761 | */ | |
834 | Name: vmbus_probe() | ||
835 | |||
836 | Desc: Add the new vmbus's child device | ||
837 | |||
838 | --*/ | ||
839 | static int vmbus_probe(struct device *child_device) | 762 | static int vmbus_probe(struct device *child_device) |
840 | { | 763 | { |
841 | int ret=0; | 764 | int ret = 0; |
842 | struct driver_context *driver_ctx = driver_to_driver_context(child_device->driver); | 765 | struct driver_context *driver_ctx = |
843 | struct device_context *device_ctx = device_to_device_context(child_device); | 766 | driver_to_driver_context(child_device->driver); |
767 | struct device_context *device_ctx = | ||
768 | device_to_device_context(child_device); | ||
844 | 769 | ||
845 | DPRINT_ENTER(VMBUS_DRV); | 770 | DPRINT_ENTER(VMBUS_DRV); |
846 | 771 | ||
847 | /* Let the specific open-source driver handles the probe if it can */ | 772 | /* Let the specific open-source driver handles the probe if it can */ |
848 | if (driver_ctx->probe) | 773 | if (driver_ctx->probe) { |
849 | { | ||
850 | ret = device_ctx->probe_error = driver_ctx->probe(child_device); | 774 | ret = device_ctx->probe_error = driver_ctx->probe(child_device); |
851 | if (ret != 0) | 775 | if (ret != 0) { |
852 | { | 776 | DPRINT_ERR(VMBUS_DRV, "probe() failed for device %s " |
853 | DPRINT_ERR(VMBUS_DRV, "probe() failed for device %s (%p) on driver %s (%d)...", dev_name(child_device), child_device, child_device->driver->name, ret); | 777 | "(%p) on driver %s (%d)...", |
854 | 778 | dev_name(child_device), child_device, | |
855 | INIT_WORK(&device_ctx->probe_failed_work_item, vmbus_probe_failed_cb); | 779 | child_device->driver->name, ret); |
780 | |||
781 | INIT_WORK(&device_ctx->probe_failed_work_item, | ||
782 | vmbus_probe_failed_cb); | ||
856 | schedule_work(&device_ctx->probe_failed_work_item); | 783 | schedule_work(&device_ctx->probe_failed_work_item); |
857 | } | 784 | } |
858 | } | 785 | } else { |
859 | else | 786 | DPRINT_ERR(VMBUS_DRV, "probe() method not set for driver - %s", |
860 | { | 787 | child_device->driver->name); |
861 | DPRINT_ERR(VMBUS_DRV, "probe() method not set for driver - %s", child_device->driver->name); | ||
862 | ret = -1; | 788 | ret = -1; |
863 | } | 789 | } |
864 | 790 | ||
@@ -866,61 +792,51 @@ static int vmbus_probe(struct device *child_device) | |||
866 | return ret; | 792 | return ret; |
867 | } | 793 | } |
868 | 794 | ||
869 | 795 | /** | |
870 | /*++ | 796 | * vmbus_remove - Remove a vmbus device |
871 | 797 | */ | |
872 | Name: vmbus_remove() | ||
873 | |||
874 | Desc: Remove a vmbus device | ||
875 | |||
876 | --*/ | ||
877 | static int vmbus_remove(struct device *child_device) | 798 | static int vmbus_remove(struct device *child_device) |
878 | { | 799 | { |
879 | int ret=0; | 800 | int ret; |
880 | struct driver_context *driver_ctx; | 801 | struct driver_context *driver_ctx; |
881 | 802 | ||
882 | DPRINT_ENTER(VMBUS_DRV); | 803 | DPRINT_ENTER(VMBUS_DRV); |
883 | 804 | ||
884 | /* Special case root bus device */ | 805 | /* Special case root bus device */ |
885 | if (child_device->parent == NULL) | 806 | if (child_device->parent == NULL) { |
886 | { | 807 | /* |
887 | /* No-op since it is statically defined and handle in vmbus_bus_exit() */ | 808 | * No-op since it is statically defined and handle in |
809 | * vmbus_bus_exit() | ||
810 | */ | ||
888 | DPRINT_EXIT(VMBUS_DRV); | 811 | DPRINT_EXIT(VMBUS_DRV); |
889 | return 0; | 812 | return 0; |
890 | } | 813 | } |
891 | 814 | ||
892 | if (child_device->driver) | 815 | if (child_device->driver) { |
893 | { | ||
894 | driver_ctx = driver_to_driver_context(child_device->driver); | 816 | driver_ctx = driver_to_driver_context(child_device->driver); |
895 | 817 | ||
896 | /* Let the specific open-source driver handles the removal if it can */ | 818 | /* |
897 | if (driver_ctx->remove) | 819 | * Let the specific open-source driver handles the removal if |
898 | { | 820 | * it can |
821 | */ | ||
822 | if (driver_ctx->remove) { | ||
899 | ret = driver_ctx->remove(child_device); | 823 | ret = driver_ctx->remove(child_device); |
900 | } | 824 | } else { |
901 | else | 825 | DPRINT_ERR(VMBUS_DRV, |
902 | { | 826 | "remove() method not set for driver - %s", |
903 | DPRINT_ERR(VMBUS_DRV, "remove() method not set for driver - %s", child_device->driver->name); | 827 | child_device->driver->name); |
904 | ret = -1; | 828 | ret = -1; |
905 | } | 829 | } |
906 | } | 830 | } |
907 | else | ||
908 | { | ||
909 | |||
910 | } | ||
911 | 831 | ||
912 | DPRINT_EXIT(VMBUS_DRV); | 832 | DPRINT_EXIT(VMBUS_DRV); |
913 | 833 | ||
914 | return 0; | 834 | return 0; |
915 | } | 835 | } |
916 | 836 | ||
917 | /*++ | 837 | /** |
918 | 838 | * vmbus_shutdown - Shutdown a vmbus device | |
919 | Name: vmbus_shutdown() | 839 | */ |
920 | |||
921 | Desc: Shutdown a vmbus device | ||
922 | |||
923 | --*/ | ||
924 | static void vmbus_shutdown(struct device *child_device) | 840 | static void vmbus_shutdown(struct device *child_device) |
925 | { | 841 | { |
926 | struct driver_context *driver_ctx; | 842 | struct driver_context *driver_ctx; |
@@ -928,16 +844,17 @@ static void vmbus_shutdown(struct device *child_device) | |||
928 | DPRINT_ENTER(VMBUS_DRV); | 844 | DPRINT_ENTER(VMBUS_DRV); |
929 | 845 | ||
930 | /* Special case root bus device */ | 846 | /* Special case root bus device */ |
931 | if (child_device->parent == NULL) | 847 | if (child_device->parent == NULL) { |
932 | { | 848 | /* |
933 | /* No-op since it is statically defined and handle in vmbus_bus_exit() */ | 849 | * No-op since it is statically defined and handle in |
850 | * vmbus_bus_exit() | ||
851 | */ | ||
934 | DPRINT_EXIT(VMBUS_DRV); | 852 | DPRINT_EXIT(VMBUS_DRV); |
935 | return; | 853 | return; |
936 | } | 854 | } |
937 | 855 | ||
938 | /* The device may not be attached yet */ | 856 | /* The device may not be attached yet */ |
939 | if (!child_device->driver) | 857 | if (!child_device->driver) { |
940 | { | ||
941 | DPRINT_EXIT(VMBUS_DRV); | 858 | DPRINT_EXIT(VMBUS_DRV); |
942 | return; | 859 | return; |
943 | } | 860 | } |
@@ -946,22 +863,16 @@ static void vmbus_shutdown(struct device *child_device) | |||
946 | 863 | ||
947 | /* Let the specific open-source driver handles the removal if it can */ | 864 | /* Let the specific open-source driver handles the removal if it can */ |
948 | if (driver_ctx->shutdown) | 865 | if (driver_ctx->shutdown) |
949 | { | ||
950 | driver_ctx->shutdown(child_device); | 866 | driver_ctx->shutdown(child_device); |
951 | } | ||
952 | 867 | ||
953 | DPRINT_EXIT(VMBUS_DRV); | 868 | DPRINT_EXIT(VMBUS_DRV); |
954 | 869 | ||
955 | return; | 870 | return; |
956 | } | 871 | } |
957 | 872 | ||
958 | /*++ | 873 | /** |
959 | 874 | * vmbus_bus_release - Final callback release of the vmbus root device | |
960 | Name: vmbus_bus_release() | 875 | */ |
961 | |||
962 | Desc: Final callback release of the vmbus root device | ||
963 | |||
964 | --*/ | ||
965 | static void vmbus_bus_release(struct device *device) | 876 | static void vmbus_bus_release(struct device *device) |
966 | { | 877 | { |
967 | DPRINT_ENTER(VMBUS_DRV); | 878 | DPRINT_ENTER(VMBUS_DRV); |
@@ -973,13 +884,9 @@ static void vmbus_bus_release(struct device *device) | |||
973 | DPRINT_EXIT(VMBUS_DRV); | 884 | DPRINT_EXIT(VMBUS_DRV); |
974 | } | 885 | } |
975 | 886 | ||
976 | /*++ | 887 | /** |
977 | 888 | * vmbus_device_release - Final callback release of the vmbus child device | |
978 | Name: vmbus_device_release() | 889 | */ |
979 | |||
980 | Desc: Final callback release of the vmbus child device | ||
981 | |||
982 | --*/ | ||
983 | static void vmbus_device_release(struct device *device) | 890 | static void vmbus_device_release(struct device *device) |
984 | { | 891 | { |
985 | struct device_context *device_ctx = device_to_device_context(device); | 892 | struct device_context *device_ctx = device_to_device_context(device); |
@@ -990,19 +897,14 @@ static void vmbus_device_release(struct device *device) | |||
990 | kfree(device_ctx); | 897 | kfree(device_ctx); |
991 | 898 | ||
992 | /* !!DO NOT REFERENCE device_ctx anymore at this point!! */ | 899 | /* !!DO NOT REFERENCE device_ctx anymore at this point!! */ |
993 | |||
994 | DPRINT_EXIT(VMBUS_DRV); | 900 | DPRINT_EXIT(VMBUS_DRV); |
995 | 901 | ||
996 | return; | 902 | return; |
997 | } | 903 | } |
998 | 904 | ||
999 | /*++ | 905 | /** |
1000 | 906 | * vmbus_msg_dpc - Tasklet routine to handle hypervisor messages | |
1001 | Name: vmbus_msg_dpc() | 907 | */ |
1002 | |||
1003 | Desc: Tasklet routine to handle hypervisor messages | ||
1004 | |||
1005 | --*/ | ||
1006 | static void vmbus_msg_dpc(unsigned long data) | 908 | static void vmbus_msg_dpc(unsigned long data) |
1007 | { | 909 | { |
1008 | struct vmbus_driver *vmbus_drv_obj = (struct vmbus_driver *)data; | 910 | struct vmbus_driver *vmbus_drv_obj = (struct vmbus_driver *)data; |
@@ -1017,13 +919,9 @@ static void vmbus_msg_dpc(unsigned long data) | |||
1017 | DPRINT_EXIT(VMBUS_DRV); | 919 | DPRINT_EXIT(VMBUS_DRV); |
1018 | } | 920 | } |
1019 | 921 | ||
1020 | /*++ | 922 | /** |
1021 | 923 | * vmbus_msg_dpc - Tasklet routine to handle hypervisor events | |
1022 | Name: vmbus_msg_dpc() | 924 | */ |
1023 | |||
1024 | Desc: Tasklet routine to handle hypervisor events | ||
1025 | |||
1026 | --*/ | ||
1027 | static void vmbus_event_dpc(unsigned long data) | 925 | static void vmbus_event_dpc(unsigned long data) |
1028 | { | 926 | { |
1029 | struct vmbus_driver *vmbus_drv_obj = (struct vmbus_driver *)data; | 927 | struct vmbus_driver *vmbus_drv_obj = (struct vmbus_driver *)data; |
@@ -1038,17 +936,10 @@ static void vmbus_event_dpc(unsigned long data) | |||
1038 | DPRINT_EXIT(VMBUS_DRV); | 936 | DPRINT_EXIT(VMBUS_DRV); |
1039 | } | 937 | } |
1040 | 938 | ||
1041 | /*++ | 939 | static irqreturn_t vmbus_isr(int irq, void *dev_id) |
1042 | |||
1043 | Name: vmbus_msg_dpc() | ||
1044 | |||
1045 | Desc: ISR routine | ||
1046 | |||
1047 | --*/ | ||
1048 | static irqreturn_t vmbus_isr(int irq, void* dev_id) | ||
1049 | { | 940 | { |
1050 | int ret=0; | ||
1051 | struct vmbus_driver *vmbus_driver_obj = &g_vmbus_drv.drv_obj; | 941 | struct vmbus_driver *vmbus_driver_obj = &g_vmbus_drv.drv_obj; |
942 | int ret; | ||
1052 | 943 | ||
1053 | DPRINT_ENTER(VMBUS_DRV); | 944 | DPRINT_ENTER(VMBUS_DRV); |
1054 | 945 | ||
@@ -1058,48 +949,31 @@ static irqreturn_t vmbus_isr(int irq, void* dev_id) | |||
1058 | ret = vmbus_driver_obj->OnIsr(&vmbus_driver_obj->Base); | 949 | ret = vmbus_driver_obj->OnIsr(&vmbus_driver_obj->Base); |
1059 | 950 | ||
1060 | /* Schedules a dpc if necessary */ | 951 | /* Schedules a dpc if necessary */ |
1061 | if (ret > 0) | 952 | if (ret > 0) { |
1062 | { | 953 | if (test_bit(0, (unsigned long *)&ret)) |
1063 | if (test_bit(0, (unsigned long*)&ret)) | ||
1064 | { | ||
1065 | tasklet_schedule(&g_vmbus_drv.msg_dpc); | 954 | tasklet_schedule(&g_vmbus_drv.msg_dpc); |
1066 | } | ||
1067 | 955 | ||
1068 | if (test_bit(1, (unsigned long*)&ret)) | 956 | if (test_bit(1, (unsigned long *)&ret)) |
1069 | { | ||
1070 | tasklet_schedule(&g_vmbus_drv.event_dpc); | 957 | tasklet_schedule(&g_vmbus_drv.event_dpc); |
1071 | } | ||
1072 | 958 | ||
1073 | DPRINT_EXIT(VMBUS_DRV); | 959 | DPRINT_EXIT(VMBUS_DRV); |
1074 | return IRQ_HANDLED; | 960 | return IRQ_HANDLED; |
1075 | } | 961 | } else { |
1076 | else | ||
1077 | { | ||
1078 | DPRINT_EXIT(VMBUS_DRV); | 962 | DPRINT_EXIT(VMBUS_DRV); |
1079 | return IRQ_NONE; | 963 | return IRQ_NONE; |
1080 | } | 964 | } |
1081 | } | 965 | } |
1082 | 966 | ||
1083 | MODULE_LICENSE("GPL"); | ||
1084 | |||
1085 | |||
1086 | /*++ | ||
1087 | |||
1088 | Name: vmbus_init() | ||
1089 | |||
1090 | Desc: Main vmbus driver entry routine | ||
1091 | |||
1092 | --*/ | ||
1093 | static int __init vmbus_init(void) | 967 | static int __init vmbus_init(void) |
1094 | { | 968 | { |
1095 | int ret=0; | 969 | int ret = 0; |
1096 | 970 | ||
1097 | DPRINT_ENTER(VMBUS_DRV); | 971 | DPRINT_ENTER(VMBUS_DRV); |
1098 | 972 | ||
1099 | DPRINT_INFO(VMBUS_DRV, | 973 | DPRINT_INFO(VMBUS_DRV, |
1100 | "Vmbus initializing.... current log level 0x%x (%x,%x)", | 974 | "Vmbus initializing.... current log level 0x%x (%x,%x)", |
1101 | vmbus_loglevel, HIWORD(vmbus_loglevel), LOWORD(vmbus_loglevel)); | 975 | vmbus_loglevel, HIWORD(vmbus_loglevel), LOWORD(vmbus_loglevel)); |
1102 | /* Todo: it is used for loglevel, to be ported to new kernel. */ | 976 | /* Todo: it is used for loglevel, to be ported to new kernel. */ |
1103 | 977 | ||
1104 | ret = vmbus_bus_init(VmbusInitialize); | 978 | ret = vmbus_bus_init(VmbusInitialize); |
1105 | 979 | ||
@@ -1107,29 +981,19 @@ static int __init vmbus_init(void) | |||
1107 | return ret; | 981 | return ret; |
1108 | } | 982 | } |
1109 | 983 | ||
1110 | |||
1111 | |||
1112 | /*++ | ||
1113 | |||
1114 | Name: vmbus_init() | ||
1115 | |||
1116 | Desc: Main vmbus driver exit routine | ||
1117 | |||
1118 | --*/ | ||
1119 | static void __exit vmbus_exit(void) | 984 | static void __exit vmbus_exit(void) |
1120 | { | 985 | { |
1121 | DPRINT_ENTER(VMBUS_DRV); | 986 | DPRINT_ENTER(VMBUS_DRV); |
1122 | 987 | ||
1123 | vmbus_bus_exit(); | 988 | vmbus_bus_exit(); |
1124 | /* Todo: it is used for loglevel, to be ported to new kernel. */ | 989 | /* Todo: it is used for loglevel, to be ported to new kernel. */ |
1125 | DPRINT_EXIT(VMBUS_DRV); | 990 | DPRINT_EXIT(VMBUS_DRV); |
1126 | |||
1127 | return; | 991 | return; |
1128 | } | 992 | } |
1129 | 993 | ||
994 | MODULE_LICENSE("GPL"); | ||
1130 | module_param(vmbus_irq, int, S_IRUGO); | 995 | module_param(vmbus_irq, int, S_IRUGO); |
1131 | module_param(vmbus_loglevel, int, S_IRUGO); | 996 | module_param(vmbus_loglevel, int, S_IRUGO); |
1132 | 997 | ||
1133 | module_init(vmbus_init); | 998 | module_init(vmbus_init); |
1134 | module_exit(vmbus_exit); | 999 | module_exit(vmbus_exit); |
1135 | /* eof */ | ||