Commit 62aede9f authored by Tian Jiang's avatar Tian Jiang Committed by Jiantao Xiao
Browse files

net: hns3: add support customized exception handling interfaces.

driver inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I6QRKC


CVE: NA

----------------------------------------------------------------------

Establish a framework to support customization requirement. Provides
interfaces to register special processing functions. When the system
is reset due to an abnormal interrupt, the registered handler is
called first.

Signed-off-by: default avatarTian Jiang <jiangtian6@h-partners.com>
Signed-off-by: default avatarshaojijie <shaojijie@huawei.com>
Signed-off-by: default avatarJiantao Xiao <xiaojiantao1@h-partners.com>
parent ae344b95
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -12,6 +12,7 @@ obj-$(CONFIG_HNS3) += hnae3.o


obj-$(CONFIG_HNS3_ENET) += hns3.o
obj-$(CONFIG_HNS3_ENET) += hns3.o
hns3-objs = hns3_enet.o hns3_ethtool.o hns3_debugfs.o
hns3-objs = hns3_enet.o hns3_ethtool.o hns3_debugfs.o
hns3-objs += hns3_ext.o


hns3-$(CONFIG_HNS3_DCB) += hns3_dcbnl.o
hns3-$(CONFIG_HNS3_DCB) += hns3_dcbnl.o


@@ -24,6 +25,6 @@ obj-$(CONFIG_HNS3_HCLGE) += hclge.o
hclge-objs = hns3pf/hclge_main.o hns3pf/hclge_mdio.o hns3pf/hclge_tm.o hns3pf/hclge_sysfs.o \
hclge-objs = hns3pf/hclge_main.o hns3pf/hclge_mdio.o hns3pf/hclge_tm.o hns3pf/hclge_sysfs.o \
		hns3pf/hclge_mbx.o hns3pf/hclge_err.o  hns3pf/hclge_debugfs.o hns3pf/hclge_ptp.o hns3pf/hclge_devlink.o \
		hns3pf/hclge_mbx.o hns3pf/hclge_err.o  hns3pf/hclge_debugfs.o hns3pf/hclge_ptp.o hns3pf/hclge_devlink.o \
		hns3_common/hclge_comm_cmd.o hns3_common/hclge_comm_rss.o hns3_common/hclge_comm_tqp_stats.o
		hns3_common/hclge_comm_cmd.o hns3_common/hclge_comm_rss.o hns3_common/hclge_comm_tqp_stats.o

hclge-objs += hns3pf/hclge_ext.o


hclge-$(CONFIG_HNS3_DCB) += hns3pf/hclge_dcb.o
hclge-$(CONFIG_HNS3_DCB) += hns3pf/hclge_dcb.o
+2 −0
Original line number Original line Diff line number Diff line
@@ -785,6 +785,8 @@ struct hnae3_ae_ops {
			struct ethtool_wolinfo *wol);
			struct ethtool_wolinfo *wol);
	int (*set_wol)(struct hnae3_handle *handle,
	int (*set_wol)(struct hnae3_handle *handle,
		       struct ethtool_wolinfo *wol);
		       struct ethtool_wolinfo *wol);
	int (*priv_ops)(struct hnae3_handle *handle, int opcode,
			void *data, size_t length);
};
};


struct hnae3_dcb_ops {
struct hnae3_dcb_ops {
+32 −0
Original line number Original line Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0+ */
// Copyright (c) 2023 Hisilicon Limited.

#ifndef __HNAE3_EXT_H
#define __HNAE3_EXT_H

enum hnae3_event_type_custom {
	HNAE3_VF_RESET_CUSTOM,
	HNAE3_VF_FUNC_RESET_CUSTOM,
	HNAE3_VF_PF_FUNC_RESET_CUSTOM,
	HNAE3_VF_FULL_RESET_CUSTOM,
	HNAE3_FLR_RESET_CUSTOM,
	HNAE3_FUNC_RESET_CUSTOM,
	HNAE3_GLOBAL_RESET_CUSTOM,
	HNAE3_IMP_RESET_CUSTOM,
	HNAE3_UNKNOWN_RESET_CUSTOM,
	HNAE3_NONE_RESET_CUSTOM,
	HNAE3_PORT_FAULT,
	HNAE3_RESET_DONE_CUSTOM,
	HNAE3_FUNC_RESET_FAIL_CUSTOM,
	HNAE3_GLOBAL_RESET_FAIL_CUSTOM,
	HNAE3_IMP_RESET_FAIL_CUSTOM,
	HNAE3_PPU_POISON_CUSTOM,
	HNAE3_IMP_RD_POISON_CUSTOM,
	HNAE3_INVALID_EVENT_CUSTOM,
};

enum hnae3_ext_opcode {
	HNAE3_EXT_OPC_RESET,
	HNAE3_EXT_OPC_EVENT_CALLBACK,
};
#endif
+6 −1
Original line number Original line Diff line number Diff line
@@ -24,6 +24,7 @@
#include <net/geneve.h>
#include <net/geneve.h>


#include "hnae3.h"
#include "hnae3.h"
#include "hnae3_ext.h"
#include "hns3_enet.h"
#include "hns3_enet.h"
/* All hns3 tracepoints are defined by the include below, which
/* All hns3 tracepoints are defined by the include below, which
 * must be included exactly once across the whole kernel with
 * must be included exactly once across the whole kernel with
@@ -6002,12 +6003,16 @@ static void hns3_process_hw_error(struct hnae3_handle *handle,
		if (hns3_hw_err[i].type == type) {
		if (hns3_hw_err[i].type == type) {
			dev_err(&handle->pdev->dev, "Detected %s!\n",
			dev_err(&handle->pdev->dev, "Detected %s!\n",
				hns3_hw_err[i].msg);
				hns3_hw_err[i].msg);
			if (handle->ae_algo->ops->priv_ops)
				handle->ae_algo->ops->priv_ops(handle,
					HNAE3_EXT_OPC_EVENT_CALLBACK, &type,
					sizeof(type));
			break;
			break;
		}
		}
	}
	}
}
}


static const struct hnae3_client_ops client_ops = {
const struct hnae3_client_ops client_ops = {
	.init_instance = hns3_client_init,
	.init_instance = hns3_client_init,
	.uninit_instance = hns3_client_uninit,
	.uninit_instance = hns3_client_uninit,
	.link_status_change = hns3_link_status_change,
	.link_status_change = hns3_link_status_change,
+75 −0
Original line number Original line Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0+
// Copyright (c) 2023 Hisilicon Limited.

#include "hns3_ext.h"

int nic_netdev_match_check(struct net_device *ndev)
{
#define HNS3_DRIVER_NAME_LEN 5

	struct ethtool_drvinfo drv_info;
	struct hnae3_handle *h;

	if (!ndev || !ndev->ethtool_ops ||
	    !ndev->ethtool_ops->get_drvinfo)
		return -EINVAL;

	ndev->ethtool_ops->get_drvinfo(ndev, &drv_info);

	if (strncmp(drv_info.driver, "hns3", HNS3_DRIVER_NAME_LEN))
		return -EINVAL;

	h = hns3_get_handle(ndev);
	if (h->flags & HNAE3_SUPPORT_VF)
		return -EINVAL;

	return 0;
}
EXPORT_SYMBOL(nic_netdev_match_check);

static int nic_invoke_pri_ops(struct net_device *ndev, int opcode,
			      void *data, size_t length)

{
	struct hnae3_handle *h;
	int ret;

	if ((!data && length) || (data && !length)) {
		netdev_err(ndev, "failed to check data and length");
		return -EINVAL;
	}

	if (nic_netdev_match_check(ndev))
		return -ENODEV;

	h = hns3_get_handle(ndev);
	if (!h->ae_algo->ops->priv_ops)
		return -EOPNOTSUPP;

	ret = h->ae_algo->ops->priv_ops(h, opcode, data, length);
	if (ret)
		netdev_err(ndev,
			   "failed to invoke pri ops, opcode = %#x, ret = %d\n",
			   opcode, ret);

	return ret;
}

void nic_chip_recover_handler(struct net_device *ndev,
			      enum hnae3_event_type_custom event_t)
{
	dev_info(&ndev->dev, "reset type is %d!!\n", event_t);

	if (event_t == HNAE3_PPU_POISON_CUSTOM)
		event_t = HNAE3_FUNC_RESET_CUSTOM;

	if (event_t != HNAE3_FUNC_RESET_CUSTOM &&
	    event_t != HNAE3_GLOBAL_RESET_CUSTOM &&
	    event_t != HNAE3_IMP_RESET_CUSTOM) {
		dev_err(&ndev->dev, "reset type err!!\n");
		return;
	}

	nic_invoke_pri_ops(ndev, HNAE3_EXT_OPC_RESET, &event_t, sizeof(event_t));
}
EXPORT_SYMBOL(nic_chip_recover_handler);
Loading