All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] i2c: ismt: Provide a DMA buffer for Interrupt Cause Logging
@ 2022-04-27 10:19 Mika Westerberg
  2022-04-27 15:19 ` Andy Shevchenko
  2022-05-21 10:53 ` Wolfram Sang
  0 siblings, 2 replies; 5+ messages in thread
From: Mika Westerberg @ 2022-04-27 10:19 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: Seth Heasley, Neil Horman, Andy Shevchenko, Jarkko Nikula,
	Mika Westerberg, linux-i2c

Before sending a MSI the hardware writes information pertinent to the
interrupt cause to a memory location pointed by SMTICL register. This
memory holds three double words where the least significant bit tells
whether the interrupt cause of master/target/error is valid. The driver
does not use this but we need to set it up because otherwise it will
perform DMA write to the default address (0) and this will cause an
IOMMU fault such as below:

  DMAR: DRHD: handling fault status reg 2
  DMAR: [DMA Write] Request device [00:12.0] PASID ffffffff fault addr 0
        [fault reason 05] PTE Write access is not set

To prevent this from happening, provide a proper DMA buffer for this
that then gets mapped by the IOMMU accordingly.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
 drivers/i2c/busses/i2c-ismt.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/i2c/busses/i2c-ismt.c b/drivers/i2c/busses/i2c-ismt.c
index c0364314877e..c16157ee8c52 100644
--- a/drivers/i2c/busses/i2c-ismt.c
+++ b/drivers/i2c/busses/i2c-ismt.c
@@ -82,6 +82,7 @@
 
 #define ISMT_DESC_ENTRIES	2	/* number of descriptor entries */
 #define ISMT_MAX_RETRIES	3	/* number of SMBus retries to attempt */
+#define ISMT_LOG_ENTRIES	3	/* number of interrupt cause log entries */
 
 /* Hardware Descriptor Constants - Control Field */
 #define ISMT_DESC_CWRL	0x01	/* Command/Write Length */
@@ -175,6 +176,8 @@ struct ismt_priv {
 	u8 head;				/* ring buffer head pointer */
 	struct completion cmp;			/* interrupt completion */
 	u8 buffer[I2C_SMBUS_BLOCK_MAX + 16];	/* temp R/W data buffer */
+	dma_addr_t log_dma;
+	u32 *log;
 };
 
 static const struct pci_device_id ismt_ids[] = {
@@ -411,6 +414,9 @@ static int ismt_access(struct i2c_adapter *adap, u16 addr,
 	memset(desc, 0, sizeof(struct ismt_desc));
 	desc->tgtaddr_rw = ISMT_DESC_ADDR_RW(addr, read_write);
 
+	/* Always clear the log entries */
+	memset(priv->log, 0, ISMT_LOG_ENTRIES * sizeof(u32));
+
 	/* Initialize common control bits */
 	if (likely(pci_dev_msi_enabled(priv->pci_dev)))
 		desc->control = ISMT_DESC_INT | ISMT_DESC_FAIR;
@@ -708,6 +714,8 @@ static void ismt_hw_init(struct ismt_priv *priv)
 	/* initialize the Master Descriptor Base Address (MDBA) */
 	writeq(priv->io_rng_dma, priv->smba + ISMT_MSTR_MDBA);
 
+	writeq(priv->log_dma, priv->smba + ISMT_GR_SMTICL);
+
 	/* initialize the Master Control Register (MCTRL) */
 	writel(ISMT_MCTRL_MEIE, priv->smba + ISMT_MSTR_MCTRL);
 
@@ -795,6 +803,12 @@ static int ismt_dev_init(struct ismt_priv *priv)
 	priv->head = 0;
 	init_completion(&priv->cmp);
 
+	priv->log = dmam_alloc_coherent(&priv->pci_dev->dev,
+					ISMT_LOG_ENTRIES * sizeof(u32),
+					&priv->log_dma, GFP_KERNEL);
+	if (!priv->log)
+		return -ENOMEM;
+
 	return 0;
 }
 
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] i2c: ismt: Provide a DMA buffer for Interrupt Cause Logging
  2022-04-27 10:19 [PATCH] i2c: ismt: Provide a DMA buffer for Interrupt Cause Logging Mika Westerberg
@ 2022-04-27 15:19 ` Andy Shevchenko
  2022-05-21 10:53 ` Wolfram Sang
  1 sibling, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2022-04-27 15:19 UTC (permalink / raw)
  To: Mika Westerberg
  Cc: Wolfram Sang, Seth Heasley, Neil Horman, Jarkko Nikula, linux-i2c

On Wed, Apr 27, 2022 at 01:19:10PM +0300, Mika Westerberg wrote:
> Before sending a MSI the hardware writes information pertinent to the
> interrupt cause to a memory location pointed by SMTICL register. This
> memory holds three double words where the least significant bit tells
> whether the interrupt cause of master/target/error is valid. The driver
> does not use this but we need to set it up because otherwise it will
> perform DMA write to the default address (0) and this will cause an
> IOMMU fault such as below:
> 
>   DMAR: DRHD: handling fault status reg 2
>   DMAR: [DMA Write] Request device [00:12.0] PASID ffffffff fault addr 0
>         [fault reason 05] PTE Write access is not set
> 
> To prevent this from happening, provide a proper DMA buffer for this
> that then gets mapped by the IOMMU accordingly.

Reviewed-by: From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

> Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> ---
>  drivers/i2c/busses/i2c-ismt.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/drivers/i2c/busses/i2c-ismt.c b/drivers/i2c/busses/i2c-ismt.c
> index c0364314877e..c16157ee8c52 100644
> --- a/drivers/i2c/busses/i2c-ismt.c
> +++ b/drivers/i2c/busses/i2c-ismt.c
> @@ -82,6 +82,7 @@
>  
>  #define ISMT_DESC_ENTRIES	2	/* number of descriptor entries */
>  #define ISMT_MAX_RETRIES	3	/* number of SMBus retries to attempt */
> +#define ISMT_LOG_ENTRIES	3	/* number of interrupt cause log entries */
>  
>  /* Hardware Descriptor Constants - Control Field */
>  #define ISMT_DESC_CWRL	0x01	/* Command/Write Length */
> @@ -175,6 +176,8 @@ struct ismt_priv {
>  	u8 head;				/* ring buffer head pointer */
>  	struct completion cmp;			/* interrupt completion */
>  	u8 buffer[I2C_SMBUS_BLOCK_MAX + 16];	/* temp R/W data buffer */
> +	dma_addr_t log_dma;
> +	u32 *log;
>  };
>  
>  static const struct pci_device_id ismt_ids[] = {
> @@ -411,6 +414,9 @@ static int ismt_access(struct i2c_adapter *adap, u16 addr,
>  	memset(desc, 0, sizeof(struct ismt_desc));
>  	desc->tgtaddr_rw = ISMT_DESC_ADDR_RW(addr, read_write);
>  
> +	/* Always clear the log entries */
> +	memset(priv->log, 0, ISMT_LOG_ENTRIES * sizeof(u32));
> +
>  	/* Initialize common control bits */
>  	if (likely(pci_dev_msi_enabled(priv->pci_dev)))
>  		desc->control = ISMT_DESC_INT | ISMT_DESC_FAIR;
> @@ -708,6 +714,8 @@ static void ismt_hw_init(struct ismt_priv *priv)
>  	/* initialize the Master Descriptor Base Address (MDBA) */
>  	writeq(priv->io_rng_dma, priv->smba + ISMT_MSTR_MDBA);
>  
> +	writeq(priv->log_dma, priv->smba + ISMT_GR_SMTICL);
> +
>  	/* initialize the Master Control Register (MCTRL) */
>  	writel(ISMT_MCTRL_MEIE, priv->smba + ISMT_MSTR_MCTRL);
>  
> @@ -795,6 +803,12 @@ static int ismt_dev_init(struct ismt_priv *priv)
>  	priv->head = 0;
>  	init_completion(&priv->cmp);
>  
> +	priv->log = dmam_alloc_coherent(&priv->pci_dev->dev,
> +					ISMT_LOG_ENTRIES * sizeof(u32),
> +					&priv->log_dma, GFP_KERNEL);
> +	if (!priv->log)
> +		return -ENOMEM;
> +
>  	return 0;
>  }
>  
> -- 
> 2.35.1
> 

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] i2c: ismt: Provide a DMA buffer for Interrupt Cause Logging
  2022-04-27 10:19 [PATCH] i2c: ismt: Provide a DMA buffer for Interrupt Cause Logging Mika Westerberg
  2022-04-27 15:19 ` Andy Shevchenko
@ 2022-05-21 10:53 ` Wolfram Sang
  2022-05-22  9:37   ` Andy Shevchenko
  2022-05-23  8:51   ` Mika Westerberg
  1 sibling, 2 replies; 5+ messages in thread
From: Wolfram Sang @ 2022-05-21 10:53 UTC (permalink / raw)
  To: Mika Westerberg
  Cc: Seth Heasley, Neil Horman, Andy Shevchenko, Jarkko Nikula, linux-i2c

[-- Attachment #1: Type: text/plain, Size: 1098 bytes --]

On Wed, Apr 27, 2022 at 01:19:10PM +0300, Mika Westerberg wrote:
> Before sending a MSI the hardware writes information pertinent to the
> interrupt cause to a memory location pointed by SMTICL register. This
> memory holds three double words where the least significant bit tells
> whether the interrupt cause of master/target/error is valid. The driver
> does not use this but we need to set it up because otherwise it will
> perform DMA write to the default address (0) and this will cause an
> IOMMU fault such as below:
> 
>   DMAR: DRHD: handling fault status reg 2
>   DMAR: [DMA Write] Request device [00:12.0] PASID ffffffff fault addr 0
>         [fault reason 05] PTE Write access is not set
> 
> To prevent this from happening, provide a proper DMA buffer for this
> that then gets mapped by the IOMMU accordingly.
> 
> Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>

No maintainer response so far, but given this looks like an important
bugfix and you guys are all from Intel as well, I'll apply it this time.

Applied to for-current, thanks!


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] i2c: ismt: Provide a DMA buffer for Interrupt Cause Logging
  2022-05-21 10:53 ` Wolfram Sang
@ 2022-05-22  9:37   ` Andy Shevchenko
  2022-05-23  8:51   ` Mika Westerberg
  1 sibling, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2022-05-22  9:37 UTC (permalink / raw)
  To: Wolfram Sang, Mika Westerberg, Seth Heasley, Neil Horman,
	Jarkko Nikula, linux-i2c

On Sat, May 21, 2022 at 12:53:57PM +0200, Wolfram Sang wrote:
> On Wed, Apr 27, 2022 at 01:19:10PM +0300, Mika Westerberg wrote:
> > Before sending a MSI the hardware writes information pertinent to the
> > interrupt cause to a memory location pointed by SMTICL register. This
> > memory holds three double words where the least significant bit tells
> > whether the interrupt cause of master/target/error is valid. The driver
> > does not use this but we need to set it up because otherwise it will
> > perform DMA write to the default address (0) and this will cause an
> > IOMMU fault such as below:
> > 
> >   DMAR: DRHD: handling fault status reg 2
> >   DMAR: [DMA Write] Request device [00:12.0] PASID ffffffff fault addr 0
> >         [fault reason 05] PTE Write access is not set
> > 
> > To prevent this from happening, provide a proper DMA buffer for this
> > that then gets mapped by the IOMMU accordingly.
> > 
> > Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> 
> No maintainer response so far, but given this looks like an important
> bugfix and you guys are all from Intel as well, I'll apply it this time.

It's indeed.

> Applied to for-current, thanks!

Thanks, Wolfram!

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] i2c: ismt: Provide a DMA buffer for Interrupt Cause Logging
  2022-05-21 10:53 ` Wolfram Sang
  2022-05-22  9:37   ` Andy Shevchenko
@ 2022-05-23  8:51   ` Mika Westerberg
  1 sibling, 0 replies; 5+ messages in thread
From: Mika Westerberg @ 2022-05-23  8:51 UTC (permalink / raw)
  To: Wolfram Sang, Seth Heasley, Neil Horman, Andy Shevchenko,
	Jarkko Nikula, linux-i2c

On Sat, May 21, 2022 at 12:53:57PM +0200, Wolfram Sang wrote:
> On Wed, Apr 27, 2022 at 01:19:10PM +0300, Mika Westerberg wrote:
> > Before sending a MSI the hardware writes information pertinent to the
> > interrupt cause to a memory location pointed by SMTICL register. This
> > memory holds three double words where the least significant bit tells
> > whether the interrupt cause of master/target/error is valid. The driver
> > does not use this but we need to set it up because otherwise it will
> > perform DMA write to the default address (0) and this will cause an
> > IOMMU fault such as below:
> > 
> >   DMAR: DRHD: handling fault status reg 2
> >   DMAR: [DMA Write] Request device [00:12.0] PASID ffffffff fault addr 0
> >         [fault reason 05] PTE Write access is not set
> > 
> > To prevent this from happening, provide a proper DMA buffer for this
> > that then gets mapped by the IOMMU accordingly.
> > 
> > Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> 
> No maintainer response so far, but given this looks like an important
> bugfix and you guys are all from Intel as well, I'll apply it this time.
> 
> Applied to for-current, thanks!

Thanks!

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-05-23  8:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-27 10:19 [PATCH] i2c: ismt: Provide a DMA buffer for Interrupt Cause Logging Mika Westerberg
2022-04-27 15:19 ` Andy Shevchenko
2022-05-21 10:53 ` Wolfram Sang
2022-05-22  9:37   ` Andy Shevchenko
2022-05-23  8:51   ` Mika Westerberg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.