Skip to content

Commit e43216a

Browse files
committed
net: renesas: rswitch: use generic MPSM operation for mdio C45
JIRA: https://issues.redhat.com/browse/RHEL-78074 commit 2aa722b Author: Nikita Yushchenko <nikita.yoush@cogentembedded.com> Date: Mon Dec 16 12:19:56 2024 +0500 net: renesas: rswitch: use generic MPSM operation for mdio C45 Introduce rswitch_etha_mpsm_op() that accepts values for MPSM register fields and executes the transaction. This avoids some code duptication, and can be used both for C45 and C22. Convert C45 read and write operations to use that. Signed-off-by: Nikita Yushchenko <nikita.yoush@cogentembedded.com> Reviewed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> Tested-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> Link: https://patch.msgid.link/20241216071957.2587354-5-nikita.yoush@cogentembedded.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Radu Rendec <rrendec@redhat.com>
1 parent 8d70caa commit e43216a

File tree

2 files changed

+40
-28
lines changed

2 files changed

+40
-28
lines changed

drivers/net/ethernet/renesas/rswitch.c

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,36 +1201,29 @@ static int rswitch_etha_hw_init(struct rswitch_etha *etha, const u8 *mac)
12011201
return rswitch_etha_change_mode(etha, EAMC_OPC_OPERATION);
12021202
}
12031203

1204-
static int rswitch_etha_set_access(struct rswitch_etha *etha, bool read,
1205-
int phyad, int devad, int regad, int data)
1204+
static int rswitch_etha_mpsm_op(struct rswitch_etha *etha, bool read,
1205+
unsigned int mmf, unsigned int pda,
1206+
unsigned int pra, unsigned int pop,
1207+
unsigned int prd)
12061208
{
1207-
int pop = read ? MDIO_READ_C45 : MDIO_WRITE_C45;
12081209
u32 val;
12091210
int ret;
12101211

1211-
if (devad == 0xffffffff)
1212-
return -ENODEV;
1213-
1214-
val = MPSM_PSME | MPSM_MFF_C45;
1215-
iowrite32((regad << 16) | (devad << 8) | (phyad << 3) | val, etha->addr + MPSM);
1212+
val = MPSM_PSME |
1213+
FIELD_PREP(MPSM_MFF, mmf) |
1214+
FIELD_PREP(MPSM_PDA, pda) |
1215+
FIELD_PREP(MPSM_PRA, pra) |
1216+
FIELD_PREP(MPSM_POP, pop) |
1217+
FIELD_PREP(MPSM_PRD, prd);
1218+
iowrite32(val, etha->addr + MPSM);
12161219

12171220
ret = rswitch_reg_wait(etha->addr, MPSM, MPSM_PSME, 0);
12181221
if (ret)
12191222
return ret;
12201223

12211224
if (read) {
1222-
writel((pop << 13) | (devad << 8) | (phyad << 3) | val, etha->addr + MPSM);
1223-
1224-
ret = rswitch_reg_wait(etha->addr, MPSM, MPSM_PSME, 0);
1225-
if (ret)
1226-
return ret;
1227-
1228-
ret = (ioread32(etha->addr + MPSM) & MPSM_PRD_MASK) >> 16;
1229-
} else {
1230-
iowrite32((data << 16) | (pop << 13) | (devad << 8) | (phyad << 3) | val,
1231-
etha->addr + MPSM);
1232-
1233-
ret = rswitch_reg_wait(etha->addr, MPSM, MPSM_PSME, 0);
1225+
val = ioread32(etha->addr + MPSM);
1226+
ret = FIELD_GET(MPSM_PRD, val);
12341227
}
12351228

12361229
return ret;
@@ -1240,16 +1233,30 @@ static int rswitch_etha_mii_read_c45(struct mii_bus *bus, int addr, int devad,
12401233
int regad)
12411234
{
12421235
struct rswitch_etha *etha = bus->priv;
1236+
int ret;
12431237

1244-
return rswitch_etha_set_access(etha, true, addr, devad, regad, 0);
1238+
ret = rswitch_etha_mpsm_op(etha, false, MPSM_MMF_C45, addr, devad,
1239+
MPSM_POP_ADDRESS, regad);
1240+
if (ret)
1241+
return ret;
1242+
1243+
return rswitch_etha_mpsm_op(etha, true, MPSM_MMF_C45, addr, devad,
1244+
MPSM_POP_READ_C45, 0);
12451245
}
12461246

12471247
static int rswitch_etha_mii_write_c45(struct mii_bus *bus, int addr, int devad,
12481248
int regad, u16 val)
12491249
{
12501250
struct rswitch_etha *etha = bus->priv;
1251+
int ret;
1252+
1253+
ret = rswitch_etha_mpsm_op(etha, false, MPSM_MMF_C45, addr, devad,
1254+
MPSM_POP_ADDRESS, regad);
1255+
if (ret)
1256+
return ret;
12511257

1252-
return rswitch_etha_set_access(etha, false, addr, devad, regad, val);
1258+
return rswitch_etha_mpsm_op(etha, false, MPSM_MMF_C45, addr, devad,
1259+
MPSM_POP_WRITE, val);
12531260
}
12541261

12551262
/* Call of_node_put(port) after done */

drivers/net/ethernet/renesas/rswitch.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -735,13 +735,18 @@ enum rswitch_etha_mode {
735735
#define MPIC_PSMCS GENMASK(22, 16)
736736
#define MPIC_PSMHT GENMASK(26, 24)
737737

738-
#define MDIO_READ_C45 0x03
739-
#define MDIO_WRITE_C45 0x01
740-
741738
#define MPSM_PSME BIT(0)
742-
#define MPSM_MFF_C45 BIT(2)
743-
#define MPSM_PRD_SHIFT 16
744-
#define MPSM_PRD_MASK GENMASK(31, MPSM_PRD_SHIFT)
739+
#define MPSM_MFF BIT(2)
740+
#define MPSM_MMF_C22 0
741+
#define MPSM_MMF_C45 1
742+
#define MPSM_PDA GENMASK(7, 3)
743+
#define MPSM_PRA GENMASK(12, 8)
744+
#define MPSM_POP GENMASK(14, 13)
745+
#define MPSM_POP_ADDRESS 0
746+
#define MPSM_POP_WRITE 1
747+
#define MPSM_POP_READ_C22 2
748+
#define MPSM_POP_READ_C45 3
749+
#define MPSM_PRD GENMASK(31, 16)
745750

746751
#define MLVC_PLV BIT(16)
747752

0 commit comments

Comments
 (0)