1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40#include <linux/firmware.h>
41#include <linux/slab.h>
42#include "pm8001_sas.h"
43#include "pm8001_ctl.h"
44
45
46
47
48
49
50
51
52
53
54
55static ssize_t pm8001_ctl_mpi_interface_rev_show(struct device *cdev,
56 struct device_attribute *attr, char *buf)
57{
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;
61
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);
65 } else {
66 return snprintf(buf, PAGE_SIZE, "%d\n",
67 pm8001_ha->main_cfg_tbl.pm80xx_tbl.interface_rev);
68 }
69}
70static
71DEVICE_ATTR(interface_rev, S_IRUGO, pm8001_ctl_mpi_interface_rev_show, NULL);
72
73
74
75
76
77
78
79
80
81static ssize_t controller_fatal_error_show(struct device *cdev,
82 struct device_attribute *attr, char *buf)
83{
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;
87
88 return snprintf(buf, PAGE_SIZE, "%d\n",
89 pm8001_ha->controller_fatal_error);
90}
91static DEVICE_ATTR_RO(controller_fatal_error);
92
93
94
95
96
97
98
99
100
101static ssize_t pm8001_ctl_fw_version_show(struct device *cdev,
102 struct device_attribute *attr, char *buf)
103{
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;
107
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));
114 } else {
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));
120 }
121}
122static DEVICE_ATTR(fw_version, S_IRUGO, pm8001_ctl_fw_version_show, NULL);
123
124
125
126
127
128
129
130
131
132static ssize_t pm8001_ctl_ila_version_show(struct device *cdev,
133 struct device_attribute *attr, char *buf)
134{
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;
138
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));
145 }
146 return 0;
147}
148static DEVICE_ATTR(ila_version, 0444, pm8001_ctl_ila_version_show, NULL);
149
150
151
152
153
154
155
156
157
158static ssize_t pm8001_ctl_inactive_fw_version_show(struct device *cdev,
159 struct device_attribute *attr, char *buf)
160{
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;
164
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));
171 }
172 return 0;
173}
174static
175DEVICE_ATTR(inc_fw_ver, 0444, pm8001_ctl_inactive_fw_version_show, NULL);
176
177
178
179
180
181
182
183
184
185static ssize_t pm8001_ctl_max_out_io_show(struct device *cdev,
186 struct device_attribute *attr, char *buf)
187{
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;
191
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);
195 } else {
196 return snprintf(buf, PAGE_SIZE, "%d\n",
197 pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_out_io);
198 }
199}
200static DEVICE_ATTR(max_out_io, S_IRUGO, pm8001_ctl_max_out_io_show, NULL);
201
202
203
204
205
206
207
208
209static ssize_t pm8001_ctl_max_devices_show(struct device *cdev,
210 struct device_attribute *attr, char *buf)
211{
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;
215
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)
219 );
220 } else {
221 return snprintf(buf, PAGE_SIZE, "%04d\n",
222 (u16)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_sgl >> 16)
223 );
224 }
225}
226static DEVICE_ATTR(max_devices, S_IRUGO, pm8001_ctl_max_devices_show, NULL);
227
228
229
230
231
232
233
234
235
236static ssize_t pm8001_ctl_max_sg_list_show(struct device *cdev,
237 struct device_attribute *attr, char *buf)
238{
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;
242
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
246 );
247 } else {
248 return snprintf(buf, PAGE_SIZE, "%04d\n",
249 pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_sgl & 0x0000FFFF
250 );
251 }
252}
253static DEVICE_ATTR(max_sg_list, S_IRUGO, pm8001_ctl_max_sg_list_show, NULL);
254
255#define SAS_1_0 0x1
256#define SAS_1_1 0x2
257#define SAS_2_0 0x4
258
259static ssize_t
260show_sas_spec_support_status(unsigned int mode, char *buf)
261{
262 ssize_t len = 0;
263
264 if (mode & SAS_1_1)
265 len = sprintf(buf, "%s", "SAS1.1");
266 if (mode & SAS_2_0)
267 len += sprintf(buf + len, "%s%s", len ? ", " : "", "SAS2.0");
268 len += sprintf(buf + len, "\n");
269
270 return len;
271}
272
273
274
275
276
277
278
279
280
281static ssize_t pm8001_ctl_sas_spec_support_show(struct device *cdev,
282 struct device_attribute *attr, char *buf)
283{
284 unsigned int mode;
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
289 if (pm8001_ha->chip_id == chip_8001)
290 mode = (pm8001_ha->main_cfg_tbl.pm8001_tbl.ctrl_cap_flag &
291 0xfe000000)>>25;
292 else
293
294 mode = (pm8001_ha->main_cfg_tbl.pm80xx_tbl.ctrl_cap_flag &
295 0xfe000000)>>25;
296 return show_sas_spec_support_status(mode, buf);
297}
298static DEVICE_ATTR(sas_spec_support, S_IRUGO,
299 pm8001_ctl_sas_spec_support_show, NULL);
300
301
302
303
304
305
306
307
308
309
310
311static ssize_t pm8001_ctl_host_sas_address_show(struct device *cdev,
312 struct device_attribute *attr, char *buf)
313{
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));
319}
320static DEVICE_ATTR(host_sas_address, S_IRUGO,
321 pm8001_ctl_host_sas_address_show, NULL);
322
323
324
325
326
327
328
329
330
331static ssize_t pm8001_ctl_logging_level_show(struct device *cdev,
332 struct device_attribute *attr, char *buf)
333{
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;
337
338 return snprintf(buf, PAGE_SIZE, "%08xh\n", pm8001_ha->logging_level);
339}
340
341static ssize_t pm8001_ctl_logging_level_store(struct device *cdev,
342 struct device_attribute *attr, const char *buf, size_t count)
343{
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;
347 int val = 0;
348
349 if (sscanf(buf, "%x", &val) != 1)
350 return -EINVAL;
351
352 pm8001_ha->logging_level = val;
353 return strlen(buf);
354}
355
356static DEVICE_ATTR(logging_level, S_IRUGO | S_IWUSR,
357 pm8001_ctl_logging_level_show, pm8001_ctl_logging_level_store);
358
359
360
361
362
363
364
365
366static ssize_t pm8001_ctl_aap_log_show(struct device *cdev,
367 struct device_attribute *attr, char *buf)
368{
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;
372 int i;
373#define AAP1_MEMMAP(r, c) \
374 (*(u32 *)((u8*)pm8001_ha->memoryMap.region[AAP1].virt_ptr + (r) * 32 \
375 + (c)))
376
377 char *str = buf;
378 int max = 2;
379 for (i = 0; i < max; i++) {
380 str += sprintf(str, "0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x"
381 "0x%08x 0x%08x\n",
382 AAP1_MEMMAP(i, 0),
383 AAP1_MEMMAP(i, 4),
384 AAP1_MEMMAP(i, 8),
385 AAP1_MEMMAP(i, 12),
386 AAP1_MEMMAP(i, 16),
387 AAP1_MEMMAP(i, 20),
388 AAP1_MEMMAP(i, 24),
389 AAP1_MEMMAP(i, 28));
390 }
391
392 return str - buf;
393}
394static DEVICE_ATTR(aap_log, S_IRUGO, pm8001_ctl_aap_log_show, NULL);
395
396
397
398
399
400
401
402static ssize_t pm8001_ctl_ib_queue_log_show(struct device *cdev,
403 struct device_attribute *attr, char *buf)
404{
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;
408 int offset;
409 char *str = buf;
410 int start = 0;
411#define IB_MEMMAP(c) \
412 (*(u32 *)((u8 *)pm8001_ha-> \
413 memoryMap.region[IB].virt_ptr + \
414 pm8001_ha->evtlog_ib_offset + (c)))
415
416 for (offset = 0; offset < IB_OB_READ_TIMES; offset++) {
417 str += sprintf(str, "0x%08x\n", IB_MEMMAP(start));
418 start = start + 4;
419 }
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;
423
424 return str - buf;
425}
426
427static DEVICE_ATTR(ib_log, S_IRUGO, pm8001_ctl_ib_queue_log_show, NULL);
428
429
430
431
432
433
434
435
436static ssize_t pm8001_ctl_ob_queue_log_show(struct device *cdev,
437 struct device_attribute *attr, char *buf)
438{
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;
442 int offset;
443 char *str = buf;
444 int start = 0;
445#define OB_MEMMAP(c) \
446 (*(u32 *)((u8 *)pm8001_ha-> \
447 memoryMap.region[OB].virt_ptr + \
448 pm8001_ha->evtlog_ob_offset + (c)))
449
450 for (offset = 0; offset < IB_OB_READ_TIMES; offset++) {
451 str += sprintf(str, "0x%08x\n", OB_MEMMAP(start));
452 start = start + 4;
453 }
454 pm8001_ha->evtlog_ob_offset += SYSFS_OFFSET;
455 if (((pm8001_ha->evtlog_ob_offset) % (PM80XX_IB_OB_QUEUE_SIZE)) == 0)
456 pm8001_ha->evtlog_ob_offset = 0;
457
458 return str - buf;
459}
460static DEVICE_ATTR(ob_log, S_IRUGO, pm8001_ctl_ob_queue_log_show, NULL);
461
462
463
464
465
466
467
468static ssize_t pm8001_ctl_bios_version_show(struct device *cdev,
469 struct device_attribute *attr, char *buf)
470{
471 struct Scsi_Host *shost = class_to_shost(cdev);
472 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
473 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
474 char *str = buf;
475 int bios_index;
476 DECLARE_COMPLETION_ONSTACK(completion);
477 struct pm8001_ioctl_payload payload;
478
479 pm8001_ha->nvmd_completion = &completion;
480 payload.minor_function = 7;
481 payload.offset = 0;
482 payload.rd_length = 4096;
483 payload.func_specific = kzalloc(4096, GFP_KERNEL);
484 if (!payload.func_specific)
485 return -ENOMEM;
486 if (PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload)) {
487 kfree(payload.func_specific);
488 return -ENOMEM;
489 }
490 wait_for_completion(&completion);
491 for (bios_index = BIOSOFFSET; bios_index < BIOS_OFFSET_LIMIT;
492 bios_index++)
493 str += sprintf(str, "%c",
494 *(payload.func_specific+bios_index));
495 kfree(payload.func_specific);
496 return str - buf;
497}
498static DEVICE_ATTR(bios_version, S_IRUGO, pm8001_ctl_bios_version_show, NULL);
499
500
501
502
503
504
505
506
507static ssize_t event_log_size_show(struct device *cdev,
508 struct device_attribute *attr, char *buf)
509{
510 struct Scsi_Host *shost = class_to_shost(cdev);
511 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
512 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
513
514 return snprintf(buf, PAGE_SIZE, "%d\n",
515 pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_size);
516}
517static DEVICE_ATTR_RO(event_log_size);
518
519
520
521
522
523
524
525
526static ssize_t pm8001_ctl_iop_log_show(struct device *cdev,
527 struct device_attribute *attr, char *buf)
528{
529 struct Scsi_Host *shost = class_to_shost(cdev);
530 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
531 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
532 char *str = buf;
533 u32 read_size =
534 pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_size / 1024;
535 static u32 start, end, count;
536 u32 max_read_times = 32;
537 u32 max_count = (read_size * 1024) / (max_read_times * 4);
538 u32 *temp = (u32 *)pm8001_ha->memoryMap.region[IOP].virt_ptr;
539
540 if ((count % max_count) == 0) {
541 start = 0;
542 end = max_read_times;
543 count = 0;
544 } else {
545 start = end;
546 end = end + max_read_times;
547 }
548
549 for (; start < end; start++)
550 str += sprintf(str, "%08x ", *(temp+start));
551 count++;
552 return str - buf;
553}
554static DEVICE_ATTR(iop_log, S_IRUGO, pm8001_ctl_iop_log_show, NULL);
555
556
557
558
559
560
561
562
563
564
565static ssize_t pm8001_ctl_fatal_log_show(struct device *cdev,
566 struct device_attribute *attr, char *buf)
567{
568 ssize_t count;
569
570 count = pm80xx_get_fatal_dump(cdev, attr, buf);
571 return count;
572}
573
574static DEVICE_ATTR(fatal_log, S_IRUGO, pm8001_ctl_fatal_log_show, NULL);
575
576
577
578
579
580
581
582
583
584static ssize_t non_fatal_log_show(struct device *cdev,
585 struct device_attribute *attr, char *buf)
586{
587 u32 count;
588
589 count = pm80xx_get_non_fatal_dump(cdev, attr, buf);
590 return count;
591}
592static DEVICE_ATTR_RO(non_fatal_log);
593
594static ssize_t non_fatal_count_show(struct device *cdev,
595 struct device_attribute *attr, char *buf)
596{
597 struct Scsi_Host *shost = class_to_shost(cdev);
598 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
599 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
600
601 return snprintf(buf, PAGE_SIZE, "%08x",
602 pm8001_ha->non_fatal_count);
603}
604
605static ssize_t non_fatal_count_store(struct device *cdev,
606 struct device_attribute *attr, const char *buf, size_t count)
607{
608 struct Scsi_Host *shost = class_to_shost(cdev);
609 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
610 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
611 int val = 0;
612
613 if (kstrtoint(buf, 16, &val) != 0)
614 return -EINVAL;
615
616 pm8001_ha->non_fatal_count = val;
617 return strlen(buf);
618}
619static DEVICE_ATTR_RW(non_fatal_count);
620
621
622
623
624
625
626
627
628static ssize_t pm8001_ctl_gsm_log_show(struct device *cdev,
629 struct device_attribute *attr, char *buf)
630{
631 ssize_t count;
632
633 count = pm8001_get_gsm_dump(cdev, SYSFS_OFFSET, buf);
634 return count;
635}
636
637static DEVICE_ATTR(gsm_log, S_IRUGO, pm8001_ctl_gsm_log_show, NULL);
638
639#define FLASH_CMD_NONE 0x00
640#define FLASH_CMD_UPDATE 0x01
641#define FLASH_CMD_SET_NVMD 0x02
642
643struct flash_command {
644 u8 command[8];
645 int code;
646};
647
648static struct flash_command flash_command_table[] =
649{
650 {"set_nvmd", FLASH_CMD_SET_NVMD},
651 {"update", FLASH_CMD_UPDATE},
652 {"", FLASH_CMD_NONE}
653};
654
655struct error_fw {
656 char *reason;
657 int err_code;
658};
659
660static struct error_fw flash_error_table[] =
661{
662 {"Failed to open fw image file", FAIL_OPEN_BIOS_FILE},
663 {"image header mismatch", FLASH_UPDATE_HDR_ERR},
664 {"image offset mismatch", FLASH_UPDATE_OFFSET_ERR},
665 {"image CRC Error", FLASH_UPDATE_CRC_ERR},
666 {"image length Error.", FLASH_UPDATE_LENGTH_ERR},
667 {"Failed to program flash chip", FLASH_UPDATE_HW_ERR},
668 {"Flash chip not supported.", FLASH_UPDATE_DNLD_NOT_SUPPORTED},
669 {"Flash update disabled.", FLASH_UPDATE_DISABLED},
670 {"Flash in progress", FLASH_IN_PROGRESS},
671 {"Image file size Error", FAIL_FILE_SIZE},
672 {"Input parameter error", FAIL_PARAMETERS},
673 {"Out of memory", FAIL_OUT_MEMORY},
674 {"OK", 0}
675};
676
677static int pm8001_set_nvmd(struct pm8001_hba_info *pm8001_ha)
678{
679 struct pm8001_ioctl_payload *payload;
680 DECLARE_COMPLETION_ONSTACK(completion);
681 u8 *ioctlbuffer;
682 u32 ret;
683 u32 length = 1024 * 5 + sizeof(*payload) - 1;
684
685 if (pm8001_ha->fw_image->size > 4096) {
686 pm8001_ha->fw_status = FAIL_FILE_SIZE;
687 return -EFAULT;
688 }
689
690 ioctlbuffer = kzalloc(length, GFP_KERNEL);
691 if (!ioctlbuffer) {
692 pm8001_ha->fw_status = FAIL_OUT_MEMORY;
693 return -ENOMEM;
694 }
695 payload = (struct pm8001_ioctl_payload *)ioctlbuffer;
696 memcpy((u8 *)&payload->func_specific, (u8 *)pm8001_ha->fw_image->data,
697 pm8001_ha->fw_image->size);
698 payload->wr_length = pm8001_ha->fw_image->size;
699 payload->id = 0;
700 payload->minor_function = 0x1;
701 pm8001_ha->nvmd_completion = &completion;
702 ret = PM8001_CHIP_DISP->set_nvmd_req(pm8001_ha, payload);
703 if (ret) {
704 pm8001_ha->fw_status = FAIL_OUT_MEMORY;
705 goto out;
706 }
707 wait_for_completion(&completion);
708out:
709 kfree(ioctlbuffer);
710 return ret;
711}
712
713static int pm8001_update_flash(struct pm8001_hba_info *pm8001_ha)
714{
715 struct pm8001_ioctl_payload *payload;
716 DECLARE_COMPLETION_ONSTACK(completion);
717 u8 *ioctlbuffer;
718 struct fw_control_info *fwControl;
719 u32 partitionSize, partitionSizeTmp;
720 u32 loopNumber, loopcount;
721 struct pm8001_fw_image_header *image_hdr;
722 u32 sizeRead = 0;
723 u32 ret = 0;
724 u32 length = 1024 * 16 + sizeof(*payload) - 1;
725
726 if (pm8001_ha->fw_image->size < 28) {
727 pm8001_ha->fw_status = FAIL_FILE_SIZE;
728 return -EFAULT;
729 }
730 ioctlbuffer = kzalloc(length, GFP_KERNEL);
731 if (!ioctlbuffer) {
732 pm8001_ha->fw_status = FAIL_OUT_MEMORY;
733 return -ENOMEM;
734 }
735 image_hdr = (struct pm8001_fw_image_header *)pm8001_ha->fw_image->data;
736 while (sizeRead < pm8001_ha->fw_image->size) {
737 partitionSizeTmp =
738 *(u32 *)((u8 *)&image_hdr->image_length + sizeRead);
739 partitionSize = be32_to_cpu(partitionSizeTmp);
740 loopcount = DIV_ROUND_UP(partitionSize + HEADER_LEN,
741 IOCTL_BUF_SIZE);
742 for (loopNumber = 0; loopNumber < loopcount; loopNumber++) {
743 payload = (struct pm8001_ioctl_payload *)ioctlbuffer;
744 payload->wr_length = 1024*16;
745 payload->id = 0;
746 fwControl =
747 (struct fw_control_info *)&payload->func_specific;
748 fwControl->len = IOCTL_BUF_SIZE;
749 fwControl->size = partitionSize + HEADER_LEN;
750 fwControl->retcode = 0;
751 fwControl->offset = loopNumber * IOCTL_BUF_SIZE;
752
753
754
755 if (((loopcount-loopNumber) == 1) &&
756 ((partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE)) {
757 fwControl->len =
758 (partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE;
759 memcpy((u8 *)fwControl->buffer,
760 (u8 *)pm8001_ha->fw_image->data + sizeRead,
761 (partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE);
762 sizeRead +=
763 (partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE;
764 } else {
765 memcpy((u8 *)fwControl->buffer,
766 (u8 *)pm8001_ha->fw_image->data + sizeRead,
767 IOCTL_BUF_SIZE);
768 sizeRead += IOCTL_BUF_SIZE;
769 }
770
771 pm8001_ha->nvmd_completion = &completion;
772 ret = PM8001_CHIP_DISP->fw_flash_update_req(pm8001_ha, payload);
773 if (ret) {
774 pm8001_ha->fw_status = FAIL_OUT_MEMORY;
775 goto out;
776 }
777 wait_for_completion(&completion);
778 if (fwControl->retcode > FLASH_UPDATE_IN_PROGRESS) {
779 pm8001_ha->fw_status = fwControl->retcode;
780 ret = -EFAULT;
781 goto out;
782 }
783 }
784 }
785out:
786 kfree(ioctlbuffer);
787 return ret;
788}
789static ssize_t pm8001_store_update_fw(struct device *cdev,
790 struct device_attribute *attr,
791 const char *buf, size_t count)
792{
793 struct Scsi_Host *shost = class_to_shost(cdev);
794 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
795 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
796 char *cmd_ptr, *filename_ptr;
797 int res, i;
798 int flash_command = FLASH_CMD_NONE;
799 int ret;
800
801 if (!capable(CAP_SYS_ADMIN))
802 return -EACCES;
803
804
805
806 if (pm8001_ha->fw_status == FLASH_IN_PROGRESS)
807 return -EINPROGRESS;
808 pm8001_ha->fw_status = FLASH_IN_PROGRESS;
809
810 cmd_ptr = kcalloc(count, 2, GFP_KERNEL);
811 if (!cmd_ptr) {
812 pm8001_ha->fw_status = FAIL_OUT_MEMORY;
813 return -ENOMEM;
814 }
815
816 filename_ptr = cmd_ptr + count;
817 res = sscanf(buf, "%s %s", cmd_ptr, filename_ptr);
818 if (res != 2) {
819 pm8001_ha->fw_status = FAIL_PARAMETERS;
820 ret = -EINVAL;
821 goto out;
822 }
823
824 for (i = 0; flash_command_table[i].code != FLASH_CMD_NONE; i++) {
825 if (!memcmp(flash_command_table[i].command,
826 cmd_ptr, strlen(cmd_ptr))) {
827 flash_command = flash_command_table[i].code;
828 break;
829 }
830 }
831 if (flash_command == FLASH_CMD_NONE) {
832 pm8001_ha->fw_status = FAIL_PARAMETERS;
833 ret = -EINVAL;
834 goto out;
835 }
836
837 ret = request_firmware(&pm8001_ha->fw_image,
838 filename_ptr,
839 pm8001_ha->dev);
840
841 if (ret) {
842 PM8001_FAIL_DBG(pm8001_ha,
843 pm8001_printk(
844 "Failed to load firmware image file %s, error %d\n",
845 filename_ptr, ret));
846 pm8001_ha->fw_status = FAIL_OPEN_BIOS_FILE;
847 goto out;
848 }
849
850 if (FLASH_CMD_UPDATE == flash_command)
851 ret = pm8001_update_flash(pm8001_ha);
852 else
853 ret = pm8001_set_nvmd(pm8001_ha);
854
855 release_firmware(pm8001_ha->fw_image);
856out:
857 kfree(cmd_ptr);
858
859 if (ret)
860 return ret;
861
862 pm8001_ha->fw_status = FLASH_OK;
863 return count;
864}
865
866static ssize_t pm8001_show_update_fw(struct device *cdev,
867 struct device_attribute *attr, char *buf)
868{
869 int i;
870 struct Scsi_Host *shost = class_to_shost(cdev);
871 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
872 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
873
874 for (i = 0; flash_error_table[i].err_code != 0; i++) {
875 if (flash_error_table[i].err_code == pm8001_ha->fw_status)
876 break;
877 }
878 if (pm8001_ha->fw_status != FLASH_IN_PROGRESS)
879 pm8001_ha->fw_status = FLASH_OK;
880
881 return snprintf(buf, PAGE_SIZE, "status=%x %s\n",
882 flash_error_table[i].err_code,
883 flash_error_table[i].reason);
884}
885
886static DEVICE_ATTR(update_fw, S_IRUGO|S_IWUSR|S_IWGRP,
887 pm8001_show_update_fw, pm8001_store_update_fw);
888struct device_attribute *pm8001_host_attrs[] = {
889 &dev_attr_interface_rev,
890 &dev_attr_controller_fatal_error,
891 &dev_attr_fw_version,
892 &dev_attr_update_fw,
893 &dev_attr_aap_log,
894 &dev_attr_iop_log,
895 &dev_attr_fatal_log,
896 &dev_attr_non_fatal_log,
897 &dev_attr_non_fatal_count,
898 &dev_attr_gsm_log,
899 &dev_attr_max_out_io,
900 &dev_attr_max_devices,
901 &dev_attr_max_sg_list,
902 &dev_attr_sas_spec_support,
903 &dev_attr_logging_level,
904 &dev_attr_event_log_size,
905 &dev_attr_host_sas_address,
906 &dev_attr_bios_version,
907 &dev_attr_ib_log,
908 &dev_attr_ob_log,
909 &dev_attr_ila_version,
910 &dev_attr_inc_fw_ver,
911 NULL,
912};
913
914