Commit c6116398 authored by Luo Jiaxing's avatar Luo Jiaxing Committed by Martin K. Petersen
Browse files

scsi: hisi_sas: Add debugfs file structure for registers

Create a file structure which was used to save the memory address and
hisi_hba pointer for REGS at debugfs. This structure is bound to the
corresponding debugfs file, it can help callback function of debugfs file
to get what it need.

Link: https://lore.kernel.org/r/1571926105-74636-9-git-send-email-john.garry@huawei.com


Signed-off-by: default avatarLuo Jiaxing <luojiaxing@huawei.com>
Signed-off-by: default avatarJohn Garry <john.garry@huawei.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 1b54c4db
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -333,6 +333,11 @@ struct hisi_sas_debugfs_dq {
	struct hisi_sas_cmd_hdr *hdr;
};

struct hisi_sas_debugfs_regs {
	struct hisi_hba *hisi_hba;
	u32 *data;
};

struct hisi_hba {
	/* This must be the first element, used by SHOST_TO_SAS_HA */
	struct sas_ha_struct *p;
@@ -414,7 +419,7 @@ struct hisi_hba {

	/* debugfs memories */
	/* Put Global AXI and RAS Register into register array */
	u32 *debugfs_regs[DEBUGFS_REGS_NUM];
	struct hisi_sas_debugfs_regs debugfs_regs[DEBUGFS_REGS_NUM];
	u32 *debugfs_port_reg[HISI_SAS_MAX_PHYS];
	struct hisi_sas_debugfs_cq debugfs_cq[HISI_SAS_MAX_QUEUES];
	struct hisi_sas_debugfs_dq debugfs_dq[HISI_SAS_MAX_QUEUES];
+29 −33
Original line number Diff line number Diff line
@@ -2743,7 +2743,7 @@ static void hisi_sas_debugfs_snapshot_port_reg(struct hisi_hba *hisi_hba)

static void hisi_sas_debugfs_snapshot_global_reg(struct hisi_hba *hisi_hba)
{
	u32 *databuf = hisi_hba->debugfs_regs[DEBUGFS_GLOBAL];
	u32 *databuf = hisi_hba->debugfs_regs[DEBUGFS_GLOBAL].data;
	const struct hisi_sas_hw *hw = hisi_hba->hw;
	const struct hisi_sas_debugfs_reg *global =
			hw->debugfs_reg_array[DEBUGFS_GLOBAL];
@@ -2755,7 +2755,7 @@ static void hisi_sas_debugfs_snapshot_global_reg(struct hisi_hba *hisi_hba)

static void hisi_sas_debugfs_snapshot_axi_reg(struct hisi_hba *hisi_hba)
{
	u32 *databuf = hisi_hba->debugfs_regs[DEBUGFS_AXI];
	u32 *databuf = hisi_hba->debugfs_regs[DEBUGFS_AXI].data;
	const struct hisi_sas_hw *hw = hisi_hba->hw;
	const struct hisi_sas_debugfs_reg *axi =
			hw->debugfs_reg_array[DEBUGFS_AXI];
@@ -2768,7 +2768,7 @@ static void hisi_sas_debugfs_snapshot_axi_reg(struct hisi_hba *hisi_hba)

static void hisi_sas_debugfs_snapshot_ras_reg(struct hisi_hba *hisi_hba)
{
	u32 *databuf = hisi_hba->debugfs_regs[DEBUGFS_RAS];
	u32 *databuf = hisi_hba->debugfs_regs[DEBUGFS_RAS].data;
	const struct hisi_sas_hw *hw = hisi_hba->hw;
	const struct hisi_sas_debugfs_reg *ras =
			hw->debugfs_reg_array[DEBUGFS_RAS];
@@ -2852,11 +2852,12 @@ static void hisi_sas_debugfs_print_reg(u32 *regs_val, const void *ptr,

static int hisi_sas_debugfs_global_show(struct seq_file *s, void *p)
{
	struct hisi_hba *hisi_hba = s->private;
	struct hisi_sas_debugfs_regs *global = s->private;
	struct hisi_hba *hisi_hba = global->hisi_hba;
	const struct hisi_sas_hw *hw = hisi_hba->hw;
	const void *reg_global = hw->debugfs_reg_array[DEBUGFS_GLOBAL];

	hisi_sas_debugfs_print_reg(hisi_hba->debugfs_regs[DEBUGFS_GLOBAL],
	hisi_sas_debugfs_print_reg(global->data,
				   reg_global, s);

	return 0;
@@ -2878,11 +2879,12 @@ static const struct file_operations hisi_sas_debugfs_global_fops = {

static int hisi_sas_debugfs_axi_show(struct seq_file *s, void *p)
{
	struct hisi_hba *hisi_hba = s->private;
	struct hisi_sas_debugfs_regs *axi = s->private;
	struct hisi_hba *hisi_hba = axi->hisi_hba;
	const struct hisi_sas_hw *hw = hisi_hba->hw;
	const void *reg_axi = hw->debugfs_reg_array[DEBUGFS_AXI];

	hisi_sas_debugfs_print_reg(hisi_hba->debugfs_regs[DEBUGFS_AXI],
	hisi_sas_debugfs_print_reg(axi->data,
				   reg_axi, s);

	return 0;
@@ -2904,11 +2906,12 @@ static const struct file_operations hisi_sas_debugfs_axi_fops = {

static int hisi_sas_debugfs_ras_show(struct seq_file *s, void *p)
{
	struct hisi_hba *hisi_hba = s->private;
	struct hisi_sas_debugfs_regs *ras = s->private;
	struct hisi_hba *hisi_hba = ras->hisi_hba;
	const struct hisi_sas_hw *hw = hisi_hba->hw;
	const void *reg_ras = hw->debugfs_reg_array[DEBUGFS_RAS];

	hisi_sas_debugfs_print_reg(hisi_hba->debugfs_regs[DEBUGFS_RAS],
	hisi_sas_debugfs_print_reg(ras->data,
				   reg_ras, s);

	return 0;
@@ -3209,7 +3212,8 @@ static void hisi_sas_debugfs_create_files(struct hisi_hba *hisi_hba)
	debugfs_create_u64("timestamp", 0400, dump_dentry,
			   debugfs_timestamp);

	debugfs_create_file("global", 0400, dump_dentry, hisi_hba,
	debugfs_create_file("global", 0400, dump_dentry,
			    &hisi_hba->debugfs_regs[DEBUGFS_GLOBAL],
			    &hisi_sas_debugfs_global_fops);

	/* Create port dir and files */
@@ -3253,10 +3257,12 @@ static void hisi_sas_debugfs_create_files(struct hisi_hba *hisi_hba)
	debugfs_create_file("itct_cache", 0400, dump_dentry, hisi_hba,
			    &hisi_sas_debugfs_itct_cache_fops);

	debugfs_create_file("axi", 0400, dump_dentry, hisi_hba,
	debugfs_create_file("axi", 0400, dump_dentry,
			    &hisi_hba->debugfs_regs[DEBUGFS_AXI],
			    &hisi_sas_debugfs_axi_fops);

	debugfs_create_file("ras", 0400, dump_dentry, hisi_hba,
	debugfs_create_file("ras", 0400, dump_dentry,
			    &hisi_hba->debugfs_regs[DEBUGFS_RAS],
			    &hisi_sas_debugfs_ras_fops);

	return;
@@ -3718,7 +3724,7 @@ static void hisi_sas_debugfs_release(struct hisi_hba *hisi_hba)
		devm_kfree(dev, hisi_hba->debugfs_cq[i].complete_hdr);

	for (i = 0; i < DEBUGFS_REGS_NUM; i++)
		devm_kfree(dev, hisi_hba->debugfs_regs[i]);
		devm_kfree(dev, hisi_hba->debugfs_regs[i].data);

	for (i = 0; i < hisi_hba->n_phy; i++)
		devm_kfree(dev, hisi_hba->debugfs_port_reg[i]);
@@ -3728,15 +3734,19 @@ static int hisi_sas_debugfs_alloc(struct hisi_hba *hisi_hba)
{
	const struct hisi_sas_hw *hw = hisi_hba->hw;
	struct device *dev = hisi_hba->dev;
	int p, c, d;
	int p, c, d, r;
	size_t sz;

	sz = hw->debugfs_reg_array[DEBUGFS_GLOBAL]->count * 4;
	hisi_hba->debugfs_regs[DEBUGFS_GLOBAL] =
				devm_kmalloc(dev, sz, GFP_KERNEL);
	for (r = 0; r < DEBUGFS_REGS_NUM; r++) {
		struct hisi_sas_debugfs_regs *regs =
				&hisi_hba->debugfs_regs[r];

	if (!hisi_hba->debugfs_regs[DEBUGFS_GLOBAL])
		sz = hw->debugfs_reg_array[r]->count * 4;
		regs->data = devm_kmalloc(dev, sz, GFP_KERNEL);
		if (!regs->data)
			goto fail;
		regs->hisi_hba = hisi_hba;
	}

	sz = hw->debugfs_reg_port->count * 4;
	for (p = 0; p < hisi_hba->n_phy; p++) {
@@ -3747,20 +3757,6 @@ static int hisi_sas_debugfs_alloc(struct hisi_hba *hisi_hba)
			goto fail;
	}

	sz = hw->debugfs_reg_array[DEBUGFS_AXI]->count * 4;
	hisi_hba->debugfs_regs[DEBUGFS_AXI] =
		devm_kmalloc(dev, sz, GFP_KERNEL);

	if (!hisi_hba->debugfs_regs[DEBUGFS_AXI])
		goto fail;

	sz = hw->debugfs_reg_array[DEBUGFS_RAS]->count * 4;
	hisi_hba->debugfs_regs[DEBUGFS_RAS] =
		devm_kmalloc(dev, sz, GFP_KERNEL);

	if (!hisi_hba->debugfs_regs[DEBUGFS_RAS])
		goto fail;

	sz = hw->complete_hdr_size * HISI_SAS_QUEUE_SLOTS;
	for (c = 0; c < hisi_hba->queue_count; c++) {
		struct hisi_sas_debugfs_cq *cq =