+ bugfix-pci-legacy-i-o-port-free-driver.patch added to -mm tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The patch titled

     bugfix: PCI legacy I/O port free driver

has been added to the -mm tree.  Its filename is

     bugfix-pci-legacy-i-o-port-free-driver.patch

See http://www.zip.com.au/~akpm/linux/patches/stuff/added-to-mm.txt to find
out what to do about this

------------------------------------------------------
Subject: bugfix: PCI legacy I/O port free driver
From: Kenji Kaneshige <kaneshige.kenji@xxxxxxxxxxxxxx>


Fix the bug that pci_release_regions() doesn't work when it is called after
pci_disable_device(), which is reported at:

    http://marc.theaimsgroup.com/?l=linux-kernel&m=114914585213991&w=2

The root cause of this bug is "PCI legacy I/O port free driver" patches had
been implemented with a wrong assumption that pci_release_regions() is
called before pci_disable_device(), while it should be called _after_
pci_disable_device().

To fix the bug, this patch makes the following changes:

    o Changed pci_request_regions()/pci_release_regions() not to refer
      bars_enabled bitmask.

    o Introduce new pci_request_selected_regions() and
      pci_release_selected_regions() for PCI legacy I/O port free
      drivers to request/release only the selected regions.

    o Added the description about pci_request_selected_regions() and
      pci_release_selected_regions().

    o Changed intel e1000 driver to use pci_request_selected_regions()
      and pci_release_selected_regions().

    o Changed Emulex lpfc driver to use pci_request_selected_regions()
      and pci_release_selected_regions().

Signed-off-by: Kenji Kaneshige <kaneshige.kenji@xxxxxxxxxxxxxx>
Cc: Greg KH <greg@xxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxx>
---

 Documentation/pci.txt          |    5 +-
 drivers/net/e1000/e1000_main.c |    7 +-
 drivers/pci/pci.c              |   77 ++++++++++++++++++-------------
 drivers/scsi/lpfc/lpfc_init.c  |    7 +-
 include/linux/pci.h            |    2 
 5 files changed, 60 insertions(+), 38 deletions(-)

diff -puN Documentation/pci.txt~bugfix-pci-legacy-i-o-port-free-driver Documentation/pci.txt
--- devel/Documentation/pci.txt~bugfix-pci-legacy-i-o-port-free-driver	2006-06-06 01:12:48.000000000 -0700
+++ devel-akpm/Documentation/pci.txt	2006-06-06 01:12:48.000000000 -0700
@@ -311,7 +311,10 @@ this on p.44, "IMPLEMENTATION NOTE".
 If your PCI device driver doesn't need I/O port resources assigned to
 I/O Port BARs, you should use pci_enable_device_bars() instead of
 pci_enable_device() in order not to enable I/O port regions for the
-corresponding devices.
+corresponding devices. In addition, you should use
+pci_request_selected_regions()/pci_release_selected_regions() instead
+of pci_request_regions()/pci_release_regions() in order not to
+request/release I/O port regions for the corresponding devices.
 
 [1] Some systems support 64KB I/O port space per PCI segment.
 [2] Some PCI-to-PCI bridges support optional 1KB aligned I/O base.
diff -puN drivers/net/e1000/e1000_main.c~bugfix-pci-legacy-i-o-port-free-driver drivers/net/e1000/e1000_main.c
--- devel/drivers/net/e1000/e1000_main.c~bugfix-pci-legacy-i-o-port-free-driver	2006-06-06 01:12:48.000000000 -0700
+++ devel-akpm/drivers/net/e1000/e1000_main.c	2006-06-06 01:12:48.000000000 -0700
@@ -616,7 +616,8 @@ e1000_probe(struct pci_dev *pdev,
 		pci_using_dac = 0;
 	}
 
-	if ((err = pci_request_regions(pdev, e1000_driver_name)))
+	err = pci_request_selected_regions(pdev, bars, e1000_driver_name);
+	if (err)
 		return err;
 
 	pci_set_master(pdev);
@@ -866,7 +867,7 @@ err_eeprom:
 err_ioremap:
 	free_netdev(netdev);
 err_alloc_etherdev:
-	pci_release_regions(pdev);
+	pci_release_selected_regions(pdev, bars);
 	return err;
 }
 
@@ -921,7 +922,7 @@ e1000_remove(struct pci_dev *pdev)
 #endif
 
 	iounmap(adapter->hw.hw_addr);
-	pci_release_regions(pdev);
+	pci_release_selected_regions(pdev, adapter->bars);
 
 	free_netdev(netdev);
 
diff -puN drivers/pci/pci.c~bugfix-pci-legacy-i-o-port-free-driver drivers/pci/pci.c
--- devel/drivers/pci/pci.c~bugfix-pci-legacy-i-o-port-free-driver	2006-06-06 01:12:48.000000000 -0700
+++ devel-akpm/drivers/pci/pci.c	2006-06-06 01:12:48.000000000 -0700
@@ -648,12 +648,6 @@ void pci_release_region(struct pci_dev *
 {
 	if (pci_resource_len(pdev, bar) == 0)
 		return;
-	if (!(pdev->bars_enabled & (1 << bar))) {
-		dev_warn(&pdev->dev,
-			 "Trying to release region #%d that is not enabled\n",
-			 bar + 1);
-		return;
-	}
 	if (pci_resource_flags(pdev, bar) & IORESOURCE_IO)
 		release_region(pci_resource_start(pdev, bar),
 				pci_resource_len(pdev, bar));
@@ -680,12 +674,7 @@ int pci_request_region(struct pci_dev *p
 {
 	if (pci_resource_len(pdev, bar) == 0)
 		return 0;
-	if (!(pdev->bars_enabled & (1 << bar))) {
-		dev_warn(&pdev->dev,
-			 "Trying to request region #%d that is not enabled\n",
-			 bar + 1);
-		goto err_out;
-	}
+
 	if (pci_resource_flags(pdev, bar) & IORESOURCE_IO) {
 		if (!request_region(pci_resource_start(pdev, bar),
 			    pci_resource_len(pdev, bar), res_name))
@@ -710,6 +699,47 @@ err_out:
 	return -EBUSY;
 }
 
+/**
+ * pci_release_selected_regions - Release selected PCI I/O and memory resources
+ * @pdev: PCI device whose resources were previously reserved
+ * @bars: Bitmask of BARs to be released
+ *
+ * Release selected PCI I/O and memory resources previously reserved.
+ * Call this function only after all use of the PCI regions has ceased.
+ */
+void pci_release_selected_regions(struct pci_dev *pdev, int bars)
+{
+	int i;
+
+	for (i = 0; i < 6; i++)
+		if (bars & (1 << i))
+			pci_release_region(pdev, i);
+}
+
+/**
+ * pci_request_selected_regions - Reserve selected PCI I/O and memory resources
+ * @pdev: PCI device whose resources are to be reserved
+ * @bars: Bitmask of BARs to be requested
+ * @res_name: Name to be associated with resource
+ */
+int pci_request_selected_regions(struct pci_dev *pdev, int bars,
+				 const char *res_name)
+{
+	int i;
+
+	for (i = 0; i < 6; i++)
+		if (bars & (1 << i))
+			if(pci_request_region(pdev, i, res_name))
+				goto err_out;
+	return 0;
+
+err_out:
+	while(--i >= 0)
+		if (bars & (1 << i))
+			pci_release_region(pdev, i);
+
+	return -EBUSY;
+}
 
 /**
  *	pci_release_regions - Release reserved PCI I/O and memory resources
@@ -722,11 +752,7 @@ err_out:
 
 void pci_release_regions(struct pci_dev *pdev)
 {
-	int i;
-	
-	for (i = 0; i < 6; i++)
-		if (pdev->bars_enabled & (1 << i))
-			pci_release_region(pdev, i);
+	pci_release_selected_regions(pdev, (1 << 6) - 1);
 }
 
 /**
@@ -744,20 +770,7 @@ void pci_release_regions(struct pci_dev 
  */
 int pci_request_regions(struct pci_dev *pdev, const char *res_name)
 {
-	int i;
-	
-	for (i = 0; i < 6; i++)
-		if (pdev->bars_enabled & (1 << i))
-			if(pci_request_region(pdev, i, res_name))
-				goto err_out;
-	return 0;
-
-err_out:
-	while(--i >= 0)
-		if (pdev->bars_enabled & (1 << i))
-			pci_release_region(pdev, i);
-		
-	return -EBUSY;
+	return pci_request_selected_regions(pdev, ((1 << 6) - 1), res_name);
 }
 
 /**
@@ -995,6 +1008,8 @@ EXPORT_SYMBOL(pci_release_regions);
 EXPORT_SYMBOL(pci_request_regions);
 EXPORT_SYMBOL(pci_release_region);
 EXPORT_SYMBOL(pci_request_region);
+EXPORT_SYMBOL(pci_release_selected_regions);
+EXPORT_SYMBOL(pci_request_selected_regions);
 EXPORT_SYMBOL(pci_set_master);
 EXPORT_SYMBOL(pci_set_mwi);
 EXPORT_SYMBOL(pci_clear_mwi);
diff -puN drivers/scsi/lpfc/lpfc_init.c~bugfix-pci-legacy-i-o-port-free-driver drivers/scsi/lpfc/lpfc_init.c
--- devel/drivers/scsi/lpfc/lpfc_init.c~bugfix-pci-legacy-i-o-port-free-driver	2006-06-06 01:12:48.000000000 -0700
+++ devel-akpm/drivers/scsi/lpfc/lpfc_init.c	2006-06-06 01:12:48.000000000 -0700
@@ -1429,7 +1429,7 @@ lpfc_pci_probe_one(struct pci_dev *pdev,
 
 	if (pci_enable_device_bars(pdev, bars))
 		goto out;
-	if (pci_request_regions(pdev, LPFC_DRIVER_NAME))
+	if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
 		goto out_disable_device;
 
 	host = scsi_host_alloc(&lpfc_template, sizeof (struct lpfc_hba));
@@ -1721,7 +1721,7 @@ out_put_host:
 	phba->host = NULL;
 	scsi_host_put(host);
 out_release_regions:
-	pci_release_regions(pdev);
+	pci_release_selected_regions(pdev, bars);
 out_disable_device:
 	pci_disable_device(pdev);
 out:
@@ -1735,6 +1735,7 @@ lpfc_pci_remove_one(struct pci_dev *pdev
 	struct Scsi_Host   *host = pci_get_drvdata(pdev);
 	struct lpfc_hba    *phba = (struct lpfc_hba *)host->hostdata;
 	unsigned long iflag;
+	int bars = pci_select_bars(pdev, IORESOURCE_MEM);
 
 	lpfc_free_sysfs_attr(phba);
 
@@ -1778,7 +1779,7 @@ lpfc_pci_remove_one(struct pci_dev *pdev
 	iounmap(phba->ctrl_regs_memmap_p);
 	iounmap(phba->slim_memmap_p);
 
-	pci_release_regions(phba->pcidev);
+	pci_release_selected_regions(phba->pcidev, bars);
 	pci_disable_device(phba->pcidev);
 
 	idr_remove(&lpfc_hba_index, phba->brd_no);
diff -puN include/linux/pci.h~bugfix-pci-legacy-i-o-port-free-driver include/linux/pci.h
--- devel/include/linux/pci.h~bugfix-pci-legacy-i-o-port-free-driver	2006-06-06 01:12:48.000000000 -0700
+++ devel-akpm/include/linux/pci.h	2006-06-06 01:12:48.000000000 -0700
@@ -531,6 +531,8 @@ int pci_request_regions(struct pci_dev *
 void pci_release_regions(struct pci_dev *);
 int pci_request_region(struct pci_dev *, int, const char *);
 void pci_release_region(struct pci_dev *, int);
+int pci_request_selected_regions(struct pci_dev *, int, const char *);
+void pci_release_selected_regions(struct pci_dev *, int);
 
 /* drivers/pci/bus.c */
 int pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
_

Patches currently in -mm which might be from kaneshige.kenji@xxxxxxxxxxxxxx are

acpi-memory-hotplug-cannot-manage-_crs-with-plural-resoureces.patch
bugfix-pci-legacy-i-o-port-free-driver.patch

-
To unsubscribe from this list: send the line "unsubscribe mm-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Kernel Newbies FAQ]     [Kernel Archive]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Photo]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]

  Powered by Linux