probe_roms.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 <asm/probe_roms.h>
  29. #include "isci.h"
  30. #include "task.h"
  31. #include "sci_controller_constants.h"
  32. #include "scic_remote_device.h"
  33. #include "sci_environment.h"
  34. #include "probe_roms.h"
  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. if (!oprom)
  41. return NULL;
  42. len = pci_biosrom_size(pdev);
  43. rom = devm_kzalloc(&pdev->dev, sizeof(*rom), GFP_KERNEL);
  44. for (i = 0; i < len && rom; i += ISCI_ROM_SIG_SIZE) {
  45. memcpy_fromio(rom->hdr.signature, oprom + i, ISCI_ROM_SIG_SIZE);
  46. if (memcmp(rom->hdr.signature, ISCI_ROM_SIG,
  47. ISCI_ROM_SIG_SIZE) == 0) {
  48. size_t copy_len = min(len - i, sizeof(*rom));
  49. memcpy_fromio(rom, oprom + i, copy_len);
  50. break;
  51. }
  52. }
  53. if (i >= len) {
  54. dev_err(&pdev->dev, "oprom parse error\n");
  55. devm_kfree(&pdev->dev, rom);
  56. rom = NULL;
  57. }
  58. pci_unmap_biosrom(oprom);
  59. return rom;
  60. }
  61. /**
  62. * isci_parse_oem_parameters() - This method will take OEM parameters
  63. * from the module init parameters and copy them to oem_params. This will
  64. * only copy values that are not set to the module parameter default values
  65. * @oem_parameters: This parameter specifies the controller default OEM
  66. * parameters. It is expected that this has been initialized to the default
  67. * parameters for the controller
  68. *
  69. *
  70. */
  71. enum sci_status isci_parse_oem_parameters(union scic_oem_parameters *oem_params,
  72. struct isci_orom *orom, int scu_index)
  73. {
  74. int i;
  75. /* check for valid inputs */
  76. if (!(scu_index >= 0
  77. && scu_index < SCI_MAX_CONTROLLERS
  78. && oem_params != NULL))
  79. return -EINVAL;
  80. for (i = 0; i < SCI_MAX_PHYS; i++) {
  81. oem_params->sds1.phys[i].sas_address.low =
  82. orom->ctrl[scu_index].phys[i].sas_address.low;
  83. oem_params->sds1.phys[i].sas_address.high =
  84. orom->ctrl[scu_index].phys[i].sas_address.high;
  85. }
  86. for (i = 0; i < SCI_MAX_PORTS; i++)
  87. oem_params->sds1.ports[i].phy_mask =
  88. orom->ctrl[scu_index].ports[i].phy_mask;
  89. return 0;
  90. }
  91. struct isci_orom *isci_request_firmware(struct pci_dev *pdev, const struct firmware *fw)
  92. {
  93. struct isci_orom *orom = NULL, *data;
  94. if (request_firmware(&fw, ISCI_FW_NAME, &pdev->dev) != 0)
  95. return NULL;
  96. if (fw->size < sizeof(*orom))
  97. goto out;
  98. data = (struct isci_orom *)fw->data;
  99. if (strncmp(ISCI_ROM_SIG, data->hdr.signature,
  100. strlen(ISCI_ROM_SIG)) != 0)
  101. goto out;
  102. orom = devm_kzalloc(&pdev->dev, fw->size, GFP_KERNEL);
  103. if (!orom)
  104. goto out;
  105. memcpy(orom, fw->data, fw->size);
  106. out:
  107. release_firmware(fw);
  108. return orom;
  109. }