xref: /openbmc/linux/drivers/scsi/pm8001/pm8001_ctl.c (revision 679062c6)
1dbf9bfe6Sjack wang /*
2e5742101SSakthivel K  * PMC-Sierra 8001/8081/8088/8089 SAS/SATA based host adapters driver
3dbf9bfe6Sjack wang  *
4dbf9bfe6Sjack wang  * Copyright (c) 2008-2009 USI Co., Ltd.
5dbf9bfe6Sjack wang  * All rights reserved.
6dbf9bfe6Sjack wang  *
7dbf9bfe6Sjack wang  * Redistribution and use in source and binary forms, with or without
8dbf9bfe6Sjack wang  * modification, are permitted provided that the following conditions
9dbf9bfe6Sjack wang  * are met:
10dbf9bfe6Sjack wang  * 1. Redistributions of source code must retain the above copyright
11dbf9bfe6Sjack wang  *    notice, this list of conditions, and the following disclaimer,
12dbf9bfe6Sjack wang  *    without modification.
13dbf9bfe6Sjack wang  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
14dbf9bfe6Sjack wang  *    substantially similar to the "NO WARRANTY" disclaimer below
15dbf9bfe6Sjack wang  *    ("Disclaimer") and any redistribution must be conditioned upon
16dbf9bfe6Sjack wang  *    including a substantially similar Disclaimer requirement for further
17dbf9bfe6Sjack wang  *    binary redistribution.
18dbf9bfe6Sjack wang  * 3. Neither the names of the above-listed copyright holders nor the names
19dbf9bfe6Sjack wang  *    of any contributors may be used to endorse or promote products derived
20dbf9bfe6Sjack wang  *    from this software without specific prior written permission.
21dbf9bfe6Sjack wang  *
22dbf9bfe6Sjack wang  * Alternatively, this software may be distributed under the terms of the
23dbf9bfe6Sjack wang  * GNU General Public License ("GPL") version 2 as published by the Free
24dbf9bfe6Sjack wang  * Software Foundation.
25dbf9bfe6Sjack wang  *
26dbf9bfe6Sjack wang  * NO WARRANTY
27dbf9bfe6Sjack wang  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28dbf9bfe6Sjack wang  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29dbf9bfe6Sjack wang  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
30dbf9bfe6Sjack wang  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31dbf9bfe6Sjack wang  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32dbf9bfe6Sjack wang  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33dbf9bfe6Sjack wang  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34dbf9bfe6Sjack wang  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
35dbf9bfe6Sjack wang  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
36dbf9bfe6Sjack wang  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37dbf9bfe6Sjack wang  * POSSIBILITY OF SUCH DAMAGES.
38dbf9bfe6Sjack wang  *
39dbf9bfe6Sjack wang  */
40dbf9bfe6Sjack wang #include <linux/firmware.h>
415a0e3ad6STejun Heo #include <linux/slab.h>
42dbf9bfe6Sjack wang #include "pm8001_sas.h"
43dbf9bfe6Sjack wang #include "pm8001_ctl.h"
444ddbea1bSVishakha Channapattan #include "pm8001_chips.h"
45dbf9bfe6Sjack wang 
46dbf9bfe6Sjack wang /* scsi host attributes */
47dbf9bfe6Sjack wang 
48dbf9bfe6Sjack wang /**
49dbf9bfe6Sjack wang  * pm8001_ctl_mpi_interface_rev_show - MPI interface revision number
50dbf9bfe6Sjack wang  * @cdev: pointer to embedded class device
51e1c3e0f8SLee Jones  * @attr: device attribute (unused)
52dbf9bfe6Sjack wang  * @buf: the buffer returned
53dbf9bfe6Sjack wang  *
54dbf9bfe6Sjack wang  * A sysfs 'read-only' shost attribute.
55dbf9bfe6Sjack wang  */
pm8001_ctl_mpi_interface_rev_show(struct device * cdev,struct device_attribute * attr,char * buf)56dbf9bfe6Sjack wang static ssize_t pm8001_ctl_mpi_interface_rev_show(struct device *cdev,
57dbf9bfe6Sjack wang 	struct device_attribute *attr, char *buf)
58dbf9bfe6Sjack wang {
59dbf9bfe6Sjack wang 	struct Scsi_Host *shost = class_to_shost(cdev);
60dbf9bfe6Sjack wang 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
61dbf9bfe6Sjack wang 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
62dbf9bfe6Sjack wang 
63e5742101SSakthivel K 	if (pm8001_ha->chip_id == chip_8001) {
64*679062c6SDeepak R Varma 		return sysfs_emit(buf, "%d\n",
65e5742101SSakthivel K 			pm8001_ha->main_cfg_tbl.pm8001_tbl.interface_rev);
66e5742101SSakthivel K 	} else {
67*679062c6SDeepak R Varma 		return sysfs_emit(buf, "%d\n",
68e5742101SSakthivel K 			pm8001_ha->main_cfg_tbl.pm80xx_tbl.interface_rev);
69e5742101SSakthivel K 	}
70dbf9bfe6Sjack wang }
71dbf9bfe6Sjack wang static
72dbf9bfe6Sjack wang DEVICE_ATTR(interface_rev, S_IRUGO, pm8001_ctl_mpi_interface_rev_show, NULL);
73dbf9bfe6Sjack wang 
74dbf9bfe6Sjack wang /**
75e2773c67SDeepak Ukey  * controller_fatal_error_show - check controller is under fatal err
76e2773c67SDeepak Ukey  * @cdev: pointer to embedded class device
77e1c3e0f8SLee Jones  * @attr: device attribute (unused)
78e2773c67SDeepak Ukey  * @buf: the buffer returned
79e2773c67SDeepak Ukey  *
80bb6beabfSRandy Dunlap  * A sysfs 'read-only' shost attribute.
81e2773c67SDeepak Ukey  */
controller_fatal_error_show(struct device * cdev,struct device_attribute * attr,char * buf)82e2773c67SDeepak Ukey static ssize_t controller_fatal_error_show(struct device *cdev,
83e2773c67SDeepak Ukey 		struct device_attribute *attr, char *buf)
84e2773c67SDeepak Ukey {
85e2773c67SDeepak Ukey 	struct Scsi_Host *shost = class_to_shost(cdev);
86e2773c67SDeepak Ukey 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
87e2773c67SDeepak Ukey 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
88e2773c67SDeepak Ukey 
89*679062c6SDeepak R Varma 	return sysfs_emit(buf, "%d\n",
90e2773c67SDeepak Ukey 			pm8001_ha->controller_fatal_error);
91e2773c67SDeepak Ukey }
92e2773c67SDeepak Ukey static DEVICE_ATTR_RO(controller_fatal_error);
93e2773c67SDeepak Ukey 
94e2773c67SDeepak Ukey /**
95dbf9bfe6Sjack wang  * pm8001_ctl_fw_version_show - firmware version
96dbf9bfe6Sjack wang  * @cdev: pointer to embedded class device
97cd2eebfdSLee Jones  * @attr: device attribute (unused)
98dbf9bfe6Sjack wang  * @buf: the buffer returned
99dbf9bfe6Sjack wang  *
100dbf9bfe6Sjack wang  * A sysfs 'read-only' shost attribute.
101dbf9bfe6Sjack wang  */
pm8001_ctl_fw_version_show(struct device * cdev,struct device_attribute * attr,char * buf)102dbf9bfe6Sjack wang static ssize_t pm8001_ctl_fw_version_show(struct device *cdev,
103dbf9bfe6Sjack wang 	struct device_attribute *attr, char *buf)
104dbf9bfe6Sjack wang {
105dbf9bfe6Sjack wang 	struct Scsi_Host *shost = class_to_shost(cdev);
106dbf9bfe6Sjack wang 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
107dbf9bfe6Sjack wang 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
108dbf9bfe6Sjack wang 
109e5742101SSakthivel K 	if (pm8001_ha->chip_id == chip_8001) {
110*679062c6SDeepak R Varma 		return sysfs_emit(buf, "%02x.%02x.%02x.%02x\n",
111e5742101SSakthivel K 		(u8)(pm8001_ha->main_cfg_tbl.pm8001_tbl.firmware_rev >> 24),
112e5742101SSakthivel K 		(u8)(pm8001_ha->main_cfg_tbl.pm8001_tbl.firmware_rev >> 16),
113e5742101SSakthivel K 		(u8)(pm8001_ha->main_cfg_tbl.pm8001_tbl.firmware_rev >> 8),
114e5742101SSakthivel K 		(u8)(pm8001_ha->main_cfg_tbl.pm8001_tbl.firmware_rev));
115e5742101SSakthivel K 	} else {
116*679062c6SDeepak R Varma 		return sysfs_emit(buf, "%02x.%02x.%02x.%02x\n",
117e5742101SSakthivel K 		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.firmware_rev >> 24),
118e5742101SSakthivel K 		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.firmware_rev >> 16),
119e5742101SSakthivel K 		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.firmware_rev >> 8),
120e5742101SSakthivel K 		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.firmware_rev));
121e5742101SSakthivel K 	}
122dbf9bfe6Sjack wang }
123dbf9bfe6Sjack wang static DEVICE_ATTR(fw_version, S_IRUGO, pm8001_ctl_fw_version_show, NULL);
12424fff017SViswas G 
12524fff017SViswas G /**
12624fff017SViswas G  * pm8001_ctl_ila_version_show - ila version
12724fff017SViswas G  * @cdev: pointer to embedded class device
128e1c3e0f8SLee Jones  * @attr: device attribute (unused)
12924fff017SViswas G  * @buf: the buffer returned
13024fff017SViswas G  *
13124fff017SViswas G  * A sysfs 'read-only' shost attribute.
13224fff017SViswas G  */
pm8001_ctl_ila_version_show(struct device * cdev,struct device_attribute * attr,char * buf)13324fff017SViswas G static ssize_t pm8001_ctl_ila_version_show(struct device *cdev,
13424fff017SViswas G 	struct device_attribute *attr, char *buf)
13524fff017SViswas G {
13624fff017SViswas G 	struct Scsi_Host *shost = class_to_shost(cdev);
13724fff017SViswas G 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
13824fff017SViswas G 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
13924fff017SViswas G 
14024fff017SViswas G 	if (pm8001_ha->chip_id != chip_8001) {
141*679062c6SDeepak R Varma 		return sysfs_emit(buf, "%02x.%02x.%02x.%02x\n",
14224fff017SViswas G 		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.ila_version >> 24),
14324fff017SViswas G 		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.ila_version >> 16),
14424fff017SViswas G 		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.ila_version >> 8),
14524fff017SViswas G 		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.ila_version));
14624fff017SViswas G 	}
14724fff017SViswas G 	return 0;
14824fff017SViswas G }
14924fff017SViswas G static DEVICE_ATTR(ila_version, 0444, pm8001_ctl_ila_version_show, NULL);
15024fff017SViswas G 
15124fff017SViswas G /**
152bb6beabfSRandy Dunlap  * pm8001_ctl_inactive_fw_version_show - Inactive firmware version number
15324fff017SViswas G  * @cdev: pointer to embedded class device
154e1c3e0f8SLee Jones  * @attr: device attribute (unused)
15524fff017SViswas G  * @buf: the buffer returned
15624fff017SViswas G  *
15724fff017SViswas G  * A sysfs 'read-only' shost attribute.
15824fff017SViswas G  */
pm8001_ctl_inactive_fw_version_show(struct device * cdev,struct device_attribute * attr,char * buf)15924fff017SViswas G static ssize_t pm8001_ctl_inactive_fw_version_show(struct device *cdev,
16024fff017SViswas G 	struct device_attribute *attr, char *buf)
16124fff017SViswas G {
16224fff017SViswas G 	struct Scsi_Host *shost = class_to_shost(cdev);
16324fff017SViswas G 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
16424fff017SViswas G 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
16524fff017SViswas G 
16624fff017SViswas G 	if (pm8001_ha->chip_id != chip_8001) {
167*679062c6SDeepak R Varma 		return sysfs_emit(buf, "%02x.%02x.%02x.%02x\n",
16824fff017SViswas G 		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.inc_fw_version >> 24),
16924fff017SViswas G 		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.inc_fw_version >> 16),
17024fff017SViswas G 		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.inc_fw_version >> 8),
17124fff017SViswas G 		(u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.inc_fw_version));
17224fff017SViswas G 	}
17324fff017SViswas G 	return 0;
17424fff017SViswas G }
17524fff017SViswas G static
17624fff017SViswas G DEVICE_ATTR(inc_fw_ver, 0444, pm8001_ctl_inactive_fw_version_show, NULL);
17724fff017SViswas G 
178dbf9bfe6Sjack wang /**
179dbf9bfe6Sjack wang  * pm8001_ctl_max_out_io_show - max outstanding io supported
180dbf9bfe6Sjack wang  * @cdev: pointer to embedded class device
181e1c3e0f8SLee Jones  * @attr: device attribute (unused)
182dbf9bfe6Sjack wang  * @buf: the buffer returned
183dbf9bfe6Sjack wang  *
184dbf9bfe6Sjack wang  * A sysfs 'read-only' shost attribute.
185dbf9bfe6Sjack wang  */
pm8001_ctl_max_out_io_show(struct device * cdev,struct device_attribute * attr,char * buf)186dbf9bfe6Sjack wang static ssize_t pm8001_ctl_max_out_io_show(struct device *cdev,
187dbf9bfe6Sjack wang 	struct device_attribute *attr, char *buf)
188dbf9bfe6Sjack wang {
189dbf9bfe6Sjack wang 	struct Scsi_Host *shost = class_to_shost(cdev);
190dbf9bfe6Sjack wang 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
191dbf9bfe6Sjack wang 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
192dbf9bfe6Sjack wang 
193e5742101SSakthivel K 	if (pm8001_ha->chip_id == chip_8001) {
194*679062c6SDeepak R Varma 		return sysfs_emit(buf, "%d\n",
195e5742101SSakthivel K 			pm8001_ha->main_cfg_tbl.pm8001_tbl.max_out_io);
196e5742101SSakthivel K 	} else {
197*679062c6SDeepak R Varma 		return sysfs_emit(buf, "%d\n",
198e5742101SSakthivel K 			pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_out_io);
199e5742101SSakthivel K 	}
200dbf9bfe6Sjack wang }
201dbf9bfe6Sjack wang static DEVICE_ATTR(max_out_io, S_IRUGO, pm8001_ctl_max_out_io_show, NULL);
202dbf9bfe6Sjack wang /**
203dbf9bfe6Sjack wang  * pm8001_ctl_max_devices_show - max devices support
204dbf9bfe6Sjack wang  * @cdev: pointer to embedded class device
205e1c3e0f8SLee Jones  * @attr: device attribute (unused)
206dbf9bfe6Sjack wang  * @buf: the buffer returned
207dbf9bfe6Sjack wang  *
208dbf9bfe6Sjack wang  * A sysfs 'read-only' shost attribute.
209dbf9bfe6Sjack wang  */
pm8001_ctl_max_devices_show(struct device * cdev,struct device_attribute * attr,char * buf)210dbf9bfe6Sjack wang static ssize_t pm8001_ctl_max_devices_show(struct device *cdev,
211dbf9bfe6Sjack wang 	struct device_attribute *attr, char *buf)
212dbf9bfe6Sjack wang {
213dbf9bfe6Sjack wang 	struct Scsi_Host *shost = class_to_shost(cdev);
214dbf9bfe6Sjack wang 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
215dbf9bfe6Sjack wang 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
216dbf9bfe6Sjack wang 
217e5742101SSakthivel K 	if (pm8001_ha->chip_id == chip_8001) {
218*679062c6SDeepak R Varma 		return sysfs_emit(buf, "%04d\n",
219*679062c6SDeepak R Varma 			(u16)(pm8001_ha->main_cfg_tbl.pm8001_tbl.max_sgl >> 16));
220e5742101SSakthivel K 	} else {
221*679062c6SDeepak R Varma 		return sysfs_emit(buf, "%04d\n",
222*679062c6SDeepak R Varma 			(u16)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_sgl >> 16));
223e5742101SSakthivel K 	}
224dbf9bfe6Sjack wang }
225dbf9bfe6Sjack wang static DEVICE_ATTR(max_devices, S_IRUGO, pm8001_ctl_max_devices_show, NULL);
226dbf9bfe6Sjack wang /**
227dbf9bfe6Sjack wang  * pm8001_ctl_max_sg_list_show - max sg list supported iff not 0.0 for no
228dbf9bfe6Sjack wang  * hardware limitation
229dbf9bfe6Sjack wang  * @cdev: pointer to embedded class device
230e1c3e0f8SLee Jones  * @attr: device attribute (unused)
231dbf9bfe6Sjack wang  * @buf: the buffer returned
232dbf9bfe6Sjack wang  *
233dbf9bfe6Sjack wang  * A sysfs 'read-only' shost attribute.
234dbf9bfe6Sjack wang  */
pm8001_ctl_max_sg_list_show(struct device * cdev,struct device_attribute * attr,char * buf)235dbf9bfe6Sjack wang static ssize_t pm8001_ctl_max_sg_list_show(struct device *cdev,
236dbf9bfe6Sjack wang 	struct device_attribute *attr, char *buf)
237dbf9bfe6Sjack wang {
238dbf9bfe6Sjack wang 	struct Scsi_Host *shost = class_to_shost(cdev);
239dbf9bfe6Sjack wang 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
240dbf9bfe6Sjack wang 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
241dbf9bfe6Sjack wang 
242e5742101SSakthivel K 	if (pm8001_ha->chip_id == chip_8001) {
243*679062c6SDeepak R Varma 		return sysfs_emit(buf, "%04d\n",
244*679062c6SDeepak R Varma 			pm8001_ha->main_cfg_tbl.pm8001_tbl.max_sgl & 0x0000FFFF);
245e5742101SSakthivel K 	} else {
246*679062c6SDeepak R Varma 		return sysfs_emit(buf, "%04d\n",
247*679062c6SDeepak R Varma 			pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_sgl & 0x0000FFFF);
248e5742101SSakthivel K 	}
249dbf9bfe6Sjack wang }
250dbf9bfe6Sjack wang static DEVICE_ATTR(max_sg_list, S_IRUGO, pm8001_ctl_max_sg_list_show, NULL);
251dbf9bfe6Sjack wang 
252dbf9bfe6Sjack wang #define SAS_1_0 0x1
253dbf9bfe6Sjack wang #define SAS_1_1 0x2
254dbf9bfe6Sjack wang #define SAS_2_0 0x4
255dbf9bfe6Sjack wang 
256dbf9bfe6Sjack wang static ssize_t
show_sas_spec_support_status(unsigned int mode,char * buf)257dbf9bfe6Sjack wang show_sas_spec_support_status(unsigned int mode, char *buf)
258dbf9bfe6Sjack wang {
259dbf9bfe6Sjack wang 	ssize_t len = 0;
260dbf9bfe6Sjack wang 
261dbf9bfe6Sjack wang 	if (mode & SAS_1_1)
262dbf9bfe6Sjack wang 		len = sprintf(buf, "%s", "SAS1.1");
263dbf9bfe6Sjack wang 	if (mode & SAS_2_0)
264dbf9bfe6Sjack wang 		len += sprintf(buf + len, "%s%s", len ? ", " : "", "SAS2.0");
265dbf9bfe6Sjack wang 	len += sprintf(buf + len, "\n");
266dbf9bfe6Sjack wang 
267dbf9bfe6Sjack wang 	return len;
268dbf9bfe6Sjack wang }
269dbf9bfe6Sjack wang 
270dbf9bfe6Sjack wang /**
271dbf9bfe6Sjack wang  * pm8001_ctl_sas_spec_support_show - sas spec supported
272dbf9bfe6Sjack wang  * @cdev: pointer to embedded class device
273e1c3e0f8SLee Jones  * @attr: device attribute (unused)
274dbf9bfe6Sjack wang  * @buf: the buffer returned
275dbf9bfe6Sjack wang  *
276dbf9bfe6Sjack wang  * A sysfs 'read-only' shost attribute.
277dbf9bfe6Sjack wang  */
pm8001_ctl_sas_spec_support_show(struct device * cdev,struct device_attribute * attr,char * buf)278dbf9bfe6Sjack wang static ssize_t pm8001_ctl_sas_spec_support_show(struct device *cdev,
279dbf9bfe6Sjack wang 	struct device_attribute *attr, char *buf)
280dbf9bfe6Sjack wang {
281dbf9bfe6Sjack wang 	unsigned int mode;
282dbf9bfe6Sjack wang 	struct Scsi_Host *shost = class_to_shost(cdev);
283dbf9bfe6Sjack wang 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
284dbf9bfe6Sjack wang 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
285e5742101SSakthivel K 	/* fe000000 means supports SAS2.1 */
286e5742101SSakthivel K 	if (pm8001_ha->chip_id == chip_8001)
287e5742101SSakthivel K 		mode = (pm8001_ha->main_cfg_tbl.pm8001_tbl.ctrl_cap_flag &
288e5742101SSakthivel K 							0xfe000000)>>25;
289e5742101SSakthivel K 	else
290e5742101SSakthivel K 		/* fe000000 means supports SAS2.1 */
291e5742101SSakthivel K 		mode = (pm8001_ha->main_cfg_tbl.pm80xx_tbl.ctrl_cap_flag &
292e5742101SSakthivel K 							0xfe000000)>>25;
293dbf9bfe6Sjack wang 	return show_sas_spec_support_status(mode, buf);
294dbf9bfe6Sjack wang }
295dbf9bfe6Sjack wang static DEVICE_ATTR(sas_spec_support, S_IRUGO,
296dbf9bfe6Sjack wang 		   pm8001_ctl_sas_spec_support_show, NULL);
297dbf9bfe6Sjack wang 
298dbf9bfe6Sjack wang /**
2993978e59bSLee Jones  * pm8001_ctl_host_sas_address_show - sas address
300dbf9bfe6Sjack wang  * @cdev: pointer to embedded class device
301e1c3e0f8SLee Jones  * @attr: device attribute (unused)
302dbf9bfe6Sjack wang  * @buf: the buffer returned
303dbf9bfe6Sjack wang  *
304dbf9bfe6Sjack wang  * This is the controller sas address
305dbf9bfe6Sjack wang  *
306dbf9bfe6Sjack wang  * A sysfs 'read-only' shost attribute.
307dbf9bfe6Sjack wang  */
pm8001_ctl_host_sas_address_show(struct device * cdev,struct device_attribute * attr,char * buf)308dbf9bfe6Sjack wang static ssize_t pm8001_ctl_host_sas_address_show(struct device *cdev,
309dbf9bfe6Sjack wang 	struct device_attribute *attr, char *buf)
310dbf9bfe6Sjack wang {
311dbf9bfe6Sjack wang 	struct Scsi_Host *shost = class_to_shost(cdev);
312dbf9bfe6Sjack wang 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
313dbf9bfe6Sjack wang 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
314*679062c6SDeepak R Varma 	return sysfs_emit(buf, "0x%016llx\n",
315dbf9bfe6Sjack wang 			be64_to_cpu(*(__be64 *)pm8001_ha->sas_addr));
316dbf9bfe6Sjack wang }
317dbf9bfe6Sjack wang static DEVICE_ATTR(host_sas_address, S_IRUGO,
318dbf9bfe6Sjack wang 		   pm8001_ctl_host_sas_address_show, NULL);
319dbf9bfe6Sjack wang 
320dbf9bfe6Sjack wang /**
321dbf9bfe6Sjack wang  * pm8001_ctl_logging_level_show - logging level
322dbf9bfe6Sjack wang  * @cdev: pointer to embedded class device
323cd2eebfdSLee Jones  * @attr: device attribute (unused)
324dbf9bfe6Sjack wang  * @buf: the buffer returned
325dbf9bfe6Sjack wang  *
326dbf9bfe6Sjack wang  * A sysfs 'read/write' shost attribute.
327dbf9bfe6Sjack wang  */
pm8001_ctl_logging_level_show(struct device * cdev,struct device_attribute * attr,char * buf)328dbf9bfe6Sjack wang static ssize_t pm8001_ctl_logging_level_show(struct device *cdev,
329dbf9bfe6Sjack wang 	struct device_attribute *attr, char *buf)
330dbf9bfe6Sjack wang {
331dbf9bfe6Sjack wang 	struct Scsi_Host *shost = class_to_shost(cdev);
332dbf9bfe6Sjack wang 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
333dbf9bfe6Sjack wang 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
334dbf9bfe6Sjack wang 
335*679062c6SDeepak R Varma 	return sysfs_emit(buf, "%08xh\n", pm8001_ha->logging_level);
336dbf9bfe6Sjack wang }
337cd2eebfdSLee Jones 
pm8001_ctl_logging_level_store(struct device * cdev,struct device_attribute * attr,const char * buf,size_t count)338dbf9bfe6Sjack wang static ssize_t pm8001_ctl_logging_level_store(struct device *cdev,
339dbf9bfe6Sjack wang 	struct device_attribute *attr, const char *buf, size_t count)
340dbf9bfe6Sjack wang {
341dbf9bfe6Sjack wang 	struct Scsi_Host *shost = class_to_shost(cdev);
342dbf9bfe6Sjack wang 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
343dbf9bfe6Sjack wang 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
344dbf9bfe6Sjack wang 	int val = 0;
345dbf9bfe6Sjack wang 
346dbf9bfe6Sjack wang 	if (sscanf(buf, "%x", &val) != 1)
347dbf9bfe6Sjack wang 		return -EINVAL;
348dbf9bfe6Sjack wang 
349dbf9bfe6Sjack wang 	pm8001_ha->logging_level = val;
350dbf9bfe6Sjack wang 	return strlen(buf);
351dbf9bfe6Sjack wang }
352dbf9bfe6Sjack wang 
353dbf9bfe6Sjack wang static DEVICE_ATTR(logging_level, S_IRUGO | S_IWUSR,
354dbf9bfe6Sjack wang 	pm8001_ctl_logging_level_show, pm8001_ctl_logging_level_store);
355dbf9bfe6Sjack wang /**
356dbf9bfe6Sjack wang  * pm8001_ctl_aap_log_show - aap1 event log
357dbf9bfe6Sjack wang  * @cdev: pointer to embedded class device
358e1c3e0f8SLee Jones  * @attr: device attribute (unused)
359dbf9bfe6Sjack wang  * @buf: the buffer returned
360dbf9bfe6Sjack wang  *
361dbf9bfe6Sjack wang  * A sysfs 'read-only' shost attribute.
362dbf9bfe6Sjack wang  */
pm8001_ctl_aap_log_show(struct device * cdev,struct device_attribute * attr,char * buf)363dbf9bfe6Sjack wang static ssize_t pm8001_ctl_aap_log_show(struct device *cdev,
364dbf9bfe6Sjack wang 	struct device_attribute *attr, char *buf)
365dbf9bfe6Sjack wang {
366dbf9bfe6Sjack wang 	struct Scsi_Host *shost = class_to_shost(cdev);
367dbf9bfe6Sjack wang 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
368dbf9bfe6Sjack wang 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
3698a23dbc6SLuo Jiaxing 	u8 *ptr = (u8 *)pm8001_ha->memoryMap.region[AAP1].virt_ptr;
370dbf9bfe6Sjack wang 	int i;
371dbf9bfe6Sjack wang 
372dbf9bfe6Sjack wang 	char *str = buf;
373dbf9bfe6Sjack wang 	int max = 2;
374dbf9bfe6Sjack wang 	for (i = 0; i < max; i++) {
375dbf9bfe6Sjack wang 		str += sprintf(str, "0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x"
376dbf9bfe6Sjack wang 			       "0x%08x 0x%08x\n",
3778a23dbc6SLuo Jiaxing 			       pm8001_ctl_aap1_memmap(ptr, i, 0),
3788a23dbc6SLuo Jiaxing 			       pm8001_ctl_aap1_memmap(ptr, i, 4),
3798a23dbc6SLuo Jiaxing 			       pm8001_ctl_aap1_memmap(ptr, i, 8),
3808a23dbc6SLuo Jiaxing 			       pm8001_ctl_aap1_memmap(ptr, i, 12),
3818a23dbc6SLuo Jiaxing 			       pm8001_ctl_aap1_memmap(ptr, i, 16),
3828a23dbc6SLuo Jiaxing 			       pm8001_ctl_aap1_memmap(ptr, i, 20),
3838a23dbc6SLuo Jiaxing 			       pm8001_ctl_aap1_memmap(ptr, i, 24),
3848a23dbc6SLuo Jiaxing 			       pm8001_ctl_aap1_memmap(ptr, i, 28));
385dbf9bfe6Sjack wang 	}
386dbf9bfe6Sjack wang 
387dbf9bfe6Sjack wang 	return str - buf;
388dbf9bfe6Sjack wang }
389dbf9bfe6Sjack wang static DEVICE_ATTR(aap_log, S_IRUGO, pm8001_ctl_aap_log_show, NULL);
390dbf9bfe6Sjack wang /**
391d078b511SAnand Kumar Santhanam  * pm8001_ctl_ib_queue_log_show - Out bound Queue log
392d078b511SAnand Kumar Santhanam  * @cdev:pointer to embedded class device
393cd2eebfdSLee Jones  * @attr: device attribute (unused)
394d078b511SAnand Kumar Santhanam  * @buf: the buffer returned
395bb6beabfSRandy Dunlap  *
396d078b511SAnand Kumar Santhanam  * A sysfs 'read-only' shost attribute.
397d078b511SAnand Kumar Santhanam  */
pm8001_ctl_ib_queue_log_show(struct device * cdev,struct device_attribute * attr,char * buf)398d078b511SAnand Kumar Santhanam static ssize_t pm8001_ctl_ib_queue_log_show(struct device *cdev,
399d078b511SAnand Kumar Santhanam 	struct device_attribute *attr, char *buf)
400d078b511SAnand Kumar Santhanam {
401d078b511SAnand Kumar Santhanam 	struct Scsi_Host *shost = class_to_shost(cdev);
402d078b511SAnand Kumar Santhanam 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
403d078b511SAnand Kumar Santhanam 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
404d078b511SAnand Kumar Santhanam 	int offset;
405d078b511SAnand Kumar Santhanam 	char *str = buf;
406d078b511SAnand Kumar Santhanam 	int start = 0;
40705c6c029SViswas G 	u32 ib_offset = pm8001_ha->ib_offset;
408c29737d0SViswas G 	u32 queue_size = pm8001_ha->max_q_num * PM8001_MPI_QUEUE * 128;
409d078b511SAnand Kumar Santhanam #define IB_MEMMAP(c)	\
410d078b511SAnand Kumar Santhanam 		(*(u32 *)((u8 *)pm8001_ha->	\
41105c6c029SViswas G 		memoryMap.region[ib_offset].virt_ptr +	\
412d078b511SAnand Kumar Santhanam 		pm8001_ha->evtlog_ib_offset + (c)))
413d078b511SAnand Kumar Santhanam 
414d078b511SAnand Kumar Santhanam 	for (offset = 0; offset < IB_OB_READ_TIMES; offset++) {
415d078b511SAnand Kumar Santhanam 		str += sprintf(str, "0x%08x\n", IB_MEMMAP(start));
416d078b511SAnand Kumar Santhanam 		start = start + 4;
417d078b511SAnand Kumar Santhanam 	}
418d078b511SAnand Kumar Santhanam 	pm8001_ha->evtlog_ib_offset += SYSFS_OFFSET;
419c29737d0SViswas G 	if (((pm8001_ha->evtlog_ib_offset) % queue_size) == 0)
420d078b511SAnand Kumar Santhanam 		pm8001_ha->evtlog_ib_offset = 0;
421d078b511SAnand Kumar Santhanam 
422d078b511SAnand Kumar Santhanam 	return str - buf;
423d078b511SAnand Kumar Santhanam }
424d078b511SAnand Kumar Santhanam 
425d078b511SAnand Kumar Santhanam static DEVICE_ATTR(ib_log, S_IRUGO, pm8001_ctl_ib_queue_log_show, NULL);
426d078b511SAnand Kumar Santhanam /**
427d078b511SAnand Kumar Santhanam  * pm8001_ctl_ob_queue_log_show - Out bound Queue log
428d078b511SAnand Kumar Santhanam  * @cdev:pointer to embedded class device
429cd2eebfdSLee Jones  * @attr: device attribute (unused)
430d078b511SAnand Kumar Santhanam  * @buf: the buffer returned
431bb6beabfSRandy Dunlap  *
432d078b511SAnand Kumar Santhanam  * A sysfs 'read-only' shost attribute.
433d078b511SAnand Kumar Santhanam  */
434d078b511SAnand Kumar Santhanam 
pm8001_ctl_ob_queue_log_show(struct device * cdev,struct device_attribute * attr,char * buf)435d078b511SAnand Kumar Santhanam static ssize_t pm8001_ctl_ob_queue_log_show(struct device *cdev,
436d078b511SAnand Kumar Santhanam 	struct device_attribute *attr, char *buf)
437d078b511SAnand Kumar Santhanam {
438d078b511SAnand Kumar Santhanam 	struct Scsi_Host *shost = class_to_shost(cdev);
439d078b511SAnand Kumar Santhanam 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
440d078b511SAnand Kumar Santhanam 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
441d078b511SAnand Kumar Santhanam 	int offset;
442d078b511SAnand Kumar Santhanam 	char *str = buf;
443d078b511SAnand Kumar Santhanam 	int start = 0;
44405c6c029SViswas G 	u32 ob_offset = pm8001_ha->ob_offset;
445c29737d0SViswas G 	u32 queue_size = pm8001_ha->max_q_num * PM8001_MPI_QUEUE * 128;
446d078b511SAnand Kumar Santhanam #define OB_MEMMAP(c)	\
447d078b511SAnand Kumar Santhanam 		(*(u32 *)((u8 *)pm8001_ha->	\
44805c6c029SViswas G 		memoryMap.region[ob_offset].virt_ptr +	\
449d078b511SAnand Kumar Santhanam 		pm8001_ha->evtlog_ob_offset + (c)))
450d078b511SAnand Kumar Santhanam 
451d078b511SAnand Kumar Santhanam 	for (offset = 0; offset < IB_OB_READ_TIMES; offset++) {
452d078b511SAnand Kumar Santhanam 		str += sprintf(str, "0x%08x\n", OB_MEMMAP(start));
453d078b511SAnand Kumar Santhanam 		start = start + 4;
454d078b511SAnand Kumar Santhanam 	}
455d078b511SAnand Kumar Santhanam 	pm8001_ha->evtlog_ob_offset += SYSFS_OFFSET;
456c29737d0SViswas G 	if (((pm8001_ha->evtlog_ob_offset) % queue_size) == 0)
457d078b511SAnand Kumar Santhanam 		pm8001_ha->evtlog_ob_offset = 0;
458d078b511SAnand Kumar Santhanam 
459d078b511SAnand Kumar Santhanam 	return str - buf;
460d078b511SAnand Kumar Santhanam }
461d078b511SAnand Kumar Santhanam static DEVICE_ATTR(ob_log, S_IRUGO, pm8001_ctl_ob_queue_log_show, NULL);
462d078b511SAnand Kumar Santhanam /**
463966fdcffSAnand Kumar Santhanam  * pm8001_ctl_bios_version_show - Bios version Display
464966fdcffSAnand Kumar Santhanam  * @cdev:pointer to embedded class device
465cd2eebfdSLee Jones  * @attr: device attribute (unused)
466966fdcffSAnand Kumar Santhanam  * @buf:the buffer returned
467bb6beabfSRandy Dunlap  *
468966fdcffSAnand Kumar Santhanam  * A sysfs 'read-only' shost attribute.
469966fdcffSAnand Kumar Santhanam  */
pm8001_ctl_bios_version_show(struct device * cdev,struct device_attribute * attr,char * buf)470966fdcffSAnand Kumar Santhanam static ssize_t pm8001_ctl_bios_version_show(struct device *cdev,
471966fdcffSAnand Kumar Santhanam 	struct device_attribute *attr, char *buf)
472966fdcffSAnand Kumar Santhanam {
473966fdcffSAnand Kumar Santhanam 	struct Scsi_Host *shost = class_to_shost(cdev);
474966fdcffSAnand Kumar Santhanam 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
475966fdcffSAnand Kumar Santhanam 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
476966fdcffSAnand Kumar Santhanam 	char *str = buf;
477966fdcffSAnand Kumar Santhanam 	int bios_index;
478966fdcffSAnand Kumar Santhanam 	DECLARE_COMPLETION_ONSTACK(completion);
479966fdcffSAnand Kumar Santhanam 	struct pm8001_ioctl_payload payload;
480966fdcffSAnand Kumar Santhanam 
481966fdcffSAnand Kumar Santhanam 	pm8001_ha->nvmd_completion = &completion;
482966fdcffSAnand Kumar Santhanam 	payload.minor_function = 7;
483966fdcffSAnand Kumar Santhanam 	payload.offset = 0;
4849b889846SViswas G 	payload.rd_length = 4096;
485966fdcffSAnand Kumar Santhanam 	payload.func_specific = kzalloc(4096, GFP_KERNEL);
486b42939aaSSuresh Thiagarajan 	if (!payload.func_specific)
487b42939aaSSuresh Thiagarajan 		return -ENOMEM;
4885b4ce882STomas Henzl 	if (PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload)) {
4895b4ce882STomas Henzl 		kfree(payload.func_specific);
4905b4ce882STomas Henzl 		return -ENOMEM;
4915b4ce882STomas Henzl 	}
492966fdcffSAnand Kumar Santhanam 	wait_for_completion(&completion);
493966fdcffSAnand Kumar Santhanam 	for (bios_index = BIOSOFFSET; bios_index < BIOS_OFFSET_LIMIT;
494966fdcffSAnand Kumar Santhanam 		bios_index++)
495966fdcffSAnand Kumar Santhanam 		str += sprintf(str, "%c",
4969e032845SSuresh Thiagarajan 			*(payload.func_specific+bios_index));
497b42939aaSSuresh Thiagarajan 	kfree(payload.func_specific);
498966fdcffSAnand Kumar Santhanam 	return str - buf;
499966fdcffSAnand Kumar Santhanam }
500966fdcffSAnand Kumar Santhanam static DEVICE_ATTR(bios_version, S_IRUGO, pm8001_ctl_bios_version_show, NULL);
501966fdcffSAnand Kumar Santhanam /**
5022040a857SDeepak Ukey  * event_log_size_show - event log size
5032040a857SDeepak Ukey  * @cdev: pointer to embedded class device
504e1c3e0f8SLee Jones  * @attr: device attribute (unused)
5052040a857SDeepak Ukey  * @buf: the buffer returned
5062040a857SDeepak Ukey  *
5072040a857SDeepak Ukey  * A sysfs read  shost attribute.
5082040a857SDeepak Ukey  */
event_log_size_show(struct device * cdev,struct device_attribute * attr,char * buf)5092040a857SDeepak Ukey static ssize_t event_log_size_show(struct device *cdev,
5102040a857SDeepak Ukey 	struct device_attribute *attr, char *buf)
5112040a857SDeepak Ukey {
5122040a857SDeepak Ukey 	struct Scsi_Host *shost = class_to_shost(cdev);
5132040a857SDeepak Ukey 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
5142040a857SDeepak Ukey 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
5152040a857SDeepak Ukey 
516*679062c6SDeepak R Varma 	return sysfs_emit(buf, "%d\n",
5172040a857SDeepak Ukey 		pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_size);
5182040a857SDeepak Ukey }
5192040a857SDeepak Ukey static DEVICE_ATTR_RO(event_log_size);
5202040a857SDeepak Ukey /**
5213978e59bSLee Jones  * pm8001_ctl_iop_log_show - IOP event log
522dbf9bfe6Sjack wang  * @cdev: pointer to embedded class device
523e1c3e0f8SLee Jones  * @attr: device attribute (unused)
524dbf9bfe6Sjack wang  * @buf: the buffer returned
525dbf9bfe6Sjack wang  *
526dbf9bfe6Sjack wang  * A sysfs 'read-only' shost attribute.
527dbf9bfe6Sjack wang  */
pm8001_ctl_iop_log_show(struct device * cdev,struct device_attribute * attr,char * buf)528dbf9bfe6Sjack wang static ssize_t pm8001_ctl_iop_log_show(struct device *cdev,
529dbf9bfe6Sjack wang 	struct device_attribute *attr, char *buf)
530dbf9bfe6Sjack wang {
531dbf9bfe6Sjack wang 	struct Scsi_Host *shost = class_to_shost(cdev);
532dbf9bfe6Sjack wang 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
533dbf9bfe6Sjack wang 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
534dbf9bfe6Sjack wang 	char *str = buf;
5355f0bd875SDeepak Ukey 	u32 read_size =
5365f0bd875SDeepak Ukey 		pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_size / 1024;
5375f0bd875SDeepak Ukey 	static u32 start, end, count;
5385f0bd875SDeepak Ukey 	u32 max_read_times = 32;
5395f0bd875SDeepak Ukey 	u32 max_count = (read_size * 1024) / (max_read_times * 4);
5405f0bd875SDeepak Ukey 	u32 *temp = (u32 *)pm8001_ha->memoryMap.region[IOP].virt_ptr;
5415f0bd875SDeepak Ukey 
5425f0bd875SDeepak Ukey 	if ((count % max_count) == 0) {
5435f0bd875SDeepak Ukey 		start = 0;
5445f0bd875SDeepak Ukey 		end = max_read_times;
5455f0bd875SDeepak Ukey 		count = 0;
5465f0bd875SDeepak Ukey 	} else {
5475f0bd875SDeepak Ukey 		start = end;
5485f0bd875SDeepak Ukey 		end = end + max_read_times;
549dbf9bfe6Sjack wang 	}
550dbf9bfe6Sjack wang 
5515f0bd875SDeepak Ukey 	for (; start < end; start++)
5525f0bd875SDeepak Ukey 		str += sprintf(str, "%08x ", *(temp+start));
5535f0bd875SDeepak Ukey 	count++;
554dbf9bfe6Sjack wang 	return str - buf;
555dbf9bfe6Sjack wang }
556dbf9bfe6Sjack wang static DEVICE_ATTR(iop_log, S_IRUGO, pm8001_ctl_iop_log_show, NULL);
557dbf9bfe6Sjack wang 
558d078b511SAnand Kumar Santhanam /**
559bb6beabfSRandy Dunlap  * pm8001_ctl_fatal_log_show - fatal error logging
560bb6beabfSRandy Dunlap  * @cdev:pointer to embedded class device
561bb6beabfSRandy Dunlap  * @attr: device attribute
562bb6beabfSRandy Dunlap  * @buf: the buffer returned
563bb6beabfSRandy Dunlap  *
564bb6beabfSRandy Dunlap  * A sysfs 'read-only' shost attribute.
565bb6beabfSRandy Dunlap  */
566d078b511SAnand Kumar Santhanam 
pm8001_ctl_fatal_log_show(struct device * cdev,struct device_attribute * attr,char * buf)567d078b511SAnand Kumar Santhanam static ssize_t pm8001_ctl_fatal_log_show(struct device *cdev,
568d078b511SAnand Kumar Santhanam 	struct device_attribute *attr, char *buf)
569d078b511SAnand Kumar Santhanam {
570cf370066SViswas G 	ssize_t count;
571d078b511SAnand Kumar Santhanam 
572d078b511SAnand Kumar Santhanam 	count = pm80xx_get_fatal_dump(cdev, attr, buf);
573d078b511SAnand Kumar Santhanam 	return count;
574d078b511SAnand Kumar Santhanam }
575d078b511SAnand Kumar Santhanam 
576d078b511SAnand Kumar Santhanam static DEVICE_ATTR(fatal_log, S_IRUGO, pm8001_ctl_fatal_log_show, NULL);
577d078b511SAnand Kumar Santhanam 
578dba2cc03SDeepak Ukey /**
579bb6beabfSRandy Dunlap  * non_fatal_log_show - non fatal error logging
580bb6beabfSRandy Dunlap  * @cdev:pointer to embedded class device
581bb6beabfSRandy Dunlap  * @attr: device attribute
582bb6beabfSRandy Dunlap  * @buf: the buffer returned
583bb6beabfSRandy Dunlap  *
584bb6beabfSRandy Dunlap  * A sysfs 'read-only' shost attribute.
585bb6beabfSRandy Dunlap  */
non_fatal_log_show(struct device * cdev,struct device_attribute * attr,char * buf)586dba2cc03SDeepak Ukey static ssize_t non_fatal_log_show(struct device *cdev,
587dba2cc03SDeepak Ukey 	struct device_attribute *attr, char *buf)
588dba2cc03SDeepak Ukey {
589dba2cc03SDeepak Ukey 	u32 count;
590dba2cc03SDeepak Ukey 
591dba2cc03SDeepak Ukey 	count = pm80xx_get_non_fatal_dump(cdev, attr, buf);
592dba2cc03SDeepak Ukey 	return count;
593dba2cc03SDeepak Ukey }
594dba2cc03SDeepak Ukey static DEVICE_ATTR_RO(non_fatal_log);
595dba2cc03SDeepak Ukey 
non_fatal_count_show(struct device * cdev,struct device_attribute * attr,char * buf)596dba2cc03SDeepak Ukey static ssize_t non_fatal_count_show(struct device *cdev,
597dba2cc03SDeepak Ukey 		struct device_attribute *attr, char *buf)
598dba2cc03SDeepak Ukey {
599dba2cc03SDeepak Ukey 	struct Scsi_Host *shost = class_to_shost(cdev);
600dba2cc03SDeepak Ukey 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
601dba2cc03SDeepak Ukey 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
602dba2cc03SDeepak Ukey 
603*679062c6SDeepak R Varma 	return sysfs_emit(buf, "%08x\n",
604dba2cc03SDeepak Ukey 			pm8001_ha->non_fatal_count);
605dba2cc03SDeepak Ukey }
606dba2cc03SDeepak Ukey 
non_fatal_count_store(struct device * cdev,struct device_attribute * attr,const char * buf,size_t count)607dba2cc03SDeepak Ukey static ssize_t non_fatal_count_store(struct device *cdev,
608dba2cc03SDeepak Ukey 		struct device_attribute *attr, const char *buf, size_t count)
609dba2cc03SDeepak Ukey {
610dba2cc03SDeepak Ukey 	struct Scsi_Host *shost = class_to_shost(cdev);
611dba2cc03SDeepak Ukey 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
612dba2cc03SDeepak Ukey 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
613dba2cc03SDeepak Ukey 	int val = 0;
614dba2cc03SDeepak Ukey 
615dba2cc03SDeepak Ukey 	if (kstrtoint(buf, 16, &val) != 0)
616dba2cc03SDeepak Ukey 		return -EINVAL;
617dba2cc03SDeepak Ukey 
618dba2cc03SDeepak Ukey 	pm8001_ha->non_fatal_count = val;
619dba2cc03SDeepak Ukey 	return strlen(buf);
620dba2cc03SDeepak Ukey }
621dba2cc03SDeepak Ukey static DEVICE_ATTR_RW(non_fatal_count);
622d078b511SAnand Kumar Santhanam 
623d078b511SAnand Kumar Santhanam /**
624bb6beabfSRandy Dunlap  * pm8001_ctl_gsm_log_show - gsm dump collection
625bb6beabfSRandy Dunlap  * @cdev:pointer to embedded class device
626bb6beabfSRandy Dunlap  * @attr: device attribute (unused)
627bb6beabfSRandy Dunlap  * @buf: the buffer returned
628bb6beabfSRandy Dunlap  *
629bb6beabfSRandy Dunlap  * A sysfs 'read-only' shost attribute.
630bb6beabfSRandy Dunlap  */
pm8001_ctl_gsm_log_show(struct device * cdev,struct device_attribute * attr,char * buf)631d078b511SAnand Kumar Santhanam static ssize_t pm8001_ctl_gsm_log_show(struct device *cdev,
632d078b511SAnand Kumar Santhanam 	struct device_attribute *attr, char *buf)
633d078b511SAnand Kumar Santhanam {
634cf370066SViswas G 	ssize_t count;
635d078b511SAnand Kumar Santhanam 
636d078b511SAnand Kumar Santhanam 	count = pm8001_get_gsm_dump(cdev, SYSFS_OFFSET, buf);
637d078b511SAnand Kumar Santhanam 	return count;
638d078b511SAnand Kumar Santhanam }
639d078b511SAnand Kumar Santhanam 
640d078b511SAnand Kumar Santhanam static DEVICE_ATTR(gsm_log, S_IRUGO, pm8001_ctl_gsm_log_show, NULL);
641d078b511SAnand Kumar Santhanam 
642dbf9bfe6Sjack wang #define FLASH_CMD_NONE      0x00
643dbf9bfe6Sjack wang #define FLASH_CMD_UPDATE    0x01
644dbf9bfe6Sjack wang #define FLASH_CMD_SET_NVMD    0x02
645dbf9bfe6Sjack wang 
646dbf9bfe6Sjack wang struct flash_command {
647dbf9bfe6Sjack wang      u8      command[8];
648dbf9bfe6Sjack wang      int     code;
649dbf9bfe6Sjack wang };
650dbf9bfe6Sjack wang 
651fa5ac2beSLuo Jiaxing static const struct flash_command flash_command_table[] = {
652dbf9bfe6Sjack wang      {"set_nvmd",    FLASH_CMD_SET_NVMD},
653dbf9bfe6Sjack wang      {"update",      FLASH_CMD_UPDATE},
654dbf9bfe6Sjack wang      {"",            FLASH_CMD_NONE} /* Last entry should be NULL. */
655dbf9bfe6Sjack wang };
656dbf9bfe6Sjack wang 
657dbf9bfe6Sjack wang struct error_fw {
658dbf9bfe6Sjack wang      char    *reason;
659dbf9bfe6Sjack wang      int     err_code;
660dbf9bfe6Sjack wang };
661dbf9bfe6Sjack wang 
662fa5ac2beSLuo Jiaxing static const struct error_fw flash_error_table[] = {
663dbf9bfe6Sjack wang      {"Failed to open fw image file",	FAIL_OPEN_BIOS_FILE},
664dbf9bfe6Sjack wang      {"image header mismatch",		FLASH_UPDATE_HDR_ERR},
665dbf9bfe6Sjack wang      {"image offset mismatch",		FLASH_UPDATE_OFFSET_ERR},
666dbf9bfe6Sjack wang      {"image CRC Error",		FLASH_UPDATE_CRC_ERR},
667dbf9bfe6Sjack wang      {"image length Error.",		FLASH_UPDATE_LENGTH_ERR},
668dbf9bfe6Sjack wang      {"Failed to program flash chip",	FLASH_UPDATE_HW_ERR},
669dbf9bfe6Sjack wang      {"Flash chip not supported.",	FLASH_UPDATE_DNLD_NOT_SUPPORTED},
670dbf9bfe6Sjack wang      {"Flash update disabled.",		FLASH_UPDATE_DISABLED},
671dbf9bfe6Sjack wang      {"Flash in progress",		FLASH_IN_PROGRESS},
672dbf9bfe6Sjack wang      {"Image file size Error",		FAIL_FILE_SIZE},
673dbf9bfe6Sjack wang      {"Input parameter error",		FAIL_PARAMETERS},
674dbf9bfe6Sjack wang      {"Out of memory",			FAIL_OUT_MEMORY},
675dbf9bfe6Sjack wang      {"OK", 0}	/* Last entry err_code = 0. */
676dbf9bfe6Sjack wang };
677dbf9bfe6Sjack wang 
pm8001_set_nvmd(struct pm8001_hba_info * pm8001_ha)678dbf9bfe6Sjack wang static int pm8001_set_nvmd(struct pm8001_hba_info *pm8001_ha)
679dbf9bfe6Sjack wang {
680dbf9bfe6Sjack wang 	struct pm8001_ioctl_payload	*payload;
681dbf9bfe6Sjack wang 	DECLARE_COMPLETION_ONSTACK(completion);
6826f8f31c7STomas Henzl 	u8		*ioctlbuffer;
6836f8f31c7STomas Henzl 	u32		ret;
6846f8f31c7STomas Henzl 	u32		length = 1024 * 5 + sizeof(*payload) - 1;
685dbf9bfe6Sjack wang 
6866f8f31c7STomas Henzl 	if (pm8001_ha->fw_image->size > 4096) {
6876f8f31c7STomas Henzl 		pm8001_ha->fw_status = FAIL_FILE_SIZE;
6886f8f31c7STomas Henzl 		return -EFAULT;
6896f8f31c7STomas Henzl 	}
6906f8f31c7STomas Henzl 
691dbf9bfe6Sjack wang 	ioctlbuffer = kzalloc(length, GFP_KERNEL);
6926f8f31c7STomas Henzl 	if (!ioctlbuffer) {
6936f8f31c7STomas Henzl 		pm8001_ha->fw_status = FAIL_OUT_MEMORY;
694dbf9bfe6Sjack wang 		return -ENOMEM;
695dbf9bfe6Sjack wang 	}
696dbf9bfe6Sjack wang 	payload = (struct pm8001_ioctl_payload *)ioctlbuffer;
6971c75a679SSakthivel K 	memcpy((u8 *)&payload->func_specific, (u8 *)pm8001_ha->fw_image->data,
698dbf9bfe6Sjack wang 				pm8001_ha->fw_image->size);
6999b889846SViswas G 	payload->wr_length = pm8001_ha->fw_image->size;
700dbf9bfe6Sjack wang 	payload->id = 0;
7011c75a679SSakthivel K 	payload->minor_function = 0x1;
702dbf9bfe6Sjack wang 	pm8001_ha->nvmd_completion = &completion;
703dbf9bfe6Sjack wang 	ret = PM8001_CHIP_DISP->set_nvmd_req(pm8001_ha, payload);
7046f8f31c7STomas Henzl 	if (ret) {
7056f8f31c7STomas Henzl 		pm8001_ha->fw_status = FAIL_OUT_MEMORY;
7066f8f31c7STomas Henzl 		goto out;
7076f8f31c7STomas Henzl 	}
708dbf9bfe6Sjack wang 	wait_for_completion(&completion);
709dbf9bfe6Sjack wang out:
710dbf9bfe6Sjack wang 	kfree(ioctlbuffer);
711dbf9bfe6Sjack wang 	return ret;
712dbf9bfe6Sjack wang }
713dbf9bfe6Sjack wang 
pm8001_update_flash(struct pm8001_hba_info * pm8001_ha)714dbf9bfe6Sjack wang static int pm8001_update_flash(struct pm8001_hba_info *pm8001_ha)
715dbf9bfe6Sjack wang {
716dbf9bfe6Sjack wang 	struct pm8001_ioctl_payload	*payload;
717dbf9bfe6Sjack wang 	DECLARE_COMPLETION_ONSTACK(completion);
7186f8f31c7STomas Henzl 	u8		*ioctlbuffer;
719dbf9bfe6Sjack wang 	struct fw_control_info	*fwControl;
720c58e935eSDamien Le Moal 	__be32		partitionSizeTmp;
721c58e935eSDamien Le Moal 	u32		partitionSize;
7226f8f31c7STomas Henzl 	u32		loopNumber, loopcount;
723dbf9bfe6Sjack wang 	struct pm8001_fw_image_header *image_hdr;
7246f8f31c7STomas Henzl 	u32		sizeRead = 0;
7256f8f31c7STomas Henzl 	u32		ret = 0;
7266f8f31c7STomas Henzl 	u32		length = 1024 * 16 + sizeof(*payload) - 1;
727106b7a25SYang Li 	u32		fc_len;
728106b7a25SYang Li 	u8		*read_buf;
729dbf9bfe6Sjack wang 
730dbf9bfe6Sjack wang 	if (pm8001_ha->fw_image->size < 28) {
7316f8f31c7STomas Henzl 		pm8001_ha->fw_status = FAIL_FILE_SIZE;
7326f8f31c7STomas Henzl 		return -EFAULT;
733dbf9bfe6Sjack wang 	}
7346f8f31c7STomas Henzl 	ioctlbuffer = kzalloc(length, GFP_KERNEL);
7356f8f31c7STomas Henzl 	if (!ioctlbuffer) {
7366f8f31c7STomas Henzl 		pm8001_ha->fw_status = FAIL_OUT_MEMORY;
7376f8f31c7STomas Henzl 		return -ENOMEM;
7386f8f31c7STomas Henzl 	}
7396f8f31c7STomas Henzl 	image_hdr = (struct pm8001_fw_image_header *)pm8001_ha->fw_image->data;
740dbf9bfe6Sjack wang 	while (sizeRead < pm8001_ha->fw_image->size) {
741dbf9bfe6Sjack wang 		partitionSizeTmp =
742c58e935eSDamien Le Moal 			*(__be32 *)((u8 *)&image_hdr->image_length + sizeRead);
743dbf9bfe6Sjack wang 		partitionSize = be32_to_cpu(partitionSizeTmp);
7445bd355eeSTomas Henzl 		loopcount = DIV_ROUND_UP(partitionSize + HEADER_LEN,
7455bd355eeSTomas Henzl 					IOCTL_BUF_SIZE);
746dbf9bfe6Sjack wang 		for (loopNumber = 0; loopNumber < loopcount; loopNumber++) {
747dbf9bfe6Sjack wang 			payload = (struct pm8001_ioctl_payload *)ioctlbuffer;
7489b889846SViswas G 			payload->wr_length = 1024*16;
749dbf9bfe6Sjack wang 			payload->id = 0;
750dbf9bfe6Sjack wang 			fwControl =
7511c75a679SSakthivel K 			      (struct fw_control_info *)&payload->func_specific;
752dbf9bfe6Sjack wang 			fwControl->len = IOCTL_BUF_SIZE;   /* IN */
753dbf9bfe6Sjack wang 			fwControl->size = partitionSize + HEADER_LEN;/* IN */
754dbf9bfe6Sjack wang 			fwControl->retcode = 0;/* OUT */
755dbf9bfe6Sjack wang 			fwControl->offset = loopNumber * IOCTL_BUF_SIZE;/*OUT */
756dbf9bfe6Sjack wang 
757106b7a25SYang Li 			/*
758106b7a25SYang Li 			 * for the last chunk of data in case file size is
759106b7a25SYang Li 			 * not even with 4k, load only the rest
760106b7a25SYang Li 			 */
761106b7a25SYang Li 
762106b7a25SYang Li 			read_buf  = (u8 *)pm8001_ha->fw_image->data + sizeRead;
763106b7a25SYang Li 			fc_len = (partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE;
764106b7a25SYang Li 
765106b7a25SYang Li 			if (loopcount - loopNumber == 1 && fc_len) {
766106b7a25SYang Li 				fwControl->len = fc_len;
767106b7a25SYang Li 				memcpy((u8 *)fwControl->buffer, read_buf, fc_len);
768106b7a25SYang Li 				sizeRead += fc_len;
769dbf9bfe6Sjack wang 			} else {
770106b7a25SYang Li 				memcpy((u8 *)fwControl->buffer, read_buf, IOCTL_BUF_SIZE);
771dbf9bfe6Sjack wang 				sizeRead += IOCTL_BUF_SIZE;
772dbf9bfe6Sjack wang 			}
773dbf9bfe6Sjack wang 
774dbf9bfe6Sjack wang 			pm8001_ha->nvmd_completion = &completion;
775dbf9bfe6Sjack wang 			ret = PM8001_CHIP_DISP->fw_flash_update_req(pm8001_ha, payload);
7766f8f31c7STomas Henzl 			if (ret) {
7776f8f31c7STomas Henzl 				pm8001_ha->fw_status = FAIL_OUT_MEMORY;
7786f8f31c7STomas Henzl 				goto out;
7796f8f31c7STomas Henzl 			}
780dbf9bfe6Sjack wang 			wait_for_completion(&completion);
78131d05e5bSTomas Henzl 			if (fwControl->retcode > FLASH_UPDATE_IN_PROGRESS) {
7826f8f31c7STomas Henzl 				pm8001_ha->fw_status = fwControl->retcode;
7836f8f31c7STomas Henzl 				ret = -EFAULT;
7846f8f31c7STomas Henzl 				goto out;
785dbf9bfe6Sjack wang 			}
786dbf9bfe6Sjack wang 		}
787dbf9bfe6Sjack wang 	}
788dbf9bfe6Sjack wang out:
789dbf9bfe6Sjack wang 	kfree(ioctlbuffer);
790dbf9bfe6Sjack wang 	return ret;
791dbf9bfe6Sjack wang }
pm8001_store_update_fw(struct device * cdev,struct device_attribute * attr,const char * buf,size_t count)792dbf9bfe6Sjack wang static ssize_t pm8001_store_update_fw(struct device *cdev,
793dbf9bfe6Sjack wang 				      struct device_attribute *attr,
794dbf9bfe6Sjack wang 				      const char *buf, size_t count)
795dbf9bfe6Sjack wang {
796dbf9bfe6Sjack wang 	struct Scsi_Host *shost = class_to_shost(cdev);
797dbf9bfe6Sjack wang 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
798dbf9bfe6Sjack wang 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
799dbf9bfe6Sjack wang 	char *cmd_ptr, *filename_ptr;
800dbf9bfe6Sjack wang 	int res, i;
801dbf9bfe6Sjack wang 	int flash_command = FLASH_CMD_NONE;
8026f8f31c7STomas Henzl 	int ret;
8036f8f31c7STomas Henzl 
804dbf9bfe6Sjack wang 	if (!capable(CAP_SYS_ADMIN))
805dbf9bfe6Sjack wang 		return -EACCES;
806dbf9bfe6Sjack wang 
8076f8f31c7STomas Henzl 	/* this test protects us from running two flash processes at once,
8086f8f31c7STomas Henzl 	 * so we should start with this test */
8096f8f31c7STomas Henzl 	if (pm8001_ha->fw_status == FLASH_IN_PROGRESS)
8106f8f31c7STomas Henzl 		return -EINPROGRESS;
8116f8f31c7STomas Henzl 	pm8001_ha->fw_status = FLASH_IN_PROGRESS;
812dbf9bfe6Sjack wang 
8136396bb22SKees Cook 	cmd_ptr = kcalloc(count, 2, GFP_KERNEL);
814dbf9bfe6Sjack wang 	if (!cmd_ptr) {
8156f8f31c7STomas Henzl 		pm8001_ha->fw_status = FAIL_OUT_MEMORY;
8166f8f31c7STomas Henzl 		return -ENOMEM;
817dbf9bfe6Sjack wang 	}
818dbf9bfe6Sjack wang 
819dbf9bfe6Sjack wang 	filename_ptr = cmd_ptr + count;
820dbf9bfe6Sjack wang 	res = sscanf(buf, "%s %s", cmd_ptr, filename_ptr);
821dbf9bfe6Sjack wang 	if (res != 2) {
8226f8f31c7STomas Henzl 		pm8001_ha->fw_status = FAIL_PARAMETERS;
8236f8f31c7STomas Henzl 		ret = -EINVAL;
8246f8f31c7STomas Henzl 		goto out;
825dbf9bfe6Sjack wang 	}
826dbf9bfe6Sjack wang 
827dbf9bfe6Sjack wang 	for (i = 0; flash_command_table[i].code != FLASH_CMD_NONE; i++) {
828dbf9bfe6Sjack wang 		if (!memcmp(flash_command_table[i].command,
829dbf9bfe6Sjack wang 				 cmd_ptr, strlen(cmd_ptr))) {
830dbf9bfe6Sjack wang 			flash_command = flash_command_table[i].code;
831dbf9bfe6Sjack wang 			break;
832dbf9bfe6Sjack wang 		}
833dbf9bfe6Sjack wang 	}
834dbf9bfe6Sjack wang 	if (flash_command == FLASH_CMD_NONE) {
8356f8f31c7STomas Henzl 		pm8001_ha->fw_status = FAIL_PARAMETERS;
8366f8f31c7STomas Henzl 		ret = -EINVAL;
8376f8f31c7STomas Henzl 		goto out;
838dbf9bfe6Sjack wang 	}
839dbf9bfe6Sjack wang 
8406f8f31c7STomas Henzl 	ret = request_firmware(&pm8001_ha->fw_image,
841dbf9bfe6Sjack wang 			       filename_ptr,
842dbf9bfe6Sjack wang 			       pm8001_ha->dev);
843dbf9bfe6Sjack wang 
8446f8f31c7STomas Henzl 	if (ret) {
8451b5d2793SJoe Perches 		pm8001_dbg(pm8001_ha, FAIL,
8466f8f31c7STomas Henzl 			   "Failed to load firmware image file %s, error %d\n",
8471b5d2793SJoe Perches 			   filename_ptr, ret);
8486f8f31c7STomas Henzl 		pm8001_ha->fw_status = FAIL_OPEN_BIOS_FILE;
8496f8f31c7STomas Henzl 		goto out;
850dbf9bfe6Sjack wang 	}
851dbf9bfe6Sjack wang 
8526f8f31c7STomas Henzl 	if (FLASH_CMD_UPDATE == flash_command)
8536f8f31c7STomas Henzl 		ret = pm8001_update_flash(pm8001_ha);
854dbf9bfe6Sjack wang 	else
8556f8f31c7STomas Henzl 		ret = pm8001_set_nvmd(pm8001_ha);
8566f8f31c7STomas Henzl 
8576f8f31c7STomas Henzl 	release_firmware(pm8001_ha->fw_image);
8586f8f31c7STomas Henzl out:
8596f8f31c7STomas Henzl 	kfree(cmd_ptr);
8606f8f31c7STomas Henzl 
8616f8f31c7STomas Henzl 	if (ret)
8626f8f31c7STomas Henzl 		return ret;
8636f8f31c7STomas Henzl 
8646f8f31c7STomas Henzl 	pm8001_ha->fw_status = FLASH_OK;
8656f8f31c7STomas Henzl 	return count;
866dbf9bfe6Sjack wang }
867dbf9bfe6Sjack wang 
pm8001_show_update_fw(struct device * cdev,struct device_attribute * attr,char * buf)868dbf9bfe6Sjack wang static ssize_t pm8001_show_update_fw(struct device *cdev,
869dbf9bfe6Sjack wang 				     struct device_attribute *attr, char *buf)
870dbf9bfe6Sjack wang {
871dbf9bfe6Sjack wang 	int i;
872dbf9bfe6Sjack wang 	struct Scsi_Host *shost = class_to_shost(cdev);
873dbf9bfe6Sjack wang 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
874dbf9bfe6Sjack wang 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
875dbf9bfe6Sjack wang 
876dbf9bfe6Sjack wang 	for (i = 0; flash_error_table[i].err_code != 0; i++) {
877dbf9bfe6Sjack wang 		if (flash_error_table[i].err_code == pm8001_ha->fw_status)
878dbf9bfe6Sjack wang 			break;
879dbf9bfe6Sjack wang 	}
880dbf9bfe6Sjack wang 	if (pm8001_ha->fw_status != FLASH_IN_PROGRESS)
881dbf9bfe6Sjack wang 		pm8001_ha->fw_status = FLASH_OK;
882dbf9bfe6Sjack wang 
883dbf9bfe6Sjack wang 	return snprintf(buf, PAGE_SIZE, "status=%x %s\n",
884dbf9bfe6Sjack wang 			flash_error_table[i].err_code,
885dbf9bfe6Sjack wang 			flash_error_table[i].reason);
886dbf9bfe6Sjack wang }
887332e2b4fSRusty Russell static DEVICE_ATTR(update_fw, S_IRUGO|S_IWUSR|S_IWGRP,
888dbf9bfe6Sjack wang 	pm8001_show_update_fw, pm8001_store_update_fw);
8894ddbea1bSVishakha Channapattan 
8904ddbea1bSVishakha Channapattan static const char *const mpiStateText[] = {
8914ddbea1bSVishakha Channapattan 	"MPI is not initialized",
8924ddbea1bSVishakha Channapattan 	"MPI is successfully initialized",
8934ddbea1bSVishakha Channapattan 	"MPI termination is in progress",
8944ddbea1bSVishakha Channapattan 	"MPI initialization failed with error in [31:16]"
8954ddbea1bSVishakha Channapattan };
8964ddbea1bSVishakha Channapattan 
897d6e71a43SBart Van Assche /**
898d6e71a43SBart Van Assche  * ctl_mpi_state_show - controller MPI state check
899d6e71a43SBart Van Assche  * @cdev: pointer to embedded class device
900d6e71a43SBart Van Assche  * @attr: device attribute (unused)
901d6e71a43SBart Van Assche  * @buf: the buffer returned
902d6e71a43SBart Van Assche  *
903d6e71a43SBart Van Assche  * A sysfs 'read-only' shost attribute.
904d6e71a43SBart Van Assche  */
ctl_mpi_state_show(struct device * cdev,struct device_attribute * attr,char * buf)9054ddbea1bSVishakha Channapattan static ssize_t ctl_mpi_state_show(struct device *cdev,
9064ddbea1bSVishakha Channapattan 		struct device_attribute *attr, char *buf)
9074ddbea1bSVishakha Channapattan {
9084ddbea1bSVishakha Channapattan 	struct Scsi_Host *shost = class_to_shost(cdev);
9094ddbea1bSVishakha Channapattan 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
9104ddbea1bSVishakha Channapattan 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
9114ddbea1bSVishakha Channapattan 	unsigned int mpidw0;
9124ddbea1bSVishakha Channapattan 
9134ddbea1bSVishakha Channapattan 	mpidw0 = pm8001_mr32(pm8001_ha->general_stat_tbl_addr, 0);
9144ddbea1bSVishakha Channapattan 	return sysfs_emit(buf, "%s\n", mpiStateText[mpidw0 & 0x0003]);
9154ddbea1bSVishakha Channapattan }
9164ddbea1bSVishakha Channapattan static DEVICE_ATTR_RO(ctl_mpi_state);
9174ddbea1bSVishakha Channapattan 
918a4c55e16SVishakha Channapattan /**
919a4c55e16SVishakha Channapattan  * ctl_hmi_error_show - controller MPI initialization fails
920a4c55e16SVishakha Channapattan  * @cdev: pointer to embedded class device
921d6e71a43SBart Van Assche  * @attr: device attribute (unused)
922a4c55e16SVishakha Channapattan  * @buf: the buffer returned
923a4c55e16SVishakha Channapattan  *
924a4c55e16SVishakha Channapattan  * A sysfs 'read-only' shost attribute.
925a4c55e16SVishakha Channapattan  */
ctl_hmi_error_show(struct device * cdev,struct device_attribute * attr,char * buf)926a4c55e16SVishakha Channapattan static ssize_t ctl_hmi_error_show(struct device *cdev,
927a4c55e16SVishakha Channapattan 		struct device_attribute *attr, char *buf)
928a4c55e16SVishakha Channapattan {
929a4c55e16SVishakha Channapattan 	struct Scsi_Host *shost = class_to_shost(cdev);
930a4c55e16SVishakha Channapattan 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
931a4c55e16SVishakha Channapattan 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
932a4c55e16SVishakha Channapattan 	unsigned int mpidw0;
933a4c55e16SVishakha Channapattan 
934a4c55e16SVishakha Channapattan 	mpidw0 = pm8001_mr32(pm8001_ha->general_stat_tbl_addr, 0);
935a4c55e16SVishakha Channapattan 	return sysfs_emit(buf, "0x%08x\n", (mpidw0 >> 16));
936a4c55e16SVishakha Channapattan }
937a4c55e16SVishakha Channapattan static DEVICE_ATTR_RO(ctl_hmi_error);
938a4c55e16SVishakha Channapattan 
939dd49ded8SVishakha Channapattan /**
940dd49ded8SVishakha Channapattan  * ctl_raae_count_show - controller raae count check
941dd49ded8SVishakha Channapattan  * @cdev: pointer to embedded class device
942d6e71a43SBart Van Assche  * @attr: device attribute (unused)
943dd49ded8SVishakha Channapattan  * @buf: the buffer returned
944dd49ded8SVishakha Channapattan  *
945dd49ded8SVishakha Channapattan  * A sysfs 'read-only' shost attribute.
946dd49ded8SVishakha Channapattan  */
ctl_raae_count_show(struct device * cdev,struct device_attribute * attr,char * buf)947dd49ded8SVishakha Channapattan static ssize_t ctl_raae_count_show(struct device *cdev,
948dd49ded8SVishakha Channapattan 		struct device_attribute *attr, char *buf)
949dd49ded8SVishakha Channapattan {
950dd49ded8SVishakha Channapattan 	struct Scsi_Host *shost = class_to_shost(cdev);
951dd49ded8SVishakha Channapattan 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
952dd49ded8SVishakha Channapattan 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
953dd49ded8SVishakha Channapattan 	unsigned int raaecnt;
954dd49ded8SVishakha Channapattan 
955dd49ded8SVishakha Channapattan 	raaecnt = pm8001_mr32(pm8001_ha->general_stat_tbl_addr, 12);
956dd49ded8SVishakha Channapattan 	return sysfs_emit(buf, "0x%08x\n", raaecnt);
957dd49ded8SVishakha Channapattan }
958dd49ded8SVishakha Channapattan static DEVICE_ATTR_RO(ctl_raae_count);
959dd49ded8SVishakha Channapattan 
9600602624aSVishakha Channapattan /**
9610602624aSVishakha Channapattan  * ctl_iop0_count_show - controller iop0 count check
9620602624aSVishakha Channapattan  * @cdev: pointer to embedded class device
963d6e71a43SBart Van Assche  * @attr: device attribute (unused)
9640602624aSVishakha Channapattan  * @buf: the buffer returned
9650602624aSVishakha Channapattan  *
9660602624aSVishakha Channapattan  * A sysfs 'read-only' shost attribute.
9670602624aSVishakha Channapattan  */
ctl_iop0_count_show(struct device * cdev,struct device_attribute * attr,char * buf)9680602624aSVishakha Channapattan static ssize_t ctl_iop0_count_show(struct device *cdev,
9690602624aSVishakha Channapattan 		struct device_attribute *attr, char *buf)
9700602624aSVishakha Channapattan {
9710602624aSVishakha Channapattan 	struct Scsi_Host *shost = class_to_shost(cdev);
9720602624aSVishakha Channapattan 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
9730602624aSVishakha Channapattan 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
9740602624aSVishakha Channapattan 	unsigned int iop0cnt;
9750602624aSVishakha Channapattan 
9760602624aSVishakha Channapattan 	iop0cnt = pm8001_mr32(pm8001_ha->general_stat_tbl_addr, 16);
9770602624aSVishakha Channapattan 	return sysfs_emit(buf, "0x%08x\n", iop0cnt);
9780602624aSVishakha Channapattan }
9790602624aSVishakha Channapattan static DEVICE_ATTR_RO(ctl_iop0_count);
9800602624aSVishakha Channapattan 
981b0c306e6SVishakha Channapattan /**
982b0c306e6SVishakha Channapattan  * ctl_iop1_count_show - controller iop1 count check
983b0c306e6SVishakha Channapattan  * @cdev: pointer to embedded class device
984d6e71a43SBart Van Assche  * @attr: device attribute (unused)
985b0c306e6SVishakha Channapattan  * @buf: the buffer returned
986b0c306e6SVishakha Channapattan  *
987b0c306e6SVishakha Channapattan  * A sysfs 'read-only' shost attribute.
988b0c306e6SVishakha Channapattan  */
ctl_iop1_count_show(struct device * cdev,struct device_attribute * attr,char * buf)989b0c306e6SVishakha Channapattan static ssize_t ctl_iop1_count_show(struct device *cdev,
990b0c306e6SVishakha Channapattan 		struct device_attribute *attr, char *buf)
991b0c306e6SVishakha Channapattan {
992b0c306e6SVishakha Channapattan 	struct Scsi_Host *shost = class_to_shost(cdev);
993b0c306e6SVishakha Channapattan 	struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
994b0c306e6SVishakha Channapattan 	struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
995b0c306e6SVishakha Channapattan 	unsigned int iop1cnt;
996b0c306e6SVishakha Channapattan 
997b0c306e6SVishakha Channapattan 	iop1cnt = pm8001_mr32(pm8001_ha->general_stat_tbl_addr, 20);
998b0c306e6SVishakha Channapattan 	return sysfs_emit(buf, "0x%08x\n", iop1cnt);
999b0c306e6SVishakha Channapattan 
1000b0c306e6SVishakha Channapattan }
1001b0c306e6SVishakha Channapattan static DEVICE_ATTR_RO(ctl_iop1_count);
1002b0c306e6SVishakha Channapattan 
1003c03b72b8SBart Van Assche static struct attribute *pm8001_host_attrs[] = {
1004c03b72b8SBart Van Assche 	&dev_attr_interface_rev.attr,
1005c03b72b8SBart Van Assche 	&dev_attr_controller_fatal_error.attr,
1006c03b72b8SBart Van Assche 	&dev_attr_fw_version.attr,
1007c03b72b8SBart Van Assche 	&dev_attr_update_fw.attr,
1008c03b72b8SBart Van Assche 	&dev_attr_aap_log.attr,
1009c03b72b8SBart Van Assche 	&dev_attr_iop_log.attr,
1010c03b72b8SBart Van Assche 	&dev_attr_fatal_log.attr,
1011c03b72b8SBart Van Assche 	&dev_attr_non_fatal_log.attr,
1012c03b72b8SBart Van Assche 	&dev_attr_non_fatal_count.attr,
1013c03b72b8SBart Van Assche 	&dev_attr_gsm_log.attr,
1014c03b72b8SBart Van Assche 	&dev_attr_max_out_io.attr,
1015c03b72b8SBart Van Assche 	&dev_attr_max_devices.attr,
1016c03b72b8SBart Van Assche 	&dev_attr_max_sg_list.attr,
1017c03b72b8SBart Van Assche 	&dev_attr_sas_spec_support.attr,
1018c03b72b8SBart Van Assche 	&dev_attr_logging_level.attr,
1019c03b72b8SBart Van Assche 	&dev_attr_event_log_size.attr,
1020c03b72b8SBart Van Assche 	&dev_attr_host_sas_address.attr,
1021c03b72b8SBart Van Assche 	&dev_attr_bios_version.attr,
1022c03b72b8SBart Van Assche 	&dev_attr_ib_log.attr,
1023c03b72b8SBart Van Assche 	&dev_attr_ob_log.attr,
1024c03b72b8SBart Van Assche 	&dev_attr_ila_version.attr,
1025c03b72b8SBart Van Assche 	&dev_attr_inc_fw_ver.attr,
1026c03b72b8SBart Van Assche 	&dev_attr_ctl_mpi_state.attr,
1027c03b72b8SBart Van Assche 	&dev_attr_ctl_hmi_error.attr,
1028c03b72b8SBart Van Assche 	&dev_attr_ctl_raae_count.attr,
1029c03b72b8SBart Van Assche 	&dev_attr_ctl_iop0_count.attr,
1030c03b72b8SBart Van Assche 	&dev_attr_ctl_iop1_count.attr,
1031dbf9bfe6Sjack wang 	NULL,
1032dbf9bfe6Sjack wang };
1033dbf9bfe6Sjack wang 
1034c03b72b8SBart Van Assche static const struct attribute_group pm8001_host_attr_group = {
1035c03b72b8SBart Van Assche 	.attrs = pm8001_host_attrs
1036c03b72b8SBart Van Assche };
1037c03b72b8SBart Van Assche 
1038c03b72b8SBart Van Assche const struct attribute_group *pm8001_host_groups[] = {
1039c03b72b8SBart Van Assche 	&pm8001_host_attr_group,
1040c03b72b8SBart Van Assche 	NULL
1041c03b72b8SBart Van Assche };
1042