From: "Théo Lebrun" <theo.lebrun@bootlin.com>
To: Nicolas Ferre <nicolas.ferre@microchip.com>,
Claudiu Beznea <claudiu.beznea@tuxon.dev>,
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>,
Richard Cochran <richardcochran@gmail.com>,
Russell King <linux@armlinux.org.uk>
Cc: "Paolo Valerio" <pvalerio@redhat.com>,
"Conor Dooley" <conor@kernel.org>,
"Nicolai Buchwitz" <nb@tipi-net.de>,
"Vladimir Kondratiev" <vladimir.kondratiev@mobileye.com>,
"Gregory CLEMENT" <gregory.clement@bootlin.com>,
"Benoît Monin" <benoit.monin@bootlin.com>,
"Tawfik Bayouk" <tawfik.bayouk@mobileye.com>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
"Maxime Chevallier" <maxime.chevallier@bootlin.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
"Théo Lebrun" <theo.lebrun@bootlin.com>
Subject: [PATCH net-next v2 02/14] net: macb: unify `struct macb *` naming convention
Date: Fri, 10 Apr 2026 21:51:50 +0200 [thread overview]
Message-ID: <20260410-macb-context-v2-2-af39f71d40b6@bootlin.com> (raw)
In-Reply-To: <20260410-macb-context-v2-0-af39f71d40b6@bootlin.com>
For historical reason, MACB has both:
struct macb *bp;
struct macb *lp; // used in at91ether functions
Use only the former.
Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
---
drivers/net/ethernet/cadence/macb_main.c | 176 ++++++++++++++++---------------
1 file changed, 91 insertions(+), 85 deletions(-)
diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index 896d481e0f95..a8a7df615d25 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -4938,71 +4938,72 @@ static const struct macb_usrio_config at91_default_usrio = {
static struct sifive_fu540_macb_mgmt *mgmt;
-static int at91ether_alloc_coherent(struct macb *lp)
+static int at91ether_alloc_coherent(struct macb *bp)
{
- struct macb_queue *q = &lp->queues[0];
+ struct macb_queue *queue = &bp->queues[0];
- q->rx_ring = dma_alloc_coherent(&lp->pdev->dev,
- (AT91ETHER_MAX_RX_DESCR *
- macb_dma_desc_get_size(lp)),
- &q->rx_ring_dma, GFP_KERNEL);
- if (!q->rx_ring)
+ queue->rx_ring = dma_alloc_coherent(&bp->pdev->dev,
+ (AT91ETHER_MAX_RX_DESCR *
+ macb_dma_desc_get_size(bp)),
+ &queue->rx_ring_dma, GFP_KERNEL);
+ if (!queue->rx_ring)
return -ENOMEM;
- q->rx_buffers = dma_alloc_coherent(&lp->pdev->dev,
- AT91ETHER_MAX_RX_DESCR *
- AT91ETHER_MAX_RBUFF_SZ,
- &q->rx_buffers_dma, GFP_KERNEL);
- if (!q->rx_buffers) {
- dma_free_coherent(&lp->pdev->dev,
+ queue->rx_buffers = dma_alloc_coherent(&bp->pdev->dev,
+ AT91ETHER_MAX_RX_DESCR *
+ AT91ETHER_MAX_RBUFF_SZ,
+ &queue->rx_buffers_dma,
+ GFP_KERNEL);
+ if (!queue->rx_buffers) {
+ dma_free_coherent(&bp->pdev->dev,
AT91ETHER_MAX_RX_DESCR *
- macb_dma_desc_get_size(lp),
- q->rx_ring, q->rx_ring_dma);
- q->rx_ring = NULL;
+ macb_dma_desc_get_size(bp),
+ queue->rx_ring, queue->rx_ring_dma);
+ queue->rx_ring = NULL;
return -ENOMEM;
}
return 0;
}
-static void at91ether_free_coherent(struct macb *lp)
+static void at91ether_free_coherent(struct macb *bp)
{
- struct macb_queue *q = &lp->queues[0];
+ struct macb_queue *queue = &bp->queues[0];
- if (q->rx_ring) {
- dma_free_coherent(&lp->pdev->dev,
+ if (queue->rx_ring) {
+ dma_free_coherent(&bp->pdev->dev,
AT91ETHER_MAX_RX_DESCR *
- macb_dma_desc_get_size(lp),
- q->rx_ring, q->rx_ring_dma);
- q->rx_ring = NULL;
+ macb_dma_desc_get_size(bp),
+ queue->rx_ring, queue->rx_ring_dma);
+ queue->rx_ring = NULL;
}
- if (q->rx_buffers) {
- dma_free_coherent(&lp->pdev->dev,
+ if (queue->rx_buffers) {
+ dma_free_coherent(&bp->pdev->dev,
AT91ETHER_MAX_RX_DESCR *
AT91ETHER_MAX_RBUFF_SZ,
- q->rx_buffers, q->rx_buffers_dma);
- q->rx_buffers = NULL;
+ queue->rx_buffers, queue->rx_buffers_dma);
+ queue->rx_buffers = NULL;
}
}
/* Initialize and start the Receiver and Transmit subsystems */
-static int at91ether_start(struct macb *lp)
+static int at91ether_start(struct macb *bp)
{
- struct macb_queue *q = &lp->queues[0];
+ struct macb_queue *queue = &bp->queues[0];
struct macb_dma_desc *desc;
dma_addr_t addr;
u32 ctl;
int i, ret;
- ret = at91ether_alloc_coherent(lp);
+ ret = at91ether_alloc_coherent(bp);
if (ret)
return ret;
- addr = q->rx_buffers_dma;
+ addr = queue->rx_buffers_dma;
for (i = 0; i < AT91ETHER_MAX_RX_DESCR; i++) {
- desc = macb_rx_desc(q, i);
- macb_set_addr(lp, desc, addr);
+ desc = macb_rx_desc(queue, i);
+ macb_set_addr(bp, desc, addr);
desc->ctrl = 0;
addr += AT91ETHER_MAX_RBUFF_SZ;
}
@@ -5011,17 +5012,17 @@ static int at91ether_start(struct macb *lp)
desc->addr |= MACB_BIT(RX_WRAP);
/* Reset buffer index */
- q->rx_tail = 0;
+ queue->rx_tail = 0;
/* Program address of descriptor list in Rx Buffer Queue register */
- macb_writel(lp, RBQP, q->rx_ring_dma);
+ macb_writel(bp, RBQP, queue->rx_ring_dma);
/* Enable Receive and Transmit */
- ctl = macb_readl(lp, NCR);
- macb_writel(lp, NCR, ctl | MACB_BIT(RE) | MACB_BIT(TE));
+ ctl = macb_readl(bp, NCR);
+ macb_writel(bp, NCR, ctl | MACB_BIT(RE) | MACB_BIT(TE));
/* Enable MAC interrupts */
- macb_writel(lp, IER, MACB_BIT(RCOMP) |
+ macb_writel(bp, IER, MACB_BIT(RCOMP) |
MACB_BIT(RXUBR) |
MACB_BIT(ISR_TUND) |
MACB_BIT(ISR_RLE) |
@@ -5032,12 +5033,12 @@ static int at91ether_start(struct macb *lp)
return 0;
}
-static void at91ether_stop(struct macb *lp)
+static void at91ether_stop(struct macb *bp)
{
u32 ctl;
/* Disable MAC interrupts */
- macb_writel(lp, IDR, MACB_BIT(RCOMP) |
+ macb_writel(bp, IDR, MACB_BIT(RCOMP) |
MACB_BIT(RXUBR) |
MACB_BIT(ISR_TUND) |
MACB_BIT(ISR_RLE) |
@@ -5046,35 +5047,35 @@ static void at91ether_stop(struct macb *lp)
MACB_BIT(HRESP));
/* Disable Receiver and Transmitter */
- ctl = macb_readl(lp, NCR);
- macb_writel(lp, NCR, ctl & ~(MACB_BIT(TE) | MACB_BIT(RE)));
+ ctl = macb_readl(bp, NCR);
+ macb_writel(bp, NCR, ctl & ~(MACB_BIT(TE) | MACB_BIT(RE)));
/* Free resources. */
- at91ether_free_coherent(lp);
+ at91ether_free_coherent(bp);
}
/* Open the ethernet interface */
static int at91ether_open(struct net_device *netdev)
{
- struct macb *lp = netdev_priv(netdev);
+ struct macb *bp = netdev_priv(netdev);
u32 ctl;
int ret;
- ret = pm_runtime_resume_and_get(&lp->pdev->dev);
+ ret = pm_runtime_resume_and_get(&bp->pdev->dev);
if (ret < 0)
return ret;
/* Clear internal statistics */
- ctl = macb_readl(lp, NCR);
- macb_writel(lp, NCR, ctl | MACB_BIT(CLRSTAT));
+ ctl = macb_readl(bp, NCR);
+ macb_writel(bp, NCR, ctl | MACB_BIT(CLRSTAT));
- macb_set_hwaddr(lp);
+ macb_set_hwaddr(bp);
- ret = at91ether_start(lp);
+ ret = at91ether_start(bp);
if (ret)
goto pm_exit;
- ret = macb_phylink_connect(lp);
+ ret = macb_phylink_connect(bp);
if (ret)
goto stop;
@@ -5083,25 +5084,25 @@ static int at91ether_open(struct net_device *netdev)
return 0;
stop:
- at91ether_stop(lp);
+ at91ether_stop(bp);
pm_exit:
- pm_runtime_put_sync(&lp->pdev->dev);
+ pm_runtime_put_sync(&bp->pdev->dev);
return ret;
}
/* Close the interface */
static int at91ether_close(struct net_device *netdev)
{
- struct macb *lp = netdev_priv(netdev);
+ struct macb *bp = netdev_priv(netdev);
netif_stop_queue(netdev);
- phylink_stop(lp->phylink);
- phylink_disconnect_phy(lp->phylink);
+ phylink_stop(bp->phylink);
+ phylink_disconnect_phy(bp->phylink);
- at91ether_stop(lp);
+ at91ether_stop(bp);
- pm_runtime_put(&lp->pdev->dev);
+ pm_runtime_put(&bp->pdev->dev);
return 0;
}
@@ -5110,19 +5111,21 @@ static int at91ether_close(struct net_device *netdev)
static netdev_tx_t at91ether_start_xmit(struct sk_buff *skb,
struct net_device *netdev)
{
- struct macb *lp = netdev_priv(netdev);
+ struct macb *bp = netdev_priv(netdev);
+ struct device *dev = &bp->pdev->dev;
- if (macb_readl(lp, TSR) & MACB_BIT(RM9200_BNQ)) {
+ if (macb_readl(bp, TSR) & MACB_BIT(RM9200_BNQ)) {
int desc = 0;
netif_stop_queue(netdev);
/* Store packet information (to free when Tx completed) */
- lp->rm9200_txq[desc].skb = skb;
- lp->rm9200_txq[desc].size = skb->len;
- lp->rm9200_txq[desc].mapping = dma_map_single(&lp->pdev->dev, skb->data,
- skb->len, DMA_TO_DEVICE);
- if (dma_mapping_error(&lp->pdev->dev, lp->rm9200_txq[desc].mapping)) {
+ bp->rm9200_txq[desc].skb = skb;
+ bp->rm9200_txq[desc].size = skb->len;
+ bp->rm9200_txq[desc].mapping = dma_map_single(dev, skb->data,
+ skb->len,
+ DMA_TO_DEVICE);
+ if (dma_mapping_error(dev, bp->rm9200_txq[desc].mapping)) {
dev_kfree_skb_any(skb);
netdev->stats.tx_dropped++;
netdev_err(netdev, "%s: DMA mapping error\n", __func__);
@@ -5130,9 +5133,9 @@ static netdev_tx_t at91ether_start_xmit(struct sk_buff *skb,
}
/* Set address of the data in the Transmit Address register */
- macb_writel(lp, TAR, lp->rm9200_txq[desc].mapping);
+ macb_writel(bp, TAR, bp->rm9200_txq[desc].mapping);
/* Set length of the packet in the Transmit Control register */
- macb_writel(lp, TCR, skb->len);
+ macb_writel(bp, TCR, skb->len);
} else {
netdev_err(netdev, "%s called, but device is busy!\n",
@@ -5148,16 +5151,17 @@ static netdev_tx_t at91ether_start_xmit(struct sk_buff *skb,
*/
static void at91ether_rx(struct net_device *netdev)
{
- struct macb *lp = netdev_priv(netdev);
- struct macb_queue *q = &lp->queues[0];
+ struct macb *bp = netdev_priv(netdev);
+ struct macb_queue *queue = &bp->queues[0];
struct macb_dma_desc *desc;
unsigned char *p_recv;
struct sk_buff *skb;
unsigned int pktlen;
- desc = macb_rx_desc(q, q->rx_tail);
+ desc = macb_rx_desc(queue, queue->rx_tail);
while (desc->addr & MACB_BIT(RX_USED)) {
- p_recv = q->rx_buffers + q->rx_tail * AT91ETHER_MAX_RBUFF_SZ;
+ p_recv = queue->rx_buffers +
+ queue->rx_tail * AT91ETHER_MAX_RBUFF_SZ;
pktlen = MACB_BF(RX_FRMLEN, desc->ctrl);
skb = netdev_alloc_skb(netdev, pktlen + 2);
if (skb) {
@@ -5179,12 +5183,12 @@ static void at91ether_rx(struct net_device *netdev)
desc->addr &= ~MACB_BIT(RX_USED);
/* wrap after last buffer */
- if (q->rx_tail == AT91ETHER_MAX_RX_DESCR - 1)
- q->rx_tail = 0;
+ if (queue->rx_tail == AT91ETHER_MAX_RX_DESCR - 1)
+ queue->rx_tail = 0;
else
- q->rx_tail++;
+ queue->rx_tail++;
- desc = macb_rx_desc(q, q->rx_tail);
+ desc = macb_rx_desc(queue, queue->rx_tail);
}
}
@@ -5192,14 +5196,14 @@ static void at91ether_rx(struct net_device *netdev)
static irqreturn_t at91ether_interrupt(int irq, void *dev_id)
{
struct net_device *netdev = dev_id;
- struct macb *lp = netdev_priv(netdev);
+ struct macb *bp = netdev_priv(netdev);
u32 intstatus, ctl;
unsigned int desc;
/* MAC Interrupt Status register indicates what interrupts are pending.
* It is automatically cleared once read.
*/
- intstatus = macb_readl(lp, ISR);
+ intstatus = macb_readl(bp, ISR);
/* Receive complete */
if (intstatus & MACB_BIT(RCOMP))
@@ -5212,23 +5216,25 @@ static irqreturn_t at91ether_interrupt(int irq, void *dev_id)
netdev->stats.tx_errors++;
desc = 0;
- if (lp->rm9200_txq[desc].skb) {
- dev_consume_skb_irq(lp->rm9200_txq[desc].skb);
- lp->rm9200_txq[desc].skb = NULL;
- dma_unmap_single(&lp->pdev->dev, lp->rm9200_txq[desc].mapping,
- lp->rm9200_txq[desc].size, DMA_TO_DEVICE);
+ if (bp->rm9200_txq[desc].skb) {
+ dev_consume_skb_irq(bp->rm9200_txq[desc].skb);
+ bp->rm9200_txq[desc].skb = NULL;
+ dma_unmap_single(&bp->pdev->dev,
+ bp->rm9200_txq[desc].mapping,
+ bp->rm9200_txq[desc].size,
+ DMA_TO_DEVICE);
netdev->stats.tx_packets++;
- netdev->stats.tx_bytes += lp->rm9200_txq[desc].size;
+ netdev->stats.tx_bytes += bp->rm9200_txq[desc].size;
}
netif_wake_queue(netdev);
}
/* Work-around for EMAC Errata section 41.3.1 */
if (intstatus & MACB_BIT(RXUBR)) {
- ctl = macb_readl(lp, NCR);
- macb_writel(lp, NCR, ctl & ~MACB_BIT(RE));
+ ctl = macb_readl(bp, NCR);
+ macb_writel(bp, NCR, ctl & ~MACB_BIT(RE));
wmb();
- macb_writel(lp, NCR, ctl | MACB_BIT(RE));
+ macb_writel(bp, NCR, ctl | MACB_BIT(RE));
}
if (intstatus & MACB_BIT(ISR_ROVR))
--
2.53.0
next prev parent reply other threads:[~2026-04-10 19:52 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-10 19:51 [PATCH net-next v2 00/14] net: macb: implement context swapping Théo Lebrun
2026-04-10 19:51 ` [PATCH net-next v2 01/14] net: macb: unify device pointer naming convention Théo Lebrun
2026-04-10 19:51 ` Théo Lebrun [this message]
2026-04-10 19:51 ` [PATCH net-next v2 03/14] net: macb: unify queue index variable naming convention and types Théo Lebrun
2026-04-10 19:51 ` [PATCH net-next v2 04/14] net: macb: enforce reverse christmas tree (RCT) convention Théo Lebrun
2026-04-10 19:51 ` [PATCH net-next v2 05/14] net: macb: allocate tieoff descriptor once across device lifetime Théo Lebrun
2026-04-10 19:51 ` [PATCH net-next v2 06/14] net: macb: introduce macb_context struct for buffer management Théo Lebrun
2026-04-10 19:51 ` [PATCH net-next v2 07/14] net: macb: avoid macb_init_rx_buffer_size() modifying state Théo Lebrun
2026-04-10 19:51 ` [PATCH net-next v2 08/14] net: macb: make `struct macb` subset reachable from macb_context struct Théo Lebrun
2026-04-10 19:51 ` [PATCH net-next v2 09/14] net: macb: change caps helpers signatures Théo Lebrun
2026-04-14 0:47 ` Jakub Kicinski
2026-04-15 13:58 ` Théo Lebrun
2026-04-10 19:51 ` [PATCH net-next v2 10/14] net: macb: change function signatures to take contexts Théo Lebrun
2026-04-10 19:51 ` [PATCH net-next v2 11/14] net: macb: introduce macb_context_alloc() helper Théo Lebrun
2026-04-10 19:52 ` [PATCH net-next v2 12/14] net: macb: re-read ISR inside IRQ handler locked section Théo Lebrun
2026-04-14 0:52 ` Jakub Kicinski
2026-04-15 14:07 ` Théo Lebrun
2026-04-10 19:52 ` [PATCH net-next v2 13/14] net: macb: use context swapping in .set_ringparam() Théo Lebrun
2026-04-14 0:50 ` Jakub Kicinski
2026-04-16 8:54 ` Théo Lebrun
2026-04-14 0:56 ` Jakub Kicinski
2026-04-22 14:00 ` Théo Lebrun
2026-04-10 19:52 ` [PATCH net-next v2 14/14] net: macb: use context swapping in .ndo_change_mtu() Théo Lebrun
2026-04-14 0:56 ` Jakub Kicinski
2026-04-22 14:35 ` Théo Lebrun
2026-04-10 19:58 ` [PATCH net-next v2 00/14] net: macb: implement context swapping Théo Lebrun
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=20260410-macb-context-v2-2-af39f71d40b6@bootlin.com \
--to=theo.lebrun@bootlin.com \
--cc=andrew+netdev@lunn.ch \
--cc=benoit.monin@bootlin.com \
--cc=claudiu.beznea@tuxon.dev \
--cc=conor@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gregory.clement@bootlin.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=maxime.chevallier@bootlin.com \
--cc=nb@tipi-net.de \
--cc=netdev@vger.kernel.org \
--cc=nicolas.ferre@microchip.com \
--cc=pabeni@redhat.com \
--cc=pvalerio@redhat.com \
--cc=richardcochran@gmail.com \
--cc=tawfik.bayouk@mobileye.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=vladimir.kondratiev@mobileye.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.