From: "Íñigo Huguet" <ihuguet@redhat.com>
To: ecree.xilinx@gmail.com, habetsm.xilinx@gmail.com, ap420073@gmail.com
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, netdev@vger.kernel.org,
"Íñigo Huguet" <ihuguet@redhat.com>
Subject: [PATCH net-next 1/5] sfc: add new helper macros to iterate channels by type
Date: Tue, 10 May 2022 10:44:39 +0200 [thread overview]
Message-ID: <20220510084443.14473-2-ihuguet@redhat.com> (raw)
In-Reply-To: <20220510084443.14473-1-ihuguet@redhat.com>
Sometimes in the driver it's needed to iterate a subset of the channels
depending on whether it is an rx, tx or xdp channel. Now it's done
iterating over all channels and checking if it's of the desired type,
leading to too much nested and a bit complex to understand code.
Add new iterator macros to allow iterating only over a single type of
channel.
Signed-off-by: Íñigo Huguet <ihuguet@redhat.com>
---
drivers/net/ethernet/sfc/net_driver.h | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/drivers/net/ethernet/sfc/net_driver.h b/drivers/net/ethernet/sfc/net_driver.h
index 318db906a154..7f665ba6a082 100644
--- a/drivers/net/ethernet/sfc/net_driver.h
+++ b/drivers/net/ethernet/sfc/net_driver.h
@@ -1501,6 +1501,27 @@ efx_get_channel(struct efx_nic *efx, unsigned index)
_channel = (_channel->channel + 1 < (_efx)->n_channels) ? \
(_efx)->channel[_channel->channel + 1] : NULL)
+#define efx_for_each_rx_channel(_channel, _efx) \
+ for (_channel = (_efx)->channel[0]; \
+ _channel; \
+ _channel = (_channel->channel + 1 < (_efx)->n_rx_channels) ? \
+ (_efx)->channel[_channel->channel + 1] : NULL)
+
+#define efx_for_each_tx_channel(_channel, _efx) \
+ for (_channel = (_efx)->channel[efx->tx_channel_offset]; \
+ _channel; \
+ _channel = (_channel->channel + 1 < \
+ (_efx)->tx_channel_offset + (_efx)->n_tx_channels) ? \
+ (_efx)->channel[_channel->channel + 1] : NULL)
+
+#define efx_for_each_xdp_channel(_channel, _efx) \
+ for (_channel = ((_efx)->n_xdp_channels > 0) ? \
+ (_efx)->channel[efx->xdp_channel_offset] : NULL; \
+ _channel; \
+ _channel = (_channel->channel + 1 < \
+ (_efx)->xdp_channel_offset + (_efx)->n_xdp_channels) ? \
+ (_efx)->channel[_channel->channel + 1] : NULL)
+
/* Iterate over all used channels in reverse */
#define efx_for_each_channel_rev(_channel, _efx) \
for (_channel = (_efx)->channel[(_efx)->n_channels - 1]; \
--
2.34.1
next prev parent reply other threads:[~2022-05-10 8:45 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-10 8:44 [PATCH net-next 0/5] sfc: refactor of efx_set_channels Íñigo Huguet
2022-05-10 8:44 ` Íñigo Huguet [this message]
2022-05-11 7:19 ` [PATCH net-next 1/5] sfc: add new helper macros to iterate channels by type Martin Habets
2022-05-11 8:41 ` Íñigo Huguet
2022-05-10 8:44 ` [PATCH net-next 2/5] sfc: separate channel->tx_queue and efx->xdp_tx_queue mappings Íñigo Huguet
2022-05-11 7:52 ` Martin Habets
2022-05-11 8:55 ` Íñigo Huguet
2022-05-10 8:44 ` [PATCH net-next 3/5] sfc: rename set_channels to set_queues and document it Íñigo Huguet
2022-05-10 8:44 ` [PATCH net-next 4/5] sfc: refactor efx_set_xdp_tx_queues Íñigo Huguet
2022-05-10 8:44 ` [PATCH net-next 5/5] sfc: move tx_channel_offset calculation to interrupts probe Íñigo Huguet
2022-05-11 8:02 ` Martin Habets
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=20220510084443.14473-2-ihuguet@redhat.com \
--to=ihuguet@redhat.com \
--cc=ap420073@gmail.com \
--cc=davem@davemloft.net \
--cc=ecree.xilinx@gmail.com \
--cc=edumazet@google.com \
--cc=habetsm.xilinx@gmail.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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).