// SPDX-License-Identifier: GPL-2.0
/*
* Broadcom STB ASP 2.0 Driver
*
* Copyright (c) 2023 Broadcom
*/
#include <linux/etherdevice.h>
#include <linux/if_vlan.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/platform_device.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/of_platform.h>
#include <linux/clk.h>
#include "bcmasp.h"
#include "bcmasp_intf_defs.h"
static void _intr2_mask_clear(struct bcmasp_priv *priv, u32 mask)
{
intr2_core_wl(priv, mask, ASP_INTR2_MASK_CLEAR);
priv->irq_mask &= ~mask;
}
static void _intr2_mask_set(struct bcmasp_priv *priv, u32 mask)
{
intr2_core_wl(priv, mask, ASP_INTR2_MASK_SET);
priv->irq_mask |= mask;
}
void bcmasp_enable_phy_irq(struct bcmasp_intf *intf, int en)
{
struct bcmasp_priv *priv = intf->parent;
/* Only supported with internal phys */
if (!intf->internal_phy)
return;
if (en)
_intr2_mask_clear(priv, ASP_INTR2_PHY_EVENT(intf->channel));
else
_intr2_mask_set(priv, ASP_INTR2_PHY_EVENT(intf->channel));
}
void bcmasp_enable_tx_irq(struct bcmasp_intf *intf, int en)
{
struct bcmasp_priv *priv = intf->parent;
if (en)
_intr2_mask_clear(priv, ASP_INTR2_TX_DESC(intf->channel));
else
_intr2_mask_set(priv, ASP_INTR2_TX_DESC(intf->channel));
}
EXPORT_SYMBOL_GPL(bcmasp_enable_tx_irq);
void bcmasp_enable_rx_irq(struct bcmasp_intf *intf, int en)
{
struct bcmasp_priv *priv = intf->parent;
if (en)
_intr2_mask_clear(priv, ASP_INTR2_RX_ECH(intf->channel));
else
_intr2_mask_set(priv, ASP_INTR2_RX_ECH(intf->channel));
}
EXPORT_SYMBOL_GPL(bcmasp_enable_rx_irq);
static void bcmasp_intr2_mask_set_all(struct bcmasp_priv *priv)
{
_intr2_mask_set(priv, 0xffffffff);
priv->irq_mask = 0xffffffff;
}
static void bcmasp_intr2_clear_all(struct bcmasp_priv *priv)
{
intr2_core_wl(priv, 0xffffffff, ASP_INTR2_CLEAR);
}
static void bcmasp_intr2_handling(struct bcmasp_intf *intf, u32 status)
{
if (status & ASP_INTR2_RX_ECH(intf->channel)) {
if (likely(napi_schedule_prep(&intf->rx_napi))) {
bcmasp_enable_rx_irq(intf, 0);
__napi_schedule_irqoff(&intf->rx_napi);
}
}
if (status & ASP_INTR2_TX_DESC(intf->channel)) {
if (likely(napi_schedule_prep(&intf->tx_napi))) {
bcmasp_enable_tx_irq(intf, 0);
__napi_schedule_irqoff(&intf->tx_napi);
}
}
if (status & ASP_INTR2_PHY_EVENT(intf->channel))
phy_mac_interrupt(intf->ndev->phydev);
}
static irqreturn_t bcmasp_isr(int irq, void *data)
{
struct bcmasp_priv *priv = data;
struct bcmasp_intf *intf;
u32 status;
status = intr2_core_rl(priv, ASP_INTR2_STATUS) &
~intr2_core_rl(priv, ASP_INTR2_MASK_STATUS);
intr2_core_wl(priv, status, ASP_INTR2_CLEAR);
if (unlikely(status == 0)) {
dev_warn(&priv->pdev->dev, "l2 spurious interrupt\n");
return IRQ_NONE;
}
/* Handle intferfaces */
list_for_each_entry(intf, &priv->intfs, list)
bcmasp_intr2_handling(intf, status);
return IRQ_HANDLED;
}
void bcmasp_flush_rx_port(struct bcmasp_intf *intf)
{
struct bcmasp_priv *priv = intf->parent;
u32 mask;
switch (intf->port) {
case 0:
mask = ASP_CTRL_UMAC0_FLUSH_MASK;
break;
case 1:
mask = ASP_CTRL_UMAC1_FLUSH_MASK;
break;
case 2:
mask = ASP_CTRL_SPB_FLUSH_MASK;
break;
default:
/* Not valid port */
return;
}
rx_ctrl_core_wl(priv, mask, priv->hw_info->rx_ctrl_flush);
}
static void bcmasp_netfilt_hw_en_wake(struct bcmasp_priv *priv,
struct bcmasp_net_filter *nfilt)
{
rx_filter_core_wl(priv, ASP_RX_FILTER_NET_OFFSET_L3_1(64),
ASP_RX_FILTER_NET_OFFSET(nfilt->hw_index));
rx_filter_core_wl(priv, ASP_RX_FILTER_NET_OFFSET_L2(32) |
ASP_RX_FILTER_NET_OFFSET_L3_0(32) |
ASP_RX_FILTER_NET_OFFSET_L3_1(96) |
ASP_RX_FILTER_NET_OFFSET_L4(32),
ASP_RX_FILTER_NET_OFFSET(nfilt->hw_index + 1));
rx_filter_core_wl(priv, ASP_RX_FILTER_NET_CFG_CH(nfilt->port + 8) |
ASP_RX_FILTER_NET_CFG_EN |
ASP_RX_FILTER_NET_CFG_L2_EN |
ASP_RX_FILTER_NET_CFG_L3_EN |
ASP_RX_FILTER_NET_CFG_L4_EN |
ASP_RX_FILTER_NET_CFG_L3_FRM(2) |
ASP_RX_FILTER_NET_CFG_L4_FRM(2) |
ASP_RX_FILTER_NET_CFG_UMC(nfilt->port),
ASP_RX_FILTER_NET_CFG(nfilt->hw_index));
rx_filter_core_wl(priv, ASP_RX_FILTER_NET_CFG_CH(nfilt->port + 8) |
ASP_RX_FILTER_NET_CFG_EN |
ASP_RX_FILTER_NET_CFG_L2_EN |
ASP_RX_FILTER_NET_CFG_L3_EN |
ASP_RX_FILTER_NET_CFG_L4_EN |
ASP_RX_FILTER_NET_CFG_L3_FRM(2) |
ASP_RX_FILTER_NET_CFG_L4_FRM(2) |
ASP_RX_FILTER_NET_CFG_UMC(nfilt->port),
ASP_RX_FILTER_NET_CFG(nfilt->hw_index + 1));
}
#define MAX_WAKE_FILTER_SIZE 256
enum asp_netfilt_reg_type {
ASP_NETFILT_MATCH = 0,
ASP_NETFILT_MASK,
ASP_NETFILT_MAX
};
static int bcmasp_netfilt_get_reg_offset(struct bcmasp_priv *priv,
struct bcmasp_net_filter *nfilt,
enum asp_netfilt_reg_type reg_type,
u32 offset)
{
u32 block_index, filter_sel;
if (offset < 32) {
block_index = ASP_RX_FILTER_NET_L2;
filter_sel = nfilt->hw_index;
} else if (offset < 64) {
block_index = ASP_RX_FILTER_NET_L2;
filter_sel = nfilt->hw_index + 1;
} else if (offset < 96) {
block_index = ASP_RX_FILTER_NET_L3_0;
filter_sel = nfilt->hw_index;
} else if (offset < 128) {
block_index = ASP_RX_FILTER_NET_L3_0;
filter_sel = nfilt->hw_index + 1;
} else if (offset < 160) {
block_index = ASP_RX_FILTER_NET_L3_1;
filter_sel = nfilt->hw_index;
} else if (offset < 192) {
block_index = ASP_RX_FILTER_NET_L3_1;
filter_sel = nfilt->hw_index + 1;
} else if (offset < 224) {
block_index = ASP_RX_FILTER_NET_L4;
filter_sel = nfilt->hw_index;
} else if (offset < 256) {
block_index = ASP_RX_FILTER_NET_L4;
filter_sel = nfilt->hw_index + 1;
} else {
return -EINVAL;
}
switch (reg_type) {
case ASP_NETFILT_MATCH:
return ASP_RX_FILTER_NET_PAT(filter_sel, block_index,
(offset % 32));
case ASP_NETFILT_MASK:
return ASP_RX_FILTER_NET_MASK(filter_sel, block_index,
(offset % 32));
default:
return -EINVAL;
}
}
static void bcmasp_netfilt_wr(struct bcmasp_priv *priv,
struct bcmasp_net_filter *nfilt,
enum asp_netfilt_reg_type reg_type,
u32 val, u32 offset)
{
int reg_offset;
/* HW only accepts 4 byte aligned writes */
if (!IS_ALIGNED(offset, 4) || offset > MAX_WAKE_FILTER_SIZE)
return;
reg_offset = bcmasp_netfilt_get_reg_offset(priv, nfilt, reg_type,
offset);
rx_filter_core_wl(priv, val, reg_offset);
}
static u32 bcmasp_netfilt_rd(struct bcmasp_priv *priv,
struct bcmasp_net_filter *nfilt,
enum asp_netfilt_reg_type reg_type,
u32 offset)
{
int reg_offset;
/* HW only accepts 4 byte aligned writes */
if (!IS_ALIGNED(offset, 4) || offset > MAX_WAKE_FILTER_SIZE)
return 0;
reg_offset = bcmasp_netfilt_get_reg_offset(priv, nfilt, reg_type,
offset);
return rx_filter_core_rl(priv, reg_offset);
}
static int bcmasp_netfilt_wr_m_wake(struct bcmasp_priv *priv,
struct bcmasp_net_filter *nfilt,
u32 offset, void *match, void *mask,
size_t size)
{
u32 shift, mask_val = 0, match_val = 0;
bool first_byte = true;
if ((offset + size) > MAX_WAKE_FILTER_SIZE)
return -EINVAL;
while (size--) {
/* The HW only accepts 4 byte aligned writes, so if we
* begin unaligned or if remaining bytes less than 4,
* we need to read then write to avoid losing current
* re
|