Loading...
1/*
2 * PMC-Sierra SPC 8001 SAS/SATA based host adapters driver
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>
41#include <linux/slab.h>
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
61 return snprintf(buf, PAGE_SIZE, "%d\n",
62 pm8001_ha->main_cfg_tbl.interface_rev);
63}
64static
65DEVICE_ATTR(interface_rev, S_IRUGO, pm8001_ctl_mpi_interface_rev_show, NULL);
66
67/**
68 * pm8001_ctl_fw_version_show - firmware version
69 * @cdev: pointer to embedded class device
70 * @buf: the buffer returned
71 *
72 * A sysfs 'read-only' shost attribute.
73 */
74static ssize_t pm8001_ctl_fw_version_show(struct device *cdev,
75 struct device_attribute *attr, char *buf)
76{
77 struct Scsi_Host *shost = class_to_shost(cdev);
78 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
79 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
80
81 return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x.%02x\n",
82 (u8)(pm8001_ha->main_cfg_tbl.firmware_rev >> 24),
83 (u8)(pm8001_ha->main_cfg_tbl.firmware_rev >> 16),
84 (u8)(pm8001_ha->main_cfg_tbl.firmware_rev >> 8),
85 (u8)(pm8001_ha->main_cfg_tbl.firmware_rev));
86}
87static DEVICE_ATTR(fw_version, S_IRUGO, pm8001_ctl_fw_version_show, NULL);
88/**
89 * pm8001_ctl_max_out_io_show - max outstanding io supported
90 * @cdev: pointer to embedded class device
91 * @buf: the buffer returned
92 *
93 * A sysfs 'read-only' shost attribute.
94 */
95static ssize_t pm8001_ctl_max_out_io_show(struct device *cdev,
96 struct device_attribute *attr, char *buf)
97{
98 struct Scsi_Host *shost = class_to_shost(cdev);
99 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
100 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
101
102 return snprintf(buf, PAGE_SIZE, "%d\n",
103 pm8001_ha->main_cfg_tbl.max_out_io);
104}
105static DEVICE_ATTR(max_out_io, S_IRUGO, pm8001_ctl_max_out_io_show, NULL);
106/**
107 * pm8001_ctl_max_devices_show - max devices support
108 * @cdev: pointer to embedded class device
109 * @buf: the buffer returned
110 *
111 * A sysfs 'read-only' shost attribute.
112 */
113static ssize_t pm8001_ctl_max_devices_show(struct device *cdev,
114 struct device_attribute *attr, char *buf)
115{
116 struct Scsi_Host *shost = class_to_shost(cdev);
117 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
118 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
119
120 return snprintf(buf, PAGE_SIZE, "%04d\n",
121 (u16)(pm8001_ha->main_cfg_tbl.max_sgl >> 16));
122}
123static DEVICE_ATTR(max_devices, S_IRUGO, pm8001_ctl_max_devices_show, NULL);
124/**
125 * pm8001_ctl_max_sg_list_show - max sg list supported iff not 0.0 for no
126 * hardware limitation
127 * @cdev: pointer to embedded class device
128 * @buf: the buffer returned
129 *
130 * A sysfs 'read-only' shost attribute.
131 */
132static ssize_t pm8001_ctl_max_sg_list_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 return snprintf(buf, PAGE_SIZE, "%04d\n",
140 pm8001_ha->main_cfg_tbl.max_sgl & 0x0000FFFF);
141}
142static DEVICE_ATTR(max_sg_list, S_IRUGO, pm8001_ctl_max_sg_list_show, NULL);
143
144#define SAS_1_0 0x1
145#define SAS_1_1 0x2
146#define SAS_2_0 0x4
147
148static ssize_t
149show_sas_spec_support_status(unsigned int mode, char *buf)
150{
151 ssize_t len = 0;
152
153 if (mode & SAS_1_1)
154 len = sprintf(buf, "%s", "SAS1.1");
155 if (mode & SAS_2_0)
156 len += sprintf(buf + len, "%s%s", len ? ", " : "", "SAS2.0");
157 len += sprintf(buf + len, "\n");
158
159 return len;
160}
161
162/**
163 * pm8001_ctl_sas_spec_support_show - sas spec supported
164 * @cdev: pointer to embedded class device
165 * @buf: the buffer returned
166 *
167 * A sysfs 'read-only' shost attribute.
168 */
169static ssize_t pm8001_ctl_sas_spec_support_show(struct device *cdev,
170 struct device_attribute *attr, char *buf)
171{
172 unsigned int mode;
173 struct Scsi_Host *shost = class_to_shost(cdev);
174 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
175 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
176 mode = (pm8001_ha->main_cfg_tbl.ctrl_cap_flag & 0xfe000000)>>25;
177 return show_sas_spec_support_status(mode, buf);
178}
179static DEVICE_ATTR(sas_spec_support, S_IRUGO,
180 pm8001_ctl_sas_spec_support_show, NULL);
181
182/**
183 * pm8001_ctl_sas_address_show - sas address
184 * @cdev: pointer to embedded class device
185 * @buf: the buffer returned
186 *
187 * This is the controller sas address
188 *
189 * A sysfs 'read-only' shost attribute.
190 */
191static ssize_t pm8001_ctl_host_sas_address_show(struct device *cdev,
192 struct device_attribute *attr, char *buf)
193{
194 struct Scsi_Host *shost = class_to_shost(cdev);
195 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
196 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
197 return snprintf(buf, PAGE_SIZE, "0x%016llx\n",
198 be64_to_cpu(*(__be64 *)pm8001_ha->sas_addr));
199}
200static DEVICE_ATTR(host_sas_address, S_IRUGO,
201 pm8001_ctl_host_sas_address_show, NULL);
202
203/**
204 * pm8001_ctl_logging_level_show - logging level
205 * @cdev: pointer to embedded class device
206 * @buf: the buffer returned
207 *
208 * A sysfs 'read/write' shost attribute.
209 */
210static ssize_t pm8001_ctl_logging_level_show(struct device *cdev,
211 struct device_attribute *attr, char *buf)
212{
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;
216
217 return snprintf(buf, PAGE_SIZE, "%08xh\n", pm8001_ha->logging_level);
218}
219static ssize_t pm8001_ctl_logging_level_store(struct device *cdev,
220 struct device_attribute *attr, const char *buf, size_t count)
221{
222 struct Scsi_Host *shost = class_to_shost(cdev);
223 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
224 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
225 int val = 0;
226
227 if (sscanf(buf, "%x", &val) != 1)
228 return -EINVAL;
229
230 pm8001_ha->logging_level = val;
231 return strlen(buf);
232}
233
234static DEVICE_ATTR(logging_level, S_IRUGO | S_IWUSR,
235 pm8001_ctl_logging_level_show, pm8001_ctl_logging_level_store);
236/**
237 * pm8001_ctl_aap_log_show - aap1 event log
238 * @cdev: pointer to embedded class device
239 * @buf: the buffer returned
240 *
241 * A sysfs 'read-only' shost attribute.
242 */
243static ssize_t pm8001_ctl_aap_log_show(struct device *cdev,
244 struct device_attribute *attr, char *buf)
245{
246 struct Scsi_Host *shost = class_to_shost(cdev);
247 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
248 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
249 int i;
250#define AAP1_MEMMAP(r, c) \
251 (*(u32 *)((u8*)pm8001_ha->memoryMap.region[AAP1].virt_ptr + (r) * 32 \
252 + (c)))
253
254 char *str = buf;
255 int max = 2;
256 for (i = 0; i < max; i++) {
257 str += sprintf(str, "0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x"
258 "0x%08x 0x%08x\n",
259 AAP1_MEMMAP(i, 0),
260 AAP1_MEMMAP(i, 4),
261 AAP1_MEMMAP(i, 8),
262 AAP1_MEMMAP(i, 12),
263 AAP1_MEMMAP(i, 16),
264 AAP1_MEMMAP(i, 20),
265 AAP1_MEMMAP(i, 24),
266 AAP1_MEMMAP(i, 28));
267 }
268
269 return str - buf;
270}
271static DEVICE_ATTR(aap_log, S_IRUGO, pm8001_ctl_aap_log_show, NULL);
272/**
273 * pm8001_ctl_aap_log_show - IOP event log
274 * @cdev: pointer to embedded class device
275 * @buf: the buffer returned
276 *
277 * A sysfs 'read-only' shost attribute.
278 */
279static ssize_t pm8001_ctl_iop_log_show(struct device *cdev,
280 struct device_attribute *attr, char *buf)
281{
282 struct Scsi_Host *shost = class_to_shost(cdev);
283 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
284 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
285#define IOP_MEMMAP(r, c) \
286 (*(u32 *)((u8*)pm8001_ha->memoryMap.region[IOP].virt_ptr + (r) * 32 \
287 + (c)))
288 int i;
289 char *str = buf;
290 int max = 2;
291 for (i = 0; i < max; i++) {
292 str += sprintf(str, "0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x"
293 "0x%08x 0x%08x\n",
294 IOP_MEMMAP(i, 0),
295 IOP_MEMMAP(i, 4),
296 IOP_MEMMAP(i, 8),
297 IOP_MEMMAP(i, 12),
298 IOP_MEMMAP(i, 16),
299 IOP_MEMMAP(i, 20),
300 IOP_MEMMAP(i, 24),
301 IOP_MEMMAP(i, 28));
302 }
303
304 return str - buf;
305}
306static DEVICE_ATTR(iop_log, S_IRUGO, pm8001_ctl_iop_log_show, NULL);
307
308#define FLASH_CMD_NONE 0x00
309#define FLASH_CMD_UPDATE 0x01
310#define FLASH_CMD_SET_NVMD 0x02
311
312struct flash_command {
313 u8 command[8];
314 int code;
315};
316
317static struct flash_command flash_command_table[] =
318{
319 {"set_nvmd", FLASH_CMD_SET_NVMD},
320 {"update", FLASH_CMD_UPDATE},
321 {"", FLASH_CMD_NONE} /* Last entry should be NULL. */
322};
323
324struct error_fw {
325 char *reason;
326 int err_code;
327};
328
329static struct error_fw flash_error_table[] =
330{
331 {"Failed to open fw image file", FAIL_OPEN_BIOS_FILE},
332 {"image header mismatch", FLASH_UPDATE_HDR_ERR},
333 {"image offset mismatch", FLASH_UPDATE_OFFSET_ERR},
334 {"image CRC Error", FLASH_UPDATE_CRC_ERR},
335 {"image length Error.", FLASH_UPDATE_LENGTH_ERR},
336 {"Failed to program flash chip", FLASH_UPDATE_HW_ERR},
337 {"Flash chip not supported.", FLASH_UPDATE_DNLD_NOT_SUPPORTED},
338 {"Flash update disabled.", FLASH_UPDATE_DISABLED},
339 {"Flash in progress", FLASH_IN_PROGRESS},
340 {"Image file size Error", FAIL_FILE_SIZE},
341 {"Input parameter error", FAIL_PARAMETERS},
342 {"Out of memory", FAIL_OUT_MEMORY},
343 {"OK", 0} /* Last entry err_code = 0. */
344};
345
346static int pm8001_set_nvmd(struct pm8001_hba_info *pm8001_ha)
347{
348 struct pm8001_ioctl_payload *payload;
349 DECLARE_COMPLETION_ONSTACK(completion);
350 u8 *ioctlbuffer = NULL;
351 u32 length = 0;
352 u32 ret = 0;
353
354 length = 1024 * 5 + sizeof(*payload) - 1;
355 ioctlbuffer = kzalloc(length, GFP_KERNEL);
356 if (!ioctlbuffer)
357 return -ENOMEM;
358 if ((pm8001_ha->fw_image->size <= 0) ||
359 (pm8001_ha->fw_image->size > 4096)) {
360 ret = FAIL_FILE_SIZE;
361 goto out;
362 }
363 payload = (struct pm8001_ioctl_payload *)ioctlbuffer;
364 memcpy((u8 *)payload->func_specific, (u8 *)pm8001_ha->fw_image->data,
365 pm8001_ha->fw_image->size);
366 payload->length = pm8001_ha->fw_image->size;
367 payload->id = 0;
368 pm8001_ha->nvmd_completion = &completion;
369 ret = PM8001_CHIP_DISP->set_nvmd_req(pm8001_ha, payload);
370 wait_for_completion(&completion);
371out:
372 kfree(ioctlbuffer);
373 return ret;
374}
375
376static int pm8001_update_flash(struct pm8001_hba_info *pm8001_ha)
377{
378 struct pm8001_ioctl_payload *payload;
379 DECLARE_COMPLETION_ONSTACK(completion);
380 u8 *ioctlbuffer = NULL;
381 u32 length = 0;
382 struct fw_control_info *fwControl;
383 u32 loopNumber, loopcount = 0;
384 u32 sizeRead = 0;
385 u32 partitionSize, partitionSizeTmp;
386 u32 ret = 0;
387 u32 partitionNumber = 0;
388 struct pm8001_fw_image_header *image_hdr;
389
390 length = 1024 * 16 + sizeof(*payload) - 1;
391 ioctlbuffer = kzalloc(length, GFP_KERNEL);
392 image_hdr = (struct pm8001_fw_image_header *)pm8001_ha->fw_image->data;
393 if (!ioctlbuffer)
394 return -ENOMEM;
395 if (pm8001_ha->fw_image->size < 28) {
396 ret = FAIL_FILE_SIZE;
397 goto out;
398 }
399
400 while (sizeRead < pm8001_ha->fw_image->size) {
401 partitionSizeTmp =
402 *(u32 *)((u8 *)&image_hdr->image_length + sizeRead);
403 partitionSize = be32_to_cpu(partitionSizeTmp);
404 loopcount = (partitionSize + HEADER_LEN)/IOCTL_BUF_SIZE;
405 if (loopcount % IOCTL_BUF_SIZE)
406 loopcount++;
407 if (loopcount == 0)
408 loopcount++;
409 for (loopNumber = 0; loopNumber < loopcount; loopNumber++) {
410 payload = (struct pm8001_ioctl_payload *)ioctlbuffer;
411 payload->length = 1024*16;
412 payload->id = 0;
413 fwControl =
414 (struct fw_control_info *)payload->func_specific;
415 fwControl->len = IOCTL_BUF_SIZE; /* IN */
416 fwControl->size = partitionSize + HEADER_LEN;/* IN */
417 fwControl->retcode = 0;/* OUT */
418 fwControl->offset = loopNumber * IOCTL_BUF_SIZE;/*OUT */
419
420 /* for the last chunk of data in case file size is not even with
421 4k, load only the rest*/
422 if (((loopcount-loopNumber) == 1) &&
423 ((partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE)) {
424 fwControl->len =
425 (partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE;
426 memcpy((u8 *)fwControl->buffer,
427 (u8 *)pm8001_ha->fw_image->data + sizeRead,
428 (partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE);
429 sizeRead +=
430 (partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE;
431 } else {
432 memcpy((u8 *)fwControl->buffer,
433 (u8 *)pm8001_ha->fw_image->data + sizeRead,
434 IOCTL_BUF_SIZE);
435 sizeRead += IOCTL_BUF_SIZE;
436 }
437
438 pm8001_ha->nvmd_completion = &completion;
439 ret = PM8001_CHIP_DISP->fw_flash_update_req(pm8001_ha, payload);
440 wait_for_completion(&completion);
441 if (ret || (fwControl->retcode > FLASH_UPDATE_IN_PROGRESS)) {
442 ret = fwControl->retcode;
443 kfree(ioctlbuffer);
444 ioctlbuffer = NULL;
445 break;
446 }
447 }
448 if (ret)
449 break;
450 partitionNumber++;
451}
452out:
453 kfree(ioctlbuffer);
454 return ret;
455}
456static ssize_t pm8001_store_update_fw(struct device *cdev,
457 struct device_attribute *attr,
458 const char *buf, size_t count)
459{
460 struct Scsi_Host *shost = class_to_shost(cdev);
461 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
462 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
463 char *cmd_ptr, *filename_ptr;
464 int res, i;
465 int flash_command = FLASH_CMD_NONE;
466 int err = 0;
467 if (!capable(CAP_SYS_ADMIN))
468 return -EACCES;
469
470 cmd_ptr = kzalloc(count*2, GFP_KERNEL);
471
472 if (!cmd_ptr) {
473 err = FAIL_OUT_MEMORY;
474 goto out;
475 }
476
477 filename_ptr = cmd_ptr + count;
478 res = sscanf(buf, "%s %s", cmd_ptr, filename_ptr);
479 if (res != 2) {
480 err = FAIL_PARAMETERS;
481 goto out1;
482 }
483
484 for (i = 0; flash_command_table[i].code != FLASH_CMD_NONE; i++) {
485 if (!memcmp(flash_command_table[i].command,
486 cmd_ptr, strlen(cmd_ptr))) {
487 flash_command = flash_command_table[i].code;
488 break;
489 }
490 }
491 if (flash_command == FLASH_CMD_NONE) {
492 err = FAIL_PARAMETERS;
493 goto out1;
494 }
495
496 if (pm8001_ha->fw_status == FLASH_IN_PROGRESS) {
497 err = FLASH_IN_PROGRESS;
498 goto out1;
499 }
500 err = request_firmware(&pm8001_ha->fw_image,
501 filename_ptr,
502 pm8001_ha->dev);
503
504 if (err) {
505 PM8001_FAIL_DBG(pm8001_ha,
506 pm8001_printk("Failed to load firmware image file %s,"
507 " error %d\n", filename_ptr, err));
508 err = FAIL_OPEN_BIOS_FILE;
509 goto out1;
510 }
511
512 switch (flash_command) {
513 case FLASH_CMD_UPDATE:
514 pm8001_ha->fw_status = FLASH_IN_PROGRESS;
515 err = pm8001_update_flash(pm8001_ha);
516 break;
517 case FLASH_CMD_SET_NVMD:
518 pm8001_ha->fw_status = FLASH_IN_PROGRESS;
519 err = pm8001_set_nvmd(pm8001_ha);
520 break;
521 default:
522 pm8001_ha->fw_status = FAIL_PARAMETERS;
523 err = FAIL_PARAMETERS;
524 break;
525 }
526 release_firmware(pm8001_ha->fw_image);
527out1:
528 kfree(cmd_ptr);
529out:
530 pm8001_ha->fw_status = err;
531
532 if (!err)
533 return count;
534 else
535 return -err;
536}
537
538static ssize_t pm8001_show_update_fw(struct device *cdev,
539 struct device_attribute *attr, char *buf)
540{
541 int i;
542 struct Scsi_Host *shost = class_to_shost(cdev);
543 struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
544 struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
545
546 for (i = 0; flash_error_table[i].err_code != 0; i++) {
547 if (flash_error_table[i].err_code == pm8001_ha->fw_status)
548 break;
549 }
550 if (pm8001_ha->fw_status != FLASH_IN_PROGRESS)
551 pm8001_ha->fw_status = FLASH_OK;
552
553 return snprintf(buf, PAGE_SIZE, "status=%x %s\n",
554 flash_error_table[i].err_code,
555 flash_error_table[i].reason);
556}
557
558static DEVICE_ATTR(update_fw, S_IRUGO|S_IWUGO,
559 pm8001_show_update_fw, pm8001_store_update_fw);
560struct device_attribute *pm8001_host_attrs[] = {
561 &dev_attr_interface_rev,
562 &dev_attr_fw_version,
563 &dev_attr_update_fw,
564 &dev_attr_aap_log,
565 &dev_attr_iop_log,
566 &dev_attr_max_out_io,
567 &dev_attr_max_devices,
568 &dev_attr_max_sg_list,
569 &dev_attr_sas_spec_support,
570 &dev_attr_logging_level,
571 &dev_attr_host_sas_address,
572 NULL,
573};
574
1/*
2 * PMC-Sierra 8001/8081/8088/8089 SAS/SATA based host adapters driver
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>
41#include <linux/slab.h>
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 * @attr: device attribute (unused)
51 * @buf: the buffer returned
52 *
53 * A sysfs 'read-only' shost attribute.
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 * controller_fatal_error_show - check controller is under fatal err
75 * @cdev: pointer to embedded class device
76 * @attr: device attribute (unused)
77 * @buf: the buffer returned
78 *
79 * A sysfs 'read only' shost attribute.
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 * pm8001_ctl_fw_version_show - firmware version
95 * @cdev: pointer to embedded class device
96 * @attr: device attribute (unused)
97 * @buf: the buffer returned
98 *
99 * A sysfs 'read-only' shost attribute.
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 * pm8001_ctl_ila_version_show - ila version
126 * @cdev: pointer to embedded class device
127 * @attr: device attribute (unused)
128 * @buf: the buffer returned
129 *
130 * A sysfs 'read-only' shost attribute.
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 * pm8001_ctl_inactive_fw_version_show - Inacative firmware version number
152 * @cdev: pointer to embedded class device
153 * @attr: device attribute (unused)
154 * @buf: the buffer returned
155 *
156 * A sysfs 'read-only' shost attribute.
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 * pm8001_ctl_max_out_io_show - max outstanding io supported
179 * @cdev: pointer to embedded class device
180 * @attr: device attribute (unused)
181 * @buf: the buffer returned
182 *
183 * A sysfs 'read-only' shost attribute.
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 * pm8001_ctl_max_devices_show - max devices support
203 * @cdev: pointer to embedded class device
204 * @attr: device attribute (unused)
205 * @buf: the buffer returned
206 *
207 * A sysfs 'read-only' shost attribute.
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 * pm8001_ctl_max_sg_list_show - max sg list supported iff not 0.0 for no
229 * hardware limitation
230 * @cdev: pointer to embedded class device
231 * @attr: device attribute (unused)
232 * @buf: the buffer returned
233 *
234 * A sysfs 'read-only' shost attribute.
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 * pm8001_ctl_sas_spec_support_show - sas spec supported
275 * @cdev: pointer to embedded class device
276 * @attr: device attribute (unused)
277 * @buf: the buffer returned
278 *
279 * A sysfs 'read-only' shost attribute.
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 /* fe000000 means supports SAS2.1 */
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 /* fe000000 means supports SAS2.1 */
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 * pm8001_ctl_sas_address_show - sas address
303 * @cdev: pointer to embedded class device
304 * @attr: device attribute (unused)
305 * @buf: the buffer returned
306 *
307 * This is the controller sas address
308 *
309 * A sysfs 'read-only' shost attribute.
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 * pm8001_ctl_logging_level_show - logging level
325 * @cdev: pointer to embedded class device
326 * @attr: device attribute (unused)
327 * @buf: the buffer returned
328 *
329 * A sysfs 'read/write' shost attribute.
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 * pm8001_ctl_aap_log_show - aap1 event log
360 * @cdev: pointer to embedded class device
361 * @attr: device attribute (unused)
362 * @buf: the buffer returned
363 *
364 * A sysfs 'read-only' shost attribute.
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 * pm8001_ctl_ib_queue_log_show - Out bound Queue log
397 * @cdev:pointer to embedded class device
398 * @attr: device attribute (unused)
399 * @buf: the buffer returned
400 * A sysfs 'read-only' shost attribute.
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 * 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.
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 * pm8001_ctl_bios_version_show - Bios version Display
463 * @cdev:pointer to embedded class device
464 * @attr: device attribute (unused)
465 * @buf:the buffer returned
466 * A sysfs 'read-only' shost attribute.
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 * event_log_size_show - event log size
501 * @cdev: pointer to embedded class device
502 * @attr: device attribute (unused)
503 * @buf: the buffer returned
504 *
505 * A sysfs read shost attribute.
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 * pm8001_ctl_aap_log_show - IOP event log
520 * @cdev: pointer to embedded class device
521 * @attr: device attribute (unused)
522 * @buf: the buffer returned
523 *
524 * A sysfs 'read-only' shost attribute.
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 ** pm8001_ctl_fatal_log_show - fatal error logging
558 ** @cdev:pointer to embedded class device
559 ** @attr: device attribute
560 ** @buf: the buffer returned
561 **
562 ** A sysfs 'read-only' shost attribute.
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 ** non_fatal_log_show - non fatal error logging
578 ** @cdev:pointer to embedded class device
579 ** @attr: device attribute
580 ** @buf: the buffer returned
581 **
582 ** A sysfs 'read-only' shost attribute.
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 ** pm8001_ctl_gsm_log_show - gsm dump collection
623 ** @cdev:pointer to embedded class device
624 ** @attr: device attribute (unused)
625 ** @buf: the buffer returned
626 ** A sysfs 'read-only' shost attribute.
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} /* Last entry should be NULL. */
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} /* Last entry err_code = 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; /* IN */
749 fwControl->size = partitionSize + HEADER_LEN;/* IN */
750 fwControl->retcode = 0;/* OUT */
751 fwControl->offset = loopNumber * IOCTL_BUF_SIZE;/*OUT */
752
753 /* for the last chunk of data in case file size is not even with
754 4k, load only the rest*/
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 /* this test protects us from running two flash processes at once,
805 * so we should start with this test */
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