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"
44 #include "pm8001_chips.h"
46 /* scsi host attributes */
49 * pm8001_ctl_mpi_interface_rev_show - MPI interface revision number
50 * @cdev: pointer to embedded class device
51 * @attr: device attribute (unused)
52 * @buf: the buffer returned
54 * A sysfs 'read-only' shost attribute.
56 static ssize_t pm8001_ctl_mpi_interface_rev_show(struct device *cdev,
57 struct device_attribute *attr, char *buf)
59 struct Scsi_Host *shost = class_to_shost(cdev);
60 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
61 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
63 if (pm8001_ha->chip_id == chip_8001) {
64 return snprintf(buf, PAGE_SIZE, "%d\n",
65 pm8001_ha->main_cfg_tbl.pm8001_tbl.interface_rev);
67 return snprintf(buf, PAGE_SIZE, "%d\n",
68 pm8001_ha->main_cfg_tbl.pm80xx_tbl.interface_rev);
72 DEVICE_ATTR(interface_rev, S_IRUGO, pm8001_ctl_mpi_interface_rev_show, NULL);
75 * controller_fatal_error_show - check controller is under fatal err
76 * @cdev: pointer to embedded class device
77 * @attr: device attribute (unused)
78 * @buf: the buffer returned
80 * A sysfs 'read only' shost attribute.
82 static ssize_t controller_fatal_error_show(struct device *cdev,
83 struct device_attribute *attr, char *buf)
85 struct Scsi_Host *shost = class_to_shost(cdev);
86 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
87 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
89 return snprintf(buf, PAGE_SIZE, "%d\n",
90 pm8001_ha->controller_fatal_error);
92 static DEVICE_ATTR_RO(controller_fatal_error);
95 * pm8001_ctl_fw_version_show - firmware version
96 * @cdev: pointer to embedded class device
97 * @attr: device attribute (unused)
98 * @buf: the buffer returned
100 * A sysfs 'read-only' shost attribute.
102 static ssize_t pm8001_ctl_fw_version_show(struct device *cdev,
103 struct device_attribute *attr, char *buf)
105 struct Scsi_Host *shost = class_to_shost(cdev);
106 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
107 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
109 if (pm8001_ha->chip_id == chip_8001) {
110 return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x.%02x\n",
111 (u8)(pm8001_ha->main_cfg_tbl.pm8001_tbl.firmware_rev >> 24),
112 (u8)(pm8001_ha->main_cfg_tbl.pm8001_tbl.firmware_rev >> 16),
113 (u8)(pm8001_ha->main_cfg_tbl.pm8001_tbl.firmware_rev >> 8),
114 (u8)(pm8001_ha->main_cfg_tbl.pm8001_tbl.firmware_rev));
116 return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x.%02x\n",
117 (u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.firmware_rev >> 24),
118 (u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.firmware_rev >> 16),
119 (u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.firmware_rev >> 8),
120 (u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.firmware_rev));
123 static DEVICE_ATTR(fw_version, S_IRUGO, pm8001_ctl_fw_version_show, NULL);
126 * pm8001_ctl_ila_version_show - ila version
127 * @cdev: pointer to embedded class device
128 * @attr: device attribute (unused)
129 * @buf: the buffer returned
131 * A sysfs 'read-only' shost attribute.
133 static ssize_t pm8001_ctl_ila_version_show(struct device *cdev,
134 struct device_attribute *attr, char *buf)
136 struct Scsi_Host *shost = class_to_shost(cdev);
137 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
138 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
140 if (pm8001_ha->chip_id != chip_8001) {
141 return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x.%02x\n",
142 (u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.ila_version >> 24),
143 (u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.ila_version >> 16),
144 (u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.ila_version >> 8),
145 (u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.ila_version));
149 static DEVICE_ATTR(ila_version, 0444, pm8001_ctl_ila_version_show, NULL);
152 * pm8001_ctl_inactive_fw_version_show - Inacative firmware version number
153 * @cdev: pointer to embedded class device
154 * @attr: device attribute (unused)
155 * @buf: the buffer returned
157 * A sysfs 'read-only' shost attribute.
159 static ssize_t pm8001_ctl_inactive_fw_version_show(struct device *cdev,
160 struct device_attribute *attr, char *buf)
162 struct Scsi_Host *shost = class_to_shost(cdev);
163 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
164 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
166 if (pm8001_ha->chip_id != chip_8001) {
167 return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x.%02x\n",
168 (u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.inc_fw_version >> 24),
169 (u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.inc_fw_version >> 16),
170 (u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.inc_fw_version >> 8),
171 (u8)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.inc_fw_version));
176 DEVICE_ATTR(inc_fw_ver, 0444, pm8001_ctl_inactive_fw_version_show, NULL);
179 * pm8001_ctl_max_out_io_show - max outstanding io supported
180 * @cdev: pointer to embedded class device
181 * @attr: device attribute (unused)
182 * @buf: the buffer returned
184 * A sysfs 'read-only' shost attribute.
186 static ssize_t pm8001_ctl_max_out_io_show(struct device *cdev,
187 struct device_attribute *attr, char *buf)
189 struct Scsi_Host *shost = class_to_shost(cdev);
190 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
191 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
193 if (pm8001_ha->chip_id == chip_8001) {
194 return snprintf(buf, PAGE_SIZE, "%d\n",
195 pm8001_ha->main_cfg_tbl.pm8001_tbl.max_out_io);
197 return snprintf(buf, PAGE_SIZE, "%d\n",
198 pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_out_io);
201 static DEVICE_ATTR(max_out_io, S_IRUGO, pm8001_ctl_max_out_io_show, NULL);
203 * pm8001_ctl_max_devices_show - max devices support
204 * @cdev: pointer to embedded class device
205 * @attr: device attribute (unused)
206 * @buf: the buffer returned
208 * A sysfs 'read-only' shost attribute.
210 static ssize_t pm8001_ctl_max_devices_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 if (pm8001_ha->chip_id == chip_8001) {
218 return snprintf(buf, PAGE_SIZE, "%04d\n",
219 (u16)(pm8001_ha->main_cfg_tbl.pm8001_tbl.max_sgl >> 16)
222 return snprintf(buf, PAGE_SIZE, "%04d\n",
223 (u16)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_sgl >> 16)
227 static DEVICE_ATTR(max_devices, S_IRUGO, pm8001_ctl_max_devices_show, NULL);
229 * pm8001_ctl_max_sg_list_show - max sg list supported iff not 0.0 for no
230 * hardware limitation
231 * @cdev: pointer to embedded class device
232 * @attr: device attribute (unused)
233 * @buf: the buffer returned
235 * A sysfs 'read-only' shost attribute.
237 static ssize_t pm8001_ctl_max_sg_list_show(struct device *cdev,
238 struct device_attribute *attr, char *buf)
240 struct Scsi_Host *shost = class_to_shost(cdev);
241 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
242 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
244 if (pm8001_ha->chip_id == chip_8001) {
245 return snprintf(buf, PAGE_SIZE, "%04d\n",
246 pm8001_ha->main_cfg_tbl.pm8001_tbl.max_sgl & 0x0000FFFF
249 return snprintf(buf, PAGE_SIZE, "%04d\n",
250 pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_sgl & 0x0000FFFF
254 static DEVICE_ATTR(max_sg_list, S_IRUGO, pm8001_ctl_max_sg_list_show, NULL);
261 show_sas_spec_support_status(unsigned int mode, char *buf)
266 len = sprintf(buf, "%s", "SAS1.1");
268 len += sprintf(buf + len, "%s%s", len ? ", " : "", "SAS2.0");
269 len += sprintf(buf + len, "\n");
275 * pm8001_ctl_sas_spec_support_show - sas spec supported
276 * @cdev: pointer to embedded class device
277 * @attr: device attribute (unused)
278 * @buf: the buffer returned
280 * A sysfs 'read-only' shost attribute.
282 static ssize_t pm8001_ctl_sas_spec_support_show(struct device *cdev,
283 struct device_attribute *attr, char *buf)
286 struct Scsi_Host *shost = class_to_shost(cdev);
287 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
288 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
289 /* fe000000 means supports SAS2.1 */
290 if (pm8001_ha->chip_id == chip_8001)
291 mode = (pm8001_ha->main_cfg_tbl.pm8001_tbl.ctrl_cap_flag &
294 /* fe000000 means supports SAS2.1 */
295 mode = (pm8001_ha->main_cfg_tbl.pm80xx_tbl.ctrl_cap_flag &
297 return show_sas_spec_support_status(mode, buf);
299 static DEVICE_ATTR(sas_spec_support, S_IRUGO,
300 pm8001_ctl_sas_spec_support_show, NULL);
303 * pm8001_ctl_host_sas_address_show - sas address
304 * @cdev: pointer to embedded class device
305 * @attr: device attribute (unused)
306 * @buf: the buffer returned
308 * This is the controller sas address
310 * A sysfs 'read-only' shost attribute.
312 static ssize_t pm8001_ctl_host_sas_address_show(struct device *cdev,
313 struct device_attribute *attr, char *buf)
315 struct Scsi_Host *shost = class_to_shost(cdev);
316 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
317 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
318 return snprintf(buf, PAGE_SIZE, "0x%016llx\n",
319 be64_to_cpu(*(__be64 *)pm8001_ha->sas_addr));
321 static DEVICE_ATTR(host_sas_address, S_IRUGO,
322 pm8001_ctl_host_sas_address_show, NULL);
325 * pm8001_ctl_logging_level_show - logging level
326 * @cdev: pointer to embedded class device
327 * @attr: device attribute (unused)
328 * @buf: the buffer returned
330 * A sysfs 'read/write' shost attribute.
332 static ssize_t pm8001_ctl_logging_level_show(struct device *cdev,
333 struct device_attribute *attr, char *buf)
335 struct Scsi_Host *shost = class_to_shost(cdev);
336 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
337 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
339 return snprintf(buf, PAGE_SIZE, "%08xh\n", pm8001_ha->logging_level);
342 static ssize_t pm8001_ctl_logging_level_store(struct device *cdev,
343 struct device_attribute *attr, const char *buf, size_t count)
345 struct Scsi_Host *shost = class_to_shost(cdev);
346 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
347 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
350 if (sscanf(buf, "%x", &val) != 1)
353 pm8001_ha->logging_level = val;
357 static DEVICE_ATTR(logging_level, S_IRUGO | S_IWUSR,
358 pm8001_ctl_logging_level_show, pm8001_ctl_logging_level_store);
360 * pm8001_ctl_aap_log_show - aap1 event log
361 * @cdev: pointer to embedded class device
362 * @attr: device attribute (unused)
363 * @buf: the buffer returned
365 * A sysfs 'read-only' shost attribute.
367 static ssize_t pm8001_ctl_aap_log_show(struct device *cdev,
368 struct device_attribute *attr, char *buf)
370 struct Scsi_Host *shost = class_to_shost(cdev);
371 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
372 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
373 u8 *ptr = (u8 *)pm8001_ha->memoryMap.region[AAP1].virt_ptr;
378 for (i = 0; i < max; i++) {
379 str += sprintf(str, "0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x"
381 pm8001_ctl_aap1_memmap(ptr, i, 0),
382 pm8001_ctl_aap1_memmap(ptr, i, 4),
383 pm8001_ctl_aap1_memmap(ptr, i, 8),
384 pm8001_ctl_aap1_memmap(ptr, i, 12),
385 pm8001_ctl_aap1_memmap(ptr, i, 16),
386 pm8001_ctl_aap1_memmap(ptr, i, 20),
387 pm8001_ctl_aap1_memmap(ptr, i, 24),
388 pm8001_ctl_aap1_memmap(ptr, i, 28));
393 static DEVICE_ATTR(aap_log, S_IRUGO, pm8001_ctl_aap_log_show, NULL);
395 * pm8001_ctl_ib_queue_log_show - Out bound Queue log
396 * @cdev:pointer to embedded class device
397 * @attr: device attribute (unused)
398 * @buf: the buffer returned
399 * A sysfs 'read-only' shost attribute.
401 static ssize_t pm8001_ctl_ib_queue_log_show(struct device *cdev,
402 struct device_attribute *attr, char *buf)
404 struct Scsi_Host *shost = class_to_shost(cdev);
405 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
406 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
410 u32 ib_offset = pm8001_ha->ib_offset;
411 #define IB_MEMMAP(c) \
412 (*(u32 *)((u8 *)pm8001_ha-> \
413 memoryMap.region[ib_offset].virt_ptr + \
414 pm8001_ha->evtlog_ib_offset + (c)))
416 for (offset = 0; offset < IB_OB_READ_TIMES; offset++) {
417 str += sprintf(str, "0x%08x\n", IB_MEMMAP(start));
420 pm8001_ha->evtlog_ib_offset += SYSFS_OFFSET;
421 if (((pm8001_ha->evtlog_ib_offset) % (PM80XX_IB_OB_QUEUE_SIZE)) == 0)
422 pm8001_ha->evtlog_ib_offset = 0;
427 static DEVICE_ATTR(ib_log, S_IRUGO, pm8001_ctl_ib_queue_log_show, NULL);
429 * pm8001_ctl_ob_queue_log_show - Out bound Queue log
430 * @cdev:pointer to embedded class device
431 * @attr: device attribute (unused)
432 * @buf: the buffer returned
433 * A sysfs 'read-only' shost attribute.
436 static ssize_t pm8001_ctl_ob_queue_log_show(struct device *cdev,
437 struct device_attribute *attr, char *buf)
439 struct Scsi_Host *shost = class_to_shost(cdev);
440 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
441 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
445 u32 ob_offset = pm8001_ha->ob_offset;
446 #define OB_MEMMAP(c) \
447 (*(u32 *)((u8 *)pm8001_ha-> \
448 memoryMap.region[ob_offset].virt_ptr + \
449 pm8001_ha->evtlog_ob_offset + (c)))
451 for (offset = 0; offset < IB_OB_READ_TIMES; offset++) {
452 str += sprintf(str, "0x%08x\n", OB_MEMMAP(start));
455 pm8001_ha->evtlog_ob_offset += SYSFS_OFFSET;
456 if (((pm8001_ha->evtlog_ob_offset) % (PM80XX_IB_OB_QUEUE_SIZE)) == 0)
457 pm8001_ha->evtlog_ob_offset = 0;
461 static DEVICE_ATTR(ob_log, S_IRUGO, pm8001_ctl_ob_queue_log_show, NULL);
463 * pm8001_ctl_bios_version_show - Bios version Display
464 * @cdev:pointer to embedded class device
465 * @attr: device attribute (unused)
466 * @buf:the buffer returned
467 * A sysfs 'read-only' shost attribute.
469 static ssize_t pm8001_ctl_bios_version_show(struct device *cdev,
470 struct device_attribute *attr, char *buf)
472 struct Scsi_Host *shost = class_to_shost(cdev);
473 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
474 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
477 DECLARE_COMPLETION_ONSTACK(completion);
478 struct pm8001_ioctl_payload payload;
480 pm8001_ha->nvmd_completion = &completion;
481 payload.minor_function = 7;
483 payload.rd_length = 4096;
484 payload.func_specific = kzalloc(4096, GFP_KERNEL);
485 if (!payload.func_specific)
487 if (PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload)) {
488 kfree(payload.func_specific);
491 wait_for_completion(&completion);
492 for (bios_index = BIOSOFFSET; bios_index < BIOS_OFFSET_LIMIT;
494 str += sprintf(str, "%c",
495 *(payload.func_specific+bios_index));
496 kfree(payload.func_specific);
499 static DEVICE_ATTR(bios_version, S_IRUGO, pm8001_ctl_bios_version_show, NULL);
501 * event_log_size_show - event log size
502 * @cdev: pointer to embedded class device
503 * @attr: device attribute (unused)
504 * @buf: the buffer returned
506 * A sysfs read shost attribute.
508 static ssize_t event_log_size_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;
515 return snprintf(buf, PAGE_SIZE, "%d\n",
516 pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_size);
518 static DEVICE_ATTR_RO(event_log_size);
520 * pm8001_ctl_iop_log_show - IOP event log
521 * @cdev: pointer to embedded class device
522 * @attr: device attribute (unused)
523 * @buf: the buffer returned
525 * A sysfs 'read-only' shost attribute.
527 static ssize_t pm8001_ctl_iop_log_show(struct device *cdev,
528 struct device_attribute *attr, char *buf)
530 struct Scsi_Host *shost = class_to_shost(cdev);
531 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
532 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
535 pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_size / 1024;
536 static u32 start, end, count;
537 u32 max_read_times = 32;
538 u32 max_count = (read_size * 1024) / (max_read_times * 4);
539 u32 *temp = (u32 *)pm8001_ha->memoryMap.region[IOP].virt_ptr;
541 if ((count % max_count) == 0) {
543 end = max_read_times;
547 end = end + max_read_times;
550 for (; start < end; start++)
551 str += sprintf(str, "%08x ", *(temp+start));
555 static DEVICE_ATTR(iop_log, S_IRUGO, pm8001_ctl_iop_log_show, NULL);
558 ** pm8001_ctl_fatal_log_show - fatal error logging
559 ** @cdev:pointer to embedded class device
560 ** @attr: device attribute
561 ** @buf: the buffer returned
563 ** A sysfs 'read-only' shost attribute.
566 static ssize_t pm8001_ctl_fatal_log_show(struct device *cdev,
567 struct device_attribute *attr, char *buf)
571 count = pm80xx_get_fatal_dump(cdev, attr, buf);
575 static DEVICE_ATTR(fatal_log, S_IRUGO, pm8001_ctl_fatal_log_show, NULL);
578 ** non_fatal_log_show - non fatal error logging
579 ** @cdev:pointer to embedded class device
580 ** @attr: device attribute
581 ** @buf: the buffer returned
583 ** A sysfs 'read-only' shost attribute.
585 static ssize_t non_fatal_log_show(struct device *cdev,
586 struct device_attribute *attr, char *buf)
590 count = pm80xx_get_non_fatal_dump(cdev, attr, buf);
593 static DEVICE_ATTR_RO(non_fatal_log);
595 static ssize_t non_fatal_count_show(struct device *cdev,
596 struct device_attribute *attr, char *buf)
598 struct Scsi_Host *shost = class_to_shost(cdev);
599 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
600 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
602 return snprintf(buf, PAGE_SIZE, "%08x",
603 pm8001_ha->non_fatal_count);
606 static ssize_t non_fatal_count_store(struct device *cdev,
607 struct device_attribute *attr, const char *buf, size_t count)
609 struct Scsi_Host *shost = class_to_shost(cdev);
610 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
611 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
614 if (kstrtoint(buf, 16, &val) != 0)
617 pm8001_ha->non_fatal_count = val;
620 static DEVICE_ATTR_RW(non_fatal_count);
623 ** pm8001_ctl_gsm_log_show - gsm dump collection
624 ** @cdev:pointer to embedded class device
625 ** @attr: device attribute (unused)
626 ** @buf: the buffer returned
627 ** A sysfs 'read-only' shost attribute.
629 static ssize_t pm8001_ctl_gsm_log_show(struct device *cdev,
630 struct device_attribute *attr, char *buf)
634 count = pm8001_get_gsm_dump(cdev, SYSFS_OFFSET, buf);
638 static DEVICE_ATTR(gsm_log, S_IRUGO, pm8001_ctl_gsm_log_show, NULL);
640 #define FLASH_CMD_NONE 0x00
641 #define FLASH_CMD_UPDATE 0x01
642 #define FLASH_CMD_SET_NVMD 0x02
644 struct flash_command {
649 static const struct flash_command flash_command_table[] = {
650 {"set_nvmd", FLASH_CMD_SET_NVMD},
651 {"update", FLASH_CMD_UPDATE},
652 {"", FLASH_CMD_NONE} /* Last entry should be NULL. */
660 static const struct error_fw flash_error_table[] = {
661 {"Failed to open fw image file", FAIL_OPEN_BIOS_FILE},
662 {"image header mismatch", FLASH_UPDATE_HDR_ERR},
663 {"image offset mismatch", FLASH_UPDATE_OFFSET_ERR},
664 {"image CRC Error", FLASH_UPDATE_CRC_ERR},
665 {"image length Error.", FLASH_UPDATE_LENGTH_ERR},
666 {"Failed to program flash chip", FLASH_UPDATE_HW_ERR},
667 {"Flash chip not supported.", FLASH_UPDATE_DNLD_NOT_SUPPORTED},
668 {"Flash update disabled.", FLASH_UPDATE_DISABLED},
669 {"Flash in progress", FLASH_IN_PROGRESS},
670 {"Image file size Error", FAIL_FILE_SIZE},
671 {"Input parameter error", FAIL_PARAMETERS},
672 {"Out of memory", FAIL_OUT_MEMORY},
673 {"OK", 0} /* Last entry err_code = 0. */
676 static int pm8001_set_nvmd(struct pm8001_hba_info *pm8001_ha)
678 struct pm8001_ioctl_payload *payload;
679 DECLARE_COMPLETION_ONSTACK(completion);
682 u32 length = 1024 * 5 + sizeof(*payload) - 1;
684 if (pm8001_ha->fw_image->size > 4096) {
685 pm8001_ha->fw_status = FAIL_FILE_SIZE;
689 ioctlbuffer = kzalloc(length, GFP_KERNEL);
691 pm8001_ha->fw_status = FAIL_OUT_MEMORY;
694 payload = (struct pm8001_ioctl_payload *)ioctlbuffer;
695 memcpy((u8 *)&payload->func_specific, (u8 *)pm8001_ha->fw_image->data,
696 pm8001_ha->fw_image->size);
697 payload->wr_length = pm8001_ha->fw_image->size;
699 payload->minor_function = 0x1;
700 pm8001_ha->nvmd_completion = &completion;
701 ret = PM8001_CHIP_DISP->set_nvmd_req(pm8001_ha, payload);
703 pm8001_ha->fw_status = FAIL_OUT_MEMORY;
706 wait_for_completion(&completion);
712 static int pm8001_update_flash(struct pm8001_hba_info *pm8001_ha)
714 struct pm8001_ioctl_payload *payload;
715 DECLARE_COMPLETION_ONSTACK(completion);
717 struct fw_control_info *fwControl;
718 u32 partitionSize, partitionSizeTmp;
719 u32 loopNumber, loopcount;
720 struct pm8001_fw_image_header *image_hdr;
723 u32 length = 1024 * 16 + sizeof(*payload) - 1;
725 if (pm8001_ha->fw_image->size < 28) {
726 pm8001_ha->fw_status = FAIL_FILE_SIZE;
729 ioctlbuffer = kzalloc(length, GFP_KERNEL);
731 pm8001_ha->fw_status = FAIL_OUT_MEMORY;
734 image_hdr = (struct pm8001_fw_image_header *)pm8001_ha->fw_image->data;
735 while (sizeRead < pm8001_ha->fw_image->size) {
737 *(u32 *)((u8 *)&image_hdr->image_length + sizeRead);
738 partitionSize = be32_to_cpu(partitionSizeTmp);
739 loopcount = DIV_ROUND_UP(partitionSize + HEADER_LEN,
741 for (loopNumber = 0; loopNumber < loopcount; loopNumber++) {
742 payload = (struct pm8001_ioctl_payload *)ioctlbuffer;
743 payload->wr_length = 1024*16;
746 (struct fw_control_info *)&payload->func_specific;
747 fwControl->len = IOCTL_BUF_SIZE; /* IN */
748 fwControl->size = partitionSize + HEADER_LEN;/* IN */
749 fwControl->retcode = 0;/* OUT */
750 fwControl->offset = loopNumber * IOCTL_BUF_SIZE;/*OUT */
752 /* for the last chunk of data in case file size is not even with
753 4k, load only the rest*/
754 if (((loopcount-loopNumber) == 1) &&
755 ((partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE)) {
757 (partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE;
758 memcpy((u8 *)fwControl->buffer,
759 (u8 *)pm8001_ha->fw_image->data + sizeRead,
760 (partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE);
762 (partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE;
764 memcpy((u8 *)fwControl->buffer,
765 (u8 *)pm8001_ha->fw_image->data + sizeRead,
767 sizeRead += IOCTL_BUF_SIZE;
770 pm8001_ha->nvmd_completion = &completion;
771 ret = PM8001_CHIP_DISP->fw_flash_update_req(pm8001_ha, payload);
773 pm8001_ha->fw_status = FAIL_OUT_MEMORY;
776 wait_for_completion(&completion);
777 if (fwControl->retcode > FLASH_UPDATE_IN_PROGRESS) {
778 pm8001_ha->fw_status = fwControl->retcode;
788 static ssize_t pm8001_store_update_fw(struct device *cdev,
789 struct device_attribute *attr,
790 const char *buf, size_t count)
792 struct Scsi_Host *shost = class_to_shost(cdev);
793 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
794 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
795 char *cmd_ptr, *filename_ptr;
797 int flash_command = FLASH_CMD_NONE;
800 if (!capable(CAP_SYS_ADMIN))
803 /* this test protects us from running two flash processes at once,
804 * so we should start with this test */
805 if (pm8001_ha->fw_status == FLASH_IN_PROGRESS)
807 pm8001_ha->fw_status = FLASH_IN_PROGRESS;
809 cmd_ptr = kcalloc(count, 2, GFP_KERNEL);
811 pm8001_ha->fw_status = FAIL_OUT_MEMORY;
815 filename_ptr = cmd_ptr + count;
816 res = sscanf(buf, "%s %s", cmd_ptr, filename_ptr);
818 pm8001_ha->fw_status = FAIL_PARAMETERS;
823 for (i = 0; flash_command_table[i].code != FLASH_CMD_NONE; i++) {
824 if (!memcmp(flash_command_table[i].command,
825 cmd_ptr, strlen(cmd_ptr))) {
826 flash_command = flash_command_table[i].code;
830 if (flash_command == FLASH_CMD_NONE) {
831 pm8001_ha->fw_status = FAIL_PARAMETERS;
836 ret = request_firmware(&pm8001_ha->fw_image,
841 pm8001_dbg(pm8001_ha, FAIL,
842 "Failed to load firmware image file %s, error %d\n",
844 pm8001_ha->fw_status = FAIL_OPEN_BIOS_FILE;
848 if (FLASH_CMD_UPDATE == flash_command)
849 ret = pm8001_update_flash(pm8001_ha);
851 ret = pm8001_set_nvmd(pm8001_ha);
853 release_firmware(pm8001_ha->fw_image);
860 pm8001_ha->fw_status = FLASH_OK;
864 static ssize_t pm8001_show_update_fw(struct device *cdev,
865 struct device_attribute *attr, char *buf)
868 struct Scsi_Host *shost = class_to_shost(cdev);
869 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
870 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
872 for (i = 0; flash_error_table[i].err_code != 0; i++) {
873 if (flash_error_table[i].err_code == pm8001_ha->fw_status)
876 if (pm8001_ha->fw_status != FLASH_IN_PROGRESS)
877 pm8001_ha->fw_status = FLASH_OK;
879 return snprintf(buf, PAGE_SIZE, "status=%x %s\n",
880 flash_error_table[i].err_code,
881 flash_error_table[i].reason);
883 static DEVICE_ATTR(update_fw, S_IRUGO|S_IWUSR|S_IWGRP,
884 pm8001_show_update_fw, pm8001_store_update_fw);
887 * ctl_mpi_state_show - controller MPI state check
888 * @cdev: pointer to embedded class device
889 * @buf: the buffer returned
891 * A sysfs 'read-only' shost attribute.
894 static const char *const mpiStateText[] = {
895 "MPI is not initialized",
896 "MPI is successfully initialized",
897 "MPI termination is in progress",
898 "MPI initialization failed with error in [31:16]"
901 static ssize_t ctl_mpi_state_show(struct device *cdev,
902 struct device_attribute *attr, char *buf)
904 struct Scsi_Host *shost = class_to_shost(cdev);
905 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
906 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
909 mpidw0 = pm8001_mr32(pm8001_ha->general_stat_tbl_addr, 0);
910 return sysfs_emit(buf, "%s\n", mpiStateText[mpidw0 & 0x0003]);
912 static DEVICE_ATTR_RO(ctl_mpi_state);
915 * ctl_hmi_error_show - controller MPI initialization fails
916 * @cdev: pointer to embedded class device
917 * @buf: the buffer returned
919 * A sysfs 'read-only' shost attribute.
922 static ssize_t ctl_hmi_error_show(struct device *cdev,
923 struct device_attribute *attr, char *buf)
925 struct Scsi_Host *shost = class_to_shost(cdev);
926 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
927 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
930 mpidw0 = pm8001_mr32(pm8001_ha->general_stat_tbl_addr, 0);
931 return sysfs_emit(buf, "0x%08x\n", (mpidw0 >> 16));
933 static DEVICE_ATTR_RO(ctl_hmi_error);
936 * ctl_raae_count_show - controller raae count check
937 * @cdev: pointer to embedded class device
938 * @buf: the buffer returned
940 * A sysfs 'read-only' shost attribute.
943 static ssize_t ctl_raae_count_show(struct device *cdev,
944 struct device_attribute *attr, char *buf)
946 struct Scsi_Host *shost = class_to_shost(cdev);
947 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
948 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
949 unsigned int raaecnt;
951 raaecnt = pm8001_mr32(pm8001_ha->general_stat_tbl_addr, 12);
952 return sysfs_emit(buf, "0x%08x\n", raaecnt);
954 static DEVICE_ATTR_RO(ctl_raae_count);
957 * ctl_iop0_count_show - controller iop0 count check
958 * @cdev: pointer to embedded class device
959 * @buf: the buffer returned
961 * A sysfs 'read-only' shost attribute.
964 static ssize_t ctl_iop0_count_show(struct device *cdev,
965 struct device_attribute *attr, char *buf)
967 struct Scsi_Host *shost = class_to_shost(cdev);
968 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
969 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
970 unsigned int iop0cnt;
972 iop0cnt = pm8001_mr32(pm8001_ha->general_stat_tbl_addr, 16);
973 return sysfs_emit(buf, "0x%08x\n", iop0cnt);
975 static DEVICE_ATTR_RO(ctl_iop0_count);
978 * ctl_iop1_count_show - controller iop1 count check
979 * @cdev: pointer to embedded class device
980 * @buf: the buffer returned
982 * A sysfs 'read-only' shost attribute.
985 static ssize_t ctl_iop1_count_show(struct device *cdev,
986 struct device_attribute *attr, char *buf)
988 struct Scsi_Host *shost = class_to_shost(cdev);
989 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
990 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
991 unsigned int iop1cnt;
993 iop1cnt = pm8001_mr32(pm8001_ha->general_stat_tbl_addr, 20);
994 return sysfs_emit(buf, "0x%08x\n", iop1cnt);
997 static DEVICE_ATTR_RO(ctl_iop1_count);
999 struct device_attribute *pm8001_host_attrs[] = {
1000 &dev_attr_interface_rev,
1001 &dev_attr_controller_fatal_error,
1002 &dev_attr_fw_version,
1003 &dev_attr_update_fw,
1006 &dev_attr_fatal_log,
1007 &dev_attr_non_fatal_log,
1008 &dev_attr_non_fatal_count,
1010 &dev_attr_max_out_io,
1011 &dev_attr_max_devices,
1012 &dev_attr_max_sg_list,
1013 &dev_attr_sas_spec_support,
1014 &dev_attr_logging_level,
1015 &dev_attr_event_log_size,
1016 &dev_attr_host_sas_address,
1017 &dev_attr_bios_version,
1020 &dev_attr_ila_version,
1021 &dev_attr_inc_fw_ver,
1022 &dev_attr_ctl_mpi_state,
1023 &dev_attr_ctl_hmi_error,
1024 &dev_attr_ctl_raae_count,
1025 &dev_attr_ctl_iop0_count,
1026 &dev_attr_ctl_iop1_count,