Skip to contentSkip to conversation

i2c: ismt: improve usage of devres API

PATCH Applied Andy Shevchenko 4 participants 10 messages Sep 16, 2015 – Oct 20, 2015 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/6 i2c: ismt: improve usage of devres API

pcim_release() will release any requested region. There is no need to duplicate this effort in the driver.

---
 drivers/i2c/busses/i2c-ismt.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)
drivers/i2c/busses/i2c-ismt.c +5 -13
index f994712..b7a68b5 100644
@@ -904,8 +904,7 @@ ismt_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	priv->smba = pcim_iomap(pdev, SMBBAR, len);
 	if (!priv->smba) {
 		dev_err(&pdev->dev, "Unable to ioremap SMBus BAR\n");
-		err = -ENODEV;
-		goto fail;
+		return -ENODEV;
 	}
 
 	if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) ||
@@ -915,32 +914,26 @@ ismt_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 						 DMA_BIT_MASK(32)) != 0)) {
 			dev_err(&pdev->dev, "pci_set_dma_mask fail %p\n",
 				pdev);
-			err = -ENODEV;
-			goto fail;
+			return -ENODEV;
 		}
 	}
 
 	err = ismt_dev_init(priv);
 	if (err)
-		goto fail;
+		return err;
 
 	ismt_hw_init(priv);
 
 	err = ismt_int_init(priv);
 	if (err)
-		goto fail;
+		return err;
 
 	err = i2c_add_adapter(&priv->adapter);
 	if (err) {
 		dev_err(&pdev->dev, "Failed to add SMBus iSMT adapter\n");
-		err = -ENODEV;
-		goto fail;
+		return -ENODEV;
 	}
 	return 0;
-
-fail:
-	pci_release_region(pdev, SMBBAR);
-	return err;
 }
 
 /**
@@ -952,7 +945,6 @@ static void ismt_remove(struct pci_dev *pdev)
 	struct ismt_priv *priv = pci_get_drvdata(pdev);
 
 	i2c_del_adapter(&priv->adapter);
-	pci_release_region(pdev, SMBBAR);
 }
 
 /**
Signature · 1 line
2.5.1

A message that is not in the archive (sent off-list or not yet received): 1442413443-123579-1-git-send-email-andriy.shevchenko-VuQAYsv1563Yd54FQh9/[email protected]

#2 lore raw

PATCH 2/6 i2c: ismt: PCI core handles power state for us

There is no need to repeat the work that is already done in the PCI driver core. Remove suspend and resume callbacks.

Note that there is no more calls performed to enable or disable a PCI device during suspend-resume cycle. Nowadays they seems to be superflous. Someone can read more in [1].

[1] https://www.kernel.org/doc/ols/2009/ols2009-pages-319-330.pdf

---
 drivers/i2c/busses/i2c-ismt.c | 33 ---------------------------------
 1 file changed, 33 deletions(-)
drivers/i2c/busses/i2c-ismt.c +0 -33
index b7a68b5..570b0a0 100644
@@ -947,44 +947,11 @@ static void ismt_remove(struct pci_dev *pdev)
 	i2c_del_adapter(&priv->adapter);
 }
 
-/**
- * ismt_suspend() - place the device in suspend
- * @pdev: PCI-Express device
- * @mesg: PM message
- */
-#ifdef CONFIG_PM
-static int ismt_suspend(struct pci_dev *pdev, pm_message_t mesg)
-{
-	pci_save_state(pdev);
-	pci_set_power_state(pdev, pci_choose_state(pdev, mesg));
-	return 0;
-}
-
-/**
- * ismt_resume() - PCI resume code
- * @pdev: PCI-Express device
- */
-static int ismt_resume(struct pci_dev *pdev)
-{
-	pci_set_power_state(pdev, PCI_D0);
-	pci_restore_state(pdev);
-	return pci_enable_device(pdev);
-}
-
-#else
-
-#define ismt_suspend NULL
-#define ismt_resume NULL
-
-#endif
-
 static struct pci_driver ismt_driver = {
 	.name = "ismt_smbus",
 	.id_table = ismt_ids,
 	.probe = ismt_probe,
 	.remove = ismt_remove,
-	.suspend = ismt_suspend,
-	.resume = ismt_resume,
 };
 
 module_pci_driver(ismt_driver);
Signature · 1 line
2.5.1
#3 lore raw

Re: [PATCH 2/6] i2c: ismt: PCI core handles power state for us

Quoted 10 lines · Andy Shevchenko

There is no need to repeat the work that is already done in the PCI driver core. Remove suspend and resume callbacks.

Note that there is no more calls performed to enable or disable a PCI device during suspend-resume cycle. Nowadays they seems to be superflous. Someone can read more in [1].

[1] https://www.kernel.org/doc/ols/2009/ols2009-pages-319-330.pdf

Checkpatch said:

WARNING: 'superflous' may be misspelled - perhaps 'superfluous'? #6:
superflous. Someone can read more in [1].

total: 0 errors, 1 warnings, 0 checks, 44 lines checked

Fixed it here.

#4 lore raw

PATCH 3/6 i2c: ismt: do not duplicate msi_enabled flag

In reply to a message not in the archive

struct pci_dev already has a flag to track if MSI is enabled or not. Use it directly.

---
 drivers/i2c/busses/i2c-ismt.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/i2c/busses/i2c-ismt.c +1 -5
index 570b0a0..6c2058d 100644
@@ -172,7 +172,6 @@ struct ismt_priv {
 	u8 head;				/* ring buffer head pointer */
 	struct completion cmp;			/* interrupt completion */
 	u8 dma_buffer[I2C_SMBUS_BLOCK_MAX + 1];	/* temp R/W data buffer */
-	bool using_msi;				/* type of interrupt flag */
 };
 
 /**
@@ -398,7 +397,7 @@ static int ismt_access(struct i2c_adapter *adap, u16 addr,
 	desc->tgtaddr_rw = ISMT_DESC_ADDR_RW(addr, read_write);
 
 	/* Initialize common control bits */
-	if (likely(priv->using_msi))
+	if (likely(pci_dev_msi_enabled(priv->pci_dev)))
 		desc->control = ISMT_DESC_INT | ISMT_DESC_FAIR;
 	else
 		desc->control = ISMT_DESC_FAIR;
@@ -806,7 +805,6 @@ static int ismt_int_init(struct ismt_priv *priv)
 		goto intx;
 	}
 
-	priv->using_msi = true;
 	goto done;
 
 	/* Try using legacy interrupts */
@@ -822,8 +820,6 @@ intx:
 		return -ENODEV;
 	}
 
-	priv->using_msi = false;
-
 done:
 	return 0;
 }
Signature · 1 line
2.5.1
#5 lore raw

PATCH 4/6 i2c: ismt: propagate actual error code

In reply to a message not in the archive

Propagate actual return code when requesting interrupt fails.

---
 drivers/i2c/busses/i2c-ismt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-ismt.c +1 -1
index 6c2058d..3bc4bad 100644
@@ -817,7 +817,7 @@ intx:
 			       priv);
 	if (err) {
 		dev_err(&priv->pci_dev->dev, "no usable interrupts\n");
-		return -ENODEV;
+		return err;
 	}
 
 done:
Signature · 1 line
2.5.1
#6 lore raw

PATCH 5/6 i2c: ismt: issue a warning when fail to request MSI

In reply to a message not in the archive

Issue the warning in all error paths when unable to register MSI or its handler.

---
 drivers/i2c/busses/i2c-ismt.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/i2c/busses/i2c-ismt.c +5 -6
index 3bc4bad..48e0693 100644
@@ -788,11 +788,8 @@ static int ismt_int_init(struct ismt_priv *priv)
 
 	/* Try using MSI interrupts */
 	err = pci_enable_msi(priv->pci_dev);
-	if (err) {
-		dev_warn(&priv->pci_dev->dev,
-			 "Unable to use MSI interrupts, falling back to legacy\n");
+	if (err)
 		goto intx;
-	}
 
 	err = devm_request_irq(&priv->pci_dev->dev,
 			       priv->pci_dev->irq,
@@ -805,10 +802,13 @@ static int ismt_int_init(struct ismt_priv *priv)
 		goto intx;
 	}
 
-	goto done;
+	return 0;
 
 	/* Try using legacy interrupts */
 intx:
+	dev_warn(&priv->pci_dev->dev,
+		 "Unable to use MSI interrupts, falling back to legacy\n");
+
 	err = devm_request_irq(&priv->pci_dev->dev,
 			       priv->pci_dev->irq,
 			       ismt_do_interrupt,
@@ -820,7 +820,6 @@ intx:
 		return err;
 	}
 
-done:
 	return 0;
 }
 
Signature · 1 line
2.5.1
#7 lore raw

PATCH 6/6 i2c: ismt: mark register space with __iomem

In reply to a message not in the archive

This fixes the code to suppress sparse warnings like:

drivers/i2c/busses/i2c-ismt.c:725:36: warning: incorrect type in argument 2 (different address spaces)
drivers/i2c/busses/i2c-ismt.c:725:36: expected void volatile [noderef] <asn:2>*addr
drivers/i2c/busses/i2c-ismt.c:725:36: got void *

---
 drivers/i2c/busses/i2c-ismt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-ismt.c +1 -1
index 48e0693..80648be 100644
@@ -165,7 +165,7 @@ struct ismt_desc {
 
 struct ismt_priv {
 	struct i2c_adapter adapter;
-	void *smba;				/* PCI BAR */
+	void __iomem *smba;			/* PCI BAR */
 	struct pci_dev *pci_dev;
 	struct ismt_desc *hw;			/* descriptor virt base addr */
 	dma_addr_t io_rng_dma;			/* descriptor HW base addr */
Signature · 1 line
2.5.1
#8 lore raw
In reply to Andy Shevchenko
Quoted 3 lines · Andy Shevchenko

pcim_release() will release any requested region. There is no need to duplicate
this effort in the driver.

Any comments on that clean up series?

Quoted 72 lines
---
 drivers/i2c/busses/i2c-ismt.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)
drivers/i2c/busses/i2c renamed from drivers/i2c/busses/i2c-ismt.c +0 -1
-ismt.c

index f994712..b7a68b5 100644

drivers/i2c/busses/i2c-ismt.c +1 -2
@@ -904,8 +904,7 @@ ismt_probe(struct pci_dev *pdev, const struct 
 pci_device_id *id)
 	priv->smba = pcim_iomap(pdev, SMBBAR, len);
 	if (!priv->smba) {
 		dev_err(&pdev->dev, "Unable to ioremap SMBus 
 BAR\n");
-		err = -ENODEV;
-		goto fail;
+		return -ENODEV;
 	}
drivers/i2c/busses/i2c-ismt.c +4 -11
 	if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) ||
@@ -915,32 +914,26 @@ ismt_probe(struct pci_dev *pdev, const struct 
 pci_device_id *id)
 						 DMA_BIT_MASK(32)) 
 != 0)) {
 			dev_err(&pdev->dev, "pci_set_dma_mask fail 
 %p\n",
 				pdev);
-			err = -ENODEV;
-			goto fail;
+			return -ENODEV;
 		}
 	}
 
 	err = ismt_dev_init(priv);
 	if (err)
-		goto fail;
+		return err;
 
 	ismt_hw_init(priv);
 
 	err = ismt_int_init(priv);
 	if (err)
-		goto fail;
+		return err;
 
 	err = i2c_add_adapter(&priv->adapter);
 	if (err) {
 		dev_err(&pdev->dev, "Failed to add SMBus iSMT 
 adapter\n");
-		err = -ENODEV;
-		goto fail;
+		return -ENODEV;
 	}
 	return 0;
-
-fail:
-	pci_release_region(pdev, SMBBAR);
-	return err;
 }
 
 /**
@@ -952,7 +945,6 @@ static void ismt_remove(struct pci_dev *pdev)
 	struct ismt_priv *priv = pci_get_drvdata(pdev);
 
 	i2c_del_adapter(&priv->adapter);
-	pci_release_region(pdev, SMBBAR);
 }
 
 /**
Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
Reviewed-by
#9 lore raw
Quoted 6 lines · Andy Shevchenko
Quoted 3 lines · Andy Shevchenko

pcim_release() will release any requested region. There is no need to duplicate
this effort in the driver.

Any comments on that clean up series?

FWIW the whole series looks good to me,

Applied
#10 lore raw
Quoted 11 lines · Mika Westerberg
Quoted 6 lines · Andy Shevchenko
Quoted 3 lines · Andy Shevchenko

pcim_release() will release any requested region. There is no need to duplicate
this effort in the driver.

Any comments on that clean up series?

FWIW the whole series looks good to me,

Applied all to for-next, thanks!