Commit 943bbe1d authored by David S. Miller's avatar David S. Miller

Merge branch 'Raw-PHY-TDR-data'

Andrew Lunn says:

====================
Raw PHY TDR data

Some ethernet PHYs allow access to raw TDR data in addition to summary
diagnostics information. Add support for retrieving this data via
netlink ethtool. The basic structure in the core is the same as for
normal phy diagnostics, the PHY driver simply uses different helpers
to fill the netlink message with different data.

There is a graphical tool under development, as well a ethtool(1)
which can dump the data as text and JSON.

A patched ethtool(1) can be found in
https://github.com/lunn/ethtool.git feature/cable-test-v5

Thanks for Chris Healy for lots of testing.

v2:
See the individual patches but:

Pass distances in centimeters, not meters

Allow the PHY to round distances to what it supports and report what
it actually used along with the results.

Make the Marvell PHY use steps a multiple of 0.805 meters, its native
step size.

v3:
Move the TDR configuration into a structure
Add a range check on step
Use NL_SET_ERR_MSG_ATTR() when appropriate
Move TDR configuration into a nest
Document attributes in the request
Unsquash the last two patches
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 53c0ec4f db8668a1
...@@ -205,6 +205,7 @@ Userspace to kernel: ...@@ -205,6 +205,7 @@ Userspace to kernel:
``ETHTOOL_MSG_EEE_SET`` set EEE settings ``ETHTOOL_MSG_EEE_SET`` set EEE settings
``ETHTOOL_MSG_TSINFO_GET`` get timestamping info ``ETHTOOL_MSG_TSINFO_GET`` get timestamping info
``ETHTOOL_MSG_CABLE_TEST_ACT`` action start cable test ``ETHTOOL_MSG_CABLE_TEST_ACT`` action start cable test
``ETHTOOL_MSG_CABLE_TEST_TDR_ACT`` action start raw TDR cable test
===================================== ================================ ===================================== ================================
Kernel to userspace: Kernel to userspace:
...@@ -237,6 +238,7 @@ Kernel to userspace: ...@@ -237,6 +238,7 @@ Kernel to userspace:
``ETHTOOL_MSG_EEE_NTF`` EEE settings ``ETHTOOL_MSG_EEE_NTF`` EEE settings
``ETHTOOL_MSG_TSINFO_GET_REPLY`` timestamping info ``ETHTOOL_MSG_TSINFO_GET_REPLY`` timestamping info
``ETHTOOL_MSG_CABLE_TEST_NTF`` Cable test results ``ETHTOOL_MSG_CABLE_TEST_NTF`` Cable test results
``ETHTOOL_MSG_CABLE_TEST_TDR_NTF`` Cable test TDR results
===================================== ================================= ===================================== =================================
``GET`` requests are sent by userspace applications to retrieve device ``GET`` requests are sent by userspace applications to retrieve device
...@@ -1014,6 +1016,100 @@ information. ...@@ -1014,6 +1016,100 @@ information.
| | | ``ETHTOOL_A_CABLE_FAULT_LENGTH_CM`` | u32 | length in cm | | | | ``ETHTOOL_A_CABLE_FAULT_LENGTH_CM`` | u32 | length in cm |
+-+-+-----------------------------------------+--------+---------------------+ +-+-+-----------------------------------------+--------+---------------------+
CABLE_TEST TDR
==============
Start a cable test and report raw TDR data
Request contents:
+--------------------------------------------+--------+-----------------------+
| ``ETHTOOL_A_CABLE_TEST_TDR_HEADER`` | nested | reply header |
+--------------------------------------------+--------+-----------------------+
| ``ETHTOOL_A_CABLE_TEST_TDR_CFG`` | nested | test configuration |
+-+------------------------------------------+--------+-----------------------+
| | ``ETHTOOL_A_CABLE_STEP_FIRST_DISTANCE `` | u32 | first data distance |
+-+-+----------------------------------------+--------+-----------------------+
| | ``ETHTOOL_A_CABLE_STEP_LAST_DISTANCE `` | u32 | last data distance |
+-+-+----------------------------------------+--------+-----------------------+
| | ``ETHTOOL_A_CABLE_STEP_STEP_DISTANCE `` | u32 | distance of each step |
+-+-+----------------------------------------+--------+-----------------------+
| | ``ETHTOOL_A_CABLE_TEST_TDR_CFG_PAIR`` | u8 | pair to test |
+-+-+----------------------------------------+--------+-----------------------+
The ETHTOOL_A_CABLE_TEST_TDR_CFG is optional, as well as all members
of the nest. All distances are expressed in centimeters. The PHY takes
the distances as a guide, and rounds to the nearest distance it
actually supports. If a pair is passed, only that one pair will be
tested. Otherwise all pairs are tested.
Notification contents:
Raw TDR data is gathered by sending a pulse down the cable and
recording the amplitude of the reflected pulse for a given distance.
It can take a number of seconds to collect TDR data, especial if the
full 100 meters is probed at 1 meter intervals. When the test is
started a notification will be sent containing just
ETHTOOL_A_CABLE_TEST_TDR_STATUS with the value
ETHTOOL_A_CABLE_TEST_NTF_STATUS_STARTED.
When the test has completed a second notification will be sent
containing ETHTOOL_A_CABLE_TEST_TDR_STATUS with the value
ETHTOOL_A_CABLE_TEST_NTF_STATUS_COMPLETED and the TDR data.
The message may optionally contain the amplitude of the pulse send
down the cable. This is measured in mV. A reflection should not be
bigger than transmitted pulse.
Before the raw TDR data should be an ETHTOOL_A_CABLE_TDR_NEST_STEP
nest containing information about the distance along the cable for the
first reading, the last reading, and the step between each
reading. Distances are measured in centimeters. These should be the
exact values the PHY used. These may be different to what the user
requested, if the native measurement resolution is greater than 1 cm.
For each step along the cable, a ETHTOOL_A_CABLE_TDR_NEST_AMPLITUDE is
used to report the amplitude of the reflection for a given pair.
+---------------------------------------------+--------+----------------------+
| ``ETHTOOL_A_CABLE_TEST_TDR_HEADER`` | nested | reply header |
+---------------------------------------------+--------+----------------------+
| ``ETHTOOL_A_CABLE_TEST_TDR_STATUS`` | u8 | completed |
+---------------------------------------------+--------+----------------------+
| ``ETHTOOL_A_CABLE_TEST_TDR_NTF_NEST`` | nested | all the results |
+-+-------------------------------------------+--------+----------------------+
| | ``ETHTOOL_A_CABLE_TDR_NEST_PULSE`` | nested | TX Pulse amplitude |
+-+-+-----------------------------------------+--------+----------------------+
| | | ``ETHTOOL_A_CABLE_PULSE_mV`` | s16 | Pulse amplitude |
+-+-+-----------------------------------------+--------+----------------------+
| | ``ETHTOOL_A_CABLE_NEST_STEP`` | nested | TDR step info |
+-+-+-----------------------------------------+--------+----------------------+
| | | ``ETHTOOL_A_CABLE_STEP_FIRST_DISTANCE ``| u32 | First data distance |
+-+-+-----------------------------------------+--------+----------------------+
| | | ``ETHTOOL_A_CABLE_STEP_LAST_DISTANCE `` | u32 | Last data distance |
+-+-+-----------------------------------------+--------+----------------------+
| | | ``ETHTOOL_A_CABLE_STEP_STEP_DISTANCE `` | u32 | distance of each step|
+-+-+-----------------------------------------+--------+----------------------+
| | ``ETHTOOL_A_CABLE_TDR_NEST_AMPLITUDE`` | nested | Reflection amplitude |
+-+-+-----------------------------------------+--------+----------------------+
| | | ``ETHTOOL_A_CABLE_RESULTS_PAIR`` | u8 | pair number |
+-+-+-----------------------------------------+--------+----------------------+
| | | ``ETHTOOL_A_CABLE_AMPLITUDE_mV`` | s16 | Reflection amplitude |
+-+-+-----------------------------------------+--------+----------------------+
| | ``ETHTOOL_A_CABLE_TDR_NEST_AMPLITUDE`` | nested | Reflection amplitude |
+-+-+-----------------------------------------+--------+----------------------+
| | | ``ETHTOOL_A_CABLE_RESULTS_PAIR`` | u8 | pair number |
+-+-+-----------------------------------------+--------+----------------------+
| | | ``ETHTOOL_A_CABLE_AMPLITUDE_mV`` | s16 | Reflection amplitude |
+-+-+-----------------------------------------+--------+----------------------+
| | ``ETHTOOL_A_CABLE_TDR_NEST_AMPLITUDE`` | nested | Reflection amplitude |
+-+-+-----------------------------------------+--------+----------------------+
| | | ``ETHTOOL_A_CABLE_RESULTS_PAIR`` | u8 | pair number |
+-+-+-----------------------------------------+--------+----------------------+
| | | ``ETHTOOL_A_CABLE_AMPLITUDE_mV`` | s16 | Reflection amplitude |
+-+-+-----------------------------------------+--------+----------------------+
Request translation Request translation
=================== ===================
...@@ -1110,4 +1206,5 @@ are netlink only. ...@@ -1110,4 +1206,5 @@ are netlink only.
``ETHTOOL_GFECPARAM`` n/a ``ETHTOOL_GFECPARAM`` n/a
``ETHTOOL_SFECPARAM`` n/a ``ETHTOOL_SFECPARAM`` n/a
n/a ''ETHTOOL_MSG_CABLE_TEST_ACT'' n/a ''ETHTOOL_MSG_CABLE_TEST_ACT''
n/a ''ETHTOOL_MSG_CABLE_TEST_TDR_ACT''
=================================== ===================================== =================================== =====================================
This diff is collapsed.
...@@ -194,7 +194,7 @@ static int tja11xx_config_aneg_cable_test(struct phy_device *phydev) ...@@ -194,7 +194,7 @@ static int tja11xx_config_aneg_cable_test(struct phy_device *phydev)
!phydev->drv->cable_test_get_status) !phydev->drv->cable_test_get_status)
return 0; return 0;
ret = ethnl_cable_test_alloc(phydev); ret = ethnl_cable_test_alloc(phydev, ETHTOOL_MSG_CABLE_TEST_NTF);
if (ret) if (ret)
return ret; return ret;
......
...@@ -519,7 +519,7 @@ int phy_start_cable_test(struct phy_device *phydev, ...@@ -519,7 +519,7 @@ int phy_start_cable_test(struct phy_device *phydev,
goto out; goto out;
} }
err = ethnl_cable_test_alloc(phydev); err = ethnl_cable_test_alloc(phydev, ETHTOOL_MSG_CABLE_TEST_NTF);
if (err) if (err)
goto out; goto out;
...@@ -552,6 +552,70 @@ int phy_start_cable_test(struct phy_device *phydev, ...@@ -552,6 +552,70 @@ int phy_start_cable_test(struct phy_device *phydev,
} }
EXPORT_SYMBOL(phy_start_cable_test); EXPORT_SYMBOL(phy_start_cable_test);
int phy_start_cable_test_tdr(struct phy_device *phydev,
struct netlink_ext_ack *extack,
const struct phy_tdr_config *config)
{
struct net_device *dev = phydev->attached_dev;
int err = -ENOMEM;
if (!(phydev->drv &&
phydev->drv->cable_test_tdr_start &&
phydev->drv->cable_test_get_status)) {
NL_SET_ERR_MSG(extack,
"PHY driver does not support cable test TDR");
return -EOPNOTSUPP;
}
mutex_lock(&phydev->lock);
if (phydev->state == PHY_CABLETEST) {
NL_SET_ERR_MSG(extack,
"PHY already performing a test");
err = -EBUSY;
goto out;
}
if (phydev->state < PHY_UP ||
phydev->state > PHY_CABLETEST) {
NL_SET_ERR_MSG(extack,
"PHY not configured. Try setting interface up");
err = -EBUSY;
goto out;
}
err = ethnl_cable_test_alloc(phydev, ETHTOOL_MSG_CABLE_TEST_TDR_NTF);
if (err)
goto out;
/* Mark the carrier down until the test is complete */
phy_link_down(phydev);
netif_testing_on(dev);
err = phydev->drv->cable_test_tdr_start(phydev, config);
if (err) {
netif_testing_off(dev);
phy_link_up(phydev);
goto out_free;
}
phydev->state = PHY_CABLETEST;
if (phy_polling_mode(phydev))
phy_trigger_machine(phydev);
mutex_unlock(&phydev->lock);
return 0;
out_free:
ethnl_cable_test_free(phydev);
out:
mutex_unlock(&phydev->lock);
return err;
}
EXPORT_SYMBOL(phy_start_cable_test_tdr);
static int phy_config_aneg(struct phy_device *phydev) static int phy_config_aneg(struct phy_device *phydev)
{ {
if (phydev->drv->config_aneg) if (phydev->drv->config_aneg)
......
...@@ -17,13 +17,17 @@ enum ethtool_multicast_groups { ...@@ -17,13 +17,17 @@ enum ethtool_multicast_groups {
struct phy_device; struct phy_device;
#if IS_ENABLED(CONFIG_ETHTOOL_NETLINK) #if IS_ENABLED(CONFIG_ETHTOOL_NETLINK)
int ethnl_cable_test_alloc(struct phy_device *phydev); int ethnl_cable_test_alloc(struct phy_device *phydev, u8 cmd);
void ethnl_cable_test_free(struct phy_device *phydev); void ethnl_cable_test_free(struct phy_device *phydev);
void ethnl_cable_test_finished(struct phy_device *phydev); void ethnl_cable_test_finished(struct phy_device *phydev);
int ethnl_cable_test_result(struct phy_device *phydev, u8 pair, u8 result); int ethnl_cable_test_result(struct phy_device *phydev, u8 pair, u8 result);
int ethnl_cable_test_fault_length(struct phy_device *phydev, u8 pair, u32 cm); int ethnl_cable_test_fault_length(struct phy_device *phydev, u8 pair, u32 cm);
int ethnl_cable_test_amplitude(struct phy_device *phydev, u8 pair, s16 mV);
int ethnl_cable_test_pulse(struct phy_device *phydev, u16 mV);
int ethnl_cable_test_step(struct phy_device *phydev, u32 first, u32 last,
u32 step);
#else #else
static inline int ethnl_cable_test_alloc(struct phy_device *phydev) static inline int ethnl_cable_test_alloc(struct phy_device *phydev, u8 cmd)
{ {
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
...@@ -46,5 +50,22 @@ static inline int ethnl_cable_test_fault_length(struct phy_device *phydev, ...@@ -46,5 +50,22 @@ static inline int ethnl_cable_test_fault_length(struct phy_device *phydev,
{ {
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
static inline int ethnl_cable_test_amplitude(struct phy_device *phydev,
u8 pair, s16 mV)
{
return -EOPNOTSUPP;
}
static inline int ethnl_cable_test_pulse(struct phy_device *phydev, u16 mV)
{
return -EOPNOTSUPP;
}
static inline int ethnl_cable_test_step(struct phy_device *phydev, u32 first,
u32 last, u32 step)
{
return -EOPNOTSUPP;
}
#endif /* IS_ENABLED(ETHTOOL_NETLINK) */ #endif /* IS_ENABLED(ETHTOOL_NETLINK) */
#endif /* _LINUX_ETHTOOL_NETLINK_H_ */ #endif /* _LINUX_ETHTOOL_NETLINK_H_ */
...@@ -548,6 +548,18 @@ struct phy_device { ...@@ -548,6 +548,18 @@ struct phy_device {
#define to_phy_device(d) container_of(to_mdio_device(d), \ #define to_phy_device(d) container_of(to_mdio_device(d), \
struct phy_device, mdio) struct phy_device, mdio)
/* A structure containing possible configuration parameters
* for a TDR cable test. The driver does not need to implement
* all the parameters, but should report what is actually used.
*/
struct phy_tdr_config {
u32 first;
u32 last;
u32 step;
s8 pair;
};
#define PHY_PAIR_ALL -1
/* struct phy_driver: Driver structure for a particular PHY type /* struct phy_driver: Driver structure for a particular PHY type
* *
* driver_data: static driver data * driver_data: static driver data
...@@ -699,6 +711,11 @@ struct phy_driver { ...@@ -699,6 +711,11 @@ struct phy_driver {
/* Start a cable test */ /* Start a cable test */
int (*cable_test_start)(struct phy_device *dev); int (*cable_test_start)(struct phy_device *dev);
/* Start a raw TDR cable test */
int (*cable_test_tdr_start)(struct phy_device *dev,
const struct phy_tdr_config *config);
/* Once per second, or on interrupt, request the status of the /* Once per second, or on interrupt, request the status of the
* test. * test.
*/ */
...@@ -1251,6 +1268,9 @@ int phy_reset_after_clk_enable(struct phy_device *phydev); ...@@ -1251,6 +1268,9 @@ int phy_reset_after_clk_enable(struct phy_device *phydev);
#if IS_ENABLED(CONFIG_PHYLIB) #if IS_ENABLED(CONFIG_PHYLIB)
int phy_start_cable_test(struct phy_device *phydev, int phy_start_cable_test(struct phy_device *phydev,
struct netlink_ext_ack *extack); struct netlink_ext_ack *extack);
int phy_start_cable_test_tdr(struct phy_device *phydev,
struct netlink_ext_ack *extack,
const struct phy_tdr_config *config);
#else #else
static inline static inline
int phy_start_cable_test(struct phy_device *phydev, int phy_start_cable_test(struct phy_device *phydev,
...@@ -1259,6 +1279,14 @@ int phy_start_cable_test(struct phy_device *phydev, ...@@ -1259,6 +1279,14 @@ int phy_start_cable_test(struct phy_device *phydev,
NL_SET_ERR_MSG(extack, "Kernel not compiled with PHYLIB support"); NL_SET_ERR_MSG(extack, "Kernel not compiled with PHYLIB support");
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
static inline
int phy_start_cable_test_tdr(struct phy_device *phydev,
struct netlink_ext_ack *extack,
const struct phy_tdr_config *config)
{
NL_SET_ERR_MSG(extack, "Kernel not compiled with PHYLIB support");
return -EOPNOTSUPP;
}
#endif #endif
int phy_cable_test_result(struct phy_device *phydev, u8 pair, u16 result); int phy_cable_test_result(struct phy_device *phydev, u8 pair, u16 result);
......
...@@ -40,6 +40,7 @@ enum { ...@@ -40,6 +40,7 @@ enum {
ETHTOOL_MSG_EEE_SET, ETHTOOL_MSG_EEE_SET,
ETHTOOL_MSG_TSINFO_GET, ETHTOOL_MSG_TSINFO_GET,
ETHTOOL_MSG_CABLE_TEST_ACT, ETHTOOL_MSG_CABLE_TEST_ACT,
ETHTOOL_MSG_CABLE_TEST_TDR_ACT,
/* add new constants above here */ /* add new constants above here */
__ETHTOOL_MSG_USER_CNT, __ETHTOOL_MSG_USER_CNT,
...@@ -76,6 +77,7 @@ enum { ...@@ -76,6 +77,7 @@ enum {
ETHTOOL_MSG_EEE_NTF, ETHTOOL_MSG_EEE_NTF,
ETHTOOL_MSG_TSINFO_GET_REPLY, ETHTOOL_MSG_TSINFO_GET_REPLY,
ETHTOOL_MSG_CABLE_TEST_NTF, ETHTOOL_MSG_CABLE_TEST_NTF,
ETHTOOL_MSG_CABLE_TEST_TDR_NTF,
/* add new constants above here */ /* add new constants above here */
__ETHTOOL_MSG_KERNEL_CNT, __ETHTOOL_MSG_KERNEL_CNT,
...@@ -478,6 +480,80 @@ enum { ...@@ -478,6 +480,80 @@ enum {
ETHTOOL_A_CABLE_TEST_NTF_MAX = (__ETHTOOL_A_CABLE_TEST_NTF_CNT - 1) ETHTOOL_A_CABLE_TEST_NTF_MAX = (__ETHTOOL_A_CABLE_TEST_NTF_CNT - 1)
}; };
/* CABLE TEST TDR */
enum {
ETHTOOL_A_CABLE_TEST_TDR_CFG_UNSPEC,
ETHTOOL_A_CABLE_TEST_TDR_CFG_FIRST, /* u32 */
ETHTOOL_A_CABLE_TEST_TDR_CFG_LAST, /* u32 */
ETHTOOL_A_CABLE_TEST_TDR_CFG_STEP, /* u32 */
ETHTOOL_A_CABLE_TEST_TDR_CFG_PAIR, /* u8 */
/* add new constants above here */
__ETHTOOL_A_CABLE_TEST_TDR_CFG_CNT,
ETHTOOL_A_CABLE_TEST_TDR_CFG_MAX = __ETHTOOL_A_CABLE_TEST_TDR_CFG_CNT - 1
};
enum {
ETHTOOL_A_CABLE_TEST_TDR_UNSPEC,
ETHTOOL_A_CABLE_TEST_TDR_HEADER, /* nest - _A_HEADER_* */
ETHTOOL_A_CABLE_TEST_TDR_CFG, /* nest - *_TDR_CFG_* */
/* add new constants above here */
__ETHTOOL_A_CABLE_TEST_TDR_CNT,
ETHTOOL_A_CABLE_TEST_TDR_MAX = __ETHTOOL_A_CABLE_TEST_TDR_CNT - 1
};
/* CABLE TEST TDR NOTIFY */
enum {
ETHTOOL_A_CABLE_AMPLITUDE_UNSPEC,
ETHTOOL_A_CABLE_AMPLITUDE_PAIR, /* u8 */
ETHTOOL_A_CABLE_AMPLITUDE_mV, /* s16 */
__ETHTOOL_A_CABLE_AMPLITUDE_CNT,
ETHTOOL_A_CABLE_AMPLITUDE_MAX = (__ETHTOOL_A_CABLE_AMPLITUDE_CNT - 1)
};
enum {
ETHTOOL_A_CABLE_PULSE_UNSPEC,
ETHTOOL_A_CABLE_PULSE_mV, /* s16 */
__ETHTOOL_A_CABLE_PULSE_CNT,
ETHTOOL_A_CABLE_PULSE_MAX = (__ETHTOOL_A_CABLE_PULSE_CNT - 1)
};
enum {
ETHTOOL_A_CABLE_STEP_UNSPEC,
ETHTOOL_A_CABLE_STEP_FIRST_DISTANCE, /* u32 */
ETHTOOL_A_CABLE_STEP_LAST_DISTANCE, /* u32 */
ETHTOOL_A_CABLE_STEP_STEP_DISTANCE, /* u32 */
__ETHTOOL_A_CABLE_STEP_CNT,
ETHTOOL_A_CABLE_STEP_MAX = (__ETHTOOL_A_CABLE_STEP_CNT - 1)
};
enum {
ETHTOOL_A_CABLE_TDR_NEST_UNSPEC,
ETHTOOL_A_CABLE_TDR_NEST_STEP, /* nest - ETHTTOOL_A_CABLE_STEP */
ETHTOOL_A_CABLE_TDR_NEST_AMPLITUDE, /* nest - ETHTOOL_A_CABLE_AMPLITUDE */
ETHTOOL_A_CABLE_TDR_NEST_PULSE, /* nest - ETHTOOL_A_CABLE_PULSE */
__ETHTOOL_A_CABLE_TDR_NEST_CNT,
ETHTOOL_A_CABLE_TDR_NEST_MAX = (__ETHTOOL_A_CABLE_TDR_NEST_CNT - 1)
};
enum {
ETHTOOL_A_CABLE_TEST_TDR_NTF_UNSPEC,
ETHTOOL_A_CABLE_TEST_TDR_NTF_HEADER, /* nest - ETHTOOL_A_HEADER_* */
ETHTOOL_A_CABLE_TEST_TDR_NTF_STATUS, /* u8 - _STARTED/_COMPLETE */
ETHTOOL_A_CABLE_TEST_TDR_NTF_NEST, /* nest - of results: */
/* add new constants above here */
__ETHTOOL_A_CABLE_TEST_TDR_NTF_CNT,
ETHTOOL_A_CABLE_TEST_TDR_NTF_MAX = __ETHTOOL_A_CABLE_TEST_TDR_NTF_CNT - 1
};
/* generic netlink info */ /* generic netlink info */
#define ETHTOOL_GENL_NAME "ethtool" #define ETHTOOL_GENL_NAME "ethtool"
#define ETHTOOL_GENL_VERSION 1 #define ETHTOOL_GENL_VERSION 1
......
...@@ -5,7 +5,11 @@ ...@@ -5,7 +5,11 @@
#include "netlink.h" #include "netlink.h"
#include "common.h" #include "common.h"
/* CABLE_TEST_ACT */ /* 802.3 standard allows 100 meters for BaseT cables. However longer
* cables might work, depending on the quality of the cables and the
* PHY. So allow testing for up to 150 meters.
*/
#define MAX_CABLE_LENGTH_CM (150 * 100)
static const struct nla_policy static const struct nla_policy
cable_test_act_policy[ETHTOOL_A_CABLE_TEST_MAX + 1] = { cable_test_act_policy[ETHTOOL_A_CABLE_TEST_MAX + 1] = {
...@@ -13,7 +17,7 @@ cable_test_act_policy[ETHTOOL_A_CABLE_TEST_MAX + 1] = { ...@@ -13,7 +17,7 @@ cable_test_act_policy[ETHTOOL_A_CABLE_TEST_MAX + 1] = {
[ETHTOOL_A_CABLE_TEST_HEADER] = { .type = NLA_NESTED }, [ETHTOOL_A_CABLE_TEST_HEADER] = { .type = NLA_NESTED },
}; };
static int ethnl_cable_test_started(struct phy_device *phydev) static int ethnl_cable_test_started(struct phy_device *phydev, u8 cmd)
{ {
struct sk_buff *skb; struct sk_buff *skb;
int err = -ENOMEM; int err = -ENOMEM;
...@@ -23,7 +27,7 @@ static int ethnl_cable_test_started(struct phy_device *phydev) ...@@ -23,7 +27,7 @@ static int ethnl_cable_test_started(struct phy_device *phydev)
if (!skb) if (!skb)
goto out; goto out;
ehdr = ethnl_bcastmsg_put(skb, ETHTOOL_MSG_CABLE_TEST_NTF); ehdr = ethnl_bcastmsg_put(skb, cmd);
if (!ehdr) { if (!ehdr) {
err = -EMSGSIZE; err = -EMSGSIZE;
goto out; goto out;
...@@ -86,7 +90,8 @@ int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info) ...@@ -86,7 +90,8 @@ int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info)
ethnl_ops_complete(dev); ethnl_ops_complete(dev);
if (!ret) if (!ret)
ethnl_cable_test_started(dev->phydev); ethnl_cable_test_started(dev->phydev,
ETHTOOL_MSG_CABLE_TEST_NTF);
out_rtnl: out_rtnl:
rtnl_unlock(); rtnl_unlock();
...@@ -95,16 +100,18 @@ int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info) ...@@ -95,16 +100,18 @@ int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info)
return ret; return ret;
} }
int ethnl_cable_test_alloc(struct phy_device *phydev) int ethnl_cable_test_alloc(struct phy_device *phydev, u8 cmd)
{ {
int err = -ENOMEM; int err = -ENOMEM;
phydev->skb = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); /* One TDR sample occupies 20 bytes. For a 150 meter cable,
* with four pairs, around 12K is needed.
*/
phydev->skb = genlmsg_new(SZ_16K, GFP_KERNEL);
if (!phydev->skb) if (!phydev->skb)
goto out; goto out;
phydev->ehdr = ethnl_bcastmsg_put(phydev->skb, phydev->ehdr = ethnl_bcastmsg_put(phydev->skb, cmd);
ETHTOOL_MSG_CABLE_TEST_NTF);
if (!phydev->ehdr) { if (!phydev->ehdr) {
err = -EMSGSIZE; err = -EMSGSIZE;
goto out; goto out;
...@@ -199,3 +206,226 @@ int ethnl_cable_test_fault_length(struct phy_device *phydev, u8 pair, u32 cm) ...@@ -199,3 +206,226 @@ int ethnl_cable_test_fault_length(struct phy_device *phydev, u8 pair, u32 cm)
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(ethnl_cable_test_fault_length); EXPORT_SYMBOL_GPL(ethnl_cable_test_fault_length);
struct cable_test_tdr_req_info {
struct ethnl_req_info base;
};
static const struct nla_policy
cable_test_tdr_act_cfg_policy[ETHTOOL_A_CABLE_TEST_TDR_CFG_MAX + 1] = {
[ETHTOOL_A_CABLE_TEST_TDR_CFG_FIRST] = { .type = NLA_U32 },
[ETHTOOL_A_CABLE_TEST_TDR_CFG_LAST] = { .type = NLA_U32 },
[ETHTOOL_A_CABLE_TEST_TDR_CFG_STEP] = { .type = NLA_U32 },
[ETHTOOL_A_CABLE_TEST_TDR_CFG_PAIR] = { .type = NLA_U8 },
};
static const struct nla_policy
cable_test_tdr_act_policy[ETHTOOL_A_CABLE_TEST_TDR_MAX + 1] = {
[ETHTOOL_A_CABLE_TEST_TDR_UNSPEC] = { .type = NLA_REJECT },
[ETHTOOL_A_CABLE_TEST_TDR_HEADER] = { .type = NLA_NESTED },
[ETHTOOL_A_CABLE_TEST_TDR_CFG] = { .type = NLA_NESTED },
};
/* CABLE_TEST_TDR_ACT */
int ethnl_act_cable_test_tdr_cfg(const struct nlattr *nest,
struct genl_info *info,
struct phy_tdr_config *cfg)
{
struct nlattr *tb[ETHTOOL_A_CABLE_TEST_TDR_CFG_MAX + 1];
int ret;
ret = nla_parse_nested(tb, ETHTOOL_A_CABLE_TEST_TDR_CFG_MAX, nest,
cable_test_tdr_act_cfg_policy, info->extack);
if (ret < 0)
return ret;
if (tb[ETHTOOL_A_CABLE_TEST_TDR_CFG_FIRST])
cfg->first = nla_get_u32(
tb[ETHTOOL_A_CABLE_TEST_TDR_CFG_FIRST]);
else
cfg->first = 100;
if (tb[ETHTOOL_A_CABLE_TEST_TDR_CFG_LAST])
cfg->last = nla_get_u32(tb[ETHTOOL_A_CABLE_TEST_TDR_CFG_LAST]);
else
cfg->last = MAX_CABLE_LENGTH_CM;
if (tb[ETHTOOL_A_CABLE_TEST_TDR_CFG_STEP])
cfg->step = nla_get_u32(tb[ETHTOOL_A_CABLE_TEST_TDR_CFG_STEP]);
else
cfg->step = 100;
if (tb[ETHTOOL_A_CABLE_TEST_TDR_CFG_PAIR]) {
cfg->pair = nla_get_u8(tb[ETHTOOL_A_CABLE_TEST_TDR_CFG_PAIR]);
if (cfg->pair > ETHTOOL_A_CABLE_PAIR_D) {
NL_SET_ERR_MSG_ATTR(
info->extack,
tb[ETHTOOL_A_CABLE_TEST_TDR_CFG_PAIR],
"invalid pair parameter");
return -EINVAL;
}
} else {
cfg->pair = PHY_PAIR_ALL;
}
if (cfg->first > MAX_CABLE_LENGTH_CM) {
NL_SET_ERR_MSG_ATTR(info->extack,
tb[ETHTOOL_A_CABLE_TEST_TDR_CFG_FIRST],
"invalid first parameter");
return -EINVAL;
}
if (cfg->last > MAX_CABLE_LENGTH_CM) {
NL_SET_ERR_MSG_ATTR(info->extack,
tb[ETHTOOL_A_CABLE_TEST_TDR_CFG_LAST],
"invalid last parameter");
return -EINVAL;
}
if (cfg->first > cfg->last) {
NL_SET_ERR_MSG(info->extack, "invalid first/last parameter");
return -EINVAL;
}
if (!cfg->step) {
NL_SET_ERR_MSG_ATTR(info->extack,
tb[ETHTOOL_A_CABLE_TEST_TDR_CFG_STEP],
"invalid step parameter");
return -EINVAL;
}
if (cfg->step > (cfg->last - cfg->first)) {
NL_SET_ERR_MSG_ATTR(info->extack,
tb[ETHTOOL_A_CABLE_TEST_TDR_CFG_STEP],
"step parameter too big");
return -EINVAL;
}
return 0;
}
int ethnl_act_cable_test_tdr(struct sk_buff *skb, struct genl_info *info)
{
struct nlattr *tb[ETHTOOL_A_CABLE_TEST_TDR_MAX + 1];
struct ethnl_req_info req_info = {};
struct phy_tdr_config cfg;
struct net_device *dev;
int ret;
ret = nlmsg_parse(info->nlhdr, GENL_HDRLEN, tb,
ETHTOOL_A_CABLE_TEST_TDR_MAX,
cable_test_tdr_act_policy, info->extack);
if (ret < 0)
return ret;
ret = ethnl_parse_header_dev_get(&req_info,
tb[ETHTOOL_A_CABLE_TEST_TDR_HEADER],
genl_info_net(info), info->extack,
true);
if (ret < 0)
return ret;
dev = req_info.dev;
if (!dev->phydev) {
ret = -EOPNOTSUPP;
goto out_dev_put;
}
ret = ethnl_act_cable_test_tdr_cfg(tb[ETHTOOL_A_CABLE_TEST_TDR_CFG],
info, &cfg);
if (ret)
goto out_dev_put;
rtnl_lock();
ret = ethnl_ops_begin(dev);
if (ret < 0)
goto out_rtnl;
ret = phy_start_cable_test_tdr(dev->phydev, info->extack, &cfg);
ethnl_ops_complete(dev);
if (!ret)
ethnl_cable_test_started(dev->phydev,
ETHTOOL_MSG_CABLE_TEST_TDR_NTF);
out_rtnl:
rtnl_unlock();
out_dev_put:
dev_put(dev);
return ret;
}
int ethnl_cable_test_amplitude(struct phy_device *phydev,
u8 pair, s16 mV)
{
struct nlattr *nest;
int ret = -EMSGSIZE;
nest = nla_nest_start(phydev->skb,
ETHTOOL_A_CABLE_TDR_NEST_AMPLITUDE);
if (!nest)
return -EMSGSIZE;
if (nla_put_u8(phydev->skb, ETHTOOL_A_CABLE_AMPLITUDE_PAIR, pair))
goto err;
if (nla_put_u16(phydev->skb, ETHTOOL_A_CABLE_AMPLITUDE_mV, mV))
goto err;
nla_nest_end(phydev->skb, nest);
return 0;
err:
nla_nest_cancel(phydev->skb, nest);
return ret;
}
EXPORT_SYMBOL_GPL(ethnl_cable_test_amplitude);
int ethnl_cable_test_pulse(struct phy_device *phydev, u16 mV)
{
struct nlattr *nest;
int ret = -EMSGSIZE;
nest = nla_nest_start(phydev->skb, ETHTOOL_A_CABLE_TDR_NEST_PULSE);
if (!nest)
return -EMSGSIZE;
if (nla_put_u16(phydev->skb, ETHTOOL_A_CABLE_PULSE_mV, mV))
goto err;
nla_nest_end(phydev->skb, nest);
return 0;
err:
nla_nest_cancel(phydev->skb, nest);
return ret;
}
EXPORT_SYMBOL_GPL(ethnl_cable_test_pulse);
int ethnl_cable_test_step(struct phy_device *phydev, u32 first, u32 last,
u32 step)
{
struct nlattr *nest;
int ret = -EMSGSIZE;
nest = nla_nest_start(phydev->skb, ETHTOOL_A_CABLE_TDR_NEST_STEP);
if (!nest)
return -EMSGSIZE;
if (nla_put_u32(phydev->skb, ETHTOOL_A_CABLE_STEP_FIRST_DISTANCE,
first))
goto err;
if (nla_put_u32(phydev->skb, ETHTOOL_A_CABLE_STEP_LAST_DISTANCE, last))
goto err;
if (nla_put_u32(phydev->skb, ETHTOOL_A_CABLE_STEP_STEP_DISTANCE, step))
goto err;
nla_nest_end(phydev->skb, nest);
return 0;
err:
nla_nest_cancel(phydev->skb, nest);
return ret;
}
EXPORT_SYMBOL_GPL(ethnl_cable_test_step);
...@@ -844,6 +844,11 @@ static const struct genl_ops ethtool_genl_ops[] = { ...@@ -844,6 +844,11 @@ static const struct genl_ops ethtool_genl_ops[] = {
.flags = GENL_UNS_ADMIN_PERM, .flags = GENL_UNS_ADMIN_PERM,
.doit = ethnl_act_cable_test, .doit = ethnl_act_cable_test,
}, },
{
.cmd = ETHTOOL_MSG_CABLE_TEST_TDR_ACT,
.flags = GENL_UNS_ADMIN_PERM,
.doit = ethnl_act_cable_test_tdr,
},
}; };
static const struct genl_multicast_group ethtool_nl_mcgrps[] = { static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
......
...@@ -360,5 +360,6 @@ int ethnl_set_coalesce(struct sk_buff *skb, struct genl_info *info); ...@@ -360,5 +360,6 @@ int ethnl_set_coalesce(struct sk_buff *skb, struct genl_info *info);
int ethnl_set_pause(struct sk_buff *skb, struct genl_info *info); int ethnl_set_pause(struct sk_buff *skb, struct genl_info *info);
int ethnl_set_eee(struct sk_buff *skb, struct genl_info *info); int ethnl_set_eee(struct sk_buff *skb, struct genl_info *info);
int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info); int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info);
int ethnl_act_cable_test_tdr(struct sk_buff *skb, struct genl_info *info);
#endif /* _NET_ETHTOOL_NETLINK_H */ #endif /* _NET_ETHTOOL_NETLINK_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment