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 'convert-drivers-to-use-ndo_hwtstamp-callbacks-part-4'

Vadim Fedorenko says:

====================
convert drivers to use ndo_hwtstamp callbacks part 4

This patchset is a subset of part 3 patchset to convert bnx2x and qede
drviers to use ndo callbacks instead ioctl to configure and report time
stamping. These drivers implemented only SIOCSHWTSTAMP command, but
converted to also provide configuration back to users. Some logic is
changed to avoid reporting configuration which is not in sync with the
HW in case of error happened.
====================

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

+104 -74
+48 -22
drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
··· 308 308 /**************************************************************************** 309 309 * General service functions 310 310 ****************************************************************************/ 311 - 312 - static int bnx2x_hwtstamp_ioctl(struct bnx2x *bp, struct ifreq *ifr); 311 + static int bnx2x_hwtstamp_set(struct net_device *dev, 312 + struct kernel_hwtstamp_config *config, 313 + struct netlink_ext_ack *extack); 314 + static int bnx2x_hwtstamp_get(struct net_device *dev, 315 + struct kernel_hwtstamp_config *config); 313 316 314 317 static void __storm_memset_dma_mapping(struct bnx2x *bp, 315 318 u32 addr, dma_addr_t mapping) ··· 12816 12813 if (!netif_running(dev)) 12817 12814 return -EAGAIN; 12818 12815 12819 - switch (cmd) { 12820 - case SIOCSHWTSTAMP: 12821 - return bnx2x_hwtstamp_ioctl(bp, ifr); 12822 - default: 12823 - DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n", 12824 - mdio->phy_id, mdio->reg_num, mdio->val_in); 12825 - return mdio_mii_ioctl(&bp->mdio, mdio, cmd); 12826 - } 12816 + DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n", 12817 + mdio->phy_id, mdio->reg_num, mdio->val_in); 12818 + return mdio_mii_ioctl(&bp->mdio, mdio, cmd); 12827 12819 } 12828 12820 12829 12821 static int bnx2x_validate_addr(struct net_device *dev) ··· 13034 13036 .ndo_get_phys_port_id = bnx2x_get_phys_port_id, 13035 13037 .ndo_set_vf_link_state = bnx2x_set_vf_link_state, 13036 13038 .ndo_features_check = bnx2x_features_check, 13039 + .ndo_hwtstamp_get = bnx2x_hwtstamp_get, 13040 + .ndo_hwtstamp_set = bnx2x_hwtstamp_set, 13037 13041 }; 13038 13042 13039 13043 static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev, ··· 15350 15350 return 0; 15351 15351 } 15352 15352 15353 - static int bnx2x_hwtstamp_ioctl(struct bnx2x *bp, struct ifreq *ifr) 15353 + static int bnx2x_hwtstamp_set(struct net_device *dev, 15354 + struct kernel_hwtstamp_config *config, 15355 + struct netlink_ext_ack *extack) 15354 15356 { 15355 - struct hwtstamp_config config; 15357 + struct bnx2x *bp = netdev_priv(dev); 15356 15358 int rc; 15357 15359 15358 - DP(BNX2X_MSG_PTP, "HWTSTAMP IOCTL called\n"); 15360 + DP(BNX2X_MSG_PTP, "HWTSTAMP SET called\n"); 15359 15361 15360 - if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) 15361 - return -EFAULT; 15362 + if (!netif_running(dev)) { 15363 + NL_SET_ERR_MSG_MOD(extack, "Device is down"); 15364 + return -EAGAIN; 15365 + } 15362 15366 15363 15367 DP(BNX2X_MSG_PTP, "Requested tx_type: %d, requested rx_filters = %d\n", 15364 - config.tx_type, config.rx_filter); 15368 + config->tx_type, config->rx_filter); 15369 + 15370 + switch (config->tx_type) { 15371 + case HWTSTAMP_TX_ON: 15372 + case HWTSTAMP_TX_OFF: 15373 + break; 15374 + default: 15375 + NL_SET_ERR_MSG_MOD(extack, 15376 + "One-step timestamping is not supported"); 15377 + return -ERANGE; 15378 + } 15365 15379 15366 15380 bp->hwtstamp_ioctl_called = true; 15367 - bp->tx_type = config.tx_type; 15368 - bp->rx_filter = config.rx_filter; 15381 + bp->tx_type = config->tx_type; 15382 + bp->rx_filter = config->rx_filter; 15369 15383 15370 15384 rc = bnx2x_configure_ptp_filters(bp); 15371 - if (rc) 15385 + if (rc) { 15386 + NL_SET_ERR_MSG_MOD(extack, "HW configuration failure"); 15372 15387 return rc; 15388 + } 15373 15389 15374 - config.rx_filter = bp->rx_filter; 15390 + config->rx_filter = bp->rx_filter; 15375 15391 15376 - return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? 15377 - -EFAULT : 0; 15392 + return 0; 15393 + } 15394 + 15395 + static int bnx2x_hwtstamp_get(struct net_device *dev, 15396 + struct kernel_hwtstamp_config *config) 15397 + { 15398 + struct bnx2x *bp = netdev_priv(dev); 15399 + 15400 + config->rx_filter = bp->rx_filter; 15401 + config->tx_type = bp->tx_type; 15402 + 15403 + return 0; 15378 15404 } 15379 15405 15380 15406 /* Configures HW for PTP */
+2 -20
drivers/net/ethernet/qlogic/qede/qede_main.c
··· 506 506 } 507 507 #endif 508 508 509 - static int qede_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) 510 - { 511 - struct qede_dev *edev = netdev_priv(dev); 512 - 513 - if (!netif_running(dev)) 514 - return -EAGAIN; 515 - 516 - switch (cmd) { 517 - case SIOCSHWTSTAMP: 518 - return qede_ptp_hw_ts(edev, ifr); 519 - default: 520 - DP_VERBOSE(edev, QED_MSG_DEBUG, 521 - "default IOCTL cmd 0x%x\n", cmd); 522 - return -EOPNOTSUPP; 523 - } 524 - 525 - return 0; 526 - } 527 - 528 509 static void qede_fp_sb_dump(struct qede_dev *edev, struct qede_fastpath *fp) 529 510 { 530 511 char *p_sb = (char *)fp->sb_info->sb_virt; ··· 698 717 .ndo_set_mac_address = qede_set_mac_addr, 699 718 .ndo_validate_addr = eth_validate_addr, 700 719 .ndo_change_mtu = qede_change_mtu, 701 - .ndo_eth_ioctl = qede_ioctl, 702 720 .ndo_tx_timeout = qede_tx_timeout, 703 721 #ifdef CONFIG_QED_SRIOV 704 722 .ndo_set_vf_mac = qede_set_vf_mac, ··· 722 742 #endif 723 743 .ndo_xdp_xmit = qede_xdp_transmit, 724 744 .ndo_setup_tc = qede_setup_tc_offload, 745 + .ndo_hwtstamp_get = qede_hwtstamp_get, 746 + .ndo_hwtstamp_set = qede_hwtstamp_set, 725 747 }; 726 748 727 749 static const struct net_device_ops qede_netdev_vf_ops = {
+49 -31
drivers/net/ethernet/qlogic/qede/qede_ptp.c
··· 199 199 return phc_cycles; 200 200 } 201 201 202 - static int qede_ptp_cfg_filters(struct qede_dev *edev) 202 + static void qede_ptp_cfg_filters(struct qede_dev *edev) 203 203 { 204 204 enum qed_ptp_hwtstamp_tx_type tx_type = QED_PTP_HWTSTAMP_TX_ON; 205 205 enum qed_ptp_filter_type rx_filter = QED_PTP_FILTER_NONE; 206 206 struct qede_ptp *ptp = edev->ptp; 207 207 208 - if (!ptp) 209 - return -EIO; 210 - 211 208 if (!ptp->hw_ts_ioctl_called) { 212 209 DP_INFO(edev, "TS IOCTL not called\n"); 213 - return 0; 210 + return; 214 211 } 215 212 216 213 switch (ptp->tx_type) { ··· 220 223 clear_bit(QEDE_FLAGS_TX_TIMESTAMPING_EN, &edev->flags); 221 224 tx_type = QED_PTP_HWTSTAMP_TX_OFF; 222 225 break; 223 - 224 - case HWTSTAMP_TX_ONESTEP_SYNC: 225 - case HWTSTAMP_TX_ONESTEP_P2P: 226 - DP_ERR(edev, "One-step timestamping is not supported\n"); 227 - return -ERANGE; 228 226 } 229 227 230 228 spin_lock_bh(&ptp->lock); ··· 278 286 ptp->ops->cfg_filters(edev->cdev, rx_filter, tx_type); 279 287 280 288 spin_unlock_bh(&ptp->lock); 289 + } 290 + 291 + int qede_hwtstamp_set(struct net_device *netdev, 292 + struct kernel_hwtstamp_config *config, 293 + struct netlink_ext_ack *extack) 294 + { 295 + struct qede_dev *edev = netdev_priv(netdev); 296 + struct qede_ptp *ptp; 297 + 298 + if (!netif_running(netdev)) { 299 + NL_SET_ERR_MSG_MOD(extack, "Device is down"); 300 + return -EAGAIN; 301 + } 302 + 303 + ptp = edev->ptp; 304 + if (!ptp) { 305 + NL_SET_ERR_MSG_MOD(extack, "HW timestamping is not supported"); 306 + return -EIO; 307 + } 308 + 309 + DP_VERBOSE(edev, QED_MSG_DEBUG, 310 + "HWTSTAMP SET: Requested tx_type = %d, requested rx_filters = %d\n", 311 + config->tx_type, config->rx_filter); 312 + 313 + switch (config->tx_type) { 314 + case HWTSTAMP_TX_ON: 315 + case HWTSTAMP_TX_OFF: 316 + break; 317 + default: 318 + NL_SET_ERR_MSG_MOD(extack, 319 + "One-step timestamping is not supported"); 320 + return -ERANGE; 321 + } 322 + 323 + ptp->hw_ts_ioctl_called = 1; 324 + ptp->tx_type = config->tx_type; 325 + ptp->rx_filter = config->rx_filter; 326 + 327 + qede_ptp_cfg_filters(edev); 328 + 329 + config->rx_filter = ptp->rx_filter; 281 330 282 331 return 0; 283 332 } 284 333 285 - int qede_ptp_hw_ts(struct qede_dev *edev, struct ifreq *ifr) 334 + int qede_hwtstamp_get(struct net_device *netdev, 335 + struct kernel_hwtstamp_config *config) 286 336 { 287 - struct hwtstamp_config config; 337 + struct qede_dev *edev = netdev_priv(netdev); 288 338 struct qede_ptp *ptp; 289 - int rc; 290 339 291 340 ptp = edev->ptp; 292 341 if (!ptp) 293 342 return -EIO; 294 343 295 - if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) 296 - return -EFAULT; 344 + config->tx_type = ptp->tx_type; 345 + config->rx_filter = ptp->rx_filter; 297 346 298 - DP_VERBOSE(edev, QED_MSG_DEBUG, 299 - "HWTSTAMP IOCTL: Requested tx_type = %d, requested rx_filters = %d\n", 300 - config.tx_type, config.rx_filter); 301 - 302 - ptp->hw_ts_ioctl_called = 1; 303 - ptp->tx_type = config.tx_type; 304 - ptp->rx_filter = config.rx_filter; 305 - 306 - rc = qede_ptp_cfg_filters(edev); 307 - if (rc) 308 - return rc; 309 - 310 - config.rx_filter = ptp->rx_filter; 311 - 312 - return copy_to_user(ifr->ifr_data, &config, 313 - sizeof(config)) ? -EFAULT : 0; 347 + return 0; 314 348 } 315 349 316 350 int qede_ptp_get_ts_info(struct qede_dev *edev, struct kernel_ethtool_ts_info *info)
+5 -1
drivers/net/ethernet/qlogic/qede/qede_ptp.h
··· 14 14 15 15 void qede_ptp_rx_ts(struct qede_dev *edev, struct sk_buff *skb); 16 16 void qede_ptp_tx_ts(struct qede_dev *edev, struct sk_buff *skb); 17 - int qede_ptp_hw_ts(struct qede_dev *edev, struct ifreq *req); 17 + int qede_hwtstamp_get(struct net_device *netdev, 18 + struct kernel_hwtstamp_config *config); 19 + int qede_hwtstamp_set(struct net_device *netdev, 20 + struct kernel_hwtstamp_config *config, 21 + struct netlink_ext_ack *extack); 18 22 void qede_ptp_disable(struct qede_dev *edev); 19 23 int qede_ptp_enable(struct qede_dev *edev); 20 24 int qede_ptp_get_ts_info(struct qede_dev *edev, struct kernel_ethtool_ts_info *ts);