Commit a23d0486 authored by Vadim Fedorenko's avatar Vadim Fedorenko Committed by Jakub Kicinski
Browse files

net: thunderx: convert to use ndo_hwtstamp callbacks



The driver implemented SIOCSHWTSTAMP ioctl command only, but it also
stores configuration in private data, so it's possible to report it back
to users. Implement both ndo_hwtstamp_set and ndo_hwtstamp_get
callbacks.

Reviewed-by: default avatarKory Maincent <kory.maincent@bootlin.com>
Signed-off-by: default avatarVadim Fedorenko <vadim.fedorenko@linux.dev>
Link: https://patch.msgid.link/20251103150952.3538205-6-vadim.fedorenko@linux.dev


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 72c35e3a
Loading
Loading
Loading
Loading
+25 −20
Original line number Diff line number Diff line
@@ -1899,18 +1899,18 @@ static int nicvf_xdp(struct net_device *netdev, struct netdev_bpf *xdp)
	}
}

static int nicvf_config_hwtstamp(struct net_device *netdev, struct ifreq *ifr)
static int nicvf_hwtstamp_set(struct net_device *netdev,
			      struct kernel_hwtstamp_config *config,
			      struct netlink_ext_ack *extack)
{
	struct hwtstamp_config config;
	struct nicvf *nic = netdev_priv(netdev);

	if (!nic->ptp_clock)
	if (!nic->ptp_clock) {
		NL_SET_ERR_MSG_MOD(extack, "HW timestamping is not supported");
		return -ENODEV;
	}

	if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
		return -EFAULT;

	switch (config.tx_type) {
	switch (config->tx_type) {
	case HWTSTAMP_TX_OFF:
	case HWTSTAMP_TX_ON:
		break;
@@ -1918,7 +1918,7 @@ static int nicvf_config_hwtstamp(struct net_device *netdev, struct ifreq *ifr)
		return -ERANGE;
	}

	switch (config.rx_filter) {
	switch (config->rx_filter) {
	case HWTSTAMP_FILTER_NONE:
		nic->hw_rx_tstamp = false;
		break;
@@ -1937,7 +1937,7 @@ static int nicvf_config_hwtstamp(struct net_device *netdev, struct ifreq *ifr)
	case HWTSTAMP_FILTER_PTP_V2_SYNC:
	case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
		nic->hw_rx_tstamp = true;
		config.rx_filter = HWTSTAMP_FILTER_ALL;
		config->rx_filter = HWTSTAMP_FILTER_ALL;
		break;
	default:
		return -ERANGE;
@@ -1946,20 +1946,24 @@ static int nicvf_config_hwtstamp(struct net_device *netdev, struct ifreq *ifr)
	if (netif_running(netdev))
		nicvf_config_hw_rx_tstamp(nic, nic->hw_rx_tstamp);

	if (copy_to_user(ifr->ifr_data, &config, sizeof(config)))
		return -EFAULT;

	return 0;
}

static int nicvf_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
static int nicvf_hwtstamp_get(struct net_device *netdev,
			      struct kernel_hwtstamp_config *config)
{
	switch (cmd) {
	case SIOCSHWTSTAMP:
		return nicvf_config_hwtstamp(netdev, req);
	default:
		return -EOPNOTSUPP;
	}
	struct nicvf *nic = netdev_priv(netdev);

	if (!nic->ptp_clock)
		return -ENODEV;

	/* TX timestamping is technically always on */
	config->tx_type = HWTSTAMP_TX_ON;
	config->rx_filter = nic->hw_rx_tstamp ?
			    HWTSTAMP_FILTER_ALL :
			    HWTSTAMP_FILTER_NONE;

	return 0;
}

static void __nicvf_set_rx_mode_task(u8 mode, struct xcast_addr_list *mc_addrs,
@@ -2081,8 +2085,9 @@ static const struct net_device_ops nicvf_netdev_ops = {
	.ndo_fix_features       = nicvf_fix_features,
	.ndo_set_features       = nicvf_set_features,
	.ndo_bpf		= nicvf_xdp,
	.ndo_eth_ioctl           = nicvf_ioctl,
	.ndo_set_rx_mode        = nicvf_set_rx_mode,
	.ndo_hwtstamp_get	= nicvf_hwtstamp_get,
	.ndo_hwtstamp_set	= nicvf_hwtstamp_set,
};

static int nicvf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)