Skip to content

Commit aa5fbf0

Browse files
committed
Merge branch 'hns3-ethtool-ksettings'
Lipeng says: ==================== net: hns3: support set_link_ksettings and for nway_reset ethtool command This patch-set adds support for set_link_ksettings && for nway_resets ethtool command and fixes some related ethtool bugs. 1, patch[4/6] adds support for ethtool_ops.set_link_ksettings. 2, patch[5/6] adds support ethtool_ops.for nway_reset. 3, patch[1/6,2/6,3/6,6/6] fix some bugs for getting port information by ethtool command(ethtool ethx). ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 739c596 + 439adf8 commit aa5fbf0

File tree

2 files changed

+59
-22
lines changed

2 files changed

+59
-22
lines changed

drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
#include "hclge_main.h"
1515
#include "hclge_mdio.h"
1616

17+
#define HCLGE_PHY_SUPPORTED_FEATURES (SUPPORTED_Autoneg | \
18+
SUPPORTED_TP | \
19+
SUPPORTED_Pause | \
20+
PHY_10BT_FEATURES | \
21+
PHY_100BT_FEATURES | \
22+
PHY_1000BT_FEATURES)
23+
1724
enum hclge_mdio_c22_op_seq {
1825
HCLGE_MDIO_C22_WRITE = 1,
1926
HCLGE_MDIO_C22_READ = 2
@@ -195,6 +202,9 @@ int hclge_mac_start_phy(struct hclge_dev *hdev)
195202
return ret;
196203
}
197204

205+
phydev->supported &= HCLGE_PHY_SUPPORTED_FEATURES;
206+
phydev->advertising = phydev->supported;
207+
198208
phy_start(phydev);
199209

200210
return 0;

drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <linux/etherdevice.h>
1111
#include <linux/string.h>
12+
#include <linux/phy.h>
1213

1314
#include "hns3_enet.h"
1415

@@ -358,17 +359,12 @@ static void hns3_driv_to_eth_caps(u32 caps, struct ethtool_link_ksettings *cmd,
358359
if (!(caps & hns3_lm_map[i].hns3_link_mode))
359360
continue;
360361

361-
if (is_advertised) {
362-
ethtool_link_ksettings_zero_link_mode(cmd,
363-
advertising);
362+
if (is_advertised)
364363
__set_bit(hns3_lm_map[i].ethtool_link_mode,
365364
cmd->link_modes.advertising);
366-
} else {
367-
ethtool_link_ksettings_zero_link_mode(cmd,
368-
supported);
365+
else
369366
__set_bit(hns3_lm_map[i].ethtool_link_mode,
370367
cmd->link_modes.supported);
371-
}
372368
}
373369
}
374370

@@ -571,26 +567,25 @@ static int hns3_get_link_ksettings(struct net_device *netdev,
571567
u32 advertised_caps;
572568
u8 media_type = HNAE3_MEDIA_TYPE_UNKNOWN;
573569
u8 link_stat;
574-
u8 auto_neg;
575-
u8 duplex;
576-
u32 speed;
577570

578571
if (!h->ae_algo || !h->ae_algo->ops)
579572
return -EOPNOTSUPP;
580573

581574
/* 1.auto_neg & speed & duplex from cmd */
582-
if (h->ae_algo->ops->get_ksettings_an_result) {
583-
h->ae_algo->ops->get_ksettings_an_result(h, &auto_neg,
584-
&speed, &duplex);
585-
cmd->base.autoneg = auto_neg;
586-
cmd->base.speed = speed;
587-
cmd->base.duplex = duplex;
588-
589-
link_stat = hns3_get_link(netdev);
590-
if (!link_stat) {
591-
cmd->base.speed = (u32)SPEED_UNKNOWN;
592-
cmd->base.duplex = DUPLEX_UNKNOWN;
593-
}
575+
if (netdev->phydev)
576+
phy_ethtool_ksettings_get(netdev->phydev, cmd);
577+
else if (h->ae_algo->ops->get_ksettings_an_result)
578+
h->ae_algo->ops->get_ksettings_an_result(h,
579+
&cmd->base.autoneg,
580+
&cmd->base.speed,
581+
&cmd->base.duplex);
582+
else
583+
return -EOPNOTSUPP;
584+
585+
link_stat = hns3_get_link(netdev);
586+
if (!link_stat) {
587+
cmd->base.speed = SPEED_UNKNOWN;
588+
cmd->base.duplex = DUPLEX_UNKNOWN;
594589
}
595590

596591
/* 2.media_type get from bios parameter block */
@@ -640,6 +635,9 @@ static int hns3_get_link_ksettings(struct net_device *netdev,
640635
break;
641636
}
642637

638+
if (!cmd->base.autoneg)
639+
advertised_caps &= ~HNS3_LM_AUTONEG_BIT;
640+
643641
/* now, map driver link modes to ethtool link modes */
644642
hns3_driv_to_eth_caps(supported_caps, cmd, false);
645643
hns3_driv_to_eth_caps(advertised_caps, cmd, true);
@@ -655,6 +653,16 @@ static int hns3_get_link_ksettings(struct net_device *netdev,
655653
return 0;
656654
}
657655

656+
static int hns3_set_link_ksettings(struct net_device *netdev,
657+
const struct ethtool_link_ksettings *cmd)
658+
{
659+
/* Only support ksettings_set for netdev with phy attached for now */
660+
if (netdev->phydev)
661+
return phy_ethtool_ksettings_set(netdev->phydev, cmd);
662+
663+
return -EOPNOTSUPP;
664+
}
665+
658666
static u32 hns3_get_rss_key_size(struct net_device *netdev)
659667
{
660668
struct hnae3_handle *h = hns3_get_handle(netdev);
@@ -824,6 +832,23 @@ static int hns3_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
824832
}
825833
}
826834

835+
static int hns3_nway_reset(struct net_device *netdev)
836+
{
837+
struct phy_device *phy = netdev->phydev;
838+
839+
if (!netif_running(netdev))
840+
return 0;
841+
842+
/* Only support nway_reset for netdev with phy attached for now */
843+
if (!phy)
844+
return -EOPNOTSUPP;
845+
846+
if (phy->autoneg != AUTONEG_ENABLE)
847+
return -EINVAL;
848+
849+
return genphy_restart_aneg(phy);
850+
}
851+
827852
static const struct ethtool_ops hns3_ethtool_ops = {
828853
.self_test = hns3_self_test,
829854
.get_drvinfo = hns3_get_drvinfo,
@@ -841,6 +866,8 @@ static const struct ethtool_ops hns3_ethtool_ops = {
841866
.get_rxfh = hns3_get_rss,
842867
.set_rxfh = hns3_set_rss,
843868
.get_link_ksettings = hns3_get_link_ksettings,
869+
.set_link_ksettings = hns3_set_link_ksettings,
870+
.nway_reset = hns3_nway_reset,
844871
};
845872

846873
void hns3_ethtool_set_ops(struct net_device *netdev)

0 commit comments

Comments
 (0)