realtek: eth: introduce regmap
The ethernet driver currently uses the legacy sw() macros. Add a regmap to the driver that is derived from the parent mfd (like in the mdio drivers). As a first consumer make use of that in the IRQ functions. Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de> Link: https://github.com/openwrt/openwrt/pull/22757 Signed-off-by: Robert Marko <robimarko@gmail.com>
This commit is contained in:
committed by
Robert Marko
parent
6c3c959b1b
commit
99a0cf9c44
@@ -8,6 +8,7 @@
|
||||
#include <linux/etherdevice.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/mfd/syscon.h>
|
||||
#include <linux/minmax.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/sched.h>
|
||||
@@ -18,6 +19,7 @@
|
||||
#include <linux/module.h>
|
||||
#include <linux/phylink.h>
|
||||
#include <linux/pkt_sched.h>
|
||||
#include <linux/regmap.h>
|
||||
#include <net/dsa.h>
|
||||
#include <net/switchdev.h>
|
||||
|
||||
@@ -142,6 +144,7 @@ struct rtl838x_rx_q {
|
||||
};
|
||||
|
||||
struct rteth_ctrl {
|
||||
struct regmap *map;
|
||||
struct net_device *netdev;
|
||||
struct platform_device *pdev;
|
||||
void *membase;
|
||||
@@ -168,10 +171,12 @@ static inline void rteth_reenable_irq(struct rteth_ctrl *ctrl, int ring)
|
||||
{
|
||||
u32 shift = ctrl->r->rx_rings % 32;
|
||||
u32 reg = ctrl->r->rx_rings / 32;
|
||||
u32 bit = BIT(ring + shift);
|
||||
unsigned long flags;
|
||||
|
||||
/* locking needed for synchronization with rteth_confirm_and_disable_irqs() */
|
||||
spin_lock_irqsave(&ctrl->lock, flags);
|
||||
sw_w32_mask(0, BIT(ring + shift), ctrl->r->dma_if_intr_msk + reg * 4);
|
||||
regmap_update_bits(ctrl->map, ctrl->r->dma_if_intr_msk + reg * 4, bit, bit);
|
||||
spin_unlock_irqrestore(&ctrl->lock, flags);
|
||||
}
|
||||
|
||||
@@ -186,9 +191,10 @@ static inline void rteth_confirm_and_disable_irqs(struct rteth_ctrl *ctrl,
|
||||
|
||||
/* get all irqs, disable only rx (on RTL839x this keeps L2), confirm all */
|
||||
spin_lock_irqsave(&ctrl->lock, flags);
|
||||
active = sw_r32(ctrl->r->dma_if_intr_sts + reg * 4);
|
||||
sw_w32_mask(active & (mask << shift), 0, ctrl->r->dma_if_intr_msk + reg * 4);
|
||||
sw_w32(active, ctrl->r->dma_if_intr_sts + reg * 4);
|
||||
regmap_read(ctrl->map, ctrl->r->dma_if_intr_sts + reg * 4, &active);
|
||||
regmap_update_bits(ctrl->map, ctrl->r->dma_if_intr_msk + reg * 4,
|
||||
active & (mask << shift), 0);
|
||||
regmap_write(ctrl->map, ctrl->r->dma_if_intr_sts + reg * 4, active);
|
||||
spin_unlock_irqrestore(&ctrl->lock, flags);
|
||||
|
||||
/* ~mask filters out RTL93xx devices */
|
||||
@@ -201,33 +207,31 @@ static void rteth_disable_all_irqs(struct rteth_ctrl *ctrl)
|
||||
int registers = ((ctrl->r->rx_rings * 2 + 7) / 32) + 1;
|
||||
|
||||
for (int reg = 0; reg < registers; reg++) {
|
||||
sw_w32(0, ctrl->r->dma_if_intr_msk + reg * 4);
|
||||
sw_w32(GENMASK(31, 0), ctrl->r->dma_if_intr_sts + reg * 4);
|
||||
regmap_write(ctrl->map, ctrl->r->dma_if_intr_msk + reg * 4, 0);
|
||||
regmap_write(ctrl->map, ctrl->r->dma_if_intr_sts + reg * 4, GENMASK(31, 0));
|
||||
}
|
||||
}
|
||||
|
||||
static void rteth_enable_all_rx_irqs(struct rteth_ctrl *ctrl)
|
||||
{
|
||||
int mask, shift, reg;
|
||||
int mask, reg;
|
||||
|
||||
/*
|
||||
* The hardware has several types of interrupts. Basically for rx/tx completion and
|
||||
* if hardware queues run out. For now the driver only needs notification about new
|
||||
* incoming packets. Leave everything else disabled.
|
||||
*/
|
||||
mask = GENMASK(ctrl->r->rx_rings - 1, 0);
|
||||
shift = ctrl->r->rx_rings % 32;
|
||||
mask = GENMASK(ctrl->r->rx_rings - 1, 0) << (ctrl->r->rx_rings % 32);
|
||||
reg = ctrl->r->rx_rings / 32;
|
||||
sw_w32_mask(0, mask << shift, ctrl->r->dma_if_intr_msk + reg * 4);
|
||||
regmap_update_bits(ctrl->map, ctrl->r->dma_if_intr_msk + reg * 4, mask, mask);
|
||||
|
||||
/*
|
||||
* RTL839x has additional L2 notification interrupts. Simply activate them. All other
|
||||
* devices that do not have the feature have adequate reserved bit space and ignore it.
|
||||
*/
|
||||
mask = GENMASK(2, 0);
|
||||
shift = (ctrl->r->rx_rings * 2 + 4) % 32;
|
||||
mask = GENMASK(2, 0) << ((ctrl->r->rx_rings * 2 + 4) % 32);
|
||||
reg = (ctrl->r->rx_rings * 2 + 4) / 32;
|
||||
sw_w32_mask(0, mask << shift, ctrl->r->dma_if_intr_msk + reg * 4);
|
||||
regmap_update_bits(ctrl->map, ctrl->r->dma_if_intr_msk + reg * 4, mask, mask);
|
||||
}
|
||||
|
||||
static void rteth_83xx_update_counter(struct rteth_ctrl *ctrl, int ring, int released)
|
||||
@@ -1478,6 +1482,9 @@ static int rteth_probe(struct platform_device *pdev)
|
||||
SET_NETDEV_DEV(dev, &pdev->dev);
|
||||
ctrl = netdev_priv(dev);
|
||||
ctrl->r = cfg;
|
||||
ctrl->map = syscon_node_to_regmap(dn->parent);
|
||||
if (IS_ERR(ctrl->map))
|
||||
return PTR_ERR(ctrl->map);
|
||||
|
||||
/* Allocate buffer memory */
|
||||
ctrl->membase = dmam_alloc_coherent(&pdev->dev, sizeof(struct notify_b),
|
||||
|
||||
Reference in New Issue
Block a user