2 * CopyRight (C) 2007 Qualcomm Inc. All Rights Reserved.
4 * This file is part of Express Card USB Driver
7 #include <linux/init.h>
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/netdevice.h>
11 #include <linux/etherdevice.h>
12 #include <linux/usb.h>
13 #include <linux/vmalloc.h>
14 #include "ft1000_usb.h"
17 #define DWNLD_HANDSHAKE_LOC 0x02
18 #define DWNLD_TYPE_LOC 0x04
19 #define DWNLD_SIZE_MSW_LOC 0x06
20 #define DWNLD_SIZE_LSW_LOC 0x08
21 #define DWNLD_PS_HDR_LOC 0x0A
23 #define MAX_DSP_WAIT_LOOPS 40
24 #define DSP_WAIT_SLEEP_TIME 1000 /* 1 millisecond */
25 #define DSP_WAIT_DISPATCH_LVL 50 /* 50 usec */
27 #define HANDSHAKE_TIMEOUT_VALUE 0xF1F1
28 #define HANDSHAKE_RESET_VALUE 0xFEFE /* When DSP requests startover */
29 #define HANDSHAKE_RESET_VALUE_USB 0xFE7E /* When DSP requests startover */
30 #define HANDSHAKE_DSP_BL_READY 0xFEFE /* At start DSP writes this when bootloader ready */
31 #define HANDSHAKE_DSP_BL_READY_USB 0xFE7E /* At start DSP writes this when bootloader ready */
32 #define HANDSHAKE_DRIVER_READY 0xFFFF /* Driver writes after receiving 0xFEFE */
33 #define HANDSHAKE_SEND_DATA 0x0000 /* DSP writes this when ready for more data */
35 #define HANDSHAKE_REQUEST 0x0001 /* Request from DSP */
36 #define HANDSHAKE_RESPONSE 0x0000 /* Satisfied DSP request */
38 #define REQUEST_CODE_LENGTH 0x0000
39 #define REQUEST_RUN_ADDRESS 0x0001
40 #define REQUEST_CODE_SEGMENT 0x0002 /* In WORD count */
41 #define REQUEST_DONE_BL 0x0003
42 #define REQUEST_DONE_CL 0x0004
43 #define REQUEST_VERSION_INFO 0x0005
44 #define REQUEST_CODE_BY_VERSION 0x0006
45 #define REQUEST_MAILBOX_DATA 0x0007
46 #define REQUEST_FILE_CHECKSUM 0x0008
48 #define STATE_START_DWNLD 0x01
49 #define STATE_BOOT_DWNLD 0x02
50 #define STATE_CODE_DWNLD 0x03
51 #define STATE_DONE_DWNLD 0x04
52 #define STATE_SECTION_PROV 0x05
53 #define STATE_DONE_PROV 0x06
54 #define STATE_DONE_FILE 0x07
56 #define MAX_LENGTH 0x7f0
58 // Temporary download mechanism for Magnemite
59 #define DWNLD_MAG_TYPE_LOC 0x00
60 #define DWNLD_MAG_LEN_LOC 0x01
61 #define DWNLD_MAG_ADDR_LOC 0x02
62 #define DWNLD_MAG_CHKSUM_LOC 0x03
63 #define DWNLD_MAG_VAL_LOC 0x04
65 #define HANDSHAKE_MAG_DSP_BL_READY 0xFEFE0000 /* At start DSP writes this when bootloader ready */
66 #define HANDSHAKE_MAG_DSP_ENTRY 0x01000000 /* Dsp writes this to request for entry address */
67 #define HANDSHAKE_MAG_DSP_DATA 0x02000000 /* Dsp writes this to request for data block */
68 #define HANDSHAKE_MAG_DSP_DONE 0x03000000 /* Dsp writes this to indicate download done */
70 #define HANDSHAKE_MAG_DRV_READY 0xFFFF0000 /* Driver writes this to indicate ready to download */
71 #define HANDSHAKE_MAG_DRV_DATA 0x02FECDAB /* Driver writes this to indicate data available to DSP */
72 #define HANDSHAKE_MAG_DRV_ENTRY 0x01FECDAB /* Driver writes this to indicate entry point to DSP */
74 #define HANDSHAKE_MAG_TIMEOUT_VALUE 0xF1F1
77 // New Magnemite downloader
78 #define DWNLD_MAG1_HANDSHAKE_LOC 0x00
79 #define DWNLD_MAG1_TYPE_LOC 0x01
80 #define DWNLD_MAG1_SIZE_LOC 0x02
81 #define DWNLD_MAG1_PS_HDR_LOC 0x03
84 long version_id; // Version ID of this image format.
85 long package_id; // Package ID of code release.
86 long build_date; // Date/time stamp when file was built.
87 long commands_offset; // Offset to attached commands in Pseudo Hdr format.
88 long loader_offset; // Offset to bootloader code.
89 long loader_code_address; // Start address of bootloader.
90 long loader_code_end; // Where bootloader code ends.
91 long loader_code_size;
92 long version_data_offset; // Offset were scrambled version data begins.
93 long version_data_size; // Size, in words, of scrambled version data.
94 long nDspImages; // Number of DSP images in file.
98 struct dsp_image_info {
99 long coff_date; // Date/time when DSP Coff image was built.
100 long begin_offset; // Offset in file where image begins.
101 long end_offset; // Offset in file where image begins.
102 long run_address; // On chip Start address of DSP code.
103 long image_size; // Size of image.
104 long version; // Embedded version # of DSP code.
105 unsigned short checksum; // DSP File checksum
110 /* checks if the doorbell register is cleared */
111 static int check_usb_db(struct ft1000_usb *ft1000dev)
119 while (loopcnt < 10) {
120 status = ft1000_read_register(ft1000dev, &temp,
121 FT1000_REG_DOORBELL);
122 DEBUG("check_usb_db: read FT1000_REG_DOORBELL value is %x\n",
125 DEBUG("FT1000:Got checkusb doorbell\n");
126 status = ft1000_write_register(ft1000dev, 0x0080,
127 FT1000_REG_DOORBELL);
128 status = ft1000_write_register(ft1000dev, 0x0100,
129 FT1000_REG_DOORBELL);
130 status = ft1000_write_register(ft1000dev, 0x8000,
131 FT1000_REG_DOORBELL);
141 while (loopcnt < 20) {
142 status = ft1000_read_register(ft1000dev, &temp,
143 FT1000_REG_DOORBELL);
144 DEBUG("FT1000:check_usb_db:Doorbell = 0x%x\n", temp);
149 DEBUG("check_usb_db: door bell is cleared, return 0\n");
154 return HANDSHAKE_MAG_TIMEOUT_VALUE;
157 /* gets the handshake and compares it with the expected value */
158 static u16 get_handshake(struct ft1000_usb *ft1000dev, u16 expected_value)
166 while (loopcnt < 100) {
167 /* Need to clear downloader doorbell if Hartley ASIC */
168 status = ft1000_write_register(ft1000dev, FT1000_DB_DNLD_RX,
169 FT1000_REG_DOORBELL);
170 if (ft1000dev->fcodeldr) {
171 DEBUG(" get_handshake: fcodeldr is %d\n",
172 ft1000dev->fcodeldr);
173 ft1000dev->fcodeldr = 0;
174 status = check_usb_db(ft1000dev);
175 if (status != STATUS_SUCCESS) {
176 DEBUG("get_handshake: check_usb_db failed\n");
177 status = STATUS_FAILURE;
180 status = ft1000_write_register(ft1000dev,
182 FT1000_REG_DOORBELL);
185 status = ft1000_read_dpram16(ft1000dev,
186 DWNLD_MAG1_HANDSHAKE_LOC, (u8 *)&handshake, 1);
187 handshake = ntohs(handshake);
190 return HANDSHAKE_TIMEOUT_VALUE;
192 if ((handshake == expected_value) ||
193 (handshake == HANDSHAKE_RESET_VALUE_USB)) {
201 return HANDSHAKE_TIMEOUT_VALUE;
204 /* write the handshake value to the handshake location */
205 static void put_handshake(struct ft1000_usb *ft1000dev,u16 handshake_value)
211 tempx = (u32)handshake_value;
212 tempx = ntohl(tempx);
214 tempword = (u16)(tempx & 0xffff);
215 status = ft1000_write_dpram16(ft1000dev, DWNLD_MAG1_HANDSHAKE_LOC,
217 tempword = (u16)(tempx >> 16);
218 status = ft1000_write_dpram16(ft1000dev, DWNLD_MAG1_HANDSHAKE_LOC,
220 status = ft1000_write_register(ft1000dev, FT1000_DB_DNLD_TX,
221 FT1000_REG_DOORBELL);
224 static u16 get_handshake_usb(struct ft1000_usb *ft1000dev, u16 expected_value)
234 while (loopcnt < 100) {
235 if (ft1000dev->usbboot == 2) {
236 status = ft1000_read_dpram32(ft1000dev, 0,
237 (u8 *)&(ft1000dev->tempbuf[0]), 64);
238 for (temp = 0; temp < 16; temp++) {
239 DEBUG("tempbuf %d = 0x%x\n", temp,
240 ft1000dev->tempbuf[temp]);
242 status = ft1000_read_dpram16(ft1000dev,
243 DWNLD_MAG1_HANDSHAKE_LOC,
244 (u8 *)&handshake, 1);
245 DEBUG("handshake from read_dpram16 = 0x%x\n",
247 if (ft1000dev->dspalive == ft1000dev->tempbuf[6]) {
250 handshake = ft1000dev->tempbuf[1];
251 ft1000dev->dspalive =
252 ft1000dev->tempbuf[6];
255 status = ft1000_read_dpram16(ft1000dev,
256 DWNLD_MAG1_HANDSHAKE_LOC,
257 (u8 *)&handshake, 1);
262 handshake = ntohs(handshake);
263 if ((handshake == expected_value) ||
264 (handshake == HANDSHAKE_RESET_VALUE_USB))
268 return HANDSHAKE_TIMEOUT_VALUE;
271 static void put_handshake_usb(struct ft1000_usb *ft1000dev,u16 handshake_value)
275 for (i=0; i<1000; i++);
278 static u16 get_request_type(struct ft1000_usb *ft1000dev)
285 if (ft1000dev->bootmode == 1) {
286 status = fix_ft1000_read_dpram32(ft1000dev,
287 DWNLD_MAG1_TYPE_LOC, (u8 *)&tempx);
288 tempx = ntohl(tempx);
291 status = ft1000_read_dpram16(ft1000dev,
292 DWNLD_MAG1_TYPE_LOC, (u8 *)&tempword, 1);
293 tempx |= (tempword << 16);
294 tempx = ntohl(tempx);
296 request_type = (u16)tempx;
301 static u16 get_request_type_usb(struct ft1000_usb *ft1000dev)
308 if (ft1000dev->bootmode == 1) {
309 status = fix_ft1000_read_dpram32(ft1000dev,
310 DWNLD_MAG1_TYPE_LOC, (u8 *)&tempx);
311 tempx = ntohl(tempx);
313 if (ft1000dev->usbboot == 2) {
314 tempx = ft1000dev->tempbuf[2];
315 tempword = ft1000dev->tempbuf[3];
318 status = ft1000_read_dpram16(ft1000dev,
322 tempx |= (tempword << 16);
323 tempx = ntohl(tempx);
325 request_type = (u16)tempx;
330 static long get_request_value(struct ft1000_usb *ft1000dev)
336 if (ft1000dev->bootmode == 1) {
337 status = fix_ft1000_read_dpram32(ft1000dev,
338 DWNLD_MAG1_SIZE_LOC, (u8 *)&value);
339 value = ntohl(value);
341 status = ft1000_read_dpram16(ft1000dev,
342 DWNLD_MAG1_SIZE_LOC, (u8 *)&tempword, 0);
344 status = ft1000_read_dpram16(ft1000dev,
345 DWNLD_MAG1_SIZE_LOC, (u8 *)&tempword, 1);
346 value |= (tempword << 16);
347 value = ntohl(value);
354 /* writes a value to DWNLD_MAG1_SIZE_LOC */
355 static void put_request_value(struct ft1000_usb *ft1000dev, long lvalue)
360 tempx = ntohl(lvalue);
361 status = fix_ft1000_write_dpram32(ft1000dev, DWNLD_MAG1_SIZE_LOC,
367 /* returns the checksum of the pseudo header */
368 static u16 hdr_checksum(struct pseudo_hdr *pHdr)
370 u16 *usPtr = (u16 *)pHdr;
374 chksum = ((((((usPtr[0] ^ usPtr[1]) ^ usPtr[2]) ^ usPtr[3]) ^
375 usPtr[4]) ^ usPtr[5]) ^ usPtr[6]);
380 static int check_buffers(u16 *buff_w, u16 *buff_r, int len, int offset)
384 for (i = 0; i < len; i++) {
385 if (buff_w[i] != buff_r[i + offset])
392 static int write_dpram32_and_check(struct ft1000_usb *ft1000dev,
393 u16 tempbuffer[], u16 dpram)
396 u16 resultbuffer[64];
399 for (i = 0; i < 10; i++) {
400 status = ft1000_write_dpram32(ft1000dev, dpram,
401 (u8 *)&tempbuffer[0], 64);
403 /* Work around for ASIC bit stuffing problem. */
404 if ((tempbuffer[31] & 0xfe00) == 0xfe00) {
405 status = ft1000_write_dpram32(ft1000dev,
406 dpram+12, (u8 *)&tempbuffer[24],
409 /* Let's check the data written */
410 status = ft1000_read_dpram32(ft1000dev, dpram,
411 (u8 *)&resultbuffer[0], 64);
412 if ((tempbuffer[31] & 0xfe00) == 0xfe00) {
413 if (check_buffers(tempbuffer, resultbuffer, 28,
415 DEBUG("FT1000:download:DPRAM write failed 1 during bootloading\n");
416 usleep_range(9000, 11000);
419 status = ft1000_read_dpram32(ft1000dev,
421 (u8 *)&resultbuffer[0], 64);
423 if (check_buffers(tempbuffer, resultbuffer, 16,
425 DEBUG("FT1000:download:DPRAM write failed 2 during bootloading\n");
426 usleep_range(9000, 11000);
430 if (check_buffers(tempbuffer, resultbuffer, 32,
432 DEBUG("FT1000:download:DPRAM write failed 3 during bootloading\n");
433 usleep_range(9000, 11000);
444 /* writes a block of DSP image to DPRAM
445 * Parameters: struct ft1000_usb - device structure
446 * u16 **pUsFile - DSP image file pointer in u16
447 * u8 **pUcFile - DSP image file pointer in u8
448 * long word_length - length of the buffer to be written to DPRAM
450 static int write_blk(struct ft1000_usb *ft1000dev, u16 **pUsFile, u8 **pUcFile,
453 int status = STATUS_SUCCESS;
459 /*DEBUG("FT1000:download:start word_length = %d\n",(int)word_length); */
460 dpram = (u16)DWNLD_MAG1_PS_HDR_LOC;
461 tempword = *(*pUsFile);
463 status = ft1000_write_dpram16(ft1000dev, dpram, tempword, 0);
464 tempword = *(*pUsFile);
466 status = ft1000_write_dpram16(ft1000dev, dpram++, tempword, 1);
468 *pUcFile = *pUcFile + 4;
470 tempword = (u16)word_length;
471 word_length = (word_length / 16) + 1;
472 for (; word_length > 0; word_length--) { /* In words */
474 for (i = 0; i < 32; i++) {
476 tempbuffer[i++] = *(*pUsFile);
478 tempbuffer[i] = *(*pUsFile);
480 *pUcFile = *pUcFile + 4;
489 /*DEBUG("write_blk: loopcnt is %d\n", loopcnt); */
490 /*DEBUG("write_blk: bootmode = %d\n", bootmode); */
491 /*DEBUG("write_blk: dpram = %x\n", dpram); */
492 if (ft1000dev->bootmode == 0) {
494 status = ft1000_write_dpram32(ft1000dev, dpram,
495 (u8 *)&tempbuffer[0], 8);
497 status = ft1000_write_dpram32(ft1000dev, dpram,
498 (u8 *)&tempbuffer[0], 64);
500 status = write_dpram32_and_check(ft1000dev, tempbuffer,
502 if (status != STATUS_SUCCESS) {
503 DEBUG("FT1000:download:Write failed tempbuffer[31] = 0x%x\n", tempbuffer[31]);
507 dpram = dpram + loopcnt;
512 static void usb_dnld_complete (struct urb *urb)
514 //DEBUG("****** usb_dnld_complete\n");
517 /* writes a block of DSP image to DPRAM
518 * Parameters: struct ft1000_usb - device structure
519 * u16 **pUsFile - DSP image file pointer in u16
520 * u8 **pUcFile - DSP image file pointer in u8
521 * long word_length - length of the buffer to be written to DPRAM
523 static int write_blk_fifo(struct ft1000_usb *ft1000dev, u16 **pUsFile,
524 u8 **pUcFile, long word_length)
526 int Status = STATUS_SUCCESS;
529 byte_length = word_length * 4;
531 if (byte_length && ((byte_length % 64) == 0))
534 if (byte_length < 64)
537 usb_init_urb(ft1000dev->tx_urb);
538 memcpy(ft1000dev->tx_buf, *pUcFile, byte_length);
539 usb_fill_bulk_urb(ft1000dev->tx_urb,
541 usb_sndbulkpipe(ft1000dev->dev,
542 ft1000dev->bulk_out_endpointAddr),
543 ft1000dev->tx_buf, byte_length, usb_dnld_complete,
546 usb_submit_urb(ft1000dev->tx_urb, GFP_ATOMIC);
548 *pUsFile = *pUsFile + (word_length << 1);
549 *pUcFile = *pUcFile + (word_length << 2);
554 static int scram_start_dwnld(struct ft1000_usb *ft1000dev, u16 *hshake,
559 DEBUG("FT1000:STATE_START_DWNLD\n");
560 if (ft1000dev->usbboot)
561 *hshake = get_handshake_usb(ft1000dev, HANDSHAKE_DSP_BL_READY);
563 *hshake = get_handshake(ft1000dev, HANDSHAKE_DSP_BL_READY);
564 if (*hshake == HANDSHAKE_DSP_BL_READY) {
565 DEBUG("scram_dnldr: handshake is HANDSHAKE_DSP_BL_READY, call put_handshake(HANDSHAKE_DRIVER_READY)\n");
566 put_handshake(ft1000dev, HANDSHAKE_DRIVER_READY);
567 } else if (*hshake == HANDSHAKE_TIMEOUT_VALUE) {
570 DEBUG("FT1000:download:Download error: Handshake failed\n");
573 *state = STATE_BOOT_DWNLD;
577 static int request_code_segment(struct ft1000_usb *ft1000dev, u16 **s_file,
578 u8 **c_file, const u8 *endpoint, bool boot_case)
583 /*DEBUG("FT1000:REQUEST_CODE_SEGMENT\n");i*/
584 word_length = get_request_value(ft1000dev);
585 /*DEBUG("FT1000:word_length = 0x%x\n", (int)word_length); */
586 /*NdisMSleep (100); */
587 if (word_length > MAX_LENGTH) {
588 DEBUG("FT1000:download:Download error: Max length exceeded\n");
589 return STATUS_FAILURE;
591 if ((word_length * 2 + (long)c_file) > (long)endpoint) {
592 /* Error, beyond boot code range.*/
593 DEBUG("FT1000:download:Download error: Requested len=%d exceeds BOOT code boundary.\n", (int)word_length);
594 return STATUS_FAILURE;
596 if (word_length & 0x1)
598 word_length = word_length / 2;
601 status = write_blk(ft1000dev, s_file, c_file, word_length);
602 /*DEBUG("write_blk returned %d\n", status); */
604 write_blk_fifo(ft1000dev, s_file, c_file, word_length);
605 if (ft1000dev->usbboot == 0)
606 ft1000dev->usbboot++;
607 if (ft1000dev->usbboot == 1)
608 ft1000_write_dpram16(ft1000dev,
609 DWNLD_MAG1_PS_HDR_LOC, 0, 0);
614 /* Scramble downloader for Harley based ASIC via USB interface */
615 int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart,
618 int status = STATUS_SUCCESS;
621 struct pseudo_hdr *pseudo_header;
622 u16 pseudo_header_len;
627 struct dsp_file_hdr *file_hdr;
628 struct dsp_image_info *dsp_img_info = NULL;
629 long requested_version;
630 bool correct_version;
631 struct drv_msg *mailbox_data;
635 u8 *boot_end = NULL, *code_end = NULL;
637 long loader_code_address, loader_code_size = 0;
638 long run_address = 0, run_size = 0;
641 u32 image_chksum = 0;
645 struct prov_record *pprov_record;
646 struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net);
648 DEBUG("Entered scram_dnldr...\n");
650 ft1000dev->fcodeldr = 0;
651 ft1000dev->usbboot = 0;
652 ft1000dev->dspalive = 0xffff;
655 // Get version id of file, at first 4 bytes of file, for newer files.
658 state = STATE_START_DWNLD;
660 file_hdr = (struct dsp_file_hdr *)pFileStart;
662 ft1000_write_register(ft1000dev, 0x800, FT1000_REG_MAG_WATERMARK);
664 s_file = (u16 *) (pFileStart + file_hdr->loader_offset);
665 c_file = (u8 *) (pFileStart + file_hdr->loader_offset);
667 boot_end = (u8 *) (pFileStart + file_hdr->loader_code_end);
669 loader_code_address = file_hdr->loader_code_address;
670 loader_code_size = file_hdr->loader_code_size;
671 correct_version = false;
673 while ((status == STATUS_SUCCESS) && (state != STATE_DONE_FILE)) {
675 case STATE_START_DWNLD:
676 status = scram_start_dwnld(ft1000dev, &handshake,
680 case STATE_BOOT_DWNLD:
681 DEBUG("FT1000:STATE_BOOT_DWNLD\n");
682 ft1000dev->bootmode = 1;
683 handshake = get_handshake(ft1000dev, HANDSHAKE_REQUEST);
684 if (handshake == HANDSHAKE_REQUEST) {
686 * Get type associated with the request.
688 request = get_request_type(ft1000dev);
690 case REQUEST_RUN_ADDRESS:
691 DEBUG("FT1000:REQUEST_RUN_ADDRESS\n");
692 put_request_value(ft1000dev,
693 loader_code_address);
695 case REQUEST_CODE_LENGTH:
696 DEBUG("FT1000:REQUEST_CODE_LENGTH\n");
697 put_request_value(ft1000dev,
700 case REQUEST_DONE_BL:
701 DEBUG("FT1000:REQUEST_DONE_BL\n");
702 /* Reposition ptrs to beginning of code section */
703 s_file = (u16 *) (boot_end);
704 c_file = (u8 *) (boot_end);
705 //DEBUG("FT1000:download:s_file = 0x%8x\n", (int)s_file);
706 //DEBUG("FT1000:download:c_file = 0x%8x\n", (int)c_file);
707 state = STATE_CODE_DWNLD;
708 ft1000dev->fcodeldr = 1;
710 case REQUEST_CODE_SEGMENT:
711 status = request_code_segment(ft1000dev,
713 (const u8 *)boot_end,
718 ("FT1000:download:Download error: Bad request type=%d in BOOT download state.\n",
720 status = STATUS_FAILURE;
723 if (ft1000dev->usbboot)
724 put_handshake_usb(ft1000dev,
727 put_handshake(ft1000dev,
731 ("FT1000:download:Download error: Handshake failed\n");
732 status = STATUS_FAILURE;
737 case STATE_CODE_DWNLD:
738 //DEBUG("FT1000:STATE_CODE_DWNLD\n");
739 ft1000dev->bootmode = 0;
740 if (ft1000dev->usbboot)
742 get_handshake_usb(ft1000dev,
746 get_handshake(ft1000dev, HANDSHAKE_REQUEST);
747 if (handshake == HANDSHAKE_REQUEST) {
749 * Get type associated with the request.
751 if (ft1000dev->usbboot)
753 get_request_type_usb(ft1000dev);
755 request = get_request_type(ft1000dev);
757 case REQUEST_FILE_CHECKSUM:
759 ("FT1000:download:image_chksum = 0x%8x\n",
761 put_request_value(ft1000dev,
764 case REQUEST_RUN_ADDRESS:
766 ("FT1000:download: REQUEST_RUN_ADDRESS\n");
767 if (correct_version) {
769 ("FT1000:download:run_address = 0x%8x\n",
771 put_request_value(ft1000dev,
775 ("FT1000:download:Download error: Got Run address request before image offset request.\n");
776 status = STATUS_FAILURE;
780 case REQUEST_CODE_LENGTH:
782 ("FT1000:download:REQUEST_CODE_LENGTH\n");
783 if (correct_version) {
785 ("FT1000:download:run_size = 0x%8x\n",
787 put_request_value(ft1000dev,
791 ("FT1000:download:Download error: Got Size request before image offset request.\n");
792 status = STATUS_FAILURE;
796 case REQUEST_DONE_CL:
797 ft1000dev->usbboot = 3;
798 /* Reposition ptrs to beginning of provisioning section */
800 (u16 *) (pFileStart +
801 file_hdr->commands_offset);
804 file_hdr->commands_offset);
805 state = STATE_DONE_DWNLD;
807 case REQUEST_CODE_SEGMENT:
808 //DEBUG("FT1000:download: REQUEST_CODE_SEGMENT - CODELOADER\n");
809 if (!correct_version) {
811 ("FT1000:download:Download error: Got Code Segment request before image offset request.\n");
812 status = STATUS_FAILURE;
816 status = request_code_segment(ft1000dev,
818 (const u8 *)code_end,
823 case REQUEST_MAILBOX_DATA:
825 ("FT1000:download: REQUEST_MAILBOX_DATA\n");
826 // Convert length from byte count to word count. Make sure we round up.
828 (long)(pft1000info->DSPInfoBlklen +
830 put_request_value(ft1000dev,
833 (struct drv_msg *)&(pft1000info->
836 * Position ASIC DPRAM auto-increment pointer.
839 data = (u16 *) & mailbox_data->data[0];
840 dpram = (u16) DWNLD_MAG1_PS_HDR_LOC;
841 if (word_length & 0x1)
844 word_length = (word_length / 2);
846 for (; word_length > 0; word_length--) { /* In words */
849 templong |= (*data++ << 16);
851 fix_ft1000_write_dpram32
858 case REQUEST_VERSION_INFO:
860 ("FT1000:download:REQUEST_VERSION_INFO\n");
862 file_hdr->version_data_size;
863 put_request_value(ft1000dev,
866 * Position ASIC DPRAM auto-increment pointer.
870 (u16 *) (pFileStart +
872 version_data_offset);
874 dpram = (u16) DWNLD_MAG1_PS_HDR_LOC;
875 if (word_length & 0x1)
878 word_length = (word_length / 2);
880 for (; word_length > 0; word_length--) { /* In words */
882 templong = ntohs(*s_file++);
883 temp = ntohs(*s_file++);
884 templong |= (temp << 16);
886 fix_ft1000_write_dpram32
893 case REQUEST_CODE_BY_VERSION:
895 ("FT1000:download:REQUEST_CODE_BY_VERSION\n");
896 correct_version = false;
898 get_request_value(ft1000dev);
901 (struct dsp_image_info *)(pFileStart
908 image < file_hdr->nDspImages;
911 if (dsp_img_info->version ==
913 correct_version = true;
915 ("FT1000:download: correct_version is TRUE\n");
944 if (!correct_version) {
946 * Error, beyond boot code range.
949 ("FT1000:download:Download error: Bad Version Request = 0x%x.\n",
950 (int)requested_version);
951 status = STATUS_FAILURE;
958 ("FT1000:download:Download error: Bad request type=%d in CODE download state.\n",
960 status = STATUS_FAILURE;
963 if (ft1000dev->usbboot)
964 put_handshake_usb(ft1000dev,
967 put_handshake(ft1000dev,
971 ("FT1000:download:Download error: Handshake failed\n");
972 status = STATUS_FAILURE;
977 case STATE_DONE_DWNLD:
978 DEBUG("FT1000:download:Code loader is done...\n");
979 state = STATE_SECTION_PROV;
982 case STATE_SECTION_PROV:
983 DEBUG("FT1000:download:STATE_SECTION_PROV\n");
984 pseudo_header = (struct pseudo_hdr *)c_file;
986 if (pseudo_header->checksum ==
987 hdr_checksum(pseudo_header)) {
988 if (pseudo_header->portdest !=
989 0x80 /* Dsp OAM */) {
990 state = STATE_DONE_PROV;
993 pseudo_header_len = ntohs(pseudo_header->length); /* Byte length for PROV records */
995 /* Get buffer for provisioning data */
997 kmalloc((pseudo_header_len +
998 sizeof(struct pseudo_hdr)),
1001 memcpy(pbuffer, (void *)c_file,
1002 (u32) (pseudo_header_len +
1005 // link provisioning data
1007 kmalloc(sizeof(struct prov_record),
1010 pprov_record->pprov_data =
1012 list_add_tail(&pprov_record->
1016 // Move to next entry if available
1018 (u8 *) ((unsigned long)
1020 (u32) ((pseudo_header_len + 1) & 0xFFFFFFFE) + sizeof(struct pseudo_hdr));
1021 if ((unsigned long)(c_file) -
1022 (unsigned long)(pFileStart)
1024 (unsigned long)FileLength) {
1025 state = STATE_DONE_FILE;
1029 status = STATUS_FAILURE;
1032 status = STATUS_FAILURE;
1035 /* Checksum did not compute */
1036 status = STATUS_FAILURE;
1039 ("ft1000:download: after STATE_SECTION_PROV, state = %d, status= %d\n",
1043 case STATE_DONE_PROV:
1044 DEBUG("FT1000:download:STATE_DONE_PROV\n");
1045 state = STATE_DONE_FILE;
1049 status = STATUS_FAILURE;
1053 if (status != STATUS_SUCCESS)
1057 // Check if Card is present
1058 status = Harley_Read_Register(&temp, FT1000_REG_SUP_IMASK);
1059 if ( (status != NDIS_STATUS_SUCCESS) || (temp == 0x0000) ) {
1063 status = Harley_Read_Register(&temp, FT1000_REG_ASIC_ID);
1064 if ( (status != NDIS_STATUS_SUCCESS) || (temp == 0xffff) ) {
1071 DEBUG("Download exiting with status = 0x%8x\n", status);
1072 ft1000_write_register(ft1000dev, FT1000_DB_DNLD_TX,
1073 FT1000_REG_DOORBELL);