pm8001_ctl.c 20 KB

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