virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH ]:Staging: hv: Allocate the vmbus irq dynamically
@ 2011-02-15 15:15 K. Y. Srinivasan
  2011-02-15 15:59 ` Greg KH
  0 siblings, 1 reply; 32+ messages in thread
From: K. Y. Srinivasan @ 2011-02-15 15:15 UTC (permalink / raw)
  To: gregkh, linux-kernel, devel, virtualization
  Cc: K. Y. Srinivasan, Haiyang Zhang, Hank Janssen


Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Hank Janssen <hjanssen@microsoft.com>

---
 drivers/staging/hv/vmbus_drv.c |   49 +++++++++++++++++++++++++++------------
 1 files changed, 34 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/hv/vmbus_drv.c b/drivers/staging/hv/vmbus_drv.c
index 459c707..f279e6a 100644
--- a/drivers/staging/hv/vmbus_drv.c
+++ b/drivers/staging/hv/vmbus_drv.c
@@ -36,9 +36,7 @@
 #include "vmbus_private.h"
 
 
-/* FIXME! We need to do this dynamically for PIC and APIC system */
-#define VMBUS_IRQ		0x5
-#define VMBUS_IRQ_VECTOR	IRQ5_VECTOR
+static int vmbus_irq;
 
 /* Main vmbus driver data structure */
 struct vmbus_driver_context {
@@ -57,6 +55,25 @@ struct vmbus_driver_context {
 	struct vm_device device_ctx;
 };
 
+/*
+ * Find an un-used IRQ that the VMBUS can use. If none is available; return -1.
+ */
+
+static int vmbus_get_irq(void)
+{
+	unsigned int avail_irq_mask;
+	int irq = -1;
+	/*
+	 * Pick the first unused interrupt. HyperV can
+	 * interrupt us on any interrupt line we specify.
+	 */
+	avail_irq_mask = probe_irq_on();
+	if (avail_irq_mask != 0)
+		irq = ffs(avail_irq_mask);
+	probe_irq_off(avail_irq_mask);
+	return irq;
+}
+
 static int vmbus_match(struct device *device, struct device_driver *driver);
 static int vmbus_probe(struct device *device);
 static int vmbus_remove(struct device *device);
@@ -80,7 +97,6 @@ EXPORT_SYMBOL(vmbus_loglevel);
 	/* (ALL_MODULES << 16 | DEBUG_LVL_ENTEREXIT); */
 	/* (((VMBUS | VMBUS_DRV)<<16) | DEBUG_LVL_ENTEREXIT); */
 
-static int vmbus_irq = VMBUS_IRQ;
 
 /* Set up per device attributes in /sys/bus/vmbus/devices/<bus device> */
 static struct device_attribute vmbus_device_attrs[] = {
@@ -466,7 +482,7 @@ static int vmbus_bus_init(void)
 	struct hv_driver *driver = &vmbus_drv.drv_obj;
 	struct vm_device *dev_ctx = &vmbus_drv.device_ctx;
 	int ret;
-	unsigned int vector;
+	unsigned int vector, prev_irq = ~0;
 
 	DPRINT_INFO(VMBUS, "+++++++ HV Driver version = %s +++++++",
 		    HV_DRV_VERSION);
@@ -518,19 +534,23 @@ static int vmbus_bus_init(void)
 	}
 
 	/* Get the interrupt resource */
-	ret = request_irq(vmbus_irq, vmbus_isr, IRQF_SAMPLE_RANDOM,
-			  driver->name, NULL);
-
-	if (ret != 0) {
-		DPRINT_ERR(VMBUS_DRV, "ERROR - Unable to request IRQ %d",
-			   vmbus_irq);
-
+get_irq_again:
+	vmbus_irq = vmbus_get_irq();
+	if ((vmbus_irq < 0) || (prev_irq == vmbus_irq)) {
+		printk(KERN_WARNING "VMBUS_DRV: Failed to allocate IRQ\n");
 		bus_unregister(&vmbus_drv_ctx->bus);
-
 		ret = -1;
 		goto cleanup;
 	}
-	vector = VMBUS_IRQ_VECTOR;
+	prev_irq = vmbus_irq;
+
+	ret = request_irq(vmbus_irq, vmbus_isr, IRQF_SAMPLE_RANDOM,
+			  driver->name, NULL);
+
+	if (ret != 0)
+		goto get_irq_again;
+
+	vector = IRQ0_VECTOR + vmbus_irq;
 
 	DPRINT_INFO(VMBUS_DRV, "irq 0x%x vector 0x%x", vmbus_irq, vector);
 
@@ -1117,7 +1137,6 @@ MODULE_DEVICE_TABLE(pci, microsoft_hv_pci_table);
 
 MODULE_LICENSE("GPL");
 MODULE_VERSION(HV_DRV_VERSION);
-module_param(vmbus_irq, int, S_IRUGO);
 module_param(vmbus_loglevel, int, S_IRUGO);
 
 module_init(vmbus_init);
-- 
1.5.5.6

^ permalink raw reply related	[flat|nested] 32+ messages in thread
* [PATCH]: Staging: hv: Allocate the vmbus irq dynamically
@ 2011-02-15 19:55 K. Y. Srinivasan
  2011-02-18 21:14 ` Greg KH
  2011-02-19 10:23 ` Thomas Gleixner
  0 siblings, 2 replies; 32+ messages in thread
From: K. Y. Srinivasan @ 2011-02-15 19:55 UTC (permalink / raw)
  To: gregkh, linux-kernel, devel, virtualization
  Cc: K. Y. Srinivasan, Haiyang Zhang, Hank Janssen


Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Hank Janssen <hjanssen@microsoft.com>

---
 drivers/staging/hv/vmbus_drv.c |   72 +++++++++++++++++++++++++++++++---------
 1 files changed, 56 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/hv/vmbus_drv.c b/drivers/staging/hv/vmbus_drv.c
index 459c707..441ce85 100644
--- a/drivers/staging/hv/vmbus_drv.c
+++ b/drivers/staging/hv/vmbus_drv.c
@@ -36,9 +36,7 @@
 #include "vmbus_private.h"
 
 
-/* FIXME! We need to do this dynamically for PIC and APIC system */
-#define VMBUS_IRQ		0x5
-#define VMBUS_IRQ_VECTOR	IRQ5_VECTOR
+static int vmbus_irq;
 
 /* Main vmbus driver data structure */
 struct vmbus_driver_context {
@@ -57,6 +55,27 @@ struct vmbus_driver_context {
 	struct vm_device device_ctx;
 };
 
+/*
+ * Find an un-used IRQ that the VMBUS can use. If none is available;
+ * return -EBUSY.
+ */
+static int vmbus_get_irq(void)
+{
+	unsigned int avail_irq_mask;
+	int irq = -EBUSY;
+
+	/*
+	 * Pick the first unused interrupt. HyperV can
+	 * interrupt us on any interrupt line we specify.
+	 */
+
+	avail_irq_mask = probe_irq_on();
+	if (avail_irq_mask != 0)
+		irq = ffs(avail_irq_mask);
+	probe_irq_off(avail_irq_mask);
+	return irq;
+}
+
 static int vmbus_match(struct device *device, struct device_driver *driver);
 static int vmbus_probe(struct device *device);
 static int vmbus_remove(struct device *device);
@@ -80,7 +99,6 @@ EXPORT_SYMBOL(vmbus_loglevel);
 	/* (ALL_MODULES << 16 | DEBUG_LVL_ENTEREXIT); */
 	/* (((VMBUS | VMBUS_DRV)<<16) | DEBUG_LVL_ENTEREXIT); */
 
-static int vmbus_irq = VMBUS_IRQ;
 
 /* Set up per device attributes in /sys/bus/vmbus/devices/<bus device> */
 static struct device_attribute vmbus_device_attrs[] = {
@@ -467,6 +485,7 @@ static int vmbus_bus_init(void)
 	struct vm_device *dev_ctx = &vmbus_drv.device_ctx;
 	int ret;
 	unsigned int vector;
+	bool irq_assigned = false;
 
 	DPRINT_INFO(VMBUS, "+++++++ HV Driver version = %s +++++++",
 		    HV_DRV_VERSION);
@@ -517,20 +536,42 @@ static int vmbus_bus_init(void)
 		goto cleanup;
 	}
 
-	/* Get the interrupt resource */
-	ret = request_irq(vmbus_irq, vmbus_isr, IRQF_SAMPLE_RANDOM,
-			  driver->name, NULL);
-
-	if (ret != 0) {
-		DPRINT_ERR(VMBUS_DRV, "ERROR - Unable to request IRQ %d",
-			   vmbus_irq);
+	/*
+	 * Get an unused interrupt line and register our handler.
+	 * Since there is a window between getting an unused
+	 * interrupt line and registering our handler, we close
+	 * this window by repeating the sequence if we raced.
+	 * This loop will terminate under the following conditions:
+	 *
+	 * 1) If we succeed in registering our handler OR
+	 * 2) If there are no free interrupt lines for our use OR
+	 * 3) request_irq fails for reasons other than an irq collision
+	 */
+	while (!irq_assigned) {
+		vmbus_irq = vmbus_get_irq();
 
-		bus_unregister(&vmbus_drv_ctx->bus);
+		if (vmbus_irq < 0) {
+			bus_unregister(&vmbus_drv_ctx->bus);
+			ret = -EBUSY;
+			goto cleanup;
+		}
 
-		ret = -1;
-		goto cleanup;
+		ret = request_irq(vmbus_irq, vmbus_isr, IRQF_SAMPLE_RANDOM,
+			  driver->name, NULL);
+		switch (ret) {
+		case -EBUSY:
+			 /* We raced and lost; try again.*/
+			continue;
+		case 0:
+			irq_assigned = true;
+			break;
+		default:
+			/* Failed to request_irq; cleanup */
+			goto cleanup;
+		}
 	}
-	vector = VMBUS_IRQ_VECTOR;
+
+	vector = IRQ0_VECTOR + vmbus_irq;
 
 	DPRINT_INFO(VMBUS_DRV, "irq 0x%x vector 0x%x", vmbus_irq, vector);
 
@@ -1117,7 +1158,6 @@ MODULE_DEVICE_TABLE(pci, microsoft_hv_pci_table);
 
 MODULE_LICENSE("GPL");
 MODULE_VERSION(HV_DRV_VERSION);
-module_param(vmbus_irq, int, S_IRUGO);
 module_param(vmbus_loglevel, int, S_IRUGO);
 
 module_init(vmbus_init);
-- 
1.5.5.6

^ permalink raw reply related	[flat|nested] 32+ messages in thread
* [PATCH]: Staging: hv: Allocate the vmbus irq dynamically
@ 2011-02-19  1:26 K. Y. Srinivasan
  0 siblings, 0 replies; 32+ messages in thread
From: K. Y. Srinivasan @ 2011-02-19  1:26 UTC (permalink / raw)
  To: gregkh, linux-kernel, devel, virtualization
  Cc: K. Y. Srinivasan, Haiyang Zhang, Hank Janssen


Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Hank Janssen <hjanssen@microsoft.com>

---
 drivers/staging/hv/vmbus_drv.c |   72 +++++++++++++++++++++++++++++++---------
 1 files changed, 56 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/hv/vmbus_drv.c b/drivers/staging/hv/vmbus_drv.c
index 459c707..441ce85 100644
--- a/drivers/staging/hv/vmbus_drv.c
+++ b/drivers/staging/hv/vmbus_drv.c
@@ -36,9 +36,7 @@
 #include "vmbus_private.h"
 
 
-/* FIXME! We need to do this dynamically for PIC and APIC system */
-#define VMBUS_IRQ		0x5
-#define VMBUS_IRQ_VECTOR	IRQ5_VECTOR
+static int vmbus_irq;
 
 /* Main vmbus driver data structure */
 struct vmbus_driver_context {
@@ -57,6 +55,27 @@ struct vmbus_driver_context {
 	struct vm_device device_ctx;
 };
 
+/*
+ * Find an un-used IRQ that the VMBUS can use. If none is available;
+ * return -EBUSY.
+ */
+static int vmbus_get_irq(void)
+{
+	unsigned int avail_irq_mask;
+	int irq = -EBUSY;
+
+	/*
+	 * Pick the first unused interrupt. HyperV can
+	 * interrupt us on any interrupt line we specify.
+	 */
+
+	avail_irq_mask = probe_irq_on();
+	if (avail_irq_mask != 0)
+		irq = ffs(avail_irq_mask);
+	probe_irq_off(avail_irq_mask);
+	return irq;
+}
+
 static int vmbus_match(struct device *device, struct device_driver *driver);
 static int vmbus_probe(struct device *device);
 static int vmbus_remove(struct device *device);
@@ -80,7 +99,6 @@ EXPORT_SYMBOL(vmbus_loglevel);
 	/* (ALL_MODULES << 16 | DEBUG_LVL_ENTEREXIT); */
 	/* (((VMBUS | VMBUS_DRV)<<16) | DEBUG_LVL_ENTEREXIT); */
 
-static int vmbus_irq = VMBUS_IRQ;
 
 /* Set up per device attributes in /sys/bus/vmbus/devices/<bus device> */
 static struct device_attribute vmbus_device_attrs[] = {
@@ -467,6 +485,7 @@ static int vmbus_bus_init(void)
 	struct vm_device *dev_ctx = &vmbus_drv.device_ctx;
 	int ret;
 	unsigned int vector;
+	bool irq_assigned = false;
 
 	DPRINT_INFO(VMBUS, "+++++++ HV Driver version = %s +++++++",
 		    HV_DRV_VERSION);
@@ -517,20 +536,42 @@ static int vmbus_bus_init(void)
 		goto cleanup;
 	}
 
-	/* Get the interrupt resource */
-	ret = request_irq(vmbus_irq, vmbus_isr, IRQF_SAMPLE_RANDOM,
-			  driver->name, NULL);
-
-	if (ret != 0) {
-		DPRINT_ERR(VMBUS_DRV, "ERROR - Unable to request IRQ %d",
-			   vmbus_irq);
+	/*
+	 * Get an unused interrupt line and register our handler.
+	 * Since there is a window between getting an unused
+	 * interrupt line and registering our handler, we close
+	 * this window by repeating the sequence if we raced.
+	 * This loop will terminate under the following conditions:
+	 *
+	 * 1) If we succeed in registering our handler OR
+	 * 2) If there are no free interrupt lines for our use OR
+	 * 3) request_irq fails for reasons other than an irq collision
+	 */
+	while (!irq_assigned) {
+		vmbus_irq = vmbus_get_irq();
 
-		bus_unregister(&vmbus_drv_ctx->bus);
+		if (vmbus_irq < 0) {
+			bus_unregister(&vmbus_drv_ctx->bus);
+			ret = -EBUSY;
+			goto cleanup;
+		}
 
-		ret = -1;
-		goto cleanup;
+		ret = request_irq(vmbus_irq, vmbus_isr, IRQF_SAMPLE_RANDOM,
+			  driver->name, NULL);
+		switch (ret) {
+		case -EBUSY:
+			 /* We raced and lost; try again.*/
+			continue;
+		case 0:
+			irq_assigned = true;
+			break;
+		default:
+			/* Failed to request_irq; cleanup */
+			goto cleanup;
+		}
 	}
-	vector = VMBUS_IRQ_VECTOR;
+
+	vector = IRQ0_VECTOR + vmbus_irq;
 
 	DPRINT_INFO(VMBUS_DRV, "irq 0x%x vector 0x%x", vmbus_irq, vector);
 
@@ -1117,7 +1158,6 @@ MODULE_DEVICE_TABLE(pci, microsoft_hv_pci_table);
 
 MODULE_LICENSE("GPL");
 MODULE_VERSION(HV_DRV_VERSION);
-module_param(vmbus_irq, int, S_IRUGO);
 module_param(vmbus_loglevel, int, S_IRUGO);
 
 module_init(vmbus_init);
-- 
1.5.5.6

^ permalink raw reply related	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2011-02-23 19:22 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-15 15:15 [PATCH ]:Staging: hv: Allocate the vmbus irq dynamically K. Y. Srinivasan
2011-02-15 15:59 ` Greg KH
2011-02-15 16:53   ` KY Srinivasan
2011-02-15 16:59     ` Hank Janssen
2011-02-15 17:22       ` Greg KH
2011-02-15 17:28         ` Hank Janssen
2011-02-15 19:09         ` Hank Janssen
2011-02-15 19:33           ` Greg KH
2011-02-15 17:25     ` Greg KH
  -- strict thread matches above, loose matches on Subject: below --
2011-02-15 19:55 [PATCH]: Staging: " K. Y. Srinivasan
2011-02-18 21:14 ` Greg KH
2011-02-18 22:00   ` KY Srinivasan
2011-02-18 22:07     ` Greg KH
2011-02-18 22:16       ` KY Srinivasan
2011-02-18 22:29         ` Greg KH
2011-02-19  0:56           ` KY Srinivasan
2011-02-19  1:02             ` Greg KH
2011-02-19  1:19               ` KY Srinivasan
2011-02-19 10:23 ` Thomas Gleixner
2011-02-19 14:34   ` KY Srinivasan
2011-02-19 15:12     ` Thomas Gleixner
2011-02-19 16:46       ` KY Srinivasan
2011-02-20 16:15         ` Thomas Gleixner
2011-02-21  3:43           ` KY Srinivasan
2011-02-21  3:50             ` Greg KH
2011-02-21 11:02             ` Thomas Gleixner
2011-02-21 14:40               ` KY Srinivasan
2011-02-21 14:51                 ` Thomas Gleixner
2011-02-21 15:43                   ` Greg KH
2011-02-23 19:16                   ` Greg KH
2011-02-23 19:22                     ` KY Srinivasan
2011-02-19  1:26 K. Y. Srinivasan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).