Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved. |
| 3 | * |
| 4 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 5 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 6 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 7 | * more details. |
| 8 | * |
| 9 | * You should have received a copy of the GNU General Public License along with |
| 10 | * this program; if not, write to the Free Software Foundation, Inc., |
| 11 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 12 | * |
| 13 | * The full GNU General Public License is included in this distribution in the |
| 14 | * file called LICENSE. |
| 15 | * |
| 16 | * Contact Information: |
| 17 | * wlanfae <wlanfae@realtek.com> |
| 18 | ******************************************************************************/ |
| 19 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 20 | #include "rtl_core.h" |
| 21 | #include "r8192E_hw.h" |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 22 | #include "r8192E_hwimg.h" |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 23 | #include "r8192E_firmware.h" |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 24 | #include <linux/firmware.h> |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 25 | |
| 26 | extern void firmware_init_param(struct net_device *dev) |
| 27 | { |
Larry Finger | e3e3762 | 2011-07-19 00:26:41 -0500 | [diff] [blame] | 28 | struct r8192_priv *priv = rtllib_priv(dev); |
Larry Finger | 5aca114 | 2011-07-18 23:10:50 -0500 | [diff] [blame] | 29 | struct rt_firmware *pfirmware = priv->pFirmware; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 30 | |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 31 | pfirmware->cmdpacket_frag_thresold = GET_COMMAND_PACKET_FRAG_THRESHOLD( |
| 32 | MAX_TRANSMIT_BUFFER_SIZE); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 33 | } |
| 34 | |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 35 | bool fw_download_code(struct net_device *dev, u8 *code_virtual_address, |
| 36 | u32 buffer_len) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 37 | { |
Larry Finger | e3e3762 | 2011-07-19 00:26:41 -0500 | [diff] [blame] | 38 | struct r8192_priv *priv = rtllib_priv(dev); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 39 | bool rt_status = true; |
| 40 | u16 frag_threshold; |
| 41 | u16 frag_length, frag_offset = 0; |
| 42 | int i; |
| 43 | |
Larry Finger | 5aca114 | 2011-07-18 23:10:50 -0500 | [diff] [blame] | 44 | struct rt_firmware *pfirmware = priv->pFirmware; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 45 | struct sk_buff *skb; |
| 46 | unsigned char *seg_ptr; |
Larry Finger | 3b83db4 | 2011-07-19 00:01:29 -0500 | [diff] [blame] | 47 | struct cb_desc *tcb_desc; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 48 | u8 bLastIniPkt; |
| 49 | |
| 50 | firmware_init_param(dev); |
| 51 | frag_threshold = pfirmware->cmdpacket_frag_thresold; |
| 52 | do { |
| 53 | if ((buffer_len - frag_offset) > frag_threshold) { |
| 54 | frag_length = frag_threshold ; |
| 55 | bLastIniPkt = 0; |
| 56 | |
| 57 | } else { |
| 58 | frag_length = buffer_len - frag_offset; |
| 59 | bLastIniPkt = 1; |
| 60 | |
| 61 | } |
| 62 | |
| 63 | skb = dev_alloc_skb(frag_length + 4); |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 64 | memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev)); |
Larry Finger | 3b83db4 | 2011-07-19 00:01:29 -0500 | [diff] [blame] | 65 | tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 66 | tcb_desc->queue_index = TXCMD_QUEUE; |
| 67 | tcb_desc->bCmdOrInit = DESC_PACKET_TYPE_INIT; |
| 68 | tcb_desc->bLastIniPkt = bLastIniPkt; |
| 69 | |
| 70 | seg_ptr = skb->data; |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 71 | for (i = 0; i < frag_length; i += 4) { |
| 72 | *seg_ptr++ = ((i+0) < frag_length) ? |
| 73 | code_virtual_address[i+3] : 0; |
| 74 | *seg_ptr++ = ((i+1) < frag_length) ? |
| 75 | code_virtual_address[i+2] : 0; |
| 76 | *seg_ptr++ = ((i+2) < frag_length) ? |
| 77 | code_virtual_address[i+1] : 0; |
| 78 | *seg_ptr++ = ((i+3) < frag_length) ? |
| 79 | code_virtual_address[i+0] : 0; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 80 | } |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 81 | tcb_desc->txbuf_size = (u16)i; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 82 | skb_put(skb, i); |
| 83 | |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 84 | if (!priv->rtllib->check_nic_enough_desc(dev, tcb_desc->queue_index) || |
| 85 | (!skb_queue_empty(&priv->rtllib->skb_waitQ[tcb_desc->queue_index])) || |
| 86 | (priv->rtllib->queue_stop)) { |
| 87 | RT_TRACE(COMP_FIRMWARE, "===================> tx " |
| 88 | "full!\n"); |
| 89 | skb_queue_tail(&priv->rtllib->skb_waitQ |
| 90 | [tcb_desc->queue_index], skb); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 91 | } else { |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 92 | priv->rtllib->softmac_hard_start_xmit(skb, dev); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | code_virtual_address += frag_length; |
| 96 | frag_offset += frag_length; |
| 97 | |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 98 | } while (frag_offset < buffer_len); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 99 | |
| 100 | write_nic_byte(dev, TPPoll, TPPoll_CQ); |
| 101 | |
| 102 | return rt_status; |
| 103 | } |
| 104 | |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 105 | bool fwSendNullPacket(struct net_device *dev, u32 Length) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 106 | { |
| 107 | bool rtStatus = true; |
Larry Finger | e3e3762 | 2011-07-19 00:26:41 -0500 | [diff] [blame] | 108 | struct r8192_priv *priv = rtllib_priv(dev); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 109 | struct sk_buff *skb; |
Larry Finger | 3b83db4 | 2011-07-19 00:01:29 -0500 | [diff] [blame] | 110 | struct cb_desc *tcb_desc; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 111 | unsigned char *ptr_buf; |
| 112 | bool bLastInitPacket = false; |
| 113 | |
| 114 | |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 115 | skb = dev_alloc_skb(Length + 4); |
| 116 | memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev)); |
Larry Finger | 3b83db4 | 2011-07-19 00:01:29 -0500 | [diff] [blame] | 117 | tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 118 | tcb_desc->queue_index = TXCMD_QUEUE; |
| 119 | tcb_desc->bCmdOrInit = DESC_PACKET_TYPE_INIT; |
| 120 | tcb_desc->bLastIniPkt = bLastInitPacket; |
| 121 | ptr_buf = skb_put(skb, Length); |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 122 | memset(ptr_buf, 0, Length); |
| 123 | tcb_desc->txbuf_size = (u16)Length; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 124 | |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 125 | if (!priv->rtllib->check_nic_enough_desc(dev, tcb_desc->queue_index) || |
| 126 | (!skb_queue_empty(&priv->rtllib->skb_waitQ[tcb_desc-> |
| 127 | queue_index])) || (priv->rtllib->queue_stop)) { |
| 128 | RT_TRACE(COMP_FIRMWARE, "===================NULL packet========" |
| 129 | "========> tx full!\n"); |
| 130 | skb_queue_tail(&priv->rtllib->skb_waitQ[tcb_desc->queue_index], |
| 131 | skb); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 132 | } else { |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 133 | priv->rtllib->softmac_hard_start_xmit(skb, dev); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | write_nic_byte(dev, TPPoll, TPPoll_CQ); |
| 137 | return rtStatus; |
| 138 | } |
| 139 | |
| 140 | bool CPUcheck_maincodeok_turnonCPU(struct net_device *dev) |
| 141 | { |
| 142 | bool rt_status = true; |
| 143 | u32 CPU_status = 0; |
| 144 | unsigned long timeout; |
| 145 | |
| 146 | timeout = jiffies + MSECS(200); |
| 147 | while (time_before(jiffies, timeout)) { |
| 148 | CPU_status = read_nic_dword(dev, CPU_GEN); |
| 149 | if (CPU_status & CPU_GEN_PUT_CODE_OK) |
| 150 | break; |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 151 | mdelay(2); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | if (!(CPU_status&CPU_GEN_PUT_CODE_OK)) { |
| 155 | RT_TRACE(COMP_ERR, "Download Firmware: Put code fail!\n"); |
| 156 | goto CPUCheckMainCodeOKAndTurnOnCPU_Fail; |
| 157 | } else { |
| 158 | RT_TRACE(COMP_FIRMWARE, "Download Firmware: Put code ok!\n"); |
| 159 | } |
| 160 | |
| 161 | CPU_status = read_nic_dword(dev, CPU_GEN); |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 162 | write_nic_byte(dev, CPU_GEN, |
| 163 | (u8)((CPU_status|CPU_GEN_PWR_STB_CPU)&0xff)); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 164 | mdelay(1); |
| 165 | |
| 166 | timeout = jiffies + MSECS(200); |
| 167 | while (time_before(jiffies, timeout)) { |
| 168 | CPU_status = read_nic_dword(dev, CPU_GEN); |
| 169 | if (CPU_status&CPU_GEN_BOOT_RDY) |
| 170 | break; |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 171 | mdelay(2); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 172 | } |
| 173 | |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 174 | if (!(CPU_status&CPU_GEN_BOOT_RDY)) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 175 | goto CPUCheckMainCodeOKAndTurnOnCPU_Fail; |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 176 | else |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 177 | RT_TRACE(COMP_FIRMWARE, "Download Firmware: Boot ready!\n"); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 178 | |
| 179 | return rt_status; |
| 180 | |
| 181 | CPUCheckMainCodeOKAndTurnOnCPU_Fail: |
| 182 | RT_TRACE(COMP_ERR, "ERR in %s()\n", __func__); |
| 183 | rt_status = false; |
| 184 | return rt_status; |
| 185 | } |
| 186 | |
| 187 | bool CPUcheck_firmware_ready(struct net_device *dev) |
| 188 | { |
| 189 | |
| 190 | bool rt_status = true; |
| 191 | u32 CPU_status = 0; |
| 192 | unsigned long timeout; |
| 193 | |
| 194 | timeout = jiffies + MSECS(20); |
| 195 | while (time_before(jiffies, timeout)) { |
| 196 | CPU_status = read_nic_dword(dev, CPU_GEN); |
| 197 | if (CPU_status&CPU_GEN_FIRM_RDY) |
| 198 | break; |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 199 | mdelay(2); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | if (!(CPU_status&CPU_GEN_FIRM_RDY)) |
| 203 | goto CPUCheckFirmwareReady_Fail; |
| 204 | else |
| 205 | RT_TRACE(COMP_FIRMWARE, "Download Firmware: Firmware ready!\n"); |
| 206 | |
| 207 | return rt_status; |
| 208 | |
| 209 | CPUCheckFirmwareReady_Fail: |
| 210 | RT_TRACE(COMP_ERR, "ERR in %s()\n", __func__); |
| 211 | rt_status = false; |
| 212 | return rt_status; |
| 213 | |
| 214 | } |
| 215 | |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 216 | static bool firmware_check_ready(struct net_device *dev, |
| 217 | u8 load_fw_status) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 218 | { |
Larry Finger | e3e3762 | 2011-07-19 00:26:41 -0500 | [diff] [blame] | 219 | struct r8192_priv *priv = rtllib_priv(dev); |
Larry Finger | 5aca114 | 2011-07-18 23:10:50 -0500 | [diff] [blame] | 220 | struct rt_firmware *pfirmware = priv->pFirmware; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 221 | bool rt_status = true; |
| 222 | |
| 223 | switch (load_fw_status) { |
| 224 | case FW_INIT_STEP0_BOOT: |
| 225 | pfirmware->firmware_status = FW_STATUS_1_MOVE_BOOT_CODE; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 226 | break; |
| 227 | |
| 228 | case FW_INIT_STEP1_MAIN: |
| 229 | pfirmware->firmware_status = FW_STATUS_2_MOVE_MAIN_CODE; |
| 230 | |
| 231 | rt_status = CPUcheck_maincodeok_turnonCPU(dev); |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 232 | if (rt_status) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 233 | pfirmware->firmware_status = FW_STATUS_3_TURNON_CPU; |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 234 | else |
| 235 | RT_TRACE(COMP_FIRMWARE, "CPUcheck_maincodeok_turnon" |
| 236 | "CPU fail!\n"); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 237 | |
| 238 | break; |
| 239 | |
| 240 | case FW_INIT_STEP2_DATA: |
| 241 | pfirmware->firmware_status = FW_STATUS_4_MOVE_DATA_CODE; |
| 242 | mdelay(1); |
| 243 | |
| 244 | rt_status = CPUcheck_firmware_ready(dev); |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 245 | if (rt_status) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 246 | pfirmware->firmware_status = FW_STATUS_5_READY; |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 247 | else |
| 248 | RT_TRACE(COMP_FIRMWARE, "CPUcheck_firmware_ready fail" |
| 249 | "(%d)!\n", rt_status); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 250 | |
| 251 | break; |
| 252 | default: |
| 253 | rt_status = false; |
| 254 | RT_TRACE(COMP_FIRMWARE, "Unknown firware status"); |
| 255 | break; |
| 256 | } |
| 257 | |
| 258 | return rt_status; |
| 259 | } |
| 260 | |
| 261 | bool init_firmware(struct net_device *dev) |
| 262 | { |
Larry Finger | e3e3762 | 2011-07-19 00:26:41 -0500 | [diff] [blame] | 263 | struct r8192_priv *priv = rtllib_priv(dev); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 264 | bool rt_status = true; |
| 265 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 266 | u8 *firmware_img_buf[3] = { &Rtl8192PciEFwBootArray[0], |
| 267 | &Rtl8192PciEFwMainArray[0], |
| 268 | &Rtl8192PciEFwDataArray[0]}; |
| 269 | |
| 270 | u32 firmware_img_len[3] = { sizeof(Rtl8192PciEFwBootArray), |
| 271 | sizeof(Rtl8192PciEFwMainArray), |
| 272 | sizeof(Rtl8192PciEFwDataArray)}; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 273 | u32 file_length = 0; |
| 274 | u8 *mapped_file = NULL; |
| 275 | u8 init_step = 0; |
Larry Finger | 6bf0400 | 2011-07-19 13:13:24 -0500 | [diff] [blame] | 276 | enum opt_rst_type rst_opt = OPT_SYSTEM_RESET; |
Larry Finger | cec0769 | 2011-07-19 13:11:41 -0500 | [diff] [blame] | 277 | enum firmware_init_step starting_state = FW_INIT_STEP0_BOOT; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 278 | |
Larry Finger | 5aca114 | 2011-07-18 23:10:50 -0500 | [diff] [blame] | 279 | struct rt_firmware *pfirmware = priv->pFirmware; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 280 | |
| 281 | RT_TRACE(COMP_FIRMWARE, " PlatformInitFirmware()==>\n"); |
| 282 | |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 283 | if (pfirmware->firmware_status == FW_STATUS_0_INIT) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 284 | rst_opt = OPT_SYSTEM_RESET; |
| 285 | starting_state = FW_INIT_STEP0_BOOT; |
| 286 | |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 287 | } else if (pfirmware->firmware_status == FW_STATUS_5_READY) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 288 | rst_opt = OPT_FIRMWARE_RESET; |
| 289 | starting_state = FW_INIT_STEP2_DATA; |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 290 | } else { |
| 291 | RT_TRACE(COMP_FIRMWARE, "PlatformInitFirmware: undefined" |
| 292 | " firmware state\n"); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 293 | } |
| 294 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 295 | priv->firmware_source = FW_SOURCE_IMG_FILE; |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 296 | for (init_step = starting_state; init_step <= FW_INIT_STEP2_DATA; |
| 297 | init_step++) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 298 | if (rst_opt == OPT_SYSTEM_RESET) { |
| 299 | switch (priv->firmware_source) { |
| 300 | case FW_SOURCE_IMG_FILE: |
| 301 | { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 302 | if (pfirmware->firmware_buf_size[init_step] == 0) { |
| 303 | const char *fw_name[3] = { "RTL8192E/boot.img", |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 304 | "RTL8192E/main.img", |
| 305 | "RTL8192E/data.img" |
| 306 | }; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 307 | const struct firmware *fw_entry; |
| 308 | int rc; |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 309 | rc = request_firmware(&fw_entry, |
| 310 | fw_name[init_step], &priv->pdev->dev); |
| 311 | if (rc < 0) { |
| 312 | RT_TRACE(COMP_FIRMWARE, "request firm" |
| 313 | "ware fail!\n"); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 314 | goto download_firmware_fail; |
| 315 | } |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 316 | if (fw_entry->size > |
| 317 | sizeof(pfirmware->firmware_buf[init_step])) { |
| 318 | RT_TRACE(COMP_FIRMWARE, "img file size " |
| 319 | "exceed the container struct " |
| 320 | "buffer fail!\n"); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 321 | goto download_firmware_fail; |
| 322 | } |
| 323 | |
| 324 | if (init_step != FW_INIT_STEP1_MAIN) { |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 325 | memcpy(pfirmware->firmware_buf[init_step], |
| 326 | fw_entry->data, fw_entry->size); |
| 327 | pfirmware->firmware_buf_size[init_step] = |
| 328 | fw_entry->size; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 329 | |
| 330 | } else { |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 331 | memset(pfirmware->firmware_buf[init_step], |
| 332 | 0, 128); |
| 333 | memcpy(&pfirmware->firmware_buf[init_step][128], |
| 334 | fw_entry->data, fw_entry->size); |
| 335 | pfirmware->firmware_buf_size[init_step] = |
| 336 | fw_entry->size + 128; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 337 | } |
| 338 | |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 339 | if (rst_opt == OPT_SYSTEM_RESET) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 340 | release_firmware(fw_entry); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 341 | } |
| 342 | mapped_file = pfirmware->firmware_buf[init_step]; |
| 343 | file_length = pfirmware->firmware_buf_size[init_step]; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 344 | break; |
| 345 | } |
| 346 | case FW_SOURCE_HEADER_FILE: |
| 347 | mapped_file = firmware_img_buf[init_step]; |
| 348 | file_length = firmware_img_len[init_step]; |
| 349 | if (init_step == FW_INIT_STEP2_DATA) { |
| 350 | memcpy(pfirmware->firmware_buf[init_step], mapped_file, file_length); |
| 351 | pfirmware->firmware_buf_size[init_step] = file_length; |
| 352 | } |
| 353 | break; |
| 354 | |
| 355 | default: |
| 356 | break; |
| 357 | } |
| 358 | |
| 359 | |
| 360 | } else if (rst_opt == OPT_FIRMWARE_RESET) { |
| 361 | mapped_file = pfirmware->firmware_buf[init_step]; |
| 362 | file_length = pfirmware->firmware_buf_size[init_step]; |
| 363 | } |
| 364 | |
Larry Finger | 11632a0 | 2011-08-25 11:48:15 -0500 | [diff] [blame^] | 365 | rt_status = fw_download_code(dev, mapped_file, file_length); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 366 | if (rt_status != true) { |
| 367 | goto download_firmware_fail; |
| 368 | } |
| 369 | |
| 370 | if (!firmware_check_ready(dev, init_step)) { |
| 371 | goto download_firmware_fail; |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | RT_TRACE(COMP_FIRMWARE, "Firmware Download Success\n"); |
| 376 | return rt_status; |
| 377 | |
| 378 | download_firmware_fail: |
| 379 | RT_TRACE(COMP_ERR, "ERR in %s()\n", __func__); |
| 380 | rt_status = false; |
| 381 | return rt_status; |
| 382 | |
| 383 | } |