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

net_tstamp: add new flag HWTSTAMP_FLAG_BONDED_PHC_INDEX

Since commit 94dd016ae538 ("bond: pass get_ts_info and SIOC[SG]HWTSTAMP
ioctl to active device") the user could get bond active interface's
PHC index directly. But when there is a failover, the bond active
interface will change, thus the PHC index is also changed. This may
break the user's program if they did not update the PHC timely.

This patch adds a new hwtstamp_config flag HWTSTAMP_FLAG_BONDED_PHC_INDEX.
When the user wants to get the bond active interface's PHC, they need to
add this flag and be aware the PHC index may be changed.

With the new flag. All flag checks in current drivers are removed. Only
the checking in net_hwtstamp_validate() is kept.

Suggested-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Hangbin Liu and committed by
David S. Miller
9c9211a3 a3c62a04

+16 -144
-4
drivers/net/dsa/hirschmann/hellcreek_hwtstamp.c
··· 52 52 */ 53 53 clear_bit_unlock(HELLCREEK_HWTSTAMP_ENABLED, &ps->state); 54 54 55 - /* Reserved for future extensions */ 56 - if (config->flags) 57 - return -EINVAL; 58 - 59 55 switch (config->tx_type) { 60 56 case HWTSTAMP_TX_ON: 61 57 tx_tstamp_enable = true;
-4
drivers/net/dsa/mv88e6xxx/hwtstamp.c
··· 100 100 */ 101 101 clear_bit_unlock(MV88E6XXX_HWTSTAMP_ENABLED, &ps->state); 102 102 103 - /* reserved for future extensions */ 104 - if (config->flags) 105 - return -EINVAL; 106 - 107 103 switch (config->tx_type) { 108 104 case HWTSTAMP_TX_OFF: 109 105 tstamp_enable = false;
-3
drivers/net/ethernet/amd/xgbe/xgbe-drv.c
··· 1508 1508 if (copy_from_user(&config, ifreq->ifr_data, sizeof(config))) 1509 1509 return -EFAULT; 1510 1510 1511 - if (config.flags) 1512 - return -EINVAL; 1513 - 1514 1511 mac_tscr = 0; 1515 1512 1516 1513 switch (config.tx_type) {
-3
drivers/net/ethernet/aquantia/atlantic/aq_main.c
··· 231 231 static int aq_ndev_config_hwtstamp(struct aq_nic_s *aq_nic, 232 232 struct hwtstamp_config *config) 233 233 { 234 - if (config->flags) 235 - return -EINVAL; 236 - 237 234 switch (config->tx_type) { 238 235 case HWTSTAMP_TX_OFF: 239 236 case HWTSTAMP_TX_ON:
-5
drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
··· 15356 15356 DP(BNX2X_MSG_PTP, "Requested tx_type: %d, requested rx_filters = %d\n", 15357 15357 config.tx_type, config.rx_filter); 15358 15358 15359 - if (config.flags) { 15360 - BNX2X_ERR("config.flags is reserved for future use\n"); 15361 - return -EINVAL; 15362 - } 15363 - 15364 15359 bp->hwtstamp_ioctl_called = true; 15365 15360 bp->tx_type = config.tx_type; 15366 15361 bp->rx_filter = config.rx_filter;
-3
drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c
··· 417 417 if (copy_from_user(&stmpconf, ifr->ifr_data, sizeof(stmpconf))) 418 418 return -EFAULT; 419 419 420 - if (stmpconf.flags) 421 - return -EINVAL; 422 - 423 420 if (stmpconf.tx_type != HWTSTAMP_TX_ON && 424 421 stmpconf.tx_type != HWTSTAMP_TX_OFF) 425 422 return -ERANGE;
-3
drivers/net/ethernet/broadcom/tg3.c
··· 13806 13806 if (copy_from_user(&stmpconf, ifr->ifr_data, sizeof(stmpconf))) 13807 13807 return -EFAULT; 13808 13808 13809 - if (stmpconf.flags) 13810 - return -EINVAL; 13811 - 13812 13809 if (stmpconf.tx_type != HWTSTAMP_TX_ON && 13813 13810 stmpconf.tx_type != HWTSTAMP_TX_OFF) 13814 13811 return -ERANGE;
-4
drivers/net/ethernet/cadence/macb_ptp.c
··· 464 464 sizeof(*tstamp_config))) 465 465 return -EFAULT; 466 466 467 - /* reserved for future extensions */ 468 - if (tstamp_config->flags) 469 - return -EINVAL; 470 - 471 467 switch (tstamp_config->tx_type) { 472 468 case HWTSTAMP_TX_OFF: 473 469 break;
-3
drivers/net/ethernet/cavium/liquidio/lio_main.c
··· 2114 2114 if (copy_from_user(&conf, ifr->ifr_data, sizeof(conf))) 2115 2115 return -EFAULT; 2116 2116 2117 - if (conf.flags) 2118 - return -EINVAL; 2119 - 2120 2117 switch (conf.tx_type) { 2121 2118 case HWTSTAMP_TX_ON: 2122 2119 case HWTSTAMP_TX_OFF:
-3
drivers/net/ethernet/cavium/liquidio/lio_vf_main.c
··· 1254 1254 if (copy_from_user(&conf, ifr->ifr_data, sizeof(conf))) 1255 1255 return -EFAULT; 1256 1256 1257 - if (conf.flags) 1258 - return -EINVAL; 1259 - 1260 1257 switch (conf.tx_type) { 1261 1258 case HWTSTAMP_TX_ON: 1262 1259 case HWTSTAMP_TX_OFF:
-3
drivers/net/ethernet/cavium/octeon/octeon_mgmt.c
··· 702 702 if (copy_from_user(&config, rq->ifr_data, sizeof(config))) 703 703 return -EFAULT; 704 704 705 - if (config.flags) /* reserved for future extensions */ 706 - return -EINVAL; 707 - 708 705 /* Check the status of hardware for tiemstamps */ 709 706 if (OCTEON_IS_MODEL(OCTEON_CN6XXX)) { 710 707 /* Get the current state of the PTP clock */
-4
drivers/net/ethernet/cavium/thunder/nicvf_main.c
··· 1917 1917 if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) 1918 1918 return -EFAULT; 1919 1919 1920 - /* reserved for future extensions */ 1921 - if (config.flags) 1922 - return -EINVAL; 1923 - 1924 1920 switch (config.tx_type) { 1925 1921 case HWTSTAMP_TX_OFF: 1926 1922 case HWTSTAMP_TX_ON:
-3
drivers/net/ethernet/engleder/tsnep_ptp.c
··· 31 31 if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) 32 32 return -EFAULT; 33 33 34 - if (config.flags) 35 - return -EINVAL; 36 - 37 34 switch (config.tx_type) { 38 35 case HWTSTAMP_TX_OFF: 39 36 case HWTSTAMP_TX_ON:
-4
drivers/net/ethernet/freescale/fec_ptp.c
··· 473 473 if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) 474 474 return -EFAULT; 475 475 476 - /* reserved for future extensions */ 477 - if (config.flags) 478 - return -EINVAL; 479 - 480 476 switch (config.tx_type) { 481 477 case HWTSTAMP_TX_OFF: 482 478 fep->hwts_tx_en = 0;
-4
drivers/net/ethernet/freescale/gianfar.c
··· 2076 2076 if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) 2077 2077 return -EFAULT; 2078 2078 2079 - /* reserved for future extensions */ 2080 - if (config.flags) 2081 - return -EINVAL; 2082 - 2083 2079 switch (config.tx_type) { 2084 2080 case HWTSTAMP_TX_OFF: 2085 2081 priv->hwts_tx_en = 0;
-4
drivers/net/ethernet/intel/e1000e/netdev.c
··· 3614 3614 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP)) 3615 3615 return -EINVAL; 3616 3616 3617 - /* flags reserved for future extensions - must be zero */ 3618 - if (config->flags) 3619 - return -EINVAL; 3620 - 3621 3617 switch (config->tx_type) { 3622 3618 case HWTSTAMP_TX_OFF: 3623 3619 tsync_tx_ctl = 0;
-4
drivers/net/ethernet/intel/i40e/i40e_ptp.c
··· 1205 1205 1206 1206 INIT_WORK(&pf->ptp_extts0_work, i40e_ptp_extts0_work); 1207 1207 1208 - /* Reserved for future extensions. */ 1209 - if (config->flags) 1210 - return -EINVAL; 1211 - 1212 1208 switch (config->tx_type) { 1213 1209 case HWTSTAMP_TX_OFF: 1214 1210 pf->ptp_tx = false;
-4
drivers/net/ethernet/intel/ice/ice_ptp.c
··· 1205 1205 static int 1206 1206 ice_ptp_set_timestamp_mode(struct ice_pf *pf, struct hwtstamp_config *config) 1207 1207 { 1208 - /* Reserved for future extensions. */ 1209 - if (config->flags) 1210 - return -EINVAL; 1211 - 1212 1208 switch (config->tx_type) { 1213 1209 case HWTSTAMP_TX_OFF: 1214 1210 ice_set_tx_tstamp(pf, false);
-4
drivers/net/ethernet/intel/igb/igb_ptp.c
··· 1015 1015 bool is_l2 = false; 1016 1016 u32 regval; 1017 1017 1018 - /* reserved for future extensions */ 1019 - if (config->flags) 1020 - return -EINVAL; 1021 - 1022 1018 switch (config->tx_type) { 1023 1019 case HWTSTAMP_TX_OFF: 1024 1020 tsync_tx_ctl = 0;
-4
drivers/net/ethernet/intel/igc/igc_ptp.c
··· 560 560 static int igc_ptp_set_timestamp_mode(struct igc_adapter *adapter, 561 561 struct hwtstamp_config *config) 562 562 { 563 - /* reserved for future extensions */ 564 - if (config->flags) 565 - return -EINVAL; 566 - 567 563 switch (config->tx_type) { 568 564 case HWTSTAMP_TX_OFF: 569 565 igc_ptp_disable_tx_timestamp(adapter);
-4
drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
··· 992 992 bool is_l2 = false; 993 993 u32 regval; 994 994 995 - /* reserved for future extensions */ 996 - if (config->flags) 997 - return -EINVAL; 998 - 999 995 switch (config->tx_type) { 1000 996 case HWTSTAMP_TX_OFF: 1001 997 tsync_tx_ctl = 0;
-3
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
··· 5142 5142 if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) 5143 5143 return -EFAULT; 5144 5144 5145 - if (config.flags) 5146 - return -EINVAL; 5147 - 5148 5145 if (config.tx_type != HWTSTAMP_TX_OFF && 5149 5146 config.tx_type != HWTSTAMP_TX_ON) 5150 5147 return -ERANGE;
-4
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
··· 2002 2002 if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) 2003 2003 return -EFAULT; 2004 2004 2005 - /* reserved for future extensions */ 2006 - if (config.flags) 2007 - return -EINVAL; 2008 - 2009 2005 switch (config.tx_type) { 2010 2006 case HWTSTAMP_TX_OFF: 2011 2007 otx2_config_hw_tx_tstamp(pfvf, false);
-4
drivers/net/ethernet/mellanox/mlx4/en_netdev.c
··· 2427 2427 if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) 2428 2428 return -EFAULT; 2429 2429 2430 - /* reserved for future extensions */ 2431 - if (config.flags) 2432 - return -EINVAL; 2433 - 2434 2430 /* device doesn't support time stamping */ 2435 2431 if (!(mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS)) 2436 2432 return -EINVAL;
-6
drivers/net/ethernet/microchip/lan743x_ptp.c
··· 1305 1305 if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) 1306 1306 return -EFAULT; 1307 1307 1308 - if (config.flags) { 1309 - netif_warn(adapter, drv, adapter->netdev, 1310 - "ignoring hwtstamp_config.flags == 0x%08X, expected 0\n", 1311 - config.flags); 1312 - } 1313 - 1314 1308 switch (config.tx_type) { 1315 1309 case HWTSTAMP_TX_OFF: 1316 1310 for (index = 0; index < LAN743X_MAX_TX_CHANNELS;
-4
drivers/net/ethernet/mscc/ocelot.c
··· 1617 1617 if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) 1618 1618 return -EFAULT; 1619 1619 1620 - /* reserved for future extensions */ 1621 - if (cfg.flags) 1622 - return -EINVAL; 1623 - 1624 1620 /* Tx type sanity check */ 1625 1621 switch (cfg.tx_type) { 1626 1622 case HWTSTAMP_TX_ON:
-4
drivers/net/ethernet/neterion/vxge/vxge-main.c
··· 3159 3159 if (copy_from_user(&config, data, sizeof(config))) 3160 3160 return -EFAULT; 3161 3161 3162 - /* reserved for future extensions */ 3163 - if (config.flags) 3164 - return -EINVAL; 3165 - 3166 3162 /* Transmit HW Timestamp not supported */ 3167 3163 switch (config.tx_type) { 3168 3164 case HWTSTAMP_TX_OFF:
-3
drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
··· 210 210 if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) 211 211 return -EFAULT; 212 212 213 - if (cfg.flags) /* reserved for future extensions */ 214 - return -EINVAL; 215 - 216 213 /* Get ieee1588's dev information */ 217 214 pdev = adapter->ptp_pdev; 218 215
-5
drivers/net/ethernet/qlogic/qede/qede_ptp.c
··· 304 304 "HWTSTAMP IOCTL: Requested tx_type = %d, requested rx_filters = %d\n", 305 305 config.tx_type, config.rx_filter); 306 306 307 - if (config.flags) { 308 - DP_ERR(edev, "config.flags is reserved for future use\n"); 309 - return -EINVAL; 310 - } 311 - 312 307 ptp->hw_ts_ioctl_called = 1; 313 308 ptp->tx_type = config.tx_type; 314 309 ptp->rx_filter = config.rx_filter;
-4
drivers/net/ethernet/renesas/ravb_main.c
··· 2221 2221 if (copy_from_user(&config, req->ifr_data, sizeof(config))) 2222 2222 return -EFAULT; 2223 2223 2224 - /* Reserved for future extensions */ 2225 - if (config.flags) 2226 - return -EINVAL; 2227 - 2228 2224 switch (config.tx_type) { 2229 2225 case HWTSTAMP_TX_OFF: 2230 2226 tstamp_tx_ctrl = 0;
-3
drivers/net/ethernet/sfc/ptp.c
··· 1765 1765 { 1766 1766 int rc; 1767 1767 1768 - if (init->flags) 1769 - return -EINVAL; 1770 - 1771 1768 if ((init->tx_type != HWTSTAMP_TX_OFF) && 1772 1769 (init->tx_type != HWTSTAMP_TX_ON)) 1773 1770 return -ERANGE;
-4
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
··· 638 638 netdev_dbg(priv->dev, "%s config flags:0x%x, tx_type:0x%x, rx_filter:0x%x\n", 639 639 __func__, config.flags, config.tx_type, config.rx_filter); 640 640 641 - /* reserved for future extensions */ 642 - if (config.flags) 643 - return -EINVAL; 644 - 645 641 if (config.tx_type != HWTSTAMP_TX_OFF && 646 642 config.tx_type != HWTSTAMP_TX_ON) 647 643 return -ERANGE;
-4
drivers/net/ethernet/ti/cpsw_priv.c
··· 626 626 if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) 627 627 return -EFAULT; 628 628 629 - /* reserved for future extensions */ 630 - if (cfg.flags) 631 - return -EINVAL; 632 - 633 629 if (cfg.tx_type != HWTSTAMP_TX_OFF && cfg.tx_type != HWTSTAMP_TX_ON) 634 630 return -ERANGE; 635 631
-4
drivers/net/ethernet/ti/netcp_ethss.c
··· 2654 2654 if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) 2655 2655 return -EFAULT; 2656 2656 2657 - /* reserved for future extensions */ 2658 - if (cfg.flags) 2659 - return -EINVAL; 2660 - 2661 2657 switch (cfg.tx_type) { 2662 2658 case HWTSTAMP_TX_OFF: 2663 2659 gbe_dev->tx_ts_enabled = 0;
-3
drivers/net/ethernet/xscale/ixp4xx_eth.c
··· 382 382 if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) 383 383 return -EFAULT; 384 384 385 - if (cfg.flags) /* reserved for future extensions */ 386 - return -EINVAL; 387 - 388 385 ret = ixp46x_ptp_find(&port->timesync_regs, &port->phc_index); 389 386 if (ret) 390 387 return ret;
-3
drivers/net/phy/dp83640.c
··· 1235 1235 if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) 1236 1236 return -EFAULT; 1237 1237 1238 - if (cfg.flags) /* reserved for future extensions */ 1239 - return -EINVAL; 1240 - 1241 1238 if (cfg.tx_type < 0 || cfg.tx_type > HWTSTAMP_TX_ONESTEP_SYNC) 1242 1239 return -ERANGE; 1243 1240
-3
drivers/net/phy/mscc/mscc_ptp.c
··· 1057 1057 if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) 1058 1058 return -EFAULT; 1059 1059 1060 - if (cfg.flags) 1061 - return -EINVAL; 1062 - 1063 1060 switch (cfg.tx_type) { 1064 1061 case HWTSTAMP_TX_ONESTEP_SYNC: 1065 1062 one_step = true;
-4
drivers/ptp/ptp_ines.c
··· 338 338 if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) 339 339 return -EFAULT; 340 340 341 - /* reserved for future extensions */ 342 - if (cfg.flags) 343 - return -EINVAL; 344 - 345 341 switch (cfg.tx_type) { 346 342 case HWTSTAMP_TX_OFF: 347 343 ts_stat_tx = 0;
+15 -1
include/uapi/linux/net_tstamp.h
··· 62 62 /** 63 63 * struct hwtstamp_config - %SIOCGHWTSTAMP and %SIOCSHWTSTAMP parameter 64 64 * 65 - * @flags: no flags defined right now, must be zero for %SIOCSHWTSTAMP 65 + * @flags: one of HWTSTAMP_FLAG_* 66 66 * @tx_type: one of HWTSTAMP_TX_* 67 67 * @rx_filter: one of HWTSTAMP_FILTER_* 68 68 * ··· 76 76 int flags; 77 77 int tx_type; 78 78 int rx_filter; 79 + }; 80 + 81 + /* possible values for hwtstamp_config->flags */ 82 + enum hwtstamp_flags { 83 + /* 84 + * With this flag, the user could get bond active interface's 85 + * PHC index. Note this PHC index is not stable as when there 86 + * is a failover, the bond active interface will be changed, so 87 + * will be the PHC index. 88 + */ 89 + HWTSTAMP_FLAG_BONDED_PHC_INDEX = (1<<0), 90 + 91 + HWTSTAMP_FLAG_LAST = HWTSTAMP_FLAG_BONDED_PHC_INDEX, 92 + HWTSTAMP_FLAG_MASK = (HWTSTAMP_FLAG_LAST - 1) | HWTSTAMP_FLAG_LAST 79 93 }; 80 94 81 95 /* possible values for hwtstamp_config->tx_type */
+1 -1
net/core/dev_ioctl.c
··· 192 192 if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) 193 193 return -EFAULT; 194 194 195 - if (cfg.flags) /* reserved for future extensions */ 195 + if (cfg.flags & ~HWTSTAMP_FLAG_MASK) 196 196 return -EINVAL; 197 197 198 198 tx_type = cfg.tx_type;