From: "Théo Lebrun" <theo.lebrun@bootlin.com>
To: Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Nicolas Ferre <nicolas.ferre@microchip.com>,
Claudiu Beznea <claudiu.beznea@tuxon.dev>,
Geert Uytterhoeven <geert@linux-m68k.org>,
Harini Katakam <harini.katakam@xilinx.com>,
Richard Cochran <richardcochran@gmail.com>,
Russell King <linux@armlinux.org.uk>
Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
"Tawfik Bayouk" <tawfik.bayouk@mobileye.com>,
"Théo Lebrun" <theo.lebrun@bootlin.com>
Subject: [PATCH net v3 15/16] net: macb: introduce DMA descriptor helpers (is 64bit? is PTP?)
Date: Fri, 08 Aug 2025 18:52:47 +0200 [thread overview]
Message-ID: <20250808-macb-fixes-v3-15-08f1fcb5179f@bootlin.com> (raw)
In-Reply-To: <20250808-macb-fixes-v3-0-08f1fcb5179f@bootlin.com>
Introduce macb_dma64() and macb_dma_ptp() helper functions.
Many codepaths are made simpler by dropping conditional compilation.
This implies two additional changes:
- Always compile related structure definitions inside <macb.h>.
- MACB_EXT_DESC can be dropped as it is useless now.
The common case is:
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
if (bp->hw_dma_cap & HW_DMA_CAP_64B) {
// ...
}
#endif
And replaced by:
if (macb_dma64(bp)) {
// ...
}
Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
---
drivers/net/ethernet/cadence/macb.h | 18 +++++++----
drivers/net/ethernet/cadence/macb_main.c | 53 +++++++++-----------------------
drivers/net/ethernet/cadence/macb_ptp.c | 8 ++---
3 files changed, 31 insertions(+), 48 deletions(-)
diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h
index ed015c4d4a33746b7ed6e32127bc04318da946c8..aa29eaac109acb2771e5732b59362dd28fcafa47 100644
--- a/drivers/net/ethernet/cadence/macb.h
+++ b/drivers/net/ethernet/cadence/macb.h
@@ -15,10 +15,6 @@
#include <linux/phy/phy.h>
#include <linux/workqueue.h>
-#if defined(CONFIG_ARCH_DMA_ADDR_T_64BIT) || defined(CONFIG_MACB_USE_HWSTAMP)
-#define MACB_EXT_DESC
-#endif
-
#define MACB_GREGS_NBR 16
#define MACB_GREGS_VERSION 2
#define MACB_MAX_QUEUES 8
@@ -826,7 +822,6 @@ struct macb_dma_desc {
u32 ctrl;
};
-#ifdef MACB_EXT_DESC
struct macb_dma_desc_64 {
u32 addrh;
u32 resvd;
@@ -836,7 +831,6 @@ struct macb_dma_desc_ptp {
u32 ts_1;
u32 ts_2;
};
-#endif
/* DMA descriptor bitfields */
#define MACB_RX_USED_OFFSET 0
@@ -1390,6 +1384,18 @@ static inline bool gem_has_ptp(struct macb *bp)
return IS_ENABLED(CONFIG_MACB_USE_HWSTAMP) && (bp->caps & MACB_CAPS_GEM_HAS_PTP);
}
+static inline bool macb_dma64(struct macb *bp)
+{
+ return IS_ENABLED(CONFIG_ARCH_DMA_ADDR_T_64BIT) &&
+ bp->caps & MACB_CAPS_DMA_64B;
+}
+
+static inline bool macb_dma_ptp(struct macb *bp)
+{
+ return IS_ENABLED(CONFIG_MACB_USE_HWSTAMP) &&
+ bp->caps & MACB_CAPS_DMA_PTP;
+}
+
/**
* struct macb_platform_data - platform data for MACB Ethernet used for PCI registration
* @pclk: platform clock
diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index 52c3a352519c3f68403d859932d26b536a01affb..15fd940c684f50c983c32e94a0856d42d9ece161 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -122,35 +122,24 @@ static unsigned int macb_dma_desc_get_size(struct macb *bp)
{
unsigned int desc_size = sizeof(struct macb_dma_desc);
-#ifdef MACB_EXT_DESC
- if (bp->caps & MACB_CAPS_DMA_64B)
+ if (macb_dma64(bp))
desc_size += sizeof(struct macb_dma_desc_64);
- if (bp->caps & MACB_CAPS_DMA_PTP)
+ if (macb_dma_ptp(bp))
desc_size += sizeof(struct macb_dma_desc_ptp);
-#endif
return desc_size;
}
static unsigned int macb_adj_dma_desc_idx(struct macb *bp, unsigned int desc_idx)
{
-#ifdef MACB_EXT_DESC
- bool is_ptp = bp->caps & MACB_CAPS_DMA_PTP;
- bool is_64b = bp->caps & MACB_CAPS_DMA_64B;
-
- return desc_idx * (1 + is_64b + is_ptp);
-#else
- return desc_idx;
-#endif
+ return desc_idx * (1 + macb_dma64(bp) + macb_dma_ptp(bp));
}
-#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
static struct macb_dma_desc_64 *macb_64b_desc(struct macb *bp, struct macb_dma_desc *desc)
{
return (struct macb_dma_desc_64 *)((void *)desc
+ sizeof(struct macb_dma_desc));
}
-#endif
/* Ring buffer accessors */
static unsigned int macb_tx_ring_wrap(struct macb *bp, unsigned int index)
@@ -472,13 +461,11 @@ static void macb_init_buffers(struct macb *bp)
struct macb_queue *queue;
unsigned int q;
-#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
/* Single register for all queues' high 32 bits. */
- if (bp->caps & MACB_CAPS_DMA_64B) {
+ if (macb_dma64(bp)) {
macb_writel(bp, RBQPH, upper_32_bits(bp->queues[0].rx_ring_dma));
macb_writel(bp, TBQPH, upper_32_bits(bp->queues[0].tx_ring_dma));
}
-#endif
for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) {
queue_writel(queue, RBQP, lower_32_bits(queue->rx_ring_dma));
@@ -1003,10 +990,9 @@ static void macb_tx_unmap(struct macb *bp, struct macb_tx_skb *tx_skb, int budge
static void macb_set_addr(struct macb *bp, struct macb_dma_desc *desc, dma_addr_t addr)
{
-#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
- struct macb_dma_desc_64 *desc_64;
+ if (macb_dma64(bp)) {
+ struct macb_dma_desc_64 *desc_64;
- if (bp->caps & MACB_CAPS_DMA_64B) {
desc_64 = macb_64b_desc(bp, desc);
desc_64->addrh = upper_32_bits(addr);
/* The low bits of RX address contain the RX_USED bit, clearing
@@ -1015,26 +1001,23 @@ static void macb_set_addr(struct macb *bp, struct macb_dma_desc *desc, dma_addr_
*/
dma_wmb();
}
-#endif
+
desc->addr = lower_32_bits(addr);
}
static dma_addr_t macb_get_addr(struct macb *bp, struct macb_dma_desc *desc)
{
dma_addr_t addr = 0;
-#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
- struct macb_dma_desc_64 *desc_64;
+ if (macb_dma64(bp)) {
+ struct macb_dma_desc_64 *desc_64;
- if (bp->caps & MACB_CAPS_DMA_64B) {
desc_64 = macb_64b_desc(bp, desc);
addr = ((u64)(desc_64->addrh) << 32);
}
-#endif
+
addr |= MACB_BF(RX_WADDR, MACB_BFEXT(RX_WADDR, desc->addr));
-#ifdef CONFIG_MACB_USE_HWSTAMP
- if (bp->caps & MACB_CAPS_DMA_PTP)
+ if (macb_dma_ptp(bp))
addr &= ~GEM_BIT(DMA_RXVALID);
-#endif
return addr;
}
@@ -2302,11 +2285,9 @@ static netdev_tx_t macb_start_xmit(struct sk_buff *skb, struct net_device *dev)
return ret;
}
-#ifdef CONFIG_MACB_USE_HWSTAMP
if ((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
- (bp->caps & MACB_CAPS_DMA_PTP))
+ macb_dma_ptp(bp))
skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
-#endif
is_lso = (skb_shinfo(skb)->gso_size != 0);
@@ -2783,14 +2764,10 @@ static void macb_configure_dma(struct macb *bp)
dmacfg &= ~GEM_BIT(TXCOEN);
dmacfg &= ~GEM_BIT(ADDR64);
-#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
- if (bp->caps & MACB_CAPS_DMA_64B)
+ if (macb_dma64(bp))
dmacfg |= GEM_BIT(ADDR64);
-#endif
-#ifdef CONFIG_MACB_USE_HWSTAMP
- if (bp->caps & MACB_CAPS_DMA_PTP)
+ if (macb_dma_ptp(bp))
dmacfg |= GEM_BIT(RXEXT) | GEM_BIT(TXEXT);
-#endif
netdev_dbg(bp->dev, "Cadence configure DMA with 0x%08x\n",
dmacfg);
gem_writel(bp, DMACFG, dmacfg);
@@ -3568,7 +3545,7 @@ static int gem_get_ts_info(struct net_device *dev,
{
struct macb *bp = netdev_priv(dev);
- if (!(bp->caps & MACB_CAPS_DMA_PTP)) {
+ if (!macb_dma_ptp(bp)) {
ethtool_op_get_ts_info(dev, info);
return 0;
}
diff --git a/drivers/net/ethernet/cadence/macb_ptp.c b/drivers/net/ethernet/cadence/macb_ptp.c
index f4ab379f28493cffe30275fd335844ae2fefc89a..c9e77819196e17a5b88f6dab77dadabfe087a1bd 100644
--- a/drivers/net/ethernet/cadence/macb_ptp.c
+++ b/drivers/net/ethernet/cadence/macb_ptp.c
@@ -28,10 +28,10 @@
static struct macb_dma_desc_ptp *macb_ptp_desc(struct macb *bp,
struct macb_dma_desc *desc)
{
- if (!(bp->caps & MACB_CAPS_DMA_PTP))
+ if (!macb_dma_ptp(bp))
return NULL;
- if (bp->caps & MACB_CAPS_DMA_64B)
+ if (macb_dma64(bp))
return (struct macb_dma_desc_ptp *)
((u8 *)desc + sizeof(struct macb_dma_desc)
+ sizeof(struct macb_dma_desc_64));
@@ -382,7 +382,7 @@ int gem_get_hwtst(struct net_device *dev,
struct macb *bp = netdev_priv(dev);
*tstamp_config = bp->tstamp_config;
- if (!(bp->caps & MACB_CAPS_DMA_PTP))
+ if (!macb_dma_ptp(bp))
return -EOPNOTSUPP;
return 0;
@@ -409,7 +409,7 @@ int gem_set_hwtst(struct net_device *dev,
struct macb *bp = netdev_priv(dev);
u32 regval;
- if (!(bp->caps & MACB_CAPS_DMA_PTP))
+ if (!macb_dma_ptp(bp))
return -EOPNOTSUPP;
switch (tstamp_config->tx_type) {
--
2.50.1
next prev parent reply other threads:[~2025-08-08 16:52 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-08 16:52 [PATCH net v3 00/16] net: macb: various fixes & cleanup Théo Lebrun
2025-08-08 16:52 ` [PATCH net v3 01/16] dt-bindings: net: cdns,macb: allow tsu_clk without tx_clk Théo Lebrun
2025-08-08 16:52 ` [PATCH net v3 02/16] dt-bindings: net: cdns,macb: sort compatibles Théo Lebrun
2025-08-08 16:52 ` [PATCH net v3 03/16] net: macb: remove illusion about TBQPH/RBQPH being per-queue Théo Lebrun
2025-08-08 16:52 ` [PATCH net v3 04/16] net: macb: move ring size computation to functions Théo Lebrun
2025-08-08 16:52 ` [PATCH net v3 05/16] net: macb: single dma_alloc_coherent() for DMA descriptors Théo Lebrun
2025-08-08 16:52 ` [PATCH net v3 06/16] net: macb: match skb_reserve(skb, NET_IP_ALIGN) with HW alignment Théo Lebrun
2025-08-08 16:52 ` [PATCH net v3 07/16] net: macb: avoid double endianness swap in macb_set_hwaddr() Théo Lebrun
2025-08-08 16:52 ` [PATCH net v3 08/16] net: macb: use BIT() macro for capability definitions Théo Lebrun
2025-08-08 16:52 ` [PATCH net v3 09/16] net: macb: remove gap in MACB_CAPS_* flags Théo Lebrun
2025-08-08 16:52 ` [PATCH net v3 10/16] net: macb: Remove local variables clk_init and init in macb_probe() Théo Lebrun
2025-08-08 16:52 ` [PATCH net v3 11/16] net: macb: drop macb_config NULL checking Théo Lebrun
2025-08-08 16:52 ` [PATCH net v3 12/16] net: macb: simplify macb_dma_desc_get_size() Théo Lebrun
2025-08-08 16:52 ` [PATCH net v3 13/16] net: macb: simplify macb_adj_dma_desc_idx() Théo Lebrun
2025-08-08 16:52 ` [PATCH net v3 14/16] net: macb: move bp->hw_dma_cap flags to bp->caps Théo Lebrun
2025-08-08 16:52 ` Théo Lebrun [this message]
2025-08-08 16:52 ` [PATCH net v3 16/16] net: macb: sort #includes Théo Lebrun
2025-08-08 23:06 ` [PATCH net v3 00/16] net: macb: various fixes & cleanup Jakub Kicinski
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=20250808-macb-fixes-v3-15-08f1fcb5179f@bootlin.com \
--to=theo.lebrun@bootlin.com \
--cc=andrew+netdev@lunn.ch \
--cc=claudiu.beznea@tuxon.dev \
--cc=conor+dt@kernel.org \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=edumazet@google.com \
--cc=geert@linux-m68k.org \
--cc=harini.katakam@xilinx.com \
--cc=krzk+dt@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=nicolas.ferre@microchip.com \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=robh@kernel.org \
--cc=tawfik.bayouk@mobileye.com \
--cc=thomas.petazzoni@bootlin.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).