Skip to content

Commit 89f5678

Browse files
plappermaulrobimarko
authored andcommitted
realtek: mdio: move cpu_port to configuration structure
Relocate the cpu port definition over to the new configuration structure. There are several family specific places where the driver checks port ranges. These are a wild mix of arbitrary values (64) or constant defines. Remove them as the the central read/write functions already have a proper check with -ENODEV bail out in place. With the cleanup drop the port defines as there is only one consumer (config structure) left. Signed-off-by: Markus Stockhausen <[email protected]> Link: openwrt/openwrt#21274 Signed-off-by: Robert Marko <[email protected]>
1 parent 36f56f2 commit 89f5678

File tree

1 file changed

+20
-35
lines changed

1 file changed

+20
-35
lines changed

target/linux/realtek/files-6.12/drivers/net/mdio/mdio-realtek-otto.c

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,9 @@
1212
#define RTMDIO_MAX_SMI_BUS 4
1313
#define RTMDIO_PAGE_SELECT 0x1f
1414

15-
#define RTMDIO_838X_CPU_PORT 28
1615
#define RTMDIO_838X_FAMILY_ID 0x8380
17-
18-
#define RTMDIO_839X_CPU_PORT 52
1916
#define RTMDIO_839X_FAMILY_ID 0x8390
20-
21-
#define RTMDIO_930X_CPU_PORT 28
2217
#define RTMDIO_930X_FAMILY_ID 0x9300
23-
24-
#define RTMDIO_931X_CPU_PORT 56
2518
#define RTMDIO_931X_FAMILY_ID 0x9310
2619

2720
/* Register base */
@@ -162,7 +155,6 @@ struct rtmdio_bus_priv {
162155
const struct rtmdio_config *cfg;
163156
u16 id;
164157
u16 family_id;
165-
int cpu_port;
166158
int page[RTMDIO_MAX_PORT];
167159
bool raw[RTMDIO_MAX_PORT];
168160
int smi_bus[RTMDIO_MAX_PORT];
@@ -180,6 +172,7 @@ struct rtmdio_bus_priv {
180172
};
181173

182174
struct rtmdio_config {
175+
int cpu_port;
183176
int raw_page;
184177
};
185178

@@ -472,7 +465,7 @@ static int rtmdio_839x_read_phy(u32 port, u32 page, u32 reg, u32 *val)
472465
int err = 0;
473466
u32 v;
474467

475-
if (port >= RTMDIO_839X_CPU_PORT || page > 8191 || reg > 31)
468+
if (page > 8191 || reg > 31)
476469
return -ENOTSUPP;
477470

478471
mutex_lock(&rtmdio_lock);
@@ -504,7 +497,7 @@ static int rtmdio_839x_write_phy(u32 port, u32 page, u32 reg, u32 val)
504497
u32 v;
505498

506499
val &= 0xffff;
507-
if (port >= RTMDIO_839X_CPU_PORT || page > 8191 || reg > 31)
500+
if (page > 8191 || reg > 31)
508501
return -ENOTSUPP;
509502

510503
mutex_lock(&rtmdio_lock);
@@ -542,10 +535,6 @@ static int rtmdio_839x_read_mmd_phy(u32 port, u32 devnum, u32 regnum, u32 *val)
542535
int err = 0;
543536
u32 v;
544537

545-
/* Take bug on RTL839x Rev <= C into account */
546-
if (port >= RTMDIO_839X_CPU_PORT)
547-
return -EIO;
548-
549538
mutex_lock(&rtmdio_lock);
550539

551540
/* Set PHY to access */
@@ -577,10 +566,6 @@ static int rtmdio_839x_write_mmd_phy(u32 port, u32 devnum, u32 regnum, u32 val)
577566
int err = 0;
578567
u32 v;
579568

580-
/* Take bug on RTL839x Rev <= C into account */
581-
if (port >= RTMDIO_839X_CPU_PORT)
582-
return -EIO;
583-
584569
mutex_lock(&rtmdio_lock);
585570

586571
/* Set PHY to access */
@@ -709,7 +694,7 @@ static int rtmdio_930x_read_phy(u32 port, u32 page, u32 reg, u32 *val)
709694
u32 v;
710695
int err = 0;
711696

712-
if (port > 63 || page > 4095 || reg > 31)
697+
if (page > 4095 || reg > 31)
713698
return -ENOTSUPP;
714699

715700
mutex_lock(&rtmdio_lock);
@@ -976,7 +961,7 @@ static int rtmdio_931x_read_phy(u32 port, u32 page, u32 reg, u32 *val)
976961
{
977962
u32 v;
978963

979-
if (port > 63 || page > 4095 || reg > 31)
964+
if (page > 4095 || reg > 31)
980965
return -ENOTSUPP;
981966

982967
mutex_lock(&rtmdio_lock);
@@ -1085,7 +1070,7 @@ static int rtmdio_read_c45(struct mii_bus *bus, int addr, int devnum, int regnum
10851070
struct rtmdio_bus_priv *priv = bus->priv;
10861071
int err, val;
10871072

1088-
if (addr >= priv->cpu_port)
1073+
if (addr >= priv->cfg->cpu_port)
10891074
return -ENODEV;
10901075

10911076
err = (*priv->read_mmd_phy)(addr, devnum, regnum, &val);
@@ -1151,7 +1136,7 @@ static int rtmdio_read(struct mii_bus *bus, int addr, int regnum)
11511136
struct rtmdio_bus_priv *priv = bus->priv;
11521137
int err, val;
11531138

1154-
if (addr >= priv->cpu_port)
1139+
if (addr >= priv->cfg->cpu_port)
11551140
return -ENODEV;
11561141

11571142
if (regnum == RTMDIO_PAGE_SELECT && priv->page[addr] != priv->cfg->raw_page)
@@ -1173,7 +1158,7 @@ static int rtmdio_write_c45(struct mii_bus *bus, int addr, int devnum, int regnu
11731158
struct rtmdio_bus_priv *priv = bus->priv;
11741159
int err;
11751160

1176-
if (addr >= priv->cpu_port)
1161+
if (addr >= priv->cfg->cpu_port)
11771162
return -ENODEV;
11781163

11791164
err = (*priv->write_mmd_phy)(addr, devnum, regnum, val);
@@ -1187,7 +1172,7 @@ static int rtmdio_write(struct mii_bus *bus, int addr, int regnum, u16 val)
11871172
struct rtmdio_bus_priv *priv = bus->priv;
11881173
int err, page;
11891174

1190-
if (addr >= priv->cpu_port)
1175+
if (addr >= priv->cfg->cpu_port)
11911176
return -ENODEV;
11921177

11931178
page = priv->page[addr];
@@ -1240,8 +1225,8 @@ static int rtmdio_839x_reset(struct mii_bus *bus)
12401225
return 0;
12411226
}
12421227

1243-
u8 mac_type_bit[RTMDIO_930X_CPU_PORT] = {0, 0, 0, 0, 2, 2, 2, 2, 4, 4, 4, 4, 6, 6, 6, 6,
1244-
8, 8, 8, 8, 10, 10, 10, 10, 12, 15, 18, 21};
1228+
u8 mac_type_bit[RTMDIO_MAX_PORT] = {0, 0, 0, 0, 2, 2, 2, 2, 4, 4, 4, 4, 6, 6, 6, 6,
1229+
8, 8, 8, 8, 10, 10, 10, 10, 12, 15, 18, 21};
12451230

12461231
static int rtmdio_930x_reset(struct mii_bus *bus)
12471232
{
@@ -1255,7 +1240,7 @@ static int rtmdio_930x_reset(struct mii_bus *bus)
12551240
u32 v;
12561241

12571242
/* Mapping of port to phy-addresses on an SMI bus */
1258-
for (int i = 0; i < RTMDIO_930X_CPU_PORT; i++) {
1243+
for (int i = 0; i < priv->cfg->cpu_port; i++) {
12591244
int pos;
12601245

12611246
if (priv->smi_bus[i] < 0)
@@ -1288,7 +1273,7 @@ static int rtmdio_930x_reset(struct mii_bus *bus)
12881273
/* Set the MAC type of each port according to the PHY-interface */
12891274
/* Values are FE: 2, GE: 3, XGE/2.5G: 0(SERDES) or 1(otherwise), SXGE: 0 */
12901275
v = 0;
1291-
for (int i = 0; i < RTMDIO_930X_CPU_PORT; i++) {
1276+
for (int i = 0; i < priv->cfg->cpu_port; i++) {
12921277
switch (priv->interfaces[i]) {
12931278
case PHY_INTERFACE_MODE_10GBASER:
12941279
break; /* Serdes: Value = 0 */
@@ -1358,7 +1343,7 @@ static int rtmdio_931x_reset(struct mii_bus *bus)
13581343
msleep(100);
13591344

13601345
/* Mapping of port to phy-addresses on an SMI bus */
1361-
for (int i = 0; i < RTMDIO_931X_CPU_PORT; i++) {
1346+
for (int i = 0; i < priv->cfg->cpu_port; i++) {
13621347
u32 pos;
13631348

13641349
if (priv->smi_bus[i] < 0)
@@ -1464,7 +1449,6 @@ static int rtmdio_probe(struct platform_device *pdev)
14641449
priv->write_mmd_phy = rtmdio_838x_write_mmd_phy;
14651450
priv->read_phy = rtmdio_838x_read_phy;
14661451
priv->write_phy = rtmdio_838x_write_phy;
1467-
priv->cpu_port = RTMDIO_838X_CPU_PORT;
14681452
break;
14691453
case RTMDIO_839X_FAMILY_ID:
14701454
bus->name = "rtl839x-eth-mdio";
@@ -1477,7 +1461,6 @@ static int rtmdio_probe(struct platform_device *pdev)
14771461
priv->write_mmd_phy = rtmdio_839x_write_mmd_phy;
14781462
priv->read_phy = rtmdio_839x_read_phy;
14791463
priv->write_phy = rtmdio_839x_write_phy;
1480-
priv->cpu_port = RTMDIO_839X_CPU_PORT;
14811464
break;
14821465
case RTMDIO_930X_FAMILY_ID:
14831466
bus->name = "rtl930x-eth-mdio";
@@ -1490,7 +1473,6 @@ static int rtmdio_probe(struct platform_device *pdev)
14901473
priv->write_mmd_phy = rtmdio_930x_write_mmd_phy;
14911474
priv->read_phy = rtmdio_930x_read_phy;
14921475
priv->write_phy = rtmdio_930x_write_phy;
1493-
priv->cpu_port = RTMDIO_930X_CPU_PORT;
14941476
break;
14951477
case RTMDIO_931X_FAMILY_ID:
14961478
bus->name = "rtl931x-eth-mdio";
@@ -1503,13 +1485,12 @@ static int rtmdio_probe(struct platform_device *pdev)
15031485
priv->write_mmd_phy = rtmdio_931x_write_mmd_phy;
15041486
priv->read_phy = rtmdio_931x_read_phy;
15051487
priv->write_phy = rtmdio_931x_write_phy;
1506-
priv->cpu_port = RTMDIO_931X_CPU_PORT;
15071488
break;
15081489
}
15091490
bus->read_c45 = rtmdio_read_c45;
15101491
bus->write_c45 = rtmdio_write_c45;
15111492
bus->parent = dev;
1512-
bus->phy_mask = ~(BIT_ULL(priv->cpu_port) - 1ULL);
1493+
bus->phy_mask = ~(BIT_ULL(priv->cfg->cpu_port) - 1ULL);
15131494

15141495
for_each_node_by_name(dn, "ethernet-phy") {
15151496
u32 smi_addr[2];
@@ -1551,7 +1532,7 @@ static int rtmdio_probe(struct platform_device *pdev)
15511532
if (of_property_read_u32(dn, "reg", &pn))
15521533
continue;
15531534
dev_dbg(dev, "Looking at port %d\n", pn);
1554-
if (pn > priv->cpu_port)
1535+
if (pn > priv->cfg->cpu_port)
15551536
continue;
15561537
if (of_get_phy_mode(dn, &priv->interfaces[pn]))
15571538
priv->interfaces[pn] = PHY_INTERFACE_MODE_NA;
@@ -1579,18 +1560,22 @@ static int rtmdio_probe(struct platform_device *pdev)
15791560
}
15801561

15811562
static const struct rtmdio_config rtmdio_838x_cfg = {
1563+
.cpu_port = 28,
15821564
.raw_page = 4095,
15831565
};
15841566

15851567
static const struct rtmdio_config rtmdio_839x_cfg = {
1568+
.cpu_port = 52,
15861569
.raw_page = 8191,
15871570
};
15881571

15891572
static const struct rtmdio_config rtmdio_930x_cfg = {
1573+
.cpu_port = 28,
15901574
.raw_page = 4095,
15911575
};
15921576

15931577
static const struct rtmdio_config rtmdio_931x_cfg = {
1578+
.cpu_port = 56,
15941579
.raw_page = 8191,
15951580
};
15961581

0 commit comments

Comments
 (0)