1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include <linux/kernel.h>
26#include <linux/module.h>
27
28#include "rt2x00.h"
29#include "rt2x00lib.h"
30
31static int rt2x00lib_request_firmware(struct rt2x00_dev *rt2x00dev)
32{
33 struct device *device = wiphy_dev(rt2x00dev->hw->wiphy);
34 const struct firmware *fw;
35 char *fw_name;
36 int retval;
37
38
39
40
41 fw_name = rt2x00dev->ops->lib->get_firmware_name(rt2x00dev);
42 if (!fw_name) {
43 rt2x00_err(rt2x00dev,
44 "Invalid firmware filename\n"
45 "Please file bug report to %s\n", DRV_PROJECT);
46 return -EINVAL;
47 }
48
49 rt2x00_info(rt2x00dev, "Loading firmware file '%s'\n", fw_name);
50
51 retval = request_firmware(&fw, fw_name, device);
52 if (retval) {
53 rt2x00_err(rt2x00dev, "Failed to request Firmware\n");
54 return retval;
55 }
56
57 if (!fw || !fw->size || !fw->data) {
58 rt2x00_err(rt2x00dev, "Failed to read Firmware\n");
59 release_firmware(fw);
60 return -ENOENT;
61 }
62
63 rt2x00_info(rt2x00dev, "Firmware detected - version: %d.%d\n",
64 fw->data[fw->size - 4], fw->data[fw->size - 3]);
65 snprintf(rt2x00dev->hw->wiphy->fw_version,
66 sizeof(rt2x00dev->hw->wiphy->fw_version), "%d.%d",
67 fw->data[fw->size - 4], fw->data[fw->size - 3]);
68
69 retval = rt2x00dev->ops->lib->check_firmware(rt2x00dev, fw->data, fw->size);
70 switch (retval) {
71 case FW_OK:
72 break;
73 case FW_BAD_CRC:
74 rt2x00_err(rt2x00dev, "Firmware checksum error\n");
75 goto exit;
76 case FW_BAD_LENGTH:
77 rt2x00_err(rt2x00dev, "Invalid firmware file length (len=%zu)\n",
78 fw->size);
79 goto exit;
80 case FW_BAD_VERSION:
81 rt2x00_err(rt2x00dev, "Current firmware does not support detected chipset\n");
82 goto exit;
83 }
84
85 rt2x00dev->fw = fw;
86
87 return 0;
88
89exit:
90 release_firmware(fw);
91
92 return -ENOENT;
93}
94
95int rt2x00lib_load_firmware(struct rt2x00_dev *rt2x00dev)
96{
97 int retval;
98
99 if (!test_bit(REQUIRE_FIRMWARE, &rt2x00dev->cap_flags))
100 return 0;
101
102 if (!rt2x00dev->fw) {
103 retval = rt2x00lib_request_firmware(rt2x00dev);
104 if (retval)
105 return retval;
106 }
107
108
109
110
111 retval = rt2x00dev->ops->lib->load_firmware(rt2x00dev,
112 rt2x00dev->fw->data,
113 rt2x00dev->fw->size);
114
115
116
117
118
119
120 rt2x00leds_led_assoc(rt2x00dev, false);
121
122 return retval;
123}
124
125void rt2x00lib_free_firmware(struct rt2x00_dev *rt2x00dev)
126{
127 release_firmware(rt2x00dev->fw);
128 rt2x00dev->fw = NULL;
129}
130