From: Loic Poulain <loic.poulain@linaro.org>
To: "Yanchao Yang (杨彦超)" <Yanchao.Yang@mediatek.com>
Cc: "Chris Feng (冯保林)" <Chris.Feng@mediatek.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-mediatek@lists.infradead.org"
<linux-mediatek@lists.infradead.org>,
"Mingliang Xu (徐明亮)" <mingliang.xu@mediatek.com>,
"Min Dong (董敏)" <min.dong@mediatek.com>,
"linuxwwan@intel.com" <linuxwwan@intel.com>,
"m.chetan.kumar@intel.com" <m.chetan.kumar@intel.com>,
"Liang Lu (吕亮)" <liang.lu@mediatek.com>,
"Haijun Liu (刘海军)" <haijun.liu@mediatek.com>,
"Haozhe Chang (常浩哲)" <Haozhe.Chang@mediatek.com>,
"Hua Yang (杨华)" <Hua.Yang@mediatek.com>,
"ryazanov.s.a@gmail.com" <ryazanov.s.a@gmail.com>,
"kuba@kernel.org" <kuba@kernel.org>,
"Aiden Wang (王咏麒)" <Aiden.Wang@mediatek.com>,
"edumazet@google.com" <edumazet@google.com>,
"pabeni@redhat.com" <pabeni@redhat.com>,
"Ting Wang (王挺)" <ting.wang@mediatek.com>,
"johannes@sipsolutions.net" <johannes@sipsolutions.net>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"Guohao Zhang (张国豪)" <Guohao.Zhang@mediatek.com>,
"Felix Chen (陈非)" <Felix.Chen@mediatek.com>,
"Lambert Wang (王伟)" <Lambert.Wang@mediatek.com>,
"davem@davemloft.net" <davem@davemloft.net>,
"Mingchuang Qiao (乔明闯)" <Mingchuang.Qiao@mediatek.com>,
"Xiayu Zhang (张夏宇)" <Xiayu.Zhang@mediatek.com>
Subject: Re: [PATCH net-next v4 01/10] net: wwan: tmi: Add PCIe core
Date: Tue, 25 Apr 2023 15:56:09 +0200 [thread overview]
Message-ID: <CAMZdPi-=jbsxYJp1VCoTyPZMH+TYdrVo5aTe3mphVJSsWZ=kLQ@mail.gmail.com> (raw)
In-Reply-To: <bbcd7e5155421d7671c995212d69ca7d8f575375.camel@mediatek.com>
Hello,
On Mon, 10 Apr 2023 at 14:16, Yanchao Yang (杨彦超)
<Yanchao.Yang@mediatek.com> wrote:
>
> Hi Loic,
>
> sorry for late response, please check following reply.
>
> On Mon, 2023-03-20 at 21:26 +0800, Yanchao Yang wrote:
> > Hi Loic,
> >
> > On Fri, 2023-03-17 at 13:34 +0100, Loic Poulain wrote:
> > > Hi Yanchao,
> > >
> > > On Fri, 17 Mar 2023 at 09:10, Yanchao Yang <
> > > yanchao.yang@mediatek.com
> > > > wrote:
> > > >
> > > > Registers the TMI device driver with the kernel. Set up all the
> > > > fundamental
> > > > configurations for the device: PCIe layer, Modem Host Cross Core
> > > > Interface
> > > > (MHCCIF), Reset Generation Unit (RGU), modem common control
> > > > operations and
> > > > build infrastructure.
> > > >
> > > > * PCIe layer code implements driver probe and removal, MSI-X
> > > > interrupt
> > > > initialization and de-initialization, and the way of resetting
> > > > the
> > > > device.
> > > > * MHCCIF provides interrupt channels to communicate events such
> > > > as
> > > > handshake,
> > > > PM and port enumeration.
> > > > * RGU provides interrupt channels to generate notifications from
> > > > the device
> > > > so that the TMI driver could get the device reset.
> > > > * Modem common control operations provide the basic read/write
> > > > functions of
> > > > the device's hardware registers, mask/unmask/get/clear functions
> > > > of
> > > > the
> > > > device's interrupt registers and inquiry functions of the
> > > > device's
> > > > status.
> > > >
> > > > Signed-off-by: Yanchao Yang <yanchao.yang@mediatek.com>
> > > > Signed-off-by: Ting Wang <ting.wang@mediatek.com>
> > > > ---
> > > > drivers/net/wwan/Kconfig | 14 +
> > > > drivers/net/wwan/Makefile | 1 +
> > > > drivers/net/wwan/mediatek/Makefile | 8 +
> > > > drivers/net/wwan/mediatek/mtk_dev.h | 203 ++++++
> > > > drivers/net/wwan/mediatek/pcie/mtk_pci.c | 887
> > > > +++++++++++++++++++++++
> > > > drivers/net/wwan/mediatek/pcie/mtk_pci.h | 144 ++++
> > > > drivers/net/wwan/mediatek/pcie/mtk_reg.h | 69 ++
> > > > 7 files changed, 1326 insertions(+)
> > > > create mode 100644 drivers/net/wwan/mediatek/Makefile
> > > > create mode 100644 drivers/net/wwan/mediatek/mtk_dev.h
> > > > create mode 100644 drivers/net/wwan/mediatek/pcie/mtk_pci.c
> > > > create mode 100644 drivers/net/wwan/mediatek/pcie/mtk_pci.h
> > > > create mode 100644 drivers/net/wwan/mediatek/pcie/mtk_reg.h
> > > >
> > >
> > > [...]
> > >
> > > > +static int mtk_pci_get_virq_id(struct mtk_md_dev *mdev, int
> > > > irq_id)
> > > > +{
> > > > + struct pci_dev *pdev = to_pci_dev(mdev->dev);
> > > > + int nr = 0;
> > > > +
> > > > + if (pdev->msix_enabled)
> > > > + nr = irq_id % mdev->msi_nvecs;
> > > > +
> > > > + return pci_irq_vector(pdev, nr);
> > > > +}
> > > > +
> > > > +static int mtk_pci_register_irq(struct mtk_md_dev *mdev, int
> > > > irq_id,
> > > > + int (*irq_cb)(int irq_id, void
> > > > *data), void *data)
> > > > +{
> > > > + struct mtk_pci_priv *priv = mdev->hw_priv;
> > > > +
> > > > + if (unlikely((irq_id < 0 || irq_id >= MTK_IRQ_CNT_MAX) ||
> > > > !irq_cb))
> > > > + return -EINVAL;
> > > > +
> > > > + if (priv->irq_cb_list[irq_id]) {
> > > > + dev_err(mdev->dev,
> > > > + "Unable to register irq, irq_id=%d, it's
> > > > already been register by %ps.\n",
> > > > + irq_id, priv->irq_cb_list[irq_id]);
> > > > + return -EFAULT;
> > > > + }
> > > > + priv->irq_cb_list[irq_id] = irq_cb;
> > > > + priv->irq_cb_data[irq_id] = data;
> > >
> > > So it looks like you re-implement your own irq chip internally.
> > > What
> > > about creating a new irq-chip/domain for this (cf
> > > irq_domain_add_simple)?
> > > That would allow the client code to use the regular irq interface
> > > and
> > > helpers
> > > and it should simply code and improve its debuggability
> > > (/proc/irq...).
> >
> > We will check it and update you later.
> No, we don’t re-implement irq chip. After studying the irq_domain
> interface you suggest, the TMI driver leverages on MSI irq domain. We
> use pci_alloc_irq_vectors to allocate MSI-X irq desc and use
> pci_request_irq to bind interrupt sources with irq handlers.
What I mean is that you're implementing some interrupt muxing into
your driver, which could possibly be abstracted with a 'virtual' irq
domain and generic ops (e.g with proper irq domain your
mtk_pci_register_irq method could be replaced with the usual
request_irq), Think about it as future improvement, I assume we can go
with the current solution for now.
> > >
> > > [...]
> > >
> > > > +static int mtk_mhccif_register_evt(struct mtk_md_dev *mdev, u32
> > > > chs,
> > > > + int (*evt_cb)(u32 status, void
> > > > *data), void *data)
> > > > +{
> > > > + struct mtk_pci_priv *priv = mdev->hw_priv;
> > > > + struct mtk_mhccif_cb *cb;
> > > > + unsigned long flag;
> > > > + int ret = 0;
> > > > +
> > > > + if (!chs || !evt_cb)
> > > > + return -EINVAL;
> > > > +
> > > > + spin_lock_irqsave(&priv->mhccif_lock, flag);
> > >
> > > Why spinlock here and not mutex. AFAIU, you always take this lock
> > > in
> > > a
> > > non-atomic/process context.
> >
> > Currently, the function is only called in the FSM initialization and
> > PM(power management) initialization process. Both are atomic.
> > On the other hand, this registration function will operate the global
> > variables “mhccif_cb_list”, but it takes very little time. So, we
> > think
> > spinlock is preferred.
> Any ideas or comments for this? Please help share it at your
> convenience.
They do not seem atomic... moreover you're using the _irqsave variant
while you're never accessing the list from (hard|soft)irq context.
> >
> > >
> > > > + list_for_each_entry(cb, &priv->mhccif_cb_list, entry) {
> > > > + if (cb->chs & chs) {
> > > > + ret = -EFAULT;
> > > > + dev_err(mdev->dev,
> > > > + "Unable to register evt,
> > > > chs=0x%08X&0x%08X registered_cb=%ps\n",
> > > > + chs, cb->chs, cb->evt_cb);
> > > > + goto err;
> > > > + }
> > > > + }
> > > > + cb = devm_kzalloc(mdev->dev, sizeof(*cb), GFP_ATOMIC);
Maybe alloc this outside the lock, so that you can use the 'regular'
GFP_KERNEL alloc.
> > > > + if (!cb) {
> > > > + ret = -ENOMEM;
> > > > + goto err;
> > > > + }
> > > > + cb->evt_cb = evt_cb;
> > > > + cb->data = data;
> > > > + cb->chs = chs;
> > > > + list_add_tail(&cb->entry, &priv->mhccif_cb_list);
> > > > +
> > > > +err:
> > > > + spin_unlock_irqrestore(&priv->mhccif_lock, flag);
> > > > +
> > > > + return ret;
> > > > +}
> > >
> > > [...]
> > >
> > > > +
> > > > +MODULE_LICENSE("GPL");
> > > > diff --git a/drivers/net/wwan/mediatek/pcie/mtk_pci.h
> > > > b/drivers/net/wwan/mediatek/pcie/mtk_pci.h
> > > > new file mode 100644
> > > > index 000000000000..b487ca9b302e
> > > > --- /dev/null
> > > > +++ b/drivers/net/wwan/mediatek/pcie/mtk_pci.h
> > >
> > > Why a separated header file, isn't the content (e.g. mtk_pci_priv)
> > > used only from mtk_pci.c?
> >
> > Do you mean that we should move all contents of “mtk_pci.h” into
> > “mtk_pci.c” directly? The “mtk_pci.h” seems to be redundant, right?
> Any ideas or comments for this? Please help share it at your
> convenience.
Yes, keep that in the .c file.
Regards,
Loic
next prev parent reply other threads:[~2023-04-25 13:56 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-17 8:09 [PATCH net-next v4 00/10] net: wwan: tmi: PCIe driver for MediaTek M.2 modem Yanchao Yang
2023-03-17 8:09 ` [PATCH net-next v4 01/10] net: wwan: tmi: Add PCIe core Yanchao Yang
2023-03-17 12:34 ` Loic Poulain
2023-03-20 13:26 ` Yanchao Yang (杨彦超)
2023-04-10 12:16 ` Yanchao Yang (杨彦超)
2023-04-25 13:56 ` Loic Poulain [this message]
2023-03-17 8:09 ` [PATCH net-next v4 02/10] net: wwan: tmi: Add control plane transaction layer Yanchao Yang
2023-03-17 8:09 ` [PATCH net-next v4 03/10] net: wwan: tmi: Add control DMA interface Yanchao Yang
2023-03-17 8:09 ` [PATCH net-next v4 04/10] net: wwan: tmi: Add control port Yanchao Yang
2023-03-17 8:09 ` [PATCH net-next v4 05/10] net: wwan: tmi: Add FSM thread Yanchao Yang
2023-03-17 8:09 ` [PATCH net-next v4 06/10] net: wwan: tmi: Add AT & MBIM WWAN ports Yanchao Yang
2023-03-17 8:09 ` [PATCH net-next v4 07/10] net: wwan: tmi: Introduce data plane hardware interface Yanchao Yang
2023-03-17 8:09 ` [PATCH net-next v4 08/10] net: wwan: tmi: Add data plane transaction layer Yanchao Yang
2023-03-17 8:09 ` [PATCH net-next v4 09/10] net: wwan: tmi: Introduce WWAN interface Yanchao Yang
2023-03-17 8:09 ` [PATCH net-next v4 10/10] net: wwan: tmi: Add maintainers and documentation Yanchao Yang
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='CAMZdPi-=jbsxYJp1VCoTyPZMH+TYdrVo5aTe3mphVJSsWZ=kLQ@mail.gmail.com' \
--to=loic.poulain@linaro.org \
--cc=Aiden.Wang@mediatek.com \
--cc=Chris.Feng@mediatek.com \
--cc=Felix.Chen@mediatek.com \
--cc=Guohao.Zhang@mediatek.com \
--cc=Haozhe.Chang@mediatek.com \
--cc=Hua.Yang@mediatek.com \
--cc=Lambert.Wang@mediatek.com \
--cc=Mingchuang.Qiao@mediatek.com \
--cc=Xiayu.Zhang@mediatek.com \
--cc=Yanchao.Yang@mediatek.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=haijun.liu@mediatek.com \
--cc=johannes@sipsolutions.net \
--cc=kuba@kernel.org \
--cc=liang.lu@mediatek.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linuxwwan@intel.com \
--cc=m.chetan.kumar@intel.com \
--cc=min.dong@mediatek.com \
--cc=mingliang.xu@mediatek.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=ryazanov.s.a@gmail.com \
--cc=ting.wang@mediatek.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).