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 * @attr: device attribute (unused)
51 * @buf: the buffer returned
53 * A sysfs 'read-only' shost attribute.
55 static ssize_t
pm8001_ctl_mpi_interface_rev_show(struct device
*cdev
,
56 struct device_attribute
*attr
, char *buf
)
58 struct Scsi_Host
*shost
= class_to_shost(cdev
);
59 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
60 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
62 if (pm8001_ha
->chip_id
== chip_8001
) {
63 return snprintf(buf
, PAGE_SIZE
, "%d\n",
64 pm8001_ha
->main_cfg_tbl
.pm8001_tbl
.interface_rev
);
66 return snprintf(buf
, PAGE_SIZE
, "%d\n",
67 pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.interface_rev
);
71 DEVICE_ATTR(interface_rev
, S_IRUGO
, pm8001_ctl_mpi_interface_rev_show
, NULL
);
74 * controller_fatal_error_show - check controller is under fatal err
75 * @cdev: pointer to embedded class device
76 * @attr: device attribute (unused)
77 * @buf: the buffer returned
79 * A sysfs 'read only' shost attribute.
81 static ssize_t
controller_fatal_error_show(struct device
*cdev
,
82 struct device_attribute
*attr
, char *buf
)
84 struct Scsi_Host
*shost
= class_to_shost(cdev
);
85 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
86 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
88 return snprintf(buf
, PAGE_SIZE
, "%d\n",
89 pm8001_ha
->controller_fatal_error
);
91 static DEVICE_ATTR_RO(controller_fatal_error
);
94 * pm8001_ctl_fw_version_show - firmware version
95 * @cdev: pointer to embedded class device
96 * @attr: device attribute (unused)
97 * @buf: the buffer returned
99 * A sysfs 'read-only' shost attribute.
101 static ssize_t
pm8001_ctl_fw_version_show(struct device
*cdev
,
102 struct device_attribute
*attr
, char *buf
)
104 struct Scsi_Host
*shost
= class_to_shost(cdev
);
105 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
106 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
108 if (pm8001_ha
->chip_id
== chip_8001
) {
109 return snprintf(buf
, PAGE_SIZE
, "%02x.%02x.%02x.%02x\n",
110 (u8
)(pm8001_ha
->main_cfg_tbl
.pm8001_tbl
.firmware_rev
>> 24),
111 (u8
)(pm8001_ha
->main_cfg_tbl
.pm8001_tbl
.firmware_rev
>> 16),
112 (u8
)(pm8001_ha
->main_cfg_tbl
.pm8001_tbl
.firmware_rev
>> 8),
113 (u8
)(pm8001_ha
->main_cfg_tbl
.pm8001_tbl
.firmware_rev
));
115 return snprintf(buf
, PAGE_SIZE
, "%02x.%02x.%02x.%02x\n",
116 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.firmware_rev
>> 24),
117 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.firmware_rev
>> 16),
118 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.firmware_rev
>> 8),
119 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.firmware_rev
));
122 static DEVICE_ATTR(fw_version
, S_IRUGO
, pm8001_ctl_fw_version_show
, NULL
);
125 * pm8001_ctl_ila_version_show - ila version
126 * @cdev: pointer to embedded class device
127 * @attr: device attribute (unused)
128 * @buf: the buffer returned
130 * A sysfs 'read-only' shost attribute.
132 static ssize_t
pm8001_ctl_ila_version_show(struct device
*cdev
,
133 struct device_attribute
*attr
, char *buf
)
135 struct Scsi_Host
*shost
= class_to_shost(cdev
);
136 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
137 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
139 if (pm8001_ha
->chip_id
!= chip_8001
) {
140 return snprintf(buf
, PAGE_SIZE
, "%02x.%02x.%02x.%02x\n",
141 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.ila_version
>> 24),
142 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.ila_version
>> 16),
143 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.ila_version
>> 8),
144 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.ila_version
));
148 static DEVICE_ATTR(ila_version
, 0444, pm8001_ctl_ila_version_show
, NULL
);
151 * pm8001_ctl_inactive_fw_version_show - Inacative firmware version number
152 * @cdev: pointer to embedded class device
153 * @attr: device attribute (unused)
154 * @buf: the buffer returned
156 * A sysfs 'read-only' shost attribute.
158 static ssize_t
pm8001_ctl_inactive_fw_version_show(struct device
*cdev
,
159 struct device_attribute
*attr
, char *buf
)
161 struct Scsi_Host
*shost
= class_to_shost(cdev
);
162 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
163 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
165 if (pm8001_ha
->chip_id
!= chip_8001
) {
166 return snprintf(buf
, PAGE_SIZE
, "%02x.%02x.%02x.%02x\n",
167 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.inc_fw_version
>> 24),
168 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.inc_fw_version
>> 16),
169 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.inc_fw_version
>> 8),
170 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.inc_fw_version
));
175 DEVICE_ATTR(inc_fw_ver
, 0444, pm8001_ctl_inactive_fw_version_show
, NULL
);
178 * pm8001_ctl_max_out_io_show - max outstanding io supported
179 * @cdev: pointer to embedded class device
180 * @attr: device attribute (unused)
181 * @buf: the buffer returned
183 * A sysfs 'read-only' shost attribute.
185 static ssize_t
pm8001_ctl_max_out_io_show(struct device
*cdev
,
186 struct device_attribute
*attr
, char *buf
)
188 struct Scsi_Host
*shost
= class_to_shost(cdev
);
189 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
190 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
192 if (pm8001_ha
->chip_id
== chip_8001
) {
193 return snprintf(buf
, PAGE_SIZE
, "%d\n",
194 pm8001_ha
->main_cfg_tbl
.pm8001_tbl
.max_out_io
);
196 return snprintf(buf
, PAGE_SIZE
, "%d\n",
197 pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.max_out_io
);
200 static DEVICE_ATTR(max_out_io
, S_IRUGO
, pm8001_ctl_max_out_io_show
, NULL
);
202 * pm8001_ctl_max_devices_show - max devices support
203 * @cdev: pointer to embedded class device
204 * @attr: device attribute (unused)
205 * @buf: the buffer returned
207 * A sysfs 'read-only' shost attribute.
209 static ssize_t
pm8001_ctl_max_devices_show(struct device
*cdev
,
210 struct device_attribute
*attr
, char *buf
)
212 struct Scsi_Host
*shost
= class_to_shost(cdev
);
213 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
214 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
216 if (pm8001_ha
->chip_id
== chip_8001
) {
217 return snprintf(buf
, PAGE_SIZE
, "%04d\n",
218 (u16
)(pm8001_ha
->main_cfg_tbl
.pm8001_tbl
.max_sgl
>> 16)
221 return snprintf(buf
, PAGE_SIZE
, "%04d\n",
222 (u16
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.max_sgl
>> 16)
226 static DEVICE_ATTR(max_devices
, S_IRUGO
, pm8001_ctl_max_devices_show
, NULL
);
228 * pm8001_ctl_max_sg_list_show - max sg list supported iff not 0.0 for no
229 * hardware limitation
230 * @cdev: pointer to embedded class device
231 * @attr: device attribute (unused)
232 * @buf: the buffer returned
234 * A sysfs 'read-only' shost attribute.
236 static ssize_t
pm8001_ctl_max_sg_list_show(struct device
*cdev
,
237 struct device_attribute
*attr
, char *buf
)
239 struct Scsi_Host
*shost
= class_to_shost(cdev
);
240 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
241 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
243 if (pm8001_ha
->chip_id
== chip_8001
) {
244 return snprintf(buf
, PAGE_SIZE
, "%04d\n",
245 pm8001_ha
->main_cfg_tbl
.pm8001_tbl
.max_sgl
& 0x0000FFFF
248 return snprintf(buf
, PAGE_SIZE
, "%04d\n",
249 pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.max_sgl
& 0x0000FFFF
253 static DEVICE_ATTR(max_sg_list
, S_IRUGO
, pm8001_ctl_max_sg_list_show
, NULL
);
260 show_sas_spec_support_status(unsigned int mode
, char *buf
)
265 len
= sprintf(buf
, "%s", "SAS1.1");
267 len
+= sprintf(buf
+ len
, "%s%s", len
? ", " : "", "SAS2.0");
268 len
+= sprintf(buf
+ len
, "\n");
274 * pm8001_ctl_sas_spec_support_show - sas spec supported
275 * @cdev: pointer to embedded class device
276 * @attr: device attribute (unused)
277 * @buf: the buffer returned
279 * A sysfs 'read-only' shost attribute.
281 static ssize_t
pm8001_ctl_sas_spec_support_show(struct device
*cdev
,
282 struct device_attribute
*attr
, char *buf
)
285 struct Scsi_Host
*shost
= class_to_shost(cdev
);
286 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
287 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
288 /* fe000000 means supports SAS2.1 */
289 if (pm8001_ha
->chip_id
== chip_8001
)
290 mode
= (pm8001_ha
->main_cfg_tbl
.pm8001_tbl
.ctrl_cap_flag
&
293 /* fe000000 means supports SAS2.1 */
294 mode
= (pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.ctrl_cap_flag
&
296 return show_sas_spec_support_status(mode
, buf
);
298 static DEVICE_ATTR(sas_spec_support
, S_IRUGO
,
299 pm8001_ctl_sas_spec_support_show
, NULL
);
302 * pm8001_ctl_sas_address_show - sas address
303 * @cdev: pointer to embedded class device
304 * @attr: device attribute (unused)
305 * @buf: the buffer returned
307 * This is the controller sas address
309 * A sysfs 'read-only' shost attribute.
311 static ssize_t
pm8001_ctl_host_sas_address_show(struct device
*cdev
,
312 struct device_attribute
*attr
, char *buf
)
314 struct Scsi_Host
*shost
= class_to_shost(cdev
);
315 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
316 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
317 return snprintf(buf
, PAGE_SIZE
, "0x%016llx\n",
318 be64_to_cpu(*(__be64
*)pm8001_ha
->sas_addr
));
320 static DEVICE_ATTR(host_sas_address
, S_IRUGO
,
321 pm8001_ctl_host_sas_address_show
, NULL
);
324 * pm8001_ctl_logging_level_show - logging level
325 * @cdev: pointer to embedded class device
326 * @attr: device attribute (unused)
327 * @buf: the buffer returned
329 * A sysfs 'read/write' shost attribute.
331 static ssize_t
pm8001_ctl_logging_level_show(struct device
*cdev
,
332 struct device_attribute
*attr
, char *buf
)
334 struct Scsi_Host
*shost
= class_to_shost(cdev
);
335 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
336 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
338 return snprintf(buf
, PAGE_SIZE
, "%08xh\n", pm8001_ha
->logging_level
);
341 static ssize_t
pm8001_ctl_logging_level_store(struct device
*cdev
,
342 struct device_attribute
*attr
, const char *buf
, size_t count
)
344 struct Scsi_Host
*shost
= class_to_shost(cdev
);
345 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
346 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
349 if (sscanf(buf
, "%x", &val
) != 1)
352 pm8001_ha
->logging_level
= val
;
356 static DEVICE_ATTR(logging_level
, S_IRUGO
| S_IWUSR
,
357 pm8001_ctl_logging_level_show
, pm8001_ctl_logging_level_store
);
359 * pm8001_ctl_aap_log_show - aap1 event log
360 * @cdev: pointer to embedded class device
361 * @attr: device attribute (unused)
362 * @buf: the buffer returned
364 * A sysfs 'read-only' shost attribute.
366 static ssize_t
pm8001_ctl_aap_log_show(struct device
*cdev
,
367 struct device_attribute
*attr
, char *buf
)
369 struct Scsi_Host
*shost
= class_to_shost(cdev
);
370 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
371 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
373 #define AAP1_MEMMAP(r, c) \
374 (*(u32 *)((u8*)pm8001_ha->memoryMap.region[AAP1].virt_ptr + (r) * 32 \
379 for (i
= 0; i
< max
; i
++) {
380 str
+= sprintf(str
, "0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x"
394 static DEVICE_ATTR(aap_log
, S_IRUGO
, pm8001_ctl_aap_log_show
, NULL
);
396 * pm8001_ctl_ib_queue_log_show - Out bound Queue log
397 * @cdev:pointer to embedded class device
398 * @attr: device attribute (unused)
399 * @buf: the buffer returned
400 * A sysfs 'read-only' shost attribute.
402 static ssize_t
pm8001_ctl_ib_queue_log_show(struct device
*cdev
,
403 struct device_attribute
*attr
, char *buf
)
405 struct Scsi_Host
*shost
= class_to_shost(cdev
);
406 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
407 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
411 u32 ib_offset
= pm8001_ha
->ib_offset
;
412 #define IB_MEMMAP(c) \
413 (*(u32 *)((u8 *)pm8001_ha-> \
414 memoryMap.region[ib_offset].virt_ptr + \
415 pm8001_ha->evtlog_ib_offset + (c)))
417 for (offset
= 0; offset
< IB_OB_READ_TIMES
; offset
++) {
418 str
+= sprintf(str
, "0x%08x\n", IB_MEMMAP(start
));
421 pm8001_ha
->evtlog_ib_offset
+= SYSFS_OFFSET
;
422 if (((pm8001_ha
->evtlog_ib_offset
) % (PM80XX_IB_OB_QUEUE_SIZE
)) == 0)
423 pm8001_ha
->evtlog_ib_offset
= 0;
428 static DEVICE_ATTR(ib_log
, S_IRUGO
, pm8001_ctl_ib_queue_log_show
, NULL
);
430 * pm8001_ctl_ob_queue_log_show - Out bound Queue log
431 * @cdev:pointer to embedded class device
432 * @attr: device attribute (unused)
433 * @buf: the buffer returned
434 * A sysfs 'read-only' shost attribute.
437 static ssize_t
pm8001_ctl_ob_queue_log_show(struct device
*cdev
,
438 struct device_attribute
*attr
, char *buf
)
440 struct Scsi_Host
*shost
= class_to_shost(cdev
);
441 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
442 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
446 u32 ob_offset
= pm8001_ha
->ob_offset
;
447 #define OB_MEMMAP(c) \
448 (*(u32 *)((u8 *)pm8001_ha-> \
449 memoryMap.region[ob_offset].virt_ptr + \
450 pm8001_ha->evtlog_ob_offset + (c)))
452 for (offset
= 0; offset
< IB_OB_READ_TIMES
; offset
++) {
453 str
+= sprintf(str
, "0x%08x\n", OB_MEMMAP(start
));
456 pm8001_ha
->evtlog_ob_offset
+= SYSFS_OFFSET
;
457 if (((pm8001_ha
->evtlog_ob_offset
) % (PM80XX_IB_OB_QUEUE_SIZE
)) == 0)
458 pm8001_ha
->evtlog_ob_offset
= 0;
462 static DEVICE_ATTR(ob_log
, S_IRUGO
, pm8001_ctl_ob_queue_log_show
, NULL
);
464 * pm8001_ctl_bios_version_show - Bios version Display
465 * @cdev:pointer to embedded class device
466 * @attr: device attribute (unused)
467 * @buf:the buffer returned
468 * A sysfs 'read-only' shost attribute.
470 static ssize_t
pm8001_ctl_bios_version_show(struct device
*cdev
,
471 struct device_attribute
*attr
, char *buf
)
473 struct Scsi_Host
*shost
= class_to_shost(cdev
);
474 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
475 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
478 DECLARE_COMPLETION_ONSTACK(completion
);
479 struct pm8001_ioctl_payload payload
;
481 pm8001_ha
->nvmd_completion
= &completion
;
482 payload
.minor_function
= 7;
484 payload
.rd_length
= 4096;
485 payload
.func_specific
= kzalloc(4096, GFP_KERNEL
);
486 if (!payload
.func_specific
)
488 if (PM8001_CHIP_DISP
->get_nvmd_req(pm8001_ha
, &payload
)) {
489 kfree(payload
.func_specific
);
492 wait_for_completion(&completion
);
493 for (bios_index
= BIOSOFFSET
; bios_index
< BIOS_OFFSET_LIMIT
;
495 str
+= sprintf(str
, "%c",
496 *(payload
.func_specific
+bios_index
));
497 kfree(payload
.func_specific
);
500 static DEVICE_ATTR(bios_version
, S_IRUGO
, pm8001_ctl_bios_version_show
, NULL
);
502 * event_log_size_show - event log size
503 * @cdev: pointer to embedded class device
504 * @attr: device attribute (unused)
505 * @buf: the buffer returned
507 * A sysfs read shost attribute.
509 static ssize_t
event_log_size_show(struct device
*cdev
,
510 struct device_attribute
*attr
, char *buf
)
512 struct Scsi_Host
*shost
= class_to_shost(cdev
);
513 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
514 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
516 return snprintf(buf
, PAGE_SIZE
, "%d\n",
517 pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.event_log_size
);
519 static DEVICE_ATTR_RO(event_log_size
);
521 * pm8001_ctl_aap_log_show - IOP event log
522 * @cdev: pointer to embedded class device
523 * @attr: device attribute (unused)
524 * @buf: the buffer returned
526 * A sysfs 'read-only' shost attribute.
528 static ssize_t
pm8001_ctl_iop_log_show(struct device
*cdev
,
529 struct device_attribute
*attr
, char *buf
)
531 struct Scsi_Host
*shost
= class_to_shost(cdev
);
532 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
533 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
536 pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.event_log_size
/ 1024;
537 static u32 start
, end
, count
;
538 u32 max_read_times
= 32;
539 u32 max_count
= (read_size
* 1024) / (max_read_times
* 4);
540 u32
*temp
= (u32
*)pm8001_ha
->memoryMap
.region
[IOP
].virt_ptr
;
542 if ((count
% max_count
) == 0) {
544 end
= max_read_times
;
548 end
= end
+ max_read_times
;
551 for (; start
< end
; start
++)
552 str
+= sprintf(str
, "%08x ", *(temp
+start
));
556 static DEVICE_ATTR(iop_log
, S_IRUGO
, pm8001_ctl_iop_log_show
, NULL
);
559 ** pm8001_ctl_fatal_log_show - fatal error logging
560 ** @cdev:pointer to embedded class device
561 ** @attr: device attribute
562 ** @buf: the buffer returned
564 ** A sysfs 'read-only' shost attribute.
567 static ssize_t
pm8001_ctl_fatal_log_show(struct device
*cdev
,
568 struct device_attribute
*attr
, char *buf
)
572 count
= pm80xx_get_fatal_dump(cdev
, attr
, buf
);
576 static DEVICE_ATTR(fatal_log
, S_IRUGO
, pm8001_ctl_fatal_log_show
, NULL
);
579 ** non_fatal_log_show - non fatal error logging
580 ** @cdev:pointer to embedded class device
581 ** @attr: device attribute
582 ** @buf: the buffer returned
584 ** A sysfs 'read-only' shost attribute.
586 static ssize_t
non_fatal_log_show(struct device
*cdev
,
587 struct device_attribute
*attr
, char *buf
)
591 count
= pm80xx_get_non_fatal_dump(cdev
, attr
, buf
);
594 static DEVICE_ATTR_RO(non_fatal_log
);
596 static ssize_t
non_fatal_count_show(struct device
*cdev
,
597 struct device_attribute
*attr
, char *buf
)
599 struct Scsi_Host
*shost
= class_to_shost(cdev
);
600 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
601 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
603 return snprintf(buf
, PAGE_SIZE
, "%08x",
604 pm8001_ha
->non_fatal_count
);
607 static ssize_t
non_fatal_count_store(struct device
*cdev
,
608 struct device_attribute
*attr
, const char *buf
, size_t count
)
610 struct Scsi_Host
*shost
= class_to_shost(cdev
);
611 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
612 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
615 if (kstrtoint(buf
, 16, &val
) != 0)
618 pm8001_ha
->non_fatal_count
= val
;
621 static DEVICE_ATTR_RW(non_fatal_count
);
624 ** pm8001_ctl_gsm_log_show - gsm dump collection
625 ** @cdev:pointer to embedded class device
626 ** @attr: device attribute (unused)
627 ** @buf: the buffer returned
628 ** A sysfs 'read-only' shost attribute.
630 static ssize_t
pm8001_ctl_gsm_log_show(struct device
*cdev
,
631 struct device_attribute
*attr
, char *buf
)
635 count
= pm8001_get_gsm_dump(cdev
, SYSFS_OFFSET
, buf
);
639 static DEVICE_ATTR(gsm_log
, S_IRUGO
, pm8001_ctl_gsm_log_show
, NULL
);
641 #define FLASH_CMD_NONE 0x00
642 #define FLASH_CMD_UPDATE 0x01
643 #define FLASH_CMD_SET_NVMD 0x02
645 struct flash_command
{
650 static struct flash_command flash_command_table
[] =
652 {"set_nvmd", FLASH_CMD_SET_NVMD
},
653 {"update", FLASH_CMD_UPDATE
},
654 {"", FLASH_CMD_NONE
} /* Last entry should be NULL. */
662 static struct error_fw flash_error_table
[] =
664 {"Failed to open fw image file", FAIL_OPEN_BIOS_FILE
},
665 {"image header mismatch", FLASH_UPDATE_HDR_ERR
},
666 {"image offset mismatch", FLASH_UPDATE_OFFSET_ERR
},
667 {"image CRC Error", FLASH_UPDATE_CRC_ERR
},
668 {"image length Error.", FLASH_UPDATE_LENGTH_ERR
},
669 {"Failed to program flash chip", FLASH_UPDATE_HW_ERR
},
670 {"Flash chip not supported.", FLASH_UPDATE_DNLD_NOT_SUPPORTED
},
671 {"Flash update disabled.", FLASH_UPDATE_DISABLED
},
672 {"Flash in progress", FLASH_IN_PROGRESS
},
673 {"Image file size Error", FAIL_FILE_SIZE
},
674 {"Input parameter error", FAIL_PARAMETERS
},
675 {"Out of memory", FAIL_OUT_MEMORY
},
676 {"OK", 0} /* Last entry err_code = 0. */
679 static int pm8001_set_nvmd(struct pm8001_hba_info
*pm8001_ha
)
681 struct pm8001_ioctl_payload
*payload
;
682 DECLARE_COMPLETION_ONSTACK(completion
);
685 u32 length
= 1024 * 5 + sizeof(*payload
) - 1;
687 if (pm8001_ha
->fw_image
->size
> 4096) {
688 pm8001_ha
->fw_status
= FAIL_FILE_SIZE
;
692 ioctlbuffer
= kzalloc(length
, GFP_KERNEL
);
694 pm8001_ha
->fw_status
= FAIL_OUT_MEMORY
;
697 payload
= (struct pm8001_ioctl_payload
*)ioctlbuffer
;
698 memcpy((u8
*)&payload
->func_specific
, (u8
*)pm8001_ha
->fw_image
->data
,
699 pm8001_ha
->fw_image
->size
);
700 payload
->wr_length
= pm8001_ha
->fw_image
->size
;
702 payload
->minor_function
= 0x1;
703 pm8001_ha
->nvmd_completion
= &completion
;
704 ret
= PM8001_CHIP_DISP
->set_nvmd_req(pm8001_ha
, payload
);
706 pm8001_ha
->fw_status
= FAIL_OUT_MEMORY
;
709 wait_for_completion(&completion
);
715 static int pm8001_update_flash(struct pm8001_hba_info
*pm8001_ha
)
717 struct pm8001_ioctl_payload
*payload
;
718 DECLARE_COMPLETION_ONSTACK(completion
);
720 struct fw_control_info
*fwControl
;
721 u32 partitionSize
, partitionSizeTmp
;
722 u32 loopNumber
, loopcount
;
723 struct pm8001_fw_image_header
*image_hdr
;
726 u32 length
= 1024 * 16 + sizeof(*payload
) - 1;
728 if (pm8001_ha
->fw_image
->size
< 28) {
729 pm8001_ha
->fw_status
= FAIL_FILE_SIZE
;
732 ioctlbuffer
= kzalloc(length
, GFP_KERNEL
);
734 pm8001_ha
->fw_status
= FAIL_OUT_MEMORY
;
737 image_hdr
= (struct pm8001_fw_image_header
*)pm8001_ha
->fw_image
->data
;
738 while (sizeRead
< pm8001_ha
->fw_image
->size
) {
740 *(u32
*)((u8
*)&image_hdr
->image_length
+ sizeRead
);
741 partitionSize
= be32_to_cpu(partitionSizeTmp
);
742 loopcount
= DIV_ROUND_UP(partitionSize
+ HEADER_LEN
,
744 for (loopNumber
= 0; loopNumber
< loopcount
; loopNumber
++) {
745 payload
= (struct pm8001_ioctl_payload
*)ioctlbuffer
;
746 payload
->wr_length
= 1024*16;
749 (struct fw_control_info
*)&payload
->func_specific
;
750 fwControl
->len
= IOCTL_BUF_SIZE
; /* IN */
751 fwControl
->size
= partitionSize
+ HEADER_LEN
;/* IN */
752 fwControl
->retcode
= 0;/* OUT */
753 fwControl
->offset
= loopNumber
* IOCTL_BUF_SIZE
;/*OUT */
755 /* for the last chunk of data in case file size is not even with
756 4k, load only the rest*/
757 if (((loopcount
-loopNumber
) == 1) &&
758 ((partitionSize
+ HEADER_LEN
) % IOCTL_BUF_SIZE
)) {
760 (partitionSize
+ HEADER_LEN
) % IOCTL_BUF_SIZE
;
761 memcpy((u8
*)fwControl
->buffer
,
762 (u8
*)pm8001_ha
->fw_image
->data
+ sizeRead
,
763 (partitionSize
+ HEADER_LEN
) % IOCTL_BUF_SIZE
);
765 (partitionSize
+ HEADER_LEN
) % IOCTL_BUF_SIZE
;
767 memcpy((u8
*)fwControl
->buffer
,
768 (u8
*)pm8001_ha
->fw_image
->data
+ sizeRead
,
770 sizeRead
+= IOCTL_BUF_SIZE
;
773 pm8001_ha
->nvmd_completion
= &completion
;
774 ret
= PM8001_CHIP_DISP
->fw_flash_update_req(pm8001_ha
, payload
);
776 pm8001_ha
->fw_status
= FAIL_OUT_MEMORY
;
779 wait_for_completion(&completion
);
780 if (fwControl
->retcode
> FLASH_UPDATE_IN_PROGRESS
) {
781 pm8001_ha
->fw_status
= fwControl
->retcode
;
791 static ssize_t
pm8001_store_update_fw(struct device
*cdev
,
792 struct device_attribute
*attr
,
793 const char *buf
, size_t count
)
795 struct Scsi_Host
*shost
= class_to_shost(cdev
);
796 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
797 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
798 char *cmd_ptr
, *filename_ptr
;
800 int flash_command
= FLASH_CMD_NONE
;
803 if (!capable(CAP_SYS_ADMIN
))
806 /* this test protects us from running two flash processes at once,
807 * so we should start with this test */
808 if (pm8001_ha
->fw_status
== FLASH_IN_PROGRESS
)
810 pm8001_ha
->fw_status
= FLASH_IN_PROGRESS
;
812 cmd_ptr
= kcalloc(count
, 2, GFP_KERNEL
);
814 pm8001_ha
->fw_status
= FAIL_OUT_MEMORY
;
818 filename_ptr
= cmd_ptr
+ count
;
819 res
= sscanf(buf
, "%s %s", cmd_ptr
, filename_ptr
);
821 pm8001_ha
->fw_status
= FAIL_PARAMETERS
;
826 for (i
= 0; flash_command_table
[i
].code
!= FLASH_CMD_NONE
; i
++) {
827 if (!memcmp(flash_command_table
[i
].command
,
828 cmd_ptr
, strlen(cmd_ptr
))) {
829 flash_command
= flash_command_table
[i
].code
;
833 if (flash_command
== FLASH_CMD_NONE
) {
834 pm8001_ha
->fw_status
= FAIL_PARAMETERS
;
839 ret
= request_firmware(&pm8001_ha
->fw_image
,
844 pm8001_dbg(pm8001_ha
, FAIL
,
845 "Failed to load firmware image file %s, error %d\n",
847 pm8001_ha
->fw_status
= FAIL_OPEN_BIOS_FILE
;
851 if (FLASH_CMD_UPDATE
== flash_command
)
852 ret
= pm8001_update_flash(pm8001_ha
);
854 ret
= pm8001_set_nvmd(pm8001_ha
);
856 release_firmware(pm8001_ha
->fw_image
);
863 pm8001_ha
->fw_status
= FLASH_OK
;
867 static ssize_t
pm8001_show_update_fw(struct device
*cdev
,
868 struct device_attribute
*attr
, char *buf
)
871 struct Scsi_Host
*shost
= class_to_shost(cdev
);
872 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
873 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
875 for (i
= 0; flash_error_table
[i
].err_code
!= 0; i
++) {
876 if (flash_error_table
[i
].err_code
== pm8001_ha
->fw_status
)
879 if (pm8001_ha
->fw_status
!= FLASH_IN_PROGRESS
)
880 pm8001_ha
->fw_status
= FLASH_OK
;
882 return snprintf(buf
, PAGE_SIZE
, "status=%x %s\n",
883 flash_error_table
[i
].err_code
,
884 flash_error_table
[i
].reason
);
887 static DEVICE_ATTR(update_fw
, S_IRUGO
|S_IWUSR
|S_IWGRP
,
888 pm8001_show_update_fw
, pm8001_store_update_fw
);
889 struct device_attribute
*pm8001_host_attrs
[] = {
890 &dev_attr_interface_rev
,
891 &dev_attr_controller_fatal_error
,
892 &dev_attr_fw_version
,
897 &dev_attr_non_fatal_log
,
898 &dev_attr_non_fatal_count
,
900 &dev_attr_max_out_io
,
901 &dev_attr_max_devices
,
902 &dev_attr_max_sg_list
,
903 &dev_attr_sas_spec_support
,
904 &dev_attr_logging_level
,
905 &dev_attr_event_log_size
,
906 &dev_attr_host_sas_address
,
907 &dev_attr_bios_version
,
910 &dev_attr_ila_version
,
911 &dev_attr_inc_fw_ver
,