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);
102 * pm8001_ctl_max_out_io_show - max outstanding io supported
103 * @cdev: pointer to embedded class device
104 * @buf: the buffer returned
106 * A sysfs 'read-only' shost attribute.
108 static ssize_t pm8001_ctl_max_out_io_show(struct device *cdev,
109 struct device_attribute *attr, char *buf)
111 struct Scsi_Host *shost = class_to_shost(cdev);
112 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
113 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
115 if (pm8001_ha->chip_id == chip_8001) {
116 return snprintf(buf, PAGE_SIZE, "%d\n",
117 pm8001_ha->main_cfg_tbl.pm8001_tbl.max_out_io);
119 return snprintf(buf, PAGE_SIZE, "%d\n",
120 pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_out_io);
123 static DEVICE_ATTR(max_out_io, S_IRUGO, pm8001_ctl_max_out_io_show, NULL);
125 * pm8001_ctl_max_devices_show - max devices support
126 * @cdev: pointer to embedded class device
127 * @buf: the buffer returned
129 * A sysfs 'read-only' shost attribute.
131 static ssize_t pm8001_ctl_max_devices_show(struct device *cdev,
132 struct device_attribute *attr, char *buf)
134 struct Scsi_Host *shost = class_to_shost(cdev);
135 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
136 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
138 if (pm8001_ha->chip_id == chip_8001) {
139 return snprintf(buf, PAGE_SIZE, "%04d\n",
140 (u16)(pm8001_ha->main_cfg_tbl.pm8001_tbl.max_sgl >> 16)
143 return snprintf(buf, PAGE_SIZE, "%04d\n",
144 (u16)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_sgl >> 16)
148 static DEVICE_ATTR(max_devices, S_IRUGO, pm8001_ctl_max_devices_show, NULL);
150 * pm8001_ctl_max_sg_list_show - max sg list supported iff not 0.0 for no
151 * hardware limitation
152 * @cdev: pointer to embedded class device
153 * @buf: the buffer returned
155 * A sysfs 'read-only' shost attribute.
157 static ssize_t pm8001_ctl_max_sg_list_show(struct device *cdev,
158 struct device_attribute *attr, char *buf)
160 struct Scsi_Host *shost = class_to_shost(cdev);
161 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
162 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
164 if (pm8001_ha->chip_id == chip_8001) {
165 return snprintf(buf, PAGE_SIZE, "%04d\n",
166 pm8001_ha->main_cfg_tbl.pm8001_tbl.max_sgl & 0x0000FFFF
169 return snprintf(buf, PAGE_SIZE, "%04d\n",
170 pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_sgl & 0x0000FFFF
174 static DEVICE_ATTR(max_sg_list, S_IRUGO, pm8001_ctl_max_sg_list_show, NULL);
181 show_sas_spec_support_status(unsigned int mode, char *buf)
186 len = sprintf(buf, "%s", "SAS1.1");
188 len += sprintf(buf + len, "%s%s", len ? ", " : "", "SAS2.0");
189 len += sprintf(buf + len, "\n");
195 * pm8001_ctl_sas_spec_support_show - sas spec supported
196 * @cdev: pointer to embedded class device
197 * @buf: the buffer returned
199 * A sysfs 'read-only' shost attribute.
201 static ssize_t pm8001_ctl_sas_spec_support_show(struct device *cdev,
202 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;
208 /* fe000000 means supports SAS2.1 */
209 if (pm8001_ha->chip_id == chip_8001)
210 mode = (pm8001_ha->main_cfg_tbl.pm8001_tbl.ctrl_cap_flag &
213 /* fe000000 means supports SAS2.1 */
214 mode = (pm8001_ha->main_cfg_tbl.pm80xx_tbl.ctrl_cap_flag &
216 return show_sas_spec_support_status(mode, buf);
218 static DEVICE_ATTR(sas_spec_support, S_IRUGO,
219 pm8001_ctl_sas_spec_support_show, NULL);
222 * pm8001_ctl_sas_address_show - sas address
223 * @cdev: pointer to embedded class device
224 * @buf: the buffer returned
226 * This is the controller sas address
228 * A sysfs 'read-only' shost attribute.
230 static ssize_t pm8001_ctl_host_sas_address_show(struct device *cdev,
231 struct device_attribute *attr, char *buf)
233 struct Scsi_Host *shost = class_to_shost(cdev);
234 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
235 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
236 return snprintf(buf, PAGE_SIZE, "0x%016llx\n",
237 be64_to_cpu(*(__be64 *)pm8001_ha->sas_addr));
239 static DEVICE_ATTR(host_sas_address, S_IRUGO,
240 pm8001_ctl_host_sas_address_show, NULL);
243 * pm8001_ctl_logging_level_show - logging level
244 * @cdev: pointer to embedded class device
245 * @buf: the buffer returned
247 * A sysfs 'read/write' shost attribute.
249 static ssize_t pm8001_ctl_logging_level_show(struct device *cdev,
250 struct device_attribute *attr, char *buf)
252 struct Scsi_Host *shost = class_to_shost(cdev);
253 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
254 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
256 return snprintf(buf, PAGE_SIZE, "%08xh\n", pm8001_ha->logging_level);
258 static ssize_t pm8001_ctl_logging_level_store(struct device *cdev,
259 struct device_attribute *attr, const char *buf, size_t count)
261 struct Scsi_Host *shost = class_to_shost(cdev);
262 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
263 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
266 if (sscanf(buf, "%x", &val) != 1)
269 pm8001_ha->logging_level = val;
273 static DEVICE_ATTR(logging_level, S_IRUGO | S_IWUSR,
274 pm8001_ctl_logging_level_show, pm8001_ctl_logging_level_store);
276 * pm8001_ctl_aap_log_show - aap1 event log
277 * @cdev: pointer to embedded class device
278 * @buf: the buffer returned
280 * A sysfs 'read-only' shost attribute.
282 static ssize_t pm8001_ctl_aap_log_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;
289 #define AAP1_MEMMAP(r, c) \
290 (*(u32 *)((u8*)pm8001_ha->memoryMap.region[AAP1].virt_ptr + (r) * 32 \
295 for (i = 0; i < max; i++) {
296 str += sprintf(str, "0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x"
310 static DEVICE_ATTR(aap_log, S_IRUGO, pm8001_ctl_aap_log_show, NULL);
312 * pm8001_ctl_ib_queue_log_show - Out bound Queue log
313 * @cdev:pointer to embedded class device
314 * @buf: the buffer returned
315 * A sysfs 'read-only' shost attribute.
317 static ssize_t pm8001_ctl_ib_queue_log_show(struct device *cdev,
318 struct device_attribute *attr, char *buf)
320 struct Scsi_Host *shost = class_to_shost(cdev);
321 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
322 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
326 #define IB_MEMMAP(c) \
327 (*(u32 *)((u8 *)pm8001_ha-> \
328 memoryMap.region[IB].virt_ptr + \
329 pm8001_ha->evtlog_ib_offset + (c)))
331 for (offset = 0; offset < IB_OB_READ_TIMES; offset++) {
332 str += sprintf(str, "0x%08x\n", IB_MEMMAP(start));
335 pm8001_ha->evtlog_ib_offset += SYSFS_OFFSET;
336 if (((pm8001_ha->evtlog_ib_offset) % (PM80XX_IB_OB_QUEUE_SIZE)) == 0)
337 pm8001_ha->evtlog_ib_offset = 0;
342 static DEVICE_ATTR(ib_log, S_IRUGO, pm8001_ctl_ib_queue_log_show, NULL);
344 * pm8001_ctl_ob_queue_log_show - Out bound Queue log
345 * @cdev:pointer to embedded class device
346 * @buf: the buffer returned
347 * A sysfs 'read-only' shost attribute.
350 static ssize_t pm8001_ctl_ob_queue_log_show(struct device *cdev,
351 struct device_attribute *attr, char *buf)
353 struct Scsi_Host *shost = class_to_shost(cdev);
354 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
355 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
359 #define OB_MEMMAP(c) \
360 (*(u32 *)((u8 *)pm8001_ha-> \
361 memoryMap.region[OB].virt_ptr + \
362 pm8001_ha->evtlog_ob_offset + (c)))
364 for (offset = 0; offset < IB_OB_READ_TIMES; offset++) {
365 str += sprintf(str, "0x%08x\n", OB_MEMMAP(start));
368 pm8001_ha->evtlog_ob_offset += SYSFS_OFFSET;
369 if (((pm8001_ha->evtlog_ob_offset) % (PM80XX_IB_OB_QUEUE_SIZE)) == 0)
370 pm8001_ha->evtlog_ob_offset = 0;
374 static DEVICE_ATTR(ob_log, S_IRUGO, pm8001_ctl_ob_queue_log_show, NULL);
376 * pm8001_ctl_bios_version_show - Bios version Display
377 * @cdev:pointer to embedded class device
378 * @buf:the buffer returned
379 * A sysfs 'read-only' shost attribute.
381 static ssize_t pm8001_ctl_bios_version_show(struct device *cdev,
382 struct device_attribute *attr, char *buf)
384 struct Scsi_Host *shost = class_to_shost(cdev);
385 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
386 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
390 DECLARE_COMPLETION_ONSTACK(completion);
391 struct pm8001_ioctl_payload payload;
393 pm8001_ha->nvmd_completion = &completion;
394 payload.minor_function = 7;
396 payload.length = 4096;
397 payload.func_specific = kzalloc(4096, GFP_KERNEL);
398 if (!payload.func_specific)
400 if (PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload)) {
401 kfree(payload.func_specific);
404 wait_for_completion(&completion);
405 virt_addr = pm8001_ha->memoryMap.region[NVMD].virt_ptr;
406 for (bios_index = BIOSOFFSET; bios_index < BIOS_OFFSET_LIMIT;
408 str += sprintf(str, "%c",
409 *((u8 *)((u8 *)virt_addr+bios_index)));
410 kfree(payload.func_specific);
413 static DEVICE_ATTR(bios_version, S_IRUGO, pm8001_ctl_bios_version_show, NULL);
415 * pm8001_ctl_aap_log_show - IOP event log
416 * @cdev: pointer to embedded class device
417 * @buf: the buffer returned
419 * A sysfs 'read-only' shost attribute.
421 static ssize_t pm8001_ctl_iop_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;
427 #define IOP_MEMMAP(r, c) \
428 (*(u32 *)((u8*)pm8001_ha->memoryMap.region[IOP].virt_ptr + (r) * 32 \
433 for (i = 0; i < max; i++) {
434 str += sprintf(str, "0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x"
448 static DEVICE_ATTR(iop_log, S_IRUGO, pm8001_ctl_iop_log_show, NULL);
451 ** pm8001_ctl_fatal_log_show - fatal error logging
452 ** @cdev:pointer to embedded class device
453 ** @buf: the buffer returned
455 ** A sysfs 'read-only' shost attribute.
458 static ssize_t pm8001_ctl_fatal_log_show(struct device *cdev,
459 struct device_attribute *attr, char *buf)
463 count = pm80xx_get_fatal_dump(cdev, attr, buf);
467 static DEVICE_ATTR(fatal_log, S_IRUGO, pm8001_ctl_fatal_log_show, NULL);
471 ** pm8001_ctl_gsm_log_show - gsm dump collection
472 ** @cdev:pointer to embedded class device
473 ** @buf: the buffer returned
474 **A sysfs 'read-only' shost attribute.
476 static ssize_t pm8001_ctl_gsm_log_show(struct device *cdev,
477 struct device_attribute *attr, char *buf)
481 count = pm8001_get_gsm_dump(cdev, SYSFS_OFFSET, buf);
485 static DEVICE_ATTR(gsm_log, S_IRUGO, pm8001_ctl_gsm_log_show, NULL);
487 #define FLASH_CMD_NONE 0x00
488 #define FLASH_CMD_UPDATE 0x01
489 #define FLASH_CMD_SET_NVMD 0x02
491 struct flash_command {
496 static struct flash_command flash_command_table[] =
498 {"set_nvmd", FLASH_CMD_SET_NVMD},
499 {"update", FLASH_CMD_UPDATE},
500 {"", FLASH_CMD_NONE} /* Last entry should be NULL. */
508 static struct error_fw flash_error_table[] =
510 {"Failed to open fw image file", FAIL_OPEN_BIOS_FILE},
511 {"image header mismatch", FLASH_UPDATE_HDR_ERR},
512 {"image offset mismatch", FLASH_UPDATE_OFFSET_ERR},
513 {"image CRC Error", FLASH_UPDATE_CRC_ERR},
514 {"image length Error.", FLASH_UPDATE_LENGTH_ERR},
515 {"Failed to program flash chip", FLASH_UPDATE_HW_ERR},
516 {"Flash chip not supported.", FLASH_UPDATE_DNLD_NOT_SUPPORTED},
517 {"Flash update disabled.", FLASH_UPDATE_DISABLED},
518 {"Flash in progress", FLASH_IN_PROGRESS},
519 {"Image file size Error", FAIL_FILE_SIZE},
520 {"Input parameter error", FAIL_PARAMETERS},
521 {"Out of memory", FAIL_OUT_MEMORY},
522 {"OK", 0} /* Last entry err_code = 0. */
525 static int pm8001_set_nvmd(struct pm8001_hba_info *pm8001_ha)
527 struct pm8001_ioctl_payload *payload;
528 DECLARE_COMPLETION_ONSTACK(completion);
529 u8 *ioctlbuffer = NULL;
533 length = 1024 * 5 + sizeof(*payload) - 1;
534 ioctlbuffer = kzalloc(length, GFP_KERNEL);
537 if ((pm8001_ha->fw_image->size <= 0) ||
538 (pm8001_ha->fw_image->size > 4096)) {
539 ret = FAIL_FILE_SIZE;
542 payload = (struct pm8001_ioctl_payload *)ioctlbuffer;
543 memcpy((u8 *)&payload->func_specific, (u8 *)pm8001_ha->fw_image->data,
544 pm8001_ha->fw_image->size);
545 payload->length = pm8001_ha->fw_image->size;
547 payload->minor_function = 0x1;
548 pm8001_ha->nvmd_completion = &completion;
549 ret = PM8001_CHIP_DISP->set_nvmd_req(pm8001_ha, payload);
550 wait_for_completion(&completion);
556 static int pm8001_update_flash(struct pm8001_hba_info *pm8001_ha)
558 struct pm8001_ioctl_payload *payload;
559 DECLARE_COMPLETION_ONSTACK(completion);
560 u8 *ioctlbuffer = NULL;
562 struct fw_control_info *fwControl;
563 u32 loopNumber, loopcount = 0;
565 u32 partitionSize, partitionSizeTmp;
567 u32 partitionNumber = 0;
568 struct pm8001_fw_image_header *image_hdr;
570 length = 1024 * 16 + sizeof(*payload) - 1;
571 ioctlbuffer = kzalloc(length, GFP_KERNEL);
572 image_hdr = (struct pm8001_fw_image_header *)pm8001_ha->fw_image->data;
575 if (pm8001_ha->fw_image->size < 28) {
576 ret = FAIL_FILE_SIZE;
580 while (sizeRead < pm8001_ha->fw_image->size) {
582 *(u32 *)((u8 *)&image_hdr->image_length + sizeRead);
583 partitionSize = be32_to_cpu(partitionSizeTmp);
584 loopcount = (partitionSize + HEADER_LEN)/IOCTL_BUF_SIZE;
585 if (loopcount % IOCTL_BUF_SIZE)
589 for (loopNumber = 0; loopNumber < loopcount; loopNumber++) {
590 payload = (struct pm8001_ioctl_payload *)ioctlbuffer;
591 payload->length = 1024*16;
594 (struct fw_control_info *)&payload->func_specific;
595 fwControl->len = IOCTL_BUF_SIZE; /* IN */
596 fwControl->size = partitionSize + HEADER_LEN;/* IN */
597 fwControl->retcode = 0;/* OUT */
598 fwControl->offset = loopNumber * IOCTL_BUF_SIZE;/*OUT */
600 /* for the last chunk of data in case file size is not even with
601 4k, load only the rest*/
602 if (((loopcount-loopNumber) == 1) &&
603 ((partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE)) {
605 (partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE;
606 memcpy((u8 *)fwControl->buffer,
607 (u8 *)pm8001_ha->fw_image->data + sizeRead,
608 (partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE);
610 (partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE;
612 memcpy((u8 *)fwControl->buffer,
613 (u8 *)pm8001_ha->fw_image->data + sizeRead,
615 sizeRead += IOCTL_BUF_SIZE;
618 pm8001_ha->nvmd_completion = &completion;
619 ret = PM8001_CHIP_DISP->fw_flash_update_req(pm8001_ha, payload);
622 wait_for_completion(&completion);
623 if (fwControl->retcode > FLASH_UPDATE_IN_PROGRESS) {
624 ret = fwControl->retcode;
636 static ssize_t pm8001_store_update_fw(struct device *cdev,
637 struct device_attribute *attr,
638 const char *buf, size_t count)
640 struct Scsi_Host *shost = class_to_shost(cdev);
641 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
642 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
643 char *cmd_ptr, *filename_ptr;
645 int flash_command = FLASH_CMD_NONE;
647 if (!capable(CAP_SYS_ADMIN))
650 cmd_ptr = kzalloc(count*2, GFP_KERNEL);
653 err = FAIL_OUT_MEMORY;
657 filename_ptr = cmd_ptr + count;
658 res = sscanf(buf, "%s %s", cmd_ptr, filename_ptr);
660 err = FAIL_PARAMETERS;
664 for (i = 0; flash_command_table[i].code != FLASH_CMD_NONE; i++) {
665 if (!memcmp(flash_command_table[i].command,
666 cmd_ptr, strlen(cmd_ptr))) {
667 flash_command = flash_command_table[i].code;
671 if (flash_command == FLASH_CMD_NONE) {
672 err = FAIL_PARAMETERS;
676 if (pm8001_ha->fw_status == FLASH_IN_PROGRESS) {
677 err = FLASH_IN_PROGRESS;
680 err = request_firmware(&pm8001_ha->fw_image,
685 PM8001_FAIL_DBG(pm8001_ha,
686 pm8001_printk("Failed to load firmware image file %s,"
687 " error %d\n", filename_ptr, err));
688 err = FAIL_OPEN_BIOS_FILE;
692 switch (flash_command) {
693 case FLASH_CMD_UPDATE:
694 pm8001_ha->fw_status = FLASH_IN_PROGRESS;
695 err = pm8001_update_flash(pm8001_ha);
697 case FLASH_CMD_SET_NVMD:
698 pm8001_ha->fw_status = FLASH_IN_PROGRESS;
699 err = pm8001_set_nvmd(pm8001_ha);
702 pm8001_ha->fw_status = FAIL_PARAMETERS;
703 err = FAIL_PARAMETERS;
706 release_firmware(pm8001_ha->fw_image);
710 pm8001_ha->fw_status = err;
718 static ssize_t pm8001_show_update_fw(struct device *cdev,
719 struct device_attribute *attr, char *buf)
722 struct Scsi_Host *shost = class_to_shost(cdev);
723 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
724 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
726 for (i = 0; flash_error_table[i].err_code != 0; i++) {
727 if (flash_error_table[i].err_code == pm8001_ha->fw_status)
730 if (pm8001_ha->fw_status != FLASH_IN_PROGRESS)
731 pm8001_ha->fw_status = FLASH_OK;
733 return snprintf(buf, PAGE_SIZE, "status=%x %s\n",
734 flash_error_table[i].err_code,
735 flash_error_table[i].reason);
738 static DEVICE_ATTR(update_fw, S_IRUGO|S_IWUSR|S_IWGRP,
739 pm8001_show_update_fw, pm8001_store_update_fw);
740 struct device_attribute *pm8001_host_attrs[] = {
741 &dev_attr_interface_rev,
742 &dev_attr_fw_version,
748 &dev_attr_max_out_io,
749 &dev_attr_max_devices,
750 &dev_attr_max_sg_list,
751 &dev_attr_sas_spec_support,
752 &dev_attr_logging_level,
753 &dev_attr_host_sas_address,
754 &dev_attr_bios_version,