probe_roms.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /*
  2. * This file is provided under a dual BSD/GPLv2 license. When using or
  3. * redistributing this file, you may do so under either license.
  4. *
  5. * GPL LICENSE SUMMARY
  6. *
  7. * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of version 2 of the GNU General Public License as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called LICENSE.GPL.
  23. */
  24. /* probe_roms - scan for oem parameters */
  25. #include <linux/kernel.h>
  26. #include <linux/firmware.h>
  27. #include <linux/uaccess.h>
  28. #include <linux/efi.h>
  29. #include <asm/probe_roms.h>
  30. #include "isci.h"
  31. #include "task.h"
  32. #include "probe_roms.h"
  33. static efi_char16_t isci_efivar_name[] =
  34. {'R', 's', 't', 'S', 'c', 'u', 'O'};
  35. struct isci_orom *isci_request_oprom(struct pci_dev *pdev)
  36. {
  37. void __iomem *oprom = pci_map_biosrom(pdev);
  38. struct isci_orom *rom = NULL;
  39. size_t len, i;
  40. int j;
  41. char oem_sig[4];
  42. struct isci_oem_hdr oem_hdr;
  43. u8 *tmp, sum;
  44. if (!oprom)
  45. return NULL;
  46. len = pci_biosrom_size(pdev);
  47. rom = devm_kzalloc(&pdev->dev, sizeof(*rom), GFP_KERNEL);
  48. if (!rom) {
  49. dev_warn(&pdev->dev,
  50. "Unable to allocate memory for orom\n");
  51. return NULL;
  52. }
  53. for (i = 0; i < len && rom; i += ISCI_OEM_SIG_SIZE) {
  54. memcpy_fromio(oem_sig, oprom + i, ISCI_OEM_SIG_SIZE);
  55. /* we think we found the OEM table */
  56. if (memcmp(oem_sig, ISCI_OEM_SIG, ISCI_OEM_SIG_SIZE) == 0) {
  57. size_t copy_len;
  58. memcpy_fromio(&oem_hdr, oprom + i, sizeof(oem_hdr));
  59. copy_len = min(oem_hdr.len - sizeof(oem_hdr),
  60. sizeof(*rom));
  61. memcpy_fromio(rom,
  62. oprom + i + sizeof(oem_hdr),
  63. copy_len);
  64. /* calculate checksum */
  65. tmp = (u8 *)&oem_hdr;
  66. for (j = 0, sum = 0; j < sizeof(oem_hdr); j++, tmp++)
  67. sum += *tmp;
  68. tmp = (u8 *)rom;
  69. for (j = 0; j < sizeof(*rom); j++, tmp++)
  70. sum += *tmp;
  71. if (sum != 0) {
  72. dev_warn(&pdev->dev,
  73. "OEM table checksum failed\n");
  74. continue;
  75. }
  76. /* keep going if that's not the oem param table */
  77. if (memcmp(rom->hdr.signature,
  78. ISCI_ROM_SIG,
  79. ISCI_ROM_SIG_SIZE) != 0)
  80. continue;
  81. dev_info(&pdev->dev,
  82. "OEM parameter table found in OROM\n");
  83. break;
  84. }
  85. }
  86. if (i >= len) {
  87. dev_err(&pdev->dev, "oprom parse error\n");
  88. devm_kfree(&pdev->dev, rom);
  89. rom = NULL;
  90. }
  91. pci_unmap_biosrom(oprom);
  92. return rom;
  93. }
  94. /**
  95. * isci_parse_oem_parameters() - This method will take OEM parameters
  96. * from the module init parameters and copy them to oem_params. This will
  97. * only copy values that are not set to the module parameter default values
  98. * @oem_parameters: This parameter specifies the controller default OEM
  99. * parameters. It is expected that this has been initialized to the default
  100. * parameters for the controller
  101. *
  102. *
  103. */
  104. enum sci_status isci_parse_oem_parameters(union scic_oem_parameters *oem_params,
  105. struct isci_orom *orom, int scu_index)
  106. {
  107. /* check for valid inputs */
  108. if (scu_index < 0 || scu_index > SCI_MAX_CONTROLLERS ||
  109. scu_index > orom->hdr.num_elements || !oem_params)
  110. return -EINVAL;
  111. oem_params->sds1 = orom->ctrl[scu_index];
  112. return 0;
  113. }
  114. struct isci_orom *isci_request_firmware(struct pci_dev *pdev, const struct firmware *fw)
  115. {
  116. struct isci_orom *orom = NULL, *data;
  117. int i, j;
  118. if (request_firmware(&fw, ISCI_FW_NAME, &pdev->dev) != 0)
  119. return NULL;
  120. if (fw->size < sizeof(*orom))
  121. goto out;
  122. data = (struct isci_orom *)fw->data;
  123. if (strncmp(ISCI_ROM_SIG, data->hdr.signature,
  124. strlen(ISCI_ROM_SIG)) != 0)
  125. goto out;
  126. orom = devm_kzalloc(&pdev->dev, fw->size, GFP_KERNEL);
  127. if (!orom)
  128. goto out;
  129. memcpy(orom, fw->data, fw->size);
  130. /*
  131. * deprecated: override default amp_control for pre-preproduction
  132. * silicon revisions
  133. */
  134. if (isci_si_rev <= ISCI_SI_REVB0)
  135. goto out;
  136. for (i = 0; i < ARRAY_SIZE(orom->ctrl); i++)
  137. for (j = 0; j < ARRAY_SIZE(orom->ctrl[i].phys); j++) {
  138. orom->ctrl[i].phys[j].afe_tx_amp_control0 = 0xe7c03;
  139. orom->ctrl[i].phys[j].afe_tx_amp_control1 = 0xe7c03;
  140. orom->ctrl[i].phys[j].afe_tx_amp_control2 = 0xe7c03;
  141. orom->ctrl[i].phys[j].afe_tx_amp_control3 = 0xe7c03;
  142. }
  143. out:
  144. release_firmware(fw);
  145. return orom;
  146. }
  147. static struct efi *get_efi(void)
  148. {
  149. #ifdef CONFIG_EFI
  150. return &efi;
  151. #else
  152. return NULL;
  153. #endif
  154. }
  155. struct isci_orom *isci_get_efi_var(struct pci_dev *pdev)
  156. {
  157. efi_status_t status;
  158. struct isci_orom *rom;
  159. struct isci_oem_hdr *oem_hdr;
  160. u8 *tmp, sum;
  161. int j;
  162. ssize_t data_len;
  163. u8 *efi_data;
  164. u32 efi_attrib = 0;
  165. data_len = 1024;
  166. efi_data = devm_kzalloc(&pdev->dev, data_len, GFP_KERNEL);
  167. if (!efi_data) {
  168. dev_warn(&pdev->dev,
  169. "Unable to allocate memory for EFI data\n");
  170. return NULL;
  171. }
  172. rom = (struct isci_orom *)(efi_data + sizeof(struct isci_oem_hdr));
  173. if (get_efi())
  174. status = get_efi()->get_variable(isci_efivar_name,
  175. &ISCI_EFI_VENDOR_GUID,
  176. &efi_attrib,
  177. &data_len,
  178. efi_data);
  179. else
  180. status = EFI_NOT_FOUND;
  181. if (status != EFI_SUCCESS) {
  182. dev_warn(&pdev->dev,
  183. "Unable to obtain EFI var data for OEM parms\n");
  184. return NULL;
  185. }
  186. oem_hdr = (struct isci_oem_hdr *)efi_data;
  187. if (memcmp(oem_hdr->sig, ISCI_OEM_SIG, ISCI_OEM_SIG_SIZE) != 0) {
  188. dev_warn(&pdev->dev,
  189. "Invalid OEM header signature\n");
  190. return NULL;
  191. }
  192. /* calculate checksum */
  193. tmp = (u8 *)efi_data;
  194. for (j = 0, sum = 0; j < (sizeof(*oem_hdr) + sizeof(*rom)); j++, tmp++)
  195. sum += *tmp;
  196. if (sum != 0) {
  197. dev_warn(&pdev->dev,
  198. "OEM table checksum failed\n");
  199. return NULL;
  200. }
  201. if (memcmp(rom->hdr.signature,
  202. ISCI_ROM_SIG,
  203. ISCI_ROM_SIG_SIZE) != 0) {
  204. dev_warn(&pdev->dev,
  205. "Invalid OEM table signature\n");
  206. return NULL;
  207. }
  208. return rom;
  209. }