pm8001_ctl.c 23 KB

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