Commit 0f032f93 authored by Hao Chen's avatar Hao Chen Committed by David S. Miller
Browse files

net: hns3: add support to query and set lane number by ethtool



When serdes lane support setting 25Gb/s or 50Gb/s speed and user wants to
set port speed as 50Gb/s, it can be setted as one 50Gb/s serdes lane or
two 25Gb/s serdes lanes.

So, this patch adds support to query and set lane number by ethtool
to satisfy this scenario.

Signed-off-by: default avatarHao Chen <chenhao418@huawei.com>
Signed-off-by: default avatarGuangbin Huang <huangguangbin2@huawei.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 2cb343b9
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -98,6 +98,7 @@ enum HNAE3_DEV_CAP_BITS {
	HNAE3_DEV_SUPPORT_MC_MAC_MNG_B,
	HNAE3_DEV_SUPPORT_CQ_B,
	HNAE3_DEV_SUPPORT_FEC_STATS_B,
	HNAE3_DEV_SUPPORT_LANE_NUM_B,
};

#define hnae3_ae_dev_fd_supported(ae_dev) \
@@ -163,6 +164,9 @@ enum HNAE3_DEV_CAP_BITS {
#define hnae3_ae_dev_fec_stats_supported(ae_dev) \
	test_bit(HNAE3_DEV_SUPPORT_FEC_STATS_B, (ae_dev)->caps)

#define hnae3_ae_dev_lane_num_supported(ae_dev) \
	test_bit(HNAE3_DEV_SUPPORT_LANE_NUM_B, (ae_dev)->caps)

enum HNAE3_PF_CAP_BITS {
	HNAE3_PF_SUPPORT_VLAN_FLTR_MDF_B = 0,
};
@@ -572,10 +576,11 @@ struct hnae3_ae_ops {
	void (*client_stop)(struct hnae3_handle *handle);
	int (*get_status)(struct hnae3_handle *handle);
	void (*get_ksettings_an_result)(struct hnae3_handle *handle,
					u8 *auto_neg, u32 *speed, u8 *duplex);
					u8 *auto_neg, u32 *speed, u8 *duplex,
					u32 *lane_num);

	int (*cfg_mac_speed_dup_h)(struct hnae3_handle *handle, int speed,
				   u8 duplex);
				   u8 duplex, u8 lane_num);

	void (*get_media_type)(struct hnae3_handle *handle, u8 *media_type,
			       u8 *module_type);
+1 −0
Original line number Diff line number Diff line
@@ -154,6 +154,7 @@ static const struct hclge_comm_caps_bit_map hclge_pf_cmd_caps[] = {
	{HCLGE_COMM_CAP_GRO_B, HNAE3_DEV_SUPPORT_GRO_B},
	{HCLGE_COMM_CAP_FD_B, HNAE3_DEV_SUPPORT_FD_B},
	{HCLGE_COMM_CAP_FEC_STATS_B, HNAE3_DEV_SUPPORT_FEC_STATS_B},
	{HCLGE_COMM_CAP_LANE_NUM_B, HNAE3_DEV_SUPPORT_LANE_NUM_B},
};

static const struct hclge_comm_caps_bit_map hclge_vf_cmd_caps[] = {
+1 −0
Original line number Diff line number Diff line
@@ -344,6 +344,7 @@ enum HCLGE_COMM_CAP_BITS {
	HCLGE_COMM_CAP_GRO_B = 20,
	HCLGE_COMM_CAP_FD_B = 21,
	HCLGE_COMM_CAP_FEC_STATS_B = 25,
	HCLGE_COMM_CAP_LANE_NUM_B = 27,
};

enum HCLGE_COMM_API_CAP_BITS {
+3 −0
Original line number Diff line number Diff line
@@ -405,6 +405,9 @@ static struct hns3_dbg_cap_info hns3_dbg_cap[] = {
	}, {
		.name = "support FEC statistics",
		.cap_bit = HNAE3_DEV_SUPPORT_FEC_STATS_B,
	}, {
		.name = "support lane num",
		.cap_bit = HNAE3_DEV_SUPPORT_LANE_NUM_B,
	}
};

+13 −6
Original line number Diff line number Diff line
@@ -712,7 +712,8 @@ static void hns3_get_ksettings(struct hnae3_handle *h,
		ops->get_ksettings_an_result(h,
					     &cmd->base.autoneg,
					     &cmd->base.speed,
					     &cmd->base.duplex);
					     &cmd->base.duplex,
					     &cmd->lanes);

	/* 2.get link mode */
	if (ops->get_link_mode)
@@ -794,6 +795,7 @@ static int hns3_check_ksettings_param(const struct net_device *netdev,
	const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
	u8 module_type = HNAE3_MODULE_TYPE_UNKNOWN;
	u8 media_type = HNAE3_MEDIA_TYPE_UNKNOWN;
	u32 lane_num;
	u8 autoneg;
	u32 speed;
	u8 duplex;
@@ -806,9 +808,9 @@ static int hns3_check_ksettings_param(const struct net_device *netdev,
		return 0;

	if (ops->get_ksettings_an_result) {
		ops->get_ksettings_an_result(handle, &autoneg, &speed, &duplex);
		ops->get_ksettings_an_result(handle, &autoneg, &speed, &duplex, &lane_num);
		if (cmd->base.autoneg == autoneg && cmd->base.speed == speed &&
		    cmd->base.duplex == duplex)
		    cmd->base.duplex == duplex && cmd->lanes == lane_num)
			return 0;
	}

@@ -845,10 +847,14 @@ static int hns3_set_link_ksettings(struct net_device *netdev,
	if (cmd->base.speed == SPEED_1000 && cmd->base.duplex == DUPLEX_HALF)
		return -EINVAL;

	if (cmd->lanes && !hnae3_ae_dev_lane_num_supported(ae_dev))
		return -EOPNOTSUPP;

	netif_dbg(handle, drv, netdev,
		  "set link(%s): autoneg=%u, speed=%u, duplex=%u\n",
		  "set link(%s): autoneg=%u, speed=%u, duplex=%u, lanes=%u\n",
		  netdev->phydev ? "phy" : "mac",
		  cmd->base.autoneg, cmd->base.speed, cmd->base.duplex);
		  cmd->base.autoneg, cmd->base.speed, cmd->base.duplex,
		  cmd->lanes);

	/* Only support ksettings_set for netdev with phy attached for now */
	if (netdev->phydev) {
@@ -886,7 +892,7 @@ static int hns3_set_link_ksettings(struct net_device *netdev,

	if (ops->cfg_mac_speed_dup_h)
		ret = ops->cfg_mac_speed_dup_h(handle, cmd->base.speed,
					       cmd->base.duplex);
					       cmd->base.duplex, (u8)(cmd->lanes));

	return ret;
}
@@ -2067,6 +2073,7 @@ static const struct ethtool_ops hns3vf_ethtool_ops = {
static const struct ethtool_ops hns3_ethtool_ops = {
	.supported_coalesce_params = HNS3_ETHTOOL_COALESCE,
	.supported_ring_params = HNS3_ETHTOOL_RING,
	.cap_link_lanes_supported = true,
	.self_test = hns3_self_test,
	.get_drvinfo = hns3_get_drvinfo,
	.get_link = hns3_get_link,
Loading