162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * PMC-Sierra 8001/8081/8088/8089 SAS/SATA based host adapters driver
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Copyright (c) 2008-2009 USI Co., Ltd.
562306a36Sopenharmony_ci * All rights reserved.
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
862306a36Sopenharmony_ci * modification, are permitted provided that the following conditions
962306a36Sopenharmony_ci * are met:
1062306a36Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright
1162306a36Sopenharmony_ci *    notice, this list of conditions, and the following disclaimer,
1262306a36Sopenharmony_ci *    without modification.
1362306a36Sopenharmony_ci * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1462306a36Sopenharmony_ci *    substantially similar to the "NO WARRANTY" disclaimer below
1562306a36Sopenharmony_ci *    ("Disclaimer") and any redistribution must be conditioned upon
1662306a36Sopenharmony_ci *    including a substantially similar Disclaimer requirement for further
1762306a36Sopenharmony_ci *    binary redistribution.
1862306a36Sopenharmony_ci * 3. Neither the names of the above-listed copyright holders nor the names
1962306a36Sopenharmony_ci *    of any contributors may be used to endorse or promote products derived
2062306a36Sopenharmony_ci *    from this software without specific prior written permission.
2162306a36Sopenharmony_ci *
2262306a36Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the
2362306a36Sopenharmony_ci * GNU General Public License ("GPL") version 2 as published by the Free
2462306a36Sopenharmony_ci * Software Foundation.
2562306a36Sopenharmony_ci *
2662306a36Sopenharmony_ci * NO WARRANTY
2762306a36Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2862306a36Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2962306a36Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
3062306a36Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3162306a36Sopenharmony_ci * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3262306a36Sopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3362306a36Sopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3462306a36Sopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3562306a36Sopenharmony_ci * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
3662306a36Sopenharmony_ci * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3762306a36Sopenharmony_ci * POSSIBILITY OF SUCH DAMAGES.
3862306a36Sopenharmony_ci *
3962306a36Sopenharmony_ci */
4062306a36Sopenharmony_ci#include <linux/firmware.h>
4162306a36Sopenharmony_ci#include <linux/slab.h>
4262306a36Sopenharmony_ci#include "pm8001_sas.h"
4362306a36Sopenharmony_ci#include "pm8001_ctl.h"
4462306a36Sopenharmony_ci#include "pm8001_chips.h"
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci/* scsi host attributes */
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci/**
4962306a36Sopenharmony_ci * pm8001_ctl_mpi_interface_rev_show - MPI interface revision number
5062306a36Sopenharmony_ci * @cdev: pointer to embedded class device
5162306a36Sopenharmony_ci * @attr: device attribute (unused)
5262306a36Sopenharmony_ci * @buf: the buffer returned
5362306a36Sopenharmony_ci *
5462306a36Sopenharmony_ci * A sysfs 'read-only' shost attribute.
5562306a36Sopenharmony_ci */
5662306a36Sopenharmony_cistatic ssize_t pm8001_ctl_mpi_interface_rev_show(struct device *cdev,
5762306a36Sopenharmony_ci	struct device_attribute *attr, char *buf)
5862306a36Sopenharmony_ci{
5962306a36Sopenharmony_ci	struct Scsi_Host *shost = class_to_shost(cdev);
6062306a36Sopenharmony_ci	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
6162306a36Sopenharmony_ci	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci	if (pm8001_ha->chip_id == chip_8001) {
6462306a36Sopenharmony_ci		return sysfs_emit(buf, "%d\n",
6562306a36Sopenharmony_ci			pm8001_ha->main_cfg_tbl.pm8001_tbl.interface_rev);
6662306a36Sopenharmony_ci	} else {
6762306a36Sopenharmony_ci		return sysfs_emit(buf, "%d\n",
6862306a36Sopenharmony_ci			pm8001_ha->main_cfg_tbl.pm80xx_tbl.interface_rev);
6962306a36Sopenharmony_ci	}
7062306a36Sopenharmony_ci}
7162306a36Sopenharmony_cistatic
7262306a36Sopenharmony_ciDEVICE_ATTR(interface_rev, S_IRUGO, pm8001_ctl_mpi_interface_rev_show, NULL);
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci/**
7562306a36Sopenharmony_ci * controller_fatal_error_show - check controller is under fatal err
7662306a36Sopenharmony_ci * @cdev: pointer to embedded class device
7762306a36Sopenharmony_ci * @attr: device attribute (unused)
7862306a36Sopenharmony_ci * @buf: the buffer returned
7962306a36Sopenharmony_ci *
8062306a36Sopenharmony_ci * A sysfs 'read-only' shost attribute.
8162306a36Sopenharmony_ci */
8262306a36Sopenharmony_cistatic ssize_t controller_fatal_error_show(struct device *cdev,
8362306a36Sopenharmony_ci		struct device_attribute *attr, char *buf)
8462306a36Sopenharmony_ci{
8562306a36Sopenharmony_ci	struct Scsi_Host *shost = class_to_shost(cdev);
8662306a36Sopenharmony_ci	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
8762306a36Sopenharmony_ci	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ci	return sysfs_emit(buf, "%d\n",
9062306a36Sopenharmony_ci			pm8001_ha->controller_fatal_error);
9162306a36Sopenharmony_ci}
9262306a36Sopenharmony_cistatic DEVICE_ATTR_RO(controller_fatal_error);
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci/**
9562306a36Sopenharmony_ci * pm8001_ctl_fw_version_show - firmware version
9662306a36Sopenharmony_ci * @cdev: pointer to embedded class device
9762306a36Sopenharmony_ci * @attr: device attribute (unused)
9862306a36Sopenharmony_ci * @buf: the buffer returned
9962306a36Sopenharmony_ci *
10062306a36Sopenharmony_ci * A sysfs 'read-only' shost attribute.
10162306a36Sopenharmony_ci */
10262306a36Sopenharmony_cistatic ssize_t pm8001_ctl_fw_version_show(struct device *cdev,
10362306a36Sopenharmony_ci	struct device_attribute *attr, char *buf)
10462306a36Sopenharmony_ci{
10562306a36Sopenharmony_ci	struct Scsi_Host *shost = class_to_shost(cdev);
10662306a36Sopenharmony_ci	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
10762306a36Sopenharmony_ci	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ci	if (pm8001_ha->chip_id == chip_8001) {
11062306a36Sopenharmony_ci		return sysfs_emit(buf, "%02x.%02x.%02x.%02x\n",
11162306a36Sopenharmony_ci		(u8)(pm8001_ha->main_cfg_tbl.pm8001_tbl.firmware_rev >> 24),
11262306a36Sopenharmony_ci		(u8)(pm8001_ha->main_cfg_tbl.pm8001_tbl.firmware_rev >> 16),
11362306a36Sopenharmony_ci		(u8)(pm8001_ha->main_cfg_tbl.pm8001_tbl.firmware_rev >> 8),
11462306a36Sopenharmony_ci		(u8)(pm8001_ha->main_cfg_tbl.pm8001_tbl.firmware_rev));
11562306a36Sopenharmony_ci	} else {
11662306a36Sopenharmony_ci		return sysfs_emit(buf, "%02x.%02x.%02x.%02x\n",
11762306a36Sopenharmony_ci		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.firmware_rev >> 24),
11862306a36Sopenharmony_ci		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.firmware_rev >> 16),
11962306a36Sopenharmony_ci		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.firmware_rev >> 8),
12062306a36Sopenharmony_ci		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.firmware_rev));
12162306a36Sopenharmony_ci	}
12262306a36Sopenharmony_ci}
12362306a36Sopenharmony_cistatic DEVICE_ATTR(fw_version, S_IRUGO, pm8001_ctl_fw_version_show, NULL);
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_ci/**
12662306a36Sopenharmony_ci * pm8001_ctl_ila_version_show - ila version
12762306a36Sopenharmony_ci * @cdev: pointer to embedded class device
12862306a36Sopenharmony_ci * @attr: device attribute (unused)
12962306a36Sopenharmony_ci * @buf: the buffer returned
13062306a36Sopenharmony_ci *
13162306a36Sopenharmony_ci * A sysfs 'read-only' shost attribute.
13262306a36Sopenharmony_ci */
13362306a36Sopenharmony_cistatic ssize_t pm8001_ctl_ila_version_show(struct device *cdev,
13462306a36Sopenharmony_ci	struct device_attribute *attr, char *buf)
13562306a36Sopenharmony_ci{
13662306a36Sopenharmony_ci	struct Scsi_Host *shost = class_to_shost(cdev);
13762306a36Sopenharmony_ci	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
13862306a36Sopenharmony_ci	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_ci	if (pm8001_ha->chip_id != chip_8001) {
14162306a36Sopenharmony_ci		return sysfs_emit(buf, "%02x.%02x.%02x.%02x\n",
14262306a36Sopenharmony_ci		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.ila_version >> 24),
14362306a36Sopenharmony_ci		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.ila_version >> 16),
14462306a36Sopenharmony_ci		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.ila_version >> 8),
14562306a36Sopenharmony_ci		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.ila_version));
14662306a36Sopenharmony_ci	}
14762306a36Sopenharmony_ci	return 0;
14862306a36Sopenharmony_ci}
14962306a36Sopenharmony_cistatic DEVICE_ATTR(ila_version, 0444, pm8001_ctl_ila_version_show, NULL);
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ci/**
15262306a36Sopenharmony_ci * pm8001_ctl_inactive_fw_version_show - Inactive firmware version number
15362306a36Sopenharmony_ci * @cdev: pointer to embedded class device
15462306a36Sopenharmony_ci * @attr: device attribute (unused)
15562306a36Sopenharmony_ci * @buf: the buffer returned
15662306a36Sopenharmony_ci *
15762306a36Sopenharmony_ci * A sysfs 'read-only' shost attribute.
15862306a36Sopenharmony_ci */
15962306a36Sopenharmony_cistatic ssize_t pm8001_ctl_inactive_fw_version_show(struct device *cdev,
16062306a36Sopenharmony_ci	struct device_attribute *attr, char *buf)
16162306a36Sopenharmony_ci{
16262306a36Sopenharmony_ci	struct Scsi_Host *shost = class_to_shost(cdev);
16362306a36Sopenharmony_ci	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
16462306a36Sopenharmony_ci	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
16562306a36Sopenharmony_ci
16662306a36Sopenharmony_ci	if (pm8001_ha->chip_id != chip_8001) {
16762306a36Sopenharmony_ci		return sysfs_emit(buf, "%02x.%02x.%02x.%02x\n",
16862306a36Sopenharmony_ci		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.inc_fw_version >> 24),
16962306a36Sopenharmony_ci		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.inc_fw_version >> 16),
17062306a36Sopenharmony_ci		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.inc_fw_version >> 8),
17162306a36Sopenharmony_ci		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.inc_fw_version));
17262306a36Sopenharmony_ci	}
17362306a36Sopenharmony_ci	return 0;
17462306a36Sopenharmony_ci}
17562306a36Sopenharmony_cistatic
17662306a36Sopenharmony_ciDEVICE_ATTR(inc_fw_ver, 0444, pm8001_ctl_inactive_fw_version_show, NULL);
17762306a36Sopenharmony_ci
17862306a36Sopenharmony_ci/**
17962306a36Sopenharmony_ci * pm8001_ctl_max_out_io_show - max outstanding io supported
18062306a36Sopenharmony_ci * @cdev: pointer to embedded class device
18162306a36Sopenharmony_ci * @attr: device attribute (unused)
18262306a36Sopenharmony_ci * @buf: the buffer returned
18362306a36Sopenharmony_ci *
18462306a36Sopenharmony_ci * A sysfs 'read-only' shost attribute.
18562306a36Sopenharmony_ci */
18662306a36Sopenharmony_cistatic ssize_t pm8001_ctl_max_out_io_show(struct device *cdev,
18762306a36Sopenharmony_ci	struct device_attribute *attr, char *buf)
18862306a36Sopenharmony_ci{
18962306a36Sopenharmony_ci	struct Scsi_Host *shost = class_to_shost(cdev);
19062306a36Sopenharmony_ci	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
19162306a36Sopenharmony_ci	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_ci	if (pm8001_ha->chip_id == chip_8001) {
19462306a36Sopenharmony_ci		return sysfs_emit(buf, "%d\n",
19562306a36Sopenharmony_ci			pm8001_ha->main_cfg_tbl.pm8001_tbl.max_out_io);
19662306a36Sopenharmony_ci	} else {
19762306a36Sopenharmony_ci		return sysfs_emit(buf, "%d\n",
19862306a36Sopenharmony_ci			pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_out_io);
19962306a36Sopenharmony_ci	}
20062306a36Sopenharmony_ci}
20162306a36Sopenharmony_cistatic DEVICE_ATTR(max_out_io, S_IRUGO, pm8001_ctl_max_out_io_show, NULL);
20262306a36Sopenharmony_ci/**
20362306a36Sopenharmony_ci * pm8001_ctl_max_devices_show - max devices support
20462306a36Sopenharmony_ci * @cdev: pointer to embedded class device
20562306a36Sopenharmony_ci * @attr: device attribute (unused)
20662306a36Sopenharmony_ci * @buf: the buffer returned
20762306a36Sopenharmony_ci *
20862306a36Sopenharmony_ci * A sysfs 'read-only' shost attribute.
20962306a36Sopenharmony_ci */
21062306a36Sopenharmony_cistatic ssize_t pm8001_ctl_max_devices_show(struct device *cdev,
21162306a36Sopenharmony_ci	struct device_attribute *attr, char *buf)
21262306a36Sopenharmony_ci{
21362306a36Sopenharmony_ci	struct Scsi_Host *shost = class_to_shost(cdev);
21462306a36Sopenharmony_ci	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
21562306a36Sopenharmony_ci	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
21662306a36Sopenharmony_ci
21762306a36Sopenharmony_ci	if (pm8001_ha->chip_id == chip_8001) {
21862306a36Sopenharmony_ci		return sysfs_emit(buf, "%04d\n",
21962306a36Sopenharmony_ci			(u16)(pm8001_ha->main_cfg_tbl.pm8001_tbl.max_sgl >> 16));
22062306a36Sopenharmony_ci	} else {
22162306a36Sopenharmony_ci		return sysfs_emit(buf, "%04d\n",
22262306a36Sopenharmony_ci			(u16)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_sgl >> 16));
22362306a36Sopenharmony_ci	}
22462306a36Sopenharmony_ci}
22562306a36Sopenharmony_cistatic DEVICE_ATTR(max_devices, S_IRUGO, pm8001_ctl_max_devices_show, NULL);
22662306a36Sopenharmony_ci/**
22762306a36Sopenharmony_ci * pm8001_ctl_max_sg_list_show - max sg list supported iff not 0.0 for no
22862306a36Sopenharmony_ci * hardware limitation
22962306a36Sopenharmony_ci * @cdev: pointer to embedded class device
23062306a36Sopenharmony_ci * @attr: device attribute (unused)
23162306a36Sopenharmony_ci * @buf: the buffer returned
23262306a36Sopenharmony_ci *
23362306a36Sopenharmony_ci * A sysfs 'read-only' shost attribute.
23462306a36Sopenharmony_ci */
23562306a36Sopenharmony_cistatic ssize_t pm8001_ctl_max_sg_list_show(struct device *cdev,
23662306a36Sopenharmony_ci	struct device_attribute *attr, char *buf)
23762306a36Sopenharmony_ci{
23862306a36Sopenharmony_ci	struct Scsi_Host *shost = class_to_shost(cdev);
23962306a36Sopenharmony_ci	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
24062306a36Sopenharmony_ci	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
24162306a36Sopenharmony_ci
24262306a36Sopenharmony_ci	if (pm8001_ha->chip_id == chip_8001) {
24362306a36Sopenharmony_ci		return sysfs_emit(buf, "%04d\n",
24462306a36Sopenharmony_ci			pm8001_ha->main_cfg_tbl.pm8001_tbl.max_sgl & 0x0000FFFF);
24562306a36Sopenharmony_ci	} else {
24662306a36Sopenharmony_ci		return sysfs_emit(buf, "%04d\n",
24762306a36Sopenharmony_ci			pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_sgl & 0x0000FFFF);
24862306a36Sopenharmony_ci	}
24962306a36Sopenharmony_ci}
25062306a36Sopenharmony_cistatic DEVICE_ATTR(max_sg_list, S_IRUGO, pm8001_ctl_max_sg_list_show, NULL);
25162306a36Sopenharmony_ci
25262306a36Sopenharmony_ci#define SAS_1_0 0x1
25362306a36Sopenharmony_ci#define SAS_1_1 0x2
25462306a36Sopenharmony_ci#define SAS_2_0 0x4
25562306a36Sopenharmony_ci
25662306a36Sopenharmony_cistatic ssize_t
25762306a36Sopenharmony_cishow_sas_spec_support_status(unsigned int mode, char *buf)
25862306a36Sopenharmony_ci{
25962306a36Sopenharmony_ci	ssize_t len = 0;
26062306a36Sopenharmony_ci
26162306a36Sopenharmony_ci	if (mode & SAS_1_1)
26262306a36Sopenharmony_ci		len = sprintf(buf, "%s", "SAS1.1");
26362306a36Sopenharmony_ci	if (mode & SAS_2_0)
26462306a36Sopenharmony_ci		len += sprintf(buf + len, "%s%s", len ? ", " : "", "SAS2.0");
26562306a36Sopenharmony_ci	len += sprintf(buf + len, "\n");
26662306a36Sopenharmony_ci
26762306a36Sopenharmony_ci	return len;
26862306a36Sopenharmony_ci}
26962306a36Sopenharmony_ci
27062306a36Sopenharmony_ci/**
27162306a36Sopenharmony_ci * pm8001_ctl_sas_spec_support_show - sas spec supported
27262306a36Sopenharmony_ci * @cdev: pointer to embedded class device
27362306a36Sopenharmony_ci * @attr: device attribute (unused)
27462306a36Sopenharmony_ci * @buf: the buffer returned
27562306a36Sopenharmony_ci *
27662306a36Sopenharmony_ci * A sysfs 'read-only' shost attribute.
27762306a36Sopenharmony_ci */
27862306a36Sopenharmony_cistatic ssize_t pm8001_ctl_sas_spec_support_show(struct device *cdev,
27962306a36Sopenharmony_ci	struct device_attribute *attr, char *buf)
28062306a36Sopenharmony_ci{
28162306a36Sopenharmony_ci	unsigned int mode;
28262306a36Sopenharmony_ci	struct Scsi_Host *shost = class_to_shost(cdev);
28362306a36Sopenharmony_ci	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
28462306a36Sopenharmony_ci	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
28562306a36Sopenharmony_ci	/* fe000000 means supports SAS2.1 */
28662306a36Sopenharmony_ci	if (pm8001_ha->chip_id == chip_8001)
28762306a36Sopenharmony_ci		mode = (pm8001_ha->main_cfg_tbl.pm8001_tbl.ctrl_cap_flag &
28862306a36Sopenharmony_ci							0xfe000000)>>25;
28962306a36Sopenharmony_ci	else
29062306a36Sopenharmony_ci		/* fe000000 means supports SAS2.1 */
29162306a36Sopenharmony_ci		mode = (pm8001_ha->main_cfg_tbl.pm80xx_tbl.ctrl_cap_flag &
29262306a36Sopenharmony_ci							0xfe000000)>>25;
29362306a36Sopenharmony_ci	return show_sas_spec_support_status(mode, buf);
29462306a36Sopenharmony_ci}
29562306a36Sopenharmony_cistatic DEVICE_ATTR(sas_spec_support, S_IRUGO,
29662306a36Sopenharmony_ci		   pm8001_ctl_sas_spec_support_show, NULL);
29762306a36Sopenharmony_ci
29862306a36Sopenharmony_ci/**
29962306a36Sopenharmony_ci * pm8001_ctl_host_sas_address_show - sas address
30062306a36Sopenharmony_ci * @cdev: pointer to embedded class device
30162306a36Sopenharmony_ci * @attr: device attribute (unused)
30262306a36Sopenharmony_ci * @buf: the buffer returned
30362306a36Sopenharmony_ci *
30462306a36Sopenharmony_ci * This is the controller sas address
30562306a36Sopenharmony_ci *
30662306a36Sopenharmony_ci * A sysfs 'read-only' shost attribute.
30762306a36Sopenharmony_ci */
30862306a36Sopenharmony_cistatic ssize_t pm8001_ctl_host_sas_address_show(struct device *cdev,
30962306a36Sopenharmony_ci	struct device_attribute *attr, char *buf)
31062306a36Sopenharmony_ci{
31162306a36Sopenharmony_ci	struct Scsi_Host *shost = class_to_shost(cdev);
31262306a36Sopenharmony_ci	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
31362306a36Sopenharmony_ci	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
31462306a36Sopenharmony_ci	return sysfs_emit(buf, "0x%016llx\n",
31562306a36Sopenharmony_ci			be64_to_cpu(*(__be64 *)pm8001_ha->sas_addr));
31662306a36Sopenharmony_ci}
31762306a36Sopenharmony_cistatic DEVICE_ATTR(host_sas_address, S_IRUGO,
31862306a36Sopenharmony_ci		   pm8001_ctl_host_sas_address_show, NULL);
31962306a36Sopenharmony_ci
32062306a36Sopenharmony_ci/**
32162306a36Sopenharmony_ci * pm8001_ctl_logging_level_show - logging level
32262306a36Sopenharmony_ci * @cdev: pointer to embedded class device
32362306a36Sopenharmony_ci * @attr: device attribute (unused)
32462306a36Sopenharmony_ci * @buf: the buffer returned
32562306a36Sopenharmony_ci *
32662306a36Sopenharmony_ci * A sysfs 'read/write' shost attribute.
32762306a36Sopenharmony_ci */
32862306a36Sopenharmony_cistatic ssize_t pm8001_ctl_logging_level_show(struct device *cdev,
32962306a36Sopenharmony_ci	struct device_attribute *attr, char *buf)
33062306a36Sopenharmony_ci{
33162306a36Sopenharmony_ci	struct Scsi_Host *shost = class_to_shost(cdev);
33262306a36Sopenharmony_ci	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
33362306a36Sopenharmony_ci	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
33462306a36Sopenharmony_ci
33562306a36Sopenharmony_ci	return sysfs_emit(buf, "%08xh\n", pm8001_ha->logging_level);
33662306a36Sopenharmony_ci}
33762306a36Sopenharmony_ci
33862306a36Sopenharmony_cistatic ssize_t pm8001_ctl_logging_level_store(struct device *cdev,
33962306a36Sopenharmony_ci	struct device_attribute *attr, const char *buf, size_t count)
34062306a36Sopenharmony_ci{
34162306a36Sopenharmony_ci	struct Scsi_Host *shost = class_to_shost(cdev);
34262306a36Sopenharmony_ci	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
34362306a36Sopenharmony_ci	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
34462306a36Sopenharmony_ci	int val = 0;
34562306a36Sopenharmony_ci
34662306a36Sopenharmony_ci	if (sscanf(buf, "%x", &val) != 1)
34762306a36Sopenharmony_ci		return -EINVAL;
34862306a36Sopenharmony_ci
34962306a36Sopenharmony_ci	pm8001_ha->logging_level = val;
35062306a36Sopenharmony_ci	return strlen(buf);
35162306a36Sopenharmony_ci}
35262306a36Sopenharmony_ci
35362306a36Sopenharmony_cistatic DEVICE_ATTR(logging_level, S_IRUGO | S_IWUSR,
35462306a36Sopenharmony_ci	pm8001_ctl_logging_level_show, pm8001_ctl_logging_level_store);
35562306a36Sopenharmony_ci/**
35662306a36Sopenharmony_ci * pm8001_ctl_aap_log_show - aap1 event log
35762306a36Sopenharmony_ci * @cdev: pointer to embedded class device
35862306a36Sopenharmony_ci * @attr: device attribute (unused)
35962306a36Sopenharmony_ci * @buf: the buffer returned
36062306a36Sopenharmony_ci *
36162306a36Sopenharmony_ci * A sysfs 'read-only' shost attribute.
36262306a36Sopenharmony_ci */
36362306a36Sopenharmony_cistatic ssize_t pm8001_ctl_aap_log_show(struct device *cdev,
36462306a36Sopenharmony_ci	struct device_attribute *attr, char *buf)
36562306a36Sopenharmony_ci{
36662306a36Sopenharmony_ci	struct Scsi_Host *shost = class_to_shost(cdev);
36762306a36Sopenharmony_ci	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
36862306a36Sopenharmony_ci	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
36962306a36Sopenharmony_ci	u8 *ptr = (u8 *)pm8001_ha->memoryMap.region[AAP1].virt_ptr;
37062306a36Sopenharmony_ci	int i;
37162306a36Sopenharmony_ci
37262306a36Sopenharmony_ci	char *str = buf;
37362306a36Sopenharmony_ci	int max = 2;
37462306a36Sopenharmony_ci	for (i = 0; i < max; i++) {
37562306a36Sopenharmony_ci		str += sprintf(str, "0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x"
37662306a36Sopenharmony_ci			       "0x%08x 0x%08x\n",
37762306a36Sopenharmony_ci			       pm8001_ctl_aap1_memmap(ptr, i, 0),
37862306a36Sopenharmony_ci			       pm8001_ctl_aap1_memmap(ptr, i, 4),
37962306a36Sopenharmony_ci			       pm8001_ctl_aap1_memmap(ptr, i, 8),
38062306a36Sopenharmony_ci			       pm8001_ctl_aap1_memmap(ptr, i, 12),
38162306a36Sopenharmony_ci			       pm8001_ctl_aap1_memmap(ptr, i, 16),
38262306a36Sopenharmony_ci			       pm8001_ctl_aap1_memmap(ptr, i, 20),
38362306a36Sopenharmony_ci			       pm8001_ctl_aap1_memmap(ptr, i, 24),
38462306a36Sopenharmony_ci			       pm8001_ctl_aap1_memmap(ptr, i, 28));
38562306a36Sopenharmony_ci	}
38662306a36Sopenharmony_ci
38762306a36Sopenharmony_ci	return str - buf;
38862306a36Sopenharmony_ci}
38962306a36Sopenharmony_cistatic DEVICE_ATTR(aap_log, S_IRUGO, pm8001_ctl_aap_log_show, NULL);
39062306a36Sopenharmony_ci/**
39162306a36Sopenharmony_ci * pm8001_ctl_ib_queue_log_show - Out bound Queue log
39262306a36Sopenharmony_ci * @cdev:pointer to embedded class device
39362306a36Sopenharmony_ci * @attr: device attribute (unused)
39462306a36Sopenharmony_ci * @buf: the buffer returned
39562306a36Sopenharmony_ci *
39662306a36Sopenharmony_ci * A sysfs 'read-only' shost attribute.
39762306a36Sopenharmony_ci */
39862306a36Sopenharmony_cistatic ssize_t pm8001_ctl_ib_queue_log_show(struct device *cdev,
39962306a36Sopenharmony_ci	struct device_attribute *attr, char *buf)
40062306a36Sopenharmony_ci{
40162306a36Sopenharmony_ci	struct Scsi_Host *shost = class_to_shost(cdev);
40262306a36Sopenharmony_ci	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
40362306a36Sopenharmony_ci	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
40462306a36Sopenharmony_ci	int offset;
40562306a36Sopenharmony_ci	char *str = buf;
40662306a36Sopenharmony_ci	int start = 0;
40762306a36Sopenharmony_ci	u32 ib_offset = pm8001_ha->ib_offset;
40862306a36Sopenharmony_ci	u32 queue_size = pm8001_ha->max_q_num * PM8001_MPI_QUEUE * 128;
40962306a36Sopenharmony_ci#define IB_MEMMAP(c)	\
41062306a36Sopenharmony_ci		(*(u32 *)((u8 *)pm8001_ha->	\
41162306a36Sopenharmony_ci		memoryMap.region[ib_offset].virt_ptr +	\
41262306a36Sopenharmony_ci		pm8001_ha->evtlog_ib_offset + (c)))
41362306a36Sopenharmony_ci
41462306a36Sopenharmony_ci	for (offset = 0; offset < IB_OB_READ_TIMES; offset++) {
41562306a36Sopenharmony_ci		str += sprintf(str, "0x%08x\n", IB_MEMMAP(start));
41662306a36Sopenharmony_ci		start = start + 4;
41762306a36Sopenharmony_ci	}
41862306a36Sopenharmony_ci	pm8001_ha->evtlog_ib_offset += SYSFS_OFFSET;
41962306a36Sopenharmony_ci	if (((pm8001_ha->evtlog_ib_offset) % queue_size) == 0)
42062306a36Sopenharmony_ci		pm8001_ha->evtlog_ib_offset = 0;
42162306a36Sopenharmony_ci
42262306a36Sopenharmony_ci	return str - buf;
42362306a36Sopenharmony_ci}
42462306a36Sopenharmony_ci
42562306a36Sopenharmony_cistatic DEVICE_ATTR(ib_log, S_IRUGO, pm8001_ctl_ib_queue_log_show, NULL);
42662306a36Sopenharmony_ci/**
42762306a36Sopenharmony_ci * pm8001_ctl_ob_queue_log_show - Out bound Queue log
42862306a36Sopenharmony_ci * @cdev:pointer to embedded class device
42962306a36Sopenharmony_ci * @attr: device attribute (unused)
43062306a36Sopenharmony_ci * @buf: the buffer returned
43162306a36Sopenharmony_ci *
43262306a36Sopenharmony_ci * A sysfs 'read-only' shost attribute.
43362306a36Sopenharmony_ci */
43462306a36Sopenharmony_ci
43562306a36Sopenharmony_cistatic ssize_t pm8001_ctl_ob_queue_log_show(struct device *cdev,
43662306a36Sopenharmony_ci	struct device_attribute *attr, char *buf)
43762306a36Sopenharmony_ci{
43862306a36Sopenharmony_ci	struct Scsi_Host *shost = class_to_shost(cdev);
43962306a36Sopenharmony_ci	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
44062306a36Sopenharmony_ci	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
44162306a36Sopenharmony_ci	int offset;
44262306a36Sopenharmony_ci	char *str = buf;
44362306a36Sopenharmony_ci	int start = 0;
44462306a36Sopenharmony_ci	u32 ob_offset = pm8001_ha->ob_offset;
44562306a36Sopenharmony_ci	u32 queue_size = pm8001_ha->max_q_num * PM8001_MPI_QUEUE * 128;
44662306a36Sopenharmony_ci#define OB_MEMMAP(c)	\
44762306a36Sopenharmony_ci		(*(u32 *)((u8 *)pm8001_ha->	\
44862306a36Sopenharmony_ci		memoryMap.region[ob_offset].virt_ptr +	\
44962306a36Sopenharmony_ci		pm8001_ha->evtlog_ob_offset + (c)))
45062306a36Sopenharmony_ci
45162306a36Sopenharmony_ci	for (offset = 0; offset < IB_OB_READ_TIMES; offset++) {
45262306a36Sopenharmony_ci		str += sprintf(str, "0x%08x\n", OB_MEMMAP(start));
45362306a36Sopenharmony_ci		start = start + 4;
45462306a36Sopenharmony_ci	}
45562306a36Sopenharmony_ci	pm8001_ha->evtlog_ob_offset += SYSFS_OFFSET;
45662306a36Sopenharmony_ci	if (((pm8001_ha->evtlog_ob_offset) % queue_size) == 0)
45762306a36Sopenharmony_ci		pm8001_ha->evtlog_ob_offset = 0;
45862306a36Sopenharmony_ci
45962306a36Sopenharmony_ci	return str - buf;
46062306a36Sopenharmony_ci}
46162306a36Sopenharmony_cistatic DEVICE_ATTR(ob_log, S_IRUGO, pm8001_ctl_ob_queue_log_show, NULL);
46262306a36Sopenharmony_ci/**
46362306a36Sopenharmony_ci * pm8001_ctl_bios_version_show - Bios version Display
46462306a36Sopenharmony_ci * @cdev:pointer to embedded class device
46562306a36Sopenharmony_ci * @attr: device attribute (unused)
46662306a36Sopenharmony_ci * @buf:the buffer returned
46762306a36Sopenharmony_ci *
46862306a36Sopenharmony_ci * A sysfs 'read-only' shost attribute.
46962306a36Sopenharmony_ci */
47062306a36Sopenharmony_cistatic ssize_t pm8001_ctl_bios_version_show(struct device *cdev,
47162306a36Sopenharmony_ci	struct device_attribute *attr, char *buf)
47262306a36Sopenharmony_ci{
47362306a36Sopenharmony_ci	struct Scsi_Host *shost = class_to_shost(cdev);
47462306a36Sopenharmony_ci	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
47562306a36Sopenharmony_ci	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
47662306a36Sopenharmony_ci	char *str = buf;
47762306a36Sopenharmony_ci	int bios_index;
47862306a36Sopenharmony_ci	DECLARE_COMPLETION_ONSTACK(completion);
47962306a36Sopenharmony_ci	struct pm8001_ioctl_payload payload;
48062306a36Sopenharmony_ci
48162306a36Sopenharmony_ci	pm8001_ha->nvmd_completion = &completion;
48262306a36Sopenharmony_ci	payload.minor_function = 7;
48362306a36Sopenharmony_ci	payload.offset = 0;
48462306a36Sopenharmony_ci	payload.rd_length = 4096;
48562306a36Sopenharmony_ci	payload.func_specific = kzalloc(4096, GFP_KERNEL);
48662306a36Sopenharmony_ci	if (!payload.func_specific)
48762306a36Sopenharmony_ci		return -ENOMEM;
48862306a36Sopenharmony_ci	if (PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload)) {
48962306a36Sopenharmony_ci		kfree(payload.func_specific);
49062306a36Sopenharmony_ci		return -ENOMEM;
49162306a36Sopenharmony_ci	}
49262306a36Sopenharmony_ci	wait_for_completion(&completion);
49362306a36Sopenharmony_ci	for (bios_index = BIOSOFFSET; bios_index < BIOS_OFFSET_LIMIT;
49462306a36Sopenharmony_ci		bios_index++)
49562306a36Sopenharmony_ci		str += sprintf(str, "%c",
49662306a36Sopenharmony_ci			*(payload.func_specific+bios_index));
49762306a36Sopenharmony_ci	kfree(payload.func_specific);
49862306a36Sopenharmony_ci	return str - buf;
49962306a36Sopenharmony_ci}
50062306a36Sopenharmony_cistatic DEVICE_ATTR(bios_version, S_IRUGO, pm8001_ctl_bios_version_show, NULL);
50162306a36Sopenharmony_ci/**
50262306a36Sopenharmony_ci * event_log_size_show - event log size
50362306a36Sopenharmony_ci * @cdev: pointer to embedded class device
50462306a36Sopenharmony_ci * @attr: device attribute (unused)
50562306a36Sopenharmony_ci * @buf: the buffer returned
50662306a36Sopenharmony_ci *
50762306a36Sopenharmony_ci * A sysfs read  shost attribute.
50862306a36Sopenharmony_ci */
50962306a36Sopenharmony_cistatic ssize_t event_log_size_show(struct device *cdev,
51062306a36Sopenharmony_ci	struct device_attribute *attr, char *buf)
51162306a36Sopenharmony_ci{
51262306a36Sopenharmony_ci	struct Scsi_Host *shost = class_to_shost(cdev);
51362306a36Sopenharmony_ci	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
51462306a36Sopenharmony_ci	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
51562306a36Sopenharmony_ci
51662306a36Sopenharmony_ci	return sysfs_emit(buf, "%d\n",
51762306a36Sopenharmony_ci		pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_size);
51862306a36Sopenharmony_ci}
51962306a36Sopenharmony_cistatic DEVICE_ATTR_RO(event_log_size);
52062306a36Sopenharmony_ci/**
52162306a36Sopenharmony_ci * pm8001_ctl_iop_log_show - IOP event log
52262306a36Sopenharmony_ci * @cdev: pointer to embedded class device
52362306a36Sopenharmony_ci * @attr: device attribute (unused)
52462306a36Sopenharmony_ci * @buf: the buffer returned
52562306a36Sopenharmony_ci *
52662306a36Sopenharmony_ci * A sysfs 'read-only' shost attribute.
52762306a36Sopenharmony_ci */
52862306a36Sopenharmony_cistatic ssize_t pm8001_ctl_iop_log_show(struct device *cdev,
52962306a36Sopenharmony_ci	struct device_attribute *attr, char *buf)
53062306a36Sopenharmony_ci{
53162306a36Sopenharmony_ci	struct Scsi_Host *shost = class_to_shost(cdev);
53262306a36Sopenharmony_ci	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
53362306a36Sopenharmony_ci	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
53462306a36Sopenharmony_ci	char *str = buf;
53562306a36Sopenharmony_ci	u32 read_size =
53662306a36Sopenharmony_ci		pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_size / 1024;
53762306a36Sopenharmony_ci	static u32 start, end, count;
53862306a36Sopenharmony_ci	u32 max_read_times = 32;
53962306a36Sopenharmony_ci	u32 max_count = (read_size * 1024) / (max_read_times * 4);
54062306a36Sopenharmony_ci	u32 *temp = (u32 *)pm8001_ha->memoryMap.region[IOP].virt_ptr;
54162306a36Sopenharmony_ci
54262306a36Sopenharmony_ci	if ((count % max_count) == 0) {
54362306a36Sopenharmony_ci		start = 0;
54462306a36Sopenharmony_ci		end = max_read_times;
54562306a36Sopenharmony_ci		count = 0;
54662306a36Sopenharmony_ci	} else {
54762306a36Sopenharmony_ci		start = end;
54862306a36Sopenharmony_ci		end = end + max_read_times;
54962306a36Sopenharmony_ci	}
55062306a36Sopenharmony_ci
55162306a36Sopenharmony_ci	for (; start < end; start++)
55262306a36Sopenharmony_ci		str += sprintf(str, "%08x ", *(temp+start));
55362306a36Sopenharmony_ci	count++;
55462306a36Sopenharmony_ci	return str - buf;
55562306a36Sopenharmony_ci}
55662306a36Sopenharmony_cistatic DEVICE_ATTR(iop_log, S_IRUGO, pm8001_ctl_iop_log_show, NULL);
55762306a36Sopenharmony_ci
55862306a36Sopenharmony_ci/**
55962306a36Sopenharmony_ci * pm8001_ctl_fatal_log_show - fatal error logging
56062306a36Sopenharmony_ci * @cdev:pointer to embedded class device
56162306a36Sopenharmony_ci * @attr: device attribute
56262306a36Sopenharmony_ci * @buf: the buffer returned
56362306a36Sopenharmony_ci *
56462306a36Sopenharmony_ci * A sysfs 'read-only' shost attribute.
56562306a36Sopenharmony_ci */
56662306a36Sopenharmony_ci
56762306a36Sopenharmony_cistatic ssize_t pm8001_ctl_fatal_log_show(struct device *cdev,
56862306a36Sopenharmony_ci	struct device_attribute *attr, char *buf)
56962306a36Sopenharmony_ci{
57062306a36Sopenharmony_ci	ssize_t count;
57162306a36Sopenharmony_ci
57262306a36Sopenharmony_ci	count = pm80xx_get_fatal_dump(cdev, attr, buf);
57362306a36Sopenharmony_ci	return count;
57462306a36Sopenharmony_ci}
57562306a36Sopenharmony_ci
57662306a36Sopenharmony_cistatic DEVICE_ATTR(fatal_log, S_IRUGO, pm8001_ctl_fatal_log_show, NULL);
57762306a36Sopenharmony_ci
57862306a36Sopenharmony_ci/**
57962306a36Sopenharmony_ci * non_fatal_log_show - non fatal error logging
58062306a36Sopenharmony_ci * @cdev:pointer to embedded class device
58162306a36Sopenharmony_ci * @attr: device attribute
58262306a36Sopenharmony_ci * @buf: the buffer returned
58362306a36Sopenharmony_ci *
58462306a36Sopenharmony_ci * A sysfs 'read-only' shost attribute.
58562306a36Sopenharmony_ci */
58662306a36Sopenharmony_cistatic ssize_t non_fatal_log_show(struct device *cdev,
58762306a36Sopenharmony_ci	struct device_attribute *attr, char *buf)
58862306a36Sopenharmony_ci{
58962306a36Sopenharmony_ci	u32 count;
59062306a36Sopenharmony_ci
59162306a36Sopenharmony_ci	count = pm80xx_get_non_fatal_dump(cdev, attr, buf);
59262306a36Sopenharmony_ci	return count;
59362306a36Sopenharmony_ci}
59462306a36Sopenharmony_cistatic DEVICE_ATTR_RO(non_fatal_log);
59562306a36Sopenharmony_ci
59662306a36Sopenharmony_cistatic ssize_t non_fatal_count_show(struct device *cdev,
59762306a36Sopenharmony_ci		struct device_attribute *attr, char *buf)
59862306a36Sopenharmony_ci{
59962306a36Sopenharmony_ci	struct Scsi_Host *shost = class_to_shost(cdev);
60062306a36Sopenharmony_ci	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
60162306a36Sopenharmony_ci	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
60262306a36Sopenharmony_ci
60362306a36Sopenharmony_ci	return sysfs_emit(buf, "%08x\n",
60462306a36Sopenharmony_ci			pm8001_ha->non_fatal_count);
60562306a36Sopenharmony_ci}
60662306a36Sopenharmony_ci
60762306a36Sopenharmony_cistatic ssize_t non_fatal_count_store(struct device *cdev,
60862306a36Sopenharmony_ci		struct device_attribute *attr, const char *buf, size_t count)
60962306a36Sopenharmony_ci{
61062306a36Sopenharmony_ci	struct Scsi_Host *shost = class_to_shost(cdev);
61162306a36Sopenharmony_ci	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
61262306a36Sopenharmony_ci	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
61362306a36Sopenharmony_ci	int val = 0;
61462306a36Sopenharmony_ci
61562306a36Sopenharmony_ci	if (kstrtoint(buf, 16, &val) != 0)
61662306a36Sopenharmony_ci		return -EINVAL;
61762306a36Sopenharmony_ci
61862306a36Sopenharmony_ci	pm8001_ha->non_fatal_count = val;
61962306a36Sopenharmony_ci	return strlen(buf);
62062306a36Sopenharmony_ci}
62162306a36Sopenharmony_cistatic DEVICE_ATTR_RW(non_fatal_count);
62262306a36Sopenharmony_ci
62362306a36Sopenharmony_ci/**
62462306a36Sopenharmony_ci * pm8001_ctl_gsm_log_show - gsm dump collection
62562306a36Sopenharmony_ci * @cdev:pointer to embedded class device
62662306a36Sopenharmony_ci * @attr: device attribute (unused)
62762306a36Sopenharmony_ci * @buf: the buffer returned
62862306a36Sopenharmony_ci *
62962306a36Sopenharmony_ci * A sysfs 'read-only' shost attribute.
63062306a36Sopenharmony_ci */
63162306a36Sopenharmony_cistatic ssize_t pm8001_ctl_gsm_log_show(struct device *cdev,
63262306a36Sopenharmony_ci	struct device_attribute *attr, char *buf)
63362306a36Sopenharmony_ci{
63462306a36Sopenharmony_ci	ssize_t count;
63562306a36Sopenharmony_ci
63662306a36Sopenharmony_ci	count = pm8001_get_gsm_dump(cdev, SYSFS_OFFSET, buf);
63762306a36Sopenharmony_ci	return count;
63862306a36Sopenharmony_ci}
63962306a36Sopenharmony_ci
64062306a36Sopenharmony_cistatic DEVICE_ATTR(gsm_log, S_IRUGO, pm8001_ctl_gsm_log_show, NULL);
64162306a36Sopenharmony_ci
64262306a36Sopenharmony_ci#define FLASH_CMD_NONE      0x00
64362306a36Sopenharmony_ci#define FLASH_CMD_UPDATE    0x01
64462306a36Sopenharmony_ci#define FLASH_CMD_SET_NVMD    0x02
64562306a36Sopenharmony_ci
64662306a36Sopenharmony_cistruct flash_command {
64762306a36Sopenharmony_ci     u8      command[8];
64862306a36Sopenharmony_ci     int     code;
64962306a36Sopenharmony_ci};
65062306a36Sopenharmony_ci
65162306a36Sopenharmony_cistatic const struct flash_command flash_command_table[] = {
65262306a36Sopenharmony_ci     {"set_nvmd",    FLASH_CMD_SET_NVMD},
65362306a36Sopenharmony_ci     {"update",      FLASH_CMD_UPDATE},
65462306a36Sopenharmony_ci     {"",            FLASH_CMD_NONE} /* Last entry should be NULL. */
65562306a36Sopenharmony_ci};
65662306a36Sopenharmony_ci
65762306a36Sopenharmony_cistruct error_fw {
65862306a36Sopenharmony_ci     char    *reason;
65962306a36Sopenharmony_ci     int     err_code;
66062306a36Sopenharmony_ci};
66162306a36Sopenharmony_ci
66262306a36Sopenharmony_cistatic const struct error_fw flash_error_table[] = {
66362306a36Sopenharmony_ci     {"Failed to open fw image file",	FAIL_OPEN_BIOS_FILE},
66462306a36Sopenharmony_ci     {"image header mismatch",		FLASH_UPDATE_HDR_ERR},
66562306a36Sopenharmony_ci     {"image offset mismatch",		FLASH_UPDATE_OFFSET_ERR},
66662306a36Sopenharmony_ci     {"image CRC Error",		FLASH_UPDATE_CRC_ERR},
66762306a36Sopenharmony_ci     {"image length Error.",		FLASH_UPDATE_LENGTH_ERR},
66862306a36Sopenharmony_ci     {"Failed to program flash chip",	FLASH_UPDATE_HW_ERR},
66962306a36Sopenharmony_ci     {"Flash chip not supported.",	FLASH_UPDATE_DNLD_NOT_SUPPORTED},
67062306a36Sopenharmony_ci     {"Flash update disabled.",		FLASH_UPDATE_DISABLED},
67162306a36Sopenharmony_ci     {"Flash in progress",		FLASH_IN_PROGRESS},
67262306a36Sopenharmony_ci     {"Image file size Error",		FAIL_FILE_SIZE},
67362306a36Sopenharmony_ci     {"Input parameter error",		FAIL_PARAMETERS},
67462306a36Sopenharmony_ci     {"Out of memory",			FAIL_OUT_MEMORY},
67562306a36Sopenharmony_ci     {"OK", 0}	/* Last entry err_code = 0. */
67662306a36Sopenharmony_ci};
67762306a36Sopenharmony_ci
67862306a36Sopenharmony_cistatic int pm8001_set_nvmd(struct pm8001_hba_info *pm8001_ha)
67962306a36Sopenharmony_ci{
68062306a36Sopenharmony_ci	struct pm8001_ioctl_payload	*payload;
68162306a36Sopenharmony_ci	DECLARE_COMPLETION_ONSTACK(completion);
68262306a36Sopenharmony_ci	u8		*ioctlbuffer;
68362306a36Sopenharmony_ci	u32		ret;
68462306a36Sopenharmony_ci	u32		length = 1024 * 5 + sizeof(*payload) - 1;
68562306a36Sopenharmony_ci
68662306a36Sopenharmony_ci	if (pm8001_ha->fw_image->size > 4096) {
68762306a36Sopenharmony_ci		pm8001_ha->fw_status = FAIL_FILE_SIZE;
68862306a36Sopenharmony_ci		return -EFAULT;
68962306a36Sopenharmony_ci	}
69062306a36Sopenharmony_ci
69162306a36Sopenharmony_ci	ioctlbuffer = kzalloc(length, GFP_KERNEL);
69262306a36Sopenharmony_ci	if (!ioctlbuffer) {
69362306a36Sopenharmony_ci		pm8001_ha->fw_status = FAIL_OUT_MEMORY;
69462306a36Sopenharmony_ci		return -ENOMEM;
69562306a36Sopenharmony_ci	}
69662306a36Sopenharmony_ci	payload = (struct pm8001_ioctl_payload *)ioctlbuffer;
69762306a36Sopenharmony_ci	memcpy((u8 *)&payload->func_specific, (u8 *)pm8001_ha->fw_image->data,
69862306a36Sopenharmony_ci				pm8001_ha->fw_image->size);
69962306a36Sopenharmony_ci	payload->wr_length = pm8001_ha->fw_image->size;
70062306a36Sopenharmony_ci	payload->id = 0;
70162306a36Sopenharmony_ci	payload->minor_function = 0x1;
70262306a36Sopenharmony_ci	pm8001_ha->nvmd_completion = &completion;
70362306a36Sopenharmony_ci	ret = PM8001_CHIP_DISP->set_nvmd_req(pm8001_ha, payload);
70462306a36Sopenharmony_ci	if (ret) {
70562306a36Sopenharmony_ci		pm8001_ha->fw_status = FAIL_OUT_MEMORY;
70662306a36Sopenharmony_ci		goto out;
70762306a36Sopenharmony_ci	}
70862306a36Sopenharmony_ci	wait_for_completion(&completion);
70962306a36Sopenharmony_ciout:
71062306a36Sopenharmony_ci	kfree(ioctlbuffer);
71162306a36Sopenharmony_ci	return ret;
71262306a36Sopenharmony_ci}
71362306a36Sopenharmony_ci
71462306a36Sopenharmony_cistatic int pm8001_update_flash(struct pm8001_hba_info *pm8001_ha)
71562306a36Sopenharmony_ci{
71662306a36Sopenharmony_ci	struct pm8001_ioctl_payload	*payload;
71762306a36Sopenharmony_ci	DECLARE_COMPLETION_ONSTACK(completion);
71862306a36Sopenharmony_ci	u8		*ioctlbuffer;
71962306a36Sopenharmony_ci	struct fw_control_info	*fwControl;
72062306a36Sopenharmony_ci	__be32		partitionSizeTmp;
72162306a36Sopenharmony_ci	u32		partitionSize;
72262306a36Sopenharmony_ci	u32		loopNumber, loopcount;
72362306a36Sopenharmony_ci	struct pm8001_fw_image_header *image_hdr;
72462306a36Sopenharmony_ci	u32		sizeRead = 0;
72562306a36Sopenharmony_ci	u32		ret = 0;
72662306a36Sopenharmony_ci	u32		length = 1024 * 16 + sizeof(*payload) - 1;
72762306a36Sopenharmony_ci	u32		fc_len;
72862306a36Sopenharmony_ci	u8		*read_buf;
72962306a36Sopenharmony_ci
73062306a36Sopenharmony_ci	if (pm8001_ha->fw_image->size < 28) {
73162306a36Sopenharmony_ci		pm8001_ha->fw_status = FAIL_FILE_SIZE;
73262306a36Sopenharmony_ci		return -EFAULT;
73362306a36Sopenharmony_ci	}
73462306a36Sopenharmony_ci	ioctlbuffer = kzalloc(length, GFP_KERNEL);
73562306a36Sopenharmony_ci	if (!ioctlbuffer) {
73662306a36Sopenharmony_ci		pm8001_ha->fw_status = FAIL_OUT_MEMORY;
73762306a36Sopenharmony_ci		return -ENOMEM;
73862306a36Sopenharmony_ci	}
73962306a36Sopenharmony_ci	image_hdr = (struct pm8001_fw_image_header *)pm8001_ha->fw_image->data;
74062306a36Sopenharmony_ci	while (sizeRead < pm8001_ha->fw_image->size) {
74162306a36Sopenharmony_ci		partitionSizeTmp =
74262306a36Sopenharmony_ci			*(__be32 *)((u8 *)&image_hdr->image_length + sizeRead);
74362306a36Sopenharmony_ci		partitionSize = be32_to_cpu(partitionSizeTmp);
74462306a36Sopenharmony_ci		loopcount = DIV_ROUND_UP(partitionSize + HEADER_LEN,
74562306a36Sopenharmony_ci					IOCTL_BUF_SIZE);
74662306a36Sopenharmony_ci		for (loopNumber = 0; loopNumber < loopcount; loopNumber++) {
74762306a36Sopenharmony_ci			payload = (struct pm8001_ioctl_payload *)ioctlbuffer;
74862306a36Sopenharmony_ci			payload->wr_length = 1024*16;
74962306a36Sopenharmony_ci			payload->id = 0;
75062306a36Sopenharmony_ci			fwControl =
75162306a36Sopenharmony_ci			      (struct fw_control_info *)&payload->func_specific;
75262306a36Sopenharmony_ci			fwControl->len = IOCTL_BUF_SIZE;   /* IN */
75362306a36Sopenharmony_ci			fwControl->size = partitionSize + HEADER_LEN;/* IN */
75462306a36Sopenharmony_ci			fwControl->retcode = 0;/* OUT */
75562306a36Sopenharmony_ci			fwControl->offset = loopNumber * IOCTL_BUF_SIZE;/*OUT */
75662306a36Sopenharmony_ci
75762306a36Sopenharmony_ci			/*
75862306a36Sopenharmony_ci			 * for the last chunk of data in case file size is
75962306a36Sopenharmony_ci			 * not even with 4k, load only the rest
76062306a36Sopenharmony_ci			 */
76162306a36Sopenharmony_ci
76262306a36Sopenharmony_ci			read_buf  = (u8 *)pm8001_ha->fw_image->data + sizeRead;
76362306a36Sopenharmony_ci			fc_len = (partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE;
76462306a36Sopenharmony_ci
76562306a36Sopenharmony_ci			if (loopcount - loopNumber == 1 && fc_len) {
76662306a36Sopenharmony_ci				fwControl->len = fc_len;
76762306a36Sopenharmony_ci				memcpy((u8 *)fwControl->buffer, read_buf, fc_len);
76862306a36Sopenharmony_ci				sizeRead += fc_len;
76962306a36Sopenharmony_ci			} else {
77062306a36Sopenharmony_ci				memcpy((u8 *)fwControl->buffer, read_buf, IOCTL_BUF_SIZE);
77162306a36Sopenharmony_ci				sizeRead += IOCTL_BUF_SIZE;
77262306a36Sopenharmony_ci			}
77362306a36Sopenharmony_ci
77462306a36Sopenharmony_ci			pm8001_ha->nvmd_completion = &completion;
77562306a36Sopenharmony_ci			ret = PM8001_CHIP_DISP->fw_flash_update_req(pm8001_ha, payload);
77662306a36Sopenharmony_ci			if (ret) {
77762306a36Sopenharmony_ci				pm8001_ha->fw_status = FAIL_OUT_MEMORY;
77862306a36Sopenharmony_ci				goto out;
77962306a36Sopenharmony_ci			}
78062306a36Sopenharmony_ci			wait_for_completion(&completion);
78162306a36Sopenharmony_ci			if (fwControl->retcode > FLASH_UPDATE_IN_PROGRESS) {
78262306a36Sopenharmony_ci				pm8001_ha->fw_status = fwControl->retcode;
78362306a36Sopenharmony_ci				ret = -EFAULT;
78462306a36Sopenharmony_ci				goto out;
78562306a36Sopenharmony_ci			}
78662306a36Sopenharmony_ci		}
78762306a36Sopenharmony_ci	}
78862306a36Sopenharmony_ciout:
78962306a36Sopenharmony_ci	kfree(ioctlbuffer);
79062306a36Sopenharmony_ci	return ret;
79162306a36Sopenharmony_ci}
79262306a36Sopenharmony_cistatic ssize_t pm8001_store_update_fw(struct device *cdev,
79362306a36Sopenharmony_ci				      struct device_attribute *attr,
79462306a36Sopenharmony_ci				      const char *buf, size_t count)
79562306a36Sopenharmony_ci{
79662306a36Sopenharmony_ci	struct Scsi_Host *shost = class_to_shost(cdev);
79762306a36Sopenharmony_ci	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
79862306a36Sopenharmony_ci	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
79962306a36Sopenharmony_ci	char *cmd_ptr, *filename_ptr;
80062306a36Sopenharmony_ci	int res, i;
80162306a36Sopenharmony_ci	int flash_command = FLASH_CMD_NONE;
80262306a36Sopenharmony_ci	int ret;
80362306a36Sopenharmony_ci
80462306a36Sopenharmony_ci	if (!capable(CAP_SYS_ADMIN))
80562306a36Sopenharmony_ci		return -EACCES;
80662306a36Sopenharmony_ci
80762306a36Sopenharmony_ci	/* this test protects us from running two flash processes at once,
80862306a36Sopenharmony_ci	 * so we should start with this test */
80962306a36Sopenharmony_ci	if (pm8001_ha->fw_status == FLASH_IN_PROGRESS)
81062306a36Sopenharmony_ci		return -EINPROGRESS;
81162306a36Sopenharmony_ci	pm8001_ha->fw_status = FLASH_IN_PROGRESS;
81262306a36Sopenharmony_ci
81362306a36Sopenharmony_ci	cmd_ptr = kcalloc(count, 2, GFP_KERNEL);
81462306a36Sopenharmony_ci	if (!cmd_ptr) {
81562306a36Sopenharmony_ci		pm8001_ha->fw_status = FAIL_OUT_MEMORY;
81662306a36Sopenharmony_ci		return -ENOMEM;
81762306a36Sopenharmony_ci	}
81862306a36Sopenharmony_ci
81962306a36Sopenharmony_ci	filename_ptr = cmd_ptr + count;
82062306a36Sopenharmony_ci	res = sscanf(buf, "%s %s", cmd_ptr, filename_ptr);
82162306a36Sopenharmony_ci	if (res != 2) {
82262306a36Sopenharmony_ci		pm8001_ha->fw_status = FAIL_PARAMETERS;
82362306a36Sopenharmony_ci		ret = -EINVAL;
82462306a36Sopenharmony_ci		goto out;
82562306a36Sopenharmony_ci	}
82662306a36Sopenharmony_ci
82762306a36Sopenharmony_ci	for (i = 0; flash_command_table[i].code != FLASH_CMD_NONE; i++) {
82862306a36Sopenharmony_ci		if (!memcmp(flash_command_table[i].command,
82962306a36Sopenharmony_ci				 cmd_ptr, strlen(cmd_ptr))) {
83062306a36Sopenharmony_ci			flash_command = flash_command_table[i].code;
83162306a36Sopenharmony_ci			break;
83262306a36Sopenharmony_ci		}
83362306a36Sopenharmony_ci	}
83462306a36Sopenharmony_ci	if (flash_command == FLASH_CMD_NONE) {
83562306a36Sopenharmony_ci		pm8001_ha->fw_status = FAIL_PARAMETERS;
83662306a36Sopenharmony_ci		ret = -EINVAL;
83762306a36Sopenharmony_ci		goto out;
83862306a36Sopenharmony_ci	}
83962306a36Sopenharmony_ci
84062306a36Sopenharmony_ci	ret = request_firmware(&pm8001_ha->fw_image,
84162306a36Sopenharmony_ci			       filename_ptr,
84262306a36Sopenharmony_ci			       pm8001_ha->dev);
84362306a36Sopenharmony_ci
84462306a36Sopenharmony_ci	if (ret) {
84562306a36Sopenharmony_ci		pm8001_dbg(pm8001_ha, FAIL,
84662306a36Sopenharmony_ci			   "Failed to load firmware image file %s, error %d\n",
84762306a36Sopenharmony_ci			   filename_ptr, ret);
84862306a36Sopenharmony_ci		pm8001_ha->fw_status = FAIL_OPEN_BIOS_FILE;
84962306a36Sopenharmony_ci		goto out;
85062306a36Sopenharmony_ci	}
85162306a36Sopenharmony_ci
85262306a36Sopenharmony_ci	if (FLASH_CMD_UPDATE == flash_command)
85362306a36Sopenharmony_ci		ret = pm8001_update_flash(pm8001_ha);
85462306a36Sopenharmony_ci	else
85562306a36Sopenharmony_ci		ret = pm8001_set_nvmd(pm8001_ha);
85662306a36Sopenharmony_ci
85762306a36Sopenharmony_ci	release_firmware(pm8001_ha->fw_image);
85862306a36Sopenharmony_ciout:
85962306a36Sopenharmony_ci	kfree(cmd_ptr);
86062306a36Sopenharmony_ci
86162306a36Sopenharmony_ci	if (ret)
86262306a36Sopenharmony_ci		return ret;
86362306a36Sopenharmony_ci
86462306a36Sopenharmony_ci	pm8001_ha->fw_status = FLASH_OK;
86562306a36Sopenharmony_ci	return count;
86662306a36Sopenharmony_ci}
86762306a36Sopenharmony_ci
86862306a36Sopenharmony_cistatic ssize_t pm8001_show_update_fw(struct device *cdev,
86962306a36Sopenharmony_ci				     struct device_attribute *attr, char *buf)
87062306a36Sopenharmony_ci{
87162306a36Sopenharmony_ci	int i;
87262306a36Sopenharmony_ci	struct Scsi_Host *shost = class_to_shost(cdev);
87362306a36Sopenharmony_ci	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
87462306a36Sopenharmony_ci	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
87562306a36Sopenharmony_ci
87662306a36Sopenharmony_ci	for (i = 0; flash_error_table[i].err_code != 0; i++) {
87762306a36Sopenharmony_ci		if (flash_error_table[i].err_code == pm8001_ha->fw_status)
87862306a36Sopenharmony_ci			break;
87962306a36Sopenharmony_ci	}
88062306a36Sopenharmony_ci	if (pm8001_ha->fw_status != FLASH_IN_PROGRESS)
88162306a36Sopenharmony_ci		pm8001_ha->fw_status = FLASH_OK;
88262306a36Sopenharmony_ci
88362306a36Sopenharmony_ci	return snprintf(buf, PAGE_SIZE, "status=%x %s\n",
88462306a36Sopenharmony_ci			flash_error_table[i].err_code,
88562306a36Sopenharmony_ci			flash_error_table[i].reason);
88662306a36Sopenharmony_ci}
88762306a36Sopenharmony_cistatic DEVICE_ATTR(update_fw, S_IRUGO|S_IWUSR|S_IWGRP,
88862306a36Sopenharmony_ci	pm8001_show_update_fw, pm8001_store_update_fw);
88962306a36Sopenharmony_ci
89062306a36Sopenharmony_cistatic const char *const mpiStateText[] = {
89162306a36Sopenharmony_ci	"MPI is not initialized",
89262306a36Sopenharmony_ci	"MPI is successfully initialized",
89362306a36Sopenharmony_ci	"MPI termination is in progress",
89462306a36Sopenharmony_ci	"MPI initialization failed with error in [31:16]"
89562306a36Sopenharmony_ci};
89662306a36Sopenharmony_ci
89762306a36Sopenharmony_ci/**
89862306a36Sopenharmony_ci * ctl_mpi_state_show - controller MPI state check
89962306a36Sopenharmony_ci * @cdev: pointer to embedded class device
90062306a36Sopenharmony_ci * @attr: device attribute (unused)
90162306a36Sopenharmony_ci * @buf: the buffer returned
90262306a36Sopenharmony_ci *
90362306a36Sopenharmony_ci * A sysfs 'read-only' shost attribute.
90462306a36Sopenharmony_ci */
90562306a36Sopenharmony_cistatic ssize_t ctl_mpi_state_show(struct device *cdev,
90662306a36Sopenharmony_ci		struct device_attribute *attr, char *buf)
90762306a36Sopenharmony_ci{
90862306a36Sopenharmony_ci	struct Scsi_Host *shost = class_to_shost(cdev);
90962306a36Sopenharmony_ci	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
91062306a36Sopenharmony_ci	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
91162306a36Sopenharmony_ci	unsigned int mpidw0;
91262306a36Sopenharmony_ci
91362306a36Sopenharmony_ci	mpidw0 = pm8001_mr32(pm8001_ha->general_stat_tbl_addr, 0);
91462306a36Sopenharmony_ci	return sysfs_emit(buf, "%s\n", mpiStateText[mpidw0 & 0x0003]);
91562306a36Sopenharmony_ci}
91662306a36Sopenharmony_cistatic DEVICE_ATTR_RO(ctl_mpi_state);
91762306a36Sopenharmony_ci
91862306a36Sopenharmony_ci/**
91962306a36Sopenharmony_ci * ctl_hmi_error_show - controller MPI initialization fails
92062306a36Sopenharmony_ci * @cdev: pointer to embedded class device
92162306a36Sopenharmony_ci * @attr: device attribute (unused)
92262306a36Sopenharmony_ci * @buf: the buffer returned
92362306a36Sopenharmony_ci *
92462306a36Sopenharmony_ci * A sysfs 'read-only' shost attribute.
92562306a36Sopenharmony_ci */
92662306a36Sopenharmony_cistatic ssize_t ctl_hmi_error_show(struct device *cdev,
92762306a36Sopenharmony_ci		struct device_attribute *attr, char *buf)
92862306a36Sopenharmony_ci{
92962306a36Sopenharmony_ci	struct Scsi_Host *shost = class_to_shost(cdev);
93062306a36Sopenharmony_ci	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
93162306a36Sopenharmony_ci	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
93262306a36Sopenharmony_ci	unsigned int mpidw0;
93362306a36Sopenharmony_ci
93462306a36Sopenharmony_ci	mpidw0 = pm8001_mr32(pm8001_ha->general_stat_tbl_addr, 0);
93562306a36Sopenharmony_ci	return sysfs_emit(buf, "0x%08x\n", (mpidw0 >> 16));
93662306a36Sopenharmony_ci}
93762306a36Sopenharmony_cistatic DEVICE_ATTR_RO(ctl_hmi_error);
93862306a36Sopenharmony_ci
93962306a36Sopenharmony_ci/**
94062306a36Sopenharmony_ci * ctl_raae_count_show - controller raae count check
94162306a36Sopenharmony_ci * @cdev: pointer to embedded class device
94262306a36Sopenharmony_ci * @attr: device attribute (unused)
94362306a36Sopenharmony_ci * @buf: the buffer returned
94462306a36Sopenharmony_ci *
94562306a36Sopenharmony_ci * A sysfs 'read-only' shost attribute.
94662306a36Sopenharmony_ci */
94762306a36Sopenharmony_cistatic ssize_t ctl_raae_count_show(struct device *cdev,
94862306a36Sopenharmony_ci		struct device_attribute *attr, char *buf)
94962306a36Sopenharmony_ci{
95062306a36Sopenharmony_ci	struct Scsi_Host *shost = class_to_shost(cdev);
95162306a36Sopenharmony_ci	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
95262306a36Sopenharmony_ci	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
95362306a36Sopenharmony_ci	unsigned int raaecnt;
95462306a36Sopenharmony_ci
95562306a36Sopenharmony_ci	raaecnt = pm8001_mr32(pm8001_ha->general_stat_tbl_addr, 12);
95662306a36Sopenharmony_ci	return sysfs_emit(buf, "0x%08x\n", raaecnt);
95762306a36Sopenharmony_ci}
95862306a36Sopenharmony_cistatic DEVICE_ATTR_RO(ctl_raae_count);
95962306a36Sopenharmony_ci
96062306a36Sopenharmony_ci/**
96162306a36Sopenharmony_ci * ctl_iop0_count_show - controller iop0 count check
96262306a36Sopenharmony_ci * @cdev: pointer to embedded class device
96362306a36Sopenharmony_ci * @attr: device attribute (unused)
96462306a36Sopenharmony_ci * @buf: the buffer returned
96562306a36Sopenharmony_ci *
96662306a36Sopenharmony_ci * A sysfs 'read-only' shost attribute.
96762306a36Sopenharmony_ci */
96862306a36Sopenharmony_cistatic ssize_t ctl_iop0_count_show(struct device *cdev,
96962306a36Sopenharmony_ci		struct device_attribute *attr, char *buf)
97062306a36Sopenharmony_ci{
97162306a36Sopenharmony_ci	struct Scsi_Host *shost = class_to_shost(cdev);
97262306a36Sopenharmony_ci	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
97362306a36Sopenharmony_ci	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
97462306a36Sopenharmony_ci	unsigned int iop0cnt;
97562306a36Sopenharmony_ci
97662306a36Sopenharmony_ci	iop0cnt = pm8001_mr32(pm8001_ha->general_stat_tbl_addr, 16);
97762306a36Sopenharmony_ci	return sysfs_emit(buf, "0x%08x\n", iop0cnt);
97862306a36Sopenharmony_ci}
97962306a36Sopenharmony_cistatic DEVICE_ATTR_RO(ctl_iop0_count);
98062306a36Sopenharmony_ci
98162306a36Sopenharmony_ci/**
98262306a36Sopenharmony_ci * ctl_iop1_count_show - controller iop1 count check
98362306a36Sopenharmony_ci * @cdev: pointer to embedded class device
98462306a36Sopenharmony_ci * @attr: device attribute (unused)
98562306a36Sopenharmony_ci * @buf: the buffer returned
98662306a36Sopenharmony_ci *
98762306a36Sopenharmony_ci * A sysfs 'read-only' shost attribute.
98862306a36Sopenharmony_ci */
98962306a36Sopenharmony_cistatic ssize_t ctl_iop1_count_show(struct device *cdev,
99062306a36Sopenharmony_ci		struct device_attribute *attr, char *buf)
99162306a36Sopenharmony_ci{
99262306a36Sopenharmony_ci	struct Scsi_Host *shost = class_to_shost(cdev);
99362306a36Sopenharmony_ci	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
99462306a36Sopenharmony_ci	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
99562306a36Sopenharmony_ci	unsigned int iop1cnt;
99662306a36Sopenharmony_ci
99762306a36Sopenharmony_ci	iop1cnt = pm8001_mr32(pm8001_ha->general_stat_tbl_addr, 20);
99862306a36Sopenharmony_ci	return sysfs_emit(buf, "0x%08x\n", iop1cnt);
99962306a36Sopenharmony_ci
100062306a36Sopenharmony_ci}
100162306a36Sopenharmony_cistatic DEVICE_ATTR_RO(ctl_iop1_count);
100262306a36Sopenharmony_ci
100362306a36Sopenharmony_cistatic struct attribute *pm8001_host_attrs[] = {
100462306a36Sopenharmony_ci	&dev_attr_interface_rev.attr,
100562306a36Sopenharmony_ci	&dev_attr_controller_fatal_error.attr,
100662306a36Sopenharmony_ci	&dev_attr_fw_version.attr,
100762306a36Sopenharmony_ci	&dev_attr_update_fw.attr,
100862306a36Sopenharmony_ci	&dev_attr_aap_log.attr,
100962306a36Sopenharmony_ci	&dev_attr_iop_log.attr,
101062306a36Sopenharmony_ci	&dev_attr_fatal_log.attr,
101162306a36Sopenharmony_ci	&dev_attr_non_fatal_log.attr,
101262306a36Sopenharmony_ci	&dev_attr_non_fatal_count.attr,
101362306a36Sopenharmony_ci	&dev_attr_gsm_log.attr,
101462306a36Sopenharmony_ci	&dev_attr_max_out_io.attr,
101562306a36Sopenharmony_ci	&dev_attr_max_devices.attr,
101662306a36Sopenharmony_ci	&dev_attr_max_sg_list.attr,
101762306a36Sopenharmony_ci	&dev_attr_sas_spec_support.attr,
101862306a36Sopenharmony_ci	&dev_attr_logging_level.attr,
101962306a36Sopenharmony_ci	&dev_attr_event_log_size.attr,
102062306a36Sopenharmony_ci	&dev_attr_host_sas_address.attr,
102162306a36Sopenharmony_ci	&dev_attr_bios_version.attr,
102262306a36Sopenharmony_ci	&dev_attr_ib_log.attr,
102362306a36Sopenharmony_ci	&dev_attr_ob_log.attr,
102462306a36Sopenharmony_ci	&dev_attr_ila_version.attr,
102562306a36Sopenharmony_ci	&dev_attr_inc_fw_ver.attr,
102662306a36Sopenharmony_ci	&dev_attr_ctl_mpi_state.attr,
102762306a36Sopenharmony_ci	&dev_attr_ctl_hmi_error.attr,
102862306a36Sopenharmony_ci	&dev_attr_ctl_raae_count.attr,
102962306a36Sopenharmony_ci	&dev_attr_ctl_iop0_count.attr,
103062306a36Sopenharmony_ci	&dev_attr_ctl_iop1_count.attr,
103162306a36Sopenharmony_ci	NULL,
103262306a36Sopenharmony_ci};
103362306a36Sopenharmony_ci
103462306a36Sopenharmony_cistatic const struct attribute_group pm8001_host_attr_group = {
103562306a36Sopenharmony_ci	.attrs = pm8001_host_attrs
103662306a36Sopenharmony_ci};
103762306a36Sopenharmony_ci
103862306a36Sopenharmony_ciconst struct attribute_group *pm8001_host_groups[] = {
103962306a36Sopenharmony_ci	&pm8001_host_attr_group,
104062306a36Sopenharmony_ci	NULL
104162306a36Sopenharmony_ci};
1042