2 * PMC-Sierra SPC 8001 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 return snprintf(buf
, PAGE_SIZE
, "%d\n",
62 pm8001_ha
->main_cfg_tbl
.interface_rev
);
65 DEVICE_ATTR(interface_rev
, S_IRUGO
, pm8001_ctl_mpi_interface_rev_show
, NULL
);
68 * pm8001_ctl_fw_version_show - firmware version
69 * @cdev: pointer to embedded class device
70 * @buf: the buffer returned
72 * A sysfs 'read-only' shost attribute.
74 static ssize_t
pm8001_ctl_fw_version_show(struct device
*cdev
,
75 struct device_attribute
*attr
, char *buf
)
77 struct Scsi_Host
*shost
= class_to_shost(cdev
);
78 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
79 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
81 return snprintf(buf
, PAGE_SIZE
, "%02x.%02x.%02x.%02x\n",
82 (u8
)(pm8001_ha
->main_cfg_tbl
.firmware_rev
>> 24),
83 (u8
)(pm8001_ha
->main_cfg_tbl
.firmware_rev
>> 16),
84 (u8
)(pm8001_ha
->main_cfg_tbl
.firmware_rev
>> 8),
85 (u8
)(pm8001_ha
->main_cfg_tbl
.firmware_rev
));
87 static DEVICE_ATTR(fw_version
, S_IRUGO
, pm8001_ctl_fw_version_show
, NULL
);
89 * pm8001_ctl_max_out_io_show - max outstanding io supported
90 * @cdev: pointer to embedded class device
91 * @buf: the buffer returned
93 * A sysfs 'read-only' shost attribute.
95 static ssize_t
pm8001_ctl_max_out_io_show(struct device
*cdev
,
96 struct device_attribute
*attr
, char *buf
)
98 struct Scsi_Host
*shost
= class_to_shost(cdev
);
99 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
100 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
102 return snprintf(buf
, PAGE_SIZE
, "%d\n",
103 pm8001_ha
->main_cfg_tbl
.max_out_io
);
105 static DEVICE_ATTR(max_out_io
, S_IRUGO
, pm8001_ctl_max_out_io_show
, NULL
);
107 * pm8001_ctl_max_devices_show - max devices support
108 * @cdev: pointer to embedded class device
109 * @buf: the buffer returned
111 * A sysfs 'read-only' shost attribute.
113 static ssize_t
pm8001_ctl_max_devices_show(struct device
*cdev
,
114 struct device_attribute
*attr
, char *buf
)
116 struct Scsi_Host
*shost
= class_to_shost(cdev
);
117 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
118 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
120 return snprintf(buf
, PAGE_SIZE
, "%04d\n",
121 (u16
)(pm8001_ha
->main_cfg_tbl
.max_sgl
>> 16));
123 static DEVICE_ATTR(max_devices
, S_IRUGO
, pm8001_ctl_max_devices_show
, NULL
);
125 * pm8001_ctl_max_sg_list_show - max sg list supported iff not 0.0 for no
126 * hardware limitation
127 * @cdev: pointer to embedded class device
128 * @buf: the buffer returned
130 * A sysfs 'read-only' shost attribute.
132 static ssize_t
pm8001_ctl_max_sg_list_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 return snprintf(buf
, PAGE_SIZE
, "%04d\n",
140 pm8001_ha
->main_cfg_tbl
.max_sgl
& 0x0000FFFF);
142 static DEVICE_ATTR(max_sg_list
, S_IRUGO
, pm8001_ctl_max_sg_list_show
, NULL
);
149 show_sas_spec_support_status(unsigned int mode
, char *buf
)
154 len
= sprintf(buf
, "%s", "SAS1.1");
156 len
+= sprintf(buf
+ len
, "%s%s", len
? ", " : "", "SAS2.0");
157 len
+= sprintf(buf
+ len
, "\n");
163 * pm8001_ctl_sas_spec_support_show - sas spec supported
164 * @cdev: pointer to embedded class device
165 * @buf: the buffer returned
167 * A sysfs 'read-only' shost attribute.
169 static ssize_t
pm8001_ctl_sas_spec_support_show(struct device
*cdev
,
170 struct device_attribute
*attr
, char *buf
)
173 struct Scsi_Host
*shost
= class_to_shost(cdev
);
174 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
175 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
176 mode
= (pm8001_ha
->main_cfg_tbl
.ctrl_cap_flag
& 0xfe000000)>>25;
177 return show_sas_spec_support_status(mode
, buf
);
179 static DEVICE_ATTR(sas_spec_support
, S_IRUGO
,
180 pm8001_ctl_sas_spec_support_show
, NULL
);
183 * pm8001_ctl_sas_address_show - sas address
184 * @cdev: pointer to embedded class device
185 * @buf: the buffer returned
187 * This is the controller sas address
189 * A sysfs 'read-only' shost attribute.
191 static ssize_t
pm8001_ctl_host_sas_address_show(struct device
*cdev
,
192 struct device_attribute
*attr
, char *buf
)
194 struct Scsi_Host
*shost
= class_to_shost(cdev
);
195 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
196 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
197 return snprintf(buf
, PAGE_SIZE
, "0x%016llx\n",
198 be64_to_cpu(*(__be64
*)pm8001_ha
->sas_addr
));
200 static DEVICE_ATTR(host_sas_address
, S_IRUGO
,
201 pm8001_ctl_host_sas_address_show
, NULL
);
204 * pm8001_ctl_logging_level_show - logging level
205 * @cdev: pointer to embedded class device
206 * @buf: the buffer returned
208 * A sysfs 'read/write' shost attribute.
210 static ssize_t
pm8001_ctl_logging_level_show(struct device
*cdev
,
211 struct device_attribute
*attr
, char *buf
)
213 struct Scsi_Host
*shost
= class_to_shost(cdev
);
214 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
215 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
217 return snprintf(buf
, PAGE_SIZE
, "%08xh\n", pm8001_ha
->logging_level
);
219 static ssize_t
pm8001_ctl_logging_level_store(struct device
*cdev
,
220 struct device_attribute
*attr
, const char *buf
, size_t count
)
222 struct Scsi_Host
*shost
= class_to_shost(cdev
);
223 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
224 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
227 if (sscanf(buf
, "%x", &val
) != 1)
230 pm8001_ha
->logging_level
= val
;
234 static DEVICE_ATTR(logging_level
, S_IRUGO
| S_IWUSR
,
235 pm8001_ctl_logging_level_show
, pm8001_ctl_logging_level_store
);
237 * pm8001_ctl_aap_log_show - aap1 event log
238 * @cdev: pointer to embedded class device
239 * @buf: the buffer returned
241 * A sysfs 'read-only' shost attribute.
243 static ssize_t
pm8001_ctl_aap_log_show(struct device
*cdev
,
244 struct device_attribute
*attr
, char *buf
)
246 struct Scsi_Host
*shost
= class_to_shost(cdev
);
247 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
248 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
250 #define AAP1_MEMMAP(r, c) \
251 (*(u32 *)((u8*)pm8001_ha->memoryMap.region[AAP1].virt_ptr + (r) * 32 \
256 for (i
= 0; i
< max
; i
++) {
257 str
+= sprintf(str
, "0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x"
271 static DEVICE_ATTR(aap_log
, S_IRUGO
, pm8001_ctl_aap_log_show
, NULL
);
273 * pm8001_ctl_aap_log_show - IOP event log
274 * @cdev: pointer to embedded class device
275 * @buf: the buffer returned
277 * A sysfs 'read-only' shost attribute.
279 static ssize_t
pm8001_ctl_iop_log_show(struct device
*cdev
,
280 struct device_attribute
*attr
, char *buf
)
282 struct Scsi_Host
*shost
= class_to_shost(cdev
);
283 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
284 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
285 #define IOP_MEMMAP(r, c) \
286 (*(u32 *)((u8*)pm8001_ha->memoryMap.region[IOP].virt_ptr + (r) * 32 \
291 for (i
= 0; i
< max
; i
++) {
292 str
+= sprintf(str
, "0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x"
306 static DEVICE_ATTR(iop_log
, S_IRUGO
, pm8001_ctl_iop_log_show
, NULL
);
308 #define FLASH_CMD_NONE 0x00
309 #define FLASH_CMD_UPDATE 0x01
310 #define FLASH_CMD_SET_NVMD 0x02
312 struct flash_command
{
317 static struct flash_command flash_command_table
[] =
319 {"set_nvmd", FLASH_CMD_SET_NVMD
},
320 {"update", FLASH_CMD_UPDATE
},
321 {"", FLASH_CMD_NONE
} /* Last entry should be NULL. */
329 static struct error_fw flash_error_table
[] =
331 {"Failed to open fw image file", FAIL_OPEN_BIOS_FILE
},
332 {"image header mismatch", FLASH_UPDATE_HDR_ERR
},
333 {"image offset mismatch", FLASH_UPDATE_OFFSET_ERR
},
334 {"image CRC Error", FLASH_UPDATE_CRC_ERR
},
335 {"image length Error.", FLASH_UPDATE_LENGTH_ERR
},
336 {"Failed to program flash chip", FLASH_UPDATE_HW_ERR
},
337 {"Flash chip not supported.", FLASH_UPDATE_DNLD_NOT_SUPPORTED
},
338 {"Flash update disabled.", FLASH_UPDATE_DISABLED
},
339 {"Flash in progress", FLASH_IN_PROGRESS
},
340 {"Image file size Error", FAIL_FILE_SIZE
},
341 {"Input parameter error", FAIL_PARAMETERS
},
342 {"Out of memory", FAIL_OUT_MEMORY
},
343 {"OK", 0} /* Last entry err_code = 0. */
346 static int pm8001_set_nvmd(struct pm8001_hba_info
*pm8001_ha
)
348 struct pm8001_ioctl_payload
*payload
;
349 DECLARE_COMPLETION_ONSTACK(completion
);
350 u8
*ioctlbuffer
= NULL
;
354 length
= 1024 * 5 + sizeof(*payload
) - 1;
355 ioctlbuffer
= kzalloc(length
, GFP_KERNEL
);
358 if ((pm8001_ha
->fw_image
->size
<= 0) ||
359 (pm8001_ha
->fw_image
->size
> 4096)) {
360 ret
= FAIL_FILE_SIZE
;
363 payload
= (struct pm8001_ioctl_payload
*)ioctlbuffer
;
364 memcpy((u8
*)payload
->func_specific
, (u8
*)pm8001_ha
->fw_image
->data
,
365 pm8001_ha
->fw_image
->size
);
366 payload
->length
= pm8001_ha
->fw_image
->size
;
368 pm8001_ha
->nvmd_completion
= &completion
;
369 ret
= PM8001_CHIP_DISP
->set_nvmd_req(pm8001_ha
, payload
);
370 wait_for_completion(&completion
);
376 static int pm8001_update_flash(struct pm8001_hba_info
*pm8001_ha
)
378 struct pm8001_ioctl_payload
*payload
;
379 DECLARE_COMPLETION_ONSTACK(completion
);
380 u8
*ioctlbuffer
= NULL
;
382 struct fw_control_info
*fwControl
;
383 u32 loopNumber
, loopcount
= 0;
385 u32 partitionSize
, partitionSizeTmp
;
387 u32 partitionNumber
= 0;
388 struct pm8001_fw_image_header
*image_hdr
;
390 length
= 1024 * 16 + sizeof(*payload
) - 1;
391 ioctlbuffer
= kzalloc(length
, GFP_KERNEL
);
392 image_hdr
= (struct pm8001_fw_image_header
*)pm8001_ha
->fw_image
->data
;
395 if (pm8001_ha
->fw_image
->size
< 28) {
396 ret
= FAIL_FILE_SIZE
;
400 while (sizeRead
< pm8001_ha
->fw_image
->size
) {
402 *(u32
*)((u8
*)&image_hdr
->image_length
+ sizeRead
);
403 partitionSize
= be32_to_cpu(partitionSizeTmp
);
404 loopcount
= (partitionSize
+ HEADER_LEN
)/IOCTL_BUF_SIZE
;
405 if (loopcount
% IOCTL_BUF_SIZE
)
409 for (loopNumber
= 0; loopNumber
< loopcount
; loopNumber
++) {
410 payload
= (struct pm8001_ioctl_payload
*)ioctlbuffer
;
411 payload
->length
= 1024*16;
414 (struct fw_control_info
*)payload
->func_specific
;
415 fwControl
->len
= IOCTL_BUF_SIZE
; /* IN */
416 fwControl
->size
= partitionSize
+ HEADER_LEN
;/* IN */
417 fwControl
->retcode
= 0;/* OUT */
418 fwControl
->offset
= loopNumber
* IOCTL_BUF_SIZE
;/*OUT */
420 /* for the last chunk of data in case file size is not even with
421 4k, load only the rest*/
422 if (((loopcount
-loopNumber
) == 1) &&
423 ((partitionSize
+ HEADER_LEN
) % IOCTL_BUF_SIZE
)) {
425 (partitionSize
+ HEADER_LEN
) % IOCTL_BUF_SIZE
;
426 memcpy((u8
*)fwControl
->buffer
,
427 (u8
*)pm8001_ha
->fw_image
->data
+ sizeRead
,
428 (partitionSize
+ HEADER_LEN
) % IOCTL_BUF_SIZE
);
430 (partitionSize
+ HEADER_LEN
) % IOCTL_BUF_SIZE
;
432 memcpy((u8
*)fwControl
->buffer
,
433 (u8
*)pm8001_ha
->fw_image
->data
+ sizeRead
,
435 sizeRead
+= IOCTL_BUF_SIZE
;
438 pm8001_ha
->nvmd_completion
= &completion
;
439 ret
= PM8001_CHIP_DISP
->fw_flash_update_req(pm8001_ha
, payload
);
440 wait_for_completion(&completion
);
441 if (ret
|| (fwControl
->retcode
> FLASH_UPDATE_IN_PROGRESS
)) {
442 ret
= fwControl
->retcode
;
456 static ssize_t
pm8001_store_update_fw(struct device
*cdev
,
457 struct device_attribute
*attr
,
458 const char *buf
, size_t count
)
460 struct Scsi_Host
*shost
= class_to_shost(cdev
);
461 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
462 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
463 char *cmd_ptr
, *filename_ptr
;
465 int flash_command
= FLASH_CMD_NONE
;
467 if (!capable(CAP_SYS_ADMIN
))
470 cmd_ptr
= kzalloc(count
*2, GFP_KERNEL
);
473 err
= FAIL_OUT_MEMORY
;
477 filename_ptr
= cmd_ptr
+ count
;
478 res
= sscanf(buf
, "%s %s", cmd_ptr
, filename_ptr
);
480 err
= FAIL_PARAMETERS
;
484 for (i
= 0; flash_command_table
[i
].code
!= FLASH_CMD_NONE
; i
++) {
485 if (!memcmp(flash_command_table
[i
].command
,
486 cmd_ptr
, strlen(cmd_ptr
))) {
487 flash_command
= flash_command_table
[i
].code
;
491 if (flash_command
== FLASH_CMD_NONE
) {
492 err
= FAIL_PARAMETERS
;
496 if (pm8001_ha
->fw_status
== FLASH_IN_PROGRESS
) {
497 err
= FLASH_IN_PROGRESS
;
500 err
= request_firmware(&pm8001_ha
->fw_image
,
505 PM8001_FAIL_DBG(pm8001_ha
,
506 pm8001_printk("Failed to load firmware image file %s,"
507 " error %d\n", filename_ptr
, err
));
508 err
= FAIL_OPEN_BIOS_FILE
;
512 switch (flash_command
) {
513 case FLASH_CMD_UPDATE
:
514 pm8001_ha
->fw_status
= FLASH_IN_PROGRESS
;
515 err
= pm8001_update_flash(pm8001_ha
);
517 case FLASH_CMD_SET_NVMD
:
518 pm8001_ha
->fw_status
= FLASH_IN_PROGRESS
;
519 err
= pm8001_set_nvmd(pm8001_ha
);
522 pm8001_ha
->fw_status
= FAIL_PARAMETERS
;
523 err
= FAIL_PARAMETERS
;
526 release_firmware(pm8001_ha
->fw_image
);
530 pm8001_ha
->fw_status
= err
;
538 static ssize_t
pm8001_show_update_fw(struct device
*cdev
,
539 struct device_attribute
*attr
, char *buf
)
542 struct Scsi_Host
*shost
= class_to_shost(cdev
);
543 struct sas_ha_struct
*sha
= SHOST_TO_SAS_HA(shost
);
544 struct pm8001_hba_info
*pm8001_ha
= sha
->lldd_ha
;
546 for (i
= 0; flash_error_table
[i
].err_code
!= 0; i
++) {
547 if (flash_error_table
[i
].err_code
== pm8001_ha
->fw_status
)
550 if (pm8001_ha
->fw_status
!= FLASH_IN_PROGRESS
)
551 pm8001_ha
->fw_status
= FLASH_OK
;
553 return snprintf(buf
, PAGE_SIZE
, "status=%x %s\n",
554 flash_error_table
[i
].err_code
,
555 flash_error_table
[i
].reason
);
558 static DEVICE_ATTR(update_fw
, S_IRUGO
|S_IWUGO
,
559 pm8001_show_update_fw
, pm8001_store_update_fw
);
560 struct device_attribute
*pm8001_host_attrs
[] = {
561 &dev_attr_interface_rev
,
562 &dev_attr_fw_version
,
566 &dev_attr_max_out_io
,
567 &dev_attr_max_devices
,
568 &dev_attr_max_sg_list
,
569 &dev_attr_sas_spec_support
,
570 &dev_attr_logging_level
,
571 &dev_attr_host_sas_address
,