netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: Loic Poulain <loic.poulain@linaro.org>
Cc: Jakub Kicinski <kuba@kernel.org>,
	David Miller <davem@davemloft.net>,
	manivannan.sadhasivam@linaro.org, hemantk@codeaurora.org,
	Network Development <netdev@vger.kernel.org>,
	linux-arm-msm@vger.kernel.org, jhugo@codeaurora.org,
	bbhatt@codeaurora.org
Subject: Re: [PATCH v7 2/2] net: Add mhi-net driver
Date: Tue, 27 Oct 2020 17:21:52 -0400	[thread overview]
Message-ID: <CA+FuTSddjtB0sbUjE59CLqC1vXXnvsV9od5xD7sQkyE5cG7WFA@mail.gmail.com> (raw)
In-Reply-To: <1603787977-6975-2-git-send-email-loic.poulain@linaro.org>

On Tue, Oct 27, 2020 at 4:33 AM Loic Poulain <loic.poulain@linaro.org> wrote:
>
> This patch adds a new network driver implementing MHI transport for
> network packets. Packets can be in any format, though QMAP (rmnet)
> is the usual protocol (flow control + PDN mux).
>
> It support two MHI devices, IP_HW0 which is, the path to the IPA
> (IP accelerator) on qcom modem, And IP_SW0 which is the software
> driven IP path (to modem CPU).
>
> Signed-off-by: Loic Poulain <loic.poulain@linaro.org>

> +static int mhi_ndo_xmit(struct sk_buff *skb, struct net_device *ndev)
> +{
> +       struct mhi_net_dev *mhi_netdev = netdev_priv(ndev);
> +       struct mhi_device *mdev = mhi_netdev->mdev;
> +       int err;
> +
> +       /* mhi_queue_skb is not thread-safe, but xmit is serialized by the
> +        * network core. Once MHI core will be thread save, migrate to

nit: thread-safe.

I also wonder whether you'd gain much from converting to
driver-internal locking, perhaps this comment is premature?

> +static void mhi_net_rx_refill_work(struct work_struct *work)
> +{
> +       struct mhi_net_dev *mhi_netdev = container_of(work, struct mhi_net_dev,
> +                                                     rx_refill.work);
> +       struct net_device *ndev = mhi_netdev->ndev;
> +       struct mhi_device *mdev = mhi_netdev->mdev;
> +       int size = READ_ONCE(ndev->mtu);
> +       struct sk_buff *skb;
> +       int err;
> +
> +       do {
> +               skb = netdev_alloc_skb(ndev, size);
> +               if (unlikely(!skb))
> +                       break;
> +
> +               err = mhi_queue_skb(mdev, DMA_FROM_DEVICE, skb, size, MHI_EOT);
> +               if (err) {
> +                       if (unlikely(err != -ENOMEM))
> +                               net_err_ratelimited("%s: Failed to queue RX buf (%d)\n",
> +                                                   ndev->name, err);
> +                       kfree_skb(skb);
> +                       break;
> +               }
> +
> +               atomic_inc(&mhi_netdev->stats.rx_queued);
> +
> +               /* Do not hog the CPU if rx buffers are completed faster than
> +                * queued (unlikely).
> +                */
> +               cond_resched();
> +       } while (1);

This function has to allocate + kfree_skb one too many skbs to break
out of the loop? Can it not observe the queue full based on rx_queued?

> +
> +       /* If we're still starved of rx buffers, reschedule latter */

nit: later

> +       if (unlikely(!atomic_read(&mhi_netdev->stats.rx_queued)))
> +               schedule_delayed_work(&mhi_netdev->rx_refill, HZ / 2);

what is the rationale for HZ / 2?

> +}
> +
> +static int mhi_net_probe(struct mhi_device *mhi_dev,
> +                        const struct mhi_device_id *id)
> +{
> +       const char *netname = (char *)id->driver_data;
> +       struct mhi_net_dev *mhi_netdev;
> +       struct net_device *ndev;
> +       struct device *dev = &mhi_dev->dev;
> +       int err;
> +
> +       ndev = alloc_netdev(sizeof(*mhi_netdev), netname, NET_NAME_PREDICTABLE,
> +                           mhi_net_setup);
> +       if (!ndev)
> +               return -ENOMEM;
> +
> +       mhi_netdev = netdev_priv(ndev);
> +       dev_set_drvdata(dev, mhi_netdev);
> +       mhi_netdev->ndev = ndev;
> +       mhi_netdev->mdev = mhi_dev;
> +       SET_NETDEV_DEV(ndev, &mhi_dev->dev);
> +
> +       /* All MHI net channels have 128 ring elements (at least for now) */
> +       mhi_netdev->rx_queue_sz = 128;
> +
> +       INIT_DELAYED_WORK(&mhi_netdev->rx_refill, mhi_net_rx_refill_work);
> +       u64_stats_init(&mhi_netdev->stats.rx_syncp);
> +       u64_stats_init(&mhi_netdev->stats.tx_syncp);
> +
> +       /* Start MHI channels */
> +       err = mhi_prepare_for_transfer(mhi_dev);
> +       if (err)
> +               goto out_err;
> +
> +       err = register_netdev(ndev);
> +       if (err) {
> +               mhi_unprepare_from_transfer(mhi_dev);
> +               goto out_err;

It's a bit odd to combine error branches with jump labels. I'd add
out_register_err: below
> +       }
> +
> +       return 0;
> +
> +out_err:
> +       free_netdev(ndev);
> +       return err;
> +}

  reply	other threads:[~2020-10-27 21:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-27  8:39 [PATCH v7 1/2] bus: mhi: Add mhi_queue_is_full function Loic Poulain
2020-10-27  8:39 ` [PATCH v7 2/2] net: Add mhi-net driver Loic Poulain
2020-10-27 21:21   ` Willem de Bruijn [this message]
2020-10-27 21:03 ` [PATCH v7 1/2] bus: mhi: Add mhi_queue_is_full function Willem de Bruijn

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=CA+FuTSddjtB0sbUjE59CLqC1vXXnvsV9od5xD7sQkyE5cG7WFA@mail.gmail.com \
    --to=willemdebruijn.kernel@gmail.com \
    --cc=bbhatt@codeaurora.org \
    --cc=davem@davemloft.net \
    --cc=hemantk@codeaurora.org \
    --cc=jhugo@codeaurora.org \
    --cc=kuba@kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=loic.poulain@linaro.org \
    --cc=manivannan.sadhasivam@linaro.org \
    --cc=netdev@vger.kernel.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 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).