Skip to content

Commit 2aa722b

Browse files
nikita-youshkuba-moo
authored andcommitted
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 <[email protected]> Reviewed-by: Yoshihiro Shimoda <[email protected]> Tested-by: Yoshihiro Shimoda <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 1ced1b8 commit 2aa722b

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
@@ -1195,36 +1195,29 @@ static int rswitch_etha_hw_init(struct rswitch_etha *etha, const u8 *mac)
11951195
return rswitch_etha_change_mode(etha, EAMC_OPC_OPERATION);
11961196
}
11971197

1198-
static int rswitch_etha_set_access(struct rswitch_etha *etha, bool read,
1199-
int phyad, int devad, int regad, int data)
1198+
static int rswitch_etha_mpsm_op(struct rswitch_etha *etha, bool read,
1199+
unsigned int mmf, unsigned int pda,
1200+
unsigned int pra, unsigned int pop,
1201+
unsigned int prd)
12001202
{
1201-
int pop = read ? MDIO_READ_C45 : MDIO_WRITE_C45;
12021203
u32 val;
12031204
int ret;
12041205

1205-
if (devad == 0xffffffff)
1206-
return -ENODEV;
1207-
1208-
val = MPSM_PSME | MPSM_MFF_C45;
1209-
iowrite32((regad << 16) | (devad << 8) | (phyad << 3) | val, etha->addr + MPSM);
1206+
val = MPSM_PSME |
1207+
FIELD_PREP(MPSM_MFF, mmf) |
1208+
FIELD_PREP(MPSM_PDA, pda) |
1209+
FIELD_PREP(MPSM_PRA, pra) |
1210+
FIELD_PREP(MPSM_POP, pop) |
1211+
FIELD_PREP(MPSM_PRD, prd);
1212+
iowrite32(val, etha->addr + MPSM);
12101213

12111214
ret = rswitch_reg_wait(etha->addr, MPSM, MPSM_PSME, 0);
12121215
if (ret)
12131216
return ret;
12141217

12151218
if (read) {
1216-
writel((pop << 13) | (devad << 8) | (phyad << 3) | val, etha->addr + MPSM);
1217-
1218-
ret = rswitch_reg_wait(etha->addr, MPSM, MPSM_PSME, 0);
1219-
if (ret)
1220-
return ret;
1221-
1222-
ret = (ioread32(etha->addr + MPSM) & MPSM_PRD_MASK) >> 16;
1223-
} else {
1224-
iowrite32((data << 16) | (pop << 13) | (devad << 8) | (phyad << 3) | val,
1225-
etha->addr + MPSM);
1226-
1227-
ret = rswitch_reg_wait(etha->addr, MPSM, MPSM_PSME, 0);
1219+
val = ioread32(etha->addr + MPSM);
1220+
ret = FIELD_GET(MPSM_PRD, val);
12281221
}
12291222

12301223
return ret;
@@ -1234,16 +1227,30 @@ static int rswitch_etha_mii_read_c45(struct mii_bus *bus, int addr, int devad,
12341227
int regad)
12351228
{
12361229
struct rswitch_etha *etha = bus->priv;
1230+
int ret;
12371231

1238-
return rswitch_etha_set_access(etha, true, addr, devad, regad, 0);
1232+
ret = rswitch_etha_mpsm_op(etha, false, MPSM_MMF_C45, addr, devad,
1233+
MPSM_POP_ADDRESS, regad);
1234+
if (ret)
1235+
return ret;
1236+
1237+
return rswitch_etha_mpsm_op(etha, true, MPSM_MMF_C45, addr, devad,
1238+
MPSM_POP_READ_C45, 0);
12391239
}
12401240

12411241
static int rswitch_etha_mii_write_c45(struct mii_bus *bus, int addr, int devad,
12421242
int regad, u16 val)
12431243
{
12441244
struct rswitch_etha *etha = bus->priv;
1245+
int ret;
1246+
1247+
ret = rswitch_etha_mpsm_op(etha, false, MPSM_MMF_C45, addr, devad,
1248+
MPSM_POP_ADDRESS, regad);
1249+
if (ret)
1250+
return ret;
12451251

1246-
return rswitch_etha_set_access(etha, false, addr, devad, regad, val);
1252+
return rswitch_etha_mpsm_op(etha, false, MPSM_MMF_C45, addr, devad,
1253+
MPSM_POP_WRITE, val);
12471254
}
12481255

12491256
/* 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)