rt2x00firmware.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. Copyright (C) 2004 - 2009 rt2x00 SourceForge Project
  3. <http://rt2x00.serialmonkey.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the
  14. Free Software Foundation, Inc.,
  15. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. */
  17. /*
  18. Module: rt2x00lib
  19. Abstract: rt2x00 firmware loading routines.
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include "rt2x00.h"
  24. #include "rt2x00lib.h"
  25. static int rt2x00lib_request_firmware(struct rt2x00_dev *rt2x00dev)
  26. {
  27. struct device *device = wiphy_dev(rt2x00dev->hw->wiphy);
  28. const struct firmware *fw;
  29. char *fw_name;
  30. int retval;
  31. /*
  32. * Read correct firmware from harddisk.
  33. */
  34. fw_name = rt2x00dev->ops->lib->get_firmware_name(rt2x00dev);
  35. if (!fw_name) {
  36. ERROR(rt2x00dev,
  37. "Invalid firmware filename.\n"
  38. "Please file bug report to %s.\n", DRV_PROJECT);
  39. return -EINVAL;
  40. }
  41. INFO(rt2x00dev, "Loading firmware file '%s'.\n", fw_name);
  42. retval = request_firmware(&fw, fw_name, device);
  43. if (retval) {
  44. ERROR(rt2x00dev, "Failed to request Firmware.\n");
  45. return retval;
  46. }
  47. if (!fw || !fw->size || !fw->data) {
  48. ERROR(rt2x00dev, "Failed to read Firmware.\n");
  49. return -ENOENT;
  50. }
  51. INFO(rt2x00dev, "Firmware detected - version: %d.%d.\n",
  52. fw->data[fw->size - 4], fw->data[fw->size - 3]);
  53. retval = rt2x00dev->ops->lib->check_firmware(rt2x00dev, fw->data, fw->size);
  54. switch (retval) {
  55. case FW_OK:
  56. break;
  57. case FW_BAD_CRC:
  58. ERROR(rt2x00dev, "Firmware checksum error.\n");
  59. goto exit;
  60. case FW_BAD_LENGTH:
  61. ERROR(rt2x00dev,
  62. "Invalid firmware file length (len=%zu)\n", fw->size);
  63. goto exit;
  64. case FW_BAD_VERSION:
  65. ERROR(rt2x00dev,
  66. "Current firmware does not support detected chipset.\n");
  67. goto exit;
  68. };
  69. rt2x00dev->fw = fw;
  70. return 0;
  71. exit:
  72. release_firmware(fw);
  73. return -ENOENT;
  74. }
  75. int rt2x00lib_load_firmware(struct rt2x00_dev *rt2x00dev)
  76. {
  77. int retval;
  78. if (!test_bit(DRIVER_REQUIRE_FIRMWARE, &rt2x00dev->flags))
  79. return 0;
  80. if (!rt2x00dev->fw) {
  81. retval = rt2x00lib_request_firmware(rt2x00dev);
  82. if (retval)
  83. return retval;
  84. }
  85. /*
  86. * Send firmware to the device.
  87. */
  88. retval = rt2x00dev->ops->lib->load_firmware(rt2x00dev,
  89. rt2x00dev->fw->data,
  90. rt2x00dev->fw->size);
  91. /*
  92. * When the firmware is uploaded to the hardware the LED
  93. * association status might have been triggered, for correct
  94. * LED handling it should now be reset.
  95. */
  96. rt2x00leds_led_assoc(rt2x00dev, false);
  97. return retval;
  98. }
  99. void rt2x00lib_free_firmware(struct rt2x00_dev *rt2x00dev)
  100. {
  101. release_firmware(rt2x00dev->fw);
  102. rt2x00dev->fw = NULL;
  103. }