2 * CopyRight (C) 2007 Qualcomm Inc. All Rights Reserved.
4 * This file is part of Express Card USB Driver
7 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/netdevice.h>
12 #include <linux/etherdevice.h>
13 #include <linux/usb.h>
14 #include <linux/vmalloc.h>
15 #include "ft1000_usb.h"
18 #define DWNLD_HANDSHAKE_LOC 0x02
19 #define DWNLD_TYPE_LOC 0x04
20 #define DWNLD_SIZE_MSW_LOC 0x06
21 #define DWNLD_SIZE_LSW_LOC 0x08
22 #define DWNLD_PS_HDR_LOC 0x0A
24 #define MAX_DSP_WAIT_LOOPS 40
25 #define DSP_WAIT_SLEEP_TIME 1000 /* 1 millisecond */
26 #define DSP_WAIT_DISPATCH_LVL 50 /* 50 usec */
28 #define HANDSHAKE_TIMEOUT_VALUE 0xF1F1
29 #define HANDSHAKE_RESET_VALUE 0xFEFE /* When DSP requests startover */
30 #define HANDSHAKE_RESET_VALUE_USB 0xFE7E /* When DSP requests startover */
31 #define HANDSHAKE_DSP_BL_READY 0xFEFE /* At start DSP writes this when bootloader ready */
32 #define HANDSHAKE_DSP_BL_READY_USB 0xFE7E /* At start DSP writes this when bootloader ready */
33 #define HANDSHAKE_DRIVER_READY 0xFFFF /* Driver writes after receiving 0xFEFE */
34 #define HANDSHAKE_SEND_DATA 0x0000 /* DSP writes this when ready for more data */
36 #define HANDSHAKE_REQUEST 0x0001 /* Request from DSP */
37 #define HANDSHAKE_RESPONSE 0x0000 /* Satisfied DSP request */
39 #define REQUEST_CODE_LENGTH 0x0000
40 #define REQUEST_RUN_ADDRESS 0x0001
41 #define REQUEST_CODE_SEGMENT 0x0002 /* In WORD count */
42 #define REQUEST_DONE_BL 0x0003
43 #define REQUEST_DONE_CL 0x0004
44 #define REQUEST_VERSION_INFO 0x0005
45 #define REQUEST_CODE_BY_VERSION 0x0006
46 #define REQUEST_MAILBOX_DATA 0x0007
47 #define REQUEST_FILE_CHECKSUM 0x0008
49 #define STATE_START_DWNLD 0x01
50 #define STATE_BOOT_DWNLD 0x02
51 #define STATE_CODE_DWNLD 0x03
52 #define STATE_DONE_DWNLD 0x04
53 #define STATE_SECTION_PROV 0x05
54 #define STATE_DONE_PROV 0x06
55 #define STATE_DONE_FILE 0x07
57 #define MAX_LENGTH 0x7f0
59 /* Temporary download mechanism for Magnemite */
60 #define DWNLD_MAG_TYPE_LOC 0x00
61 #define DWNLD_MAG_LEN_LOC 0x01
62 #define DWNLD_MAG_ADDR_LOC 0x02
63 #define DWNLD_MAG_CHKSUM_LOC 0x03
64 #define DWNLD_MAG_VAL_LOC 0x04
66 #define HANDSHAKE_MAG_DSP_BL_READY 0xFEFE0000 /* At start DSP writes this when bootloader ready */
67 #define HANDSHAKE_MAG_DSP_ENTRY 0x01000000 /* Dsp writes this to request for entry address */
68 #define HANDSHAKE_MAG_DSP_DATA 0x02000000 /* Dsp writes this to request for data block */
69 #define HANDSHAKE_MAG_DSP_DONE 0x03000000 /* Dsp writes this to indicate download done */
71 #define HANDSHAKE_MAG_DRV_READY 0xFFFF0000 /* Driver writes this to indicate ready to download */
72 #define HANDSHAKE_MAG_DRV_DATA 0x02FECDAB /* Driver writes this to indicate data available to DSP */
73 #define HANDSHAKE_MAG_DRV_ENTRY 0x01FECDAB /* Driver writes this to indicate entry point to DSP */
75 #define HANDSHAKE_MAG_TIMEOUT_VALUE 0xF1F1
78 /* New Magnemite downloader */
79 #define DWNLD_MAG1_HANDSHAKE_LOC 0x00
80 #define DWNLD_MAG1_TYPE_LOC 0x01
81 #define DWNLD_MAG1_SIZE_LOC 0x02
82 #define DWNLD_MAG1_PS_HDR_LOC 0x03
85 long version_id; /* Version ID of this image format. */
86 long package_id; /* Package ID of code release. */
87 long build_date; /* Date/time stamp when file was built. */
88 long commands_offset; /* Offset to attached commands in Pseudo Hdr format. */
89 long loader_offset; /* Offset to bootloader code. */
90 long loader_code_address; /* Start address of bootloader. */
91 long loader_code_end; /* Where bootloader code ends. */
92 long loader_code_size;
93 long version_data_offset; /* Offset were scrambled version data begins. */
94 long version_data_size; /* Size, in words, of scrambled version data. */
95 long nDspImages; /* Number of DSP images in file. */
99 struct dsp_image_info {
100 long coff_date; /* Date/time when DSP Coff image was built. */
101 long begin_offset; /* Offset in file where image begins. */
102 long end_offset; /* Offset in file where image begins. */
103 long run_address; /* On chip Start address of DSP code. */
104 long image_size; /* Size of image. */
105 long version; /* Embedded version # of DSP code. */
106 unsigned short checksum; /* DSP File checksum */
111 /* checks if the doorbell register is cleared */
112 static int check_usb_db(struct ft1000_usb *ft1000dev)
120 while (loopcnt < 10) {
121 status = ft1000_read_register(ft1000dev, &temp,
122 FT1000_REG_DOORBELL);
123 pr_debug("read FT1000_REG_DOORBELL value is %x\n", temp);
125 pr_debug("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);
140 while (loopcnt < 20) {
141 status = ft1000_read_register(ft1000dev, &temp,
142 FT1000_REG_DOORBELL);
143 pr_debug("Doorbell = 0x%x\n", temp);
148 pr_debug("door bell is cleared, return 0\n");
156 /* gets the handshake and compares it with the expected value */
157 static u16 get_handshake(struct ft1000_usb *ft1000dev, u16 expected_value)
165 while (loopcnt < 100) {
166 /* Need to clear downloader doorbell if Hartley ASIC */
167 status = ft1000_write_register(ft1000dev, FT1000_DB_DNLD_RX,
168 FT1000_REG_DOORBELL);
169 if (ft1000dev->fcodeldr) {
170 pr_debug("fcodeldr is %d\n", ft1000dev->fcodeldr);
171 ft1000dev->fcodeldr = 0;
172 status = check_usb_db(ft1000dev);
174 pr_debug("check_usb_db failed\n");
177 status = ft1000_write_register(ft1000dev,
179 FT1000_REG_DOORBELL);
182 status = ft1000_read_dpram16(ft1000dev,
183 DWNLD_MAG1_HANDSHAKE_LOC, (u8 *)&handshake, 1);
184 handshake = ntohs(handshake);
187 return HANDSHAKE_TIMEOUT_VALUE;
189 if ((handshake == expected_value) ||
190 (handshake == HANDSHAKE_RESET_VALUE_USB)) {
197 return HANDSHAKE_TIMEOUT_VALUE;
200 /* write the handshake value to the handshake location */
201 static void put_handshake(struct ft1000_usb *ft1000dev, u16 handshake_value)
207 tempx = (u32)handshake_value;
208 tempx = ntohl(tempx);
210 tempword = (u16)(tempx & 0xffff);
211 status = ft1000_write_dpram16(ft1000dev, DWNLD_MAG1_HANDSHAKE_LOC,
213 tempword = (u16)(tempx >> 16);
214 status = ft1000_write_dpram16(ft1000dev, DWNLD_MAG1_HANDSHAKE_LOC,
216 status = ft1000_write_register(ft1000dev, FT1000_DB_DNLD_TX,
217 FT1000_REG_DOORBELL);
220 static u16 get_handshake_usb(struct ft1000_usb *ft1000dev, u16 expected_value)
230 while (loopcnt < 100) {
231 if (ft1000dev->usbboot == 2) {
232 status = ft1000_read_dpram32(ft1000dev, 0,
233 (u8 *)&ft1000dev->tempbuf[0], 64);
234 for (temp = 0; temp < 16; temp++) {
235 pr_debug("tempbuf %d = 0x%x\n",
236 temp, ft1000dev->tempbuf[temp]);
238 status = ft1000_read_dpram16(ft1000dev,
239 DWNLD_MAG1_HANDSHAKE_LOC,
240 (u8 *)&handshake, 1);
241 pr_debug("handshake from read_dpram16 = 0x%x\n",
243 if (ft1000dev->dspalive == ft1000dev->tempbuf[6]) {
246 handshake = ft1000dev->tempbuf[1];
247 ft1000dev->dspalive =
248 ft1000dev->tempbuf[6];
251 status = ft1000_read_dpram16(ft1000dev,
252 DWNLD_MAG1_HANDSHAKE_LOC,
253 (u8 *)&handshake, 1);
258 handshake = ntohs(handshake);
259 if ((handshake == expected_value) ||
260 (handshake == HANDSHAKE_RESET_VALUE_USB))
264 return HANDSHAKE_TIMEOUT_VALUE;
267 static void put_handshake_usb(struct ft1000_usb *ft1000dev, u16 handshake_value)
271 for (i = 0; i < 1000; i++)
275 static u16 get_request_type(struct ft1000_usb *ft1000dev)
282 if (ft1000dev->bootmode == 1) {
283 status = fix_ft1000_read_dpram32(ft1000dev,
284 DWNLD_MAG1_TYPE_LOC, (u8 *)&tempx);
285 tempx = ntohl(tempx);
288 status = ft1000_read_dpram16(ft1000dev,
289 DWNLD_MAG1_TYPE_LOC, (u8 *)&tempword, 1);
290 tempx |= (tempword << 16);
291 tempx = ntohl(tempx);
293 request_type = (u16)tempx;
298 static u16 get_request_type_usb(struct ft1000_usb *ft1000dev)
305 if (ft1000dev->bootmode == 1) {
306 status = fix_ft1000_read_dpram32(ft1000dev,
307 DWNLD_MAG1_TYPE_LOC, (u8 *)&tempx);
308 tempx = ntohl(tempx);
310 if (ft1000dev->usbboot == 2) {
311 tempx = ft1000dev->tempbuf[2];
312 tempword = ft1000dev->tempbuf[3];
315 status = ft1000_read_dpram16(ft1000dev,
319 tempx |= (tempword << 16);
320 tempx = ntohl(tempx);
322 request_type = (u16)tempx;
327 static long get_request_value(struct ft1000_usb *ft1000dev)
333 if (ft1000dev->bootmode == 1) {
334 status = fix_ft1000_read_dpram32(ft1000dev,
335 DWNLD_MAG1_SIZE_LOC, (u8 *)&value);
336 value = ntohl(value);
338 status = ft1000_read_dpram16(ft1000dev,
339 DWNLD_MAG1_SIZE_LOC, (u8 *)&tempword, 0);
341 status = ft1000_read_dpram16(ft1000dev,
342 DWNLD_MAG1_SIZE_LOC, (u8 *)&tempword, 1);
343 value |= (tempword << 16);
344 value = ntohl(value);
351 /* writes a value to DWNLD_MAG1_SIZE_LOC */
352 static void put_request_value(struct ft1000_usb *ft1000dev, long lvalue)
357 tempx = ntohl(lvalue);
358 status = fix_ft1000_write_dpram32(ft1000dev, DWNLD_MAG1_SIZE_LOC,
364 /* returns the checksum of the pseudo header */
365 static u16 hdr_checksum(struct pseudo_hdr *pHdr)
367 u16 *usPtr = (u16 *)pHdr;
371 chksum = (((((usPtr[0] ^ usPtr[1]) ^ usPtr[2]) ^ usPtr[3]) ^
372 usPtr[4]) ^ usPtr[5]) ^ usPtr[6];
377 static int check_buffers(u16 *buff_w, u16 *buff_r, int len, int offset)
381 for (i = 0; i < len; i++) {
382 if (buff_w[i] != buff_r[i + offset])
389 static int write_dpram32_and_check(struct ft1000_usb *ft1000dev,
390 u16 tempbuffer[], u16 dpram)
393 u16 resultbuffer[64];
396 for (i = 0; i < 10; i++) {
397 status = ft1000_write_dpram32(ft1000dev, dpram,
398 (u8 *)&tempbuffer[0], 64);
400 /* Work around for ASIC bit stuffing problem. */
401 if ((tempbuffer[31] & 0xfe00) == 0xfe00) {
402 status = ft1000_write_dpram32(ft1000dev,
403 dpram+12, (u8 *)&tempbuffer[24],
406 /* Let's check the data written */
407 status = ft1000_read_dpram32(ft1000dev, dpram,
408 (u8 *)&resultbuffer[0], 64);
409 if ((tempbuffer[31] & 0xfe00) == 0xfe00) {
410 if (check_buffers(tempbuffer, resultbuffer, 28,
412 pr_debug("DPRAM write failed 1 during bootloading\n");
413 usleep_range(9000, 11000);
416 status = ft1000_read_dpram32(ft1000dev,
418 (u8 *)&resultbuffer[0], 64);
420 if (check_buffers(tempbuffer, resultbuffer, 16,
422 pr_debug("DPRAM write failed 2 during bootloading\n");
423 usleep_range(9000, 11000);
427 if (check_buffers(tempbuffer, resultbuffer, 32,
429 pr_debug("DPRAM write failed 3 during bootloading\n");
430 usleep_range(9000, 11000);
441 /* writes a block of DSP image to DPRAM
442 * Parameters: struct ft1000_usb - device structure
443 * u16 **pUsFile - DSP image file pointer in u16
444 * u8 **pUcFile - DSP image file pointer in u8
445 * long word_length - length of the buffer to be written to DPRAM
447 static int write_blk(struct ft1000_usb *ft1000dev, u16 **pUsFile, u8 **pUcFile,
456 /*pr_debug("start word_length = %d\n",(int)word_length); */
457 dpram = (u16)DWNLD_MAG1_PS_HDR_LOC;
458 tempword = *(*pUsFile);
460 status = ft1000_write_dpram16(ft1000dev, dpram, tempword, 0);
461 tempword = *(*pUsFile);
463 status = ft1000_write_dpram16(ft1000dev, dpram++, tempword, 1);
465 *pUcFile = *pUcFile + 4;
467 tempword = (u16)word_length;
468 word_length = (word_length / 16) + 1;
469 for (; word_length > 0; word_length--) { /* In words */
471 for (i = 0; i < 32; i++) {
473 tempbuffer[i++] = *(*pUsFile);
475 tempbuffer[i] = *(*pUsFile);
477 *pUcFile = *pUcFile + 4;
486 /*pr_debug("loopcnt is %d\n", loopcnt); */
487 /*pr_debug("write_blk: bootmode = %d\n", bootmode); */
488 /*pr_debug("write_blk: dpram = %x\n", dpram); */
489 if (ft1000dev->bootmode == 0) {
491 status = ft1000_write_dpram32(ft1000dev, dpram,
492 (u8 *)&tempbuffer[0], 8);
494 status = ft1000_write_dpram32(ft1000dev, dpram,
495 (u8 *)&tempbuffer[0], 64);
497 status = write_dpram32_and_check(ft1000dev, tempbuffer,
500 pr_debug("Write failed tempbuffer[31] = 0x%x\n",
505 dpram = dpram + loopcnt;
510 static void usb_dnld_complete(struct urb *urb)
512 /* pr_debug("****** usb_dnld_complete\n"); */
515 /* writes a block of DSP image to DPRAM
516 * Parameters: struct ft1000_usb - device structure
517 * u16 **pUsFile - DSP image file pointer in u16
518 * u8 **pUcFile - DSP image file pointer in u8
519 * long word_length - length of the buffer to be written to DPRAM
521 static int write_blk_fifo(struct ft1000_usb *ft1000dev, u16 **pUsFile,
522 u8 **pUcFile, long word_length)
526 byte_length = word_length * 4;
528 if (byte_length && ((byte_length % 64) == 0))
531 if (byte_length < 64)
534 usb_init_urb(ft1000dev->tx_urb);
535 memcpy(ft1000dev->tx_buf, *pUcFile, byte_length);
536 usb_fill_bulk_urb(ft1000dev->tx_urb,
538 usb_sndbulkpipe(ft1000dev->dev,
539 ft1000dev->bulk_out_endpointAddr),
540 ft1000dev->tx_buf, byte_length, usb_dnld_complete,
543 usb_submit_urb(ft1000dev->tx_urb, GFP_ATOMIC);
545 *pUsFile = *pUsFile + (word_length << 1);
546 *pUcFile = *pUcFile + (word_length << 2);
551 static int scram_start_dwnld(struct ft1000_usb *ft1000dev, u16 *hshake,
556 if (ft1000dev->usbboot)
557 *hshake = get_handshake_usb(ft1000dev, HANDSHAKE_DSP_BL_READY);
559 *hshake = get_handshake(ft1000dev, HANDSHAKE_DSP_BL_READY);
560 if (*hshake == HANDSHAKE_DSP_BL_READY) {
561 pr_debug("handshake is HANDSHAKE_DSP_BL_READY, call put_handshake(HANDSHAKE_DRIVER_READY)\n");
562 put_handshake(ft1000dev, HANDSHAKE_DRIVER_READY);
563 } else if (*hshake == HANDSHAKE_TIMEOUT_VALUE) {
566 pr_debug("Download error: Handshake failed\n");
569 *state = STATE_BOOT_DWNLD;
573 static int request_code_segment(struct ft1000_usb *ft1000dev, u16 **s_file,
574 u8 **c_file, const u8 *endpoint, bool boot_case)
579 word_length = get_request_value(ft1000dev);
580 /*pr_debug("word_length = 0x%x\n", (int)word_length); */
581 /*NdisMSleep (100); */
582 if (word_length > MAX_LENGTH) {
583 pr_debug("Download error: Max length exceeded\n");
586 if ((word_length * 2 + (long)c_file) > (long)endpoint) {
587 /* Error, beyond boot code range.*/
588 pr_debug("Download error: Requested len=%d exceeds BOOT code boundary\n",
592 if (word_length & 0x1)
594 word_length = word_length / 2;
597 status = write_blk(ft1000dev, s_file, c_file, word_length);
598 /*pr_debug("write_blk returned %d\n", status); */
600 status = write_blk_fifo(ft1000dev, s_file, c_file, word_length);
601 if (ft1000dev->usbboot == 0)
602 ft1000dev->usbboot++;
603 if (ft1000dev->usbboot == 1)
604 status |= ft1000_write_dpram16(ft1000dev,
605 DWNLD_MAG1_PS_HDR_LOC, 0, 0);
610 /* Scramble downloader for Harley based ASIC via USB interface */
611 int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart,
617 struct pseudo_hdr *pseudo_header;
618 u16 pseudo_header_len;
623 struct dsp_file_hdr *file_hdr;
624 struct dsp_image_info *dsp_img_info = NULL;
625 long requested_version;
626 bool correct_version;
627 struct drv_msg *mailbox_data;
631 u8 *boot_end = NULL, *code_end = NULL;
633 long loader_code_address, loader_code_size = 0;
634 long run_address = 0, run_size = 0;
637 u32 image_chksum = 0;
641 struct prov_record *pprov_record;
642 struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net);
644 ft1000dev->fcodeldr = 0;
645 ft1000dev->usbboot = 0;
646 ft1000dev->dspalive = 0xffff;
649 * Get version id of file, at first 4 bytes of file, for newer files.
652 state = STATE_START_DWNLD;
654 file_hdr = pFileStart;
656 ft1000_write_register(ft1000dev, 0x800, FT1000_REG_MAG_WATERMARK);
658 s_file = (u16 *) (pFileStart + file_hdr->loader_offset);
659 c_file = (u8 *) (pFileStart + file_hdr->loader_offset);
661 boot_end = (u8 *) (pFileStart + file_hdr->loader_code_end);
663 loader_code_address = file_hdr->loader_code_address;
664 loader_code_size = file_hdr->loader_code_size;
665 correct_version = false;
667 while ((status == 0) && (state != STATE_DONE_FILE)) {
669 case STATE_START_DWNLD:
670 status = scram_start_dwnld(ft1000dev, &handshake,
674 case STATE_BOOT_DWNLD:
675 pr_debug("STATE_BOOT_DWNLD\n");
676 ft1000dev->bootmode = 1;
677 handshake = get_handshake(ft1000dev, HANDSHAKE_REQUEST);
678 if (handshake == HANDSHAKE_REQUEST) {
680 * Get type associated with the request.
682 request = get_request_type(ft1000dev);
684 case REQUEST_RUN_ADDRESS:
685 pr_debug("REQUEST_RUN_ADDRESS\n");
686 put_request_value(ft1000dev,
687 loader_code_address);
689 case REQUEST_CODE_LENGTH:
690 pr_debug("REQUEST_CODE_LENGTH\n");
691 put_request_value(ft1000dev,
694 case REQUEST_DONE_BL:
695 pr_debug("REQUEST_DONE_BL\n");
696 /* Reposition ptrs to beginning of code section */
697 s_file = (u16 *) (boot_end);
698 c_file = (u8 *) (boot_end);
699 /* pr_debug("download:s_file = 0x%8x\n", (int)s_file); */
700 /* pr_debug("FT1000:download:c_file = 0x%8x\n", (int)c_file); */
701 state = STATE_CODE_DWNLD;
702 ft1000dev->fcodeldr = 1;
704 case REQUEST_CODE_SEGMENT:
705 status = request_code_segment(ft1000dev,
711 pr_debug("Download error: Bad request type=%d in BOOT download state\n",
716 if (ft1000dev->usbboot)
717 put_handshake_usb(ft1000dev,
720 put_handshake(ft1000dev,
723 pr_debug("Download error: Handshake failed\n");
729 case STATE_CODE_DWNLD:
730 /* pr_debug("STATE_CODE_DWNLD\n"); */
731 ft1000dev->bootmode = 0;
732 if (ft1000dev->usbboot)
734 get_handshake_usb(ft1000dev,
738 get_handshake(ft1000dev, HANDSHAKE_REQUEST);
739 if (handshake == HANDSHAKE_REQUEST) {
741 * Get type associated with the request.
743 if (ft1000dev->usbboot)
745 get_request_type_usb(ft1000dev);
747 request = get_request_type(ft1000dev);
749 case REQUEST_FILE_CHECKSUM:
750 pr_debug("image_chksum = 0x%8x\n",
752 put_request_value(ft1000dev,
755 case REQUEST_RUN_ADDRESS:
756 pr_debug("REQUEST_RUN_ADDRESS\n");
757 if (correct_version) {
758 pr_debug("run_address = 0x%8x\n",
760 put_request_value(ft1000dev,
763 pr_debug("Download error: Got Run address request before image offset request\n");
768 case REQUEST_CODE_LENGTH:
769 pr_debug("REQUEST_CODE_LENGTH\n");
770 if (correct_version) {
771 pr_debug("run_size = 0x%8x\n",
773 put_request_value(ft1000dev,
776 pr_debug("Download error: Got Size request before image offset request\n");
781 case REQUEST_DONE_CL:
782 ft1000dev->usbboot = 3;
783 /* Reposition ptrs to beginning of provisioning section */
785 (u16 *) (pFileStart +
786 file_hdr->commands_offset);
789 file_hdr->commands_offset);
790 state = STATE_DONE_DWNLD;
792 case REQUEST_CODE_SEGMENT:
793 /* pr_debug("REQUEST_CODE_SEGMENT - CODELOADER\n"); */
794 if (!correct_version) {
795 pr_debug("Download error: Got Code Segment request before image offset request\n");
800 status = request_code_segment(ft1000dev,
807 case REQUEST_MAILBOX_DATA:
808 pr_debug("REQUEST_MAILBOX_DATA\n");
809 /* Convert length from byte count to word count. Make sure we round up. */
811 (long)(pft1000info->DSPInfoBlklen +
813 put_request_value(ft1000dev,
816 (struct drv_msg *)&(pft1000info->
819 * Position ASIC DPRAM auto-increment pointer.
822 data = (u16 *)&mailbox_data->data[0];
823 dpram = (u16)DWNLD_MAG1_PS_HDR_LOC;
824 if (word_length & 0x1)
827 word_length = word_length / 2;
829 for (; word_length > 0; word_length--) { /* In words */
832 templong |= (*data++ << 16);
834 fix_ft1000_write_dpram32
841 case REQUEST_VERSION_INFO:
842 pr_debug("REQUEST_VERSION_INFO\n");
844 file_hdr->version_data_size;
845 put_request_value(ft1000dev,
848 * Position ASIC DPRAM auto-increment pointer.
852 (u16 *) (pFileStart +
854 version_data_offset);
856 dpram = (u16)DWNLD_MAG1_PS_HDR_LOC;
857 if (word_length & 0x1)
860 word_length = word_length / 2;
862 for (; word_length > 0; word_length--) { /* In words */
864 templong = ntohs(*s_file++);
865 temp = ntohs(*s_file++);
866 templong |= (temp << 16);
868 fix_ft1000_write_dpram32
875 case REQUEST_CODE_BY_VERSION:
876 pr_debug("REQUEST_CODE_BY_VERSION\n");
877 correct_version = false;
879 get_request_value(ft1000dev);
882 (struct dsp_image_info *)(pFileStart
889 image < file_hdr->nDspImages;
892 if (dsp_img_info->version ==
894 correct_version = true;
895 pr_debug("correct_version is TRUE\n");
924 if (!correct_version) {
926 * Error, beyond boot code range.
928 pr_debug("Download error: Bad Version Request = 0x%x.\n",
929 (int)requested_version);
936 pr_debug("Download error: Bad request type=%d in CODE download state.\n",
941 if (ft1000dev->usbboot)
942 put_handshake_usb(ft1000dev,
945 put_handshake(ft1000dev,
948 pr_debug("Download error: Handshake failed\n");
954 case STATE_DONE_DWNLD:
955 pr_debug("Code loader is done...\n");
956 state = STATE_SECTION_PROV;
959 case STATE_SECTION_PROV:
960 pr_debug("STATE_SECTION_PROV\n");
961 pseudo_header = (struct pseudo_hdr *)c_file;
963 if (pseudo_header->checksum ==
964 hdr_checksum(pseudo_header)) {
965 if (pseudo_header->portdest !=
966 0x80 /* Dsp OAM */) {
967 state = STATE_DONE_PROV;
970 pseudo_header_len = ntohs(pseudo_header->length); /* Byte length for PROV records */
972 /* Get buffer for provisioning data */
974 kmalloc(pseudo_header_len +
975 sizeof(struct pseudo_hdr),
978 memcpy(pbuffer, c_file,
979 (u32) (pseudo_header_len +
982 /* link provisioning data */
984 kmalloc(sizeof(struct prov_record),
987 pprov_record->pprov_data =
989 list_add_tail(&pprov_record->
993 /* Move to next entry if available */
995 (u8 *) ((unsigned long)
997 (u32) ((pseudo_header_len + 1) & 0xFFFFFFFE) + sizeof(struct pseudo_hdr));
998 if ((unsigned long)(c_file) -
999 (unsigned long)(pFileStart)
1001 (unsigned long)FileLength) {
1002 state = STATE_DONE_FILE;
1012 /* Checksum did not compute */
1015 pr_debug("after STATE_SECTION_PROV, state = %d, status= %d\n",
1019 case STATE_DONE_PROV:
1020 pr_debug("STATE_DONE_PROV\n");
1021 state = STATE_DONE_FILE;
1033 // Check if Card is present
1034 status = Harley_Read_Register(&temp, FT1000_REG_SUP_IMASK);
1035 if ( (status != NDIS_STATUS_SUCCESS) || (temp == 0x0000) ) {
1039 status = Harley_Read_Register(&temp, FT1000_REG_ASIC_ID);
1040 if ( (status != NDIS_STATUS_SUCCESS) || (temp == 0xffff) ) {
1047 pr_debug("Download exiting with status = 0x%8x\n", status);
1048 ft1000_write_register(ft1000dev, FT1000_DB_DNLD_TX,
1049 FT1000_REG_DOORBELL);