mbox series

[v3,0/7] Add support for MHI Endpoint function driver

Message ID 20230314044623.10254-1-manivannan.sadhasivam@linaro.org
Headers show
Series Add support for MHI Endpoint function driver | expand

Message

Manivannan Sadhasivam March 14, 2023, 4:46 a.m. UTC
Hello,

This series adds support for Modem Host Interface (MHI) Endpoint function
driver and few updates to the PCI endpoint core.

MHI
===

MHI is the communication protocol used by the host machines to control and
communicate with the Qualcomm modems/WLAN devices over any high speed physical
bus like PCIe. In Linux kernel, MHI is modeled as a bus driver [1] and there
are two instances of MHI used in a typical setup.

1. MHI host - MHI implementation for the host machines like x86/ARM64.
2. MHI Endpoint - MHI implementation for the endpoint devices like modems.

MHI EPF
=======

The MHI Endpoint function driver (MHI EPF) is used on the MHI endpoint devices
like modems. The MHI EPF driver sits in between the PCIe EP and MHI EP bus and
carries out all of the PCIe related activities like BAR config, PCIe Event
handling, MMIO read/write etc,... for the MHI EP bus.

Below is the simple representation of the setup:


                 +----------------------------------------------------+
                 |                  Endpoint CPU                      |                   
                 |                                                    |
+------------+   |   +------------+   +-----------+   +-----------+   |
|            |   |   |            |   |           |   |           |   |
|            |   |   |   MHI EP   |   |           |   |           |   | PCIe Bus
|  Modem DSP +---+---+    Bus     +---+  MHI EPF  +---+  PCIe EP  +---+---------
|            |   |   |            |   |           |   |           |   |
|            |   |   |            |   |           |   |           |   |
+------------+   |   +------------+   +-----------+   +-----------+   |
                 |                                                    |
                 |                                                    |
                 +----------------------------------------------------+

The data packets will be read from the Modem DSP by the MHI stack and will be
transmitted to the host machine over PCIe bus with the help of MHI EPF driver.

Test setup
==========

This series has been tested on Snapdragon X55 modem a.k.a SDX55 connected to
the ARM64 host machine.

Thanks,
Mani

[1] https://www.kernel.org/doc/html/latest/mhi/mhi.html

Changes in v3:

* Fixed the probe function of EPF_VNTB driver

Changes in v2:

* Rebased on top of v6.3-rc1
* Switched to the new callback interface for passing events from EPC to EPF
* Dropped one patch related to notifier

Manivannan Sadhasivam (7):
  PCI: endpoint: Pass EPF device ID to the probe function
  PCI: endpoint: Warn and return if EPC is started/stopped multiple
    times
  PCI: endpoint: Add linkdown notifier support
  PCI: endpoint: Add BME notifier support
  PCI: qcom-ep: Add support for Link down notification
  PCI: qcom-ep: Add support for BME notification
  PCI: endpoint: Add PCI Endpoint function driver for MHI bus

 drivers/pci/controller/dwc/pcie-qcom-ep.c     |   2 +
 drivers/pci/endpoint/functions/Kconfig        |  10 +
 drivers/pci/endpoint/functions/Makefile       |   1 +
 drivers/pci/endpoint/functions/pci-epf-mhi.c  | 454 ++++++++++++++++++
 drivers/pci/endpoint/functions/pci-epf-ntb.c  |   3 +-
 drivers/pci/endpoint/functions/pci-epf-test.c |   2 +-
 drivers/pci/endpoint/functions/pci-epf-vntb.c |   2 +-
 drivers/pci/endpoint/pci-ep-cfs.c             |   3 +
 drivers/pci/endpoint/pci-epc-core.c           |  52 ++
 drivers/pci/endpoint/pci-epf-core.c           |   8 +-
 include/linux/pci-epc.h                       |   2 +
 include/linux/pci-epf.h                       |   8 +-
 12 files changed, 540 insertions(+), 7 deletions(-)
 create mode 100644 drivers/pci/endpoint/functions/pci-epf-mhi.c

Comments

Manivannan Sadhasivam May 15, 2023, 7 a.m. UTC | #1
On Tue, Mar 14, 2023 at 10:16:16AM +0530, Manivannan Sadhasivam wrote:
> Hello,
> 
> This series adds support for Modem Host Interface (MHI) Endpoint function
> driver and few updates to the PCI endpoint core.
> 
> MHI
> ===
> 
> MHI is the communication protocol used by the host machines to control and
> communicate with the Qualcomm modems/WLAN devices over any high speed physical
> bus like PCIe. In Linux kernel, MHI is modeled as a bus driver [1] and there
> are two instances of MHI used in a typical setup.
> 
> 1. MHI host - MHI implementation for the host machines like x86/ARM64.
> 2. MHI Endpoint - MHI implementation for the endpoint devices like modems.
> 
> MHI EPF
> =======
> 
> The MHI Endpoint function driver (MHI EPF) is used on the MHI endpoint devices
> like modems. The MHI EPF driver sits in between the PCIe EP and MHI EP bus and
> carries out all of the PCIe related activities like BAR config, PCIe Event
> handling, MMIO read/write etc,... for the MHI EP bus.
> 
> Below is the simple representation of the setup:
> 
> 
>                  +----------------------------------------------------+
>                  |                  Endpoint CPU                      |                   
>                  |                                                    |
> +------------+   |   +------------+   +-----------+   +-----------+   |
> |            |   |   |            |   |           |   |           |   |
> |            |   |   |   MHI EP   |   |           |   |           |   | PCIe Bus
> |  Modem DSP +---+---+    Bus     +---+  MHI EPF  +---+  PCIe EP  +---+---------
> |            |   |   |            |   |           |   |           |   |
> |            |   |   |            |   |           |   |           |   |
> +------------+   |   +------------+   +-----------+   +-----------+   |
>                  |                                                    |
>                  |                                                    |
>                  +----------------------------------------------------+
> 
> The data packets will be read from the Modem DSP by the MHI stack and will be
> transmitted to the host machine over PCIe bus with the help of MHI EPF driver.
> 
> Test setup
> ==========
> 
> This series has been tested on Snapdragon X55 modem a.k.a SDX55 connected to
> the ARM64 host machine.
> 

Lorenzo, gentle ping on this series.

- Mani

> Thanks,
> Mani
> 
> [1] https://www.kernel.org/doc/html/latest/mhi/mhi.html
> 
> Changes in v3:
> 
> * Fixed the probe function of EPF_VNTB driver
> 
> Changes in v2:
> 
> * Rebased on top of v6.3-rc1
> * Switched to the new callback interface for passing events from EPC to EPF
> * Dropped one patch related to notifier
> 
> Manivannan Sadhasivam (7):
>   PCI: endpoint: Pass EPF device ID to the probe function
>   PCI: endpoint: Warn and return if EPC is started/stopped multiple
>     times
>   PCI: endpoint: Add linkdown notifier support
>   PCI: endpoint: Add BME notifier support
>   PCI: qcom-ep: Add support for Link down notification
>   PCI: qcom-ep: Add support for BME notification
>   PCI: endpoint: Add PCI Endpoint function driver for MHI bus
> 
>  drivers/pci/controller/dwc/pcie-qcom-ep.c     |   2 +
>  drivers/pci/endpoint/functions/Kconfig        |  10 +
>  drivers/pci/endpoint/functions/Makefile       |   1 +
>  drivers/pci/endpoint/functions/pci-epf-mhi.c  | 454 ++++++++++++++++++
>  drivers/pci/endpoint/functions/pci-epf-ntb.c  |   3 +-
>  drivers/pci/endpoint/functions/pci-epf-test.c |   2 +-
>  drivers/pci/endpoint/functions/pci-epf-vntb.c |   2 +-
>  drivers/pci/endpoint/pci-ep-cfs.c             |   3 +
>  drivers/pci/endpoint/pci-epc-core.c           |  52 ++
>  drivers/pci/endpoint/pci-epf-core.c           |   8 +-
>  include/linux/pci-epc.h                       |   2 +
>  include/linux/pci-epf.h                       |   8 +-
>  12 files changed, 540 insertions(+), 7 deletions(-)
>  create mode 100644 drivers/pci/endpoint/functions/pci-epf-mhi.c
> 
> -- 
> 2.25.1
>
Kishon Vijay Abraham I May 15, 2023, 8:07 a.m. UTC | #2
Hi Manivannan,

On 3/14/2023 10:16 AM, Manivannan Sadhasivam wrote:
> Add PCI Endpoint driver for the Qualcomm MHI (Modem Host Interface) bus.
> The driver implements the MHI function over PCI in the endpoint device
> such as SDX55 modem. The MHI endpoint function driver acts as a
> controller driver for the MHI Endpoint stack and carries out all PCI
> related activities like mapping the host memory using iATU, triggering
> MSIs etc...
> 
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> ---
>   drivers/pci/endpoint/functions/Kconfig       |  10 +
>   drivers/pci/endpoint/functions/Makefile      |   1 +
>   drivers/pci/endpoint/functions/pci-epf-mhi.c | 454 +++++++++++++++++++
>   3 files changed, 465 insertions(+)
>   create mode 100644 drivers/pci/endpoint/functions/pci-epf-mhi.c
> 
> diff --git a/drivers/pci/endpoint/functions/Kconfig b/drivers/pci/endpoint/functions/Kconfig
> index 9fd560886871..f5171b4fabbe 100644
> --- a/drivers/pci/endpoint/functions/Kconfig
> +++ b/drivers/pci/endpoint/functions/Kconfig
> @@ -37,3 +37,13 @@ config PCI_EPF_VNTB
>   	  between PCI Root Port and PCIe Endpoint.
>   
>   	  If in doubt, say "N" to disable Endpoint NTB driver.
> +
> +config PCI_EPF_MHI
> +	tristate "PCI Endpoint driver for MHI bus"
> +	depends on PCI_ENDPOINT && MHI_BUS_EP
> +	help
> +	   Enable this configuration option to enable the PCI Endpoint
> +	   driver for Modem Host Interface (MHI) bus in Qualcomm Endpoint
> +	   devices such as SDX55.
> +
> +	   If in doubt, say "N" to disable Endpoint driver for MHI bus.
> diff --git a/drivers/pci/endpoint/functions/Makefile b/drivers/pci/endpoint/functions/Makefile
> index 5c13001deaba..696473fce50e 100644
> --- a/drivers/pci/endpoint/functions/Makefile
> +++ b/drivers/pci/endpoint/functions/Makefile
> @@ -6,3 +6,4 @@
>   obj-$(CONFIG_PCI_EPF_TEST)		+= pci-epf-test.o
>   obj-$(CONFIG_PCI_EPF_NTB)		+= pci-epf-ntb.o
>   obj-$(CONFIG_PCI_EPF_VNTB) 		+= pci-epf-vntb.o
> +obj-$(CONFIG_PCI_EPF_MHI)		+= pci-epf-mhi.o
> diff --git a/drivers/pci/endpoint/functions/pci-epf-mhi.c b/drivers/pci/endpoint/functions/pci-epf-mhi.c
> new file mode 100644
> index 000000000000..03e7f42663b3
> --- /dev/null
> +++ b/drivers/pci/endpoint/functions/pci-epf-mhi.c
.
.
<snip>
.
.
> +static int pci_epf_mhi_link_up(struct pci_epf *epf)
> +{
> +	struct pci_epf_mhi *epf_mhi = epf_get_drvdata(epf);
> +	const struct pci_epf_mhi_ep_info *info = epf_mhi->info;
> +	struct mhi_ep_cntrl *mhi_cntrl = &epf_mhi->mhi_cntrl;
> +	struct pci_epc *epc = epf->epc;
> +	struct device *dev = &epf->dev;
> +	int ret;
> +
> +	mhi_cntrl->mmio = epf_mhi->mmio;
> +	mhi_cntrl->irq = epf_mhi->irq;
> +	mhi_cntrl->mru = info->mru;
> +
> +	/* Assign the struct dev of PCI EP as MHI controller device */
> +	mhi_cntrl->cntrl_dev = epc->dev.parent;
> +	mhi_cntrl->raise_irq = pci_epf_mhi_raise_irq;
> +	mhi_cntrl->alloc_map = pci_epf_mhi_alloc_map;
> +	mhi_cntrl->unmap_free = pci_epf_mhi_unmap_free;
> +	mhi_cntrl->read_from_host = pci_epf_mhi_read_from_host;
> +	mhi_cntrl->write_to_host = pci_epf_mhi_write_to_host;
> +
> +	/* Register the MHI EP controller */
> +	ret = mhi_ep_register_controller(mhi_cntrl, info->config);
> +	if (ret) {
> +		dev_err(dev, "Failed to register MHI EP controller: %d\n", ret);
> +		return ret;
> +	}

Any reason for delaying registration with MHI bus till link up? Since 
after linkup, the host can start using the device, this should be doing 
minimal stuff IMHO. Or is there further handshake between the host side 
MHI driver and the endpoint side MHI driver?

Thanks,
Kishon
Manivannan Sadhasivam May 15, 2023, 11:36 a.m. UTC | #3
Hi Kishon,

On Mon, May 15, 2023 at 01:37:28PM +0530, Kishon VijayAbraham I wrote:
> Hi Manivannan,
> 
> On 3/14/2023 10:16 AM, Manivannan Sadhasivam wrote:
> > Add PCI Endpoint driver for the Qualcomm MHI (Modem Host Interface) bus.
> > The driver implements the MHI function over PCI in the endpoint device
> > such as SDX55 modem. The MHI endpoint function driver acts as a
> > controller driver for the MHI Endpoint stack and carries out all PCI
> > related activities like mapping the host memory using iATU, triggering
> > MSIs etc...
> > 
> > Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> > ---
> >   drivers/pci/endpoint/functions/Kconfig       |  10 +
> >   drivers/pci/endpoint/functions/Makefile      |   1 +
> >   drivers/pci/endpoint/functions/pci-epf-mhi.c | 454 +++++++++++++++++++
> >   3 files changed, 465 insertions(+)
> >   create mode 100644 drivers/pci/endpoint/functions/pci-epf-mhi.c
> > 
> > diff --git a/drivers/pci/endpoint/functions/Kconfig b/drivers/pci/endpoint/functions/Kconfig
> > index 9fd560886871..f5171b4fabbe 100644
> > --- a/drivers/pci/endpoint/functions/Kconfig
> > +++ b/drivers/pci/endpoint/functions/Kconfig
> > @@ -37,3 +37,13 @@ config PCI_EPF_VNTB
> >   	  between PCI Root Port and PCIe Endpoint.
> >   	  If in doubt, say "N" to disable Endpoint NTB driver.
> > +
> > +config PCI_EPF_MHI
> > +	tristate "PCI Endpoint driver for MHI bus"
> > +	depends on PCI_ENDPOINT && MHI_BUS_EP
> > +	help
> > +	   Enable this configuration option to enable the PCI Endpoint
> > +	   driver for Modem Host Interface (MHI) bus in Qualcomm Endpoint
> > +	   devices such as SDX55.
> > +
> > +	   If in doubt, say "N" to disable Endpoint driver for MHI bus.
> > diff --git a/drivers/pci/endpoint/functions/Makefile b/drivers/pci/endpoint/functions/Makefile
> > index 5c13001deaba..696473fce50e 100644
> > --- a/drivers/pci/endpoint/functions/Makefile
> > +++ b/drivers/pci/endpoint/functions/Makefile
> > @@ -6,3 +6,4 @@
> >   obj-$(CONFIG_PCI_EPF_TEST)		+= pci-epf-test.o
> >   obj-$(CONFIG_PCI_EPF_NTB)		+= pci-epf-ntb.o
> >   obj-$(CONFIG_PCI_EPF_VNTB) 		+= pci-epf-vntb.o
> > +obj-$(CONFIG_PCI_EPF_MHI)		+= pci-epf-mhi.o
> > diff --git a/drivers/pci/endpoint/functions/pci-epf-mhi.c b/drivers/pci/endpoint/functions/pci-epf-mhi.c
> > new file mode 100644
> > index 000000000000..03e7f42663b3
> > --- /dev/null
> > +++ b/drivers/pci/endpoint/functions/pci-epf-mhi.c
> .
> .
> <snip>
> .
> .
> > +static int pci_epf_mhi_link_up(struct pci_epf *epf)
> > +{
> > +	struct pci_epf_mhi *epf_mhi = epf_get_drvdata(epf);
> > +	const struct pci_epf_mhi_ep_info *info = epf_mhi->info;
> > +	struct mhi_ep_cntrl *mhi_cntrl = &epf_mhi->mhi_cntrl;
> > +	struct pci_epc *epc = epf->epc;
> > +	struct device *dev = &epf->dev;
> > +	int ret;
> > +
> > +	mhi_cntrl->mmio = epf_mhi->mmio;
> > +	mhi_cntrl->irq = epf_mhi->irq;
> > +	mhi_cntrl->mru = info->mru;
> > +
> > +	/* Assign the struct dev of PCI EP as MHI controller device */
> > +	mhi_cntrl->cntrl_dev = epc->dev.parent;
> > +	mhi_cntrl->raise_irq = pci_epf_mhi_raise_irq;
> > +	mhi_cntrl->alloc_map = pci_epf_mhi_alloc_map;
> > +	mhi_cntrl->unmap_free = pci_epf_mhi_unmap_free;
> > +	mhi_cntrl->read_from_host = pci_epf_mhi_read_from_host;
> > +	mhi_cntrl->write_to_host = pci_epf_mhi_write_to_host;
> > +
> > +	/* Register the MHI EP controller */
> > +	ret = mhi_ep_register_controller(mhi_cntrl, info->config);
> > +	if (ret) {
> > +		dev_err(dev, "Failed to register MHI EP controller: %d\n", ret);
> > +		return ret;
> > +	}
> 
> Any reason for delaying registration with MHI bus till link up? Since after
> linkup, the host can start using the device, this should be doing minimal
> stuff IMHO. Or is there further handshake between the host side MHI driver
> and the endpoint side MHI driver?
> 

Yes, there are further handshakes required between ep and host before the host
can start using MHI and this is done during mhi_ep_power_up(). Moreover,
registering the controller during link_up event allows us to do cleanup properly
when the link goes down.

- Mani
 
> Thanks,
> Kishon
Kishon Vijay Abraham I May 16, 2023, 3:38 a.m. UTC | #4
On 5/15/2023 5:06 PM, Manivannan Sadhasivam wrote:
> Hi Kishon,
> 
> On Mon, May 15, 2023 at 01:37:28PM +0530, Kishon VijayAbraham I wrote:
>> Hi Manivannan,
>>
>> On 3/14/2023 10:16 AM, Manivannan Sadhasivam wrote:
>>> Add PCI Endpoint driver for the Qualcomm MHI (Modem Host Interface) bus.
>>> The driver implements the MHI function over PCI in the endpoint device
>>> such as SDX55 modem. The MHI endpoint function driver acts as a
>>> controller driver for the MHI Endpoint stack and carries out all PCI
>>> related activities like mapping the host memory using iATU, triggering
>>> MSIs etc...
>>>
>>> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
>>> ---
>>>    drivers/pci/endpoint/functions/Kconfig       |  10 +
>>>    drivers/pci/endpoint/functions/Makefile      |   1 +
>>>    drivers/pci/endpoint/functions/pci-epf-mhi.c | 454 +++++++++++++++++++
>>>    3 files changed, 465 insertions(+)
>>>    create mode 100644 drivers/pci/endpoint/functions/pci-epf-mhi.c
>>>
>>> diff --git a/drivers/pci/endpoint/functions/Kconfig b/drivers/pci/endpoint/functions/Kconfig
>>> index 9fd560886871..f5171b4fabbe 100644
>>> --- a/drivers/pci/endpoint/functions/Kconfig
>>> +++ b/drivers/pci/endpoint/functions/Kconfig
>>> @@ -37,3 +37,13 @@ config PCI_EPF_VNTB
>>>    	  between PCI Root Port and PCIe Endpoint.
>>>    	  If in doubt, say "N" to disable Endpoint NTB driver.
>>> +
>>> +config PCI_EPF_MHI
>>> +	tristate "PCI Endpoint driver for MHI bus"
>>> +	depends on PCI_ENDPOINT && MHI_BUS_EP
>>> +	help
>>> +	   Enable this configuration option to enable the PCI Endpoint
>>> +	   driver for Modem Host Interface (MHI) bus in Qualcomm Endpoint
>>> +	   devices such as SDX55.
>>> +
>>> +	   If in doubt, say "N" to disable Endpoint driver for MHI bus.
>>> diff --git a/drivers/pci/endpoint/functions/Makefile b/drivers/pci/endpoint/functions/Makefile
>>> index 5c13001deaba..696473fce50e 100644
>>> --- a/drivers/pci/endpoint/functions/Makefile
>>> +++ b/drivers/pci/endpoint/functions/Makefile
>>> @@ -6,3 +6,4 @@
>>>    obj-$(CONFIG_PCI_EPF_TEST)		+= pci-epf-test.o
>>>    obj-$(CONFIG_PCI_EPF_NTB)		+= pci-epf-ntb.o
>>>    obj-$(CONFIG_PCI_EPF_VNTB) 		+= pci-epf-vntb.o
>>> +obj-$(CONFIG_PCI_EPF_MHI)		+= pci-epf-mhi.o
>>> diff --git a/drivers/pci/endpoint/functions/pci-epf-mhi.c b/drivers/pci/endpoint/functions/pci-epf-mhi.c
>>> new file mode 100644
>>> index 000000000000..03e7f42663b3
>>> --- /dev/null
>>> +++ b/drivers/pci/endpoint/functions/pci-epf-mhi.c
>> .
>> .
>> <snip>
>> .
>> .
>>> +static int pci_epf_mhi_link_up(struct pci_epf *epf)
>>> +{
>>> +	struct pci_epf_mhi *epf_mhi = epf_get_drvdata(epf);
>>> +	const struct pci_epf_mhi_ep_info *info = epf_mhi->info;
>>> +	struct mhi_ep_cntrl *mhi_cntrl = &epf_mhi->mhi_cntrl;
>>> +	struct pci_epc *epc = epf->epc;
>>> +	struct device *dev = &epf->dev;
>>> +	int ret;
>>> +
>>> +	mhi_cntrl->mmio = epf_mhi->mmio;
>>> +	mhi_cntrl->irq = epf_mhi->irq;
>>> +	mhi_cntrl->mru = info->mru;
>>> +
>>> +	/* Assign the struct dev of PCI EP as MHI controller device */
>>> +	mhi_cntrl->cntrl_dev = epc->dev.parent;
>>> +	mhi_cntrl->raise_irq = pci_epf_mhi_raise_irq;
>>> +	mhi_cntrl->alloc_map = pci_epf_mhi_alloc_map;
>>> +	mhi_cntrl->unmap_free = pci_epf_mhi_unmap_free;
>>> +	mhi_cntrl->read_from_host = pci_epf_mhi_read_from_host;
>>> +	mhi_cntrl->write_to_host = pci_epf_mhi_write_to_host;
>>> +
>>> +	/* Register the MHI EP controller */
>>> +	ret = mhi_ep_register_controller(mhi_cntrl, info->config);
>>> +	if (ret) {
>>> +		dev_err(dev, "Failed to register MHI EP controller: %d\n", ret);
>>> +		return ret;
>>> +	}
>>
>> Any reason for delaying registration with MHI bus till link up? Since after
>> linkup, the host can start using the device, this should be doing minimal
>> stuff IMHO. Or is there further handshake between the host side MHI driver
>> and the endpoint side MHI driver?
>>
> 
> Yes, there are further handshakes required between ep and host before the host
> can start using MHI and this is done during mhi_ep_power_up(). Moreover,
> registering the controller during link_up event allows us to do cleanup properly
> when the link goes down.

Thank you for clarifying!

For the entire series:

Reviewed-by: Kishon Vijay Abraham I <kishon@kernel.org>
> 
> - Mani
>   
>> Thanks,
>> Kishon
>