diff --git a/misc/read_mii/read_mii.c b/misc/read_mii/read_mii.c new file mode 100644 index 0000000..603c8f1 --- /dev/null +++ b/misc/read_mii/read_mii.c @@ -0,0 +1,41 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char** argv) +{ + if (argc < 3) { + exit(1); + } + + struct ifreq ifr; + struct mii_ioctl_data* mii = (struct mii_ioctl_data*)(&ifr.ifr_data); + + memset(&ifr, 0, sizeof(ifr)); + strcpy(ifr.ifr_name, "eth0"); //set to whatever your ethernet device is + + mii->phy_id = atoi(argv[1]); //set to your phy's ID + mii->reg_num = atoi(argv[2]); //the register you want to read + + int fd = socket(AF_INET, SOCK_DGRAM, 0); + if (fd < 0) { + perror("Couldn't open socket"); + exit(2); + } + + int err = ioctl(fd, SIOCGMIIREG, &ifr); + if (err < 0) { + perror("Couldn't get MII registers"); + exit(3); + } + + printf("<<< PHY dev %d reg %2d: 0x%04x\n", (int)mii->phy_id, + (int)mii->reg_num, (int)mii->val_out); + + return 0; +} diff --git a/ti_tools/linux_lsp/kernel/linux-dvr-rdk/drivers/net/cpsw.c b/ti_tools/linux_lsp/kernel/linux-dvr-rdk/drivers/net/cpsw.c index 8242ac6..2e293eb 100755 --- a/ti_tools/linux_lsp/kernel/linux-dvr-rdk/drivers/net/cpsw.c +++ b/ti_tools/linux_lsp/kernel/linux-dvr-rdk/drivers/net/cpsw.c @@ -2438,6 +2438,26 @@ static int cpsw_ndo_do_ioctl(struct net_device *ndev, struct ifreq *ifrq, return cpsw_switch_config_ioctl(ndev, ifrq, cmd); #endif /* CONFIG_TI_CPSW_DUAL_EMAC */ + case SIOCGMIIREG: { + int ret; + struct cpsw_priv *priv = netdev_priv(ndev); + struct mii_ioctl_data* mii = (struct mii_ioctl_data*)&ifrq->ifr_data; + int slave_no = cpsw_slave_phy_index(priv); + struct phy_device *phy = priv->slaves[slave_no].phy; + struct mii_bus *bus = phy->bus; + + if (!phy || !bus || !bus->read) { + return -EOPNOTSUPP; + } + + ret = bus->read(bus, mii->phy_id, mii->reg_num); + if (ret < 0) + return ret; + + mii->val_out = (u16)ret; + break; + } + default: return -EOPNOTSUPP; }