From: Joe Damato <jdamato@fastly.com>
To: Jijie Shao <shaojijie@huawei.com>
Cc: yisen.zhuang@huawei.com, salil.mehta@huawei.com,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org, shenjian15@huawei.com,
wangpeiyang1@huawei.com, liuyonglong@huawei.com,
sudongming1@huawei.com, xujunsheng@huawei.com,
shiyongbang@huawei.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH net-next 07/10] net: hibmcge: Implement rx_poll function to receive packets
Date: Wed, 31 Jul 2024 14:23:53 +0100 [thread overview]
Message-ID: <Zqo66ZPaD2GtLZwg@LQ3V64L9R2> (raw)
In-Reply-To: <20240731094245.1967834-8-shaojijie@huawei.com>
On Wed, Jul 31, 2024 at 05:42:42PM +0800, Jijie Shao wrote:
> Implement rx_poll function to read the rx descriptor after
> receiving the rx interrupt. Adjust the skb based on the
> descriptor to complete the reception of the packet.
>
> Signed-off-by: Jijie Shao <shaojijie@huawei.com>
> ---
> .../ethernet/hisilicon/hibmcge/hbg_common.h | 5 +
> .../net/ethernet/hisilicon/hibmcge/hbg_hw.c | 10 ++
> .../net/ethernet/hisilicon/hibmcge/hbg_hw.h | 1 +
> .../net/ethernet/hisilicon/hibmcge/hbg_irq.c | 9 +-
> .../net/ethernet/hisilicon/hibmcge/hbg_main.c | 2 +
> .../net/ethernet/hisilicon/hibmcge/hbg_reg.h | 2 +
> .../hisilicon/hibmcge/hbg_reg_union.h | 65 ++++++++
> .../net/ethernet/hisilicon/hibmcge/hbg_txrx.c | 157 +++++++++++++++++-
> 8 files changed, 248 insertions(+), 3 deletions(-)
> diff --git a/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c b/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c
> index 8efeea9b0c26..bb5f8321da8a 100644
> --- a/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c
> +++ b/drivers/net/ethernet/hisilicon/hibmcge/hbg_main.c
> @@ -36,6 +36,7 @@ static int hbg_net_open(struct net_device *dev)
> return 0;
>
> netif_carrier_off(dev);
> + napi_enable(&priv->rx_ring.napi);
> napi_enable(&priv->tx_ring.napi);
> hbg_enable_intr(priv, true);
> hbg_hw_mac_enable(priv, HBG_STATUS_ENABLE);
In the future, it might be good to consider using:
- netif_napi_set_irq
- netif_queue_set_napi
to link NAPIs with IRQs and queues.
For an example, see 64b62146ba9e ("net/mlx4: link NAPI instances to
queues and IRQs).
[...]
> +static int hbg_rx_fill_buffers(struct hbg_priv *priv)
> +{
> + struct hbg_ring *ring = &priv->rx_ring;
> + int ret;
> +
> + while (!(hbg_fifo_is_full(priv, ring->dir) ||
> + hbg_queue_is_full(ring->ntc, ring->ntu, ring))) {
> + ret = hbg_rx_fill_one_buffer(priv);
> + if (ret)
> + return ret;
> + }
> +
> + return 0;
> +}
> +
> +static bool hbg_sync_data_from_hw(struct hbg_priv *priv,
> + struct hbg_buffer *buffer)
> +{
> + struct hbg_rx_desc *rx_desc;
> +
> + /* make sure HW write desc complete */
> + dma_rmb();
> +
> + dma_sync_single_for_cpu(&priv->pdev->dev, buffer->skb_dma,
> + buffer->skb_len, DMA_FROM_DEVICE);
> +
> + rx_desc = (struct hbg_rx_desc *)buffer->skb->data;
> + return rx_desc->len != 0;
> +}
Have you looked into using the page pool to simplify some of the
logic above?
> +static int hbg_napi_rx_poll(struct napi_struct *napi, int budget)
> +{
> + struct hbg_ring *ring = container_of(napi, struct hbg_ring, napi);
> + struct hbg_priv *priv = ring->priv;
> + struct hbg_rx_desc *rx_desc;
> + struct hbg_buffer *buffer;
> + u32 packet_done = 0;
> +
> + if (unlikely(!hbg_nic_is_open(priv))) {
> + napi_complete(napi);
> + return 0;
> + }
> +
> + while (packet_done < budget) {
> + if (unlikely(hbg_queue_is_empty(ring->ntc, ring->ntu)))
> + break;
> +
> + buffer = &ring->queue[ring->ntc];
> + if (unlikely(!buffer->skb))
> + goto next_buffer;
> +
> + if (unlikely(!hbg_sync_data_from_hw(priv, buffer)))
> + break;
> +
> + hbg_dma_unmap(buffer);
> +
> + rx_desc = (struct hbg_rx_desc *)buffer->skb->data;
> + skb_reserve(buffer->skb, HBG_PACKET_HEAD_SIZE + NET_IP_ALIGN);
> + skb_put(buffer->skb, rx_desc->len);
> + buffer->skb->protocol = eth_type_trans(buffer->skb, priv->netdev);
> +
> + priv->netdev->stats.rx_bytes += rx_desc->len;
> + priv->netdev->stats.rx_packets++;
> + netif_receive_skb(buffer->skb);
Any reason why not napi_gro_receive ?
> + buffer->skb = NULL;
> + hbg_rx_fill_one_buffer(priv);
> +
> +next_buffer:
> + hbg_queue_move_next(ntc, ring);
> + packet_done++;
> + }
> +
> + hbg_rx_fill_buffers(priv);
> + if (packet_done >= budget)
> + return packet_done;
> +
> + napi_complete(napi);
Maybe:
if (napi_complete_done(napi))
hbg_irq_enable(priv, HBG_IRQ_RX, true);
> + hbg_irq_enable(priv, HBG_IRQ_RX, true);
> +
> + return packet_done;
> +}
[...]
next prev parent reply other threads:[~2024-07-31 13:23 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-31 9:42 [RFC PATCH net-next 00/10] Add support of HIBMCGE Ethernet Driver Jijie Shao
2024-07-31 9:42 ` [RFC PATCH net-next 01/10] net: hibmcge: Add pci table supported in this module Jijie Shao
2024-07-31 9:42 ` [RFC PATCH net-next 02/10] net: hibmcge: Add read/write registers supported through the bar space Jijie Shao
2024-08-05 12:55 ` Simon Horman
2024-08-05 13:08 ` Jijie Shao
2024-07-31 9:42 ` [RFC PATCH net-next 03/10] net: hibmcge: Add mdio and hardware configuration supported in this module Jijie Shao
2024-08-01 0:42 ` Andrew Lunn
2024-08-01 9:04 ` Jijie Shao
2024-08-01 12:07 ` Andrew Lunn
2024-07-31 9:42 ` [RFC PATCH net-next 04/10] net: hibmcge: Add interrupt " Jijie Shao
2024-07-31 13:14 ` Joe Damato
2024-08-01 11:31 ` Jijie Shao
2024-08-05 12:57 ` Simon Horman
2024-08-05 13:29 ` Jijie Shao
2024-07-31 9:42 ` [RFC PATCH net-next 05/10] net: hibmcge: Implement some .ndo functions Jijie Shao
2024-08-01 0:51 ` Andrew Lunn
2024-08-01 9:13 ` Jijie Shao
2024-08-01 12:18 ` Andrew Lunn
2024-08-01 12:33 ` Jijie Shao
2024-08-01 12:36 ` Andrew Lunn
2024-08-01 13:08 ` Jijie Shao
2024-07-31 9:42 ` [RFC PATCH net-next 06/10] net: hibmcge: Implement .ndo_start_xmit function Jijie Shao
2024-07-31 9:42 ` [RFC PATCH net-next 07/10] net: hibmcge: Implement rx_poll function to receive packets Jijie Shao
2024-07-31 13:23 ` Joe Damato [this message]
2024-08-01 11:58 ` Jijie Shao
2024-07-31 9:42 ` [RFC PATCH net-next 08/10] net: hibmcge: Implement workqueue and some ethtool_ops functions Jijie Shao
2024-08-01 1:10 ` Andrew Lunn
2024-08-01 11:10 ` Jijie Shao
2024-08-01 12:26 ` Andrew Lunn
2024-08-01 13:06 ` Jijie Shao
2024-08-01 20:16 ` Andrew Lunn
2024-07-31 9:42 ` [RFC PATCH net-next 09/10] net: hibmcge: Add a Makefile and update Kconfig for hibmcge Jijie Shao
2024-08-01 1:13 ` Andrew Lunn
2024-08-01 12:15 ` Jijie Shao
2024-08-01 12:33 ` Andrew Lunn
2024-07-31 9:42 ` [RFC PATCH net-next 10/10] net: hibmcge: Add maintainer " Jijie Shao
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=Zqo66ZPaD2GtLZwg@LQ3V64L9R2 \
--to=jdamato@fastly.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liuyonglong@huawei.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=salil.mehta@huawei.com \
--cc=shaojijie@huawei.com \
--cc=shenjian15@huawei.com \
--cc=shiyongbang@huawei.com \
--cc=sudongming1@huawei.com \
--cc=wangpeiyang1@huawei.com \
--cc=xujunsheng@huawei.com \
--cc=yisen.zhuang@huawei.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