Re: [PATCH] bus: mhi: Add MHI PCI support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Sep 23, 2020 at 06:31:09PM +0200, Loic Poulain wrote:
> Hi Bjorn,
> 
> On Wed, 23 Sep 2020 at 17:17, Bjorn Andersson
> <bjorn.andersson@xxxxxxxxxx> wrote:
> >
> > 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@xxxxxxxxxx>
> > > ---
> > [..]
> > > 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"?
> 
> Right, mhi_pci_modem looks good.
> 

Please use "mhi_pci_generic". This driver is not specific to modems...

Thanks,
Mani

> >
> > > @@ -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@xxxxxxxxxx>
> > > + */
> > > +
> > > +#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?
> 
> You're right, don't use any delay function in that version.
> 
> >
> > > +
> > > +#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?
> 
> ack.
> 
> >
> > > +};
> > > +
> > [..]
> > > +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.
> >
> 
> ok, thanks.
> 
> > > +             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()?
> 
> Indeed, thanks.
> 
> >
> > > +             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
> 
> will do.
> 
> >
> > > +MODULE_LICENSE("GPL");
> > > +MODULE_VERSION("1");
> >
> > And please drop the version, as this is likely not going to be updated
> > consistently.
> >
> > Regards,
> > Bjorn



[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [Linux for Sparc]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux