Commit ea256222 authored by Luo bin's avatar Luo bin Committed by David S. Miller
Browse files

hinic: add support to set and get pause params



add support to set pause params with ethtool -A and get pause
params with ethtool -a. Also remove set_link_ksettings ops for VF
and enable pause by default.

Signed-off-by: default avatarLuo bin <luobin9@huawei.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 491f14db
Loading
Loading
Loading
Loading
+85 −1
Original line number Diff line number Diff line
@@ -613,6 +613,64 @@ static int hinic_set_ringparam(struct net_device *netdev,

	return 0;
}

static void hinic_get_pauseparam(struct net_device *netdev,
				 struct ethtool_pauseparam *pause)
{
	struct hinic_dev *nic_dev = netdev_priv(netdev);
	struct hinic_pause_config pause_info = {0};
	struct hinic_nic_cfg *nic_cfg;
	int err;

	nic_cfg = &nic_dev->hwdev->func_to_io.nic_cfg;

	err = hinic_get_hw_pause_info(nic_dev->hwdev, &pause_info);
	if (!err) {
		pause->autoneg = pause_info.auto_neg;
		if (nic_cfg->pause_set || !pause_info.auto_neg) {
			pause->rx_pause = nic_cfg->rx_pause;
			pause->tx_pause = nic_cfg->tx_pause;
		} else {
			pause->rx_pause = pause_info.rx_pause;
			pause->tx_pause = pause_info.tx_pause;
		}
	}
}

static int hinic_set_pauseparam(struct net_device *netdev,
				struct ethtool_pauseparam *pause)
{
	struct hinic_dev *nic_dev = netdev_priv(netdev);
	struct hinic_pause_config pause_info = {0};
	struct hinic_port_cap port_cap = {0};
	int err;

	err = hinic_port_get_cap(nic_dev, &port_cap);
	if (err)
		return -EIO;

	if (pause->autoneg != port_cap.autoneg_state)
		return -EOPNOTSUPP;

	pause_info.auto_neg = pause->autoneg;
	pause_info.rx_pause = pause->rx_pause;
	pause_info.tx_pause = pause->tx_pause;

	mutex_lock(&nic_dev->hwdev->func_to_io.nic_cfg.cfg_mutex);
	err = hinic_set_hw_pause_info(nic_dev->hwdev, &pause_info);
	if (err) {
		mutex_unlock(&nic_dev->hwdev->func_to_io.nic_cfg.cfg_mutex);
		return err;
	}
	nic_dev->hwdev->func_to_io.nic_cfg.pause_set = true;
	nic_dev->hwdev->func_to_io.nic_cfg.auto_neg = pause->autoneg;
	nic_dev->hwdev->func_to_io.nic_cfg.rx_pause = pause->rx_pause;
	nic_dev->hwdev->func_to_io.nic_cfg.tx_pause = pause->tx_pause;
	mutex_unlock(&nic_dev->hwdev->func_to_io.nic_cfg.cfg_mutex);

	return 0;
}

static void hinic_get_channels(struct net_device *netdev,
			       struct ethtool_channels *channels)
{
@@ -1241,6 +1299,27 @@ static const struct ethtool_ops hinic_ethtool_ops = {
	.get_link = ethtool_op_get_link,
	.get_ringparam = hinic_get_ringparam,
	.set_ringparam = hinic_set_ringparam,
	.get_pauseparam = hinic_get_pauseparam,
	.set_pauseparam = hinic_set_pauseparam,
	.get_channels = hinic_get_channels,
	.set_channels = hinic_set_channels,
	.get_rxnfc = hinic_get_rxnfc,
	.set_rxnfc = hinic_set_rxnfc,
	.get_rxfh_key_size = hinic_get_rxfh_key_size,
	.get_rxfh_indir_size = hinic_get_rxfh_indir_size,
	.get_rxfh = hinic_get_rxfh,
	.set_rxfh = hinic_set_rxfh,
	.get_sset_count = hinic_get_sset_count,
	.get_ethtool_stats = hinic_get_ethtool_stats,
	.get_strings = hinic_get_strings,
};

static const struct ethtool_ops hinicvf_ethtool_ops = {
	.get_link_ksettings = hinic_get_link_ksettings,
	.get_drvinfo = hinic_get_drvinfo,
	.get_link = ethtool_op_get_link,
	.get_ringparam = hinic_get_ringparam,
	.set_ringparam = hinic_set_ringparam,
	.get_channels = hinic_get_channels,
	.set_channels = hinic_set_channels,
	.get_rxnfc = hinic_get_rxnfc,
@@ -1256,5 +1335,10 @@ static const struct ethtool_ops hinic_ethtool_ops = {

void hinic_set_ethtool_ops(struct net_device *netdev)
{
	struct hinic_dev *nic_dev = netdev_priv(netdev);

	if (!HINIC_IS_VF(nic_dev->hwdev->hwif))
		netdev->ethtool_ops = &hinic_ethtool_ops;
	else
		netdev->ethtool_ops = &hinicvf_ethtool_ops;
}
+2 −0
Original line number Diff line number Diff line
@@ -777,6 +777,8 @@ struct hinic_hwdev *hinic_init_hwdev(struct pci_dev *pdev)
		goto err_dev_cap;
	}

	mutex_init(&hwdev->func_to_io.nic_cfg.cfg_mutex);

	err = hinic_vf_func_init(hwdev);
	if (err) {
		dev_err(&pdev->dev, "Failed to init nic mbox\n");
+2 −0
Original line number Diff line number Diff line
@@ -48,6 +48,8 @@ enum hinic_port_cmd {
	HINIC_PORT_CMD_ADD_VLAN         = 3,
	HINIC_PORT_CMD_DEL_VLAN         = 4,

	HINIC_PORT_CMD_SET_PFC		= 5,

	HINIC_PORT_CMD_SET_MAC          = 9,
	HINIC_PORT_CMD_GET_MAC          = 10,
	HINIC_PORT_CMD_DEL_MAC          = 11,
+10 −0
Original line number Diff line number Diff line
@@ -47,6 +47,15 @@ struct hinic_free_db_area {
	struct semaphore        idx_lock;
};

struct hinic_nic_cfg {
	/* lock for getting nic cfg */
	struct mutex		cfg_mutex;
	bool			pause_set;
	u32			auto_neg;
	u32			rx_pause;
	u32			tx_pause;
};

struct hinic_func_to_io {
	struct hinic_hwif       *hwif;
	struct hinic_hwdev      *hwdev;
@@ -78,6 +87,7 @@ struct hinic_func_to_io {
	u16			max_vfs;
	struct vf_data_storage	*vf_infos;
	u8			link_status;
	struct hinic_nic_cfg	nic_cfg;
};

struct hinic_wq_page_size {
+65 −10
Original line number Diff line number Diff line
@@ -887,6 +887,26 @@ static void netdev_features_init(struct net_device *netdev)
	netdev->features = netdev->hw_features | NETIF_F_HW_VLAN_CTAG_FILTER;
}

static void hinic_refresh_nic_cfg(struct hinic_dev *nic_dev)
{
	struct hinic_nic_cfg *nic_cfg = &nic_dev->hwdev->func_to_io.nic_cfg;
	struct hinic_pause_config pause_info = {0};
	struct hinic_port_cap port_cap = {0};

	if (hinic_port_get_cap(nic_dev, &port_cap))
		return;

	mutex_lock(&nic_cfg->cfg_mutex);
	if (nic_cfg->pause_set || !port_cap.autoneg_state) {
		nic_cfg->auto_neg = port_cap.autoneg_state;
		pause_info.auto_neg = nic_cfg->auto_neg;
		pause_info.rx_pause = nic_cfg->rx_pause;
		pause_info.tx_pause = nic_cfg->tx_pause;
		hinic_set_hw_pause_info(nic_dev->hwdev, &pause_info);
	}
	mutex_unlock(&nic_cfg->cfg_mutex);
}

/**
 * link_status_event_handler - link event handler
 * @handle: nic device for the handler
@@ -918,6 +938,9 @@ static void link_status_event_handler(void *handle, void *buf_in, u16 in_size,

		up(&nic_dev->mgmt_lock);

		if (!HINIC_IS_VF(nic_dev->hwdev->hwif))
			hinic_refresh_nic_cfg(nic_dev);

		netif_info(nic_dev, drv, nic_dev->netdev, "HINIC_Link is UP\n");
	} else {
		down(&nic_dev->mgmt_lock);
@@ -948,28 +971,54 @@ static int set_features(struct hinic_dev *nic_dev,
{
	netdev_features_t changed = force_change ? ~0 : pre_features ^ features;
	u32 csum_en = HINIC_RX_CSUM_OFFLOAD_EN;
	netdev_features_t failed_features = 0;
	int ret = 0;
	int err = 0;

	if (changed & NETIF_F_TSO)
		err = hinic_port_set_tso(nic_dev, (features & NETIF_F_TSO) ?
	if (changed & NETIF_F_TSO) {
		ret = hinic_port_set_tso(nic_dev, (features & NETIF_F_TSO) ?
					 HINIC_TSO_ENABLE : HINIC_TSO_DISABLE);
		if (ret) {
			err = ret;
			failed_features |= NETIF_F_TSO;
		}
	}

	if (changed & NETIF_F_RXCSUM)
		err = hinic_set_rx_csum_offload(nic_dev, csum_en);
	if (changed & NETIF_F_RXCSUM) {
		ret = hinic_set_rx_csum_offload(nic_dev, csum_en);
		if (ret) {
			err = ret;
			failed_features |= NETIF_F_RXCSUM;
		}
	}

	if (changed & NETIF_F_LRO) {
		err = hinic_set_rx_lro_state(nic_dev,
		ret = hinic_set_rx_lro_state(nic_dev,
					     !!(features & NETIF_F_LRO),
					     HINIC_LRO_RX_TIMER_DEFAULT,
					     HINIC_LRO_MAX_WQE_NUM_DEFAULT);
		if (ret) {
			err = ret;
			failed_features |= NETIF_F_LRO;
		}
	}

	if (changed & NETIF_F_HW_VLAN_CTAG_RX)
		err = hinic_set_rx_vlan_offload(nic_dev,
	if (changed & NETIF_F_HW_VLAN_CTAG_RX) {
		ret = hinic_set_rx_vlan_offload(nic_dev,
						!!(features &
						   NETIF_F_HW_VLAN_CTAG_RX));
		if (ret) {
			err = ret;
			failed_features |= NETIF_F_HW_VLAN_CTAG_RX;
		}
	}

	return err;
	if (err) {
		nic_dev->netdev->features = features ^ failed_features;
		return -EIO;
	}

	return 0;
}

/**
@@ -1008,8 +1057,6 @@ static int nic_dev_init(struct pci_dev *pdev)
		goto err_alloc_etherdev;
	}

	hinic_set_ethtool_ops(netdev);

	if (!HINIC_IS_VF(hwdev->hwif))
		netdev->netdev_ops = &hinic_netdev_ops;
	else
@@ -1032,6 +1079,8 @@ static int nic_dev_init(struct pci_dev *pdev)
	nic_dev->sriov_info.pdev = pdev;
	nic_dev->max_qps = num_qps;

	hinic_set_ethtool_ops(netdev);

	sema_init(&nic_dev->mgmt_lock, 1);

	tx_stats = &nic_dev->tx_stats;
@@ -1100,6 +1149,11 @@ static int nic_dev_init(struct pci_dev *pdev)
	if (err)
		goto err_set_features;

	/* enable pause and disable pfc by default */
	err = hinic_dcb_set_pfc(nic_dev->hwdev, 0, 0);
	if (err)
		goto err_set_pfc;

	SET_NETDEV_DEV(netdev, &pdev->dev);

	err = register_netdev(netdev);
@@ -1111,6 +1165,7 @@ static int nic_dev_init(struct pci_dev *pdev)
	return 0;

err_reg_netdev:
err_set_pfc:
err_set_features:
	hinic_hwdev_cb_unregister(nic_dev->hwdev,
				  HINIC_MGMT_MSG_CMD_LINK_STATUS);
Loading