realtek: mdio: add phy to port lookup
The Realtek mdio bus operations are based on the port number. As of now the driver exposes a single bus with a 1:1 mapping between phy and port. This will change in the future when the driver exposes multiple busses. This will need a mapping - e.g. - bus 0, phy 23 -> read/write port 23 - bus 1, phy 0 -> read/write port 24 Provide a rtmdio_phy_to_port() indirection function that will lookup the port number based on a bus and a phy. For now it will only run some basic sanity checks and return the given input address (because of 1:1 mapping). Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de> Link: https://github.com/openwrt/openwrt/pull/22731 Signed-off-by: Robert Marko <robimarko@gmail.com>
This commit is contained in:
parent
15de91f1e9
commit
3ef3fb9db9
@ -223,6 +223,19 @@ struct rtmdio_phy_info {
|
||||
unsigned int poll_lpa_1000;
|
||||
};
|
||||
|
||||
static int rtmdio_phy_to_port(struct mii_bus *bus, int phy)
|
||||
{
|
||||
struct rtmdio_ctrl *ctrl = rtmdio_ctrl_from_bus(bus);
|
||||
|
||||
if (phy < 0 || phy >= ctrl->cfg->num_phys)
|
||||
return -ENOENT;
|
||||
|
||||
if (!test_bit(phy, ctrl->valid_ports))
|
||||
return -ENOENT;
|
||||
|
||||
return phy;
|
||||
}
|
||||
|
||||
static int rtmdio_run_cmd(struct mii_bus *bus, int cmd, int mask, int regnum, int fail)
|
||||
{
|
||||
struct rtmdio_ctrl *ctrl = rtmdio_ctrl_from_bus(bus);
|
||||
@ -501,13 +514,14 @@ static int rtmdio_931x_write_mmd_phy(struct mii_bus *bus, u32 addr, u32 devnum,
|
||||
return rtmdio_931x_run_cmd(bus, RTMDIO_931X_CMD_WRITE_C45);
|
||||
}
|
||||
|
||||
static int rtmdio_read_c45(struct mii_bus *bus, int addr, int devnum, int regnum)
|
||||
static int rtmdio_read_c45(struct mii_bus *bus, int phy, int devnum, int regnum)
|
||||
{
|
||||
struct rtmdio_ctrl *ctrl = rtmdio_ctrl_from_bus(bus);
|
||||
int err, val;
|
||||
int err, val, addr;
|
||||
|
||||
if (addr >= ctrl->cfg->num_phys)
|
||||
return -ENODEV;
|
||||
addr = rtmdio_phy_to_port(bus, phy);
|
||||
if (addr < 0)
|
||||
return addr;
|
||||
|
||||
guard(mutex)(&ctrl->lock);
|
||||
err = (*ctrl->cfg->read_mmd_phy)(bus, addr, devnum, regnum, &val);
|
||||
@ -517,13 +531,14 @@ static int rtmdio_read_c45(struct mii_bus *bus, int addr, int devnum, int regnum
|
||||
return err ? err : val;
|
||||
}
|
||||
|
||||
static int rtmdio_read(struct mii_bus *bus, int addr, int regnum)
|
||||
static int rtmdio_read(struct mii_bus *bus, int phy, int regnum)
|
||||
{
|
||||
struct rtmdio_ctrl *ctrl = rtmdio_ctrl_from_bus(bus);
|
||||
int err, val;
|
||||
int err, val, addr;
|
||||
|
||||
if (addr >= ctrl->cfg->num_phys)
|
||||
return -ENODEV;
|
||||
addr = rtmdio_phy_to_port(bus, phy);
|
||||
if (addr < 0)
|
||||
return addr;
|
||||
|
||||
guard(mutex)(&ctrl->lock);
|
||||
if (regnum == RTMDIO_PAGE_SELECT && ctrl->port[addr].page != ctrl->cfg->raw_page)
|
||||
@ -538,13 +553,14 @@ static int rtmdio_read(struct mii_bus *bus, int addr, int regnum)
|
||||
return err ? err : val;
|
||||
}
|
||||
|
||||
static int rtmdio_write_c45(struct mii_bus *bus, int addr, int devnum, int regnum, u16 val)
|
||||
static int rtmdio_write_c45(struct mii_bus *bus, int phy, int devnum, int regnum, u16 val)
|
||||
{
|
||||
struct rtmdio_ctrl *ctrl = rtmdio_ctrl_from_bus(bus);
|
||||
int err;
|
||||
int err, addr;
|
||||
|
||||
if (addr >= ctrl->cfg->num_phys)
|
||||
return -ENODEV;
|
||||
addr = rtmdio_phy_to_port(bus, phy);
|
||||
if (addr < 0)
|
||||
return addr;
|
||||
|
||||
guard(mutex)(&ctrl->lock);
|
||||
err = (*ctrl->cfg->write_mmd_phy)(bus, addr, devnum, regnum, val);
|
||||
@ -554,13 +570,14 @@ static int rtmdio_write_c45(struct mii_bus *bus, int addr, int devnum, int regnu
|
||||
return err;
|
||||
}
|
||||
|
||||
static int rtmdio_write(struct mii_bus *bus, int addr, int regnum, u16 val)
|
||||
static int rtmdio_write(struct mii_bus *bus, int phy, int regnum, u16 val)
|
||||
{
|
||||
struct rtmdio_ctrl *ctrl = rtmdio_ctrl_from_bus(bus);
|
||||
int err, page;
|
||||
int err, page, addr;
|
||||
|
||||
if (addr >= ctrl->cfg->num_phys)
|
||||
return -ENODEV;
|
||||
addr = rtmdio_phy_to_port(bus, phy);
|
||||
if (addr < 0)
|
||||
return addr;
|
||||
|
||||
guard(mutex)(&ctrl->lock);
|
||||
page = ctrl->port[addr].page;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user