]>
Commit | Line | Data |
---|---|---|
f8942e07 SH |
1 | #include "headers.h" |
2 | ||
43664e14 | 3 | int InterfaceFileDownload(PVOID arg, struct file *flp, unsigned int on_chip_loc) |
f8942e07 | 4 | { |
a5e4b81e | 5 | /* unsigned int reg = 0; */ |
43664e14 | 6 | mm_segment_t oldfs = {0}; |
a5e4b81e | 7 | int errno = 0, len = 0; /* ,is_config_file = 0 */ |
43664e14 | 8 | loff_t pos = 0; |
f8942e07 | 9 | PS_INTERFACE_ADAPTER psIntfAdapter = (PS_INTERFACE_ADAPTER)arg; |
a5e4b81e | 10 | /* PMINI_ADAPTER Adapter = psIntfAdapter->psAdapter; */ |
43664e14 | 11 | char *buff = kmalloc(MAX_TRANSFER_CTRL_BYTE_USB, GFP_KERNEL); |
f8942e07 | 12 | |
43664e14 MPS |
13 | if (!buff) |
14 | return -ENOMEM; | |
f8942e07 | 15 | |
43664e14 MPS |
16 | while (1) { |
17 | oldfs = get_fs(); | |
18 | set_fs(get_ds()); | |
19 | len = vfs_read(flp, (void __force __user *)buff, | |
a5e4b81e | 20 | MAX_TRANSFER_CTRL_BYTE_USB, &pos); |
43664e14 MPS |
21 | set_fs(oldfs); |
22 | if (len <= 0) { | |
23 | if (len < 0) { | |
24 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, | |
25 | DBG_TYPE_INITEXIT, MP_INIT, | |
26 | DBG_LVL_ALL, "len < 0"); | |
27 | errno = len; | |
28 | } else { | |
29 | errno = 0; | |
30 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, | |
31 | DBG_TYPE_INITEXIT, MP_INIT, | |
32 | DBG_LVL_ALL, | |
33 | "Got end of file!"); | |
34 | } | |
35 | break; | |
36 | } | |
37 | /* BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_INITEXIT, MP_INIT, | |
a5e4b81e KM |
38 | * DBG_LVL_ALL, buff, |
39 | * MAX_TRANSFER_CTRL_BYTE_USB); | |
40 | */ | |
43664e14 MPS |
41 | errno = InterfaceWRM(psIntfAdapter, on_chip_loc, buff, len); |
42 | if (errno) { | |
43 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, | |
44 | DBG_TYPE_PRINTK, 0, 0, | |
45 | "WRM Failed! status: %d", errno); | |
46 | break; | |
f8942e07 | 47 | } |
43664e14 MPS |
48 | on_chip_loc += MAX_TRANSFER_CTRL_BYTE_USB; |
49 | } | |
f8942e07 | 50 | |
082e889b | 51 | kfree(buff); |
43664e14 | 52 | return errno; |
f8942e07 SH |
53 | } |
54 | ||
a5e4b81e | 55 | int InterfaceFileReadbackFromChip(PVOID arg, struct file *flp, unsigned int on_chip_loc) |
f8942e07 | 56 | { |
43664e14 MPS |
57 | char *buff, *buff_readback; |
58 | unsigned int reg = 0; | |
a5e4b81e KM |
59 | mm_segment_t oldfs = {0}; |
60 | int errno = 0, len = 0, is_config_file = 0; | |
61 | loff_t pos = 0; | |
a8658182 | 62 | static int fw_down; |
a5e4b81e | 63 | INT Status = STATUS_SUCCESS; |
f8942e07 | 64 | PS_INTERFACE_ADAPTER psIntfAdapter = (PS_INTERFACE_ADAPTER)arg; |
41c7b7c0 | 65 | int bytes; |
f8942e07 | 66 | |
a5e4b81e KM |
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) { | |
70 | kfree(buff); | |
71 | kfree(buff_readback); | |
f8942e07 | 72 | |
a5e4b81e KM |
73 | return -ENOMEM; |
74 | } | |
f8942e07 | 75 | |
a5e4b81e | 76 | is_config_file = (on_chip_loc == CONFIG_BEGIN_ADDR) ? 1 : 0; |
f8942e07 SH |
77 | |
78 | memset(buff_readback, 0, MAX_TRANSFER_CTRL_BYTE_USB); | |
79 | memset(buff, 0, MAX_TRANSFER_CTRL_BYTE_USB); | |
a5e4b81e KM |
80 | while (1) { |
81 | oldfs = get_fs(); | |
82 | set_fs(get_ds()); | |
83 | len = vfs_read(flp, (void __force __user *)buff, MAX_TRANSFER_CTRL_BYTE_USB, &pos); | |
84 | set_fs(oldfs); | |
85 | fw_down++; | |
f8942e07 | 86 | |
a5e4b81e KM |
87 | if (len <= 0) { |
88 | if (len < 0) { | |
89 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "len < 0"); | |
90 | errno = len; | |
91 | } else { | |
92 | errno = 0; | |
93 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Got end of file!"); | |
94 | } | |
95 | break; | |
96 | } | |
f8942e07 | 97 | |
41c7b7c0 KM |
98 | bytes = InterfaceRDM(psIntfAdapter, on_chip_loc, buff_readback, len); |
99 | if (bytes < 0) { | |
100 | Status = bytes; | |
a5e4b81e | 101 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "RDM of len %d Failed! %d", len, reg); |
f8942e07 SH |
102 | goto exit; |
103 | } | |
104 | reg++; | |
a5e4b81e KM |
105 | if ((len-sizeof(unsigned int)) < 4) { |
106 | if (memcmp(buff_readback, buff, len)) { | |
107 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Firmware Download is not proper %d", fw_down); | |
108 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Length is: %d", len); | |
f8942e07 SH |
109 | Status = -EIO; |
110 | goto exit; | |
a5e4b81e KM |
111 | } |
112 | } else { | |
113 | len -= 4; | |
114 | ||
115 | while (len) { | |
116 | if (*(unsigned int *)&buff_readback[len] != *(unsigned int *)&buff[len]) { | |
117 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Firmware Download is not proper %d", fw_down); | |
118 | 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]); | |
119 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "len =%x!!!", len); | |
f8942e07 SH |
120 | Status = -EIO; |
121 | goto exit; | |
a5e4b81e KM |
122 | } |
123 | len -= 4; | |
124 | } | |
125 | } | |
126 | on_chip_loc += MAX_TRANSFER_CTRL_BYTE_USB; | |
127 | } /* End of while(1) */ | |
128 | ||
f8942e07 | 129 | exit: |
a5e4b81e KM |
130 | kfree(buff); |
131 | kfree(buff_readback); | |
f8942e07 SH |
132 | return Status; |
133 | } | |
134 | ||
a5e4b81e | 135 | static int bcm_download_config_file(PMINI_ADAPTER Adapter, FIRMWARE_INFO *psFwInfo) |
f8942e07 SH |
136 | { |
137 | int retval = STATUS_SUCCESS; | |
138 | B_UINT32 value = 0; | |
139 | ||
a5e4b81e | 140 | if (Adapter->pstargetparams == NULL) { |
a8658182 KM |
141 | Adapter->pstargetparams = kmalloc(sizeof(STARGETPARAMS), GFP_KERNEL); |
142 | if (Adapter->pstargetparams == NULL) | |
a5e4b81e | 143 | return -ENOMEM; |
f8942e07 | 144 | } |
a5e4b81e KM |
145 | |
146 | if (psFwInfo->u32FirmwareLength != sizeof(STARGETPARAMS)) | |
147 | return -EIO; | |
148 | ||
149 | retval = copy_from_user(Adapter->pstargetparams, psFwInfo->pvMappedFirmwareAddress, psFwInfo->u32FirmwareLength); | |
150 | if (retval) { | |
082e889b | 151 | kfree(Adapter->pstargetparams); |
f8942e07 | 152 | Adapter->pstargetparams = NULL; |
ef5d2056 | 153 | return -EFAULT; |
f8942e07 | 154 | } |
a5e4b81e | 155 | |
f8942e07 SH |
156 | /* Parse the structure and then Download the Firmware */ |
157 | beceem_parse_target_struct(Adapter); | |
158 | ||
a5e4b81e | 159 | /* Initializing the NVM. */ |
f8942e07 | 160 | BcmInitNVM(Adapter); |
a5e4b81e | 161 | retval = InitLedSettings(Adapter); |
f8942e07 | 162 | |
a5e4b81e KM |
163 | if (retval) { |
164 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "INIT LED Failed\n"); | |
f8942e07 SH |
165 | return retval; |
166 | } | |
167 | ||
a5e4b81e | 168 | if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) { |
f8942e07 SH |
169 | Adapter->LEDInfo.bLedInitDone = FALSE; |
170 | Adapter->DriverState = DRIVER_INIT; | |
171 | wake_up(&Adapter->LEDInfo.notify_led_event); | |
172 | } | |
173 | ||
a5e4b81e | 174 | if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) { |
f8942e07 SH |
175 | Adapter->DriverState = FW_DOWNLOAD; |
176 | wake_up(&Adapter->LEDInfo.notify_led_event); | |
177 | } | |
178 | ||
179 | /* Initialize the DDR Controller */ | |
180 | retval = ddr_init(Adapter); | |
a5e4b81e KM |
181 | if (retval) { |
182 | BCM_DEBUG_PRINT (Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "DDR Init Failed\n"); | |
f8942e07 SH |
183 | return retval; |
184 | } | |
185 | ||
186 | value = 0; | |
187 | wrmalt(Adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 4, &value, sizeof(value)); | |
188 | wrmalt(Adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 8, &value, sizeof(value)); | |
189 | ||
a5e4b81e | 190 | if (Adapter->eNVMType == NVM_FLASH) { |
f8942e07 | 191 | retval = PropagateCalParamsFromFlashToMemory(Adapter); |
a5e4b81e KM |
192 | if (retval) { |
193 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "propagaion of cal param failed with status :%d", retval); | |
f8942e07 SH |
194 | return retval; |
195 | } | |
196 | } | |
197 | ||
a5e4b81e | 198 | retval = buffDnldVerify(Adapter, (PUCHAR)Adapter->pstargetparams, sizeof(STARGETPARAMS), CONFIG_BEGIN_ADDR); |
f8942e07 | 199 | |
a5e4b81e KM |
200 | if (retval) |
201 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "configuration file not downloaded properly"); | |
f8942e07 SH |
202 | else |
203 | Adapter->bCfgDownloaded = TRUE; | |
204 | ||
f8942e07 SH |
205 | return retval; |
206 | } | |
a5e4b81e KM |
207 | |
208 | static int bcm_compare_buff_contents(unsigned char *readbackbuff, unsigned char *buff, unsigned int len) | |
f8942e07 SH |
209 | { |
210 | int retval = STATUS_SUCCESS; | |
a5e4b81e KM |
211 | PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev); |
212 | if ((len-sizeof(unsigned int)) < 4) { | |
213 | if (memcmp(readbackbuff , buff, len)) | |
214 | retval = -EINVAL; | |
215 | } else { | |
216 | len -= 4; | |
217 | ||
218 | while (len) { | |
219 | if (*(unsigned int *)&readbackbuff[len] != *(unsigned int *)&buff[len]) { | |
220 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Firmware Download is not proper"); | |
221 | 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]); | |
222 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "len =%x!!!", len); | |
223 | retval = -EINVAL; | |
f8942e07 SH |
224 | break; |
225 | } | |
a5e4b81e | 226 | len -= 4; |
f8942e07 SH |
227 | } |
228 | } | |
229 | return retval; | |
230 | } | |
a5e4b81e | 231 | |
f8942e07 SH |
232 | int bcm_ioctl_fw_download(PMINI_ADAPTER Adapter, FIRMWARE_INFO *psFwInfo) |
233 | { | |
234 | int retval = STATUS_SUCCESS; | |
235 | PUCHAR buff = NULL; | |
236 | ||
a5e4b81e KM |
237 | /* Config File is needed for the Driver to download the Config file and |
238 | * Firmware. Check for the Config file to be first to be sent from the | |
239 | * Application | |
240 | */ | |
241 | atomic_set(&Adapter->uiMBupdate, FALSE); | |
242 | if (!Adapter->bCfgDownloaded && psFwInfo->u32StartingAddress != CONFIG_BEGIN_ADDR) { | |
243 | /* Can't Download Firmware. */ | |
244 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Download the config File first\n"); | |
f8942e07 SH |
245 | return -EINVAL; |
246 | } | |
247 | ||
248 | /* If Config File, Finish the DDR Settings and then Download CFG File */ | |
a5e4b81e KM |
249 | if (psFwInfo->u32StartingAddress == CONFIG_BEGIN_ADDR) { |
250 | retval = bcm_download_config_file(Adapter, psFwInfo); | |
251 | } else { | |
252 | buff = kzalloc(psFwInfo->u32FirmwareLength, GFP_KERNEL); | |
253 | if (buff == NULL) { | |
254 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Failed in allocation memory"); | |
f8942e07 SH |
255 | return -ENOMEM; |
256 | } | |
a5e4b81e KM |
257 | |
258 | retval = copy_from_user(buff, psFwInfo->pvMappedFirmwareAddress, psFwInfo->u32FirmwareLength); | |
259 | if (retval != STATUS_SUCCESS) { | |
260 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "copying buffer from user space failed"); | |
ef5d2056 | 261 | retval = -EFAULT; |
a5e4b81e | 262 | goto error; |
f8942e07 SH |
263 | } |
264 | ||
f8942e07 SH |
265 | retval = buffDnldVerify(Adapter, |
266 | buff, | |
267 | psFwInfo->u32FirmwareLength, | |
268 | psFwInfo->u32StartingAddress); | |
a5e4b81e KM |
269 | |
270 | if (retval != STATUS_SUCCESS) { | |
271 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "f/w download failed status :%d", retval); | |
f8942e07 SH |
272 | goto error; |
273 | } | |
274 | } | |
a5e4b81e | 275 | |
f8942e07 | 276 | error: |
082e889b | 277 | kfree(buff); |
f8942e07 SH |
278 | return retval; |
279 | } | |
280 | ||
a5e4b81e | 281 | static INT buffDnld(PMINI_ADAPTER Adapter, PUCHAR mappedbuffer, UINT u32FirmwareLength, ULONG u32StartingAddress) |
f8942e07 | 282 | { |
a5e4b81e | 283 | unsigned int len = 0; |
f8942e07 SH |
284 | int retval = STATUS_SUCCESS; |
285 | len = u32FirmwareLength; | |
286 | ||
a5e4b81e KM |
287 | while (u32FirmwareLength) { |
288 | len = MIN_VAL(u32FirmwareLength, MAX_TRANSFER_CTRL_BYTE_USB); | |
289 | retval = wrm(Adapter, u32StartingAddress, mappedbuffer, len); | |
290 | ||
291 | if (retval) { | |
292 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "wrm failed with status :%d", retval); | |
f8942e07 SH |
293 | break; |
294 | } | |
a5e4b81e KM |
295 | u32StartingAddress += len; |
296 | u32FirmwareLength -= len; | |
297 | mappedbuffer += len; | |
f8942e07 SH |
298 | } |
299 | return retval; | |
f8942e07 SH |
300 | } |
301 | ||
a5e4b81e | 302 | static INT buffRdbkVerify(PMINI_ADAPTER Adapter, PUCHAR mappedbuffer, UINT u32FirmwareLength, ULONG u32StartingAddress) |
f8942e07 | 303 | { |
f8942e07 SH |
304 | UINT len = u32FirmwareLength; |
305 | INT retval = STATUS_SUCCESS; | |
a5e4b81e | 306 | PUCHAR readbackbuff = kzalloc(MAX_TRANSFER_CTRL_BYTE_USB, GFP_KERNEL); |
41c7b7c0 | 307 | int bytes; |
f8942e07 | 308 | |
a5e4b81e KM |
309 | if (NULL == readbackbuff) { |
310 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "MEMORY ALLOCATION FAILED"); | |
f8942e07 SH |
311 | return -ENOMEM; |
312 | } | |
f8942e07 | 313 | |
a5e4b81e KM |
314 | while (u32FirmwareLength && !retval) { |
315 | len = MIN_VAL(u32FirmwareLength, MAX_TRANSFER_CTRL_BYTE_USB); | |
41c7b7c0 | 316 | bytes = rdm(Adapter, u32StartingAddress, readbackbuff, len); |
f8942e07 | 317 | |
41c7b7c0 KM |
318 | if (bytes < 0) { |
319 | retval = bytes; | |
a5e4b81e | 320 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "rdm failed with status %d", retval); |
f8942e07 SH |
321 | break; |
322 | } | |
323 | ||
a8658182 KM |
324 | retval = bcm_compare_buff_contents(readbackbuff, mappedbuffer, len); |
325 | if (STATUS_SUCCESS != retval) | |
f8942e07 | 326 | break; |
a5e4b81e KM |
327 | |
328 | u32StartingAddress += len; | |
329 | u32FirmwareLength -= len; | |
330 | mappedbuffer += len; | |
331 | ||
332 | } /* end of while (u32FirmwareLength && !retval) */ | |
082e889b | 333 | kfree(readbackbuff); |
f8942e07 SH |
334 | return retval; |
335 | } | |
336 | ||
a5e4b81e | 337 | INT buffDnldVerify(PMINI_ADAPTER Adapter, unsigned char *mappedbuffer, unsigned int u32FirmwareLength, unsigned long u32StartingAddress) |
f8942e07 SH |
338 | { |
339 | INT status = STATUS_SUCCESS; | |
340 | ||
a5e4b81e KM |
341 | status = buffDnld(Adapter, mappedbuffer, u32FirmwareLength, u32StartingAddress); |
342 | if (status != STATUS_SUCCESS) { | |
343 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Buffer download failed"); | |
f8942e07 SH |
344 | goto error; |
345 | } | |
346 | ||
a5e4b81e KM |
347 | status = buffRdbkVerify(Adapter, mappedbuffer, u32FirmwareLength, u32StartingAddress); |
348 | if (status != STATUS_SUCCESS) { | |
349 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Buffer readback verifier failed"); | |
f8942e07 SH |
350 | goto error; |
351 | } | |
352 | error: | |
353 | return status; | |
354 | } |