Re: [PATCH net-next v6 3/9] net: dsa: realtek: rtl8365mb: set speed for family D

From: Linus Walleij

Date: Mon Oct 19 2026 - 04:29:36 EST


On Mon, Oct 19, 2026 at 12:41 AM Luiz Angelo Daros de Luca
<luizluca@xxxxxxxxx> wrote:

> > #define RTL8365MB_PORT_SPEED_10M 0
> > #define RTL8365MB_PORT_SPEED_100M 1
> > #define RTL8365MB_PORT_SPEED_1000M 2
> > +#define RTL8365MB_D_PORT_SPEED_2500M 5
>
> I also used the same _<FAMILY>_ tag trick previously, but it gets
> confusing quickly. Does RTL8365MB_D_xxx mean something exclusive to
> family D, or family D and later? I hope a more seasoned reviewer can
> weigh in on this.

I'm not seasoned.

But in the Microchip switches there are a ton of different
devices and it is managed by way of family-specific
files, includes etc. But we bake everything into one single
module in the end, the only optional part is PTP.

Here the family is somewhat and piecemal encoded in the
hardware registers so:

#define REG_CHIP_ID0 0x00

#define SW_FAMILY_ID_M GENMASK(15, 8)
#define KSZ84_FAMILY_ID 0x84
#define KSZ87_FAMILY_ID 0x87
#define KSZ88_FAMILY_ID 0x88
#define KSZ8895_FAMILY_ID 0x95

#define SW_CHIP_ID_M GENMASK(7, 4)
#define KSZ87_CHIP_ID_94 0x6
#define KSZ87_CHIP_ID_95 0x9
#define KSZ88_CHIP_ID_63 0x3
#define KSZ8895_CHIP_ID_95XA 0x0
#define KSZ8895_CHIP_ID_95 0x4
#define KSZ8895_CHIP_ID_95R 0x6

it all comes pretty naturally from this.

Then we go on to define boolean family deduction helpers:

static inline bool ksz_is_ksz87xx(struct ksz_device *dev)
{
return dev->chip_id == KSZ8795_CHIP_ID ||
dev->chip_id == KSZ8794_CHIP_ID ||
dev->chip_id == KSZ8765_CHIP_ID;
}

static inline bool ksz_is_ksz88x3(struct ksz_device *dev)
{
return dev->chip_id == KSZ88X3_CHIP_ID;
}

This makes it pretty straight-forward to code it up.

The same can be achived even if you don't have any hardware
ID registersm with made-up family enums and using DT match
data obviously.

Yours,
Linus Walleij