blob: ae2b1242d0ace6f9bf7e5f01d04d2cbf406fbeda [file] [log] [blame]
jack wangdbf9bfe2009-10-14 16:19:21 +08001/*
Sakthivel Ke5742102013-04-17 16:26:36 +05302 * PMC-Sierra 8001/8081/8088/8089 SAS/SATA based host adapters driver
jack wangdbf9bfe2009-10-14 16:19:21 +08003 *
4 * Copyright (c) 2008-2009 USI Co., Ltd.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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.
21 *
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.
25 *
26 * NO WARRANTY
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.
38 *
39 */
40#include <linux/firmware.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090041#include <linux/slab.h>
jack wangdbf9bfe2009-10-14 16:19:21 +080042#include "pm8001_sas.h"
43#include "pm8001_ctl.h"
44
45/* scsi host attributes */
46
47/**
48 * pm8001_ctl_mpi_interface_rev_show - MPI interface revision number
49 * @cdev: pointer to embedded class device
50 * @buf: the buffer returned
51 *
52 * A sysfs 'read-only' shost attribute.
53 */
54static ssize_t pm8001_ctl_mpi_interface_rev_show(struct device *cdev,
55 struct device_attribute *attr, char *buf)
56{
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;
60
Sakthivel Ke5742102013-04-17 16:26:36 +053061 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);
64 } else {
65 return snprintf(buf, PAGE_SIZE, "%d\n",
66 pm8001_ha->main_cfg_tbl.pm80xx_tbl.interface_rev);
67 }
jack wangdbf9bfe2009-10-14 16:19:21 +080068}
69static
70DEVICE_ATTR(interface_rev, S_IRUGO, pm8001_ctl_mpi_interface_rev_show, NULL);
71
72/**
73 * pm8001_ctl_fw_version_show - firmware version
74 * @cdev: pointer to embedded class device
75 * @buf: the buffer returned
76 *
77 * A sysfs 'read-only' shost attribute.
78 */
79static ssize_t pm8001_ctl_fw_version_show(struct device *cdev,
80 struct device_attribute *attr, char *buf)
81{
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;
85
Sakthivel Ke5742102013-04-17 16:26:36 +053086 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));
92 } else {
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));
98 }
jack wangdbf9bfe2009-10-14 16:19:21 +080099}
100static DEVICE_ATTR(fw_version, S_IRUGO, pm8001_ctl_fw_version_show, NULL);
101/**
102 * pm8001_ctl_max_out_io_show - max outstanding io supported
103 * @cdev: pointer to embedded class device
104 * @buf: the buffer returned
105 *
106 * A sysfs 'read-only' shost attribute.
107 */
108static ssize_t pm8001_ctl_max_out_io_show(struct device *cdev,
109 struct device_attribute *attr, char *buf)
110{
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;
114
Sakthivel Ke5742102013-04-17 16:26:36 +0530115 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);
118 } else {
119 return snprintf(buf, PAGE_SIZE, "%d\n",
120 pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_out_io);
121 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800122}
123static DEVICE_ATTR(max_out_io, S_IRUGO, pm8001_ctl_max_out_io_show, NULL);
124/**
125 * pm8001_ctl_max_devices_show - max devices support
126 * @cdev: pointer to embedded class device
127 * @buf: the buffer returned
128 *
129 * A sysfs 'read-only' shost attribute.
130 */
131static ssize_t pm8001_ctl_max_devices_show(struct device *cdev,
132 struct device_attribute *attr, char *buf)
133{
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;
137
Sakthivel Ke5742102013-04-17 16:26:36 +0530138 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)
141 );
142 } else {
143 return snprintf(buf, PAGE_SIZE, "%04d\n",
144 (u16)(pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_sgl >> 16)
145 );
146 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800147}
148static DEVICE_ATTR(max_devices, S_IRUGO, pm8001_ctl_max_devices_show, NULL);
149/**
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
154 *
155 * A sysfs 'read-only' shost attribute.
156 */
157static ssize_t pm8001_ctl_max_sg_list_show(struct device *cdev,
158 struct device_attribute *attr, char *buf)
159{
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;
163
Sakthivel Ke5742102013-04-17 16:26:36 +0530164 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
167 );
168 } else {
169 return snprintf(buf, PAGE_SIZE, "%04d\n",
170 pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_sgl & 0x0000FFFF
171 );
172 }
jack wangdbf9bfe2009-10-14 16:19:21 +0800173}
174static DEVICE_ATTR(max_sg_list, S_IRUGO, pm8001_ctl_max_sg_list_show, NULL);
175
176#define SAS_1_0 0x1
177#define SAS_1_1 0x2
178#define SAS_2_0 0x4
179
180static ssize_t
181show_sas_spec_support_status(unsigned int mode, char *buf)
182{
183 ssize_t len = 0;
184
185 if (mode & SAS_1_1)
186 len = sprintf(buf, "%s", "SAS1.1");
187 if (mode & SAS_2_0)
188 len += sprintf(buf + len, "%s%s", len ? ", " : "", "SAS2.0");
189 len += sprintf(buf + len, "\n");
190
191 return len;
192}
193
194/**
195 * pm8001_ctl_sas_spec_support_show - sas spec supported
196 * @cdev: pointer to embedded class device
197 * @buf: the buffer returned
198 *
199 * A sysfs 'read-only' shost attribute.
200 */
201static ssize_t pm8001_ctl_sas_spec_support_show(struct device *cdev,
202 struct device_attribute *attr, char *buf)
203{
204 unsigned int mode;
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;
Sakthivel Ke5742102013-04-17 16:26:36 +0530208 /* 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 &
211 0xfe000000)>>25;
212 else
213 /* fe000000 means supports SAS2.1 */
214 mode = (pm8001_ha->main_cfg_tbl.pm80xx_tbl.ctrl_cap_flag &
215 0xfe000000)>>25;
jack wangdbf9bfe2009-10-14 16:19:21 +0800216 return show_sas_spec_support_status(mode, buf);
217}
218static DEVICE_ATTR(sas_spec_support, S_IRUGO,
219 pm8001_ctl_sas_spec_support_show, NULL);
220
221/**
222 * pm8001_ctl_sas_address_show - sas address
223 * @cdev: pointer to embedded class device
224 * @buf: the buffer returned
225 *
226 * This is the controller sas address
227 *
228 * A sysfs 'read-only' shost attribute.
229 */
230static ssize_t pm8001_ctl_host_sas_address_show(struct device *cdev,
231 struct device_attribute *attr, char *buf)
232{
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));
238}
239static DEVICE_ATTR(host_sas_address, S_IRUGO,
240 pm8001_ctl_host_sas_address_show, NULL);
241
242/**
243 * pm8001_ctl_logging_level_show - logging level
244 * @cdev: pointer to embedded class device
245 * @buf: the buffer returned
246 *
247 * A sysfs 'read/write' shost attribute.
248 */
249static ssize_t pm8001_ctl_logging_level_show(struct device *cdev,
250 struct device_attribute *attr, char *buf)
251{
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;
255
256 return snprintf(buf, PAGE_SIZE, "%08xh\n", pm8001_ha->logging_level);
257}
258static ssize_t pm8001_ctl_logging_level_store(struct device *cdev,
259 struct device_attribute *attr, const char *buf, size_t count)
260{
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;
264 int val = 0;
265
266 if (sscanf(buf, "%x", &val) != 1)
267 return -EINVAL;
268
269 pm8001_ha->logging_level = val;
270 return strlen(buf);
271}
272
273static DEVICE_ATTR(logging_level, S_IRUGO | S_IWUSR,
274 pm8001_ctl_logging_level_show, pm8001_ctl_logging_level_store);
275/**
276 * pm8001_ctl_aap_log_show - aap1 event log
277 * @cdev: pointer to embedded class device
278 * @buf: the buffer returned
279 *
280 * A sysfs 'read-only' shost attribute.
281 */
282static ssize_t pm8001_ctl_aap_log_show(struct device *cdev,
283 struct device_attribute *attr, char *buf)
284{
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 int i;
289#define AAP1_MEMMAP(r, c) \
290 (*(u32 *)((u8*)pm8001_ha->memoryMap.region[AAP1].virt_ptr + (r) * 32 \
291 + (c)))
292
293 char *str = buf;
294 int max = 2;
295 for (i = 0; i < max; i++) {
296 str += sprintf(str, "0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x"
297 "0x%08x 0x%08x\n",
298 AAP1_MEMMAP(i, 0),
299 AAP1_MEMMAP(i, 4),
300 AAP1_MEMMAP(i, 8),
301 AAP1_MEMMAP(i, 12),
302 AAP1_MEMMAP(i, 16),
303 AAP1_MEMMAP(i, 20),
304 AAP1_MEMMAP(i, 24),
305 AAP1_MEMMAP(i, 28));
306 }
307
308 return str - buf;
309}
310static DEVICE_ATTR(aap_log, S_IRUGO, pm8001_ctl_aap_log_show, NULL);
311/**
312 * pm8001_ctl_aap_log_show - IOP event log
313 * @cdev: pointer to embedded class device
314 * @buf: the buffer returned
315 *
316 * A sysfs 'read-only' shost attribute.
317 */
318static ssize_t pm8001_ctl_iop_log_show(struct device *cdev,
319 struct device_attribute *attr, char *buf)
320{
321 struct Scsi_Host *shost = class_to_shost(cdev);
322 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
323 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
324#define IOP_MEMMAP(r, c) \
325 (*(u32 *)((u8*)pm8001_ha->memoryMap.region[IOP].virt_ptr + (r) * 32 \
326 + (c)))
327 int i;
328 char *str = buf;
329 int max = 2;
330 for (i = 0; i < max; i++) {
331 str += sprintf(str, "0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x"
332 "0x%08x 0x%08x\n",
333 IOP_MEMMAP(i, 0),
334 IOP_MEMMAP(i, 4),
335 IOP_MEMMAP(i, 8),
336 IOP_MEMMAP(i, 12),
337 IOP_MEMMAP(i, 16),
338 IOP_MEMMAP(i, 20),
339 IOP_MEMMAP(i, 24),
340 IOP_MEMMAP(i, 28));
341 }
342
343 return str - buf;
344}
345static DEVICE_ATTR(iop_log, S_IRUGO, pm8001_ctl_iop_log_show, NULL);
346
347#define FLASH_CMD_NONE 0x00
348#define FLASH_CMD_UPDATE 0x01
349#define FLASH_CMD_SET_NVMD 0x02
350
351struct flash_command {
352 u8 command[8];
353 int code;
354};
355
356static struct flash_command flash_command_table[] =
357{
358 {"set_nvmd", FLASH_CMD_SET_NVMD},
359 {"update", FLASH_CMD_UPDATE},
360 {"", FLASH_CMD_NONE} /* Last entry should be NULL. */
361};
362
363struct error_fw {
364 char *reason;
365 int err_code;
366};
367
368static struct error_fw flash_error_table[] =
369{
370 {"Failed to open fw image file", FAIL_OPEN_BIOS_FILE},
371 {"image header mismatch", FLASH_UPDATE_HDR_ERR},
372 {"image offset mismatch", FLASH_UPDATE_OFFSET_ERR},
373 {"image CRC Error", FLASH_UPDATE_CRC_ERR},
374 {"image length Error.", FLASH_UPDATE_LENGTH_ERR},
375 {"Failed to program flash chip", FLASH_UPDATE_HW_ERR},
376 {"Flash chip not supported.", FLASH_UPDATE_DNLD_NOT_SUPPORTED},
377 {"Flash update disabled.", FLASH_UPDATE_DISABLED},
378 {"Flash in progress", FLASH_IN_PROGRESS},
379 {"Image file size Error", FAIL_FILE_SIZE},
380 {"Input parameter error", FAIL_PARAMETERS},
381 {"Out of memory", FAIL_OUT_MEMORY},
382 {"OK", 0} /* Last entry err_code = 0. */
383};
384
385static int pm8001_set_nvmd(struct pm8001_hba_info *pm8001_ha)
386{
387 struct pm8001_ioctl_payload *payload;
388 DECLARE_COMPLETION_ONSTACK(completion);
389 u8 *ioctlbuffer = NULL;
390 u32 length = 0;
391 u32 ret = 0;
392
393 length = 1024 * 5 + sizeof(*payload) - 1;
394 ioctlbuffer = kzalloc(length, GFP_KERNEL);
395 if (!ioctlbuffer)
396 return -ENOMEM;
397 if ((pm8001_ha->fw_image->size <= 0) ||
398 (pm8001_ha->fw_image->size > 4096)) {
399 ret = FAIL_FILE_SIZE;
400 goto out;
401 }
402 payload = (struct pm8001_ioctl_payload *)ioctlbuffer;
403 memcpy((u8 *)payload->func_specific, (u8 *)pm8001_ha->fw_image->data,
404 pm8001_ha->fw_image->size);
405 payload->length = pm8001_ha->fw_image->size;
406 payload->id = 0;
407 pm8001_ha->nvmd_completion = &completion;
408 ret = PM8001_CHIP_DISP->set_nvmd_req(pm8001_ha, payload);
409 wait_for_completion(&completion);
410out:
411 kfree(ioctlbuffer);
412 return ret;
413}
414
415static int pm8001_update_flash(struct pm8001_hba_info *pm8001_ha)
416{
417 struct pm8001_ioctl_payload *payload;
418 DECLARE_COMPLETION_ONSTACK(completion);
419 u8 *ioctlbuffer = NULL;
420 u32 length = 0;
421 struct fw_control_info *fwControl;
422 u32 loopNumber, loopcount = 0;
423 u32 sizeRead = 0;
424 u32 partitionSize, partitionSizeTmp;
425 u32 ret = 0;
426 u32 partitionNumber = 0;
427 struct pm8001_fw_image_header *image_hdr;
428
429 length = 1024 * 16 + sizeof(*payload) - 1;
430 ioctlbuffer = kzalloc(length, GFP_KERNEL);
431 image_hdr = (struct pm8001_fw_image_header *)pm8001_ha->fw_image->data;
432 if (!ioctlbuffer)
433 return -ENOMEM;
434 if (pm8001_ha->fw_image->size < 28) {
435 ret = FAIL_FILE_SIZE;
436 goto out;
437 }
438
439 while (sizeRead < pm8001_ha->fw_image->size) {
440 partitionSizeTmp =
441 *(u32 *)((u8 *)&image_hdr->image_length + sizeRead);
442 partitionSize = be32_to_cpu(partitionSizeTmp);
443 loopcount = (partitionSize + HEADER_LEN)/IOCTL_BUF_SIZE;
444 if (loopcount % IOCTL_BUF_SIZE)
445 loopcount++;
446 if (loopcount == 0)
447 loopcount++;
448 for (loopNumber = 0; loopNumber < loopcount; loopNumber++) {
449 payload = (struct pm8001_ioctl_payload *)ioctlbuffer;
450 payload->length = 1024*16;
451 payload->id = 0;
452 fwControl =
453 (struct fw_control_info *)payload->func_specific;
454 fwControl->len = IOCTL_BUF_SIZE; /* IN */
455 fwControl->size = partitionSize + HEADER_LEN;/* IN */
456 fwControl->retcode = 0;/* OUT */
457 fwControl->offset = loopNumber * IOCTL_BUF_SIZE;/*OUT */
458
459 /* for the last chunk of data in case file size is not even with
460 4k, load only the rest*/
461 if (((loopcount-loopNumber) == 1) &&
462 ((partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE)) {
463 fwControl->len =
464 (partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE;
465 memcpy((u8 *)fwControl->buffer,
466 (u8 *)pm8001_ha->fw_image->data + sizeRead,
467 (partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE);
468 sizeRead +=
469 (partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE;
470 } else {
471 memcpy((u8 *)fwControl->buffer,
472 (u8 *)pm8001_ha->fw_image->data + sizeRead,
473 IOCTL_BUF_SIZE);
474 sizeRead += IOCTL_BUF_SIZE;
475 }
476
477 pm8001_ha->nvmd_completion = &completion;
478 ret = PM8001_CHIP_DISP->fw_flash_update_req(pm8001_ha, payload);
479 wait_for_completion(&completion);
480 if (ret || (fwControl->retcode > FLASH_UPDATE_IN_PROGRESS)) {
481 ret = fwControl->retcode;
482 kfree(ioctlbuffer);
483 ioctlbuffer = NULL;
484 break;
485 }
486 }
487 if (ret)
488 break;
489 partitionNumber++;
490}
491out:
492 kfree(ioctlbuffer);
493 return ret;
494}
495static ssize_t pm8001_store_update_fw(struct device *cdev,
496 struct device_attribute *attr,
497 const char *buf, size_t count)
498{
499 struct Scsi_Host *shost = class_to_shost(cdev);
500 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
501 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
502 char *cmd_ptr, *filename_ptr;
503 int res, i;
504 int flash_command = FLASH_CMD_NONE;
505 int err = 0;
506 if (!capable(CAP_SYS_ADMIN))
507 return -EACCES;
508
509 cmd_ptr = kzalloc(count*2, GFP_KERNEL);
510
511 if (!cmd_ptr) {
512 err = FAIL_OUT_MEMORY;
513 goto out;
514 }
515
516 filename_ptr = cmd_ptr + count;
517 res = sscanf(buf, "%s %s", cmd_ptr, filename_ptr);
518 if (res != 2) {
519 err = FAIL_PARAMETERS;
520 goto out1;
521 }
522
523 for (i = 0; flash_command_table[i].code != FLASH_CMD_NONE; i++) {
524 if (!memcmp(flash_command_table[i].command,
525 cmd_ptr, strlen(cmd_ptr))) {
526 flash_command = flash_command_table[i].code;
527 break;
528 }
529 }
530 if (flash_command == FLASH_CMD_NONE) {
531 err = FAIL_PARAMETERS;
532 goto out1;
533 }
534
535 if (pm8001_ha->fw_status == FLASH_IN_PROGRESS) {
536 err = FLASH_IN_PROGRESS;
537 goto out1;
538 }
539 err = request_firmware(&pm8001_ha->fw_image,
540 filename_ptr,
541 pm8001_ha->dev);
542
543 if (err) {
544 PM8001_FAIL_DBG(pm8001_ha,
545 pm8001_printk("Failed to load firmware image file %s,"
546 " error %d\n", filename_ptr, err));
547 err = FAIL_OPEN_BIOS_FILE;
548 goto out1;
549 }
550
551 switch (flash_command) {
552 case FLASH_CMD_UPDATE:
553 pm8001_ha->fw_status = FLASH_IN_PROGRESS;
554 err = pm8001_update_flash(pm8001_ha);
555 break;
556 case FLASH_CMD_SET_NVMD:
557 pm8001_ha->fw_status = FLASH_IN_PROGRESS;
558 err = pm8001_set_nvmd(pm8001_ha);
559 break;
560 default:
561 pm8001_ha->fw_status = FAIL_PARAMETERS;
562 err = FAIL_PARAMETERS;
563 break;
564 }
565 release_firmware(pm8001_ha->fw_image);
566out1:
567 kfree(cmd_ptr);
568out:
569 pm8001_ha->fw_status = err;
570
571 if (!err)
572 return count;
573 else
574 return -err;
575}
576
577static ssize_t pm8001_show_update_fw(struct device *cdev,
578 struct device_attribute *attr, char *buf)
579{
580 int i;
581 struct Scsi_Host *shost = class_to_shost(cdev);
582 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
583 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
584
585 for (i = 0; flash_error_table[i].err_code != 0; i++) {
586 if (flash_error_table[i].err_code == pm8001_ha->fw_status)
587 break;
588 }
589 if (pm8001_ha->fw_status != FLASH_IN_PROGRESS)
590 pm8001_ha->fw_status = FLASH_OK;
591
592 return snprintf(buf, PAGE_SIZE, "status=%x %s\n",
593 flash_error_table[i].err_code,
594 flash_error_table[i].reason);
595}
596
597static DEVICE_ATTR(update_fw, S_IRUGO|S_IWUGO,
598 pm8001_show_update_fw, pm8001_store_update_fw);
599struct device_attribute *pm8001_host_attrs[] = {
600 &dev_attr_interface_rev,
601 &dev_attr_fw_version,
602 &dev_attr_update_fw,
603 &dev_attr_aap_log,
604 &dev_attr_iop_log,
605 &dev_attr_max_out_io,
606 &dev_attr_max_devices,
607 &dev_attr_max_sg_list,
608 &dev_attr_sas_spec_support,
609 &dev_attr_logging_level,
610 &dev_attr_host_sas_address,
611 NULL,
612};
613