pm8001_ctl.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  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_ib_queue_log_show - Out bound Queue log
  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_ib_queue_log_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. int offset;
  303. char *str = buf;
  304. int start = 0;
  305. #define IB_MEMMAP(c) \
  306. (*(u32 *)((u8 *)pm8001_ha-> \
  307. memoryMap.region[IB].virt_ptr + \
  308. pm8001_ha->evtlog_ib_offset + (c)))
  309. for (offset = 0; offset < IB_OB_READ_TIMES; offset++) {
  310. str += sprintf(str, "0x%08x\n", IB_MEMMAP(start));
  311. start = start + 4;
  312. }
  313. pm8001_ha->evtlog_ib_offset += SYSFS_OFFSET;
  314. if (((pm8001_ha->evtlog_ib_offset) % (PM80XX_IB_OB_QUEUE_SIZE)) == 0)
  315. pm8001_ha->evtlog_ib_offset = 0;
  316. return str - buf;
  317. }
  318. static DEVICE_ATTR(ib_log, S_IRUGO, pm8001_ctl_ib_queue_log_show, NULL);
  319. /**
  320. * pm8001_ctl_ob_queue_log_show - Out bound Queue log
  321. * @cdev:pointer to embedded class device
  322. * @buf: the buffer returned
  323. * A sysfs 'read-only' shost attribute.
  324. */
  325. static ssize_t pm8001_ctl_ob_queue_log_show(struct device *cdev,
  326. struct device_attribute *attr, char *buf)
  327. {
  328. struct Scsi_Host *shost = class_to_shost(cdev);
  329. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  330. struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
  331. int offset;
  332. char *str = buf;
  333. int start = 0;
  334. #define OB_MEMMAP(c) \
  335. (*(u32 *)((u8 *)pm8001_ha-> \
  336. memoryMap.region[OB].virt_ptr + \
  337. pm8001_ha->evtlog_ob_offset + (c)))
  338. for (offset = 0; offset < IB_OB_READ_TIMES; offset++) {
  339. str += sprintf(str, "0x%08x\n", OB_MEMMAP(start));
  340. start = start + 4;
  341. }
  342. pm8001_ha->evtlog_ob_offset += SYSFS_OFFSET;
  343. if (((pm8001_ha->evtlog_ob_offset) % (PM80XX_IB_OB_QUEUE_SIZE)) == 0)
  344. pm8001_ha->evtlog_ob_offset = 0;
  345. return str - buf;
  346. }
  347. static DEVICE_ATTR(ob_log, S_IRUGO, pm8001_ctl_ob_queue_log_show, NULL);
  348. /**
  349. * pm8001_ctl_bios_version_show - Bios version Display
  350. * @cdev:pointer to embedded class device
  351. * @buf:the buffer returned
  352. * A sysfs 'read-only' shost attribute.
  353. */
  354. static ssize_t pm8001_ctl_bios_version_show(struct device *cdev,
  355. struct device_attribute *attr, char *buf)
  356. {
  357. struct Scsi_Host *shost = class_to_shost(cdev);
  358. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  359. struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
  360. char *str = buf;
  361. int bios_index;
  362. DECLARE_COMPLETION_ONSTACK(completion);
  363. struct pm8001_ioctl_payload payload;
  364. pm8001_ha->nvmd_completion = &completion;
  365. payload.minor_function = 7;
  366. payload.offset = 0;
  367. payload.length = 4096;
  368. payload.func_specific = kzalloc(4096, GFP_KERNEL);
  369. if (!payload.func_specific)
  370. return -ENOMEM;
  371. if (PM8001_CHIP_DISP->get_nvmd_req(pm8001_ha, &payload)) {
  372. kfree(payload.func_specific);
  373. return -ENOMEM;
  374. }
  375. wait_for_completion(&completion);
  376. for (bios_index = BIOSOFFSET; bios_index < BIOS_OFFSET_LIMIT;
  377. bios_index++)
  378. str += sprintf(str, "%c",
  379. *(payload.func_specific+bios_index));
  380. kfree(payload.func_specific);
  381. return str - buf;
  382. }
  383. static DEVICE_ATTR(bios_version, S_IRUGO, pm8001_ctl_bios_version_show, NULL);
  384. /**
  385. * pm8001_ctl_aap_log_show - IOP event log
  386. * @cdev: pointer to embedded class device
  387. * @buf: the buffer returned
  388. *
  389. * A sysfs 'read-only' shost attribute.
  390. */
  391. static ssize_t pm8001_ctl_iop_log_show(struct device *cdev,
  392. struct device_attribute *attr, char *buf)
  393. {
  394. struct Scsi_Host *shost = class_to_shost(cdev);
  395. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  396. struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
  397. #define IOP_MEMMAP(r, c) \
  398. (*(u32 *)((u8*)pm8001_ha->memoryMap.region[IOP].virt_ptr + (r) * 32 \
  399. + (c)))
  400. int i;
  401. char *str = buf;
  402. int max = 2;
  403. for (i = 0; i < max; i++) {
  404. str += sprintf(str, "0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x"
  405. "0x%08x 0x%08x\n",
  406. IOP_MEMMAP(i, 0),
  407. IOP_MEMMAP(i, 4),
  408. IOP_MEMMAP(i, 8),
  409. IOP_MEMMAP(i, 12),
  410. IOP_MEMMAP(i, 16),
  411. IOP_MEMMAP(i, 20),
  412. IOP_MEMMAP(i, 24),
  413. IOP_MEMMAP(i, 28));
  414. }
  415. return str - buf;
  416. }
  417. static DEVICE_ATTR(iop_log, S_IRUGO, pm8001_ctl_iop_log_show, NULL);
  418. /**
  419. ** pm8001_ctl_fatal_log_show - fatal error logging
  420. ** @cdev:pointer to embedded class device
  421. ** @buf: the buffer returned
  422. **
  423. ** A sysfs 'read-only' shost attribute.
  424. **/
  425. static ssize_t pm8001_ctl_fatal_log_show(struct device *cdev,
  426. struct device_attribute *attr, char *buf)
  427. {
  428. ssize_t count;
  429. count = pm80xx_get_fatal_dump(cdev, attr, buf);
  430. return count;
  431. }
  432. static DEVICE_ATTR(fatal_log, S_IRUGO, pm8001_ctl_fatal_log_show, NULL);
  433. /**
  434. ** pm8001_ctl_gsm_log_show - gsm dump collection
  435. ** @cdev:pointer to embedded class device
  436. ** @buf: the buffer returned
  437. **A sysfs 'read-only' shost attribute.
  438. **/
  439. static ssize_t pm8001_ctl_gsm_log_show(struct device *cdev,
  440. struct device_attribute *attr, char *buf)
  441. {
  442. ssize_t count;
  443. count = pm8001_get_gsm_dump(cdev, SYSFS_OFFSET, buf);
  444. return count;
  445. }
  446. static DEVICE_ATTR(gsm_log, S_IRUGO, pm8001_ctl_gsm_log_show, NULL);
  447. #define FLASH_CMD_NONE 0x00
  448. #define FLASH_CMD_UPDATE 0x01
  449. #define FLASH_CMD_SET_NVMD 0x02
  450. struct flash_command {
  451. u8 command[8];
  452. int code;
  453. };
  454. static struct flash_command flash_command_table[] =
  455. {
  456. {"set_nvmd", FLASH_CMD_SET_NVMD},
  457. {"update", FLASH_CMD_UPDATE},
  458. {"", FLASH_CMD_NONE} /* Last entry should be NULL. */
  459. };
  460. struct error_fw {
  461. char *reason;
  462. int err_code;
  463. };
  464. static struct error_fw flash_error_table[] =
  465. {
  466. {"Failed to open fw image file", FAIL_OPEN_BIOS_FILE},
  467. {"image header mismatch", FLASH_UPDATE_HDR_ERR},
  468. {"image offset mismatch", FLASH_UPDATE_OFFSET_ERR},
  469. {"image CRC Error", FLASH_UPDATE_CRC_ERR},
  470. {"image length Error.", FLASH_UPDATE_LENGTH_ERR},
  471. {"Failed to program flash chip", FLASH_UPDATE_HW_ERR},
  472. {"Flash chip not supported.", FLASH_UPDATE_DNLD_NOT_SUPPORTED},
  473. {"Flash update disabled.", FLASH_UPDATE_DISABLED},
  474. {"Flash in progress", FLASH_IN_PROGRESS},
  475. {"Image file size Error", FAIL_FILE_SIZE},
  476. {"Input parameter error", FAIL_PARAMETERS},
  477. {"Out of memory", FAIL_OUT_MEMORY},
  478. {"OK", 0} /* Last entry err_code = 0. */
  479. };
  480. static int pm8001_set_nvmd(struct pm8001_hba_info *pm8001_ha)
  481. {
  482. struct pm8001_ioctl_payload *payload;
  483. DECLARE_COMPLETION_ONSTACK(completion);
  484. u8 *ioctlbuffer;
  485. u32 ret;
  486. u32 length = 1024 * 5 + sizeof(*payload) - 1;
  487. if (pm8001_ha->fw_image->size > 4096) {
  488. pm8001_ha->fw_status = FAIL_FILE_SIZE;
  489. return -EFAULT;
  490. }
  491. ioctlbuffer = kzalloc(length, GFP_KERNEL);
  492. if (!ioctlbuffer) {
  493. pm8001_ha->fw_status = FAIL_OUT_MEMORY;
  494. return -ENOMEM;
  495. }
  496. payload = (struct pm8001_ioctl_payload *)ioctlbuffer;
  497. memcpy((u8 *)&payload->func_specific, (u8 *)pm8001_ha->fw_image->data,
  498. pm8001_ha->fw_image->size);
  499. payload->length = pm8001_ha->fw_image->size;
  500. payload->id = 0;
  501. payload->minor_function = 0x1;
  502. pm8001_ha->nvmd_completion = &completion;
  503. ret = PM8001_CHIP_DISP->set_nvmd_req(pm8001_ha, payload);
  504. if (ret) {
  505. pm8001_ha->fw_status = FAIL_OUT_MEMORY;
  506. goto out;
  507. }
  508. wait_for_completion(&completion);
  509. out:
  510. kfree(ioctlbuffer);
  511. return ret;
  512. }
  513. static int pm8001_update_flash(struct pm8001_hba_info *pm8001_ha)
  514. {
  515. struct pm8001_ioctl_payload *payload;
  516. DECLARE_COMPLETION_ONSTACK(completion);
  517. u8 *ioctlbuffer;
  518. struct fw_control_info *fwControl;
  519. u32 partitionSize, partitionSizeTmp;
  520. u32 loopNumber, loopcount;
  521. struct pm8001_fw_image_header *image_hdr;
  522. u32 sizeRead = 0;
  523. u32 ret = 0;
  524. u32 length = 1024 * 16 + sizeof(*payload) - 1;
  525. if (pm8001_ha->fw_image->size < 28) {
  526. pm8001_ha->fw_status = FAIL_FILE_SIZE;
  527. return -EFAULT;
  528. }
  529. ioctlbuffer = kzalloc(length, GFP_KERNEL);
  530. if (!ioctlbuffer) {
  531. pm8001_ha->fw_status = FAIL_OUT_MEMORY;
  532. return -ENOMEM;
  533. }
  534. image_hdr = (struct pm8001_fw_image_header *)pm8001_ha->fw_image->data;
  535. while (sizeRead < pm8001_ha->fw_image->size) {
  536. partitionSizeTmp =
  537. *(u32 *)((u8 *)&image_hdr->image_length + sizeRead);
  538. partitionSize = be32_to_cpu(partitionSizeTmp);
  539. loopcount = DIV_ROUND_UP(partitionSize + HEADER_LEN,
  540. IOCTL_BUF_SIZE);
  541. for (loopNumber = 0; loopNumber < loopcount; loopNumber++) {
  542. payload = (struct pm8001_ioctl_payload *)ioctlbuffer;
  543. payload->length = 1024*16;
  544. payload->id = 0;
  545. fwControl =
  546. (struct fw_control_info *)&payload->func_specific;
  547. fwControl->len = IOCTL_BUF_SIZE; /* IN */
  548. fwControl->size = partitionSize + HEADER_LEN;/* IN */
  549. fwControl->retcode = 0;/* OUT */
  550. fwControl->offset = loopNumber * IOCTL_BUF_SIZE;/*OUT */
  551. /* for the last chunk of data in case file size is not even with
  552. 4k, load only the rest*/
  553. if (((loopcount-loopNumber) == 1) &&
  554. ((partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE)) {
  555. fwControl->len =
  556. (partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE;
  557. memcpy((u8 *)fwControl->buffer,
  558. (u8 *)pm8001_ha->fw_image->data + sizeRead,
  559. (partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE);
  560. sizeRead +=
  561. (partitionSize + HEADER_LEN) % IOCTL_BUF_SIZE;
  562. } else {
  563. memcpy((u8 *)fwControl->buffer,
  564. (u8 *)pm8001_ha->fw_image->data + sizeRead,
  565. IOCTL_BUF_SIZE);
  566. sizeRead += IOCTL_BUF_SIZE;
  567. }
  568. pm8001_ha->nvmd_completion = &completion;
  569. ret = PM8001_CHIP_DISP->fw_flash_update_req(pm8001_ha, payload);
  570. if (ret) {
  571. pm8001_ha->fw_status = FAIL_OUT_MEMORY;
  572. goto out;
  573. }
  574. wait_for_completion(&completion);
  575. if (fwControl->retcode > FLASH_UPDATE_IN_PROGRESS) {
  576. pm8001_ha->fw_status = fwControl->retcode;
  577. ret = -EFAULT;
  578. goto out;
  579. }
  580. }
  581. }
  582. out:
  583. kfree(ioctlbuffer);
  584. return ret;
  585. }
  586. static ssize_t pm8001_store_update_fw(struct device *cdev,
  587. struct device_attribute *attr,
  588. const char *buf, size_t count)
  589. {
  590. struct Scsi_Host *shost = class_to_shost(cdev);
  591. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  592. struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
  593. char *cmd_ptr, *filename_ptr;
  594. int res, i;
  595. int flash_command = FLASH_CMD_NONE;
  596. int ret;
  597. if (!capable(CAP_SYS_ADMIN))
  598. return -EACCES;
  599. /* this test protects us from running two flash processes at once,
  600. * so we should start with this test */
  601. if (pm8001_ha->fw_status == FLASH_IN_PROGRESS)
  602. return -EINPROGRESS;
  603. pm8001_ha->fw_status = FLASH_IN_PROGRESS;
  604. cmd_ptr = kzalloc(count*2, GFP_KERNEL);
  605. if (!cmd_ptr) {
  606. pm8001_ha->fw_status = FAIL_OUT_MEMORY;
  607. return -ENOMEM;
  608. }
  609. filename_ptr = cmd_ptr + count;
  610. res = sscanf(buf, "%s %s", cmd_ptr, filename_ptr);
  611. if (res != 2) {
  612. pm8001_ha->fw_status = FAIL_PARAMETERS;
  613. ret = -EINVAL;
  614. goto out;
  615. }
  616. for (i = 0; flash_command_table[i].code != FLASH_CMD_NONE; i++) {
  617. if (!memcmp(flash_command_table[i].command,
  618. cmd_ptr, strlen(cmd_ptr))) {
  619. flash_command = flash_command_table[i].code;
  620. break;
  621. }
  622. }
  623. if (flash_command == FLASH_CMD_NONE) {
  624. pm8001_ha->fw_status = FAIL_PARAMETERS;
  625. ret = -EINVAL;
  626. goto out;
  627. }
  628. ret = request_firmware(&pm8001_ha->fw_image,
  629. filename_ptr,
  630. pm8001_ha->dev);
  631. if (ret) {
  632. PM8001_FAIL_DBG(pm8001_ha,
  633. pm8001_printk(
  634. "Failed to load firmware image file %s, error %d\n",
  635. filename_ptr, ret));
  636. pm8001_ha->fw_status = FAIL_OPEN_BIOS_FILE;
  637. goto out;
  638. }
  639. if (FLASH_CMD_UPDATE == flash_command)
  640. ret = pm8001_update_flash(pm8001_ha);
  641. else
  642. ret = pm8001_set_nvmd(pm8001_ha);
  643. release_firmware(pm8001_ha->fw_image);
  644. out:
  645. kfree(cmd_ptr);
  646. if (ret)
  647. return ret;
  648. pm8001_ha->fw_status = FLASH_OK;
  649. return count;
  650. }
  651. static ssize_t pm8001_show_update_fw(struct device *cdev,
  652. struct device_attribute *attr, char *buf)
  653. {
  654. int i;
  655. struct Scsi_Host *shost = class_to_shost(cdev);
  656. struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
  657. struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
  658. for (i = 0; flash_error_table[i].err_code != 0; i++) {
  659. if (flash_error_table[i].err_code == pm8001_ha->fw_status)
  660. break;
  661. }
  662. if (pm8001_ha->fw_status != FLASH_IN_PROGRESS)
  663. pm8001_ha->fw_status = FLASH_OK;
  664. return snprintf(buf, PAGE_SIZE, "status=%x %s\n",
  665. flash_error_table[i].err_code,
  666. flash_error_table[i].reason);
  667. }
  668. static DEVICE_ATTR(update_fw, S_IRUGO|S_IWUSR|S_IWGRP,
  669. pm8001_show_update_fw, pm8001_store_update_fw);
  670. struct device_attribute *pm8001_host_attrs[] = {
  671. &dev_attr_interface_rev,
  672. &dev_attr_fw_version,
  673. &dev_attr_update_fw,
  674. &dev_attr_aap_log,
  675. &dev_attr_iop_log,
  676. &dev_attr_fatal_log,
  677. &dev_attr_gsm_log,
  678. &dev_attr_max_out_io,
  679. &dev_attr_max_devices,
  680. &dev_attr_max_sg_list,
  681. &dev_attr_sas_spec_support,
  682. &dev_attr_logging_level,
  683. &dev_attr_host_sas_address,
  684. &dev_attr_bios_version,
  685. &dev_attr_ib_log,
  686. &dev_attr_ob_log,
  687. NULL,
  688. };