Skip to contentSkip to conversation

net: hns3: support wake on lan configuration and query

PATCH Superseded Hao Lan 3 participants 4 messages Mar 10, 2023 – Mar 13, 2023

Subsystems (4)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Hao Lan

author
#0 lore raw

PATCH v3 1/1 net: hns3: support wake on lan configuration and query

The HNS3 driver supports Wake-on-LAN, which can wake up the server from power off state to power on state by magic packet or magic security packet.

ChangeLog:
v1->v2:
Deleted the debugfs function that overlaps with the ethtool function from suggestion of Andrew Lunn.

v2->v3:
Return the wol configuration stored in driver,
suggested by Alexander H Duyck.

---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h   |  12 ++
 .../hns3/hns3_common/hclge_comm_cmd.c         |   1 +
 .../hns3/hns3_common/hclge_comm_cmd.h         |   3 +
 .../ethernet/hisilicon/hns3/hns3_debugfs.c    |   3 +
 .../ethernet/hisilicon/hns3/hns3_ethtool.c    |  27 ++++
 .../hisilicon/hns3/hns3pf/hclge_cmd.h         |  12 ++
 .../hisilicon/hns3/hns3pf/hclge_main.c        | 126 ++++++++++++++++++
 .../hisilicon/hns3/hns3pf/hclge_main.h        |   8 ++
 8 files changed, 192 insertions(+)
drivers/net/ethernet/hisilicon/hns3/hnae3.h +12 -0
index 40f4306449eb..9c9c72dc57e0 100644
@@ -100,6 +100,7 @@ enum HNAE3_DEV_CAP_BITS {
 	HNAE3_DEV_SUPPORT_CQ_B,
 	HNAE3_DEV_SUPPORT_FEC_STATS_B,
 	HNAE3_DEV_SUPPORT_LANE_NUM_B,
+	HNAE3_DEV_SUPPORT_WOL_B,
 };
 
 #define hnae3_ae_dev_fd_supported(ae_dev) \
@@ -168,6 +169,9 @@ enum HNAE3_DEV_CAP_BITS {
 #define hnae3_ae_dev_lane_num_supported(ae_dev) \
 	test_bit(HNAE3_DEV_SUPPORT_LANE_NUM_B, (ae_dev)->caps)
 
+#define hnae3_ae_dev_wol_supported(ae_dev) \
+	test_bit(HNAE3_DEV_SUPPORT_WOL_B, (ae_dev)->caps)
+
 enum HNAE3_PF_CAP_BITS {
 	HNAE3_PF_SUPPORT_VLAN_FLTR_MDF_B = 0,
 };
@@ -561,6 +565,10 @@ struct hnae3_ae_dev {
  *   Get phc info
  * clean_vf_config
  *   Clean residual vf info after disable sriov
+ * get_wol
+ *   Get wake on lan info
+ * set_wol
+ *   Config wake on lan
  */
 struct hnae3_ae_ops {
 	int (*init_ae_dev)(struct hnae3_ae_dev *ae_dev);
@@ -760,6 +768,10 @@ struct hnae3_ae_ops {
 	void (*clean_vf_config)(struct hnae3_ae_dev *ae_dev, int num_vfs);
 	int (*get_dscp_prio)(struct hnae3_handle *handle, u8 dscp,
 			     u8 *tc_map_mode, u8 *priority);
+	void (*get_wol)(struct hnae3_handle *handle,
+			struct ethtool_wolinfo *wol);
+	int (*set_wol)(struct hnae3_handle *handle,
+		       struct ethtool_wolinfo *wol);
 };
 
 struct hnae3_dcb_ops {
drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_cmd.c +1 -0
index f671a63cecde..cbbab5b2b402 100644
@@ -155,6 +155,7 @@ static const struct hclge_comm_caps_bit_map hclge_pf_cmd_caps[] = {
 	{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},
+	{HCLGE_COMM_CAP_WOL_B, HNAE3_DEV_SUPPORT_WOL_B},
 };
 
 static const struct hclge_comm_caps_bit_map hclge_vf_cmd_caps[] = {
drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_cmd.h +3 -0
index b1f9383b418f..de72ecbfd5ad 100644
@@ -294,6 +294,8 @@ enum hclge_opcode_type {
 	HCLGE_PPP_CMD0_INT_CMD		= 0x2100,
 	HCLGE_PPP_CMD1_INT_CMD		= 0x2101,
 	HCLGE_MAC_ETHERTYPE_IDX_RD      = 0x2105,
+	HCLGE_OPC_WOL_GET_SUPPORTED_MODE	= 0x2201,
+	HCLGE_OPC_WOL_CFG		= 0x2202,
 	HCLGE_NCSI_INT_EN		= 0x2401,
 
 	/* ROH MAC commands */
@@ -345,6 +347,7 @@ enum HCLGE_COMM_CAP_BITS {
 	HCLGE_COMM_CAP_FD_B = 21,
 	HCLGE_COMM_CAP_FEC_STATS_B = 25,
 	HCLGE_COMM_CAP_LANE_NUM_B = 27,
+	HCLGE_COMM_CAP_WOL_B = 28,
 };
 
 enum HCLGE_COMM_API_CAP_BITS {
drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c +3 -0
index 66feb23f7b7b..4c3e90a1c4d0 100644
@@ -408,6 +408,9 @@ static struct hns3_dbg_cap_info hns3_dbg_cap[] = {
 	}, {
 		.name = "support lane num",
 		.cap_bit = HNAE3_DEV_SUPPORT_LANE_NUM_B,
+	}, {
+		.name = "support wake on lan",
+		.cap_bit = HNAE3_DEV_SUPPORT_WOL_B,
 	}
 };
 
drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c +27 -0
index 55306fe8a540..10de2b4c401b 100644
@@ -2063,6 +2063,31 @@ static int hns3_get_link_ext_state(struct net_device *netdev,
 	return -ENODATA;
 }
 
+static void hns3_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
+{
+	struct hnae3_handle *handle = hns3_get_handle(netdev);
+	struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
+	const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
+
+	if (!hnae3_ae_dev_wol_supported(ae_dev))
+		return;
+
+	ops->get_wol(handle, wol);
+}
+
+static int hns3_set_wol(struct net_device *netdev,
+			struct ethtool_wolinfo *wol)
+{
+	struct hnae3_handle *handle = hns3_get_handle(netdev);
+	struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
+	const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
+
+	if (!hnae3_ae_dev_wol_supported(ae_dev))
+		return -EOPNOTSUPP;
+
+	return ops->set_wol(handle, wol);
+}
+
 static const struct ethtool_ops hns3vf_ethtool_ops = {
 	.supported_coalesce_params = HNS3_ETHTOOL_COALESCE,
 	.supported_ring_params = HNS3_ETHTOOL_RING,
@@ -2139,6 +2164,8 @@ static const struct ethtool_ops hns3_ethtool_ops = {
 	.set_tunable = hns3_set_tunable,
 	.reset = hns3_set_reset,
 	.get_link_ext_state = hns3_get_link_ext_state,
+	.get_wol = hns3_get_wol,
+	.set_wol = hns3_set_wol,
 };
 
 void hns3_ethtool_set_ops(struct net_device *netdev)
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h +12 -0
index 43cada51d8cb..91c173f40701 100644
@@ -872,6 +872,18 @@ struct hclge_phy_reg_cmd {
 	u8 rsv1[18];
 };
 
+struct hclge_wol_cfg_cmd {
+	__le32 wake_on_lan_mode;
+	u8 sopass[SOPASS_MAX];
+	u8 sopass_size;
+	u8 rsv[13];
+};
+
+struct hclge_query_wol_supported_cmd {
+	__le32 supported_wake_mode;
+	u8 rsv[20];
+};
+
 struct hclge_hw;
 int hclge_cmd_send(struct hclge_hw *hw, struct hclge_desc *desc, int num);
 enum hclge_comm_cmd_status hclge_cmd_mdio_write(struct hclge_hw *hw,
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +126 -0

150 lines not on this page · raw message

drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h +8 -0
index 13f23d606e77..81aa6b0facf5 100644
@@ -249,6 +249,13 @@ enum HCLGE_MAC_DUPLEX {
 #define QUERY_SFP_SPEED		0
 #define QUERY_ACTIVE_SPEED	1
 
+struct hclge_wol_info {
+	u32 wol_support_mode; /* store the wake on lan info */
+	u32 wol_current_mode;
+	u8 wol_sopass[SOPASS_MAX];
+	u8 wol_sopass_size;
+};
+
 struct hclge_mac {
 	u8 mac_id;
 	u8 phy_addr;
@@ -268,6 +275,7 @@ struct hclge_mac {
 	u32 user_fec_mode;
 	u32 fec_ability;
 	int link;	/* store the link status of mac & phy (if phy exists) */
+	struct hclge_wol_info wol;
 	struct phy_device *phydev;
 	struct mii_bus *mdio_bus;
 	phy_interface_t phy_if;
Signature · 1 line
2.30.0
Reviewed-by on v3 1/1
#1 lore raw
Quoted 9 lines · Hao Lan

The HNS3 driver supports Wake-on-LAN, which can wake up the server from power off state to power on state by magic packet or magic security packet.

ChangeLog:
v1->v2:
Deleted the debugfs function that overlaps with the ethtool function from suggestion of Andrew Lunn.

Quoted 5 lines

v2->v3:
Return the wol configuration stored in driver,
suggested by Alexander H Duyck.

...

drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c static int hns3_get_link_ext_state(struct net_device *netdev, · line 2070

Quoted 13 lines
drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c +5 -0
index 55306fe8a540..10de2b4c401b 100644
@@ -2063,6 +2063,31 @@ static int hns3_get_link_ext_state(struct net_device *netdev,
 	return -ENODATA;
 }
 
+static void hns3_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
+{
+	struct hnae3_handle *handle = hns3_get_handle(netdev);
+	struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
+	const struct hnae3_ae_ops *ops = handle->ae_algo->ops;

nit: the local variable declarations could be reverse xmas tree

     - longest line to shortest line. One option being:

	const struct hnae3_ae_ops *ops;
	struct hnae3_handle *handle;
	struct hnae3_ae_dev *ae_dev;

	handle = hns3_get_handle(netdev);
	ae_dev = pci_get_drvdata(handle->pdev);
	ops = handle->ae_algo->ops;

Likewise elsewhere in this patch.

author
#2 lore raw

Thanks for your suggestion. Generally I follow the reverse xmas tree style for readability. But for this case, whether it looks a bit bloated ?

Quoted 48 lines · Simon Horman

Simon Horman <[email protected]>

Quoted 9 lines · Hao Lan

The HNS3 driver supports Wake-on-LAN, which can wake up the server from power off state to power on state by magic packet or magic security packet.

ChangeLog:
v1->v2:
Deleted the debugfs function that overlaps with the ethtool function from suggestion of Andrew Lunn.

Quoted 5 lines

v2->v3:
Return the wol configuration stored in driver,
suggested by Alexander H Duyck.

...

drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c static int hns3_get_link_ext_state(struct net_device *netdev, · line 2070

Quoted 13 lines
drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c +5 -0
index 55306fe8a540..10de2b4c401b 100644
@@ -2063,6 +2063,31 @@ static int hns3_get_link_ext_state(struct net_device *netdev,
 	return -ENODATA;
 }
 
+static void hns3_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
+{
+	struct hnae3_handle *handle = hns3_get_handle(netdev);
+	struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
+	const struct hnae3_ae_ops *ops = handle->ae_algo->ops;

nit: the local variable declarations could be reverse xmas tree

     - longest line to shortest line. One option being:

	const struct hnae3_ae_ops *ops;
	struct hnae3_handle *handle;
	struct hnae3_ae_dev *ae_dev;

	handle = hns3_get_handle(netdev);
	ae_dev = pci_get_drvdata(handle->pdev);
	ops = handle->ae_algo->ops;

Likewise elsewhere in this patch.
.

maintainer
#3 lore raw
Quoted 2 lines · On Mon, 13 Mar 2023 16:05:55 +0800 Hao Lan wrote:

Thanks for your suggestion. Generally I follow the reverse xmas tree style for readability. But for this case, whether it looks a bit bloated ?

It only appears so because the driver has too many indirection layers. Add a helper to go from netdev to the local struct.

Reminder: please don't top post and trim your replies.