Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp263474ybi; Fri, 31 May 2019 00:49:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqyDrh32CLovMUILBb3oJMwLZZUghKPZMXG/qJVkrtpsepuit8uGlWqrnV+ZSPGMg/krHMZO X-Received: by 2002:a63:1212:: with SMTP id h18mr7403073pgl.266.1559288951981; Fri, 31 May 2019 00:49:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559288951; cv=none; d=google.com; s=arc-20160816; b=HRRHYb1Fn7X0ByBIPu+QK5OPqdfLhTLijXPG1rO0CUXPwzDfpDlEoz9qMWjTf/PmCi RJWE69/k4O871MA45dDnF84u6zPRepVoLO1c9+iQVFKpy//JvDljh4Za3Zw9dLUmv+/X BQFaWL4gFYq8eudRD+XUrhRRQ7vD/dEAuZ8mJAGITY1+fY9r2eB3eP1yJ8/3X/ouV3+w yEVIQeb6n9VneHIxmUSaKcdr7DXOzhot/2uOjU/gTMr40uX8f0GVCYEutpSuA8v0IYxp OsnGZLdoyd2iBl9tATWMbeaI+/bt+3xLrgbbANLM9zWdnnLg+utb17VOhZAaV0fOBYBz TktQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=dzpfityjiyVjBLgLIDdS7jy7fuGuzY8jJendAr5fdaU=; b=R9cwFTlXdN4ydSiWjxsPRYoZccfEcR/fZuveC1i2BpwIKRbSYAH6HGN1wS6fQBb6LC tYvyhI/q0yFdOcWwpmJ9x+eyyoMyonyLFgbI9vVYzNL7GAw8yBd4YLppfi5wDkw3H1Xi ieN8Kzf2N0DSMhGic/lCHe957PCGGWn3cJFsdDAO0GtB8J1kEf3Z7RobdKDkn+YyudnQ 6csMCyFWUZyU30MT5xagNG7SgS0BdbG2cAtYnTuOq/uIFk/Ve3QoJWBSM7gV3p4dWJlH iv9Xc82BY2PC7F4jPh/XxCBJl0MWxeb1BKR0MY/yTMrS7NCXu4J9OXtoK12a7NBU2HuS sbUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cogentembedded-com.20150623.gappssmtp.com header.s=20150623 header.b=hZaEcrWu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bg10si5029592plb.28.2019.05.31.00.48.56; Fri, 31 May 2019 00:49:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@cogentembedded-com.20150623.gappssmtp.com header.s=20150623 header.b=hZaEcrWu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726947AbfEaHrp (ORCPT + 99 others); Fri, 31 May 2019 03:47:45 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:41741 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726158AbfEaHrp (ORCPT ); Fri, 31 May 2019 03:47:45 -0400 Received: by mail-wr1-f67.google.com with SMTP id c2so5797631wrm.8 for ; Fri, 31 May 2019 00:47:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cogentembedded-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=dzpfityjiyVjBLgLIDdS7jy7fuGuzY8jJendAr5fdaU=; b=hZaEcrWuUar2mSp1ulSSIeJ12sn8rUP1OAZf+IIRLpBbnKhQSP9vi0gQXR0j1ER0LX ltI4MssBF2CzGdisONdQnG4gD88VboWQpwTL4trObnfDYR3Sl/QFjKXn9dby4LOS043X 3Rops2zaYBopA+JOQ7ZNXWXkJsaNcBwiOE/9T0nsnPbNUxOwEAvapWcICHZuH3or8+mt 8ZX1Pgan+DnhKlHYud7azYM+juhUDqlDTTbFLwWum0uUKv/+cLO6k9tuvm6x+605IMli yWW9EQXOgkBgS7mI9g53fdyB525QQpsuP4QZcJVDgLZkUqMELDZVpMazCy6hyuS6Ffg1 +64Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=dzpfityjiyVjBLgLIDdS7jy7fuGuzY8jJendAr5fdaU=; b=OKPY9gUfKjtQ+ODAHHvcl7T1Zffb1NcTfaK6ZIMPyHMb0XAim5sERV6TzvVLvuWact 4rplFCgBJ9esEhGx7lqDUz5QkGOYM4Uy45QvZFCrN3Oc3T1u4jBgDhK8ttKAkwAisgnd vtsbYXN62khHJw5/B8qd3HfChHDsGkM0Qc5kd+a1n08LuxVeopodKKSBKpJ5ldu/qz9u 863r0XS4OekfwOa86yTnWj3CtEqeZVQsFjvnx1HNzUzWkX+eSfPIHaGEeqdBL6fY72S0 ctWDSrmwD6Rs5Ijaz8Vucglii9AJPhUpCFkvol+EVs3qz2rCEpuKmSrSpU0UjfFLutcb ZQIA== X-Gm-Message-State: APjAAAWRWzSrWm1yREBN6b6L4IieYMjc80qC7wYzJRU57rxuY9taW423 G+kCRnLHhLH5nQJ4VzrBZgiuNQ== X-Received: by 2002:a5d:6709:: with SMTP id o9mr5380589wru.301.1559288863582; Fri, 31 May 2019 00:47:43 -0700 (PDT) Received: from cobook.home (nikaet.starlink.ru. [94.141.168.29]) by smtp.gmail.com with ESMTPSA id a4sm11022778wrf.78.2019.05.31.00.47.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 May 2019 00:47:43 -0700 (PDT) From: Nikita Yushchenko To: Andrew Lunn , Florian Fainelli Cc: Heiner Kallweit , "David S. Miller" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Chris Healy , Nikita Yushchenko Subject: [PATCH] net: phy: support C45 phys in SIOCGMIIREG/SIOCSMIIREG ioctls Date: Fri, 31 May 2019 10:47:27 +0300 Message-Id: <20190531074727.3257-1-nikita.yoush@cogentembedded.com> X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This change allows phytool [1] and similar tools to read and write C45 phy registers from userspace. This is useful for debugging and for porting vendor phy diagnostics tools. [1] https://github.com/wkz/phytool Signed-off-by: Nikita Yushchenko --- drivers/net/phy/phy.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index e8885429293a..3d991958bde0 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -407,6 +407,7 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd) struct mii_ioctl_data *mii_data = if_mii(ifr); u16 val = mii_data->val_in; bool change_autoneg = false; + int ret; switch (cmd) { case SIOCGMIIPHY: @@ -414,12 +415,28 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd) /* fall through */ case SIOCGMIIREG: + if (mdio_phy_id_is_c45(mii_data->phy_id)) { + ret = phy_read_mmd(phydev, + mdio_phy_id_devad(mii_data->phy_id), + mii_data->reg_num); + if (ret < 0) + return ret; + mii_data->val_out = ret; + return 0; + } mii_data->val_out = mdiobus_read(phydev->mdio.bus, mii_data->phy_id, mii_data->reg_num); return 0; case SIOCSMIIREG: + if (mdio_phy_id_is_c45(mii_data->phy_id)) { + ret = phy_write_mmd(phydev, + mdio_phy_id_devad(mii_data->phy_id), + mii_data->reg_num, + mii_data->val_in); + return ret; + } if (mii_data->phy_id == phydev->mdio.addr) { switch (mii_data->reg_num) { case MII_BMCR: -- 2.11.0