From: David Altobelli <david.altobelli@hpe.com>
Subject: [PATCH] hpilo: Add support for iLO5
Patch-mainline: Not yet, internal review
References: bsc#999101

Due to changes in iLO firmware a changes is needed for the hpilo
driver to function correctly on Gen10 platforms with iLO5 BMC.
Otherwise no HPE utilities which access /dev/hpilo/d0ccb* will work.
Although the kernel module loads fine, all open() generate EBUSY and
all read() read invalid data.

This patch adds the support for iLO5 by using BAR5 for CCB's.

Also the patch has a minor code refactoring to simplify the error code
handling.

Signed-off-by: David Altobelli <david.altobelli@hpe.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>

---

 drivers/misc/hpilo.c |   20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

--- a/drivers/misc/hpilo.c
+++ b/drivers/misc/hpilo.c
@@ -688,7 +688,9 @@ static void ilo_unmap_device(struct pci_
 
 static int __devinit ilo_map_device(struct pci_dev *pdev, struct ilo_hwinfo *hw)
 {
-	int error = -ENOMEM;
+	int bar;
+	unsigned long off;
+	unsigned long sz;
 
 	/* map the memory mapped i/o registers */
 	hw->mmio_vaddr = pci_iomap(pdev, 1, 0);
@@ -698,7 +700,17 @@ static int __devinit ilo_map_device(stru
 	}
 
 	/* map the adapter shared memory region */
-	hw->ram_vaddr = pci_iomap(pdev, 2, max_ccb * ILOHW_CCB_SZ);
+	if (pdev->subsystem_device == 0x00E4) {
+		bar = 5;
+		/* Last 8k is reserved for CCBs */
+		off = pci_resource_len(pdev, bar) - 0x2000;
+		sz = 0;
+	} else {
+		bar = 2;
+		off = 0;
+		sz = max_ccb * ILOHW_CCB_SZ;
+	}
+	hw->ram_vaddr = pci_iomap(pdev, bar, sz) + off;
 	if (hw->ram_vaddr == NULL) {
 		dev_err(&pdev->dev, "Error mapping shared mem\n");
 		goto mmio_free;
@@ -717,7 +729,7 @@ ram_free:
 mmio_free:
 	pci_iounmap(pdev, hw->mmio_vaddr);
 out:
-	return error;
+	return -ENOMEM;
 }
 
 static void ilo_remove(struct pci_dev *pdev)
@@ -899,7 +911,7 @@ static void __exit ilo_exit(void)
 	class_destroy(ilo_class);
 }
 
-MODULE_VERSION("1.4.1");
+MODULE_VERSION("1.5.0");
 MODULE_ALIAS(ILO_NAME);
 MODULE_DESCRIPTION(ILO_NAME);
 MODULE_AUTHOR("David Altobelli <david.altobelli@hp.com>");
