Skip to content

Commit 8066021

Browse files
oleremdavem330
authored andcommitted
ethtool: provide UAPI for PHY Signal Quality Index (SQI)
Signal Quality Index is a mandatory value required by "OPEN Alliance SIG" for the 100Base-T1 PHYs [1]. This indicator can be used for cable integrity diagnostic and investigating other noise sources and implement by at least two vendors: NXP[2] and TI[3]. [1] http://www.opensig.org/download/document/218/Advanced_PHY_features_for_automotive_Ethernet_V1.0.pdf [2] https://www.nxp.com/docs/en/data-sheet/TJA1100.pdf [3] https://www.ti.com/product/DP83TC811R-Q1 Signed-off-by: Oleksij Rempel <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Reviewed-by: Michal Kubecek <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b0301a5 commit 8066021

File tree

4 files changed

+82
-3
lines changed

4 files changed

+82
-3
lines changed

Documentation/networking/ethtool-netlink.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,12 @@ Request contents:
454454

455455
Kernel response contents:
456456

457-
==================================== ====== ==========================
457+
==================================== ====== ============================
458458
``ETHTOOL_A_LINKSTATE_HEADER`` nested reply header
459459
``ETHTOOL_A_LINKSTATE_LINK`` bool link state (up/down)
460-
==================================== ====== ==========================
460+
``ETHTOOL_A_LINKSTATE_SQI`` u32 Current Signal Quality Index
461+
``ETHTOOL_A_LINKSTATE_SQI_MAX`` u32 Max support SQI value
462+
==================================== ====== ============================
461463

462464
For most NIC drivers, the value of ``ETHTOOL_A_LINKSTATE_LINK`` returns
463465
carrier flag provided by ``netif_carrier_ok()`` but there are drivers which

include/linux/phy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,8 @@ struct phy_driver {
723723
struct ethtool_tunable *tuna,
724724
const void *data);
725725
int (*set_loopback)(struct phy_device *dev, bool enable);
726+
int (*get_sqi)(struct phy_device *dev);
727+
int (*get_sqi_max)(struct phy_device *dev);
726728
};
727729
#define to_phy_driver(d) container_of(to_mdio_common_driver(d), \
728730
struct phy_driver, mdiodrv)

include/uapi/linux/ethtool_netlink.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ enum {
232232
ETHTOOL_A_LINKSTATE_UNSPEC,
233233
ETHTOOL_A_LINKSTATE_HEADER, /* nest - _A_HEADER_* */
234234
ETHTOOL_A_LINKSTATE_LINK, /* u8 */
235+
ETHTOOL_A_LINKSTATE_SQI, /* u32 */
236+
ETHTOOL_A_LINKSTATE_SQI_MAX, /* u32 */
235237

236238
/* add new constants above here */
237239
__ETHTOOL_A_LINKSTATE_CNT,

net/ethtool/linkstate.c

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "netlink.h"
44
#include "common.h"
5+
#include <linux/phy.h>
56

67
struct linkstate_req_info {
78
struct ethnl_req_info base;
@@ -10,6 +11,8 @@ struct linkstate_req_info {
1011
struct linkstate_reply_data {
1112
struct ethnl_reply_data base;
1213
int link;
14+
int sqi;
15+
int sqi_max;
1316
};
1417

1518
#define LINKSTATE_REPDATA(__reply_base) \
@@ -20,8 +23,46 @@ linkstate_get_policy[ETHTOOL_A_LINKSTATE_MAX + 1] = {
2023
[ETHTOOL_A_LINKSTATE_UNSPEC] = { .type = NLA_REJECT },
2124
[ETHTOOL_A_LINKSTATE_HEADER] = { .type = NLA_NESTED },
2225
[ETHTOOL_A_LINKSTATE_LINK] = { .type = NLA_REJECT },
26+
[ETHTOOL_A_LINKSTATE_SQI] = { .type = NLA_REJECT },
27+
[ETHTOOL_A_LINKSTATE_SQI_MAX] = { .type = NLA_REJECT },
2328
};
2429

30+
static int linkstate_get_sqi(struct net_device *dev)
31+
{
32+
struct phy_device *phydev = dev->phydev;
33+
int ret;
34+
35+
if (!phydev)
36+
return -EOPNOTSUPP;
37+
38+
mutex_lock(&phydev->lock);
39+
if (!phydev->drv || !phydev->drv->get_sqi)
40+
ret = -EOPNOTSUPP;
41+
else
42+
ret = phydev->drv->get_sqi(phydev);
43+
mutex_unlock(&phydev->lock);
44+
45+
return ret;
46+
}
47+
48+
static int linkstate_get_sqi_max(struct net_device *dev)
49+
{
50+
struct phy_device *phydev = dev->phydev;
51+
int ret;
52+
53+
if (!phydev)
54+
return -EOPNOTSUPP;
55+
56+
mutex_lock(&phydev->lock);
57+
if (!phydev->drv || !phydev->drv->get_sqi_max)
58+
ret = -EOPNOTSUPP;
59+
else
60+
ret = phydev->drv->get_sqi_max(phydev);
61+
mutex_unlock(&phydev->lock);
62+
63+
return ret;
64+
}
65+
2566
static int linkstate_prepare_data(const struct ethnl_req_info *req_base,
2667
struct ethnl_reply_data *reply_base,
2768
struct genl_info *info)
@@ -34,6 +75,19 @@ static int linkstate_prepare_data(const struct ethnl_req_info *req_base,
3475
if (ret < 0)
3576
return ret;
3677
data->link = __ethtool_get_link(dev);
78+
79+
ret = linkstate_get_sqi(dev);
80+
if (ret < 0 && ret != -EOPNOTSUPP)
81+
return ret;
82+
83+
data->sqi = ret;
84+
85+
ret = linkstate_get_sqi_max(dev);
86+
if (ret < 0 && ret != -EOPNOTSUPP)
87+
return ret;
88+
89+
data->sqi_max = ret;
90+
3791
ethnl_ops_complete(dev);
3892

3993
return 0;
@@ -42,8 +96,19 @@ static int linkstate_prepare_data(const struct ethnl_req_info *req_base,
4296
static int linkstate_reply_size(const struct ethnl_req_info *req_base,
4397
const struct ethnl_reply_data *reply_base)
4498
{
45-
return nla_total_size(sizeof(u8)) /* LINKSTATE_LINK */
99+
struct linkstate_reply_data *data = LINKSTATE_REPDATA(reply_base);
100+
int len;
101+
102+
len = nla_total_size(sizeof(u8)) /* LINKSTATE_LINK */
46103
+ 0;
104+
105+
if (data->sqi != -EOPNOTSUPP)
106+
len += nla_total_size(sizeof(u32));
107+
108+
if (data->sqi_max != -EOPNOTSUPP)
109+
len += nla_total_size(sizeof(u32));
110+
111+
return len;
47112
}
48113

49114
static int linkstate_fill_reply(struct sk_buff *skb,
@@ -56,6 +121,14 @@ static int linkstate_fill_reply(struct sk_buff *skb,
56121
nla_put_u8(skb, ETHTOOL_A_LINKSTATE_LINK, !!data->link))
57122
return -EMSGSIZE;
58123

124+
if (data->sqi != -EOPNOTSUPP &&
125+
nla_put_u32(skb, ETHTOOL_A_LINKSTATE_SQI, data->sqi))
126+
return -EMSGSIZE;
127+
128+
if (data->sqi_max != -EOPNOTSUPP &&
129+
nla_put_u32(skb, ETHTOOL_A_LINKSTATE_SQI_MAX, data->sqi_max))
130+
return -EMSGSIZE;
131+
59132
return 0;
60133
}
61134

0 commit comments

Comments
 (0)