Unverified Commit c6bcd162 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!4220 backport some patches for kunpeng hccs

Merge Pull Request from: @huangdengdui 
 
backport some patches for kunpeng hccs are as follows:
734add1a278f05db2d5a0b9d280a8bce94ce5eeb soc: hisilicon: kunpeng_hccs: Fix some incorrect format strings
e1e720f3f2c50a6f3440b3684decd7b7c046e111 soc: hisilicon: kunpeng_hccs: Add failure log for no _CRS method
a079f3244563a4c4dc32b0a9bfa0e3e519f3c9ed soc: hisilicon: kunpeng_hccs: Remove an unused blank line
a07d8fc358af5f297b41b2182a5fce710e3c9bd7 doc: kunpeng_hccs: Fix incorrect email domain name
be2f78a8a638e71bbbc2109bc052524143e8f42a soc: hisilicon: kunpeng_hccs: Support the platform with PCC type3 and interrupt ack 
 
Link:https://gitee.com/openeuler/kernel/pulls/4220

 

Reviewed-by: default avatarFred Kimmy <xweikong@163.com>
Signed-off-by: default avatarJialin Zhang <zhangjialin11@huawei.com>
parents ecb0378f 1575a8ca
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@ What: /sys/devices/platform/HISI04Bx:00/chipX/linked_full_lane
What:		/sys/devices/platform/HISI04Bx:00/chipX/crc_err_cnt
Date:		November 2023
KernelVersion:	6.6
Contact:	Huisong Li <lihuisong@huawei.org>
Contact:	Huisong Li <lihuisong@huawei.com>
Description:
		The /sys/devices/platform/HISI04Bx:00/chipX/ directory
		contains read-only attributes exposing some summarization
@@ -26,7 +26,7 @@ What: /sys/devices/platform/HISI04Bx:00/chipX/dieY/linked_full_lane
What:		/sys/devices/platform/HISI04Bx:00/chipX/dieY/crc_err_cnt
Date:		November 2023
KernelVersion:	6.6
Contact:	Huisong Li <lihuisong@huawei.org>
Contact:	Huisong Li <lihuisong@huawei.com>
Description:
		The /sys/devices/platform/HISI04Bx:00/chipX/dieY/ directory
		contains read-only attributes exposing some summarization
@@ -54,7 +54,7 @@ What: /sys/devices/platform/HISI04Bx:00/chipX/dieY/hccsN/lane_mask
What:		/sys/devices/platform/HISI04Bx:00/chipX/dieY/hccsN/crc_err_cnt
Date:		November 2023
KernelVersion:	6.6
Contact:	Huisong Li <lihuisong@huawei.org>
Contact:	Huisong Li <lihuisong@huawei.com>
Description:
		The /sys/devices/platform/HISI04Bx/chipX/dieX/hccsN/ directory
		contains read-only attributes exposing information about
+90 −85
Original line number Diff line number Diff line
@@ -38,11 +38,6 @@
#define HCCS_PCC_CMD_WAIT_RETRIES_NUM		500ULL
#define HCCS_POLL_STATUS_TIME_INTERVAL_US	3

enum hccs_hw_device_version {
	HCCS_HW_DEVICE_V1 = 0,
	HCCS_HW_DEVICE_V2 = 1,
};

static struct hccs_port_info *kobj_to_port_info(struct kobject *k)
{
	return container_of(k, struct hccs_port_info, kobj);
@@ -105,21 +100,6 @@ static int hccs_get_pcc_chan_id(struct hccs_dev *hdev)
	return 0;
}

static int hccs_get_device_version(struct hccs_dev *hdev)
{
	const struct acpi_device_id *acpi_id;

	acpi_id = acpi_match_device(hdev->dev->driver->acpi_match_table,
				    hdev->dev);
	if (!acpi_id) {
		dev_err(hdev->dev, "get device version failed.");
		return -EINVAL;
	}

	hdev->dev_ver = (u8)acpi_id->driver_data;
	return 0;
}

static void hccs_chan_tx_done(struct mbox_client *cl, void *msg, int ret)
{
	if (ret < 0)
@@ -130,7 +110,7 @@ static void hccs_chan_tx_done(struct mbox_client *cl, void *msg, int ret)
			 *(u8 *)msg, ret);
}

static void hccs_pcc_rx_callback(struct mbox_client *cl, void *m)
static void hccs_pcc_rx_callback(struct mbox_client *cl, void *mssg)
{
	struct hccs_mbox_client_info *cl_info =
			container_of(cl, struct hccs_mbox_client_info, client);
@@ -159,10 +139,8 @@ static int hccs_register_pcc_channel(struct hccs_dev *hdev)
	cl->tx_block = false;
	cl->knows_txdone = true;
	cl->tx_done = hccs_chan_tx_done;
	if (hdev->dev_ver == HCCS_HW_DEVICE_V2) {
		cl->rx_callback = hccs_pcc_rx_callback;
	cl->rx_callback = hdev->verspec_data->rx_callback;
	init_completion(&cl_info->done);
	}

	pcc_chan = pcc_mbox_request_channel(cl, hdev->chan_id);
	if (IS_ERR(pcc_chan)) {
@@ -180,12 +158,12 @@ static int hccs_register_pcc_channel(struct hccs_dev *hdev)
	 */
	cl_info->deadline_us =
			HCCS_PCC_CMD_WAIT_RETRIES_NUM * pcc_chan->latency;
	if (hdev->dev_ver == HCCS_HW_DEVICE_V1 &&
	if (!hdev->verspec_data->has_txdone_irq &&
	    cl_info->mbox_chan->mbox->txdone_irq) {
		dev_err(dev, "PCC IRQ in PCCT is enabled.\n");
		rc = -EINVAL;
		goto err_mbx_channel_free;
	} else if (hdev->dev_ver == HCCS_HW_DEVICE_V2 &&
	} else if (hdev->verspec_data->has_txdone_irq &&
		   !cl_info->mbox_chan->mbox->txdone_irq) {
		dev_err(dev, "PCC IRQ in PCCT isn't supported.\n");
		rc = -EINVAL;
@@ -211,60 +189,76 @@ static int hccs_register_pcc_channel(struct hccs_dev *hdev)
	return rc;
}

static int hccs_check_chan_cmd_complete(struct hccs_dev *hdev)
static int hccs_wait_cmd_complete_by_poll(struct hccs_dev *hdev)
{
	struct hccs_mbox_client_info *cl_info = &hdev->cl_info;
	struct acpi_pcct_shared_memory __iomem *comm_base;
	int ret = 0;
	struct acpi_pcct_shared_memory __iomem *comm_base =
							cl_info->pcc_comm_addr;
	u16 status;
	int ret;

	/*
	 * Poll PCC status register every 3us(delay_us) for maximum of
	 * deadline_us(timeout_us) until PCC command complete bit is set(cond)
	 */
	if (hdev->dev_ver == HCCS_HW_DEVICE_V1) {
		comm_base = cl_info->pcc_comm_addr;
	ret = readw_poll_timeout(&comm_base->status, status,
				 status & PCC_STATUS_CMD_COMPLETE,
				 HCCS_POLL_STATUS_TIME_INTERVAL_US,
				 cl_info->deadline_us);
	if (unlikely(ret))
		dev_err(hdev->dev, "poll PCC status failed, ret = %d.\n", ret);
	} else {

	return ret;
}

static int hccs_wait_cmd_complete_by_irq(struct hccs_dev *hdev)
{
	struct hccs_mbox_client_info *cl_info = &hdev->cl_info;

	if (!wait_for_completion_timeout(&cl_info->done,
			usecs_to_jiffies(cl_info->deadline_us))) {
		dev_err(hdev->dev, "PCC command executed timeout!\n");
			ret = -ETIMEDOUT;
		}
		return -ETIMEDOUT;
	}

	return ret;
	return 0;
}

static void hccs_fill_pcc_shared_mem_region(struct hccs_dev *hdev, u8 cmd,
static inline void hccs_fill_pcc_shared_mem_region(struct hccs_dev *hdev,
						   u8 cmd,
						   struct hccs_desc *desc,
						   void __iomem *comm_space,
						   u16 space_size)
{
	struct hccs_mbox_client_info *cl_info = &hdev->cl_info;
	struct acpi_pcct_ext_pcc_shared_memory tmp1 = {0};
	struct acpi_pcct_shared_memory tmp2 = {0};

	if (hdev->dev_ver == HCCS_HW_DEVICE_V1) {
		tmp2.signature = PCC_SIGNATURE | hdev->chan_id;
		tmp2.command = cmd;
		tmp2.status = 0;
		memcpy_toio(cl_info->pcc_comm_addr, (void *)&tmp2,
	struct acpi_pcct_shared_memory tmp = {
		.signature = PCC_SIGNATURE | hdev->chan_id,
		.command = cmd,
		.status = 0,
	};

	memcpy_toio(hdev->cl_info.pcc_comm_addr, (void *)&tmp,
		    sizeof(struct acpi_pcct_shared_memory));
	} else {
		tmp1.signature = PCC_SIGNATURE | hdev->chan_id;
		tmp1.command = cmd;
		tmp1.flags = PCC_CMD_COMPLETION_NOTIFY;
		tmp1.length = HCCS_PCC_SHARE_MEM_BYTES;
		memcpy_toio(cl_info->pcc_comm_addr, (void *)&tmp1,
			    sizeof(struct acpi_pcct_ext_pcc_shared_memory));

	/* Copy the message to the PCC comm space */
	memcpy_toio(comm_space, (void *)desc, space_size);
}

static inline void hccs_fill_ext_pcc_shared_mem_region(struct hccs_dev *hdev,
						       u8 cmd,
						       struct hccs_desc *desc,
						       void __iomem *comm_space,
						       u16 space_size)
{
	struct acpi_pcct_ext_pcc_shared_memory tmp = {
		.signature = PCC_SIGNATURE | hdev->chan_id,
		.flags = PCC_CMD_COMPLETION_NOTIFY,
		.length = HCCS_PCC_SHARE_MEM_BYTES,
		.command = cmd,
	};

	memcpy_toio(hdev->cl_info.pcc_comm_addr, (void *)&tmp,
		    sizeof(struct acpi_pcct_ext_pcc_shared_memory));

	/* Copy the message to the PCC comm space */
	memcpy_toio(comm_space, (void *)desc, space_size);
}
@@ -272,22 +266,18 @@ static void hccs_fill_pcc_shared_mem_region(struct hccs_dev *hdev, u8 cmd,
static int hccs_pcc_cmd_send(struct hccs_dev *hdev, u8 cmd,
			     struct hccs_desc *desc)
{
	const struct hccs_verspecific_data *verspec_data = hdev->verspec_data;
	struct hccs_mbox_client_info *cl_info = &hdev->cl_info;
	struct hccs_fw_inner_head *fw_inner_head;
	void __iomem *comm_space;
	u16 shared_mem_size;
	u16 space_size;
	int ret;

	shared_mem_size = hdev->dev_ver == HCCS_HW_DEVICE_V1 ?
			sizeof(struct acpi_pcct_shared_memory) :
			sizeof(struct acpi_pcct_ext_pcc_shared_memory);
	comm_space = cl_info->pcc_comm_addr + shared_mem_size;
	space_size = HCCS_PCC_SHARE_MEM_BYTES - shared_mem_size;

	hccs_fill_pcc_shared_mem_region(hdev, cmd, desc,
	comm_space = cl_info->pcc_comm_addr + verspec_data->shared_mem_size;
	space_size = HCCS_PCC_SHARE_MEM_BYTES - verspec_data->shared_mem_size;
	verspec_data->fill_pcc_shared_mem(hdev, cmd, desc,
					  comm_space, space_size);
	if (cl_info->mbox_chan->mbox->txdone_irq)
	if (verspec_data->has_txdone_irq)
		reinit_completion(&cl_info->done);

	/* Ring doorbell */
@@ -298,8 +288,7 @@ static int hccs_pcc_cmd_send(struct hccs_dev *hdev, u8 cmd,
		goto end;
	}

	/* Wait for completion */
	ret = hccs_check_chan_cmd_complete(hdev);
	ret = verspec_data->wait_cmd_complete(hdev);
	if (ret)
		goto end;

@@ -313,7 +302,7 @@ static int hccs_pcc_cmd_send(struct hccs_dev *hdev, u8 cmd,
	}

end:
	if (cl_info->mbox_chan->mbox->txdone_irq)
	if (verspec_data->has_txdone_irq)
		mbox_chan_txdone(cl_info->mbox_chan, ret);
	else
		mbox_client_txdone(cl_info->mbox_chan, ret);
@@ -603,7 +592,6 @@ static int hccs_get_all_port_info_on_die(struct hccs_dev *hdev,

static int hccs_query_all_port_info_on_platform(struct hccs_dev *hdev)
{

	struct device *dev = hdev->dev;
	struct hccs_chip_info *chip;
	struct hccs_die_info *die;
@@ -1288,9 +1276,10 @@ static int hccs_probe(struct platform_device *pdev)
	hdev->dev = &pdev->dev;
	platform_set_drvdata(pdev, hdev);

	rc = hccs_get_device_version(hdev);
	if (rc)
		return rc;
	/*
	 * Here would never be failure as the driver and device has been matched.
	 */
	hdev->verspec_data = acpi_device_get_match_data(hdev->dev);

	mutex_init(&hdev->lock);
	rc = hccs_get_pcc_chan_id(hdev);
@@ -1330,10 +1319,26 @@ static int hccs_remove(struct platform_device *pdev)
	return 0;
}

static const struct hccs_verspecific_data hisi04b1_verspec_data = {
	.rx_callback = NULL,
	.wait_cmd_complete = hccs_wait_cmd_complete_by_poll,
	.fill_pcc_shared_mem = hccs_fill_pcc_shared_mem_region,
	.shared_mem_size = sizeof(struct acpi_pcct_shared_memory),
	.has_txdone_irq = false,
};

static const struct hccs_verspecific_data hisi04b2_verspec_data = {
	.rx_callback = hccs_pcc_rx_callback,
	.wait_cmd_complete = hccs_wait_cmd_complete_by_irq,
	.fill_pcc_shared_mem = hccs_fill_ext_pcc_shared_mem_region,
	.shared_mem_size = sizeof(struct acpi_pcct_ext_pcc_shared_memory),
	.has_txdone_irq = true,
};

static const struct acpi_device_id hccs_acpi_match[] = {
	{ "HISI04B1", HCCS_HW_DEVICE_V1},
	{ "HISI04B2", HCCS_HW_DEVICE_V2},
	{ ""},
	{ "HISI04B1", (unsigned long)&hisi04b1_verspec_data},
	{ "HISI04B2", (unsigned long)&hisi04b2_verspec_data},
	{ }
};
MODULE_DEVICE_TABLE(acpi, hccs_acpi_match);

+14 −1
Original line number Diff line number Diff line
@@ -54,11 +54,24 @@ struct hccs_mbox_client_info {
	struct completion done;
};

struct hccs_desc;

struct hccs_verspecific_data {
	void (*rx_callback)(struct mbox_client *cl, void *mssg);
	int (*wait_cmd_complete)(struct hccs_dev *hdev);
	void (*fill_pcc_shared_mem)(struct hccs_dev *hdev,
				    u8 cmd, struct hccs_desc *desc,
				    void __iomem *comm_space,
				    u16 space_size);
	u16 shared_mem_size;
	bool has_txdone_irq;
};

struct hccs_dev {
	struct device *dev;
	struct acpi_device *acpi_dev;
	const struct hccs_verspecific_data *verspec_data;
	u64 caps;
	u8 dev_ver;
	u8 chip_num;
	struct hccs_chip_info *chips;
	u8 chan_id;