pm8001_ctl.c 17 KB

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