Commit 783fa7311b2c639f39c6163f9fbb05253fb2d702
Committed by
James Bottomley
1 parent
a71d035de8
Exists in
master
and in
7 other branches
[SCSI] sym53c8xx: handle pci_iomap() failures
sym_init_device() doesn't check if pci_iomap() fails. It also tries to map device RAM without first checking FE_RAM. 1) Move some initialization from sym_init_device() to the top of sym2_probe(). 2) Rename sym_init_device() to sym_iomap_device(). 3) Call sym_iomap_device() after sym_check_supported() instead of before so that device->chip.features will be set. 4) Check FE_RAM in sym_iomap_device() before mapping RAM. 5) If sym_iomap_device() cannot map registers, then abort. 6) If sym_iomap_device() cannot map RAM, then fall back to not using RAM and continue. 7) Remove the check for FE_RAM in sym_attach() since dev->ram_base is now always set correctly. Signed-off-by: Tony Battersby <tonyb@cybernetics.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Showing 1 changed file with 36 additions and 26 deletions Side-by-side Diff
drivers/scsi/sym53c8xx_2/sym_glue.c
... | ... | @@ -1236,7 +1236,7 @@ |
1236 | 1236 | #endif /* SYM_LINUX_PROC_INFO_SUPPORT */ |
1237 | 1237 | |
1238 | 1238 | /* |
1239 | - * Free resources claimed by sym_init_device(). Note that | |
1239 | + * Free resources claimed by sym_iomap_device(). Note that | |
1240 | 1240 | * sym_free_resources() should be used instead of this function after calling |
1241 | 1241 | * sym_attach(). |
1242 | 1242 | */ |
1243 | 1243 | |
... | ... | @@ -1336,12 +1336,9 @@ |
1336 | 1336 | np->maxburst = dev->chip.burst_max; |
1337 | 1337 | np->myaddr = dev->host_id; |
1338 | 1338 | np->mmio_ba = (u32)dev->mmio_base; |
1339 | + np->ram_ba = (u32)dev->ram_base; | |
1339 | 1340 | np->s.ioaddr = dev->s.ioaddr; |
1340 | 1341 | np->s.ramaddr = dev->s.ramaddr; |
1341 | - if (!(np->features & FE_RAM)) | |
1342 | - dev->ram_base = 0; | |
1343 | - if (dev->ram_base) | |
1344 | - np->ram_ba = (u32)dev->ram_base; | |
1345 | 1342 | |
1346 | 1343 | /* |
1347 | 1344 | * Edit its name. |
1348 | 1345 | |
1349 | 1346 | |
1350 | 1347 | |
1351 | 1348 | |
1352 | 1349 | |
... | ... | @@ -1559,30 +1556,28 @@ |
1559 | 1556 | } |
1560 | 1557 | |
1561 | 1558 | /* |
1562 | - * Read and check the PCI configuration for any detected NCR | |
1563 | - * boards and save data for attaching after all boards have | |
1564 | - * been detected. | |
1559 | + * Map HBA registers and on-chip SRAM (if present). | |
1565 | 1560 | */ |
1566 | -static void __devinit | |
1567 | -sym_init_device(struct pci_dev *pdev, struct sym_device *device) | |
1561 | +static int __devinit | |
1562 | +sym_iomap_device(struct sym_device *device) | |
1568 | 1563 | { |
1569 | - int i = 2; | |
1564 | + struct pci_dev *pdev = device->pdev; | |
1570 | 1565 | struct pci_bus_region bus_addr; |
1566 | + int i = 2; | |
1571 | 1567 | |
1572 | - device->host_id = SYM_SETUP_HOST_ID; | |
1573 | - device->pdev = pdev; | |
1574 | - | |
1575 | 1568 | pcibios_resource_to_bus(pdev, &bus_addr, &pdev->resource[1]); |
1576 | 1569 | device->mmio_base = bus_addr.start; |
1577 | 1570 | |
1578 | - /* | |
1579 | - * If the BAR is 64-bit, resource 2 will be occupied by the | |
1580 | - * upper 32 bits | |
1581 | - */ | |
1582 | - if (!pdev->resource[i].flags) | |
1583 | - i++; | |
1584 | - pcibios_resource_to_bus(pdev, &bus_addr, &pdev->resource[i]); | |
1585 | - device->ram_base = bus_addr.start; | |
1571 | + if (device->chip.features & FE_RAM) { | |
1572 | + /* | |
1573 | + * If the BAR is 64-bit, resource 2 will be occupied by the | |
1574 | + * upper 32 bits | |
1575 | + */ | |
1576 | + if (!pdev->resource[i].flags) | |
1577 | + i++; | |
1578 | + pcibios_resource_to_bus(pdev, &bus_addr, &pdev->resource[i]); | |
1579 | + device->ram_base = bus_addr.start; | |
1580 | + } | |
1586 | 1581 | |
1587 | 1582 | #ifdef CONFIG_SCSI_SYM53C8XX_MMIO |
1588 | 1583 | if (device->mmio_base) |
1589 | 1584 | |
... | ... | @@ -1592,9 +1587,21 @@ |
1592 | 1587 | if (!device->s.ioaddr) |
1593 | 1588 | device->s.ioaddr = pci_iomap(pdev, 0, |
1594 | 1589 | pci_resource_len(pdev, 0)); |
1595 | - if (device->ram_base) | |
1590 | + if (!device->s.ioaddr) { | |
1591 | + dev_err(&pdev->dev, "could not map registers; giving up.\n"); | |
1592 | + return -EIO; | |
1593 | + } | |
1594 | + if (device->ram_base) { | |
1596 | 1595 | device->s.ramaddr = pci_iomap(pdev, i, |
1597 | 1596 | pci_resource_len(pdev, i)); |
1597 | + if (!device->s.ramaddr) { | |
1598 | + dev_warn(&pdev->dev, | |
1599 | + "could not map SRAM; continuing anyway.\n"); | |
1600 | + device->ram_base = 0; | |
1601 | + } | |
1602 | + } | |
1603 | + | |
1604 | + return 0; | |
1598 | 1605 | } |
1599 | 1606 | |
1600 | 1607 | /* |
... | ... | @@ -1711,6 +1718,8 @@ |
1711 | 1718 | |
1712 | 1719 | memset(&sym_dev, 0, sizeof(sym_dev)); |
1713 | 1720 | memset(&nvram, 0, sizeof(nvram)); |
1721 | + sym_dev.pdev = pdev; | |
1722 | + sym_dev.host_id = SYM_SETUP_HOST_ID; | |
1714 | 1723 | |
1715 | 1724 | if (pci_enable_device(pdev)) |
1716 | 1725 | goto leave; |
1717 | 1726 | |
... | ... | @@ -1720,11 +1729,12 @@ |
1720 | 1729 | if (pci_request_regions(pdev, NAME53C8XX)) |
1721 | 1730 | goto disable; |
1722 | 1731 | |
1723 | - sym_init_device(pdev, &sym_dev); | |
1724 | - do_iounmap = 1; | |
1725 | - | |
1726 | 1732 | if (sym_check_supported(&sym_dev)) |
1727 | 1733 | goto free; |
1734 | + | |
1735 | + if (sym_iomap_device(&sym_dev)) | |
1736 | + goto free; | |
1737 | + do_iounmap = 1; | |
1728 | 1738 | |
1729 | 1739 | if (sym_check_raid(&sym_dev)) { |
1730 | 1740 | do_disable_device = 0; /* Don't disable the device */ |