net: hns3: support wake on lan for hns3
Subsystems (4)
cover net: hns3: support wake on lan for hns3
HNS3 (HiSilicon Network System 3) supports Wake-on-LAN, magic mode and magic security mode on each pf.
This patch supports the ethtool LAN wake-up configuration and query interfaces and debugfs query interfaces. It does not support the suspend resume interface because there is no corresponding application scenario.
Hao Lan (2):
net: hns3: support wake on lan configuration and query
net: hns3: support debugfs for wake on lan
drivers/net/ethernet/hisilicon/hns3/hnae3.h | 13 ++ .../hns3/hns3_common/hclge_comm_cmd.c | 1 + .../hns3/hns3_common/hclge_comm_cmd.h | 3 + .../ethernet/hisilicon/hns3/hns3_debugfs.c | 10 + .../ethernet/hisilicon/hns3/hns3_ethtool.c | 27 +++ .../hisilicon/hns3/hns3pf/hclge_cmd.h | 24 ++ .../hisilicon/hns3/hns3pf/hclge_debugfs.c | 62 ++++++ .../hisilicon/hns3/hns3pf/hclge_main.c | 206 ++++++++++++++++++ .../hisilicon/hns3/hns3pf/hclge_main.h | 10 + 9 files changed, 356 insertions(+)
Signature · 1 line
2.30.0
PATCH 1/2 net: hns3: support wake on lan configuration and query
Implement configuration and query WOL by ethtool and added the needed device commands and structures to hns3. Add it do not support suspend resume interface.
--- 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_ethtool.c | 27 +++ .../hisilicon/hns3/hns3pf/hclge_cmd.h | 26 +++ .../hisilicon/hns3/hns3pf/hclge_main.c | 204 ++++++++++++++++++ .../hisilicon/hns3/hns3pf/hclge_main.h | 10 + 7 files changed, 283 insertions(+)
drivers/net/ethernet/hisilicon/hns3/hnae3.h +12 -0
@@ -99,6 +99,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) \
@@ -167,6 +168,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 , };
@@ -560,6 +564,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);
@@ -759,6 +767,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
@@ -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
@@ -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_ethtool.c +27 -0
@@ -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) || !ops->get_wol) +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) || !ops->set_wol) +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 +26 -0
@@ -872,6 +872,32 @@ struct hclge_phy_reg_cmd {u8 rsv1[18 ]; }; +enum HCLGE_WOL_MODE { +HCLGE_WOL_PHY =BIT (0 ), +HCLGE_WOL_UNICAST =BIT (1 ), +HCLGE_WOL_MULTICAST =BIT (2 ), +HCLGE_WOL_BROADCAST =BIT (3 ), +HCLGE_WOL_ARP =BIT (4 ), +HCLGE_WOL_MAGIC =BIT (5 ), +HCLGE_WOL_MAGICSECURED =BIT (6 ), +HCLGE_WOL_FILTER =BIT (7 ), +HCLGE_WOL_DISABLE =0 , +}; + +#define HCLGE_SOPASS_MAX 6 + +struct hclge_wol_cfg_cmd { +__le32 wake_on_lan_mode; +u8 sopass[HCLGE_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 +204 -0
228 lines not on this page · raw message
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h +10 -0
@@ -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[HCLGE_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;
@@ -1141,4 +1149,6 @@ int hclge_dbg_dump_rst_info(struct hclge_dev *hdev, char *buf, int len);int hclge_push_vf_link_status (struct hclge_vport *vport);int hclge_enable_vport_vlan_filter (struct hclge_vport *vport,bool request_en);int hclge_mac_update_stats (struct hclge_dev *hdev); +int hclge_get_wol_supported_mode (struct hclge_dev *hdev,u32 *wol_supported); +int hclge_get_wol_cfg (struct hclge_dev *hdev,u32 *mode);#endif
Signature · 1 line
2.30.0
Re: [PATCH net-next 1/2] net: hns3: support wake on lan configuration and query
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h struct hclge_phy_reg_cmd { · line 885
Quoted 11 lines
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h +11
-0+enum HCLGE_WOL_MODE { +HCLGE_WOL_PHY =BIT (0 ), +HCLGE_WOL_UNICAST =BIT (1 ), +HCLGE_WOL_MULTICAST =BIT (2 ), +HCLGE_WOL_BROADCAST =BIT (3 ), +HCLGE_WOL_ARP =BIT (4 ), +HCLGE_WOL_MAGIC =BIT (5 ), +HCLGE_WOL_MAGICSECURED =BIT (6 ), +HCLGE_WOL_FILTER =BIT (7 ), +HCLGE_WOL_DISABLE =0 , +};
These are the exact same values as WAKE_PHY, WAKE_CAST etc. Since they are ABI, they will never change. So you may as well throw these away and just use the Linux values.
Quoted 28 lines
struct
hclge_hw;
inthclge_cmd_send(struct hclge_hw *hw, struct hclge_desc *desc, int num); enumhclge_comm_cmd_statushclge_cmd_mdio_write(structhclge_hw*hw,drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +17
-0@@ -11500,6 +11500,201 @@ static void hclge_uninit_rxd_adv_layout(struct hclge_dev *hdev)hclge_write_dev (&hdev->hw,HCLGE_RXD_ADV_LAYOUT_EN_REG ,0 ); } +static __u32 hclge_wol_mode_to_ethtool (u32 mode) +{ +__u32 ret =0 ; + +if (mode &HCLGE_WOL_PHY ) + ret |=WAKE_PHY ; + +if (mode &HCLGE_WOL_UNICAST ) + ret |=WAKE_UCAST ; + +if (mode &HCLGE_WOL_MULTICAST ) + ret |=WAKE_MCAST ; + +if (mode &HCLGE_WOL_BROADCAST ) + ret |=WAKE_BCAST ; + +if (mode &HCLGE_WOL_ARP )
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c static void hclge_uninit_rxd_adv_layout(struct hclge_dev *hdev) · line 11529
Quoted 10 lines
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +10
-0+ ret |=WAKE_ARP ; + +if (mode &HCLGE_WOL_MAGIC ) + ret |=WAKE_MAGIC ; + +if (mode &HCLGE_WOL_MAGICSECURED ) + ret |=WAKE_MAGICSECURE ; + +if (mode &HCLGE_WOL_FILTER ) + ret |=WAKE_FILTER ;
Once you throw away HCLGE_WOL_*, this function becomes much simpler.
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c static void hclge_uninit_rxd_adv_layout(struct hclge_dev *hdev) · line 11542
Quoted 13 lines
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +13
-0+ +return ret; +} + +static u32 hclge_wol_mode_from_ethtool (__u32 mode) +{ +u32 ret =HCLGE_WOL_DISABLE ; + +if (mode &WAKE_PHY ) + ret |=HCLGE_WOL_PHY ; + +if (mode &WAKE_UCAST ) + ret |=HCLGE_WOL_UNICAST ;
This one two.
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c static int hclge_reset_ae_dev(struct hnae3_ae_dev *ae_dev) · line 12278
Quoted 5 lines
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +1
-0@@ -12075,6 +12275,8 @@ static int hclge_reset_ae_dev(struct hnae3_ae_dev *ae_dev)hclge_init_rxd_adv_layout (hdev); + (void )hclge_update_wol (hdev);
Please avoid casts like this. If there is an error, you should not ignore it. If it cannot fail, make it a void function.
Andrew
Re: [PATCH net-next 1/2] net: hns3: support wake on lan configuration and query
Hi Andrew,
Thank you for reviewing our code. Thank you very much. You're right, such as WAKE_PHY, WAKE_CAST, these are implemented in the kernel, they are ABI, they will never change, we use it will directly simplify our code, your advice is very useful, thank you very much for your advice.
However, these interfaces serve as a buffer between our firmware and the linux community. Considering our interface expansion and evolution, we may add some private modes in the future. If the Linux community does not accept our private modes, we will not be able to carry out these work.
So please let us keep enum HCLGE_WOL_MODE, thank you.
Best regards,
Hao Lan
Quoted 86 lines · Andrew Lunn
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h struct hclge_phy_reg_cmd { · line 885
Quoted 11 lines
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h +11
-0+enum HCLGE_WOL_MODE { +HCLGE_WOL_PHY =BIT (0 ), +HCLGE_WOL_UNICAST =BIT (1 ), +HCLGE_WOL_MULTICAST =BIT (2 ), +HCLGE_WOL_BROADCAST =BIT (3 ), +HCLGE_WOL_ARP =BIT (4 ), +HCLGE_WOL_MAGIC =BIT (5 ), +HCLGE_WOL_MAGICSECURED =BIT (6 ), +HCLGE_WOL_FILTER =BIT (7 ), +HCLGE_WOL_DISABLE =0 , +};These are the exact same values as
WAKE_PHY,WAKE_CASTetc. Since they are ABI, they will never change. So you may as well throw these away and just use the Linux values.Quoted 28 lines
struct
hclge_hw;
inthclge_cmd_send(struct hclge_hw *hw, struct hclge_desc *desc, int num); enumhclge_comm_cmd_statushclge_cmd_mdio_write(structhclge_hw*hw,drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +17
-0@@ -11500,6 +11500,201 @@ static void hclge_uninit_rxd_adv_layout(struct hclge_dev *hdev)hclge_write_dev (&hdev->hw,HCLGE_RXD_ADV_LAYOUT_EN_REG ,0 ); } +static __u32 hclge_wol_mode_to_ethtool (u32 mode) +{ +__u32 ret =0 ; + +if (mode &HCLGE_WOL_PHY ) + ret |=WAKE_PHY ; + +if (mode &HCLGE_WOL_UNICAST ) + ret |=WAKE_UCAST ; + +if (mode &HCLGE_WOL_MULTICAST ) + ret |=WAKE_MCAST ; + +if (mode &HCLGE_WOL_BROADCAST ) + ret |=WAKE_BCAST ; + +if (mode &HCLGE_WOL_ARP )drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c static void hclge_uninit_rxd_adv_layout(struct hclge_dev *hdev) · line 11529
Quoted 10 lines
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +10
-0+ ret |=WAKE_ARP ; + +if (mode &HCLGE_WOL_MAGIC ) + ret |=WAKE_MAGIC ; + +if (mode &HCLGE_WOL_MAGICSECURED ) + ret |=WAKE_MAGICSECURE ; + +if (mode &HCLGE_WOL_FILTER ) + ret |=WAKE_FILTER ;Once you throw away HCLGE_WOL_*, this function becomes much simpler.
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c static void hclge_uninit_rxd_adv_layout(struct hclge_dev *hdev) · line 11542
Quoted 13 lines
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +13
-0+ +return ret; +} + +static u32 hclge_wol_mode_from_ethtool (__u32 mode) +{ +u32 ret =HCLGE_WOL_DISABLE ; + +if (mode &WAKE_PHY ) + ret |=HCLGE_WOL_PHY ; + +if (mode &WAKE_UCAST ) + ret |=HCLGE_WOL_UNICAST ;This one two.
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c static int hclge_reset_ae_dev(struct hnae3_ae_dev *ae_dev) · line 12278
Quoted 5 lines
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +1
-0@@ -12075,6 +12275,8 @@ static int hclge_reset_ae_dev(struct hnae3_ae_dev *ae_dev)hclge_init_rxd_adv_layout (hdev); + (void )hclge_update_wol (hdev);Please avoid casts like this. If there is an error, you should not ignore it. If it cannot fail, make it a void function.
Andrew
.
Re: [PATCH net-next 1/2] net: hns3: support wake on lan configuration and query
Quoted 9 lines · Hao Lan
Hi Andrew,
Thank you for reviewing our code. Thank you very much. You're right, such asWAKE_PHY,WAKE_CAST, these are implemented in the kernel, they are ABI, they will never change, we use it will directly simplify our code, your advice is very useful, thank you very much for your advice.
However, these interfaces serve as a buffer between our firmware and the linux community. Considering our interface expansion and evolution, we may add some private modes in the future.
You cannot add private WOL modes, since they will be unusable without ethtool support. And to add ethtool support, they need to be public. And to make them public, you just add more WAKE_ macros. Just make sure the new modes you add are well described, so other drivers can also implement them.
Andrew
PATCH 2/2 net: hns3: support debugfs for wake on lan
In reply to Hao LanImplement debugfs for wake on lan to hns3. The debugfs support verify the firmware wake on lan configuration.
--- drivers/net/ethernet/hisilicon/hns3/hnae3.h | 1 + .../ethernet/hisilicon/hns3/hns3_debugfs.c | 10 +++ .../hisilicon/hns3/hns3pf/hclge_debugfs.c | 62 +++++++++++++++++++ 3 files changed, 73 insertions(+)
drivers/net/ethernet/hisilicon/hns3/hnae3.h +1 -0
@@ -321,6 +321,7 @@ enum hnae3_dbg_cmd {HNAE3_DBG_CMD_UMV_INFO ,HNAE3_DBG_CMD_PAGE_POOL_INFO ,HNAE3_DBG_CMD_COAL_INFO , +HNAE3_DBG_CMD_WOL_INFO , HNAE3_DBG_CMD_UNKNOWN, };
drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c +10 -0
@@ -357,6 +357,13 @@ static struct hns3_dbg_cmd_info hns3_dbg_cmd[] = { .buf_len = HNS3_DBG_READ_LEN_1MB, .init = hns3_dbg_common_file_init, }, + { + .name = "wol_info", + .cmd = HNAE3_DBG_CMD_WOL_INFO, + .dentry = HNS3_DBG_DENTRY_COMMON, + .buf_len = HNS3_DBG_READ_LEN, + .init = hns3_dbg_common_file_init, + }, };static struct hns3_dbg_cap_info hns3_dbg_cap[] = {
@@ -408,6 +415,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/hns3pf/hclge_debugfs.c +62 -0
74 lines not on this page · raw message
Signature · 1 line
2.30.0
Re: [PATCH net-next 2/2] net: hns3: support debugfs for wake on lan
Quoted 2 lines · Hao Lan
Implement debugfs for wake on lan to hns3. The debugfs support verify the firmware wake on lan configuration.
Is this actually needed, now you have verified the firmware? I can see it being a useful development tool, but now the feature is finished, the firmware is bug free, it is of no real use. Everybody will just use ethtool.
Andrew