Commit ec796ec9 authored by Hao Lan's avatar Hao Lan Committed by Hao Chen
Browse files

net: hns3: add command queue trace for hns3

maillist inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/IBQKQF
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git/commit/?id=92e599577377



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

Add support to dump command queue trace for hns3.

Signed-off-by: default avatarHao Lan <lanhao@huawei.com>
Signed-off-by: default avatarJijie Shao <shaojijie@huawei.com>
Link: https://lore.kernel.org/r/20240410125354.2177067-2-shaojijie@huawei.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Signed-off-by: default avatarHao Chen <chenhao418@huawei.com>
parent bcf0b1b9
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -474,10 +474,14 @@ static int hclge_comm_cmd_check_result(struct hclge_comm_hw *hw,
int hclge_comm_cmd_send(struct hclge_comm_hw *hw, struct hclge_desc *desc,
			int num)
{
	bool is_special = hclge_comm_is_special_opcode(le16_to_cpu(desc->opcode));
	struct hclge_comm_cmq_ring *csq = &hw->cmq.csq;
	int ret;
	int ntc;

	if (hw->cmq.ops.trace_cmd_send)
		hw->cmq.ops.trace_cmd_send(hw, desc, num, is_special);

	spin_lock_bh(&hw->cmq.csq.lock);

	if (test_bit(HCLGE_COMM_STATE_CMD_DISABLE, &hw->comm_state)) {
@@ -511,6 +515,9 @@ int hclge_comm_cmd_send(struct hclge_comm_hw *hw, struct hclge_desc *desc,

	spin_unlock_bh(&hw->cmq.csq.lock);

	if (hw->cmq.ops.trace_cmd_get)
		hw->cmq.ops.trace_cmd_get(hw, desc, num, is_special);

	return ret;
}

@@ -588,6 +595,17 @@ int hclge_comm_cmd_queue_init(struct pci_dev *pdev, struct hclge_comm_hw *hw)
	return ret;
}

void hclge_comm_cmd_init_ops(struct hclge_comm_hw *hw,
			     const struct hclge_comm_cmq_ops *ops)
{
	struct hclge_comm_cmq *cmdq = &hw->cmq;

	if (ops) {
		cmdq->ops.trace_cmd_send = ops->trace_cmd_send;
		cmdq->ops.trace_cmd_get = ops->trace_cmd_get;
	}
}

int hclge_comm_cmd_init(struct hnae3_ae_dev *ae_dev, struct hclge_comm_hw *hw,
			u32 *fw_version, bool is_pf,
			unsigned long reset_pending)
+13 −1
Original line number Diff line number Diff line
@@ -447,11 +447,22 @@ enum hclge_comm_cmd_status {
	HCLGE_COMM_ERR_CSQ_ERROR	= -3,
};

struct hclge_comm_hw;
struct hclge_comm_cmq_ops {
	void (*trace_cmd_send)(struct hclge_comm_hw *hw,
			       struct hclge_desc *desc,
			       int num, bool is_special);
	void (*trace_cmd_get)(struct hclge_comm_hw *hw,
			      struct hclge_desc *desc,
			      int num, bool is_special);
};

struct hclge_comm_cmq {
	struct hclge_comm_cmq_ring csq;
	struct hclge_comm_cmq_ring crq;
	u16 tx_timeout;
	enum hclge_comm_cmd_status last_status;
	struct hclge_comm_cmq_ops ops;
};

struct hclge_comm_hw {
@@ -498,5 +509,6 @@ int hclge_comm_cmd_queue_init(struct pci_dev *pdev, struct hclge_comm_hw *hw);
int hclge_comm_cmd_init(struct hnae3_ae_dev *ae_dev, struct hclge_comm_hw *hw,
			u32 *fw_version, bool is_pf,
			unsigned long reset_pending);

void hclge_comm_cmd_init_ops(struct hclge_comm_hw *hw,
			     const struct hclge_comm_cmq_ops *ops);
#endif
+44 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@
#include "hclge_unic_guid.h"
#include "hclge_unic_addr.h"
#endif
#include "hclge_trace.h"

#define HCLGE_NAME			"hclge"

@@ -415,6 +416,48 @@ int hclge_cmd_send(struct hclge_hw *hw, struct hclge_desc *desc, int num)
	return hclge_comm_cmd_send(&hw->hw, desc, num);
}

static void hclge_trace_cmd_send(struct hclge_comm_hw *hw, struct hclge_desc *desc,
				 int num, bool is_special)
{
	int i;

	trace_hclge_pf_cmd_send(hw, desc, 0, num);

	if (!is_special) {
		for (i = 1; i < num; i++)
			trace_hclge_pf_cmd_send(hw, &desc[i], i, num);
	} else {
		for (i = 1; i < num; i++)
			trace_hclge_pf_special_cmd_send(hw, (__le32 *)&desc[i],
							i, num);
	}
}

static void hclge_trace_cmd_get(struct hclge_comm_hw *hw, struct hclge_desc *desc,
				int num, bool is_special)
{
	int i;

	if (!HCLGE_COMM_SEND_SYNC(le16_to_cpu(desc->flag)))
		return;

	trace_hclge_pf_cmd_get(hw, desc, 0, num);

	if (!is_special) {
		for (i = 1; i < num; i++)
			trace_hclge_pf_cmd_get(hw, &desc[i], i, num);
	} else {
		for (i = 1; i < num; i++)
			trace_hclge_pf_special_cmd_get(hw, (__le32 *)&desc[i],
						       i, num);
	}
}

static const struct hclge_comm_cmq_ops hclge_cmq_ops = {
	.trace_cmd_send = hclge_trace_cmd_send,
	.trace_cmd_get = hclge_trace_cmd_get,
};

static int hclge_mac_update_stats_defective(struct hclge_dev *hdev)
{
#define HCLGE_MAC_CMD_NUM 21
@@ -12565,6 +12608,7 @@ static int hclge_init_ae_dev(struct hnae3_ae_dev *ae_dev)
		goto err_pci_uninit;

	/* Firmware command initialize */
	hclge_comm_cmd_init_ops(&hdev->hw.hw, &hclge_cmq_ops);
	ret = hclge_comm_cmd_init(hdev->ae_dev, &hdev->hw.hw, &hdev->fw_version,
				  true, hdev->reset_pending);
	if (ret)
+94 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@

#include <linux/tracepoint.h>

#define PF_DESC_LEN	(sizeof(struct hclge_desc) / sizeof(u32))
#define PF_GET_MBX_LEN	(sizeof(struct hclge_mbx_vf_to_pf_cmd) / sizeof(u32))
#define PF_SEND_MBX_LEN	(sizeof(struct hclge_mbx_pf_to_vf_cmd) / sizeof(u32))

@@ -77,6 +78,99 @@ TRACE_EVENT(hclge_pf_mbx_send,
	)
);

DECLARE_EVENT_CLASS(hclge_pf_cmd_template,
		    TP_PROTO(struct hclge_comm_hw *hw,
			     struct hclge_desc *desc,
			     int index,
			     int num),
		    TP_ARGS(hw, desc, index, num),

		    TP_STRUCT__entry(__field(u16, opcode)
			__field(u16, flag)
			__field(u16, retval)
			__field(u16, rsv)
			__field(int, index)
			__field(int, num)
			__string(pciname, pci_name(hw->cmq.csq.pdev))
			__array(u32, data, HCLGE_DESC_DATA_LEN)),

		    TP_fast_assign(int i;
			__entry->opcode = le16_to_cpu(desc->opcode);
			__entry->flag = le16_to_cpu(desc->flag);
			__entry->retval = le16_to_cpu(desc->retval);
			__entry->rsv = le16_to_cpu(desc->rsv);
			__entry->index = index;
			__entry->num = num;
			__assign_str(pciname, pci_name(hw->cmq.csq.pdev));
			for (i = 0; i < HCLGE_DESC_DATA_LEN; i++)
				__entry->data[i] = le32_to_cpu(desc->data[i]);),

		    TP_printk("%s opcode:0x%04x %d-%d flag:0x%04x retval:0x%04x rsv:0x%04x data:%s",
			      __get_str(pciname), __entry->opcode,
			      __entry->index, __entry->num,
			      __entry->flag, __entry->retval, __entry->rsv,
			      __print_array(__entry->data,
					    HCLGE_DESC_DATA_LEN, sizeof(u32)))
);

DEFINE_EVENT(hclge_pf_cmd_template, hclge_pf_cmd_send,
	     TP_PROTO(struct hclge_comm_hw *hw,
		      struct hclge_desc *desc,
		      int index,
		      int num),
	     TP_ARGS(hw, desc, index, num)
);

DEFINE_EVENT(hclge_pf_cmd_template, hclge_pf_cmd_get,
	     TP_PROTO(struct hclge_comm_hw *hw,
		      struct hclge_desc *desc,
		      int index,
		      int num),
	     TP_ARGS(hw, desc, index, num)
);

DECLARE_EVENT_CLASS(hclge_pf_special_cmd_template,
		    TP_PROTO(struct hclge_comm_hw *hw,
			     __le32 *data,
			     int index,
			     int num),
		    TP_ARGS(hw, data, index, num),

		    TP_STRUCT__entry(__field(int, index)
			__field(int, num)
			__string(pciname, pci_name(hw->cmq.csq.pdev))
			__array(u32, data, PF_DESC_LEN)),

		    TP_fast_assign(int i;
			__entry->index = index;
			__entry->num = num;
			__assign_str(pciname, pci_name(hw->cmq.csq.pdev));
			for (i = 0; i < PF_DESC_LEN; i++)
				__entry->data[i] = le32_to_cpu(data[i]);
		),

		    TP_printk("%s %d-%d data:%s",
			      __get_str(pciname),
			      __entry->index, __entry->num,
			      __print_array(__entry->data,
					    PF_DESC_LEN, sizeof(u32)))
);

DEFINE_EVENT(hclge_pf_special_cmd_template, hclge_pf_special_cmd_send,
	     TP_PROTO(struct hclge_comm_hw *hw,
		      __le32 *desc,
		      int index,
		      int num),
	     TP_ARGS(hw, desc, index, num));

DEFINE_EVENT(hclge_pf_special_cmd_template, hclge_pf_special_cmd_get,
	     TP_PROTO(struct hclge_comm_hw *hw,
		      __le32 *desc,
		      int index,
		      int num),
	     TP_ARGS(hw, desc, index, num)
);

#endif /* _HCLGE_TRACE_H_ */

/* This must be outside ifdef _HCLGE_TRACE_H */
+40 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
#include "hclgevf_unic_addr.h"
#endif
#include "hclgevf_dcb.h"
#include "hclgevf_trace.h"

#define HCLGEVF_NAME	"hclgevf"

@@ -65,6 +66,42 @@ int hclgevf_cmd_send(struct hclgevf_hw *hw, struct hclge_desc *desc, int num)
	return hclge_comm_cmd_send(&hw->hw, desc, num);
}

static void hclgevf_trace_cmd_send(struct hclge_comm_hw *hw, struct hclge_desc *desc,
				   int num, bool is_special)
{
	int i;

	trace_hclge_vf_cmd_send(hw, desc, 0, num);

	if (is_special)
		return;

	for (i = 1; i < num; i++)
		trace_hclge_vf_cmd_send(hw, &desc[i], i, num);
}

static void hclgevf_trace_cmd_get(struct hclge_comm_hw *hw, struct hclge_desc *desc,
				  int num, bool is_special)
{
	int i;

	if (!HCLGE_COMM_SEND_SYNC(le16_to_cpu(desc->flag)))
		return;

	trace_hclge_vf_cmd_get(hw, desc, 0, num);

	if (is_special)
		return;

	for (i = 1; i < num; i++)
		trace_hclge_vf_cmd_get(hw, &desc[i], i, num);
}

static const struct hclge_comm_cmq_ops hclgevf_cmq_ops = {
	.trace_cmd_send = hclgevf_trace_cmd_send,
	.trace_cmd_get = hclgevf_trace_cmd_get,
};

void hclgevf_arq_init(struct hclgevf_dev *hdev)
{
	struct hclge_comm_cmq *cmdq = &hdev->hw.hw.cmq;
@@ -3118,6 +3155,7 @@ static int hclgevf_reset_hdev(struct hclgevf_dev *hdev)
	}

	hclgevf_arq_init(hdev);

	ret = hclge_comm_cmd_init(hdev->ae_dev, &hdev->hw.hw,
				  &hdev->fw_version, false,
				  hdev->reset_pending);
@@ -3176,6 +3214,8 @@ static int hclgevf_init_hdev(struct hclgevf_dev *hdev)
		goto err_cmd_queue_init;

	hclgevf_arq_init(hdev);

	hclge_comm_cmd_init_ops(&hdev->hw.hw, &hclgevf_cmq_ops);
	ret = hclge_comm_cmd_init(hdev->ae_dev, &hdev->hw.hw,
				  &hdev->fw_version, false,
				  hdev->reset_pending);
Loading