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);*/
40 errno
= InterfaceWRM(psIntfAdapter
, on_chip_loc
, buff
, len
);
42 BCM_DEBUG_PRINT(psIntfAdapter
->psAdapter
,
43 DBG_TYPE_PRINTK
, 0, 0,
44 "WRM Failed! status: %d", errno
);
47 on_chip_loc
+= MAX_TRANSFER_CTRL_BYTE_USB
;
54 int InterfaceFileReadbackFromChip(PVOID arg
, struct file
*flp
,
55 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;
62 static int fw_down
= 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
)
76 is_config_file
= (on_chip_loc
== CONFIG_BEGIN_ADDR
)? 1:0;
78 memset(buff_readback
, 0, MAX_TRANSFER_CTRL_BYTE_USB
);
79 memset(buff
, 0, MAX_TRANSFER_CTRL_BYTE_USB
);
82 oldfs
=get_fs(); set_fs(get_ds());
83 len
=vfs_read(flp
, (void __force __user
*)buff
, MAX_TRANSFER_CTRL_BYTE_USB
, &pos
);
90 BCM_DEBUG_PRINT(psIntfAdapter
->psAdapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "len < 0");
96 BCM_DEBUG_PRINT(psIntfAdapter
->psAdapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "Got end of file!");
102 Status
= InterfaceRDM(psIntfAdapter
, on_chip_loc
, buff_readback
, len
);
105 BCM_DEBUG_PRINT(psIntfAdapter
->psAdapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "RDM of len %d Failed! %d", len
, reg
);
109 if((len
-sizeof(unsigned int))<4)
111 if(memcmp(buff_readback
, buff
, len
))
113 BCM_DEBUG_PRINT(psIntfAdapter
->psAdapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "Firmware Download is not proper %d", fw_down
);
114 BCM_DEBUG_PRINT(psIntfAdapter
->psAdapter
,DBG_TYPE_INITEXIT
, MP_INIT
,DBG_LVL_ALL
,"Length is: %d",len
);
124 if(*(unsigned int*)&buff_readback
[len
] != *(unsigned int *)&buff
[len
])
126 BCM_DEBUG_PRINT(psIntfAdapter
->psAdapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "Firmware Download is not proper %d", fw_down
);
127 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
]);
128 BCM_DEBUG_PRINT(psIntfAdapter
->psAdapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "len =%x!!!", len
);
135 on_chip_loc
+=MAX_TRANSFER_CTRL_BYTE_USB
;
136 }/* End of while(1)*/
139 kfree(buff_readback
);
143 static int bcm_download_config_file(PMINI_ADAPTER Adapter
,
144 FIRMWARE_INFO
*psFwInfo
)
146 int retval
= STATUS_SUCCESS
;
149 if(Adapter
->pstargetparams
== NULL
)
151 if((Adapter
->pstargetparams
=
152 kmalloc(sizeof(STARGETPARAMS
), GFP_KERNEL
)) == NULL
)
157 if(psFwInfo
->u32FirmwareLength
!= sizeof(STARGETPARAMS
))
161 retval
= copy_from_user(Adapter
->pstargetparams
,
162 psFwInfo
->pvMappedFirmwareAddress
, psFwInfo
->u32FirmwareLength
);
165 kfree(Adapter
->pstargetparams
);
166 Adapter
->pstargetparams
= NULL
;
169 /* Parse the structure and then Download the Firmware */
170 beceem_parse_target_struct(Adapter
);
172 //Initializing the NVM.
175 retval
= InitLedSettings (Adapter
);
179 BCM_DEBUG_PRINT (Adapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "INIT LED Failed\n");
183 if(Adapter
->LEDInfo
.led_thread_running
& BCM_LED_THREAD_RUNNING_ACTIVELY
)
185 Adapter
->LEDInfo
.bLedInitDone
= FALSE
;
186 Adapter
->DriverState
= DRIVER_INIT
;
187 wake_up(&Adapter
->LEDInfo
.notify_led_event
);
190 if(Adapter
->LEDInfo
.led_thread_running
& BCM_LED_THREAD_RUNNING_ACTIVELY
)
192 Adapter
->DriverState
= FW_DOWNLOAD
;
193 wake_up(&Adapter
->LEDInfo
.notify_led_event
);
196 /* Initialize the DDR Controller */
197 retval
= ddr_init(Adapter
);
200 BCM_DEBUG_PRINT (Adapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "DDR Init Failed\n");
205 wrmalt(Adapter
, EEPROM_CAL_DATA_INTERNAL_LOC
- 4, &value
, sizeof(value
));
206 wrmalt(Adapter
, EEPROM_CAL_DATA_INTERNAL_LOC
- 8, &value
, sizeof(value
));
208 if(Adapter
->eNVMType
== NVM_FLASH
)
210 retval
= PropagateCalParamsFromFlashToMemory(Adapter
);
213 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
,"propagaion of cal param failed with status :%d", retval
);
219 retval
=buffDnldVerify(Adapter
,(PUCHAR
)Adapter
->pstargetparams
,sizeof(STARGETPARAMS
),CONFIG_BEGIN_ADDR
);
223 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "configuration file not downloaded properly");
226 Adapter
->bCfgDownloaded
= TRUE
;
231 static int bcm_compare_buff_contents(unsigned char *readbackbuff
,
232 unsigned char *buff
,unsigned int len
)
234 int retval
= STATUS_SUCCESS
;
235 PMINI_ADAPTER Adapter
= GET_BCM_ADAPTER(gblpnetdev
);
236 if((len
-sizeof(unsigned int))<4)
238 if(memcmp(readbackbuff
, buff
, len
))
248 if(*(unsigned int*)&readbackbuff
[len
] !=
249 *(unsigned int *)&buff
[len
])
251 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "Firmware Download is not proper");
252 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
]);
253 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "len =%x!!!", len
);
262 int bcm_ioctl_fw_download(PMINI_ADAPTER Adapter
, FIRMWARE_INFO
*psFwInfo
)
264 int retval
= STATUS_SUCCESS
;
267 /* Config File is needed for the Driver to download the Config file and
268 Firmware. Check for the Config file to be first to be sent from the
271 atomic_set (&Adapter
->uiMBupdate
, FALSE
);
272 if(!Adapter
->bCfgDownloaded
&&
273 psFwInfo
->u32StartingAddress
!= CONFIG_BEGIN_ADDR
)
275 /*Can't Download Firmware.*/
276 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
,"Download the config File first\n");
280 /* If Config File, Finish the DDR Settings and then Download CFG File */
281 if(psFwInfo
->u32StartingAddress
== CONFIG_BEGIN_ADDR
)
283 retval
= bcm_download_config_file (Adapter
, psFwInfo
);
288 buff
= kzalloc(psFwInfo
->u32FirmwareLength
,GFP_KERNEL
);
291 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
,"Failed in allocation memory");
294 retval
= copy_from_user(buff
,psFwInfo
->pvMappedFirmwareAddress
, psFwInfo
->u32FirmwareLength
);
295 if(retval
!= STATUS_SUCCESS
)
297 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "copying buffer from user space failed");
302 retval
= buffDnldVerify(Adapter
,
304 psFwInfo
->u32FirmwareLength
,
305 psFwInfo
->u32StartingAddress
);
306 if(retval
!= STATUS_SUCCESS
)
308 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
,"f/w download failed status :%d", retval
);
317 static INT
buffDnld(PMINI_ADAPTER Adapter
, PUCHAR mappedbuffer
, UINT u32FirmwareLength
,
318 ULONG u32StartingAddress
)
321 unsigned int len
= 0;
322 int retval
= STATUS_SUCCESS
;
323 len
= u32FirmwareLength
;
325 while(u32FirmwareLength
)
327 len
= MIN_VAL (u32FirmwareLength
, MAX_TRANSFER_CTRL_BYTE_USB
);
328 retval
= wrm (Adapter
, u32StartingAddress
, mappedbuffer
, len
);
331 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "wrm failed with status :%d", retval
);
334 u32StartingAddress
+= len
;
335 u32FirmwareLength
-= len
;
342 static INT
buffRdbkVerify(PMINI_ADAPTER Adapter
,
343 PUCHAR mappedbuffer
, UINT u32FirmwareLength
,
344 ULONG u32StartingAddress
)
346 UINT len
= u32FirmwareLength
;
347 INT retval
= STATUS_SUCCESS
;
348 PUCHAR readbackbuff
= kzalloc(MAX_TRANSFER_CTRL_BYTE_USB
,GFP_KERNEL
);
350 if(NULL
== readbackbuff
)
352 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "MEMORY ALLOCATION FAILED");
355 while (u32FirmwareLength
&& !retval
)
358 len
= MIN_VAL (u32FirmwareLength
, MAX_TRANSFER_CTRL_BYTE_USB
);
360 retval
= rdm (Adapter
, u32StartingAddress
, readbackbuff
, len
);
363 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "rdm failed with status %d" ,retval
);
367 if (STATUS_SUCCESS
!= (retval
= bcm_compare_buff_contents (readbackbuff
, mappedbuffer
, len
)))
371 u32StartingAddress
+= len
;
372 u32FirmwareLength
-= len
;
374 }/* end of while (u32FirmwareLength && !retval) */
379 INT
buffDnldVerify(PMINI_ADAPTER Adapter
, unsigned char *mappedbuffer
, unsigned int u32FirmwareLength
,
380 unsigned long u32StartingAddress
)
382 INT status
= STATUS_SUCCESS
;
384 status
= buffDnld(Adapter
,mappedbuffer
,u32FirmwareLength
,u32StartingAddress
);
385 if(status
!= STATUS_SUCCESS
)
387 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
,"Buffer download failed");
391 status
= buffRdbkVerify(Adapter
,mappedbuffer
,u32FirmwareLength
,u32StartingAddress
);
392 if(status
!= STATUS_SUCCESS
)
394 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
,"Buffer readback verifier failed");