32 #include <linux/device.h>
33 #include <linux/usb/ch9.h>
35 #include <linux/module.h>
41 #define FWBUFF_ALIGN_SZ 512
42 #define MAX_DUMP_FWSZ 49152
55 usb_set_intfdata(pusb_intf,
NULL);
58 padapter->
fw = firmware;
64 static const char firmware_file[] =
"rtlwifi/rtl8712u.bin";
82 static u32 rtl871x_open_fw(
struct _adapter *padapter,
const u8 **ppmappedfw)
86 if (padapter->
fw->size > 200000) {
88 (
int)padapter->
fw->size);
91 *ppmappedfw = (
u8 *)((*praw)->data);
95 static void fill_fwpriv(
struct _adapter *padapter,
struct fw_priv *pfwpriv)
105 switch (pregpriv->rf_config) {
116 pfwpriv->
mp_mode = (pregpriv->mp_mode == 1) ? 1 : 0;
117 pfwpriv->
vcsType = pregpriv->vrtl_carrier_sense;
118 pfwpriv->
vcsMode = pregpriv->vcs_type;
120 pfwpriv->
turboMode = ((pregpriv->wifi_test == 1) ? 0 : 1);
124 static void update_fwhdr(
struct fw_hdr *pfwhdr,
const u8 *pmappedfw)
138 static u8 chk_fwhdr(
struct fw_hdr *pfwhdr,
u32 ulfilelength)
147 intf = (
u8)((pfwhdr->
version&0x3000) >> 12);
149 rfconf = (
u8)((pfwhdr->
version&0xC000) >> 14);
157 if (fw_sz != ulfilelength)
162 static u8 rtl8712_dl_fw(
struct _adapter *padapter)
167 u32 maxlen = 0, tmp32;
168 uint dump_imem_sz, imem_sz, dump_emem_sz, emem_sz;
171 const u8 *pmappedfw =
NULL;
177 ulfilelength = rtl871x_open_fw(padapter, &pmappedfw);
178 if (pmappedfw && (ulfilelength > 0)) {
179 update_fwhdr(&fwhdr, pmappedfw);
180 if (chk_fwhdr(&fwhdr, ulfilelength) ==
_FAIL)
182 fill_fwpriv(padapter, &fwhdr.fwpriv);
184 maxlen = (fwhdr.img_IMEM_size > fwhdr.img_SRAM_size) ?
185 fwhdr.img_IMEM_size : fwhdr.img_SRAM_size;
188 if (ptmpchar ==
NULL)
193 ppayload = (
u8 *)(ptx_desc) + txdscp_sz;
198 imem_sz = fwhdr.img_IMEM_size;
204 dump_imem_sz = imem_sz;
209 memcpy(ppayload, ptr, dump_imem_sz);
214 imem_sz -= dump_imem_sz;
215 }
while (imem_sz > 0);
227 emem_sz = fwhdr.img_SRAM_size;
233 dump_emem_sz = emem_sz;
238 memcpy(ppayload, ptr, dump_emem_sz);
242 emem_sz -= dump_emem_sz;
243 }
while (emem_sz > 0);
258 if (tmp8_a != (tmp8|
BIT(2)))
264 if (tmp8_a != (tmp8|
BIT(2)))
272 while (((tmp16 &
_IMEM_RDY) == 0) && (i > 0)) {
290 memcpy(ppayload, &fwhdr.fwpriv, fwhdr.fw_priv_sz);
312 while (((tmp16 &
_FWRDY) == 0) && (i > 0)) {
334 if (rtl8712_dl_fw(padapter) !=
_SUCCESS)
358 for (i = 0; i < 6; i++)