Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * PMC-Sierra 8001/8081/8088/8089 SAS/SATA based host adapters driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (c) 2008-2009 USI Co., Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Redistribution and use in source and binary forms, with or without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * modification, are permitted provided that the following conditions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * are met:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * 1. Redistributions of source code must retain the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *    notice, this list of conditions, and the following disclaimer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *    without modification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *    substantially similar to the "NO WARRANTY" disclaimer below
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *    ("Disclaimer") and any redistribution must be conditioned upon
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *    including a substantially similar Disclaimer requirement for further
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *    binary redistribution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * 3. Neither the names of the above-listed copyright holders nor the names
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *    of any contributors may be used to endorse or promote products derived
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *    from this software without specific prior written permission.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * Alternatively, this software may be distributed under the terms of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * GNU General Public License ("GPL") version 2 as published by the Free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * NO WARRANTY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * POSSIBILITY OF SUCH DAMAGES.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include <linux/firmware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #include "pm8001_sas.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #include "pm8001_ctl.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) /* scsi host attributes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * pm8001_ctl_mpi_interface_rev_show - MPI interface revision number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * @cdev: pointer to embedded class device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * @attr: device attribute (unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  * @buf: the buffer returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  * A sysfs 'read-only' shost attribute.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) static ssize_t pm8001_ctl_mpi_interface_rev_show(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	struct Scsi_Host *shost = class_to_shost(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	if (pm8001_ha->chip_id == chip_8001) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		return snprintf(buf, PAGE_SIZE, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 			pm8001_ha->main_cfg_tbl.pm8001_tbl.interface_rev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		return snprintf(buf, PAGE_SIZE, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 			pm8001_ha->main_cfg_tbl.pm80xx_tbl.interface_rev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) DEVICE_ATTR(interface_rev, S_IRUGO, pm8001_ctl_mpi_interface_rev_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  * controller_fatal_error_show - check controller is under fatal err
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  * @cdev: pointer to embedded class device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  * @attr: device attribute (unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  * @buf: the buffer returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  * A sysfs 'read only' shost attribute.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) static ssize_t controller_fatal_error_show(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	struct Scsi_Host *shost = class_to_shost(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	return snprintf(buf, PAGE_SIZE, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			pm8001_ha->controller_fatal_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) static DEVICE_ATTR_RO(controller_fatal_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  * pm8001_ctl_fw_version_show - firmware version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  * @cdev: pointer to embedded class device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  * @attr: device attribute (unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  * @buf: the buffer returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  * A sysfs 'read-only' shost attribute.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static ssize_t pm8001_ctl_fw_version_show(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	struct Scsi_Host *shost = class_to_shost(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	if (pm8001_ha->chip_id == chip_8001) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x.%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		(u8)(pm8001_ha->main_cfg_tbl.pm8001_tbl.firmware_rev >> 24),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		(u8)(pm8001_ha->main_cfg_tbl.pm8001_tbl.firmware_rev >> 16),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		(u8)(pm8001_ha->main_cfg_tbl.pm8001_tbl.firmware_rev >> 8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		(u8)(pm8001_ha->main_cfg_tbl.pm8001_tbl.firmware_rev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x.%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.firmware_rev >> 24),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.firmware_rev >> 16),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.firmware_rev >> 8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.firmware_rev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static DEVICE_ATTR(fw_version, S_IRUGO, pm8001_ctl_fw_version_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  * pm8001_ctl_ila_version_show - ila version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  * @cdev: pointer to embedded class device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)  * @attr: device attribute (unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)  * @buf: the buffer returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)  * A sysfs 'read-only' shost attribute.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static ssize_t pm8001_ctl_ila_version_show(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	struct Scsi_Host *shost = class_to_shost(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	if (pm8001_ha->chip_id != chip_8001) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x.%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.ila_version >> 24),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.ila_version >> 16),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.ila_version >> 8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.ila_version));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static DEVICE_ATTR(ila_version, 0444, pm8001_ctl_ila_version_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)  * pm8001_ctl_inactive_fw_version_show - Inacative firmware version number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)  * @cdev: pointer to embedded class device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)  * @attr: device attribute (unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)  * @buf: the buffer returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)  * A sysfs 'read-only' shost attribute.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static ssize_t pm8001_ctl_inactive_fw_version_show(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	struct Scsi_Host *shost = class_to_shost(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	if (pm8001_ha->chip_id != chip_8001) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x.%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.inc_fw_version >> 24),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.inc_fw_version >> 16),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.inc_fw_version >> 8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.inc_fw_version));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) DEVICE_ATTR(inc_fw_ver, 0444, pm8001_ctl_inactive_fw_version_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)  * pm8001_ctl_max_out_io_show - max outstanding io supported
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)  * @cdev: pointer to embedded class device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  * @attr: device attribute (unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  * @buf: the buffer returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  * A sysfs 'read-only' shost attribute.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static ssize_t pm8001_ctl_max_out_io_show(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	struct Scsi_Host *shost = class_to_shost(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	if (pm8001_ha->chip_id == chip_8001) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		return snprintf(buf, PAGE_SIZE, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			pm8001_ha->main_cfg_tbl.pm8001_tbl.max_out_io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		return snprintf(buf, PAGE_SIZE, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_out_io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static DEVICE_ATTR(max_out_io, S_IRUGO, pm8001_ctl_max_out_io_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)  * pm8001_ctl_max_devices_show - max devices support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)  * @cdev: pointer to embedded class device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)  * @attr: device attribute (unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)  * @buf: the buffer returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)  * A sysfs 'read-only' shost attribute.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static ssize_t pm8001_ctl_max_devices_show(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	struct Scsi_Host *shost = class_to_shost(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	if (pm8001_ha->chip_id == chip_8001) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		return snprintf(buf, PAGE_SIZE, "%04d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			(u16)(pm8001_ha->main_cfg_tbl.pm8001_tbl.max_sgl >> 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 			);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		return snprintf(buf, PAGE_SIZE, "%04d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 			(u16)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_sgl >> 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static DEVICE_ATTR(max_devices, S_IRUGO, pm8001_ctl_max_devices_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)  * pm8001_ctl_max_sg_list_show - max sg list supported iff not 0.0 for no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)  * hardware limitation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)  * @cdev: pointer to embedded class device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)  * @attr: device attribute (unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)  * @buf: the buffer returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  * A sysfs 'read-only' shost attribute.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static ssize_t pm8001_ctl_max_sg_list_show(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	struct Scsi_Host *shost = class_to_shost(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	if (pm8001_ha->chip_id == chip_8001) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		return snprintf(buf, PAGE_SIZE, "%04d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 			pm8001_ha->main_cfg_tbl.pm8001_tbl.max_sgl & 0x0000FFFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 			);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		return snprintf(buf, PAGE_SIZE, "%04d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 			pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_sgl & 0x0000FFFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 			);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static DEVICE_ATTR(max_sg_list, S_IRUGO, pm8001_ctl_max_sg_list_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) #define SAS_1_0 0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) #define SAS_1_1 0x2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) #define SAS_2_0 0x4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) show_sas_spec_support_status(unsigned int mode, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	ssize_t len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	if (mode & SAS_1_1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		len = sprintf(buf, "%s", "SAS1.1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	if (mode & SAS_2_0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		len += sprintf(buf + len, "%s%s", len ? ", " : "", "SAS2.0");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	len += sprintf(buf + len, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)  * pm8001_ctl_sas_spec_support_show - sas spec supported
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)  * @cdev: pointer to embedded class device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)  * @attr: device attribute (unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)  * @buf: the buffer returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)  * A sysfs 'read-only' shost attribute.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) static ssize_t pm8001_ctl_sas_spec_support_show(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	unsigned int mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	struct Scsi_Host *shost = class_to_shost(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	/* fe000000 means supports SAS2.1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	if (pm8001_ha->chip_id == chip_8001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		mode = (pm8001_ha->main_cfg_tbl.pm8001_tbl.ctrl_cap_flag &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 							0xfe000000)>>25;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		/* fe000000 means supports SAS2.1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		mode = (pm8001_ha->main_cfg_tbl.pm80xx_tbl.ctrl_cap_flag &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 							0xfe000000)>>25;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	return show_sas_spec_support_status(mode, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) static DEVICE_ATTR(sas_spec_support, S_IRUGO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		   pm8001_ctl_sas_spec_support_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)  * pm8001_ctl_sas_address_show - sas address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)  * @cdev: pointer to embedded class device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)  * @attr: device attribute (unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)  * @buf: the buffer returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)  * This is the controller sas address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)  * A sysfs 'read-only' shost attribute.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) static ssize_t pm8001_ctl_host_sas_address_show(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	struct Scsi_Host *shost = class_to_shost(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	return snprintf(buf, PAGE_SIZE, "0x%016llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 			be64_to_cpu(*(__be64 *)pm8001_ha->sas_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) static DEVICE_ATTR(host_sas_address, S_IRUGO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		   pm8001_ctl_host_sas_address_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)  * pm8001_ctl_logging_level_show - logging level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)  * @cdev: pointer to embedded class device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)  * @attr: device attribute (unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)  * @buf: the buffer returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)  * A sysfs 'read/write' shost attribute.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) static ssize_t pm8001_ctl_logging_level_show(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	struct Scsi_Host *shost = class_to_shost(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	return snprintf(buf, PAGE_SIZE, "%08xh\n", pm8001_ha->logging_level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) static ssize_t pm8001_ctl_logging_level_store(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	struct device_attribute *attr, const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	struct Scsi_Host *shost = class_to_shost(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	int val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	if (sscanf(buf, "%x", &val) != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	pm8001_ha->logging_level = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	return strlen(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) static DEVICE_ATTR(logging_level, S_IRUGO | S_IWUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	pm8001_ctl_logging_level_show, pm8001_ctl_logging_level_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)  * pm8001_ctl_aap_log_show - aap1 event log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)  * @cdev: pointer to embedded class device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)  * @attr: device attribute (unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)  * @buf: the buffer returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)  * A sysfs 'read-only' shost attribute.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) static ssize_t pm8001_ctl_aap_log_show(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	struct Scsi_Host *shost = class_to_shost(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) #define AAP1_MEMMAP(r, c) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	(*(u32 *)((u8*)pm8001_ha->memoryMap.region[AAP1].virt_ptr + (r) * 32 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	+ (c)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	char *str = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	int max = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	for (i = 0; i < max; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		str += sprintf(str, "0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 			       "0x%08x 0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 			       AAP1_MEMMAP(i, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 			       AAP1_MEMMAP(i, 4),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 			       AAP1_MEMMAP(i, 8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 			       AAP1_MEMMAP(i, 12),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 			       AAP1_MEMMAP(i, 16),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 			       AAP1_MEMMAP(i, 20),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 			       AAP1_MEMMAP(i, 24),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 			       AAP1_MEMMAP(i, 28));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	return str - buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) static DEVICE_ATTR(aap_log, S_IRUGO, pm8001_ctl_aap_log_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)  * pm8001_ctl_ib_queue_log_show - Out bound Queue log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)  * @cdev:pointer to embedded class device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)  * @attr: device attribute (unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)  * @buf: the buffer returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)  * A sysfs 'read-only' shost attribute.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) static ssize_t pm8001_ctl_ib_queue_log_show(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	struct Scsi_Host *shost = class_to_shost(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	int offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	char *str = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	int start = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	u32 ib_offset = pm8001_ha->ib_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) #define IB_MEMMAP(c)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		(*(u32 *)((u8 *)pm8001_ha->	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		memoryMap.region[ib_offset].virt_ptr +	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		pm8001_ha->evtlog_ib_offset + (c)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	for (offset = 0; offset < IB_OB_READ_TIMES; offset++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		str += sprintf(str, "0x%08x\n", IB_MEMMAP(start));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		start = start + 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	pm8001_ha->evtlog_ib_offset += SYSFS_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	if (((pm8001_ha->evtlog_ib_offset) % (PM80XX_IB_OB_QUEUE_SIZE)) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		pm8001_ha->evtlog_ib_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	return str - buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) static DEVICE_ATTR(ib_log, S_IRUGO, pm8001_ctl_ib_queue_log_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)  * pm8001_ctl_ob_queue_log_show - Out bound Queue log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)  * @cdev:pointer to embedded class device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)  * @attr: device attribute (unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)  * @buf: the buffer returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)  * A sysfs 'read-only' shost attribute.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) static ssize_t pm8001_ctl_ob_queue_log_show(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	struct Scsi_Host *shost = class_to_shost(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	int offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	char *str = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	int start = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	u32 ob_offset = pm8001_ha->ob_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) #define OB_MEMMAP(c)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 		(*(u32 *)((u8 *)pm8001_ha->	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 		memoryMap.region[ob_offset].virt_ptr +	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		pm8001_ha->evtlog_ob_offset + (c)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	for (offset = 0; offset < IB_OB_READ_TIMES; offset++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		str += sprintf(str, "0x%08x\n", OB_MEMMAP(start));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		start = start + 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	pm8001_ha->evtlog_ob_offset += SYSFS_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	if (((pm8001_ha->evtlog_ob_offset) % (PM80XX_IB_OB_QUEUE_SIZE)) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		pm8001_ha->evtlog_ob_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	return str - buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) static DEVICE_ATTR(ob_log, S_IRUGO, pm8001_ctl_ob_queue_log_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)  * pm8001_ctl_bios_version_show - Bios version Display
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)  * @cdev:pointer to embedded class device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)  * @attr: device attribute (unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)  * @buf:the buffer returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)  * A sysfs 'read-only' shost attribute.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) static ssize_t pm8001_ctl_bios_version_show(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	struct Scsi_Host *shost = class_to_shost(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	char *str = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	int bios_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	DECLARE_COMPLETION_ONSTACK(completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	struct pm8001_ioctl_payload payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	pm8001_ha->nvmd_completion = &completion;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	payload.minor_function = 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	payload.offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	payload.rd_length = 4096;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	payload.func_specific = kzalloc(4096, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	if (!payload.func_specific)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	if (PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		kfree(payload.func_specific);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	wait_for_completion(&completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	for (bios_index = BIOSOFFSET; bios_index < BIOS_OFFSET_LIMIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 		bios_index++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		str += sprintf(str, "%c",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 			*(payload.func_specific+bios_index));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	kfree(payload.func_specific);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	return str - buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) static DEVICE_ATTR(bios_version, S_IRUGO, pm8001_ctl_bios_version_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)  * event_log_size_show - event log size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)  * @cdev: pointer to embedded class device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)  * @attr: device attribute (unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)  * @buf: the buffer returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)  * A sysfs read  shost attribute.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) static ssize_t event_log_size_show(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	struct Scsi_Host *shost = class_to_shost(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	return snprintf(buf, PAGE_SIZE, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 		pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) static DEVICE_ATTR_RO(event_log_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)  * pm8001_ctl_aap_log_show - IOP event log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)  * @cdev: pointer to embedded class device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)  * @attr: device attribute (unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)  * @buf: the buffer returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)  * A sysfs 'read-only' shost attribute.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) static ssize_t pm8001_ctl_iop_log_show(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	struct Scsi_Host *shost = class_to_shost(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	char *str = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	u32 read_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 		pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_size / 1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	static u32 start, end, count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	u32 max_read_times = 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	u32 max_count = (read_size * 1024) / (max_read_times * 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	u32 *temp = (u32 *)pm8001_ha->memoryMap.region[IOP].virt_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	if ((count % max_count) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 		start = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 		end = max_read_times;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 		count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 		start = end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 		end = end + max_read_times;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	for (; start < end; start++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 		str += sprintf(str, "%08x ", *(temp+start));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	return str - buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) static DEVICE_ATTR(iop_log, S_IRUGO, pm8001_ctl_iop_log_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)  ** pm8001_ctl_fatal_log_show - fatal error logging
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)  ** @cdev:pointer to embedded class device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)  ** @attr: device attribute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)  ** @buf: the buffer returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)  **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)  ** A sysfs 'read-only' shost attribute.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) static ssize_t pm8001_ctl_fatal_log_show(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	ssize_t count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	count = pm80xx_get_fatal_dump(cdev, attr, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) static DEVICE_ATTR(fatal_log, S_IRUGO, pm8001_ctl_fatal_log_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)  ** non_fatal_log_show - non fatal error logging
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)  ** @cdev:pointer to embedded class device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581)  ** @attr: device attribute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)  ** @buf: the buffer returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)  **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)  ** A sysfs 'read-only' shost attribute.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) static ssize_t non_fatal_log_show(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	u32 count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	count = pm80xx_get_non_fatal_dump(cdev, attr, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) static DEVICE_ATTR_RO(non_fatal_log);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) static ssize_t non_fatal_count_show(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 		struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	struct Scsi_Host *shost = class_to_shost(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	return snprintf(buf, PAGE_SIZE, "%08x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 			pm8001_ha->non_fatal_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) static ssize_t non_fatal_count_store(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 		struct device_attribute *attr, const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	struct Scsi_Host *shost = class_to_shost(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 	int val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 	if (kstrtoint(buf, 16, &val) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	pm8001_ha->non_fatal_count = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	return strlen(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) static DEVICE_ATTR_RW(non_fatal_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)  ** pm8001_ctl_gsm_log_show - gsm dump collection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)  ** @cdev:pointer to embedded class device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)  ** @attr: device attribute (unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627)  ** @buf: the buffer returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)  ** A sysfs 'read-only' shost attribute.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) static ssize_t pm8001_ctl_gsm_log_show(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 	ssize_t count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 	count = pm8001_get_gsm_dump(cdev, SYSFS_OFFSET, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) static DEVICE_ATTR(gsm_log, S_IRUGO, pm8001_ctl_gsm_log_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) #define FLASH_CMD_NONE      0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) #define FLASH_CMD_UPDATE    0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) #define FLASH_CMD_SET_NVMD    0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) struct flash_command {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646)      u8      command[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647)      int     code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) static struct flash_command flash_command_table[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)      {"set_nvmd",    FLASH_CMD_SET_NVMD},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653)      {"update",      FLASH_CMD_UPDATE},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)      {"",            FLASH_CMD_NONE} /* Last entry should be NULL. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) struct error_fw {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658)      char    *reason;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659)      int     err_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) static struct error_fw flash_error_table[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)      {"Failed to open fw image file",	FAIL_OPEN_BIOS_FILE},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665)      {"image header mismatch",		FLASH_UPDATE_HDR_ERR},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666)      {"image offset mismatch",		FLASH_UPDATE_OFFSET_ERR},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)      {"image CRC Error",		FLASH_UPDATE_CRC_ERR},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668)      {"image length Error.",		FLASH_UPDATE_LENGTH_ERR},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669)      {"Failed to program flash chip",	FLASH_UPDATE_HW_ERR},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670)      {"Flash chip not supported.",	FLASH_UPDATE_DNLD_NOT_SUPPORTED},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)      {"Flash update disabled.",		FLASH_UPDATE_DISABLED},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)      {"Flash in progress",		FLASH_IN_PROGRESS},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)      {"Image file size Error",		FAIL_FILE_SIZE},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)      {"Input parameter error",		FAIL_PARAMETERS},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675)      {"Out of memory",			FAIL_OUT_MEMORY},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676)      {"OK", 0}	/* Last entry err_code = 0. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) static int pm8001_set_nvmd(struct pm8001_hba_info *pm8001_ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 	struct pm8001_ioctl_payload	*payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	DECLARE_COMPLETION_ONSTACK(completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	u8		*ioctlbuffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	u32		ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 	u32		length = 1024 * 5 + sizeof(*payload) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 	if (pm8001_ha->fw_image->size > 4096) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 		pm8001_ha->fw_status = FAIL_FILE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 	ioctlbuffer = kzalloc(length, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 	if (!ioctlbuffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 		pm8001_ha->fw_status = FAIL_OUT_MEMORY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 	payload = (struct pm8001_ioctl_payload *)ioctlbuffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 	memcpy((u8 *)&payload->func_specific, (u8 *)pm8001_ha->fw_image->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 				pm8001_ha->fw_image->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	payload->wr_length = pm8001_ha->fw_image->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 	payload->id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 	payload->minor_function = 0x1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 	pm8001_ha->nvmd_completion = &completion;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	ret = PM8001_CHIP_DISP->set_nvmd_req(pm8001_ha, payload);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 		pm8001_ha->fw_status = FAIL_OUT_MEMORY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 	wait_for_completion(&completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 	kfree(ioctlbuffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) static int pm8001_update_flash(struct pm8001_hba_info *pm8001_ha)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 	struct pm8001_ioctl_payload	*payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 	DECLARE_COMPLETION_ONSTACK(completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 	u8		*ioctlbuffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 	struct fw_control_info	*fwControl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 	u32		partitionSize, partitionSizeTmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 	u32		loopNumber, loopcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 	struct pm8001_fw_image_header *image_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 	u32		sizeRead = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 	u32		ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 	u32		length = 1024 * 16 + sizeof(*payload) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 	if (pm8001_ha->fw_image->size < 28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 		pm8001_ha->fw_status = FAIL_FILE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 	ioctlbuffer = kzalloc(length, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 	if (!ioctlbuffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 		pm8001_ha->fw_status = FAIL_OUT_MEMORY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 	image_hdr = (struct pm8001_fw_image_header *)pm8001_ha->fw_image->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 	while (sizeRead < pm8001_ha->fw_image->size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 		partitionSizeTmp =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 			*(u32 *)((u8 *)&image_hdr->image_length + sizeRead);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 		partitionSize = be32_to_cpu(partitionSizeTmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 		loopcount = DIV_ROUND_UP(partitionSize + HEADER_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 					IOCTL_BUF_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 		for (loopNumber = 0; loopNumber < loopcount; loopNumber++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 			payload = (struct pm8001_ioctl_payload *)ioctlbuffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 			payload->wr_length = 1024*16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 			payload->id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 			fwControl =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 			      (struct fw_control_info *)&payload->func_specific;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 			fwControl->len = IOCTL_BUF_SIZE;   /* IN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 			fwControl->size = partitionSize + HEADER_LEN;/* IN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 			fwControl->retcode = 0;/* OUT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 			fwControl->offset = loopNumber * IOCTL_BUF_SIZE;/*OUT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 		/* for the last chunk of data in case file size is not even with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 		4k, load only the rest*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 		if (((loopcount-loopNumber) == 1) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 			((partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 			fwControl->len =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 				(partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 			memcpy((u8 *)fwControl->buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 				(u8 *)pm8001_ha->fw_image->data + sizeRead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 				(partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 			sizeRead +=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) 				(partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 			memcpy((u8 *)fwControl->buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 				(u8 *)pm8001_ha->fw_image->data + sizeRead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) 				IOCTL_BUF_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 			sizeRead += IOCTL_BUF_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 		pm8001_ha->nvmd_completion = &completion;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 		ret = PM8001_CHIP_DISP->fw_flash_update_req(pm8001_ha, payload);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) 			pm8001_ha->fw_status = FAIL_OUT_MEMORY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 		wait_for_completion(&completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) 		if (fwControl->retcode > FLASH_UPDATE_IN_PROGRESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) 			pm8001_ha->fw_status = fwControl->retcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 			ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) 	kfree(ioctlbuffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) static ssize_t pm8001_store_update_fw(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 				      struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) 				      const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 	struct Scsi_Host *shost = class_to_shost(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) 	char *cmd_ptr, *filename_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) 	int res, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) 	int flash_command = FLASH_CMD_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) 	if (!capable(CAP_SYS_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) 		return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) 	/* this test protects us from running two flash processes at once,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) 	 * so we should start with this test */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) 	if (pm8001_ha->fw_status == FLASH_IN_PROGRESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) 		return -EINPROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) 	pm8001_ha->fw_status = FLASH_IN_PROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) 	cmd_ptr = kcalloc(count, 2, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) 	if (!cmd_ptr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 		pm8001_ha->fw_status = FAIL_OUT_MEMORY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) 	filename_ptr = cmd_ptr + count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 	res = sscanf(buf, "%s %s", cmd_ptr, filename_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) 	if (res != 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) 		pm8001_ha->fw_status = FAIL_PARAMETERS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 	for (i = 0; flash_command_table[i].code != FLASH_CMD_NONE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) 		if (!memcmp(flash_command_table[i].command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) 				 cmd_ptr, strlen(cmd_ptr))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) 			flash_command = flash_command_table[i].code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) 	if (flash_command == FLASH_CMD_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) 		pm8001_ha->fw_status = FAIL_PARAMETERS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) 	ret = request_firmware(&pm8001_ha->fw_image,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) 			       filename_ptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) 			       pm8001_ha->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) 		pm8001_dbg(pm8001_ha, FAIL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) 			   "Failed to load firmware image file %s, error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) 			   filename_ptr, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) 		pm8001_ha->fw_status = FAIL_OPEN_BIOS_FILE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) 	if (FLASH_CMD_UPDATE == flash_command)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) 		ret = pm8001_update_flash(pm8001_ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) 		ret = pm8001_set_nvmd(pm8001_ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) 	release_firmware(pm8001_ha->fw_image);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) 	kfree(cmd_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) 	pm8001_ha->fw_status = FLASH_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) static ssize_t pm8001_show_update_fw(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) 				     struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) 	struct Scsi_Host *shost = class_to_shost(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) 	for (i = 0; flash_error_table[i].err_code != 0; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) 		if (flash_error_table[i].err_code == pm8001_ha->fw_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) 	if (pm8001_ha->fw_status != FLASH_IN_PROGRESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) 		pm8001_ha->fw_status = FLASH_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) 	return snprintf(buf, PAGE_SIZE, "status=%x %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) 			flash_error_table[i].err_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) 			flash_error_table[i].reason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) static DEVICE_ATTR(update_fw, S_IRUGO|S_IWUSR|S_IWGRP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) 	pm8001_show_update_fw, pm8001_store_update_fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) struct device_attribute *pm8001_host_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) 	&dev_attr_interface_rev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) 	&dev_attr_controller_fatal_error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) 	&dev_attr_fw_version,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) 	&dev_attr_update_fw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) 	&dev_attr_aap_log,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) 	&dev_attr_iop_log,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) 	&dev_attr_fatal_log,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) 	&dev_attr_non_fatal_log,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) 	&dev_attr_non_fatal_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) 	&dev_attr_gsm_log,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) 	&dev_attr_max_out_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) 	&dev_attr_max_devices,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) 	&dev_attr_max_sg_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) 	&dev_attr_sas_spec_support,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) 	&dev_attr_logging_level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) 	&dev_attr_event_log_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) 	&dev_attr_host_sas_address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) 	&dev_attr_bios_version,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) 	&dev_attr_ib_log,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) 	&dev_attr_ob_log,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) 	&dev_attr_ila_version,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) 	&dev_attr_inc_fw_ver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914)