diff mbox series

[v2,1/3] mei: bus: add client dma interface

Message ID 20210420172755.12178-1-emmanuel.grumbach@intel.com (mailing list archive)
State Accepted
Commit fc07b83286afa09740b0fde2a011fe69bbaeeda1
Delegated to: Luca Coelho
Headers show
Series [v2,1/3] mei: bus: add client dma interface | expand

Commit Message

Emmanuel Grumbach April 20, 2021, 5:27 p.m. UTC
From: Alexander Usyskin <alexander.usyskin@intel.com>

Expose the client dma mapping via mei client bus interface.
The client dma has to be mapped before the device is enabled,
therefore we need to create device linking already during mapping
and we need to unmap after the client is disable hence we need to
postpone the unlink and flush till unmapping or when
destroying the device.

Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
Co-developed-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
---
This is a another version of the patch:
https://lore.kernel.org/lkml/20210206144325.25682-6-tomas.winkler@intel.com/

Greg asked to route this patch through the wireless drivers tree:
https://lore.kernel.org/lkml/YB6sIi61X5p6Dq6y@kroah.com/
So here it is.
---
---
 drivers/misc/mei/bus.c     | 67 ++++++++++++++++++++++++++++++++++++--
 drivers/misc/mei/client.c  |  3 ++
 drivers/misc/mei/hw.h      |  5 +++
 include/linux/mei_cl_bus.h |  3 ++
 4 files changed, 75 insertions(+), 3 deletions(-)

Comments

Emmanuel Grumbach May 12, 2021, 5:49 a.m. UTC | #1
Hi Greg,

On Tue, Apr 20, 2021 at 8:29 PM Emmanuel Grumbach
<emmanuel.grumbach@intel.com> wrote:
>
> From: Alexander Usyskin <alexander.usyskin@intel.com>
>
> Expose the client dma mapping via mei client bus interface.
> The client dma has to be mapped before the device is enabled,
> therefore we need to create device linking already during mapping
> and we need to unmap after the client is disable hence we need to
> postpone the unlink and flush till unmapping or when
> destroying the device.
>
> Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
> Co-developed-by: Tomas Winkler <tomas.winkler@intel.com>
> Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
> Signed-off-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
> Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
> ---
> This is a another version of the patch:
> https://lore.kernel.org/lkml/20210206144325.25682-6-tomas.winkler@intel.com/
>
> Greg asked to route this patch through the wireless drivers tree:
> https://lore.kernel.org/lkml/YB6sIi61X5p6Dq6y@kroah.com/
> So here it is.
> ---

I think I fixed all the issues you raised on the previous version of the patch.
This series has been reviewed internally as well. The merge window is
now closed, can we move forward with this?

Thanks.
Greg Kroah-Hartman May 12, 2021, 6:02 a.m. UTC | #2
On Wed, May 12, 2021 at 08:49:06AM +0300, Emmanuel Grumbach wrote:
> Hi Greg,
> 
> On Tue, Apr 20, 2021 at 8:29 PM Emmanuel Grumbach
> <emmanuel.grumbach@intel.com> wrote:
> >
> > From: Alexander Usyskin <alexander.usyskin@intel.com>
> >
> > Expose the client dma mapping via mei client bus interface.
> > The client dma has to be mapped before the device is enabled,
> > therefore we need to create device linking already during mapping
> > and we need to unmap after the client is disable hence we need to
> > postpone the unlink and flush till unmapping or when
> > destroying the device.
> >
> > Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
> > Co-developed-by: Tomas Winkler <tomas.winkler@intel.com>
> > Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
> > Signed-off-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
> > Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
> > ---
> > This is a another version of the patch:
> > https://lore.kernel.org/lkml/20210206144325.25682-6-tomas.winkler@intel.com/
> >
> > Greg asked to route this patch through the wireless drivers tree:
> > https://lore.kernel.org/lkml/YB6sIi61X5p6Dq6y@kroah.com/
> > So here it is.
> > ---
> 
> I think I fixed all the issues you raised on the previous version of the patch.
> This series has been reviewed internally as well. The merge window is
> now closed, can we move forward with this?

$ mdfrm -c ~/mail/todo/
1823 messages in /home/gregkh/mail/todo/

Please relax, there is no rush.

greg k-h
Greg Kroah-Hartman May 13, 2021, 6:57 p.m. UTC | #3
On Tue, Apr 20, 2021 at 08:27:53PM +0300, Emmanuel Grumbach wrote:
> From: Alexander Usyskin <alexander.usyskin@intel.com>
> 
> Expose the client dma mapping via mei client bus interface.
> The client dma has to be mapped before the device is enabled,
> therefore we need to create device linking already during mapping
> and we need to unmap after the client is disable hence we need to
> postpone the unlink and flush till unmapping or when
> destroying the device.
> 
> Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
> Co-developed-by: Tomas Winkler <tomas.winkler@intel.com>
> Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
> Signed-off-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
> Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
> ---
> This is a another version of the patch:
> https://lore.kernel.org/lkml/20210206144325.25682-6-tomas.winkler@intel.com/
> 
> Greg asked to route this patch through the wireless drivers tree:
> https://lore.kernel.org/lkml/YB6sIi61X5p6Dq6y@kroah.com/
> So here it is.

Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Luca Coelho May 21, 2021, 8:51 a.m. UTC | #4
Emmanuel Grumbach <emmanuel.grumbach@intel.com> wrote:

> From: Alexander Usyskin <alexander.usyskin@intel.com>
> 
> Expose the client dma mapping via mei client bus interface.
> The client dma has to be mapped before the device is enabled,
> therefore we need to create device linking already during mapping
> and we need to unmap after the client is disable hence we need to
> postpone the unlink and flush till unmapping or when
> destroying the device.
> 
> Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
> Co-developed-by: Tomas Winkler <tomas.winkler@intel.com>
> Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
> Signed-off-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
> Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

3 patches applied to iwlwifi-next.git, thanks.

d0f2edda1651 iwlwifi: pcie: don't enable BHs with IRQs disabled
fc07b83286af mei: bus: add client dma interface
09df8fa50be8 iwlwifi: mei: add the driver to allow cooperation with CSME
Luca Coelho May 21, 2021, 8:55 a.m. UTC | #5
On Fri, 2021-05-21 at 11:51 +0300, Luca Coelho wrote:
> Emmanuel Grumbach <emmanuel.grumbach@intel.com> wrote:
> 
> > From: Alexander Usyskin <alexander.usyskin@intel.com>
> > 
> > Expose the client dma mapping via mei client bus interface.
> > The client dma has to be mapped before the device is enabled,
> > therefore we need to create device linking already during mapping
> > and we need to unmap after the client is disable hence we need to
> > postpone the unlink and flush till unmapping or when
> > destroying the device.
> > 
> > Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
> > Co-developed-by: Tomas Winkler <tomas.winkler@intel.com>
> > Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
> > Signed-off-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
> > Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
> > Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> 
> 3 patches applied to iwlwifi-next.git, thanks.
> 
> d0f2edda1651 iwlwifi: pcie: don't enable BHs with IRQs disabled

This came out wrong.  

> fc07b83286af mei: bus: add client dma interface
> 09df8fa50be8 iwlwifi: mei: add the driver to allow cooperation with CSME

This one was the third commit that was applied:

43d400b75bbf iwlwifi: integrate with iwlmei

--
Cheers,
Luca.
diff mbox series

Patch

diff --git a/drivers/misc/mei/bus.c b/drivers/misc/mei/bus.c
index 935acc6bbf3c..7a325572ad1d 100644
--- a/drivers/misc/mei/bus.c
+++ b/drivers/misc/mei/bus.c
@@ -643,6 +643,64 @@  static void mei_cl_bus_vtag_free(struct mei_cl_device *cldev)
 	kfree(cl_vtag);
 }
 
+void *mei_cldev_dma_map(struct mei_cl_device *cldev, u8 buffer_id, size_t size)
+{
+	struct mei_device *bus;
+	struct mei_cl *cl;
+	int ret;
+
+	if (!cldev || !buffer_id || !size)
+		return ERR_PTR(-EINVAL);
+
+	if (!IS_ALIGNED(size, MEI_FW_PAGE_SIZE)) {
+		dev_err(&cldev->dev, "Map size should be aligned to %lu\n",
+			MEI_FW_PAGE_SIZE);
+		return ERR_PTR(-EINVAL);
+	}
+
+	cl = cldev->cl;
+	bus = cldev->bus;
+
+	mutex_lock(&bus->device_lock);
+	if (cl->state == MEI_FILE_UNINITIALIZED) {
+		ret = mei_cl_link(cl);
+		if (ret)
+			goto out;
+		/* update pointers */
+		cl->cldev = cldev;
+	}
+
+	ret = mei_cl_dma_alloc_and_map(cl, NULL, buffer_id, size);
+out:
+	mutex_unlock(&bus->device_lock);
+	if (ret)
+		return ERR_PTR(ret);
+	return cl->dma.vaddr;
+}
+EXPORT_SYMBOL_GPL(mei_cldev_dma_map);
+
+int mei_cldev_dma_unmap(struct mei_cl_device *cldev)
+{
+	struct mei_device *bus;
+	struct mei_cl *cl;
+	int ret;
+
+	if (!cldev)
+		return -EINVAL;
+
+	cl = cldev->cl;
+	bus = cldev->bus;
+
+	mutex_lock(&bus->device_lock);
+	ret = mei_cl_dma_unmap(cl, NULL);
+
+	mei_cl_flush_queues(cl, NULL);
+	mei_cl_unlink(cl);
+	mutex_unlock(&bus->device_lock);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(mei_cldev_dma_unmap);
+
 /**
  * mei_cldev_enable - enable me client device
  *     create connection with me client
@@ -753,9 +811,11 @@  int mei_cldev_disable(struct mei_cl_device *cldev)
 		dev_err(bus->dev, "Could not disconnect from the ME client\n");
 
 out:
-	/* Flush queues and remove any pending read */
-	mei_cl_flush_queues(cl, NULL);
-	mei_cl_unlink(cl);
+	/* Flush queues and remove any pending read unless we have mapped DMA */
+	if (!cl->dma_mapped) {
+		mei_cl_flush_queues(cl, NULL);
+		mei_cl_unlink(cl);
+	}
 
 	mutex_unlock(&bus->device_lock);
 	return err;
@@ -1054,6 +1114,7 @@  static void mei_cl_bus_dev_release(struct device *dev)
 	if (!cldev)
 		return;
 
+	mei_cl_flush_queues(cldev->cl, NULL);
 	mei_me_cl_put(cldev->me_cl);
 	mei_dev_bus_put(cldev->bus);
 	mei_cl_unlink(cldev->cl);
diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c
index 2cc370adb238..5e71f455db35 100644
--- a/drivers/misc/mei/client.c
+++ b/drivers/misc/mei/client.c
@@ -700,6 +700,9 @@  int mei_cl_unlink(struct mei_cl *cl)
 
 	cl_dbg(dev, cl, "unlink client");
 
+	if (cl->state == MEI_FILE_UNINITIALIZED)
+		return 0;
+
 	if (dev->open_handle_count > 0)
 		dev->open_handle_count--;
 
diff --git a/drivers/misc/mei/hw.h b/drivers/misc/mei/hw.h
index b10606550613..bc240b88abf1 100644
--- a/drivers/misc/mei/hw.h
+++ b/drivers/misc/mei/hw.h
@@ -22,6 +22,11 @@ 
 #define MEI_D0I3_TIMEOUT            5  /* D0i3 set/unset max response time */
 #define MEI_HBM_TIMEOUT             1  /* 1 second */
 
+/*
+ * FW page size for DMA allocations
+ */
+#define MEI_FW_PAGE_SIZE 4096UL
+
 /*
  * MEI Version
  */
diff --git a/include/linux/mei_cl_bus.h b/include/linux/mei_cl_bus.h
index 07f5ef8fc456..8c8d46ba33bf 100644
--- a/include/linux/mei_cl_bus.h
+++ b/include/linux/mei_cl_bus.h
@@ -116,4 +116,7 @@  int mei_cldev_enable(struct mei_cl_device *cldev);
 int mei_cldev_disable(struct mei_cl_device *cldev);
 bool mei_cldev_enabled(struct mei_cl_device *cldev);
 
+void *mei_cldev_dma_map(struct mei_cl_device *cldev, u8 buffer_id, size_t size);
+int mei_cldev_dma_unmap(struct mei_cl_device *cldev);
+
 #endif /* _LINUX_MEI_CL_BUS_H */