Skip to content

Commit c456553

Browse files
ffainellikuba-moo
authored andcommitted
net: dsa: b53: add support for FDB operations on 5325/5365
BCM5325 and BCM5365 are part of a much older generation of switches which, due to their limited number of ports and VLAN entries (up to 256) allowed a single 64-bit register to hold a full ARL entry. This requires a little bit of massaging when reading, writing and converting ARL entries in both directions. Signed-off-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com> Link: https://patch.msgid.link/20250614080000.1884236-6-noltari@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 0cbec9a commit c456553

File tree

3 files changed

+115
-22
lines changed

3 files changed

+115
-22
lines changed

drivers/net/dsa/b53/b53_common.c

Lines changed: 82 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,6 +1764,45 @@ static int b53_arl_read(struct b53_device *dev, u64 mac,
17641764
return *idx >= dev->num_arl_bins ? -ENOSPC : -ENOENT;
17651765
}
17661766

1767+
static int b53_arl_read_25(struct b53_device *dev, u64 mac,
1768+
u16 vid, struct b53_arl_entry *ent, u8 *idx)
1769+
{
1770+
DECLARE_BITMAP(free_bins, B53_ARLTBL_MAX_BIN_ENTRIES);
1771+
unsigned int i;
1772+
int ret;
1773+
1774+
ret = b53_arl_op_wait(dev);
1775+
if (ret)
1776+
return ret;
1777+
1778+
bitmap_zero(free_bins, dev->num_arl_bins);
1779+
1780+
/* Read the bins */
1781+
for (i = 0; i < dev->num_arl_bins; i++) {
1782+
u64 mac_vid;
1783+
1784+
b53_read64(dev, B53_ARLIO_PAGE,
1785+
B53_ARLTBL_MAC_VID_ENTRY(i), &mac_vid);
1786+
1787+
b53_arl_to_entry_25(ent, mac_vid);
1788+
1789+
if (!(mac_vid & ARLTBL_VALID_25)) {
1790+
set_bit(i, free_bins);
1791+
continue;
1792+
}
1793+
if ((mac_vid & ARLTBL_MAC_MASK) != mac)
1794+
continue;
1795+
if (dev->vlan_enabled &&
1796+
((mac_vid >> ARLTBL_VID_S_65) & ARLTBL_VID_MASK_25) != vid)
1797+
continue;
1798+
*idx = i;
1799+
return 0;
1800+
}
1801+
1802+
*idx = find_first_bit(free_bins, dev->num_arl_bins);
1803+
return *idx >= dev->num_arl_bins ? -ENOSPC : -ENOENT;
1804+
}
1805+
17671806
static int b53_arl_op(struct b53_device *dev, int op, int port,
17681807
const unsigned char *addr, u16 vid, bool is_valid)
17691808
{
@@ -1786,7 +1825,10 @@ static int b53_arl_op(struct b53_device *dev, int op, int port,
17861825
if (ret)
17871826
return ret;
17881827

1789-
ret = b53_arl_read(dev, mac, vid, &ent, &idx);
1828+
if (is5325(dev) || is5365(dev))
1829+
ret = b53_arl_read_25(dev, mac, vid, &ent, &idx);
1830+
else
1831+
ret = b53_arl_read(dev, mac, vid, &ent, &idx);
17901832

17911833
/* If this is a read, just finish now */
17921834
if (op)
@@ -1830,12 +1872,17 @@ static int b53_arl_op(struct b53_device *dev, int op, int port,
18301872
ent.is_static = true;
18311873
ent.is_age = false;
18321874
memcpy(ent.mac, addr, ETH_ALEN);
1833-
b53_arl_from_entry(&mac_vid, &fwd_entry, &ent);
1875+
if (is5325(dev) || is5365(dev))
1876+
b53_arl_from_entry_25(&mac_vid, &ent);
1877+
else
1878+
b53_arl_from_entry(&mac_vid, &fwd_entry, &ent);
18341879

18351880
b53_write64(dev, B53_ARLIO_PAGE,
18361881
B53_ARLTBL_MAC_VID_ENTRY(idx), mac_vid);
1837-
b53_write32(dev, B53_ARLIO_PAGE,
1838-
B53_ARLTBL_DATA_ENTRY(idx), fwd_entry);
1882+
1883+
if (!is5325(dev) && !is5365(dev))
1884+
b53_write32(dev, B53_ARLIO_PAGE,
1885+
B53_ARLTBL_DATA_ENTRY(idx), fwd_entry);
18391886

18401887
return b53_arl_rw_op(dev, 0);
18411888
}
@@ -1847,12 +1894,6 @@ int b53_fdb_add(struct dsa_switch *ds, int port,
18471894
struct b53_device *priv = ds->priv;
18481895
int ret;
18491896

1850-
/* 5325 and 5365 require some more massaging, but could
1851-
* be supported eventually
1852-
*/
1853-
if (is5325(priv) || is5365(priv))
1854-
return -EOPNOTSUPP;
1855-
18561897
mutex_lock(&priv->arl_mutex);
18571898
ret = b53_arl_op(priv, 0, port, addr, vid, true);
18581899
mutex_unlock(&priv->arl_mutex);
@@ -1879,10 +1920,15 @@ EXPORT_SYMBOL(b53_fdb_del);
18791920
static int b53_arl_search_wait(struct b53_device *dev)
18801921
{
18811922
unsigned int timeout = 1000;
1882-
u8 reg;
1923+
u8 reg, offset;
1924+
1925+
if (is5325(dev) || is5365(dev))
1926+
offset = B53_ARL_SRCH_CTL_25;
1927+
else
1928+
offset = B53_ARL_SRCH_CTL;
18831929

18841930
do {
1885-
b53_read8(dev, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, &reg);
1931+
b53_read8(dev, B53_ARLIO_PAGE, offset, &reg);
18861932
if (!(reg & ARL_SRCH_STDN))
18871933
return 0;
18881934

@@ -1899,13 +1945,24 @@ static void b53_arl_search_rd(struct b53_device *dev, u8 idx,
18991945
struct b53_arl_entry *ent)
19001946
{
19011947
u64 mac_vid;
1902-
u32 fwd_entry;
19031948

1904-
b53_read64(dev, B53_ARLIO_PAGE,
1905-
B53_ARL_SRCH_RSTL_MACVID(idx), &mac_vid);
1906-
b53_read32(dev, B53_ARLIO_PAGE,
1907-
B53_ARL_SRCH_RSTL(idx), &fwd_entry);
1908-
b53_arl_to_entry(ent, mac_vid, fwd_entry);
1949+
if (is5325(dev)) {
1950+
b53_read64(dev, B53_ARLIO_PAGE, B53_ARL_SRCH_RSTL_0_MACVID_25,
1951+
&mac_vid);
1952+
b53_arl_to_entry_25(ent, mac_vid);
1953+
} else if (is5365(dev)) {
1954+
b53_read64(dev, B53_ARLIO_PAGE, B53_ARL_SRCH_RSTL_0_MACVID_65,
1955+
&mac_vid);
1956+
b53_arl_to_entry_25(ent, mac_vid);
1957+
} else {
1958+
u32 fwd_entry;
1959+
1960+
b53_read64(dev, B53_ARLIO_PAGE, B53_ARL_SRCH_RSTL_MACVID(idx),
1961+
&mac_vid);
1962+
b53_read32(dev, B53_ARLIO_PAGE, B53_ARL_SRCH_RSTL(idx),
1963+
&fwd_entry);
1964+
b53_arl_to_entry(ent, mac_vid, fwd_entry);
1965+
}
19091966
}
19101967

19111968
static int b53_fdb_copy(int port, const struct b53_arl_entry *ent,
@@ -1926,14 +1983,20 @@ int b53_fdb_dump(struct dsa_switch *ds, int port,
19261983
struct b53_device *priv = ds->priv;
19271984
struct b53_arl_entry results[2];
19281985
unsigned int count = 0;
1986+
u8 offset;
19291987
int ret;
19301988
u8 reg;
19311989

19321990
mutex_lock(&priv->arl_mutex);
19331991

1992+
if (is5325(priv) || is5365(priv))
1993+
offset = B53_ARL_SRCH_CTL_25;
1994+
else
1995+
offset = B53_ARL_SRCH_CTL;
1996+
19341997
/* Start search operation */
19351998
reg = ARL_SRCH_STDN;
1936-
b53_write8(priv, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, reg);
1999+
b53_write8(priv, offset, B53_ARL_SRCH_CTL, reg);
19372000

19382001
do {
19392002
ret = b53_arl_search_wait(priv);

drivers/net/dsa/b53/b53_priv.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,19 @@ static inline void b53_arl_to_entry(struct b53_arl_entry *ent,
317317
ent->vid = mac_vid >> ARLTBL_VID_S;
318318
}
319319

320+
static inline void b53_arl_to_entry_25(struct b53_arl_entry *ent,
321+
u64 mac_vid)
322+
{
323+
memset(ent, 0, sizeof(*ent));
324+
ent->port = (mac_vid >> ARLTBL_DATA_PORT_ID_S_25) &
325+
ARLTBL_DATA_PORT_ID_MASK_25;
326+
ent->is_valid = !!(mac_vid & ARLTBL_VALID_25);
327+
ent->is_age = !!(mac_vid & ARLTBL_AGE_25);
328+
ent->is_static = !!(mac_vid & ARLTBL_STATIC_25);
329+
u64_to_ether_addr(mac_vid, ent->mac);
330+
ent->vid = mac_vid >> ARLTBL_VID_S_65;
331+
}
332+
320333
static inline void b53_arl_from_entry(u64 *mac_vid, u32 *fwd_entry,
321334
const struct b53_arl_entry *ent)
322335
{
@@ -331,6 +344,22 @@ static inline void b53_arl_from_entry(u64 *mac_vid, u32 *fwd_entry,
331344
*fwd_entry |= ARLTBL_AGE;
332345
}
333346

347+
static inline void b53_arl_from_entry_25(u64 *mac_vid,
348+
const struct b53_arl_entry *ent)
349+
{
350+
*mac_vid = ether_addr_to_u64(ent->mac);
351+
*mac_vid |= (u64)(ent->port & ARLTBL_DATA_PORT_ID_MASK_25) <<
352+
ARLTBL_DATA_PORT_ID_S_25;
353+
*mac_vid |= (u64)(ent->vid & ARLTBL_VID_MASK_25) <<
354+
ARLTBL_VID_S_65;
355+
if (ent->is_valid)
356+
*mac_vid |= ARLTBL_VALID_25;
357+
if (ent->is_static)
358+
*mac_vid |= ARLTBL_STATIC_25;
359+
if (ent->is_age)
360+
*mac_vid |= ARLTBL_AGE_25;
361+
}
362+
334363
#ifdef CONFIG_BCM47XX
335364

336365
#include <linux/bcm47xx_nvram.h>

drivers/net/dsa/b53/b53_regs.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,10 @@
324324
#define ARLTBL_VID_MASK 0xfff
325325
#define ARLTBL_DATA_PORT_ID_S_25 48
326326
#define ARLTBL_DATA_PORT_ID_MASK_25 0xf
327-
#define ARLTBL_AGE_25 BIT(61)
328-
#define ARLTBL_STATIC_25 BIT(62)
329-
#define ARLTBL_VALID_25 BIT(63)
327+
#define ARLTBL_VID_S_65 53
328+
#define ARLTBL_AGE_25 BIT_ULL(61)
329+
#define ARLTBL_STATIC_25 BIT_ULL(62)
330+
#define ARLTBL_VALID_25 BIT_ULL(63)
330331

331332
/* ARL Table Data Entry N Registers (32 bit) */
332333
#define B53_ARLTBL_DATA_ENTRY(n) ((0x10 * (n)) + 0x18)

0 commit comments

Comments
 (0)