4 int InterfaceFileDownload( PVOID arg
,
6 unsigned int on_chip_loc
)
9 mm_segment_t oldfs
={0};
10 int errno
=0, len
=0 /*,is_config_file = 0*/;
12 PS_INTERFACE_ADAPTER psIntfAdapter
= (PS_INTERFACE_ADAPTER
)arg
;
13 //PMINI_ADAPTER Adapter = psIntfAdapter->psAdapter;
14 char *buff
=kmalloc(MAX_TRANSFER_CTRL_BYTE_USB
, GFP_KERNEL
);
22 oldfs
=get_fs(); set_fs(get_ds());
23 len
=vfs_read(flp
, (void __force __user
*)buff
, MAX_TRANSFER_CTRL_BYTE_USB
, &pos
);
29 BCM_DEBUG_PRINT(psIntfAdapter
->psAdapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "len < 0");
35 BCM_DEBUG_PRINT(psIntfAdapter
->psAdapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "Got end of file!");
39 //BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, buff, MAX_TRANSFER_CTRL_BYTE_USB);
40 errno
= InterfaceWRM(psIntfAdapter
, on_chip_loc
, buff
, len
) ;
43 BCM_DEBUG_PRINT(psIntfAdapter
->psAdapter
,DBG_TYPE_PRINTK
, 0, 0, "WRM Failed! status: %d", errno
);
47 on_chip_loc
+=MAX_TRANSFER_CTRL_BYTE_USB
;
54 int InterfaceFileReadbackFromChip( PVOID arg
,
56 unsigned int on_chip_loc
)
58 char *buff
, *buff_readback
;
60 mm_segment_t oldfs
={0};
61 int errno
=0, len
=0, is_config_file
= 0;
63 static int fw_down
= 0;
64 INT Status
= STATUS_SUCCESS
;
65 PS_INTERFACE_ADAPTER psIntfAdapter
= (PS_INTERFACE_ADAPTER
)arg
;
67 buff
=kmalloc(MAX_TRANSFER_CTRL_BYTE_USB
, GFP_DMA
);
68 buff_readback
=kmalloc(MAX_TRANSFER_CTRL_BYTE_USB
, GFP_DMA
);
69 if(!buff
|| !buff_readback
)
77 is_config_file
= (on_chip_loc
== CONFIG_BEGIN_ADDR
)? 1:0;
79 memset(buff_readback
, 0, MAX_TRANSFER_CTRL_BYTE_USB
);
80 memset(buff
, 0, MAX_TRANSFER_CTRL_BYTE_USB
);
83 oldfs
=get_fs(); set_fs(get_ds());
84 len
=vfs_read(flp
, (void __force __user
*)buff
, MAX_TRANSFER_CTRL_BYTE_USB
, &pos
);
91 BCM_DEBUG_PRINT(psIntfAdapter
->psAdapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "len < 0");
97 BCM_DEBUG_PRINT(psIntfAdapter
->psAdapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "Got end of file!");
103 Status
= InterfaceRDM(psIntfAdapter
, on_chip_loc
, buff_readback
, len
);
106 BCM_DEBUG_PRINT(psIntfAdapter
->psAdapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "RDM of len %d Failed! %d", len
, reg
);
110 if((len
-sizeof(unsigned int))<4)
112 if(memcmp(buff_readback
, buff
, len
))
114 BCM_DEBUG_PRINT(psIntfAdapter
->psAdapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "Firmware Download is not proper %d", fw_down
);
115 BCM_DEBUG_PRINT(psIntfAdapter
->psAdapter
,DBG_TYPE_INITEXIT
, MP_INIT
,DBG_LVL_ALL
,"Length is: %d",len
);
125 if(*(unsigned int*)&buff_readback
[len
] != *(unsigned int *)&buff
[len
])
127 BCM_DEBUG_PRINT(psIntfAdapter
->psAdapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "Firmware Download is not proper %d", fw_down
);
128 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
]);
129 BCM_DEBUG_PRINT(psIntfAdapter
->psAdapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "len =%x!!!", len
);
136 on_chip_loc
+=MAX_TRANSFER_CTRL_BYTE_USB
;
137 }/* End of while(1)*/
140 kfree(buff_readback
);
144 static int bcm_download_config_file(PMINI_ADAPTER Adapter
,
145 FIRMWARE_INFO
*psFwInfo
)
147 int retval
= STATUS_SUCCESS
;
150 if(Adapter
->pstargetparams
== NULL
)
152 if((Adapter
->pstargetparams
=
153 kmalloc(sizeof(STARGETPARAMS
), GFP_KERNEL
)) == NULL
)
158 if(psFwInfo
->u32FirmwareLength
!= sizeof(STARGETPARAMS
))
162 retval
= copy_from_user(Adapter
->pstargetparams
,
163 psFwInfo
->pvMappedFirmwareAddress
, psFwInfo
->u32FirmwareLength
);
166 kfree(Adapter
->pstargetparams
);
167 Adapter
->pstargetparams
= NULL
;
170 /* Parse the structure and then Download the Firmware */
171 beceem_parse_target_struct(Adapter
);
173 //Initializing the NVM.
176 retval
= InitLedSettings (Adapter
);
180 BCM_DEBUG_PRINT (Adapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "INIT LED Failed\n");
184 if(Adapter
->LEDInfo
.led_thread_running
& BCM_LED_THREAD_RUNNING_ACTIVELY
)
186 Adapter
->LEDInfo
.bLedInitDone
= FALSE
;
187 Adapter
->DriverState
= DRIVER_INIT
;
188 wake_up(&Adapter
->LEDInfo
.notify_led_event
);
191 if(Adapter
->LEDInfo
.led_thread_running
& BCM_LED_THREAD_RUNNING_ACTIVELY
)
193 Adapter
->DriverState
= FW_DOWNLOAD
;
194 wake_up(&Adapter
->LEDInfo
.notify_led_event
);
197 /* Initialize the DDR Controller */
198 retval
= ddr_init(Adapter
);
201 BCM_DEBUG_PRINT (Adapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "DDR Init Failed\n");
206 wrmalt(Adapter
, EEPROM_CAL_DATA_INTERNAL_LOC
- 4, &value
, sizeof(value
));
207 wrmalt(Adapter
, EEPROM_CAL_DATA_INTERNAL_LOC
- 8, &value
, sizeof(value
));
209 if(Adapter
->eNVMType
== NVM_FLASH
)
211 retval
= PropagateCalParamsFromFlashToMemory(Adapter
);
214 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
,"propagaion of cal param failed with status :%d", retval
);
220 retval
=buffDnldVerify(Adapter
,(PUCHAR
)Adapter
->pstargetparams
,sizeof(STARGETPARAMS
),CONFIG_BEGIN_ADDR
);
224 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "configuration file not downloaded properly");
227 Adapter
->bCfgDownloaded
= TRUE
;
232 static int bcm_compare_buff_contents(unsigned char *readbackbuff
,
233 unsigned char *buff
,unsigned int len
)
235 int retval
= STATUS_SUCCESS
;
236 PMINI_ADAPTER Adapter
= GET_BCM_ADAPTER(gblpnetdev
);
237 if((len
-sizeof(unsigned int))<4)
239 if(memcmp(readbackbuff
, buff
, len
))
249 if(*(unsigned int*)&readbackbuff
[len
] !=
250 *(unsigned int *)&buff
[len
])
252 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "Firmware Download is not proper");
253 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
]);
254 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "len =%x!!!", len
);
263 int bcm_ioctl_fw_download(PMINI_ADAPTER Adapter
, FIRMWARE_INFO
*psFwInfo
)
265 int retval
= STATUS_SUCCESS
;
268 /* Config File is needed for the Driver to download the Config file and
269 Firmware. Check for the Config file to be first to be sent from the
272 atomic_set (&Adapter
->uiMBupdate
, FALSE
);
273 if(!Adapter
->bCfgDownloaded
&&
274 psFwInfo
->u32StartingAddress
!= CONFIG_BEGIN_ADDR
)
276 /*Can't Download Firmware.*/
277 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
,"Download the config File first\n");
281 /* If Config File, Finish the DDR Settings and then Download CFG File */
282 if(psFwInfo
->u32StartingAddress
== CONFIG_BEGIN_ADDR
)
284 retval
= bcm_download_config_file (Adapter
, psFwInfo
);
289 buff
= kzalloc(psFwInfo
->u32FirmwareLength
,GFP_KERNEL
);
292 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
,"Failed in allocation memory");
295 retval
= copy_from_user(buff
,psFwInfo
->pvMappedFirmwareAddress
, psFwInfo
->u32FirmwareLength
);
296 if(retval
!= STATUS_SUCCESS
)
298 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "copying buffer from user space failed");
303 retval
= buffDnldVerify(Adapter
,
305 psFwInfo
->u32FirmwareLength
,
306 psFwInfo
->u32StartingAddress
);
307 if(retval
!= STATUS_SUCCESS
)
309 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
,"f/w download failed status :%d", retval
);
318 static INT
buffDnld(PMINI_ADAPTER Adapter
, PUCHAR mappedbuffer
, UINT u32FirmwareLength
,
319 ULONG u32StartingAddress
)
322 unsigned int len
= 0;
323 int retval
= STATUS_SUCCESS
;
324 len
= u32FirmwareLength
;
326 while(u32FirmwareLength
)
328 len
= MIN_VAL (u32FirmwareLength
, MAX_TRANSFER_CTRL_BYTE_USB
);
329 retval
= wrm (Adapter
, u32StartingAddress
, mappedbuffer
, len
);
332 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "wrm failed with status :%d", retval
);
335 u32StartingAddress
+= len
;
336 u32FirmwareLength
-= len
;
343 static INT
buffRdbkVerify(PMINI_ADAPTER Adapter
,
344 PUCHAR mappedbuffer
, UINT u32FirmwareLength
,
345 ULONG u32StartingAddress
)
347 UINT len
= u32FirmwareLength
;
348 INT retval
= STATUS_SUCCESS
;
349 PUCHAR readbackbuff
= kzalloc(MAX_TRANSFER_CTRL_BYTE_USB
,GFP_KERNEL
);
351 if(NULL
== readbackbuff
)
353 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "MEMORY ALLOCATION FAILED");
356 while (u32FirmwareLength
&& !retval
)
359 len
= MIN_VAL (u32FirmwareLength
, MAX_TRANSFER_CTRL_BYTE_USB
);
361 retval
= rdm (Adapter
, u32StartingAddress
, readbackbuff
, len
);
364 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
, "rdm failed with status %d" ,retval
);
368 if (STATUS_SUCCESS
!= (retval
= bcm_compare_buff_contents (readbackbuff
, mappedbuffer
, len
)))
372 u32StartingAddress
+= len
;
373 u32FirmwareLength
-= len
;
375 }/* end of while (u32FirmwareLength && !retval) */
380 INT
buffDnldVerify(PMINI_ADAPTER Adapter
, unsigned char *mappedbuffer
, unsigned int u32FirmwareLength
,
381 unsigned long u32StartingAddress
)
383 INT status
= STATUS_SUCCESS
;
385 status
= buffDnld(Adapter
,mappedbuffer
,u32FirmwareLength
,u32StartingAddress
);
386 if(status
!= STATUS_SUCCESS
)
388 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
,"Buffer download failed");
392 status
= buffRdbkVerify(Adapter
,mappedbuffer
,u32FirmwareLength
,u32StartingAddress
);
393 if(status
!= STATUS_SUCCESS
)
395 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_INITEXIT
, MP_INIT
, DBG_LVL_ALL
,"Buffer readback verifier failed");