From: Bjorn Andersson <bjorn.andersson@linaro.org>
To: Loic Poulain <loic.poulain@linaro.org>
Cc: manivannan.sadhasivam@linaro.org, hemantk@codeaurora.org,
linux-arm-msm@vger.kernel.org
Subject: Re: [PATCH] bus: mhi: Add MHI PCI support
Date: Wed, 23 Sep 2020 10:17:09 -0500 [thread overview]
Message-ID: <20200923151709.GC40811@yoga> (raw)
In-Reply-To: <1600868432-12438-1-git-send-email-loic.poulain@linaro.org>
On Wed 23 Sep 08:40 CDT 2020, Loic Poulain wrote:
> This is a generic MHI-over-PCI controller driver for MHI only devices
> such as QCOM modems. For now it supports registering of Qualcomm SDX55
> based PCIe modules. The MHI channels have been extracted from mhi
> downstream driver.
>
> This driver is easily extendable to support other MHI PCI devices like
> different modem hw or OEM superset.
>
> Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
> ---
[..]
> diff --git a/drivers/bus/mhi/controllers/mhi_pci_common.c b/drivers/bus/mhi/controllers/mhi_pci_common.c
> new file mode 100644
> index 0000000..705b283
> --- /dev/null
> +++ b/drivers/bus/mhi/controllers/mhi_pci_common.c
ath11k is also "PCI" and "MHI" but this isn't "common" code for it, so
perhaps "mhi_pci_generic.c" or "mhi_pci_modem.c"?
> @@ -0,0 +1,339 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * MHI PCI driver - MHI over PCI controller driver
> + *
> + * This module is a generic driver for registering pure MHI-over-PCI devices,
> + * such as PCIe QCOM modems.
> + *
> + * Copyright (C) 2020 Linaro Ltd <loic.poulain@linaro.org>
> + */
> +
> +#include <linux/device.h>
> +#include <linux/mhi.h>
> +#include <linux/module.h>
> +#include <linux/pci.h>
> +#include <linux/delay.h>
Can you confirm that you need delay.h?
> +
> +#define MHI_PCI_BAR_NUM 0
> +
> +enum {
> + EV_RING_0,
> + EV_RING_1,
> + EV_RING_2,
> + EV_RING_3,
Maybe you can just use the numbers 0-3 instead?
> +};
> +
[..]
> +static int mhi_pci_claim(struct mhi_controller *mhic)
> +{
> + struct pci_dev *pdev = to_pci_dev(mhic->cntrl_dev);
> + int err;
> +
> + err = pci_assign_resource(pdev, MHI_PCI_BAR_NUM);
> + if (err) {
> + dev_err(&pdev->dev, "failed to assign pci resource: %d\n", err);
Afaict all code paths of pci_assign_resource() will log already.
> + return err;
> + }
> +
> + err = pcim_enable_device(pdev);
> + if (err) {
> + dev_err(&pdev->dev, "failed to enable pci device: %d\n", err);
> + return err;
> + }
> +
> + err = pcim_iomap_regions(pdev, 1 << MHI_PCI_BAR_NUM, pci_name(pdev));
> + if (err) {
> + dev_err(&pdev->dev, "failed to map pci region: %d\n", err);
> + return err;
> + }
> + mhic->regs = pcim_iomap_table(pdev)[MHI_PCI_BAR_NUM];
> +
> + err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
> + if (err) {
> + dev_err(&pdev->dev, "Cannot set proper DMA mask\n");
> + return err;
> + }
> +
> + err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
> + if (err) {
> + dev_err(&pdev->dev, "set consistent dma mask failed\n");
> + return err;
> + }
> +
> + pci_set_master(pdev);
> +
> + return 0;
> +}
[..]
> +static int mhi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> +{
> + const struct mhi_pci_dev_info *info = (struct mhi_pci_dev_info *) id->driver_data;
> + const struct mhi_controller_config *mhic_config;
> + struct mhi_controller *mhic;
> + int err;
> +
> + dev_info(&pdev->dev, "MHI PCI device found: %s\n", info->name);
> +
> + mhic = devm_kzalloc(&pdev->dev, sizeof(*mhic), GFP_KERNEL);
> + if (!mhic) {
> + dev_err(&pdev->dev, "failed to allocate mhi controller\n");
kzalloc() will log errors as well.
> + return -ENOMEM;
> + }
> +
> + mhic_config = info->config;
> + mhic->cntrl_dev = &pdev->dev;
> + mhic->iova_start = 0;
> + mhic->iova_stop = 0xffffffff;
> + mhic->fw_image = NULL;
> + mhic->edl_image = NULL;
> +
> + mhic->read_reg = mhi_pci_read_reg;
> + mhic->write_reg = mhi_pci_write_reg;
> + mhic->status_cb = mhi_pci_status_cb;
> + mhic->runtime_get = mhi_pci_runtime_get;
> + mhic->runtime_put = mhi_pci_runtime_put;
> +
> + err = mhi_pci_claim(mhic);
> + if (err)
> + return err;
> +
> + err = mhi_pci_get_irqs(mhic, mhic_config);
> + if (err)
> + return err;
> +
> + pci_set_drvdata(pdev, mhic);
> +
> + err = mhi_register_controller(mhic, mhic_config);
> + if (err) {
> + dev_err(&pdev->dev, "failed to register MHI controller\n");
Afaict all errors that occurs if you pass valid data to this function
will print an error message already...
> + pci_free_irq_vectors(pdev);
> + return err;
> + }
> +
> + /* MHI bus does not power up the controller by default */
> + err = mhi_prepare_for_power_up(mhic);
> + if (err) {
> + dev_err(&pdev->dev, "failed to prepare MHI controller\n");
mhi_unregister_controller()?
> + return err;
> + }
> +
> + err = mhi_sync_power_up(mhic);
> + if (err) {
> + dev_err(&pdev->dev, "failed to power up MHI controller\n");
> + mhi_unprepare_after_power_down(mhic);
> + mhi_unregister_controller(mhic);
> + return err;
> + }
> +
> + return 0;
> +}
> +
> +static void mhi_pci_remove(struct pci_dev *pdev)
> +{
> + struct mhi_controller *mhic = pci_get_drvdata(pdev);
> +
> + mhi_power_down(mhic, true);
> + mhi_unprepare_after_power_down(mhic);
> + mhi_unregister_controller(mhic);
> +}
> +
> +static struct pci_driver mhi_pci_driver = {
> + .name = "mhi-pci",
> + .id_table = mhi_pci_id_table,
> + .probe = mhi_pci_probe,
> + .remove = mhi_pci_remove
> +};
> +module_pci_driver(mhi_pci_driver);
> +
> +MODULE_AUTHOR("Loic Poulain <loic.poulain@linaro,org>");
> +MODULE_DESCRIPTION("mhi-pci");
Please expand this
> +MODULE_LICENSE("GPL");
> +MODULE_VERSION("1");
And please drop the version, as this is likely not going to be updated
consistently.
Regards,
Bjorn
next prev parent reply other threads:[~2020-09-23 15:17 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-23 13:40 [PATCH] bus: mhi: Add MHI PCI support Loic Poulain
2020-09-23 14:03 ` Jeffrey Hugo
2020-09-23 14:35 ` Loic Poulain
2020-09-23 14:55 ` Jeffrey Hugo
2020-09-23 15:42 ` Loic Poulain
2020-09-23 15:17 ` Bjorn Andersson [this message]
2020-09-23 15:28 ` Jeffrey Hugo
2020-09-23 16:31 ` Loic Poulain
2020-09-26 5:18 ` Manivannan Sadhasivam
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200923151709.GC40811@yoga \
--to=bjorn.andersson@linaro.org \
--cc=hemantk@codeaurora.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=loic.poulain@linaro.org \
--cc=manivannan.sadhasivam@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.