Skip to contentSkip to conversation

cardbus/hotplugging still broken in 2.5.56

BUG Jens Taprogge 5 participants 5 messages Jan 15, 2003 Pcmcia

lore
Share & tools
lore
#0 lore raw

The cardbus problems are caused by

[email protected] 2002-11-25 18:31:10-08:00 [email protected]

as far as I can tell.

pci_enable_device() will fail at least on i386 (see arch/i386/pci/i386.c: pcibios_enable_resource (line 260)) if the resources have not been assigned previously. Hence the ostensible resource collisions.

The attached patch should fix the problem.

I have send the patch to Dave Jones some time ago but did not hear from him yet.

I am not subscribed to the list so please cc me on replys.

Jens

Signature · 1 line
Jens Taprogge
drivers/pcmcia/cardbus.c +23 -6
diff -ur linux-2.5.51/drivers/pcmcia/cardbus.c linux-2.5.51_jlt/drivers/pcmcia/cardbus.c
@@ -229,6 +229,17 @@
     
 =====================================================================*/
 
+static void cb_free_resources(struct pci_dev *dev)
+{
+	int i;
+
+	for (i = 0; i < 7; i++) {
+		struct resource *res = dev->resource + i;
+		if (res->parent)
+			release_resource(res);
+	}
+}
+
 int cb_alloc(socket_info_t * s)
 {
 	struct pci_bus *bus;
@@ -283,25 +294,31 @@
 		dev->hdr_type = hdr & 0x7f;
 
 		pci_setup_device(dev);
-		if (pci_enable_device(dev))
-			continue;
 
 		strcpy(dev->dev.bus_id, dev->slot_name);
 
 		/* FIXME: Do we need to enable the expansion ROM? */
 		for (r = 0; r < 7; r++) {
 			struct resource *res = dev->resource + r;
-			if (res->flags)
-				pci_assign_resource(dev, r);
+			if (res->flags && pci_assign_resource(dev, r) < 0) {
+				cb_free_resources(dev);
+				continue;
+			}
 		}
 
 		/* Does this function have an interrupt at all? */
 		pci_readb(dev, PCI_INTERRUPT_PIN, &irq_pin);
-		if (irq_pin) {
+		if (irq_pin)
 			dev->irq = irq;
-			pci_writeb(dev, PCI_INTERRUPT_LINE, irq);
+
+		if (pci_enable_device(dev)) {
+			cb_free_resources(dev);
+			continue;
 		}
 
+		if (irq_pin)
+			pci_writeb(dev, PCI_INTERRUPT_LINE, irq);
+		
 		device_register(&dev->dev);
 		pci_insert_device(dev, bus);
 	}
#1 lore raw
Quoted 11 lines · Jens Taprogge

The cardbus problems are caused by

[email protected] 2002-11-25 18:31:10-08:00 [email protected]

as far as I can tell.

pci_enable_device() will fail at least on i386 (see arch/i386/pci/i386.c: pcibios_enable_resource (line 260)) if the resources have not been assigned previously. Hence the ostensible resource collisions.

Quoted 6 lines

The attached patch should fix the problem.

I have send the patch to Dave Jones some time ago but did not hear from him yet.

I am not subscribed to the list so please cc me on replys.

Thanks. Your patch fixed the cardbus hotplug issue perfectly on my laptop. It survives multiple insert/eject cycles without any problems.

The patch posted by Yaacov Akiba Slama today also fixed cardbus hotplug for me, but with his patch the kernel still prints "PCI: No IRQ known for interrupt pin A of device xx:xx.x. Please try using pci=biosirq" when the cardbus NIC is inserted; Jens Taprogge's patch silenced that warning.

/Mikael

#2 lore raw

Can you test the enclosed patch. It seems to be both simple and to resolve the resource collisions and the "No IRQ known" problem. I added a smal comment (and modified another) so future janitors won't move pci_enable above pci_assign_resource again. If everyone is ok, I can send it to Linus for inclusion in BK (I have the green light of Dave Jones).

Thanks,
Yaacov Akiba Slama

Quoted 22 lines · Mikael Pettersson
Quoted 11 lines · Jens Taprogge

The cardbus problems are caused by

[email protected] 2002-11-25 18:31:10-08:00 [email protected]

as far as I can tell.

pci_enable_device() will fail at least on i386 (see arch/i386/pci/i386.c: pcibios_enable_resource (line 260)) if the resources have not been assigned previously. Hence the ostensible resource collisions.

Quoted 6 lines

The attached patch should fix the problem.

I have send the patch to Dave Jones some time ago but did not hear from him yet.

I am not subscribed to the list so please cc me on replys.

Thanks. Your patch fixed the cardbus hotplug issue perfectly on my laptop. It survives multiple insert/eject cycles without any problems.

Quoted 9 lines

The patch posted by Yaacov Akiba Slama today also fixed cardbus hotplug for me, but with his patch the kernel still prints "PCI: No IRQ known for interrupt pin A of device xx:xx.x. Please try using pci=biosirq" when the cardbus NIC is inserted; Jens Taprogge's patch silenced that warning.

/Mikael

pcmcia/cardbus.c renamed from pcmcia/cardbus.c.original +11 -7
@@ -285,25 +285,29 @@
 		dev->dev.dma_mask = &dev->dma_mask;
 
 		pci_setup_device(dev);
-		if (pci_enable_device(dev))
-			continue;
 
 		strcpy(dev->dev.bus_id, dev->slot_name);
 
-		/* FIXME: Do we need to enable the expansion ROM? */
+		/* We need to assign resources for expansion ROM. */
 		for (r = 0; r < 7; r++) {
 			struct resource *res = dev->resource + r;
-			if (res->flags)
+			if (!res->start && res->end)
 				pci_assign_resource(dev, r);
 		}
 
 		/* Does this function have an interrupt at all? */
 		pci_readb(dev, PCI_INTERRUPT_PIN, &irq_pin);
-		if (irq_pin) {
+		if (irq_pin)
 			dev->irq = irq;
-			pci_writeb(dev, PCI_INTERRUPT_LINE, irq);
-		}
+		
+		/* pci_enable_device needs to be called after pci_assign_resource */
+		/* because it returns an error if (!res->start && res->end).      */
+		if (pci_enable_device(dev))
+			continue;
 
+		if (irq_pin)
+			pci_writeb(dev, PCI_INTERRUPT_LINE, irq);
+		
 		device_register(&dev->dev);
 		pci_insert_device(dev, bus);
 	}
#3 lore raw

You are not freeing the possibly already allocated resources in case of a failure of either pci_assign_resource() or pca_enable_device(). In fact you are not even checking if pci_assign_resource() fails. That seems wrong to me.

Btw.: who is in charge of this file? Dave Jones? Is someone working on integrating it with PCI Hotplug?

Best Regards
Jens

Quoted 83 lines · Yaacov Akiba Slama

Can you test the enclosed patch. It seems to be both simple and to resolve the resource collisions and the "No IRQ known" problem. I added a smal comment (and modified another) so future janitors won't move pci_enable above pci_assign_resource again.
If everyone is ok, I can send it to Linus for inclusion in BK (I have the green light of Dave Jones).

Thanks,
Yaacov Akiba Slama

Quoted 31 lines · Mikael Pettersson
Quoted 11 lines · Jens Taprogge

The cardbus problems are caused by

[email protected] 2002-11-25 18:31:10-08:00 [email protected]

as far as I can tell.

pci_enable_device() will fail at least on i386 (see arch/i386/pci/i386.c: pcibios_enable_resource (line 260)) if the resources have not been assigned previously. Hence the ostensible resource collisions.

Quoted 6 lines

The attached patch should fix the problem.

I have send the patch to Dave Jones some time ago but did not hear from him yet.

I am not subscribed to the list so please cc me on replys.

Thanks. Your patch fixed the cardbus hotplug issue perfectly on my laptop. It survives multiple insert/eject cycles without any problems.

The patch posted by Yaacov Akiba Slama today also fixed cardbus hotplug for me, but with his patch the kernel still prints "PCI: No IRQ known for interrupt pin A of device xx:xx.x. Please try using pci=biosirq" when the cardbus NIC is inserted; Jens Taprogge's patch silenced that warning.

/Mikael

pcmcia/cardbus.c renamed from pcmcia/cardbus.c.original +11 -7
@@ -285,25 +285,29 @@
 		dev->dev.dma_mask = &dev->dma_mask;
 
 		pci_setup_device(dev);
-		if (pci_enable_device(dev))
-			continue;
 
 		strcpy(dev->dev.bus_id, dev->slot_name);
 
-		/* FIXME: Do we need to enable the expansion ROM? */
+		/* We need to assign resources for expansion ROM. */
 		for (r = 0; r < 7; r++) {
 			struct resource *res = dev->resource + r;
-			if (res->flags)
+			if (!res->start && res->end)
 				pci_assign_resource(dev, r);
 		}
 
 		/* Does this function have an interrupt at all? */
 		pci_readb(dev, PCI_INTERRUPT_PIN, &irq_pin);
-		if (irq_pin) {
+		if (irq_pin)
 			dev->irq = irq;
-			pci_writeb(dev, PCI_INTERRUPT_LINE, irq);
-		}
+		
+		/* pci_enable_device needs to be called after pci_assign_resource */
+		/* because it returns an error if (!res->start && res->end).      */
+		if (pci_enable_device(dev))
+			continue;
 
+		if (irq_pin)
+			pci_writeb(dev, PCI_INTERRUPT_LINE, irq);
+		
 		device_register(&dev->dev);
 		pci_insert_device(dev, bus);
 	}
Signature · 1 line
Jens Taprogge
#4 lore raw
Quoted 6 lines · Jens Taprogge

You are not freeing the possibly already allocated resources in case of a failure of either pci_assign_resource() or pca_enable_device(). In fact you are not even checking if pci_assign_resource() fails. That seems wrong to me.

Btw.: who is in charge of this file? Dave Jones?

Not me, more likely David Hinds.

Dave

Signature · 2 lines
| Dave Jones.        http://www.codemonkey.org.uk
| SuSE Labs