3 int InterfaceFileDownload(PVOID arg
, struct file
*flp
, unsigned int on_chip_loc
)
5 /* unsigned int reg = 0; */
6 mm_segment_t oldfs
= {0};
7 int errno
= 0, len
= 0; /* ,is_config_file = 0 */
9 PS_INTERFACE_ADAPTER psIntfAdapter
= (PS_INTERFACE_ADAPTER
)arg
;
10 /* PMINI_ADAPTER Adapter = psIntfAdapter->psAdapter; */
11 char *buff
= kmalloc(MAX_TRANSFER_CTRL_BYTE_USB
, GFP_KERNEL
);
19 len
= vfs_read(flp
, (void __force __user
*)buff
,
20 MAX_TRANSFER_CTRL_BYTE_USB
, &pos
);
24 BCM_DEBUG_PRINT(psIntfAdapter
->psAdapter
,
25 DBG_TYPE_INITEXIT
, MP_INIT
,
26 DBG_LVL_ALL
, "len < 0");
30 BCM_DEBUG_PRINT(psIntfAdapter
->psAdapter
,
31 DBG_TYPE_INITEXIT
, MP_INIT
,
37 /* BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_INITEXIT, MP_INIT,
39 * MAX_TRANSFER_CTRL_BYTE_USB);
41 errno
= InterfaceWRM(psIntfAdapter
, on_chip_loc
, buff
, len
);
43 BCM_DEBUG_PRINT(psIntfAdapter
->psAdapter
,
44 DBG_TYPE_PRINTK
, 0, 0,
45 "WRM Failed! status: %d", errno
);
48 on_chip_loc
+= MAX_TRANSFER_CTRL_BYTE_USB
;
55 int InterfaceFileReadbackFromChip(PVOID arg
, struct file
*flp
, unsigned int on_chip_loc
)
57 char *buff
, *buff_readback
;
59 mm_segment_t oldfs
= {0};
60 int errno
= 0, len
= 0, is_config_file
= 0;
63 INT Status
= STATUS_SUCCESS
;
64 PS_INTERFACE_ADAPTER psIntfAdapter
= (PS_INTERFACE_ADAPTER
)arg
;
66 buff
= kmalloc(MAX_TRANSFER_CTRL_BYTE_USB
, GFP_DMA
);
67 buff_readback
= kmalloc(MAX_TRANSFER_CTRL_BYTE_USB
, GFP_DMA
);
68 if (!buff
|| !buff_readback
) {
75 is_config_file
= (on_chip_loc
== CONFIG_BEGIN_ADDR
) ? 1 : 0;
77 memset(buff_readback
, 0, MAX_TRANSFER_CTRL_BYTE_USB
);
78 memset(buff
, 0, MAX_TRANSFER_CTRL_BYTE_USB
);
82 len
= vfs_read(flp
, (void __force __user
*)buff
, MAX_TRANSFER_CTRL_BYTE_USB
, &pos
);
88 BCM_DEBUG_PRINT(psIntfAdapter
->psAdapter
, DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "len < 0");
92 BCM_DEBUG_PRINT(psIntfAdapter
->psAdapter
, DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "Got end of file!");
97 Status
= InterfaceRDM(psIntfAdapter
, on_chip_loc
, buff_readback
, len
);
99 BCM_DEBUG_PRINT(psIntfAdapter
->psAdapter
, DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "RDM of len %d Failed! %d", len
, reg
);
103 if ((len
-sizeof(unsigned int)) < 4) {
104 if (memcmp(buff_readback
, buff
, len
)) {
105 BCM_DEBUG_PRINT(psIntfAdapter
->psAdapter
, DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "Firmware Download is not proper %d", fw_down
);
106 BCM_DEBUG_PRINT(psIntfAdapter
->psAdapter
, DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "Length is: %d", len
);
114 if (*(unsigned int *)&buff_readback
[len
] != *(unsigned int *)&buff
[len
]) {
115 BCM_DEBUG_PRINT(psIntfAdapter
->psAdapter
, DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "Firmware Download is not proper %d", fw_down
);
116 BCM_DEBUG_PRINT(psIntfAdapter
->psAdapter
, DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "Val from Binary %x, Val From Read Back %x ", *(unsigned int *)&buff
[len
], *(unsigned int*)&buff_readback
[len
]);
117 BCM_DEBUG_PRINT(psIntfAdapter
->psAdapter
, DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "len =%x!!!", len
);
124 on_chip_loc
+= MAX_TRANSFER_CTRL_BYTE_USB
;
125 } /* End of while(1) */
129 kfree(buff_readback
);
133 static int bcm_download_config_file(PMINI_ADAPTER Adapter
, FIRMWARE_INFO
*psFwInfo
)
135 int retval
= STATUS_SUCCESS
;
138 if (Adapter
->pstargetparams
== NULL
) {
139 Adapter
->pstargetparams
= kmalloc(sizeof(STARGETPARAMS
), GFP_KERNEL
);
140 if (Adapter
->pstargetparams
== NULL
)
144 if (psFwInfo
->u32FirmwareLength
!= sizeof(STARGETPARAMS
))
147 retval
= copy_from_user(Adapter
->pstargetparams
, psFwInfo
->pvMappedFirmwareAddress
, psFwInfo
->u32FirmwareLength
);
149 kfree(Adapter
->pstargetparams
);
150 Adapter
->pstargetparams
= NULL
;
154 /* Parse the structure and then Download the Firmware */
155 beceem_parse_target_struct(Adapter
);
157 /* Initializing the NVM. */
159 retval
= InitLedSettings(Adapter
);
162 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "INIT LED Failed\n");
166 if (Adapter
->LEDInfo
.led_thread_running
& BCM_LED_THREAD_RUNNING_ACTIVELY
) {
167 Adapter
->LEDInfo
.bLedInitDone
= FALSE
;
168 Adapter
->DriverState
= DRIVER_INIT
;
169 wake_up(&Adapter
->LEDInfo
.notify_led_event
);
172 if (Adapter
->LEDInfo
.led_thread_running
& BCM_LED_THREAD_RUNNING_ACTIVELY
) {
173 Adapter
->DriverState
= FW_DOWNLOAD
;
174 wake_up(&Adapter
->LEDInfo
.notify_led_event
);
177 /* Initialize the DDR Controller */
178 retval
= ddr_init(Adapter
);
180 BCM_DEBUG_PRINT (Adapter
, DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "DDR Init Failed\n");
185 wrmalt(Adapter
, EEPROM_CAL_DATA_INTERNAL_LOC
- 4, &value
, sizeof(value
));
186 wrmalt(Adapter
, EEPROM_CAL_DATA_INTERNAL_LOC
- 8, &value
, sizeof(value
));
188 if (Adapter
->eNVMType
== NVM_FLASH
) {
189 retval
= PropagateCalParamsFromFlashToMemory(Adapter
);
191 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "propagaion of cal param failed with status :%d", retval
);
196 retval
= buffDnldVerify(Adapter
, (PUCHAR
)Adapter
->pstargetparams
, sizeof(STARGETPARAMS
), CONFIG_BEGIN_ADDR
);
199 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "configuration file not downloaded properly");
201 Adapter
->bCfgDownloaded
= TRUE
;
206 static int bcm_compare_buff_contents(unsigned char *readbackbuff
, unsigned char *buff
, unsigned int len
)
208 int retval
= STATUS_SUCCESS
;
209 PMINI_ADAPTER Adapter
= GET_BCM_ADAPTER(gblpnetdev
);
210 if ((len
-sizeof(unsigned int)) < 4) {
211 if (memcmp(readbackbuff
, buff
, len
))
217 if (*(unsigned int *)&readbackbuff
[len
] != *(unsigned int *)&buff
[len
]) {
218 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "Firmware Download is not proper");
219 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "Val from Binary %x, Val From Read Back %x ", *(unsigned int *)&buff
[len
], *(unsigned int*)&readbackbuff
[len
]);
220 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "len =%x!!!", len
);
230 int bcm_ioctl_fw_download(PMINI_ADAPTER Adapter
, FIRMWARE_INFO
*psFwInfo
)
232 int retval
= STATUS_SUCCESS
;
235 /* Config File is needed for the Driver to download the Config file and
236 * Firmware. Check for the Config file to be first to be sent from the
239 atomic_set(&Adapter
->uiMBupdate
, FALSE
);
240 if (!Adapter
->bCfgDownloaded
&& psFwInfo
->u32StartingAddress
!= CONFIG_BEGIN_ADDR
) {
241 /* Can't Download Firmware. */
242 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "Download the config File first\n");
246 /* If Config File, Finish the DDR Settings and then Download CFG File */
247 if (psFwInfo
->u32StartingAddress
== CONFIG_BEGIN_ADDR
) {
248 retval
= bcm_download_config_file(Adapter
, psFwInfo
);
250 buff
= kzalloc(psFwInfo
->u32FirmwareLength
, GFP_KERNEL
);
252 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "Failed in allocation memory");
256 retval
= copy_from_user(buff
, psFwInfo
->pvMappedFirmwareAddress
, psFwInfo
->u32FirmwareLength
);
257 if (retval
!= STATUS_SUCCESS
) {
258 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "copying buffer from user space failed");
263 retval
= buffDnldVerify(Adapter
,
265 psFwInfo
->u32FirmwareLength
,
266 psFwInfo
->u32StartingAddress
);
268 if (retval
!= STATUS_SUCCESS
) {
269 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "f/w download failed status :%d", retval
);
279 static INT
buffDnld(PMINI_ADAPTER Adapter
, PUCHAR mappedbuffer
, UINT u32FirmwareLength
, ULONG u32StartingAddress
)
281 unsigned int len
= 0;
282 int retval
= STATUS_SUCCESS
;
283 len
= u32FirmwareLength
;
285 while (u32FirmwareLength
) {
286 len
= MIN_VAL(u32FirmwareLength
, MAX_TRANSFER_CTRL_BYTE_USB
);
287 retval
= wrm(Adapter
, u32StartingAddress
, mappedbuffer
, len
);
290 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "wrm failed with status :%d", retval
);
293 u32StartingAddress
+= len
;
294 u32FirmwareLength
-= len
;
300 static INT
buffRdbkVerify(PMINI_ADAPTER Adapter
, PUCHAR mappedbuffer
, UINT u32FirmwareLength
, ULONG u32StartingAddress
)
302 UINT len
= u32FirmwareLength
;
303 INT retval
= STATUS_SUCCESS
;
304 PUCHAR readbackbuff
= kzalloc(MAX_TRANSFER_CTRL_BYTE_USB
, GFP_KERNEL
);
306 if (NULL
== readbackbuff
) {
307 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "MEMORY ALLOCATION FAILED");
311 while (u32FirmwareLength
&& !retval
) {
312 len
= MIN_VAL(u32FirmwareLength
, MAX_TRANSFER_CTRL_BYTE_USB
);
313 retval
= rdm(Adapter
, u32StartingAddress
, readbackbuff
, len
);
316 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "rdm failed with status %d", retval
);
320 retval
= bcm_compare_buff_contents(readbackbuff
, mappedbuffer
, len
);
321 if (STATUS_SUCCESS
!= retval
)
324 u32StartingAddress
+= len
;
325 u32FirmwareLength
-= len
;
328 } /* end of while (u32FirmwareLength && !retval) */
333 INT
buffDnldVerify(PMINI_ADAPTER Adapter
, unsigned char *mappedbuffer
, unsigned int u32FirmwareLength
, unsigned long u32StartingAddress
)
335 INT status
= STATUS_SUCCESS
;
337 status
= buffDnld(Adapter
, mappedbuffer
, u32FirmwareLength
, u32StartingAddress
);
338 if (status
!= STATUS_SUCCESS
) {
339 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "Buffer download failed");
343 status
= buffRdbkVerify(Adapter
, mappedbuffer
, u32FirmwareLength
, u32StartingAddress
);
344 if (status
!= STATUS_SUCCESS
) {
345 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "Buffer readback verifier failed");