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.

ti: netcp: convert to ndo_hwtstamp callbacks

Convert TI NetCP driver to use ndo_hwtstamp_get()/ndo_hwtstamp_set()
callbacks. The logic is slightly changed, because I believe the original
logic was not really correct. Config reading part is using the very
first module to get the configuration instead of iterating over all of
them and keep the last one as the configuration is supposed to be identical
for all modules. HW timestamp config set path is now trying to configure
all modules, but in case of error from one module it adds extack
message. This way the configuration will be as synchronized as possible.

There are only 2 modules using netcp core infrastructure, and both use
the very same function to configure HW timestamping, so no actual
difference in behavior is expected.

Signed-off-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Reviewed-by: Kory Maincent <kory.maincent@bootlin.com>
Link: https://patch.msgid.link/20251103172902.3538392-1-vadim.fedorenko@linux.dev
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Vadim Fedorenko and committed by
Jakub Kicinski
3f02b827 bdf27b54

+103 -32
+5
drivers/net/ethernet/ti/netcp.h
··· 207 207 int (*del_vid)(void *intf_priv, int vid); 208 208 int (*ioctl)(void *intf_priv, struct ifreq *req, int cmd); 209 209 int (*set_rx_mode)(void *intf_priv, bool promisc); 210 + int (*hwtstamp_get)(void *intf_priv, 211 + struct kernel_hwtstamp_config *cfg); 212 + int (*hwtstamp_set)(void *intf_priv, 213 + struct kernel_hwtstamp_config *cfg, 214 + struct netlink_ext_ack *extack); 210 215 211 216 /* used internally */ 212 217 struct list_head module_list;
+58
drivers/net/ethernet/ti/netcp_core.c
··· 1781 1781 return 0; 1782 1782 } 1783 1783 1784 + static int netcp_ndo_hwtstamp_get(struct net_device *ndev, 1785 + struct kernel_hwtstamp_config *config) 1786 + { 1787 + struct netcp_intf *netcp = netdev_priv(ndev); 1788 + struct netcp_intf_modpriv *intf_modpriv; 1789 + struct netcp_module *module; 1790 + int err = -EOPNOTSUPP; 1791 + 1792 + if (!netif_running(ndev)) 1793 + return -EINVAL; 1794 + 1795 + for_each_module(netcp, intf_modpriv) { 1796 + module = intf_modpriv->netcp_module; 1797 + if (!module->hwtstamp_get) 1798 + continue; 1799 + 1800 + err = module->hwtstamp_get(intf_modpriv->module_priv, config); 1801 + break; 1802 + } 1803 + 1804 + return err; 1805 + } 1806 + 1807 + static int netcp_ndo_hwtstamp_set(struct net_device *ndev, 1808 + struct kernel_hwtstamp_config *config, 1809 + struct netlink_ext_ack *extack) 1810 + { 1811 + struct netcp_intf *netcp = netdev_priv(ndev); 1812 + struct netcp_intf_modpriv *intf_modpriv; 1813 + struct netcp_module *module; 1814 + int ret = -1, err = -EOPNOTSUPP; 1815 + 1816 + if (!netif_running(ndev)) 1817 + return -EINVAL; 1818 + 1819 + for_each_module(netcp, intf_modpriv) { 1820 + module = intf_modpriv->netcp_module; 1821 + if (!module->hwtstamp_set) 1822 + continue; 1823 + 1824 + err = module->hwtstamp_set(intf_modpriv->module_priv, config, 1825 + extack); 1826 + if ((err < 0) && (err != -EOPNOTSUPP)) { 1827 + NL_SET_ERR_MSG_WEAK_MOD(extack, 1828 + "At least one module failed to setup HW timestamps"); 1829 + ret = err; 1830 + goto out; 1831 + } 1832 + if (err == 0) 1833 + ret = err; 1834 + } 1835 + 1836 + out: 1837 + return (ret == 0) ? 0 : err; 1838 + } 1839 + 1784 1840 static int netcp_ndo_ioctl(struct net_device *ndev, 1785 1841 struct ifreq *req, int cmd) 1786 1842 { ··· 2008 1952 .ndo_tx_timeout = netcp_ndo_tx_timeout, 2009 1953 .ndo_select_queue = dev_pick_tx_zero, 2010 1954 .ndo_setup_tc = netcp_setup_tc, 1955 + .ndo_hwtstamp_get = netcp_ndo_hwtstamp_get, 1956 + .ndo_hwtstamp_set = netcp_ndo_hwtstamp_set, 2011 1957 }; 2012 1958 2013 1959 static int netcp_create_interface(struct netcp_device *netcp_device,
+40 -32
drivers/net/ethernet/ti/netcp_ethss.c
··· 2591 2591 return 0; 2592 2592 } 2593 2593 2594 - static int gbe_hwtstamp_get(struct gbe_intf *gbe_intf, struct ifreq *ifr) 2594 + static int gbe_hwtstamp_get(void *intf_priv, struct kernel_hwtstamp_config *cfg) 2595 2595 { 2596 - struct gbe_priv *gbe_dev = gbe_intf->gbe_dev; 2597 - struct cpts *cpts = gbe_dev->cpts; 2598 - struct hwtstamp_config cfg; 2596 + struct gbe_intf *gbe_intf = intf_priv; 2597 + struct gbe_priv *gbe_dev; 2598 + struct phy_device *phy; 2599 2599 2600 - if (!cpts) 2600 + gbe_dev = gbe_intf->gbe_dev; 2601 + 2602 + if (!gbe_dev->cpts) 2601 2603 return -EOPNOTSUPP; 2602 2604 2603 - cfg.flags = 0; 2604 - cfg.tx_type = gbe_dev->tx_ts_enabled ? HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF; 2605 - cfg.rx_filter = gbe_dev->rx_ts_enabled; 2605 + phy = gbe_intf->slave->phy; 2606 + if (phy_has_hwtstamp(phy)) 2607 + return -EOPNOTSUPP; 2606 2608 2607 - return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0; 2609 + cfg->flags = 0; 2610 + cfg->tx_type = gbe_dev->tx_ts_enabled ? HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF; 2611 + cfg->rx_filter = gbe_dev->rx_ts_enabled; 2612 + 2613 + return 0; 2608 2614 } 2609 2615 2610 2616 static void gbe_hwtstamp(struct gbe_intf *gbe_intf) ··· 2643 2637 writel(ctl, GBE_REG_ADDR(slave, port_regs, ts_ctl_ltype2)); 2644 2638 } 2645 2639 2646 - static int gbe_hwtstamp_set(struct gbe_intf *gbe_intf, struct ifreq *ifr) 2640 + static int gbe_hwtstamp_set(void *intf_priv, struct kernel_hwtstamp_config *cfg, 2641 + struct netlink_ext_ack *extack) 2647 2642 { 2648 - struct gbe_priv *gbe_dev = gbe_intf->gbe_dev; 2649 - struct cpts *cpts = gbe_dev->cpts; 2650 - struct hwtstamp_config cfg; 2643 + struct gbe_intf *gbe_intf = intf_priv; 2644 + struct gbe_priv *gbe_dev; 2645 + struct phy_device *phy; 2651 2646 2652 - if (!cpts) 2647 + gbe_dev = gbe_intf->gbe_dev; 2648 + 2649 + if (!gbe_dev->cpts) 2653 2650 return -EOPNOTSUPP; 2654 2651 2655 - if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) 2656 - return -EFAULT; 2652 + phy = gbe_intf->slave->phy; 2653 + if (phy_has_hwtstamp(phy)) 2654 + return phy->mii_ts->hwtstamp(phy->mii_ts, cfg, extack); 2657 2655 2658 - switch (cfg.tx_type) { 2656 + switch (cfg->tx_type) { 2659 2657 case HWTSTAMP_TX_OFF: 2660 2658 gbe_dev->tx_ts_enabled = 0; 2661 2659 break; ··· 2670 2660 return -ERANGE; 2671 2661 } 2672 2662 2673 - switch (cfg.rx_filter) { 2663 + switch (cfg->rx_filter) { 2674 2664 case HWTSTAMP_FILTER_NONE: 2675 2665 gbe_dev->rx_ts_enabled = HWTSTAMP_FILTER_NONE; 2676 2666 break; ··· 2678 2668 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: 2679 2669 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: 2680 2670 gbe_dev->rx_ts_enabled = HWTSTAMP_FILTER_PTP_V1_L4_EVENT; 2681 - cfg.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT; 2671 + cfg->rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT; 2682 2672 break; 2683 2673 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: 2684 2674 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: ··· 2690 2680 case HWTSTAMP_FILTER_PTP_V2_SYNC: 2691 2681 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: 2692 2682 gbe_dev->rx_ts_enabled = HWTSTAMP_FILTER_PTP_V2_EVENT; 2693 - cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; 2683 + cfg->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; 2694 2684 break; 2695 2685 default: 2696 2686 return -ERANGE; ··· 2698 2688 2699 2689 gbe_hwtstamp(gbe_intf); 2700 2690 2701 - return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0; 2691 + return 0; 2702 2692 } 2703 2693 2704 2694 static void gbe_register_cpts(struct gbe_priv *gbe_dev) ··· 2755 2745 { 2756 2746 } 2757 2747 2758 - static inline int gbe_hwtstamp_get(struct gbe_intf *gbe_intf, struct ifreq *req) 2748 + static inline int gbe_hwtstamp_get(struct gbe_intf *gbe_intf, 2749 + struct kernel_hwtstamp_config *cfg) 2759 2750 { 2760 2751 return -EOPNOTSUPP; 2761 2752 } 2762 2753 2763 - static inline int gbe_hwtstamp_set(struct gbe_intf *gbe_intf, struct ifreq *req) 2754 + static inline int gbe_hwtstamp_set(struct gbe_intf *gbe_intf, 2755 + struct kernel_hwtstamp_config *cfg, 2756 + struct netlink_ext_ack *extack) 2764 2757 { 2765 2758 return -EOPNOTSUPP; 2766 2759 } ··· 2828 2815 { 2829 2816 struct gbe_intf *gbe_intf = intf_priv; 2830 2817 struct phy_device *phy = gbe_intf->slave->phy; 2831 - 2832 - if (!phy_has_hwtstamp(phy)) { 2833 - switch (cmd) { 2834 - case SIOCGHWTSTAMP: 2835 - return gbe_hwtstamp_get(gbe_intf, req); 2836 - case SIOCSHWTSTAMP: 2837 - return gbe_hwtstamp_set(gbe_intf, req); 2838 - } 2839 - } 2840 2818 2841 2819 if (phy) 2842 2820 return phy_mii_ioctl(phy, req, cmd); ··· 3828 3824 .add_vid = gbe_add_vid, 3829 3825 .del_vid = gbe_del_vid, 3830 3826 .ioctl = gbe_ioctl, 3827 + .hwtstamp_get = gbe_hwtstamp_get, 3828 + .hwtstamp_set = gbe_hwtstamp_set, 3831 3829 }; 3832 3830 3833 3831 static struct netcp_module xgbe_module = { ··· 3847 3841 .add_vid = gbe_add_vid, 3848 3842 .del_vid = gbe_del_vid, 3849 3843 .ioctl = gbe_ioctl, 3844 + .hwtstamp_get = gbe_hwtstamp_get, 3845 + .hwtstamp_set = gbe_hwtstamp_set, 3850 3846 }; 3851 3847 3852 3848 static int __init keystone_gbe_init(void)