pm8001: Fix erratic calculation in update_flash
[deliverable/linux.git] / drivers / scsi / pm8001 / pm8001_ctl.c
CommitLineData
dbf9bfe6 1/*
e5742101 2 * PMC-Sierra 8001/8081/8088/8089 SAS/SATA based host adapters driver
dbf9bfe6 3 *
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>
5a0e3ad6 41#include <linux/slab.h>
dbf9bfe6 42#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
e5742101
S
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);
64 } else {
65 return snprintf(buf, PAGE_SIZE, "%d\n",
66 pm8001_ha->main_cfg_tbl.pm80xx_tbl.interface_rev);
67 }
dbf9bfe6 68}
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
e5742101
S
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));
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 }
dbf9bfe6 99}
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
e5742101
S
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);
118 } else {
119 return snprintf(buf, PAGE_SIZE, "%d\n",
120 pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_out_io);
121 }
dbf9bfe6 122}
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
e5742101
S
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)
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 }
dbf9bfe6 147}
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
e5742101
S
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
167 );
168 } else {
169 return snprintf(buf, PAGE_SIZE, "%04d\n",
170 pm8001_ha->main_cfg_tbl.pm80xx_tbl.max_sgl & 0x0000FFFF
171 );
172 }
dbf9bfe6 173}
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;
e5742101
S
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 &
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;
dbf9bfe6 216 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);
d078b511
AKS
311/**
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.
316 */
317static ssize_t pm8001_ctl_ib_queue_log_show(struct device *cdev,
318 struct device_attribute *attr, char *buf)
319{
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;
323 int offset;
324 char *str = buf;
325 int start = 0;
859b5d10
V
326#define IB_MEMMAP(c) \
327 (*(u32 *)((u8 *)pm8001_ha-> \
328 memoryMap.region[IB].virt_ptr + \
d078b511
AKS
329 pm8001_ha->evtlog_ib_offset + (c)))
330
331 for (offset = 0; offset < IB_OB_READ_TIMES; offset++) {
859b5d10 332 str += sprintf(str, "0x%08x\n", IB_MEMMAP(start));
d078b511
AKS
333 start = start + 4;
334 }
335 pm8001_ha->evtlog_ib_offset += SYSFS_OFFSET;
859b5d10 336 if (((pm8001_ha->evtlog_ib_offset) % (PM80XX_IB_OB_QUEUE_SIZE)) == 0)
d078b511
AKS
337 pm8001_ha->evtlog_ib_offset = 0;
338
339 return str - buf;
340}
341
342static DEVICE_ATTR(ib_log, S_IRUGO, pm8001_ctl_ib_queue_log_show, NULL);
343/**
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.
348 */
349
350static ssize_t pm8001_ctl_ob_queue_log_show(struct device *cdev,
351 struct device_attribute *attr, char *buf)
352{
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;
356 int offset;
357 char *str = buf;
358 int start = 0;
859b5d10
V
359#define OB_MEMMAP(c) \
360 (*(u32 *)((u8 *)pm8001_ha-> \
361 memoryMap.region[OB].virt_ptr + \
d078b511
AKS
362 pm8001_ha->evtlog_ob_offset + (c)))
363
364 for (offset = 0; offset < IB_OB_READ_TIMES; offset++) {
859b5d10 365 str += sprintf(str, "0x%08x\n", OB_MEMMAP(start));
d078b511
AKS
366 start = start + 4;
367 }
368 pm8001_ha->evtlog_ob_offset += SYSFS_OFFSET;
859b5d10 369 if (((pm8001_ha->evtlog_ob_offset) % (PM80XX_IB_OB_QUEUE_SIZE)) == 0)
d078b511
AKS
370 pm8001_ha->evtlog_ob_offset = 0;
371
372 return str - buf;
373}
374static DEVICE_ATTR(ob_log, S_IRUGO, pm8001_ctl_ob_queue_log_show, NULL);
966fdcff
AKS
375/**
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.
380 */
381static ssize_t pm8001_ctl_bios_version_show(struct device *cdev,
382 struct device_attribute *attr, char *buf)
383{
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;
387 char *str = buf;
388 void *virt_addr;
389 int bios_index;
390 DECLARE_COMPLETION_ONSTACK(completion);
391 struct pm8001_ioctl_payload payload;
392
393 pm8001_ha->nvmd_completion = &completion;
394 payload.minor_function = 7;
395 payload.offset = 0;
396 payload.length = 4096;
397 payload.func_specific = kzalloc(4096, GFP_KERNEL);
b42939aa
ST
398 if (!payload.func_specific)
399 return -ENOMEM;
5b4ce882
TH
400 if (PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload)) {
401 kfree(payload.func_specific);
402 return -ENOMEM;
403 }
966fdcff
AKS
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;
407 bios_index++)
408 str += sprintf(str, "%c",
409 *((u8 *)((u8 *)virt_addr+bios_index)));
b42939aa 410 kfree(payload.func_specific);
966fdcff
AKS
411 return str - buf;
412}
413static DEVICE_ATTR(bios_version, S_IRUGO, pm8001_ctl_bios_version_show, NULL);
dbf9bfe6 414/**
415 * pm8001_ctl_aap_log_show - IOP event log
416 * @cdev: pointer to embedded class device
417 * @buf: the buffer returned
418 *
419 * A sysfs 'read-only' shost attribute.
420 */
421static ssize_t pm8001_ctl_iop_log_show(struct device *cdev,
422 struct device_attribute *attr, char *buf)
423{
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 \
429 + (c)))
430 int i;
431 char *str = buf;
432 int max = 2;
433 for (i = 0; i < max; i++) {
434 str += sprintf(str, "0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x"
435 "0x%08x 0x%08x\n",
436 IOP_MEMMAP(i, 0),
437 IOP_MEMMAP(i, 4),
438 IOP_MEMMAP(i, 8),
439 IOP_MEMMAP(i, 12),
440 IOP_MEMMAP(i, 16),
441 IOP_MEMMAP(i, 20),
442 IOP_MEMMAP(i, 24),
443 IOP_MEMMAP(i, 28));
444 }
445
446 return str - buf;
447}
448static DEVICE_ATTR(iop_log, S_IRUGO, pm8001_ctl_iop_log_show, NULL);
449
d078b511
AKS
450/**
451 ** pm8001_ctl_fatal_log_show - fatal error logging
452 ** @cdev:pointer to embedded class device
453 ** @buf: the buffer returned
454 **
455 ** A sysfs 'read-only' shost attribute.
456 **/
457
458static ssize_t pm8001_ctl_fatal_log_show(struct device *cdev,
459 struct device_attribute *attr, char *buf)
460{
cf370066 461 ssize_t count;
d078b511
AKS
462
463 count = pm80xx_get_fatal_dump(cdev, attr, buf);
464 return count;
465}
466
467static DEVICE_ATTR(fatal_log, S_IRUGO, pm8001_ctl_fatal_log_show, NULL);
468
469
470/**
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.
475 **/
476static ssize_t pm8001_ctl_gsm_log_show(struct device *cdev,
477 struct device_attribute *attr, char *buf)
478{
cf370066 479 ssize_t count;
d078b511
AKS
480
481 count = pm8001_get_gsm_dump(cdev, SYSFS_OFFSET, buf);
482 return count;
483}
484
485static DEVICE_ATTR(gsm_log, S_IRUGO, pm8001_ctl_gsm_log_show, NULL);
486
dbf9bfe6 487#define FLASH_CMD_NONE 0x00
488#define FLASH_CMD_UPDATE 0x01
489#define FLASH_CMD_SET_NVMD 0x02
490
491struct flash_command {
492 u8 command[8];
493 int code;
494};
495
496static struct flash_command flash_command_table[] =
497{
498 {"set_nvmd", FLASH_CMD_SET_NVMD},
499 {"update", FLASH_CMD_UPDATE},
500 {"", FLASH_CMD_NONE} /* Last entry should be NULL. */
501};
502
503struct error_fw {
504 char *reason;
505 int err_code;
506};
507
508static struct error_fw flash_error_table[] =
509{
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. */
523};
524
525static int pm8001_set_nvmd(struct pm8001_hba_info *pm8001_ha)
526{
527 struct pm8001_ioctl_payload *payload;
528 DECLARE_COMPLETION_ONSTACK(completion);
529 u8 *ioctlbuffer = NULL;
530 u32 length = 0;
531 u32 ret = 0;
532
533 length = 1024 * 5 + sizeof(*payload) - 1;
534 ioctlbuffer = kzalloc(length, GFP_KERNEL);
535 if (!ioctlbuffer)
536 return -ENOMEM;
537 if ((pm8001_ha->fw_image->size <= 0) ||
538 (pm8001_ha->fw_image->size > 4096)) {
539 ret = FAIL_FILE_SIZE;
540 goto out;
541 }
542 payload = (struct pm8001_ioctl_payload *)ioctlbuffer;
1c75a679 543 memcpy((u8 *)&payload->func_specific, (u8 *)pm8001_ha->fw_image->data,
dbf9bfe6 544 pm8001_ha->fw_image->size);
545 payload->length = pm8001_ha->fw_image->size;
546 payload->id = 0;
1c75a679 547 payload->minor_function = 0x1;
dbf9bfe6 548 pm8001_ha->nvmd_completion = &completion;
549 ret = PM8001_CHIP_DISP->set_nvmd_req(pm8001_ha, payload);
550 wait_for_completion(&completion);
551out:
552 kfree(ioctlbuffer);
553 return ret;
554}
555
556static int pm8001_update_flash(struct pm8001_hba_info *pm8001_ha)
557{
558 struct pm8001_ioctl_payload *payload;
559 DECLARE_COMPLETION_ONSTACK(completion);
560 u8 *ioctlbuffer = NULL;
561 u32 length = 0;
562 struct fw_control_info *fwControl;
563 u32 loopNumber, loopcount = 0;
564 u32 sizeRead = 0;
565 u32 partitionSize, partitionSizeTmp;
566 u32 ret = 0;
567 u32 partitionNumber = 0;
568 struct pm8001_fw_image_header *image_hdr;
569
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;
573 if (!ioctlbuffer)
574 return -ENOMEM;
575 if (pm8001_ha->fw_image->size < 28) {
576 ret = FAIL_FILE_SIZE;
577 goto out;
578 }
579
580 while (sizeRead < pm8001_ha->fw_image->size) {
581 partitionSizeTmp =
582 *(u32 *)((u8 *)&image_hdr->image_length + sizeRead);
583 partitionSize = be32_to_cpu(partitionSizeTmp);
5bd355ee
TH
584 loopcount = DIV_ROUND_UP(partitionSize + HEADER_LEN,
585 IOCTL_BUF_SIZE);
dbf9bfe6 586 for (loopNumber = 0; loopNumber < loopcount; loopNumber++) {
587 payload = (struct pm8001_ioctl_payload *)ioctlbuffer;
588 payload->length = 1024*16;
589 payload->id = 0;
590 fwControl =
1c75a679 591 (struct fw_control_info *)&payload->func_specific;
dbf9bfe6 592 fwControl->len = IOCTL_BUF_SIZE; /* IN */
593 fwControl->size = partitionSize + HEADER_LEN;/* IN */
594 fwControl->retcode = 0;/* OUT */
595 fwControl->offset = loopNumber * IOCTL_BUF_SIZE;/*OUT */
596
597 /* for the last chunk of data in case file size is not even with
598 4k, load only the rest*/
599 if (((loopcount-loopNumber) == 1) &&
600 ((partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE)) {
601 fwControl->len =
602 (partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE;
603 memcpy((u8 *)fwControl->buffer,
604 (u8 *)pm8001_ha->fw_image->data + sizeRead,
605 (partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE);
606 sizeRead +=
607 (partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE;
608 } else {
609 memcpy((u8 *)fwControl->buffer,
610 (u8 *)pm8001_ha->fw_image->data + sizeRead,
611 IOCTL_BUF_SIZE);
612 sizeRead += IOCTL_BUF_SIZE;
613 }
614
615 pm8001_ha->nvmd_completion = &completion;
616 ret = PM8001_CHIP_DISP->fw_flash_update_req(pm8001_ha, payload);
31d05e5b
TH
617 if (ret)
618 break;
dbf9bfe6 619 wait_for_completion(&completion);
31d05e5b 620 if (fwControl->retcode > FLASH_UPDATE_IN_PROGRESS) {
dbf9bfe6 621 ret = fwControl->retcode;
dbf9bfe6 622 break;
623 }
624 }
625 if (ret)
626 break;
627 partitionNumber++;
628}
629out:
630 kfree(ioctlbuffer);
631 return ret;
632}
633static ssize_t pm8001_store_update_fw(struct device *cdev,
634 struct device_attribute *attr,
635 const char *buf, size_t count)
636{
637 struct Scsi_Host *shost = class_to_shost(cdev);
638 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
639 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
640 char *cmd_ptr, *filename_ptr;
641 int res, i;
642 int flash_command = FLASH_CMD_NONE;
643 int err = 0;
644 if (!capable(CAP_SYS_ADMIN))
645 return -EACCES;
646
647 cmd_ptr = kzalloc(count*2, GFP_KERNEL);
648
649 if (!cmd_ptr) {
650 err = FAIL_OUT_MEMORY;
651 goto out;
652 }
653
654 filename_ptr = cmd_ptr + count;
655 res = sscanf(buf, "%s %s", cmd_ptr, filename_ptr);
656 if (res != 2) {
657 err = FAIL_PARAMETERS;
658 goto out1;
659 }
660
661 for (i = 0; flash_command_table[i].code != FLASH_CMD_NONE; i++) {
662 if (!memcmp(flash_command_table[i].command,
663 cmd_ptr, strlen(cmd_ptr))) {
664 flash_command = flash_command_table[i].code;
665 break;
666 }
667 }
668 if (flash_command == FLASH_CMD_NONE) {
669 err = FAIL_PARAMETERS;
670 goto out1;
671 }
672
673 if (pm8001_ha->fw_status == FLASH_IN_PROGRESS) {
674 err = FLASH_IN_PROGRESS;
675 goto out1;
676 }
677 err = request_firmware(&pm8001_ha->fw_image,
678 filename_ptr,
679 pm8001_ha->dev);
680
681 if (err) {
682 PM8001_FAIL_DBG(pm8001_ha,
683 pm8001_printk("Failed to load firmware image file %s,"
684 " error %d\n", filename_ptr, err));
685 err = FAIL_OPEN_BIOS_FILE;
686 goto out1;
687 }
688
689 switch (flash_command) {
690 case FLASH_CMD_UPDATE:
691 pm8001_ha->fw_status = FLASH_IN_PROGRESS;
692 err = pm8001_update_flash(pm8001_ha);
693 break;
694 case FLASH_CMD_SET_NVMD:
695 pm8001_ha->fw_status = FLASH_IN_PROGRESS;
696 err = pm8001_set_nvmd(pm8001_ha);
697 break;
698 default:
699 pm8001_ha->fw_status = FAIL_PARAMETERS;
700 err = FAIL_PARAMETERS;
701 break;
702 }
703 release_firmware(pm8001_ha->fw_image);
704out1:
705 kfree(cmd_ptr);
706out:
707 pm8001_ha->fw_status = err;
708
709 if (!err)
710 return count;
711 else
712 return -err;
713}
714
715static ssize_t pm8001_show_update_fw(struct device *cdev,
716 struct device_attribute *attr, char *buf)
717{
718 int i;
719 struct Scsi_Host *shost = class_to_shost(cdev);
720 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
721 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
722
723 for (i = 0; flash_error_table[i].err_code != 0; i++) {
724 if (flash_error_table[i].err_code == pm8001_ha->fw_status)
725 break;
726 }
727 if (pm8001_ha->fw_status != FLASH_IN_PROGRESS)
728 pm8001_ha->fw_status = FLASH_OK;
729
730 return snprintf(buf, PAGE_SIZE, "status=%x %s\n",
731 flash_error_table[i].err_code,
732 flash_error_table[i].reason);
733}
734
332e2b4f 735static DEVICE_ATTR(update_fw, S_IRUGO|S_IWUSR|S_IWGRP,
dbf9bfe6 736 pm8001_show_update_fw, pm8001_store_update_fw);
737struct device_attribute *pm8001_host_attrs[] = {
738 &dev_attr_interface_rev,
739 &dev_attr_fw_version,
740 &dev_attr_update_fw,
741 &dev_attr_aap_log,
742 &dev_attr_iop_log,
d078b511
AKS
743 &dev_attr_fatal_log,
744 &dev_attr_gsm_log,
dbf9bfe6 745 &dev_attr_max_out_io,
746 &dev_attr_max_devices,
747 &dev_attr_max_sg_list,
748 &dev_attr_sas_spec_support,
749 &dev_attr_logging_level,
750 &dev_attr_host_sas_address,
966fdcff 751 &dev_attr_bios_version,
d078b511
AKS
752 &dev_attr_ib_log,
753 &dev_attr_ob_log,
dbf9bfe6 754 NULL,
755};
756
This page took 0.389297 seconds and 5 git commands to generate.