2 * PMC-Sierra 8001/8081/8088/8089 SAS/SATA based host adapters driver
4 * Copyright (c) 2008-2009 USI Co., Ltd.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions, and the following disclaimer,
12 * without modification.
13 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
14 * substantially similar to the "NO WARRANTY" disclaimer below
15 * ("Disclaimer") and any redistribution must be conditioned upon
16 * including a substantially similar Disclaimer requirement for further
17 * binary redistribution.
18 * 3. Neither the names of the above-listed copyright holders nor the names
19 * of any contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * Alternatively, this software may be distributed under the terms of the
23 * GNU General Public License ("GPL") version 2 as published by the Free
24 * Software Foundation.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
30 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
35 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
36 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGES.
40 #include <linux/firmware.h>
41 #include <linux/slab.h>
42 #include "pm8001_sas.h"
43 #include "pm8001_ctl.h"
45 /* scsi host attributes */
48 * pm8001_ctl_mpi_interface_rev_show - MPI interface revision number
49 * @cdev: pointer to embedded class device
50 * @buf: the buffer returned
52 * A sysfs 'read-only' shost attribute.
54 static ssize_t
pm8001_ctl_mpi_interface_rev_show(struct device
*cdev
,
55 struct device_attribute
*attr
, char *buf
)
57 struct Scsi_Host
*shost
= class_to_shost(cdev
);
58 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
59 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
61 if (pm8001_ha
->chip_id
== chip_8001
) {
62 return snprintf(buf
, PAGE_SIZE
, "%d\n",
63 pm8001_ha
->main_cfg_tbl
.pm8001_tbl
.interface_rev
);
65 return snprintf(buf
, PAGE_SIZE
, "%d\n",
66 pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.interface_rev
);
70 DEVICE_ATTR(interface_rev
, S_IRUGO
, pm8001_ctl_mpi_interface_rev_show
, NULL
);
73 * controller_fatal_error_show - check controller is under fatal err
74 * @cdev: pointer to embedded class device
75 * @buf: the buffer returned
77 * A sysfs 'read only' shost attribute.
79 static ssize_t
controller_fatal_error_show(struct device
*cdev
,
80 struct device_attribute
*attr
, char *buf
)
82 struct Scsi_Host
*shost
= class_to_shost(cdev
);
83 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
84 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
86 return snprintf(buf
, PAGE_SIZE
, "%d\n",
87 pm8001_ha
->controller_fatal_error
);
89 static DEVICE_ATTR_RO(controller_fatal_error
);
92 * pm8001_ctl_fw_version_show - firmware version
93 * @cdev: pointer to embedded class device
94 * @buf: the buffer returned
96 * A sysfs 'read-only' shost attribute.
98 static ssize_t
pm8001_ctl_fw_version_show(struct device
*cdev
,
99 struct device_attribute
*attr
, char *buf
)
101 struct Scsi_Host
*shost
= class_to_shost(cdev
);
102 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
103 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
105 if (pm8001_ha
->chip_id
== chip_8001
) {
106 return snprintf(buf
, PAGE_SIZE
, "%02x.%02x.%02x.%02x\n",
107 (u8
)(pm8001_ha
->main_cfg_tbl
.pm8001_tbl
.firmware_rev
>> 24),
108 (u8
)(pm8001_ha
->main_cfg_tbl
.pm8001_tbl
.firmware_rev
>> 16),
109 (u8
)(pm8001_ha
->main_cfg_tbl
.pm8001_tbl
.firmware_rev
>> 8),
110 (u8
)(pm8001_ha
->main_cfg_tbl
.pm8001_tbl
.firmware_rev
));
112 return snprintf(buf
, PAGE_SIZE
, "%02x.%02x.%02x.%02x\n",
113 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.firmware_rev
>> 24),
114 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.firmware_rev
>> 16),
115 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.firmware_rev
>> 8),
116 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.firmware_rev
));
119 static DEVICE_ATTR(fw_version
, S_IRUGO
, pm8001_ctl_fw_version_show
, NULL
);
122 * pm8001_ctl_ila_version_show - ila version
123 * @cdev: pointer to embedded class device
124 * @buf: the buffer returned
126 * A sysfs 'read-only' shost attribute.
128 static ssize_t
pm8001_ctl_ila_version_show(struct device
*cdev
,
129 struct device_attribute
*attr
, char *buf
)
131 struct Scsi_Host
*shost
= class_to_shost(cdev
);
132 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
133 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
135 if (pm8001_ha
->chip_id
!= chip_8001
) {
136 return snprintf(buf
, PAGE_SIZE
, "%02x.%02x.%02x.%02x\n",
137 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.ila_version
>> 24),
138 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.ila_version
>> 16),
139 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.ila_version
>> 8),
140 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.ila_version
));
144 static DEVICE_ATTR(ila_version
, 0444, pm8001_ctl_ila_version_show
, NULL
);
147 * pm8001_ctl_inactive_fw_version_show - Inacative firmware version number
148 * @cdev: pointer to embedded class device
149 * @buf: the buffer returned
151 * A sysfs 'read-only' shost attribute.
153 static ssize_t
pm8001_ctl_inactive_fw_version_show(struct device
*cdev
,
154 struct device_attribute
*attr
, char *buf
)
156 struct Scsi_Host
*shost
= class_to_shost(cdev
);
157 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
158 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
160 if (pm8001_ha
->chip_id
!= chip_8001
) {
161 return snprintf(buf
, PAGE_SIZE
, "%02x.%02x.%02x.%02x\n",
162 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.inc_fw_version
>> 24),
163 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.inc_fw_version
>> 16),
164 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.inc_fw_version
>> 8),
165 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.inc_fw_version
));
170 DEVICE_ATTR(inc_fw_ver
, 0444, pm8001_ctl_inactive_fw_version_show
, NULL
);
173 * pm8001_ctl_max_out_io_show - max outstanding io supported
174 * @cdev: pointer to embedded class device
175 * @buf: the buffer returned
177 * A sysfs 'read-only' shost attribute.
179 static ssize_t
pm8001_ctl_max_out_io_show(struct device
*cdev
,
180 struct device_attribute
*attr
, char *buf
)
182 struct Scsi_Host
*shost
= class_to_shost(cdev
);
183 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
184 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
186 if (pm8001_ha
->chip_id
== chip_8001
) {
187 return snprintf(buf
, PAGE_SIZE
, "%d\n",
188 pm8001_ha
->main_cfg_tbl
.pm8001_tbl
.max_out_io
);
190 return snprintf(buf
, PAGE_SIZE
, "%d\n",
191 pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.max_out_io
);
194 static DEVICE_ATTR(max_out_io
, S_IRUGO
, pm8001_ctl_max_out_io_show
, NULL
);
196 * pm8001_ctl_max_devices_show - max devices support
197 * @cdev: pointer to embedded class device
198 * @buf: the buffer returned
200 * A sysfs 'read-only' shost attribute.
202 static ssize_t
pm8001_ctl_max_devices_show(struct device
*cdev
,
203 struct device_attribute
*attr
, char *buf
)
205 struct Scsi_Host
*shost
= class_to_shost(cdev
);
206 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
207 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
209 if (pm8001_ha
->chip_id
== chip_8001
) {
210 return snprintf(buf
, PAGE_SIZE
, "%04d\n",
211 (u16
)(pm8001_ha
->main_cfg_tbl
.pm8001_tbl
.max_sgl
>> 16)
214 return snprintf(buf
, PAGE_SIZE
, "%04d\n",
215 (u16
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.max_sgl
>> 16)
219 static DEVICE_ATTR(max_devices
, S_IRUGO
, pm8001_ctl_max_devices_show
, NULL
);
221 * pm8001_ctl_max_sg_list_show - max sg list supported iff not 0.0 for no
222 * hardware limitation
223 * @cdev: pointer to embedded class device
224 * @buf: the buffer returned
226 * A sysfs 'read-only' shost attribute.
228 static ssize_t
pm8001_ctl_max_sg_list_show(struct device
*cdev
,
229 struct device_attribute
*attr
, char *buf
)
231 struct Scsi_Host
*shost
= class_to_shost(cdev
);
232 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
233 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
235 if (pm8001_ha
->chip_id
== chip_8001
) {
236 return snprintf(buf
, PAGE_SIZE
, "%04d\n",
237 pm8001_ha
->main_cfg_tbl
.pm8001_tbl
.max_sgl
& 0x0000FFFF
240 return snprintf(buf
, PAGE_SIZE
, "%04d\n",
241 pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.max_sgl
& 0x0000FFFF
245 static DEVICE_ATTR(max_sg_list
, S_IRUGO
, pm8001_ctl_max_sg_list_show
, NULL
);
252 show_sas_spec_support_status(unsigned int mode
, char *buf
)
257 len
= sprintf(buf
, "%s", "SAS1.1");
259 len
+= sprintf(buf
+ len
, "%s%s", len
? ", " : "", "SAS2.0");
260 len
+= sprintf(buf
+ len
, "\n");
266 * pm8001_ctl_sas_spec_support_show - sas spec supported
267 * @cdev: pointer to embedded class device
268 * @buf: the buffer returned
270 * A sysfs 'read-only' shost attribute.
272 static ssize_t
pm8001_ctl_sas_spec_support_show(struct device
*cdev
,
273 struct device_attribute
*attr
, char *buf
)
276 struct Scsi_Host
*shost
= class_to_shost(cdev
);
277 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
278 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
279 /* fe000000 means supports SAS2.1 */
280 if (pm8001_ha
->chip_id
== chip_8001
)
281 mode
= (pm8001_ha
->main_cfg_tbl
.pm8001_tbl
.ctrl_cap_flag
&
284 /* fe000000 means supports SAS2.1 */
285 mode
= (pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.ctrl_cap_flag
&
287 return show_sas_spec_support_status(mode
, buf
);
289 static DEVICE_ATTR(sas_spec_support
, S_IRUGO
,
290 pm8001_ctl_sas_spec_support_show
, NULL
);
293 * pm8001_ctl_sas_address_show - sas address
294 * @cdev: pointer to embedded class device
295 * @buf: the buffer returned
297 * This is the controller sas address
299 * A sysfs 'read-only' shost attribute.
301 static ssize_t
pm8001_ctl_host_sas_address_show(struct device
*cdev
,
302 struct device_attribute
*attr
, char *buf
)
304 struct Scsi_Host
*shost
= class_to_shost(cdev
);
305 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
306 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
307 return snprintf(buf
, PAGE_SIZE
, "0x%016llx\n",
308 be64_to_cpu(*(__be64
*)pm8001_ha
->sas_addr
));
310 static DEVICE_ATTR(host_sas_address
, S_IRUGO
,
311 pm8001_ctl_host_sas_address_show
, NULL
);
314 * pm8001_ctl_logging_level_show - logging level
315 * @cdev: pointer to embedded class device
316 * @buf: the buffer returned
318 * A sysfs 'read/write' shost attribute.
320 static ssize_t
pm8001_ctl_logging_level_show(struct device
*cdev
,
321 struct device_attribute
*attr
, char *buf
)
323 struct Scsi_Host
*shost
= class_to_shost(cdev
);
324 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
325 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
327 return snprintf(buf
, PAGE_SIZE
, "%08xh\n", pm8001_ha
->logging_level
);
329 static ssize_t
pm8001_ctl_logging_level_store(struct device
*cdev
,
330 struct device_attribute
*attr
, const char *buf
, size_t count
)
332 struct Scsi_Host
*shost
= class_to_shost(cdev
);
333 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
334 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
337 if (sscanf(buf
, "%x", &val
) != 1)
340 pm8001_ha
->logging_level
= val
;
344 static DEVICE_ATTR(logging_level
, S_IRUGO
| S_IWUSR
,
345 pm8001_ctl_logging_level_show
, pm8001_ctl_logging_level_store
);
347 * pm8001_ctl_aap_log_show - aap1 event log
348 * @cdev: pointer to embedded class device
349 * @buf: the buffer returned
351 * A sysfs 'read-only' shost attribute.
353 static ssize_t
pm8001_ctl_aap_log_show(struct device
*cdev
,
354 struct device_attribute
*attr
, char *buf
)
356 struct Scsi_Host
*shost
= class_to_shost(cdev
);
357 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
358 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
360 #define AAP1_MEMMAP(r, c) \
361 (*(u32 *)((u8*)pm8001_ha->memoryMap.region[AAP1].virt_ptr + (r) * 32 \
366 for (i
= 0; i
< max
; i
++) {
367 str
+= sprintf(str
, "0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x"
381 static DEVICE_ATTR(aap_log
, S_IRUGO
, pm8001_ctl_aap_log_show
, NULL
);
383 * pm8001_ctl_ib_queue_log_show - Out bound Queue log
384 * @cdev:pointer to embedded class device
385 * @buf: the buffer returned
386 * A sysfs 'read-only' shost attribute.
388 static ssize_t
pm8001_ctl_ib_queue_log_show(struct device
*cdev
,
389 struct device_attribute
*attr
, char *buf
)
391 struct Scsi_Host
*shost
= class_to_shost(cdev
);
392 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
393 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
397 #define IB_MEMMAP(c) \
398 (*(u32 *)((u8 *)pm8001_ha-> \
399 memoryMap.region[IB].virt_ptr + \
400 pm8001_ha->evtlog_ib_offset + (c)))
402 for (offset
= 0; offset
< IB_OB_READ_TIMES
; offset
++) {
403 str
+= sprintf(str
, "0x%08x\n", IB_MEMMAP(start
));
406 pm8001_ha
->evtlog_ib_offset
+= SYSFS_OFFSET
;
407 if (((pm8001_ha
->evtlog_ib_offset
) % (PM80XX_IB_OB_QUEUE_SIZE
)) == 0)
408 pm8001_ha
->evtlog_ib_offset
= 0;
413 static DEVICE_ATTR(ib_log
, S_IRUGO
, pm8001_ctl_ib_queue_log_show
, NULL
);
415 * pm8001_ctl_ob_queue_log_show - Out bound Queue log
416 * @cdev:pointer to embedded class device
417 * @buf: the buffer returned
418 * A sysfs 'read-only' shost attribute.
421 static ssize_t
pm8001_ctl_ob_queue_log_show(struct device
*cdev
,
422 struct device_attribute
*attr
, char *buf
)
424 struct Scsi_Host
*shost
= class_to_shost(cdev
);
425 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
426 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
430 #define OB_MEMMAP(c) \
431 (*(u32 *)((u8 *)pm8001_ha-> \
432 memoryMap.region[OB].virt_ptr + \
433 pm8001_ha->evtlog_ob_offset + (c)))
435 for (offset
= 0; offset
< IB_OB_READ_TIMES
; offset
++) {
436 str
+= sprintf(str
, "0x%08x\n", OB_MEMMAP(start
));
439 pm8001_ha
->evtlog_ob_offset
+= SYSFS_OFFSET
;
440 if (((pm8001_ha
->evtlog_ob_offset
) % (PM80XX_IB_OB_QUEUE_SIZE
)) == 0)
441 pm8001_ha
->evtlog_ob_offset
= 0;
445 static DEVICE_ATTR(ob_log
, S_IRUGO
, pm8001_ctl_ob_queue_log_show
, NULL
);
447 * pm8001_ctl_bios_version_show - Bios version Display
448 * @cdev:pointer to embedded class device
449 * @buf:the buffer returned
450 * A sysfs 'read-only' shost attribute.
452 static ssize_t
pm8001_ctl_bios_version_show(struct device
*cdev
,
453 struct device_attribute
*attr
, char *buf
)
455 struct Scsi_Host
*shost
= class_to_shost(cdev
);
456 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
457 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
460 DECLARE_COMPLETION_ONSTACK(completion
);
461 struct pm8001_ioctl_payload payload
;
463 pm8001_ha
->nvmd_completion
= &completion
;
464 payload
.minor_function
= 7;
466 payload
.length
= 4096;
467 payload
.func_specific
= kzalloc(4096, GFP_KERNEL
);
468 if (!payload
.func_specific
)
470 if (PM8001_CHIP_DISP
->get_nvmd_req(pm8001_ha
, &payload
)) {
471 kfree(payload
.func_specific
);
474 wait_for_completion(&completion
);
475 for (bios_index
= BIOSOFFSET
; bios_index
< BIOS_OFFSET_LIMIT
;
477 str
+= sprintf(str
, "%c",
478 *(payload
.func_specific
+bios_index
));
479 kfree(payload
.func_specific
);
482 static DEVICE_ATTR(bios_version
, S_IRUGO
, pm8001_ctl_bios_version_show
, NULL
);
484 * event_log_size_show - event log size
485 * @cdev: pointer to embedded class device
486 * @buf: the buffer returned
488 * A sysfs read shost attribute.
490 static ssize_t
event_log_size_show(struct device
*cdev
,
491 struct device_attribute
*attr
, char *buf
)
493 struct Scsi_Host
*shost
= class_to_shost(cdev
);
494 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
495 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
497 return snprintf(buf
, PAGE_SIZE
, "%d\n",
498 pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.event_log_size
);
500 static DEVICE_ATTR_RO(event_log_size
);
502 * pm8001_ctl_aap_log_show - IOP event log
503 * @cdev: pointer to embedded class device
504 * @buf: the buffer returned
506 * A sysfs 'read-only' shost attribute.
508 static ssize_t
pm8001_ctl_iop_log_show(struct device
*cdev
,
509 struct device_attribute
*attr
, char *buf
)
511 struct Scsi_Host
*shost
= class_to_shost(cdev
);
512 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
513 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
516 pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.event_log_size
/ 1024;
517 static u32 start
, end
, count
;
518 u32 max_read_times
= 32;
519 u32 max_count
= (read_size
* 1024) / (max_read_times
* 4);
520 u32
*temp
= (u32
*)pm8001_ha
->memoryMap
.region
[IOP
].virt_ptr
;
522 if ((count
% max_count
) == 0) {
524 end
= max_read_times
;
528 end
= end
+ max_read_times
;
531 for (; start
< end
; start
++)
532 str
+= sprintf(str
, "%08x ", *(temp
+start
));
536 static DEVICE_ATTR(iop_log
, S_IRUGO
, pm8001_ctl_iop_log_show
, NULL
);
539 ** pm8001_ctl_fatal_log_show - fatal error logging
540 ** @cdev:pointer to embedded class device
541 ** @buf: the buffer returned
543 ** A sysfs 'read-only' shost attribute.
546 static ssize_t
pm8001_ctl_fatal_log_show(struct device
*cdev
,
547 struct device_attribute
*attr
, char *buf
)
551 count
= pm80xx_get_fatal_dump(cdev
, attr
, buf
);
555 static DEVICE_ATTR(fatal_log
, S_IRUGO
, pm8001_ctl_fatal_log_show
, NULL
);
559 ** pm8001_ctl_gsm_log_show - gsm dump collection
560 ** @cdev:pointer to embedded class device
561 ** @buf: the buffer returned
562 **A sysfs 'read-only' shost attribute.
564 static ssize_t
pm8001_ctl_gsm_log_show(struct device
*cdev
,
565 struct device_attribute
*attr
, char *buf
)
569 count
= pm8001_get_gsm_dump(cdev
, SYSFS_OFFSET
, buf
);
573 static DEVICE_ATTR(gsm_log
, S_IRUGO
, pm8001_ctl_gsm_log_show
, NULL
);
575 #define FLASH_CMD_NONE 0x00
576 #define FLASH_CMD_UPDATE 0x01
577 #define FLASH_CMD_SET_NVMD 0x02
579 struct flash_command
{
584 static struct flash_command flash_command_table
[] =
586 {"set_nvmd", FLASH_CMD_SET_NVMD
},
587 {"update", FLASH_CMD_UPDATE
},
588 {"", FLASH_CMD_NONE
} /* Last entry should be NULL. */
596 static struct error_fw flash_error_table
[] =
598 {"Failed to open fw image file", FAIL_OPEN_BIOS_FILE
},
599 {"image header mismatch", FLASH_UPDATE_HDR_ERR
},
600 {"image offset mismatch", FLASH_UPDATE_OFFSET_ERR
},
601 {"image CRC Error", FLASH_UPDATE_CRC_ERR
},
602 {"image length Error.", FLASH_UPDATE_LENGTH_ERR
},
603 {"Failed to program flash chip", FLASH_UPDATE_HW_ERR
},
604 {"Flash chip not supported.", FLASH_UPDATE_DNLD_NOT_SUPPORTED
},
605 {"Flash update disabled.", FLASH_UPDATE_DISABLED
},
606 {"Flash in progress", FLASH_IN_PROGRESS
},
607 {"Image file size Error", FAIL_FILE_SIZE
},
608 {"Input parameter error", FAIL_PARAMETERS
},
609 {"Out of memory", FAIL_OUT_MEMORY
},
610 {"OK", 0} /* Last entry err_code = 0. */
613 static int pm8001_set_nvmd(struct pm8001_hba_info
*pm8001_ha
)
615 struct pm8001_ioctl_payload
*payload
;
616 DECLARE_COMPLETION_ONSTACK(completion
);
619 u32 length
= 1024 * 5 + sizeof(*payload
) - 1;
621 if (pm8001_ha
->fw_image
->size
> 4096) {
622 pm8001_ha
->fw_status
= FAIL_FILE_SIZE
;
626 ioctlbuffer
= kzalloc(length
, GFP_KERNEL
);
628 pm8001_ha
->fw_status
= FAIL_OUT_MEMORY
;
631 payload
= (struct pm8001_ioctl_payload
*)ioctlbuffer
;
632 memcpy((u8
*)&payload
->func_specific
, (u8
*)pm8001_ha
->fw_image
->data
,
633 pm8001_ha
->fw_image
->size
);
634 payload
->length
= pm8001_ha
->fw_image
->size
;
636 payload
->minor_function
= 0x1;
637 pm8001_ha
->nvmd_completion
= &completion
;
638 ret
= PM8001_CHIP_DISP
->set_nvmd_req(pm8001_ha
, payload
);
640 pm8001_ha
->fw_status
= FAIL_OUT_MEMORY
;
643 wait_for_completion(&completion
);
649 static int pm8001_update_flash(struct pm8001_hba_info
*pm8001_ha
)
651 struct pm8001_ioctl_payload
*payload
;
652 DECLARE_COMPLETION_ONSTACK(completion
);
654 struct fw_control_info
*fwControl
;
655 u32 partitionSize
, partitionSizeTmp
;
656 u32 loopNumber
, loopcount
;
657 struct pm8001_fw_image_header
*image_hdr
;
660 u32 length
= 1024 * 16 + sizeof(*payload
) - 1;
662 if (pm8001_ha
->fw_image
->size
< 28) {
663 pm8001_ha
->fw_status
= FAIL_FILE_SIZE
;
666 ioctlbuffer
= kzalloc(length
, GFP_KERNEL
);
668 pm8001_ha
->fw_status
= FAIL_OUT_MEMORY
;
671 image_hdr
= (struct pm8001_fw_image_header
*)pm8001_ha
->fw_image
->data
;
672 while (sizeRead
< pm8001_ha
->fw_image
->size
) {
674 *(u32
*)((u8
*)&image_hdr
->image_length
+ sizeRead
);
675 partitionSize
= be32_to_cpu(partitionSizeTmp
);
676 loopcount
= DIV_ROUND_UP(partitionSize
+ HEADER_LEN
,
678 for (loopNumber
= 0; loopNumber
< loopcount
; loopNumber
++) {
679 payload
= (struct pm8001_ioctl_payload
*)ioctlbuffer
;
680 payload
->length
= 1024*16;
683 (struct fw_control_info
*)&payload
->func_specific
;
684 fwControl
->len
= IOCTL_BUF_SIZE
; /* IN */
685 fwControl
->size
= partitionSize
+ HEADER_LEN
;/* IN */
686 fwControl
->retcode
= 0;/* OUT */
687 fwControl
->offset
= loopNumber
* IOCTL_BUF_SIZE
;/*OUT */
689 /* for the last chunk of data in case file size is not even with
690 4k, load only the rest*/
691 if (((loopcount
-loopNumber
) == 1) &&
692 ((partitionSize
+ HEADER_LEN
) % IOCTL_BUF_SIZE
)) {
694 (partitionSize
+ HEADER_LEN
) % IOCTL_BUF_SIZE
;
695 memcpy((u8
*)fwControl
->buffer
,
696 (u8
*)pm8001_ha
->fw_image
->data
+ sizeRead
,
697 (partitionSize
+ HEADER_LEN
) % IOCTL_BUF_SIZE
);
699 (partitionSize
+ HEADER_LEN
) % IOCTL_BUF_SIZE
;
701 memcpy((u8
*)fwControl
->buffer
,
702 (u8
*)pm8001_ha
->fw_image
->data
+ sizeRead
,
704 sizeRead
+= IOCTL_BUF_SIZE
;
707 pm8001_ha
->nvmd_completion
= &completion
;
708 ret
= PM8001_CHIP_DISP
->fw_flash_update_req(pm8001_ha
, payload
);
710 pm8001_ha
->fw_status
= FAIL_OUT_MEMORY
;
713 wait_for_completion(&completion
);
714 if (fwControl
->retcode
> FLASH_UPDATE_IN_PROGRESS
) {
715 pm8001_ha
->fw_status
= fwControl
->retcode
;
725 static ssize_t
pm8001_store_update_fw(struct device
*cdev
,
726 struct device_attribute
*attr
,
727 const char *buf
, size_t count
)
729 struct Scsi_Host
*shost
= class_to_shost(cdev
);
730 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
731 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
732 char *cmd_ptr
, *filename_ptr
;
734 int flash_command
= FLASH_CMD_NONE
;
737 if (!capable(CAP_SYS_ADMIN
))
740 /* this test protects us from running two flash processes at once,
741 * so we should start with this test */
742 if (pm8001_ha
->fw_status
== FLASH_IN_PROGRESS
)
744 pm8001_ha
->fw_status
= FLASH_IN_PROGRESS
;
746 cmd_ptr
= kcalloc(count
, 2, GFP_KERNEL
);
748 pm8001_ha
->fw_status
= FAIL_OUT_MEMORY
;
752 filename_ptr
= cmd_ptr
+ count
;
753 res
= sscanf(buf
, "%s %s", cmd_ptr
, filename_ptr
);
755 pm8001_ha
->fw_status
= FAIL_PARAMETERS
;
760 for (i
= 0; flash_command_table
[i
].code
!= FLASH_CMD_NONE
; i
++) {
761 if (!memcmp(flash_command_table
[i
].command
,
762 cmd_ptr
, strlen(cmd_ptr
))) {
763 flash_command
= flash_command_table
[i
].code
;
767 if (flash_command
== FLASH_CMD_NONE
) {
768 pm8001_ha
->fw_status
= FAIL_PARAMETERS
;
773 ret
= request_firmware(&pm8001_ha
->fw_image
,
778 PM8001_FAIL_DBG(pm8001_ha
,
780 "Failed to load firmware image file %s, error %d\n",
782 pm8001_ha
->fw_status
= FAIL_OPEN_BIOS_FILE
;
786 if (FLASH_CMD_UPDATE
== flash_command
)
787 ret
= pm8001_update_flash(pm8001_ha
);
789 ret
= pm8001_set_nvmd(pm8001_ha
);
791 release_firmware(pm8001_ha
->fw_image
);
798 pm8001_ha
->fw_status
= FLASH_OK
;
802 static ssize_t
pm8001_show_update_fw(struct device
*cdev
,
803 struct device_attribute
*attr
, char *buf
)
806 struct Scsi_Host
*shost
= class_to_shost(cdev
);
807 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
808 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
810 for (i
= 0; flash_error_table
[i
].err_code
!= 0; i
++) {
811 if (flash_error_table
[i
].err_code
== pm8001_ha
->fw_status
)
814 if (pm8001_ha
->fw_status
!= FLASH_IN_PROGRESS
)
815 pm8001_ha
->fw_status
= FLASH_OK
;
817 return snprintf(buf
, PAGE_SIZE
, "status=%x %s\n",
818 flash_error_table
[i
].err_code
,
819 flash_error_table
[i
].reason
);
822 static DEVICE_ATTR(update_fw
, S_IRUGO
|S_IWUSR
|S_IWGRP
,
823 pm8001_show_update_fw
, pm8001_store_update_fw
);
824 struct device_attribute
*pm8001_host_attrs
[] = {
825 &dev_attr_interface_rev
,
826 &dev_attr_controller_fatal_error
,
827 &dev_attr_fw_version
,
833 &dev_attr_max_out_io
,
834 &dev_attr_max_devices
,
835 &dev_attr_max_sg_list
,
836 &dev_attr_sas_spec_support
,
837 &dev_attr_logging_level
,
838 &dev_attr_event_log_size
,
839 &dev_attr_host_sas_address
,
840 &dev_attr_bios_version
,
843 &dev_attr_ila_version
,
844 &dev_attr_inc_fw_ver
,