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

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'add-hwtstamp_get-callback-to-phy-drivers'

Vadim Fedorenko says:

====================
add hwtstamp_get callback to phy drivers

PHY drivers are able to configure HW time stamping and are not able to
report configuration back to user space. Add callback to report
configuration like it's done for net_device and add implementation to
the drivers.
====================

Link: https://patch.msgid.link/20251124181151.277256-1-vadim.fedorenko@linux.dev
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+139 -51
+1 -1
drivers/net/ethernet/ti/netcp_ethss.c
··· 2657 2657 2658 2658 phy = gbe_intf->slave->phy; 2659 2659 if (phy_has_hwtstamp(phy)) 2660 - return phy->mii_ts->hwtstamp(phy->mii_ts, cfg, extack); 2660 + return phy->mii_ts->hwtstamp_set(phy->mii_ts, cfg, extack); 2661 2661 2662 2662 switch (cfg->tx_type) { 2663 2663 case HWTSTAMP_TX_OFF:
+17 -4
drivers/net/phy/bcm-phy-ptp.c
··· 780 780 kfree_skb(skb); 781 781 } 782 782 783 - static int bcm_ptp_hwtstamp(struct mii_timestamper *mii_ts, 784 - struct kernel_hwtstamp_config *cfg, 785 - struct netlink_ext_ack *extack) 783 + static int bcm_ptp_hwtstamp_get(struct mii_timestamper *mii_ts, 784 + struct kernel_hwtstamp_config *cfg) 785 + { 786 + struct bcm_ptp_private *priv = mii2priv(mii_ts); 787 + 788 + cfg->rx_filter = priv->hwts_rx ? HWTSTAMP_FILTER_PTP_V2_EVENT 789 + : HWTSTAMP_FILTER_NONE; 790 + cfg->tx_type = priv->tx_type; 791 + 792 + return 0; 793 + } 794 + 795 + static int bcm_ptp_hwtstamp_set(struct mii_timestamper *mii_ts, 796 + struct kernel_hwtstamp_config *cfg, 797 + struct netlink_ext_ack *extack) 786 798 { 787 799 struct bcm_ptp_private *priv = mii2priv(mii_ts); 788 800 u16 mode, ctrl; ··· 910 898 911 899 priv->mii_ts.rxtstamp = bcm_ptp_rxtstamp; 912 900 priv->mii_ts.txtstamp = bcm_ptp_txtstamp; 913 - priv->mii_ts.hwtstamp = bcm_ptp_hwtstamp; 901 + priv->mii_ts.hwtstamp_set = bcm_ptp_hwtstamp_set; 902 + priv->mii_ts.hwtstamp_get = bcm_ptp_hwtstamp_get; 914 903 priv->mii_ts.ts_info = bcm_ptp_ts_info; 915 904 916 905 priv->phydev->mii_ts = &priv->mii_ts;
+21 -8
drivers/net/phy/dp83640.c
··· 1176 1176 return IRQ_HANDLED; 1177 1177 } 1178 1178 1179 - static int dp83640_hwtstamp(struct mii_timestamper *mii_ts, 1180 - struct kernel_hwtstamp_config *cfg, 1181 - struct netlink_ext_ack *extack) 1179 + static int dp83640_hwtstamp_get(struct mii_timestamper *mii_ts, 1180 + struct kernel_hwtstamp_config *cfg) 1181 + { 1182 + struct dp83640_private *dp83640 = 1183 + container_of(mii_ts, struct dp83640_private, mii_ts); 1184 + 1185 + cfg->rx_filter = dp83640->hwts_rx_en; 1186 + cfg->tx_type = dp83640->hwts_tx_en; 1187 + 1188 + return 0; 1189 + } 1190 + 1191 + static int dp83640_hwtstamp_set(struct mii_timestamper *mii_ts, 1192 + struct kernel_hwtstamp_config *cfg, 1193 + struct netlink_ext_ack *extack) 1182 1194 { 1183 1195 struct dp83640_private *dp83640 = 1184 1196 container_of(mii_ts, struct dp83640_private, mii_ts); ··· 1210 1198 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: 1211 1199 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: 1212 1200 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: 1213 - dp83640->hwts_rx_en = 1; 1201 + dp83640->hwts_rx_en = HWTSTAMP_FILTER_PTP_V1_L4_EVENT; 1214 1202 dp83640->layer = PTP_CLASS_L4; 1215 1203 dp83640->version = PTP_CLASS_V1; 1216 1204 cfg->rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT; ··· 1218 1206 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: 1219 1207 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: 1220 1208 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: 1221 - dp83640->hwts_rx_en = 1; 1209 + dp83640->hwts_rx_en = HWTSTAMP_FILTER_PTP_V2_L4_EVENT; 1222 1210 dp83640->layer = PTP_CLASS_L4; 1223 1211 dp83640->version = PTP_CLASS_V2; 1224 1212 cfg->rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT; ··· 1226 1214 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: 1227 1215 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: 1228 1216 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: 1229 - dp83640->hwts_rx_en = 1; 1217 + dp83640->hwts_rx_en = HWTSTAMP_FILTER_PTP_V2_L2_EVENT; 1230 1218 dp83640->layer = PTP_CLASS_L2; 1231 1219 dp83640->version = PTP_CLASS_V2; 1232 1220 cfg->rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT; ··· 1234 1222 case HWTSTAMP_FILTER_PTP_V2_EVENT: 1235 1223 case HWTSTAMP_FILTER_PTP_V2_SYNC: 1236 1224 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: 1237 - dp83640->hwts_rx_en = 1; 1225 + dp83640->hwts_rx_en = HWTSTAMP_FILTER_PTP_V2_EVENT; 1238 1226 dp83640->layer = PTP_CLASS_L4 | PTP_CLASS_L2; 1239 1227 dp83640->version = PTP_CLASS_V2; 1240 1228 cfg->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; ··· 1419 1407 dp83640->phydev = phydev; 1420 1408 dp83640->mii_ts.rxtstamp = dp83640_rxtstamp; 1421 1409 dp83640->mii_ts.txtstamp = dp83640_txtstamp; 1422 - dp83640->mii_ts.hwtstamp = dp83640_hwtstamp; 1410 + dp83640->mii_ts.hwtstamp_set = dp83640_hwtstamp_set; 1411 + dp83640->mii_ts.hwtstamp_get = dp83640_hwtstamp_get; 1423 1412 dp83640->mii_ts.ts_info = dp83640_ts_info; 1424 1413 1425 1414 INIT_DELAYED_WORK(&dp83640->ts_work, rx_timestamp_work);
+8 -8
drivers/net/phy/micrel.c
··· 3147 3147 lanphy_read_page_reg(phydev, LAN8814_PAGE_PORT_REGS, PTP_TSU_INT_STS); 3148 3148 } 3149 3149 3150 - static int lan8814_hwtstamp(struct mii_timestamper *mii_ts, 3151 - struct kernel_hwtstamp_config *config, 3152 - struct netlink_ext_ack *extack) 3150 + static int lan8814_hwtstamp_set(struct mii_timestamper *mii_ts, 3151 + struct kernel_hwtstamp_config *config, 3152 + struct netlink_ext_ack *extack) 3153 3153 { 3154 3154 struct kszphy_ptp_priv *ptp_priv = 3155 3155 container_of(mii_ts, struct kszphy_ptp_priv, mii_ts); ··· 4389 4389 4390 4390 ptp_priv->mii_ts.rxtstamp = lan8814_rxtstamp; 4391 4391 ptp_priv->mii_ts.txtstamp = lan8814_txtstamp; 4392 - ptp_priv->mii_ts.hwtstamp = lan8814_hwtstamp; 4392 + ptp_priv->mii_ts.hwtstamp_set = lan8814_hwtstamp_set; 4393 4393 ptp_priv->mii_ts.ts_info = lan8814_ts_info; 4394 4394 4395 4395 phydev->mii_ts = &ptp_priv->mii_ts; ··· 5042 5042 #define LAN8841_PTP_TX_TIMESTAMP_EN 443 5043 5043 #define LAN8841_PTP_TX_MOD 445 5044 5044 5045 - static int lan8841_hwtstamp(struct mii_timestamper *mii_ts, 5046 - struct kernel_hwtstamp_config *config, 5047 - struct netlink_ext_ack *extack) 5045 + static int lan8841_hwtstamp_set(struct mii_timestamper *mii_ts, 5046 + struct kernel_hwtstamp_config *config, 5047 + struct netlink_ext_ack *extack) 5048 5048 { 5049 5049 struct kszphy_ptp_priv *ptp_priv = container_of(mii_ts, struct kszphy_ptp_priv, mii_ts); 5050 5050 struct phy_device *phydev = ptp_priv->phydev; ··· 5924 5924 5925 5925 ptp_priv->mii_ts.rxtstamp = lan8841_rxtstamp; 5926 5926 ptp_priv->mii_ts.txtstamp = lan8814_txtstamp; 5927 - ptp_priv->mii_ts.hwtstamp = lan8841_hwtstamp; 5927 + ptp_priv->mii_ts.hwtstamp_set = lan8841_hwtstamp_set; 5928 5928 ptp_priv->mii_ts.ts_info = lan8841_ts_info; 5929 5929 5930 5930 phydev->mii_ts = &ptp_priv->mii_ts;
+4 -4
drivers/net/phy/microchip_rds_ptp.c
··· 476 476 return true; 477 477 } 478 478 479 - static int mchp_rds_ptp_hwtstamp(struct mii_timestamper *mii_ts, 480 - struct kernel_hwtstamp_config *config, 481 - struct netlink_ext_ack *extack) 479 + static int mchp_rds_ptp_hwtstamp_set(struct mii_timestamper *mii_ts, 480 + struct kernel_hwtstamp_config *config, 481 + struct netlink_ext_ack *extack) 482 482 { 483 483 struct mchp_rds_ptp_clock *clock = 484 484 container_of(mii_ts, struct mchp_rds_ptp_clock, ··· 1281 1281 1282 1282 clock->mii_ts.rxtstamp = mchp_rds_ptp_rxtstamp; 1283 1283 clock->mii_ts.txtstamp = mchp_rds_ptp_txtstamp; 1284 - clock->mii_ts.hwtstamp = mchp_rds_ptp_hwtstamp; 1284 + clock->mii_ts.hwtstamp_set = mchp_rds_ptp_hwtstamp_set; 1285 1285 clock->mii_ts.ts_info = mchp_rds_ptp_ts_info; 1286 1286 1287 1287 phydev->mii_ts = &clock->mii_ts;
+17 -4
drivers/net/phy/mscc/mscc_ptp.c
··· 1051 1051 val); 1052 1052 } 1053 1053 1054 - static int vsc85xx_hwtstamp(struct mii_timestamper *mii_ts, 1055 - struct kernel_hwtstamp_config *cfg, 1056 - struct netlink_ext_ack *extack) 1054 + static int vsc85xx_hwtstamp_get(struct mii_timestamper *mii_ts, 1055 + struct kernel_hwtstamp_config *cfg) 1056 + { 1057 + struct vsc8531_private *vsc8531 = 1058 + container_of(mii_ts, struct vsc8531_private, mii_ts); 1059 + 1060 + cfg->tx_type = vsc8531->ptp->tx_type; 1061 + cfg->rx_filter = vsc8531->ptp->rx_filter; 1062 + 1063 + return 0; 1064 + } 1065 + 1066 + static int vsc85xx_hwtstamp_set(struct mii_timestamper *mii_ts, 1067 + struct kernel_hwtstamp_config *cfg, 1068 + struct netlink_ext_ack *extack) 1057 1069 { 1058 1070 struct vsc8531_private *vsc8531 = 1059 1071 container_of(mii_ts, struct vsc8531_private, mii_ts); ··· 1623 1611 1624 1612 vsc8531->mii_ts.rxtstamp = vsc85xx_rxtstamp; 1625 1613 vsc8531->mii_ts.txtstamp = vsc85xx_txtstamp; 1626 - vsc8531->mii_ts.hwtstamp = vsc85xx_hwtstamp; 1614 + vsc8531->mii_ts.hwtstamp_set = vsc85xx_hwtstamp_set; 1615 + vsc8531->mii_ts.hwtstamp_get = vsc85xx_hwtstamp_get; 1627 1616 vsc8531->mii_ts.ts_info = vsc85xx_ts_info; 1628 1617 phydev->mii_ts = &vsc8531->mii_ts; 1629 1618
+18 -4
drivers/net/phy/nxp-c45-tja11xx.c
··· 1012 1012 return true; 1013 1013 } 1014 1014 1015 - static int nxp_c45_hwtstamp(struct mii_timestamper *mii_ts, 1016 - struct kernel_hwtstamp_config *cfg, 1017 - struct netlink_ext_ack *extack) 1015 + static int nxp_c45_hwtstamp_get(struct mii_timestamper *mii_ts, 1016 + struct kernel_hwtstamp_config *cfg) 1017 + { 1018 + struct nxp_c45_phy *priv = container_of(mii_ts, struct nxp_c45_phy, 1019 + mii_ts); 1020 + 1021 + cfg->tx_type = priv->hwts_tx; 1022 + cfg->rx_filter = priv->hwts_rx ? HWTSTAMP_FILTER_PTP_V2_L2_EVENT 1023 + : HWTSTAMP_FILTER_NONE; 1024 + 1025 + return 0; 1026 + } 1027 + 1028 + static int nxp_c45_hwtstamp_set(struct mii_timestamper *mii_ts, 1029 + struct kernel_hwtstamp_config *cfg, 1030 + struct netlink_ext_ack *extack) 1018 1031 { 1019 1032 struct nxp_c45_phy *priv = container_of(mii_ts, struct nxp_c45_phy, 1020 1033 mii_ts); ··· 1762 1749 IS_ENABLED(CONFIG_NETWORK_PHY_TIMESTAMPING)) { 1763 1750 priv->mii_ts.rxtstamp = nxp_c45_rxtstamp; 1764 1751 priv->mii_ts.txtstamp = nxp_c45_txtstamp; 1765 - priv->mii_ts.hwtstamp = nxp_c45_hwtstamp; 1752 + priv->mii_ts.hwtstamp_set = nxp_c45_hwtstamp_set; 1753 + priv->mii_ts.hwtstamp_get = nxp_c45_hwtstamp_get; 1766 1754 priv->mii_ts.ts_info = nxp_c45_ts_info; 1767 1755 phydev->mii_ts = &priv->mii_ts; 1768 1756 ret = nxp_c45_init_ptp_clock(priv);
+10 -4
drivers/net/phy/phy.c
··· 405 405 return 0; 406 406 407 407 case SIOCSHWTSTAMP: 408 - if (phydev->mii_ts && phydev->mii_ts->hwtstamp) { 408 + if (phydev->mii_ts && phydev->mii_ts->hwtstamp_set) { 409 409 if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) 410 410 return -EFAULT; 411 411 412 412 hwtstamp_config_to_kernel(&kernel_cfg, &cfg); 413 - ret = phydev->mii_ts->hwtstamp(phydev->mii_ts, &kernel_cfg, &extack); 413 + ret = phydev->mii_ts->hwtstamp_set(phydev->mii_ts, 414 + &kernel_cfg, 415 + &extack); 414 416 if (ret) 415 417 return ret; 416 418 ··· 478 476 if (!phydev) 479 477 return -ENODEV; 480 478 479 + if (phydev->mii_ts && phydev->mii_ts->hwtstamp_get) 480 + return phydev->mii_ts->hwtstamp_get(phydev->mii_ts, config); 481 + 481 482 return -EOPNOTSUPP; 482 483 } 483 484 ··· 498 493 if (!phydev) 499 494 return -ENODEV; 500 495 501 - if (phydev->mii_ts && phydev->mii_ts->hwtstamp) 502 - return phydev->mii_ts->hwtstamp(phydev->mii_ts, config, extack); 496 + if (phydev->mii_ts && phydev->mii_ts->hwtstamp_set) 497 + return phydev->mii_ts->hwtstamp_set(phydev->mii_ts, config, 498 + extack); 503 499 504 500 return -EOPNOTSUPP; 505 501 }
+27 -4
drivers/ptp/ptp_ines.c
··· 328 328 return ns; 329 329 } 330 330 331 - static int ines_hwtstamp(struct mii_timestamper *mii_ts, 332 - struct kernel_hwtstamp_config *cfg, 333 - struct netlink_ext_ack *extack) 331 + static int ines_hwtstamp_get(struct mii_timestamper *mii_ts, 332 + struct kernel_hwtstamp_config *cfg) 333 + { 334 + struct ines_port *port = container_of(mii_ts, struct ines_port, mii_ts); 335 + unsigned long flags; 336 + u32 port_conf; 337 + 338 + cfg->rx_filter = port->rxts_enabled ? HWTSTAMP_FILTER_PTP_V2_EVENT 339 + : HWTSTAMP_FILTER_NONE; 340 + if (port->txts_enabled) { 341 + spin_lock_irqsave(&port->lock, flags); 342 + port_conf = ines_read32(port, port_conf); 343 + spin_unlock_irqrestore(&port->lock, flags); 344 + cfg->tx_type = (port_conf & CM_ONE_STEP) ? HWTSTAMP_TX_ONESTEP_P2P 345 + : HWTSTAMP_TX_OFF; 346 + } else { 347 + cfg->tx_type = HWTSTAMP_TX_OFF; 348 + } 349 + 350 + return 0; 351 + } 352 + 353 + static int ines_hwtstamp_set(struct mii_timestamper *mii_ts, 354 + struct kernel_hwtstamp_config *cfg, 355 + struct netlink_ext_ack *extack) 334 356 { 335 357 struct ines_port *port = container_of(mii_ts, struct ines_port, mii_ts); 336 358 u32 cm_one_step = 0, port_conf, ts_stat_rx, ts_stat_tx; ··· 731 709 } 732 710 port->mii_ts.rxtstamp = ines_rxtstamp; 733 711 port->mii_ts.txtstamp = ines_txtstamp; 734 - port->mii_ts.hwtstamp = ines_hwtstamp; 712 + port->mii_ts.hwtstamp_set = ines_hwtstamp_set; 713 + port->mii_ts.hwtstamp_get = ines_hwtstamp_get; 735 714 port->mii_ts.link_state = ines_link_state; 736 715 port->mii_ts.ts_info = ines_ts_info; 737 716
+9 -4
include/linux/mii_timestamper.h
··· 27 27 * as soon as a timestamp becomes available. One of the PTP_CLASS_ 28 28 * values is passed in 'type'. 29 29 * 30 - * @hwtstamp: Handles SIOCSHWTSTAMP ioctl for hardware time stamping. 30 + * @hwtstamp_set: Handles SIOCSHWTSTAMP ioctl for hardware time stamping. 31 + * 32 + * @hwtstamp_get: Handles SIOCGHWTSTAMP ioctl for hardware time stamping. 31 33 * 32 34 * @link_state: Allows the device to respond to changes in the link 33 35 * state. The caller invokes this function while holding ··· 53 51 void (*txtstamp)(struct mii_timestamper *mii_ts, 54 52 struct sk_buff *skb, int type); 55 53 56 - int (*hwtstamp)(struct mii_timestamper *mii_ts, 57 - struct kernel_hwtstamp_config *kernel_config, 58 - struct netlink_ext_ack *extack); 54 + int (*hwtstamp_set)(struct mii_timestamper *mii_ts, 55 + struct kernel_hwtstamp_config *kernel_config, 56 + struct netlink_ext_ack *extack); 57 + 58 + int (*hwtstamp_get)(struct mii_timestamper *mii_ts, 59 + struct kernel_hwtstamp_config *kernel_config); 59 60 60 61 void (*link_state)(struct mii_timestamper *mii_ts, 61 62 struct phy_device *phydev);
+2 -2
include/linux/phy.h
··· 1915 1915 */ 1916 1916 static inline bool phy_has_hwtstamp(struct phy_device *phydev) 1917 1917 { 1918 - return phydev && phydev->mii_ts && phydev->mii_ts->hwtstamp; 1918 + return phydev && phydev->mii_ts && phydev->mii_ts->hwtstamp_set; 1919 1919 } 1920 1920 1921 1921 /** ··· 1950 1950 struct kernel_hwtstamp_config *cfg, 1951 1951 struct netlink_ext_ack *extack) 1952 1952 { 1953 - return phydev->mii_ts->hwtstamp(phydev->mii_ts, cfg, extack); 1953 + return phydev->mii_ts->hwtstamp_set(phydev->mii_ts, cfg, extack); 1954 1954 } 1955 1955 1956 1956 static inline bool phy_rxtstamp(struct phy_device *phydev, struct sk_buff *skb,
+5 -4
net/core/dev_ioctl.c
··· 249 249 * 250 250 * Helper for calling the default hardware provider timestamping. 251 251 * 252 - * Note: phy_mii_ioctl() only handles SIOCSHWTSTAMP (not SIOCGHWTSTAMP), and 253 - * there only exists a phydev->mii_ts->hwtstamp() method. So this will return 254 - * -EOPNOTSUPP for phylib for now, which is still more accurate than letting 255 - * the netdev handle the GET request. 252 + * Note: phy_mii_ioctl() only handles SIOCSHWTSTAMP (not SIOCGHWTSTAMP), but 253 + * phydev->mii_ts has both hwtstamp_get() and hwtstamp_set() methods. So this 254 + * will return -EOPNOTSUPP for phylib only if hwtstamp_get() is not 255 + * implemented for now, which is still more accurate than letting the netdev 256 + * handle the GET request. 256 257 */ 257 258 int dev_get_hwtstamp_phylib(struct net_device *dev, 258 259 struct kernel_hwtstamp_config *cfg)