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 * pm8001_ctl_fw_version_show - firmware version
74 * @cdev: pointer to embedded class device
75 * @buf: the buffer returned
77 * A sysfs 'read-only' shost attribute.
79 static ssize_t
pm8001_ctl_fw_version_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 if (pm8001_ha
->chip_id
== chip_8001
) {
87 return snprintf(buf
, PAGE_SIZE
, "%02x.%02x.%02x.%02x\n",
88 (u8
)(pm8001_ha
->main_cfg_tbl
.pm8001_tbl
.firmware_rev
>> 24),
89 (u8
)(pm8001_ha
->main_cfg_tbl
.pm8001_tbl
.firmware_rev
>> 16),
90 (u8
)(pm8001_ha
->main_cfg_tbl
.pm8001_tbl
.firmware_rev
>> 8),
91 (u8
)(pm8001_ha
->main_cfg_tbl
.pm8001_tbl
.firmware_rev
));
93 return snprintf(buf
, PAGE_SIZE
, "%02x.%02x.%02x.%02x\n",
94 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.firmware_rev
>> 24),
95 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.firmware_rev
>> 16),
96 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.firmware_rev
>> 8),
97 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.firmware_rev
));
100 static DEVICE_ATTR(fw_version
, S_IRUGO
, pm8001_ctl_fw_version_show
, NULL
);
103 * pm8001_ctl_ila_version_show - ila version
104 * @cdev: pointer to embedded class device
105 * @buf: the buffer returned
107 * A sysfs 'read-only' shost attribute.
109 static ssize_t
pm8001_ctl_ila_version_show(struct device
*cdev
,
110 struct device_attribute
*attr
, char *buf
)
112 struct Scsi_Host
*shost
= class_to_shost(cdev
);
113 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
114 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
116 if (pm8001_ha
->chip_id
!= chip_8001
) {
117 return snprintf(buf
, PAGE_SIZE
, "%02x.%02x.%02x.%02x\n",
118 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.ila_version
>> 24),
119 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.ila_version
>> 16),
120 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.ila_version
>> 8),
121 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.ila_version
));
125 static DEVICE_ATTR(ila_version
, 0444, pm8001_ctl_ila_version_show
, NULL
);
128 * pm8001_ctl_inactive_fw_version_show - Inacative firmware version number
129 * @cdev: pointer to embedded class device
130 * @buf: the buffer returned
132 * A sysfs 'read-only' shost attribute.
134 static ssize_t
pm8001_ctl_inactive_fw_version_show(struct device
*cdev
,
135 struct device_attribute
*attr
, char *buf
)
137 struct Scsi_Host
*shost
= class_to_shost(cdev
);
138 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
139 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
141 if (pm8001_ha
->chip_id
!= chip_8001
) {
142 return snprintf(buf
, PAGE_SIZE
, "%02x.%02x.%02x.%02x\n",
143 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.inc_fw_version
>> 24),
144 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.inc_fw_version
>> 16),
145 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.inc_fw_version
>> 8),
146 (u8
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.inc_fw_version
));
151 DEVICE_ATTR(inc_fw_ver
, 0444, pm8001_ctl_inactive_fw_version_show
, NULL
);
154 * pm8001_ctl_max_out_io_show - max outstanding io supported
155 * @cdev: pointer to embedded class device
156 * @buf: the buffer returned
158 * A sysfs 'read-only' shost attribute.
160 static ssize_t
pm8001_ctl_max_out_io_show(struct device
*cdev
,
161 struct device_attribute
*attr
, char *buf
)
163 struct Scsi_Host
*shost
= class_to_shost(cdev
);
164 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
165 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
167 if (pm8001_ha
->chip_id
== chip_8001
) {
168 return snprintf(buf
, PAGE_SIZE
, "%d\n",
169 pm8001_ha
->main_cfg_tbl
.pm8001_tbl
.max_out_io
);
171 return snprintf(buf
, PAGE_SIZE
, "%d\n",
172 pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.max_out_io
);
175 static DEVICE_ATTR(max_out_io
, S_IRUGO
, pm8001_ctl_max_out_io_show
, NULL
);
177 * pm8001_ctl_max_devices_show - max devices support
178 * @cdev: pointer to embedded class device
179 * @buf: the buffer returned
181 * A sysfs 'read-only' shost attribute.
183 static ssize_t
pm8001_ctl_max_devices_show(struct device
*cdev
,
184 struct device_attribute
*attr
, char *buf
)
186 struct Scsi_Host
*shost
= class_to_shost(cdev
);
187 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
188 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
190 if (pm8001_ha
->chip_id
== chip_8001
) {
191 return snprintf(buf
, PAGE_SIZE
, "%04d\n",
192 (u16
)(pm8001_ha
->main_cfg_tbl
.pm8001_tbl
.max_sgl
>> 16)
195 return snprintf(buf
, PAGE_SIZE
, "%04d\n",
196 (u16
)(pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.max_sgl
>> 16)
200 static DEVICE_ATTR(max_devices
, S_IRUGO
, pm8001_ctl_max_devices_show
, NULL
);
202 * pm8001_ctl_max_sg_list_show - max sg list supported iff not 0.0 for no
203 * hardware limitation
204 * @cdev: pointer to embedded class device
205 * @buf: the buffer returned
207 * A sysfs 'read-only' shost attribute.
209 static ssize_t
pm8001_ctl_max_sg_list_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 pm8001_ha
->main_cfg_tbl
.pm8001_tbl
.max_sgl
& 0x0000FFFF
221 return snprintf(buf
, PAGE_SIZE
, "%04d\n",
222 pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.max_sgl
& 0x0000FFFF
226 static DEVICE_ATTR(max_sg_list
, S_IRUGO
, pm8001_ctl_max_sg_list_show
, NULL
);
233 show_sas_spec_support_status(unsigned int mode
, char *buf
)
238 len
= sprintf(buf
, "%s", "SAS1.1");
240 len
+= sprintf(buf
+ len
, "%s%s", len
? ", " : "", "SAS2.0");
241 len
+= sprintf(buf
+ len
, "\n");
247 * pm8001_ctl_sas_spec_support_show - sas spec supported
248 * @cdev: pointer to embedded class device
249 * @buf: the buffer returned
251 * A sysfs 'read-only' shost attribute.
253 static ssize_t
pm8001_ctl_sas_spec_support_show(struct device
*cdev
,
254 struct device_attribute
*attr
, char *buf
)
257 struct Scsi_Host
*shost
= class_to_shost(cdev
);
258 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
259 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
260 /* fe000000 means supports SAS2.1 */
261 if (pm8001_ha
->chip_id
== chip_8001
)
262 mode
= (pm8001_ha
->main_cfg_tbl
.pm8001_tbl
.ctrl_cap_flag
&
265 /* fe000000 means supports SAS2.1 */
266 mode
= (pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.ctrl_cap_flag
&
268 return show_sas_spec_support_status(mode
, buf
);
270 static DEVICE_ATTR(sas_spec_support
, S_IRUGO
,
271 pm8001_ctl_sas_spec_support_show
, NULL
);
274 * pm8001_ctl_sas_address_show - sas address
275 * @cdev: pointer to embedded class device
276 * @buf: the buffer returned
278 * This is the controller sas address
280 * A sysfs 'read-only' shost attribute.
282 static ssize_t
pm8001_ctl_host_sas_address_show(struct device
*cdev
,
283 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 return snprintf(buf
, PAGE_SIZE
, "0x%016llx\n",
289 be64_to_cpu(*(__be64
*)pm8001_ha
->sas_addr
));
291 static DEVICE_ATTR(host_sas_address
, S_IRUGO
,
292 pm8001_ctl_host_sas_address_show
, NULL
);
295 * pm8001_ctl_logging_level_show - logging level
296 * @cdev: pointer to embedded class device
297 * @buf: the buffer returned
299 * A sysfs 'read/write' shost attribute.
301 static ssize_t
pm8001_ctl_logging_level_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
;
308 return snprintf(buf
, PAGE_SIZE
, "%08xh\n", pm8001_ha
->logging_level
);
310 static ssize_t
pm8001_ctl_logging_level_store(struct device
*cdev
,
311 struct device_attribute
*attr
, const char *buf
, size_t count
)
313 struct Scsi_Host
*shost
= class_to_shost(cdev
);
314 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
315 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
318 if (sscanf(buf
, "%x", &val
) != 1)
321 pm8001_ha
->logging_level
= val
;
325 static DEVICE_ATTR(logging_level
, S_IRUGO
| S_IWUSR
,
326 pm8001_ctl_logging_level_show
, pm8001_ctl_logging_level_store
);
328 * pm8001_ctl_aap_log_show - aap1 event log
329 * @cdev: pointer to embedded class device
330 * @buf: the buffer returned
332 * A sysfs 'read-only' shost attribute.
334 static ssize_t
pm8001_ctl_aap_log_show(struct device
*cdev
,
335 struct device_attribute
*attr
, char *buf
)
337 struct Scsi_Host
*shost
= class_to_shost(cdev
);
338 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
339 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
341 #define AAP1_MEMMAP(r, c) \
342 (*(u32 *)((u8*)pm8001_ha->memoryMap.region[AAP1].virt_ptr + (r) * 32 \
347 for (i
= 0; i
< max
; i
++) {
348 str
+= sprintf(str
, "0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x"
362 static DEVICE_ATTR(aap_log
, S_IRUGO
, pm8001_ctl_aap_log_show
, NULL
);
364 * pm8001_ctl_ib_queue_log_show - Out bound Queue log
365 * @cdev:pointer to embedded class device
366 * @buf: the buffer returned
367 * A sysfs 'read-only' shost attribute.
369 static ssize_t
pm8001_ctl_ib_queue_log_show(struct device
*cdev
,
370 struct device_attribute
*attr
, char *buf
)
372 struct Scsi_Host
*shost
= class_to_shost(cdev
);
373 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
374 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
378 #define IB_MEMMAP(c) \
379 (*(u32 *)((u8 *)pm8001_ha-> \
380 memoryMap.region[IB].virt_ptr + \
381 pm8001_ha->evtlog_ib_offset + (c)))
383 for (offset
= 0; offset
< IB_OB_READ_TIMES
; offset
++) {
384 str
+= sprintf(str
, "0x%08x\n", IB_MEMMAP(start
));
387 pm8001_ha
->evtlog_ib_offset
+= SYSFS_OFFSET
;
388 if (((pm8001_ha
->evtlog_ib_offset
) % (PM80XX_IB_OB_QUEUE_SIZE
)) == 0)
389 pm8001_ha
->evtlog_ib_offset
= 0;
394 static DEVICE_ATTR(ib_log
, S_IRUGO
, pm8001_ctl_ib_queue_log_show
, NULL
);
396 * pm8001_ctl_ob_queue_log_show - Out bound Queue log
397 * @cdev:pointer to embedded class device
398 * @buf: the buffer returned
399 * A sysfs 'read-only' shost attribute.
402 static ssize_t
pm8001_ctl_ob_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 #define OB_MEMMAP(c) \
412 (*(u32 *)((u8 *)pm8001_ha-> \
413 memoryMap.region[OB].virt_ptr + \
414 pm8001_ha->evtlog_ob_offset + (c)))
416 for (offset
= 0; offset
< IB_OB_READ_TIMES
; offset
++) {
417 str
+= sprintf(str
, "0x%08x\n", OB_MEMMAP(start
));
420 pm8001_ha
->evtlog_ob_offset
+= SYSFS_OFFSET
;
421 if (((pm8001_ha
->evtlog_ob_offset
) % (PM80XX_IB_OB_QUEUE_SIZE
)) == 0)
422 pm8001_ha
->evtlog_ob_offset
= 0;
426 static DEVICE_ATTR(ob_log
, S_IRUGO
, pm8001_ctl_ob_queue_log_show
, NULL
);
428 * pm8001_ctl_bios_version_show - Bios version Display
429 * @cdev:pointer to embedded class device
430 * @buf:the buffer returned
431 * A sysfs 'read-only' shost attribute.
433 static ssize_t
pm8001_ctl_bios_version_show(struct device
*cdev
,
434 struct device_attribute
*attr
, char *buf
)
436 struct Scsi_Host
*shost
= class_to_shost(cdev
);
437 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
438 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
441 DECLARE_COMPLETION_ONSTACK(completion
);
442 struct pm8001_ioctl_payload payload
;
444 pm8001_ha
->nvmd_completion
= &completion
;
445 payload
.minor_function
= 7;
447 payload
.length
= 4096;
448 payload
.func_specific
= kzalloc(4096, GFP_KERNEL
);
449 if (!payload
.func_specific
)
451 if (PM8001_CHIP_DISP
->get_nvmd_req(pm8001_ha
, &payload
)) {
452 kfree(payload
.func_specific
);
455 wait_for_completion(&completion
);
456 for (bios_index
= BIOSOFFSET
; bios_index
< BIOS_OFFSET_LIMIT
;
458 str
+= sprintf(str
, "%c",
459 *(payload
.func_specific
+bios_index
));
460 kfree(payload
.func_specific
);
463 static DEVICE_ATTR(bios_version
, S_IRUGO
, pm8001_ctl_bios_version_show
, NULL
);
465 * event_log_size_show - event log size
466 * @cdev: pointer to embedded class device
467 * @buf: the buffer returned
469 * A sysfs read shost attribute.
471 static ssize_t
event_log_size_show(struct device
*cdev
,
472 struct device_attribute
*attr
, char *buf
)
474 struct Scsi_Host
*shost
= class_to_shost(cdev
);
475 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
476 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
478 return snprintf(buf
, PAGE_SIZE
, "%d\n",
479 pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.event_log_size
);
481 static DEVICE_ATTR_RO(event_log_size
);
483 * pm8001_ctl_aap_log_show - IOP event log
484 * @cdev: pointer to embedded class device
485 * @buf: the buffer returned
487 * A sysfs 'read-only' shost attribute.
489 static ssize_t
pm8001_ctl_iop_log_show(struct device
*cdev
,
490 struct device_attribute
*attr
, char *buf
)
492 struct Scsi_Host
*shost
= class_to_shost(cdev
);
493 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
494 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
497 pm8001_ha
->main_cfg_tbl
.pm80xx_tbl
.event_log_size
/ 1024;
498 static u32 start
, end
, count
;
499 u32 max_read_times
= 32;
500 u32 max_count
= (read_size
* 1024) / (max_read_times
* 4);
501 u32
*temp
= (u32
*)pm8001_ha
->memoryMap
.region
[IOP
].virt_ptr
;
503 if ((count
% max_count
) == 0) {
505 end
= max_read_times
;
509 end
= end
+ max_read_times
;
512 for (; start
< end
; start
++)
513 str
+= sprintf(str
, "%08x ", *(temp
+start
));
517 static DEVICE_ATTR(iop_log
, S_IRUGO
, pm8001_ctl_iop_log_show
, NULL
);
520 ** pm8001_ctl_fatal_log_show - fatal error logging
521 ** @cdev:pointer to embedded class device
522 ** @buf: the buffer returned
524 ** A sysfs 'read-only' shost attribute.
527 static ssize_t
pm8001_ctl_fatal_log_show(struct device
*cdev
,
528 struct device_attribute
*attr
, char *buf
)
532 count
= pm80xx_get_fatal_dump(cdev
, attr
, buf
);
536 static DEVICE_ATTR(fatal_log
, S_IRUGO
, pm8001_ctl_fatal_log_show
, NULL
);
540 ** pm8001_ctl_gsm_log_show - gsm dump collection
541 ** @cdev:pointer to embedded class device
542 ** @buf: the buffer returned
543 **A sysfs 'read-only' shost attribute.
545 static ssize_t
pm8001_ctl_gsm_log_show(struct device
*cdev
,
546 struct device_attribute
*attr
, char *buf
)
550 count
= pm8001_get_gsm_dump(cdev
, SYSFS_OFFSET
, buf
);
554 static DEVICE_ATTR(gsm_log
, S_IRUGO
, pm8001_ctl_gsm_log_show
, NULL
);
556 #define FLASH_CMD_NONE 0x00
557 #define FLASH_CMD_UPDATE 0x01
558 #define FLASH_CMD_SET_NVMD 0x02
560 struct flash_command
{
565 static struct flash_command flash_command_table
[] =
567 {"set_nvmd", FLASH_CMD_SET_NVMD
},
568 {"update", FLASH_CMD_UPDATE
},
569 {"", FLASH_CMD_NONE
} /* Last entry should be NULL. */
577 static struct error_fw flash_error_table
[] =
579 {"Failed to open fw image file", FAIL_OPEN_BIOS_FILE
},
580 {"image header mismatch", FLASH_UPDATE_HDR_ERR
},
581 {"image offset mismatch", FLASH_UPDATE_OFFSET_ERR
},
582 {"image CRC Error", FLASH_UPDATE_CRC_ERR
},
583 {"image length Error.", FLASH_UPDATE_LENGTH_ERR
},
584 {"Failed to program flash chip", FLASH_UPDATE_HW_ERR
},
585 {"Flash chip not supported.", FLASH_UPDATE_DNLD_NOT_SUPPORTED
},
586 {"Flash update disabled.", FLASH_UPDATE_DISABLED
},
587 {"Flash in progress", FLASH_IN_PROGRESS
},
588 {"Image file size Error", FAIL_FILE_SIZE
},
589 {"Input parameter error", FAIL_PARAMETERS
},
590 {"Out of memory", FAIL_OUT_MEMORY
},
591 {"OK", 0} /* Last entry err_code = 0. */
594 static int pm8001_set_nvmd(struct pm8001_hba_info
*pm8001_ha
)
596 struct pm8001_ioctl_payload
*payload
;
597 DECLARE_COMPLETION_ONSTACK(completion
);
600 u32 length
= 1024 * 5 + sizeof(*payload
) - 1;
602 if (pm8001_ha
->fw_image
->size
> 4096) {
603 pm8001_ha
->fw_status
= FAIL_FILE_SIZE
;
607 ioctlbuffer
= kzalloc(length
, GFP_KERNEL
);
609 pm8001_ha
->fw_status
= FAIL_OUT_MEMORY
;
612 payload
= (struct pm8001_ioctl_payload
*)ioctlbuffer
;
613 memcpy((u8
*)&payload
->func_specific
, (u8
*)pm8001_ha
->fw_image
->data
,
614 pm8001_ha
->fw_image
->size
);
615 payload
->length
= pm8001_ha
->fw_image
->size
;
617 payload
->minor_function
= 0x1;
618 pm8001_ha
->nvmd_completion
= &completion
;
619 ret
= PM8001_CHIP_DISP
->set_nvmd_req(pm8001_ha
, payload
);
621 pm8001_ha
->fw_status
= FAIL_OUT_MEMORY
;
624 wait_for_completion(&completion
);
630 static int pm8001_update_flash(struct pm8001_hba_info
*pm8001_ha
)
632 struct pm8001_ioctl_payload
*payload
;
633 DECLARE_COMPLETION_ONSTACK(completion
);
635 struct fw_control_info
*fwControl
;
636 u32 partitionSize
, partitionSizeTmp
;
637 u32 loopNumber
, loopcount
;
638 struct pm8001_fw_image_header
*image_hdr
;
641 u32 length
= 1024 * 16 + sizeof(*payload
) - 1;
643 if (pm8001_ha
->fw_image
->size
< 28) {
644 pm8001_ha
->fw_status
= FAIL_FILE_SIZE
;
647 ioctlbuffer
= kzalloc(length
, GFP_KERNEL
);
649 pm8001_ha
->fw_status
= FAIL_OUT_MEMORY
;
652 image_hdr
= (struct pm8001_fw_image_header
*)pm8001_ha
->fw_image
->data
;
653 while (sizeRead
< pm8001_ha
->fw_image
->size
) {
655 *(u32
*)((u8
*)&image_hdr
->image_length
+ sizeRead
);
656 partitionSize
= be32_to_cpu(partitionSizeTmp
);
657 loopcount
= DIV_ROUND_UP(partitionSize
+ HEADER_LEN
,
659 for (loopNumber
= 0; loopNumber
< loopcount
; loopNumber
++) {
660 payload
= (struct pm8001_ioctl_payload
*)ioctlbuffer
;
661 payload
->length
= 1024*16;
664 (struct fw_control_info
*)&payload
->func_specific
;
665 fwControl
->len
= IOCTL_BUF_SIZE
; /* IN */
666 fwControl
->size
= partitionSize
+ HEADER_LEN
;/* IN */
667 fwControl
->retcode
= 0;/* OUT */
668 fwControl
->offset
= loopNumber
* IOCTL_BUF_SIZE
;/*OUT */
670 /* for the last chunk of data in case file size is not even with
671 4k, load only the rest*/
672 if (((loopcount
-loopNumber
) == 1) &&
673 ((partitionSize
+ HEADER_LEN
) % IOCTL_BUF_SIZE
)) {
675 (partitionSize
+ HEADER_LEN
) % IOCTL_BUF_SIZE
;
676 memcpy((u8
*)fwControl
->buffer
,
677 (u8
*)pm8001_ha
->fw_image
->data
+ sizeRead
,
678 (partitionSize
+ HEADER_LEN
) % IOCTL_BUF_SIZE
);
680 (partitionSize
+ HEADER_LEN
) % IOCTL_BUF_SIZE
;
682 memcpy((u8
*)fwControl
->buffer
,
683 (u8
*)pm8001_ha
->fw_image
->data
+ sizeRead
,
685 sizeRead
+= IOCTL_BUF_SIZE
;
688 pm8001_ha
->nvmd_completion
= &completion
;
689 ret
= PM8001_CHIP_DISP
->fw_flash_update_req(pm8001_ha
, payload
);
691 pm8001_ha
->fw_status
= FAIL_OUT_MEMORY
;
694 wait_for_completion(&completion
);
695 if (fwControl
->retcode
> FLASH_UPDATE_IN_PROGRESS
) {
696 pm8001_ha
->fw_status
= fwControl
->retcode
;
706 static ssize_t
pm8001_store_update_fw(struct device
*cdev
,
707 struct device_attribute
*attr
,
708 const char *buf
, size_t count
)
710 struct Scsi_Host
*shost
= class_to_shost(cdev
);
711 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
712 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
713 char *cmd_ptr
, *filename_ptr
;
715 int flash_command
= FLASH_CMD_NONE
;
718 if (!capable(CAP_SYS_ADMIN
))
721 /* this test protects us from running two flash processes at once,
722 * so we should start with this test */
723 if (pm8001_ha
->fw_status
== FLASH_IN_PROGRESS
)
725 pm8001_ha
->fw_status
= FLASH_IN_PROGRESS
;
727 cmd_ptr
= kcalloc(count
, 2, GFP_KERNEL
);
729 pm8001_ha
->fw_status
= FAIL_OUT_MEMORY
;
733 filename_ptr
= cmd_ptr
+ count
;
734 res
= sscanf(buf
, "%s %s", cmd_ptr
, filename_ptr
);
736 pm8001_ha
->fw_status
= FAIL_PARAMETERS
;
741 for (i
= 0; flash_command_table
[i
].code
!= FLASH_CMD_NONE
; i
++) {
742 if (!memcmp(flash_command_table
[i
].command
,
743 cmd_ptr
, strlen(cmd_ptr
))) {
744 flash_command
= flash_command_table
[i
].code
;
748 if (flash_command
== FLASH_CMD_NONE
) {
749 pm8001_ha
->fw_status
= FAIL_PARAMETERS
;
754 ret
= request_firmware(&pm8001_ha
->fw_image
,
759 PM8001_FAIL_DBG(pm8001_ha
,
761 "Failed to load firmware image file %s, error %d\n",
763 pm8001_ha
->fw_status
= FAIL_OPEN_BIOS_FILE
;
767 if (FLASH_CMD_UPDATE
== flash_command
)
768 ret
= pm8001_update_flash(pm8001_ha
);
770 ret
= pm8001_set_nvmd(pm8001_ha
);
772 release_firmware(pm8001_ha
->fw_image
);
779 pm8001_ha
->fw_status
= FLASH_OK
;
783 static ssize_t
pm8001_show_update_fw(struct device
*cdev
,
784 struct device_attribute
*attr
, char *buf
)
787 struct Scsi_Host
*shost
= class_to_shost(cdev
);
788 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
789 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
791 for (i
= 0; flash_error_table
[i
].err_code
!= 0; i
++) {
792 if (flash_error_table
[i
].err_code
== pm8001_ha
->fw_status
)
795 if (pm8001_ha
->fw_status
!= FLASH_IN_PROGRESS
)
796 pm8001_ha
->fw_status
= FLASH_OK
;
798 return snprintf(buf
, PAGE_SIZE
, "status=%x %s\n",
799 flash_error_table
[i
].err_code
,
800 flash_error_table
[i
].reason
);
803 static DEVICE_ATTR(update_fw
, S_IRUGO
|S_IWUSR
|S_IWGRP
,
804 pm8001_show_update_fw
, pm8001_store_update_fw
);
805 struct device_attribute
*pm8001_host_attrs
[] = {
806 &dev_attr_interface_rev
,
807 &dev_attr_fw_version
,
813 &dev_attr_max_out_io
,
814 &dev_attr_max_devices
,
815 &dev_attr_max_sg_list
,
816 &dev_attr_sas_spec_support
,
817 &dev_attr_logging_level
,
818 &dev_attr_event_log_size
,
819 &dev_attr_host_sas_address
,
820 &dev_attr_bios_version
,
823 &dev_attr_ila_version
,
824 &dev_attr_inc_fw_ver
,