Skip to content

Commit e9f3143

Browse files
Ryceancurrykuba-moo
authored andcommitted
net: bcmasp: Add support for asp-v3.0
The asp-v3.0 is a major HW revision that reduced the number of channels and filters. The goal was to save cost by reducing the feature set. Changes for asp-v3.0 - Number of network filters were reduced. - Number of channels were reduced. - EDPKT stats were removed. - Fix a bug with csum offload. Signed-off-by: Justin Chen <justin.chen@broadcom.com> Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com> Link: https://patch.msgid.link/20250422233645.1931036-8-justin.chen@broadcom.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 9a8a737 commit e9f3143

File tree

4 files changed

+92
-48
lines changed

4 files changed

+92
-48
lines changed

drivers/net/ethernet/broadcom/asp2/bcmasp.c

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ void bcmasp_netfilt_suspend(struct bcmasp_intf *intf)
518518
int ret, i;
519519

520520
/* Write all filters to HW */
521-
for (i = 0; i < NUM_NET_FILTERS; i++) {
521+
for (i = 0; i < priv->num_net_filters; i++) {
522522
/* If the filter does not match the port, skip programming. */
523523
if (!priv->net_filters[i].claimed ||
524524
priv->net_filters[i].port != intf->port)
@@ -551,7 +551,7 @@ int bcmasp_netfilt_get_all_active(struct bcmasp_intf *intf, u32 *rule_locs,
551551
struct bcmasp_priv *priv = intf->parent;
552552
int j = 0, i;
553553

554-
for (i = 0; i < NUM_NET_FILTERS; i++) {
554+
for (i = 0; i < priv->num_net_filters; i++) {
555555
if (!priv->net_filters[i].claimed ||
556556
priv->net_filters[i].port != intf->port)
557557
continue;
@@ -577,7 +577,7 @@ int bcmasp_netfilt_get_active(struct bcmasp_intf *intf)
577577
struct bcmasp_priv *priv = intf->parent;
578578
int cnt = 0, i;
579579

580-
for (i = 0; i < NUM_NET_FILTERS; i++) {
580+
for (i = 0; i < priv->num_net_filters; i++) {
581581
if (!priv->net_filters[i].claimed ||
582582
priv->net_filters[i].port != intf->port)
583583
continue;
@@ -602,7 +602,7 @@ bool bcmasp_netfilt_check_dup(struct bcmasp_intf *intf,
602602
size_t fs_size = 0;
603603
int i;
604604

605-
for (i = 0; i < NUM_NET_FILTERS; i++) {
605+
for (i = 0; i < priv->num_net_filters; i++) {
606606
if (!priv->net_filters[i].claimed ||
607607
priv->net_filters[i].port != intf->port)
608608
continue;
@@ -670,7 +670,7 @@ struct bcmasp_net_filter *bcmasp_netfilt_get_init(struct bcmasp_intf *intf,
670670
int i, open_index = -1;
671671

672672
/* Check whether we exceed the filter table capacity */
673-
if (loc != RX_CLS_LOC_ANY && loc >= NUM_NET_FILTERS)
673+
if (loc != RX_CLS_LOC_ANY && loc >= priv->num_net_filters)
674674
return ERR_PTR(-EINVAL);
675675

676676
/* If the filter location is busy (already claimed) and we are initializing
@@ -686,7 +686,7 @@ struct bcmasp_net_filter *bcmasp_netfilt_get_init(struct bcmasp_intf *intf,
686686
/* Initialize the loop index based on the desired location or from 0 */
687687
i = loc == RX_CLS_LOC_ANY ? 0 : loc;
688688

689-
for ( ; i < NUM_NET_FILTERS; i++) {
689+
for ( ; i < priv->num_net_filters; i++) {
690690
/* Found matching network filter */
691691
if (!init &&
692692
priv->net_filters[i].claimed &&
@@ -779,7 +779,7 @@ static void bcmasp_en_mda_filter(struct bcmasp_intf *intf, bool en,
779779
priv->mda_filters[i].en = en;
780780
priv->mda_filters[i].port = intf->port;
781781

782-
rx_filter_core_wl(priv, ((intf->channel + 8) |
782+
rx_filter_core_wl(priv, ((intf->channel + priv->tx_chan_offset) |
783783
(en << ASP_RX_FILTER_MDA_CFG_EN_SHIFT) |
784784
ASP_RX_FILTER_MDA_CFG_UMC_SEL(intf->port)),
785785
ASP_RX_FILTER_MDA_CFG(i));
@@ -865,7 +865,7 @@ void bcmasp_disable_all_filters(struct bcmasp_intf *intf)
865865
res_count = bcmasp_total_res_mda_cnt(intf->parent);
866866

867867
/* Disable all filters held by this port */
868-
for (i = res_count; i < NUM_MDA_FILTERS; i++) {
868+
for (i = res_count; i < priv->num_mda_filters; i++) {
869869
if (priv->mda_filters[i].en &&
870870
priv->mda_filters[i].port == intf->port)
871871
bcmasp_en_mda_filter(intf, 0, i);
@@ -909,7 +909,7 @@ int bcmasp_set_en_mda_filter(struct bcmasp_intf *intf, unsigned char *addr,
909909

910910
res_count = bcmasp_total_res_mda_cnt(intf->parent);
911911

912-
for (i = res_count; i < NUM_MDA_FILTERS; i++) {
912+
for (i = res_count; i < priv->num_mda_filters; i++) {
913913
/* If filter not enabled or belongs to another port skip */
914914
if (!priv->mda_filters[i].en ||
915915
priv->mda_filters[i].port != intf->port)
@@ -924,7 +924,7 @@ int bcmasp_set_en_mda_filter(struct bcmasp_intf *intf, unsigned char *addr,
924924
}
925925

926926
/* Create new filter if possible */
927-
for (i = res_count; i < NUM_MDA_FILTERS; i++) {
927+
for (i = res_count; i < priv->num_mda_filters; i++) {
928928
if (priv->mda_filters[i].en)
929929
continue;
930930

@@ -944,12 +944,12 @@ static void bcmasp_core_init_filters(struct bcmasp_priv *priv)
944944
/* Disable all filters and reset software view since the HW
945945
* can lose context while in deep sleep suspend states
946946
*/
947-
for (i = 0; i < NUM_MDA_FILTERS; i++) {
947+
for (i = 0; i < priv->num_mda_filters; i++) {
948948
rx_filter_core_wl(priv, 0x0, ASP_RX_FILTER_MDA_CFG(i));
949949
priv->mda_filters[i].en = 0;
950950
}
951951

952-
for (i = 0; i < NUM_NET_FILTERS; i++)
952+
for (i = 0; i < priv->num_net_filters; i++)
953953
rx_filter_core_wl(priv, 0x0, ASP_RX_FILTER_NET_CFG(i));
954954

955955
/* Top level filter enable bit should be enabled at all times, set
@@ -966,18 +966,8 @@ static void bcmasp_core_init_filters(struct bcmasp_priv *priv)
966966
/* ASP core initialization */
967967
static void bcmasp_core_init(struct bcmasp_priv *priv)
968968
{
969-
tx_analytics_core_wl(priv, 0x0, ASP_TX_ANALYTICS_CTRL);
970-
rx_analytics_core_wl(priv, 0x4, ASP_RX_ANALYTICS_CTRL);
971-
972-
rx_edpkt_core_wl(priv, (ASP_EDPKT_HDR_SZ_128 << ASP_EDPKT_HDR_SZ_SHIFT),
973-
ASP_EDPKT_HDR_CFG);
974-
rx_edpkt_core_wl(priv,
975-
(ASP_EDPKT_ENDI_BT_SWP_WD << ASP_EDPKT_ENDI_DESC_SHIFT),
976-
ASP_EDPKT_ENDI);
977-
978969
rx_edpkt_core_wl(priv, 0x1b, ASP_EDPKT_BURST_BUF_PSCAL_TOUT);
979970
rx_edpkt_core_wl(priv, 0x3e8, ASP_EDPKT_BURST_BUF_WRITE_TOUT);
980-
rx_edpkt_core_wl(priv, 0x3e8, ASP_EDPKT_BURST_BUF_READ_TOUT);
981971

982972
rx_edpkt_core_wl(priv, ASP_EDPKT_ENABLE_EN, ASP_EDPKT_ENABLE);
983973

@@ -1020,6 +1010,18 @@ static void bcmasp_core_clock_select_one(struct bcmasp_priv *priv, bool slow)
10201010
ctrl_core_wl(priv, reg, ASP_CTRL_CORE_CLOCK_SELECT);
10211011
}
10221012

1013+
static void bcmasp_core_clock_select_one_ctrl2(struct bcmasp_priv *priv, bool slow)
1014+
{
1015+
u32 reg;
1016+
1017+
reg = ctrl2_core_rl(priv, ASP_CTRL2_CORE_CLOCK_SELECT);
1018+
if (slow)
1019+
reg &= ~ASP_CTRL2_CORE_CLOCK_SELECT_MAIN;
1020+
else
1021+
reg |= ASP_CTRL2_CORE_CLOCK_SELECT_MAIN;
1022+
ctrl2_core_wl(priv, reg, ASP_CTRL2_CORE_CLOCK_SELECT);
1023+
}
1024+
10231025
static void bcmasp_core_clock_set_ll(struct bcmasp_priv *priv, u32 clr, u32 set)
10241026
{
10251027
u32 reg;
@@ -1180,29 +1182,51 @@ static void bcmasp_eee_fixup(struct bcmasp_intf *intf, bool en)
11801182

11811183
static const struct bcmasp_plat_data v21_plat_data = {
11821184
.core_clock_select = bcmasp_core_clock_select_one,
1185+
.num_mda_filters = 32,
1186+
.num_net_filters = 32,
1187+
.tx_chan_offset = 8,
1188+
.rx_ctrl_offset = 0x0,
11831189
};
11841190

11851191
static const struct bcmasp_plat_data v22_plat_data = {
11861192
.core_clock_select = bcmasp_core_clock_select_many,
11871193
.eee_fixup = bcmasp_eee_fixup,
1194+
.num_mda_filters = 32,
1195+
.num_net_filters = 32,
1196+
.tx_chan_offset = 8,
1197+
.rx_ctrl_offset = 0x0,
1198+
};
1199+
1200+
static const struct bcmasp_plat_data v30_plat_data = {
1201+
.core_clock_select = bcmasp_core_clock_select_one_ctrl2,
1202+
.num_mda_filters = 20,
1203+
.num_net_filters = 16,
1204+
.tx_chan_offset = 0,
1205+
.rx_ctrl_offset = 0x10000,
11881206
};
11891207

11901208
static void bcmasp_set_pdata(struct bcmasp_priv *priv, const struct bcmasp_plat_data *pdata)
11911209
{
11921210
priv->core_clock_select = pdata->core_clock_select;
11931211
priv->eee_fixup = pdata->eee_fixup;
1212+
priv->num_mda_filters = pdata->num_mda_filters;
1213+
priv->num_net_filters = pdata->num_net_filters;
1214+
priv->tx_chan_offset = pdata->tx_chan_offset;
1215+
priv->rx_ctrl_offset = pdata->rx_ctrl_offset;
11941216
}
11951217

11961218
static const struct of_device_id bcmasp_of_match[] = {
11971219
{ .compatible = "brcm,asp-v2.1", .data = &v21_plat_data },
11981220
{ .compatible = "brcm,asp-v2.2", .data = &v22_plat_data },
1221+
{ .compatible = "brcm,asp-v3.0", .data = &v30_plat_data },
11991222
{ /* sentinel */ },
12001223
};
12011224
MODULE_DEVICE_TABLE(of, bcmasp_of_match);
12021225

12031226
static const struct of_device_id bcmasp_mdio_of_match[] = {
12041227
{ .compatible = "brcm,asp-v2.1-mdio", },
12051228
{ .compatible = "brcm,asp-v2.2-mdio", },
1229+
{ .compatible = "brcm,asp-v3.0-mdio", },
12061230
{ /* sentinel */ },
12071231
};
12081232
MODULE_DEVICE_TABLE(of, bcmasp_mdio_of_match);
@@ -1284,6 +1308,17 @@ static int bcmasp_probe(struct platform_device *pdev)
12841308
* how many interfaces come up.
12851309
*/
12861310
bcmasp_core_init(priv);
1311+
1312+
priv->mda_filters = devm_kcalloc(dev, priv->num_mda_filters,
1313+
sizeof(*priv->mda_filters), GFP_KERNEL);
1314+
if (!priv->mda_filters)
1315+
return -ENOMEM;
1316+
1317+
priv->net_filters = devm_kcalloc(dev, priv->num_net_filters,
1318+
sizeof(*priv->net_filters), GFP_KERNEL);
1319+
if (!priv->net_filters)
1320+
return -ENOMEM;
1321+
12871322
bcmasp_core_init_filters(priv);
12881323

12891324
ports_node = of_find_node_by_name(dev->of_node, "ethernet-ports");

drivers/net/ethernet/broadcom/asp2/bcmasp.h

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,10 @@ struct bcmasp_mda_filter {
363363
struct bcmasp_plat_data {
364364
void (*core_clock_select)(struct bcmasp_priv *priv, bool slow);
365365
void (*eee_fixup)(struct bcmasp_intf *priv, bool en);
366+
unsigned int num_mda_filters;
367+
unsigned int num_net_filters;
368+
unsigned int tx_chan_offset;
369+
unsigned int rx_ctrl_offset;
366370
};
367371

368372
struct bcmasp_priv {
@@ -379,20 +383,24 @@ struct bcmasp_priv {
379383

380384
void (*core_clock_select)(struct bcmasp_priv *priv, bool slow);
381385
void (*eee_fixup)(struct bcmasp_intf *intf, bool en);
386+
unsigned int num_mda_filters;
387+
unsigned int num_net_filters;
388+
unsigned int tx_chan_offset;
389+
unsigned int rx_ctrl_offset;
382390

383391
void __iomem *base;
384392

385393
struct list_head intfs;
386394

387-
struct bcmasp_mda_filter mda_filters[NUM_MDA_FILTERS];
395+
struct bcmasp_mda_filter *mda_filters;
388396

389397
/* MAC destination address filters lock */
390398
spinlock_t mda_lock;
391399

392400
/* Protects accesses to ASP_CTRL_CLOCK_CTRL */
393401
spinlock_t clk_lock;
394402

395-
struct bcmasp_net_filter net_filters[NUM_NET_FILTERS];
403+
struct bcmasp_net_filter *net_filters;
396404

397405
/* Network filter lock */
398406
struct mutex net_lock;
@@ -482,8 +490,8 @@ BCMASP_FP_IO_MACRO_Q(rx_edpkt_cfg);
482490
#define PKT_OFFLOAD_EPKT_IP(x) ((x) << 21)
483491
#define PKT_OFFLOAD_EPKT_TP(x) ((x) << 19)
484492
#define PKT_OFFLOAD_EPKT_LEN(x) ((x) << 16)
485-
#define PKT_OFFLOAD_EPKT_CSUM_L3 BIT(15)
486-
#define PKT_OFFLOAD_EPKT_CSUM_L2 BIT(14)
493+
#define PKT_OFFLOAD_EPKT_CSUM_L4 BIT(15)
494+
#define PKT_OFFLOAD_EPKT_CSUM_L3 BIT(14)
487495
#define PKT_OFFLOAD_EPKT_ID(x) ((x) << 12)
488496
#define PKT_OFFLOAD_EPKT_SEQ(x) ((x) << 10)
489497
#define PKT_OFFLOAD_EPKT_TS(x) ((x) << 8)
@@ -515,12 +523,27 @@ BCMASP_CORE_IO_MACRO(intr2, ASP_INTR2_OFFSET);
515523
BCMASP_CORE_IO_MACRO(wakeup_intr2, ASP_WAKEUP_INTR2_OFFSET);
516524
BCMASP_CORE_IO_MACRO(tx_analytics, ASP_TX_ANALYTICS_OFFSET);
517525
BCMASP_CORE_IO_MACRO(rx_analytics, ASP_RX_ANALYTICS_OFFSET);
518-
BCMASP_CORE_IO_MACRO(rx_ctrl, ASP_RX_CTRL_OFFSET);
519526
BCMASP_CORE_IO_MACRO(rx_filter, ASP_RX_FILTER_OFFSET);
520527
BCMASP_CORE_IO_MACRO(rx_edpkt, ASP_EDPKT_OFFSET);
521528
BCMASP_CORE_IO_MACRO(ctrl, ASP_CTRL_OFFSET);
522529
BCMASP_CORE_IO_MACRO(ctrl2, ASP_CTRL2_OFFSET);
523530

531+
#define BCMASP_CORE_IO_MACRO_OFFSET(name, offset) \
532+
static inline u32 name##_core_rl(struct bcmasp_priv *priv, \
533+
u32 off) \
534+
{ \
535+
u32 reg = readl_relaxed(priv->base + priv->name##_offset + \
536+
(offset) + off); \
537+
return reg; \
538+
} \
539+
static inline void name##_core_wl(struct bcmasp_priv *priv, \
540+
u32 val, u32 off) \
541+
{ \
542+
writel_relaxed(val, priv->base + priv->name##_offset + \
543+
(offset) + off); \
544+
}
545+
BCMASP_CORE_IO_MACRO_OFFSET(rx_ctrl, ASP_RX_CTRL_OFFSET);
546+
524547
struct bcmasp_intf *bcmasp_interface_create(struct bcmasp_priv *priv,
525548
struct device_node *ndev_dn, int i);
526549

drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "bcmasp_intf_defs.h"
1111

1212
enum bcmasp_stat_type {
13-
BCMASP_STAT_RX_EDPKT,
1413
BCMASP_STAT_RX_CTRL,
1514
BCMASP_STAT_RX_CTRL_PER_INTF,
1615
BCMASP_STAT_SOFT,
@@ -33,20 +32,13 @@ struct bcmasp_stats {
3332
.reg_offset = offset, \
3433
}
3534

36-
#define STAT_BCMASP_RX_EDPKT(str, offset) \
37-
STAT_BCMASP_OFFSET(str, BCMASP_STAT_RX_EDPKT, offset)
3835
#define STAT_BCMASP_RX_CTRL(str, offset) \
3936
STAT_BCMASP_OFFSET(str, BCMASP_STAT_RX_CTRL, offset)
4037
#define STAT_BCMASP_RX_CTRL_PER_INTF(str, offset) \
4138
STAT_BCMASP_OFFSET(str, BCMASP_STAT_RX_CTRL_PER_INTF, offset)
4239

4340
/* Must match the order of struct bcmasp_mib_counters */
4441
static const struct bcmasp_stats bcmasp_gstrings_stats[] = {
45-
/* EDPKT counters */
46-
STAT_BCMASP_RX_EDPKT("RX Time Stamp", ASP_EDPKT_RX_TS_COUNTER),
47-
STAT_BCMASP_RX_EDPKT("RX PKT Count", ASP_EDPKT_RX_PKT_CNT),
48-
STAT_BCMASP_RX_EDPKT("RX PKT Buffered", ASP_EDPKT_HDR_EXTR_CNT),
49-
STAT_BCMASP_RX_EDPKT("RX PKT Pushed to DRAM", ASP_EDPKT_HDR_OUT_CNT),
5042
/* ASP RX control */
5143
STAT_BCMASP_RX_CTRL_PER_INTF("Frames From Unimac",
5244
ASP_RX_CTRL_UMAC_0_FRAME_COUNT),
@@ -113,9 +105,6 @@ static void bcmasp_update_mib_counters(struct bcmasp_intf *intf)
113105
switch (s->type) {
114106
case BCMASP_STAT_SOFT:
115107
continue;
116-
case BCMASP_STAT_RX_EDPKT:
117-
val = rx_edpkt_core_rl(intf->parent, offset);
118-
break;
119108
case BCMASP_STAT_RX_CTRL:
120109
val = rx_ctrl_core_rl(intf->parent, offset);
121110
break;
@@ -272,7 +261,7 @@ static int bcmasp_flow_get(struct bcmasp_intf *intf, struct ethtool_rxnfc *cmd)
272261

273262
memcpy(&cmd->fs, &nfilter->fs, sizeof(nfilter->fs));
274263

275-
cmd->data = NUM_NET_FILTERS;
264+
cmd->data = intf->parent->num_net_filters;
276265

277266
return 0;
278267
}
@@ -319,7 +308,7 @@ static int bcmasp_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
319308
break;
320309
case ETHTOOL_GRXCLSRLALL:
321310
err = bcmasp_netfilt_get_all_active(intf, rule_locs, &cmd->rule_cnt);
322-
cmd->data = NUM_NET_FILTERS;
311+
cmd->data = intf->parent->num_net_filters;
323312
break;
324313
default:
325314
err = -EOPNOTSUPP;

0 commit comments

Comments
 (0)