Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

phy: Add Open Alliance helpers for the PHY framework

Introduce helper functions specific to Open Alliance diagnostics,
integrating them into the PHY framework. Currently, these helpers
are limited to 1000BaseT1 specific TDR functionality.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Link: https://patch.msgid.link/20240812073046.1728288-2-o.rempel@pengutronix.de
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Oleksij Rempel and committed by
Jakub Kicinski
9e7c1a9b 2140e63c

+128
+3
drivers/net/phy/Kconfig
··· 44 44 <Speed in megabits>Mbps OR <Speed in gigabits>Gbps OR link 45 45 for any speed known to the PHY. 46 46 47 + config OPEN_ALLIANCE_HELPERS 48 + bool 49 + 47 50 config PHYLIB_LEDS 48 51 def_bool OF 49 52 depends on LEDS_CLASS=y || LEDS_CLASS=PHYLIB
+1
drivers/net/phy/Makefile
··· 22 22 obj-$(CONFIG_MDIO_DEVRES) += mdio_devres.o 23 23 libphy-$(CONFIG_SWPHY) += swphy.o 24 24 libphy-$(CONFIG_LED_TRIGGER_PHY) += phy_led_triggers.o 25 + libphy-$(CONFIG_OPEN_ALLIANCE_HELPERS) += open_alliance_helpers.o 25 26 26 27 obj-$(CONFIG_PHYLINK) += phylink.o 27 28 obj-$(CONFIG_PHYLIB) += libphy.o
+77
drivers/net/phy/open_alliance_helpers.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * open_alliance_helpers.c - OPEN Alliance specific PHY diagnostic helpers 4 + * 5 + * This file contains helper functions for implementing advanced diagnostic 6 + * features as specified by the OPEN Alliance for automotive Ethernet PHYs. 7 + * These helpers include functionality for Time Delay Reflection (TDR), dynamic 8 + * channel quality assessment, and other PHY diagnostics. 9 + * 10 + * For more information on the specifications, refer to the OPEN Alliance 11 + * documentation: https://opensig.org/automotive-ethernet-specifications/ 12 + * Currently following specifications are partially or fully implemented: 13 + * - Advanced diagnostic features for 1000BASE-T1 automotive Ethernet PHYs. 14 + * TC12 - advanced PHY features. 15 + * https://opensig.org/wp-content/uploads/2024/03/Advanced_PHY_features_for_automotive_Ethernet_v2.0_fin.pdf 16 + */ 17 + 18 + #include <linux/bitfield.h> 19 + #include <linux/ethtool_netlink.h> 20 + 21 + #include "open_alliance_helpers.h" 22 + 23 + /** 24 + * oa_1000bt1_get_ethtool_cable_result_code - Convert TDR status to ethtool 25 + * result code 26 + * @reg_value: Value read from the TDR register 27 + * 28 + * This function takes a register value from the HDD.TDR register and converts 29 + * the TDR status to the corresponding ethtool cable test result code. 30 + * 31 + * Return: The appropriate ethtool result code based on the TDR status 32 + */ 33 + int oa_1000bt1_get_ethtool_cable_result_code(u16 reg_value) 34 + { 35 + u8 tdr_status = FIELD_GET(OA_1000BT1_HDD_TDR_STATUS_MASK, reg_value); 36 + u8 dist_val = FIELD_GET(OA_1000BT1_HDD_TDR_DISTANCE_MASK, reg_value); 37 + 38 + switch (tdr_status) { 39 + case OA_1000BT1_HDD_TDR_STATUS_CABLE_OK: 40 + return ETHTOOL_A_CABLE_RESULT_CODE_OK; 41 + case OA_1000BT1_HDD_TDR_STATUS_OPEN: 42 + return ETHTOOL_A_CABLE_RESULT_CODE_OPEN; 43 + case OA_1000BT1_HDD_TDR_STATUS_SHORT: 44 + return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT; 45 + case OA_1000BT1_HDD_TDR_STATUS_NOISE: 46 + return ETHTOOL_A_CABLE_RESULT_CODE_NOISE; 47 + default: 48 + if (dist_val == OA_1000BT1_HDD_TDR_DISTANCE_RESOLUTION_NOT_POSSIBLE) 49 + return ETHTOOL_A_CABLE_RESULT_CODE_RESOLUTION_NOT_POSSIBLE; 50 + return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC; 51 + } 52 + } 53 + EXPORT_SYMBOL_GPL(oa_1000bt1_get_ethtool_cable_result_code); 54 + 55 + /** 56 + * oa_1000bt1_get_tdr_distance - Get distance to the main fault from TDR 57 + * register value 58 + * @reg_value: Value read from the TDR register 59 + * 60 + * This function takes a register value from the HDD.TDR register and extracts 61 + * the distance to the main fault detected by the TDR feature. The distance is 62 + * measured in centimeters and ranges from 0 to 3100 centimeters. If the 63 + * distance is not available (0x3f), the function returns -ERANGE. 64 + * 65 + * Return: The distance to the main fault in centimeters, or -ERANGE if the 66 + * resolution is not possible. 67 + */ 68 + int oa_1000bt1_get_tdr_distance(u16 reg_value) 69 + { 70 + u8 dist_val = FIELD_GET(OA_1000BT1_HDD_TDR_DISTANCE_MASK, reg_value); 71 + 72 + if (dist_val == OA_1000BT1_HDD_TDR_DISTANCE_RESOLUTION_NOT_POSSIBLE) 73 + return -ERANGE; 74 + 75 + return dist_val * 100; 76 + } 77 + EXPORT_SYMBOL_GPL(oa_1000bt1_get_tdr_distance);
+47
drivers/net/phy/open_alliance_helpers.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + #ifndef OPEN_ALLIANCE_HELPERS_H 4 + #define OPEN_ALLIANCE_HELPERS_H 5 + 6 + /* 7 + * These defines reflect the TDR (Time Delay Reflection) diagnostic feature 8 + * for 1000BASE-T1 automotive Ethernet PHYs as specified by the OPEN Alliance. 9 + * 10 + * The register values are part of the HDD.TDR register, which provides 11 + * information about the cable status and faults. The exact register offset 12 + * is device-specific and should be provided by the driver. 13 + */ 14 + #define OA_1000BT1_HDD_TDR_ACTIVATION_MASK GENMASK(1, 0) 15 + #define OA_1000BT1_HDD_TDR_ACTIVATION_OFF 1 16 + #define OA_1000BT1_HDD_TDR_ACTIVATION_ON 2 17 + 18 + #define OA_1000BT1_HDD_TDR_STATUS_MASK GENMASK(7, 4) 19 + #define OA_1000BT1_HDD_TDR_STATUS_SHORT 3 20 + #define OA_1000BT1_HDD_TDR_STATUS_OPEN 6 21 + #define OA_1000BT1_HDD_TDR_STATUS_NOISE 5 22 + #define OA_1000BT1_HDD_TDR_STATUS_CABLE_OK 7 23 + #define OA_1000BT1_HDD_TDR_STATUS_TEST_IN_PROGRESS 8 24 + #define OA_1000BT1_HDD_TDR_STATUS_TEST_NOT_POSSIBLE 13 25 + 26 + /* 27 + * OA_1000BT1_HDD_TDR_DISTANCE_MASK: 28 + * This mask is used to extract the distance to the first/main fault 29 + * detected by the TDR feature. Each bit represents an approximate distance 30 + * of 1 meter, ranging from 0 to 31 meters. The exact interpretation of the 31 + * bits may vary, but generally: 32 + * 000000 = no error 33 + * 000001 = error about 0-1m away 34 + * 000010 = error between 1-2m away 35 + * ... 36 + * 011111 = error about 30-31m away 37 + * 111111 = resolution not possible / out of distance 38 + */ 39 + #define OA_1000BT1_HDD_TDR_DISTANCE_MASK GENMASK(13, 8) 40 + #define OA_1000BT1_HDD_TDR_DISTANCE_NO_ERROR 0 41 + #define OA_1000BT1_HDD_TDR_DISTANCE_RESOLUTION_NOT_POSSIBLE 0x3f 42 + 43 + int oa_1000bt1_get_ethtool_cable_result_code(u16 reg_value); 44 + int oa_1000bt1_get_tdr_distance(u16 reg_value); 45 + 46 + #endif /* OPEN_ALLIANCE_HELPERS_H */ 47 +