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 struct bcm_interface_adapter
*psIntfAdapter
= arg
;
10 /* struct bcm_mini_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
);
29 /* BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_INITEXIT, MP_INIT,
31 * MAX_TRANSFER_CTRL_BYTE_USB);
33 errno
= InterfaceWRM(psIntfAdapter
, on_chip_loc
, buff
, len
);
36 on_chip_loc
+= MAX_TRANSFER_CTRL_BYTE_USB
;
43 int InterfaceFileReadbackFromChip(PVOID arg
, struct file
*flp
,
44 unsigned int on_chip_loc
)
46 char *buff
, *buff_readback
;
48 mm_segment_t oldfs
= {0};
49 int errno
= 0, len
= 0, is_config_file
= 0;
52 INT Status
= STATUS_SUCCESS
;
53 struct bcm_interface_adapter
*psIntfAdapter
= arg
;
56 buff
= kmalloc(MAX_TRANSFER_CTRL_BYTE_USB
, GFP_DMA
);
57 buff_readback
= kmalloc(MAX_TRANSFER_CTRL_BYTE_USB
, GFP_DMA
);
58 if (!buff
|| !buff_readback
) {
65 is_config_file
= (on_chip_loc
== CONFIG_BEGIN_ADDR
) ? 1 : 0;
67 memset(buff_readback
, 0, MAX_TRANSFER_CTRL_BYTE_USB
);
68 memset(buff
, 0, MAX_TRANSFER_CTRL_BYTE_USB
);
72 len
= vfs_read(flp
, (void __force __user
*)buff
,
73 MAX_TRANSFER_CTRL_BYTE_USB
, &pos
);
85 bytes
= InterfaceRDM(psIntfAdapter
, on_chip_loc
,
92 if ((len
-sizeof(unsigned int)) < 4) {
93 if (memcmp(buff_readback
, buff
, len
)) {
101 if (*(unsigned int *)&buff_readback
[len
] !=
102 *(unsigned int *)&buff
[len
]) {
109 on_chip_loc
+= MAX_TRANSFER_CTRL_BYTE_USB
;
110 } /* End of while(1) */
114 kfree(buff_readback
);
118 static int bcm_download_config_file(struct bcm_mini_adapter
*Adapter
,
119 struct bcm_firmware_info
*psFwInfo
)
121 int retval
= STATUS_SUCCESS
;
124 if (Adapter
->pstargetparams
== NULL
) {
125 Adapter
->pstargetparams
=
126 kmalloc(sizeof(struct bcm_target_params
), GFP_KERNEL
);
127 if (Adapter
->pstargetparams
== NULL
)
131 if (psFwInfo
->u32FirmwareLength
!= sizeof(struct bcm_target_params
))
134 retval
= copy_from_user(Adapter
->pstargetparams
,
135 psFwInfo
->pvMappedFirmwareAddress
,
136 psFwInfo
->u32FirmwareLength
);
138 kfree(Adapter
->pstargetparams
);
139 Adapter
->pstargetparams
= NULL
;
143 /* Parse the structure and then Download the Firmware */
144 beceem_parse_target_struct(Adapter
);
146 /* Initializing the NVM. */
148 retval
= InitLedSettings(Adapter
);
153 if (Adapter
->LEDInfo
.led_thread_running
&
154 BCM_LED_THREAD_RUNNING_ACTIVELY
) {
155 Adapter
->LEDInfo
.bLedInitDone
= false;
156 Adapter
->DriverState
= DRIVER_INIT
;
157 wake_up(&Adapter
->LEDInfo
.notify_led_event
);
160 if (Adapter
->LEDInfo
.led_thread_running
&
161 BCM_LED_THREAD_RUNNING_ACTIVELY
) {
162 Adapter
->DriverState
= FW_DOWNLOAD
;
163 wake_up(&Adapter
->LEDInfo
.notify_led_event
);
166 /* Initialize the DDR Controller */
167 retval
= ddr_init(Adapter
);
172 wrmalt(Adapter
, EEPROM_CAL_DATA_INTERNAL_LOC
- 4,
173 &value
, sizeof(value
));
174 wrmalt(Adapter
, EEPROM_CAL_DATA_INTERNAL_LOC
- 8,
175 &value
, sizeof(value
));
177 if (Adapter
->eNVMType
== NVM_FLASH
) {
178 retval
= PropagateCalParamsFromFlashToMemory(Adapter
);
183 retval
= buffDnldVerify(Adapter
, (PUCHAR
)Adapter
->pstargetparams
,
184 sizeof(struct bcm_target_params
), CONFIG_BEGIN_ADDR
);
187 BCM_DEBUG_PRINT(Adapter
, DBG_TYPE_INITEXIT
,
188 MP_INIT
, DBG_LVL_ALL
,
189 "configuration file not downloaded properly");
191 Adapter
->bCfgDownloaded
= TRUE
;
196 int bcm_ioctl_fw_download(struct bcm_mini_adapter
*Adapter
,
197 struct bcm_firmware_info
*psFwInfo
)
199 int retval
= STATUS_SUCCESS
;
202 /* Config File is needed for the Driver to download the Config file and
203 * Firmware. Check for the Config file to be first to be sent from the
206 atomic_set(&Adapter
->uiMBupdate
, false);
207 if (!Adapter
->bCfgDownloaded
&&
208 psFwInfo
->u32StartingAddress
!= CONFIG_BEGIN_ADDR
) {
209 /* Can't Download Firmware. */
213 /* If Config File, Finish the DDR Settings and then Download CFG File */
214 if (psFwInfo
->u32StartingAddress
== CONFIG_BEGIN_ADDR
) {
215 retval
= bcm_download_config_file(Adapter
, psFwInfo
);
217 buff
= kzalloc(psFwInfo
->u32FirmwareLength
, GFP_KERNEL
);
221 retval
= copy_from_user(buff
,
222 psFwInfo
->pvMappedFirmwareAddress
,
223 psFwInfo
->u32FirmwareLength
);
224 if (retval
!= STATUS_SUCCESS
) {
229 retval
= buffDnldVerify(Adapter
,
231 psFwInfo
->u32FirmwareLength
,
232 psFwInfo
->u32StartingAddress
);
234 if (retval
!= STATUS_SUCCESS
)
243 static INT
buffDnld(struct bcm_mini_adapter
*Adapter
,
244 PUCHAR mappedbuffer
, UINT u32FirmwareLength
,
245 ULONG u32StartingAddress
)
247 unsigned int len
= 0;
248 int retval
= STATUS_SUCCESS
;
249 len
= u32FirmwareLength
;
251 while (u32FirmwareLength
) {
252 len
= MIN_VAL(u32FirmwareLength
, MAX_TRANSFER_CTRL_BYTE_USB
);
253 retval
= wrm(Adapter
, u32StartingAddress
, mappedbuffer
, len
);
257 u32StartingAddress
+= len
;
258 u32FirmwareLength
-= len
;
264 static INT
buffRdbkVerify(struct bcm_mini_adapter
*Adapter
,
265 PUCHAR mappedbuffer
, UINT u32FirmwareLength
,
266 ULONG u32StartingAddress
)
268 UINT len
= u32FirmwareLength
;
269 INT retval
= STATUS_SUCCESS
;
270 PUCHAR readbackbuff
= kzalloc(MAX_TRANSFER_CTRL_BYTE_USB
, GFP_KERNEL
);
273 if (NULL
== readbackbuff
)
276 while (u32FirmwareLength
&& !retval
) {
277 len
= MIN_VAL(u32FirmwareLength
, MAX_TRANSFER_CTRL_BYTE_USB
);
278 bytes
= rdm(Adapter
, u32StartingAddress
, readbackbuff
, len
);
285 if (memcmp(readbackbuff
, mappedbuffer
, len
) != 0) {
286 pr_err("%s() failed. The firmware doesn't match what was written",
291 u32StartingAddress
+= len
;
292 u32FirmwareLength
-= len
;
295 } /* end of while (u32FirmwareLength && !retval) */
300 INT
buffDnldVerify(struct bcm_mini_adapter
*Adapter
,
301 unsigned char *mappedbuffer
,
302 unsigned int u32FirmwareLength
,
303 unsigned long u32StartingAddress
)
305 INT status
= STATUS_SUCCESS
;
307 status
= buffDnld(Adapter
, mappedbuffer
,
308 u32FirmwareLength
, u32StartingAddress
);
309 if (status
!= STATUS_SUCCESS
)
312 status
= buffRdbkVerify(Adapter
, mappedbuffer
,
313 u32FirmwareLength
, u32StartingAddress
);
314 if (status
!= STATUS_SUCCESS
)