diff options
author | Scott Wood <scottwood@freescale.com> | 2014-04-07 23:49:35 (GMT) |
---|---|---|
committer | Scott Wood <scottwood@freescale.com> | 2014-04-07 23:49:35 (GMT) |
commit | 62b8c978ee6b8d135d9e7953221de58000dba986 (patch) | |
tree | 683b04b2e627f6710c22c151b23c8cc9a165315e /drivers/staging/ft1000/ft1000-usb | |
parent | 78fd82238d0e5716578c326404184a27ba67fd6e (diff) | |
download | linux-fsl-qoriq-62b8c978ee6b8d135d9e7953221de58000dba986.tar.xz |
Rewind v3.13-rc3+ (78fd82238d0e5716) to v3.12
Diffstat (limited to 'drivers/staging/ft1000/ft1000-usb')
-rw-r--r-- | drivers/staging/ft1000/ft1000-usb/ft1000_download.c | 575 | ||||
-rw-r--r-- | drivers/staging/ft1000/ft1000-usb/ft1000_hw.c | 457 | ||||
-rw-r--r-- | drivers/staging/ft1000/ft1000-usb/ft1000_usb.c | 6 | ||||
-rw-r--r-- | drivers/staging/ft1000/ft1000-usb/ft1000_usb.h | 2 |
4 files changed, 601 insertions, 439 deletions
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_download.c b/drivers/staging/ft1000/ft1000-usb/ft1000_download.c index 12f333f..5190c8a 100644 --- a/drivers/staging/ft1000/ft1000-usb/ft1000_download.c +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_download.c @@ -1,8 +1,12 @@ -/* -* CopyRight (C) 2007 Qualcomm Inc. All Rights Reserved. -* -* This file is part of Express Card USB Driver -*/ +//===================================================== +// CopyRight (C) 2007 Qualcomm Inc. All Rights Reserved. +// +// +// This file is part of Express Card USB Driver +// +// $Id: +//==================================================== +// 20090926; aelias; removed compiler warnings; ubuntu 9.04; 2.6.28-15-generic #include <linux/init.h> #include <linux/kernel.h> @@ -107,12 +111,23 @@ struct dsp_image_info { }; -/* checks if the doorbell register is cleared */ -static int check_usb_db(struct ft1000_usb *ft1000dev) +//--------------------------------------------------------------------------- +// Function: check_usb_db +// +// Parameters: struct ft1000_usb - device structure +// +// Returns: 0 - success +// +// Description: This function checks if the doorbell register is cleared +// +// Notes: +// +//--------------------------------------------------------------------------- +static u32 check_usb_db (struct ft1000_usb *ft1000dev) { int loopcnt; u16 temp; - int status; + u32 status; loopcnt = 0; @@ -154,12 +169,25 @@ static int check_usb_db(struct ft1000_usb *ft1000dev) return HANDSHAKE_MAG_TIMEOUT_VALUE; } -/* gets the handshake and compares it with the expected value */ +//--------------------------------------------------------------------------- +// Function: get_handshake +// +// Parameters: struct ft1000_usb - device structure +// u16 expected_value - the handshake value expected +// +// Returns: handshakevalue - success +// HANDSHAKE_TIMEOUT_VALUE - failure +// +// Description: This function gets the handshake and compare with the expected value +// +// Notes: +// +//--------------------------------------------------------------------------- static u16 get_handshake(struct ft1000_usb *ft1000dev, u16 expected_value) { u16 handshake; int loopcnt; - int status = 0; + u32 status = 0; loopcnt = 0; @@ -201,12 +229,25 @@ static u16 get_handshake(struct ft1000_usb *ft1000dev, u16 expected_value) return HANDSHAKE_TIMEOUT_VALUE; } -/* write the handshake value to the handshake location */ +//--------------------------------------------------------------------------- +// Function: put_handshake +// +// Parameters: struct ft1000_usb - device structure +// u16 handshake_value - handshake to be written +// +// Returns: none +// +// Description: This function write the handshake value to the handshake location +// in DPRAM +// +// Notes: +// +//--------------------------------------------------------------------------- static void put_handshake(struct ft1000_usb *ft1000dev,u16 handshake_value) { u32 tempx; u16 tempword; - int status; + u32 status; tempx = (u32)handshake_value; tempx = ntohl(tempx); @@ -226,7 +267,7 @@ static u16 get_handshake_usb(struct ft1000_usb *ft1000dev, u16 expected_value) u16 handshake; int loopcnt; u16 temp; - int status = 0; + u32 status = 0; loopcnt = 0; handshake = 0; @@ -275,10 +316,22 @@ static void put_handshake_usb(struct ft1000_usb *ft1000dev,u16 handshake_value) for (i=0; i<1000; i++); } +//--------------------------------------------------------------------------- +// Function: get_request_type +// +// Parameters: struct ft1000_usb - device structure +// +// Returns: request type - success +// +// Description: This function returns the request type +// +// Notes: +// +//--------------------------------------------------------------------------- static u16 get_request_type(struct ft1000_usb *ft1000dev) { u16 request_type; - int status; + u32 status; u16 tempword; u32 tempx; @@ -301,7 +354,7 @@ static u16 get_request_type(struct ft1000_usb *ft1000dev) static u16 get_request_type_usb(struct ft1000_usb *ft1000dev) { u16 request_type; - int status; + u32 status; u16 tempword; u32 tempx; @@ -327,11 +380,23 @@ static u16 get_request_type_usb(struct ft1000_usb *ft1000dev) return request_type; } +//--------------------------------------------------------------------------- +// Function: get_request_value +// +// Parameters: struct ft1000_usb - device structure +// +// Returns: request value - success +// +// Description: This function returns the request value +// +// Notes: +// +//--------------------------------------------------------------------------- static long get_request_value(struct ft1000_usb *ft1000dev) { u32 value; u16 tempword; - int status; + u32 status; if (ft1000dev->bootmode == 1) { status = fix_ft1000_read_dpram32(ft1000dev, @@ -351,11 +416,23 @@ static long get_request_value(struct ft1000_usb *ft1000dev) } -/* writes a value to DWNLD_MAG1_SIZE_LOC */ +//--------------------------------------------------------------------------- +// Function: put_request_value +// +// Parameters: struct ft1000_usb - device structure +// long lvalue - value to be put into DPRAM location DWNLD_MAG1_SIZE_LOC +// +// Returns: none +// +// Description: This function writes a value to DWNLD_MAG1_SIZE_LOC +// +// Notes: +// +//--------------------------------------------------------------------------- static void put_request_value(struct ft1000_usb *ft1000dev, long lvalue) { u32 tempx; - int status; + u32 status; tempx = ntohl(lvalue); status = fix_ft1000_write_dpram32(ft1000dev, DWNLD_MAG1_SIZE_LOC, @@ -364,7 +441,18 @@ static void put_request_value(struct ft1000_usb *ft1000dev, long lvalue) -/* returns the checksum of the pseudo header */ +//--------------------------------------------------------------------------- +// Function: hdr_checksum +// +// Parameters: struct pseudo_hdr *pHdr - Pseudo header pointer +// +// Returns: checksum - success +// +// Description: This function returns the checksum of the pseudo header +// +// Notes: +// +//--------------------------------------------------------------------------- static u16 hdr_checksum(struct pseudo_hdr *pHdr) { u16 *usPtr = (u16 *)pHdr; @@ -383,130 +471,144 @@ static int check_buffers(u16 *buff_w, u16 *buff_r, int len, int offset) for (i = 0; i < len; i++) { if (buff_w[i] != buff_r[i + offset]) - return -EREMOTEIO; + return -1; } return 0; } -static int write_dpram32_and_check(struct ft1000_usb *ft1000dev, - u16 tempbuffer[], u16 dpram) +//--------------------------------------------------------------------------- +// Function: write_blk +// +// Parameters: struct ft1000_usb - device structure +// u16 **pUsFile - DSP image file pointer in u16 +// u8 **pUcFile - DSP image file pointer in u8 +// long word_length - length of the buffer to be written +// to DPRAM +// +// Returns: STATUS_SUCCESS - success +// STATUS_FAILURE - failure +// +// Description: This function writes a block of DSP image to DPRAM +// +// Notes: +// +//--------------------------------------------------------------------------- +static u32 write_blk (struct ft1000_usb *ft1000dev, u16 **pUsFile, u8 **pUcFile, long word_length) { - int status; - u16 resultbuffer[64]; - int i; - - for (i = 0; i < 10; i++) { - status = ft1000_write_dpram32(ft1000dev, dpram, - (u8 *)&tempbuffer[0], 64); - if (status == 0) { - /* Work around for ASIC bit stuffing problem. */ - if ((tempbuffer[31] & 0xfe00) == 0xfe00) { - status = ft1000_write_dpram32(ft1000dev, - dpram+12, (u8 *)&tempbuffer[24], - 64); - } - /* Let's check the data written */ - status = ft1000_read_dpram32(ft1000dev, dpram, - (u8 *)&resultbuffer[0], 64); - if ((tempbuffer[31] & 0xfe00) == 0xfe00) { - if (check_buffers(tempbuffer, resultbuffer, 28, - 0)) { + u32 Status = STATUS_SUCCESS; + u16 dpram; + int loopcnt, i, j; + u16 tempword; + u16 tempbuffer[64]; + u16 resultbuffer[64]; + + //DEBUG("FT1000:download:start word_length = %d\n",(int)word_length); + dpram = (u16)DWNLD_MAG1_PS_HDR_LOC; + tempword = *(*pUsFile); + (*pUsFile)++; + Status = ft1000_write_dpram16(ft1000dev, dpram, tempword, 0); + tempword = *(*pUsFile); + (*pUsFile)++; + Status = ft1000_write_dpram16(ft1000dev, dpram++, tempword, 1); + + *pUcFile = *pUcFile + 4; + word_length--; + tempword = (u16)word_length; + word_length = (word_length / 16) + 1; + for (; word_length > 0; word_length--) /* In words */ + { + loopcnt = 0; + + for (i=0; i<32; i++) + { + if (tempword != 0) + { + tempbuffer[i++] = *(*pUsFile); + (*pUsFile)++; + tempbuffer[i] = *(*pUsFile); + (*pUsFile)++; + *pUcFile = *pUcFile + 4; + loopcnt++; + tempword--; + } + else + { + tempbuffer[i++] = 0; + tempbuffer[i] = 0; + } + } + + //DEBUG("write_blk: loopcnt is %d\n", loopcnt); + //DEBUG("write_blk: bootmode = %d\n", bootmode); + //DEBUG("write_blk: dpram = %x\n", dpram); + if (ft1000dev->bootmode == 0) + { + if (dpram >= 0x3F4) + Status = ft1000_write_dpram32 (ft1000dev, dpram, (u8 *)&tempbuffer[0], 8); + else + Status = ft1000_write_dpram32 (ft1000dev, dpram, (u8 *)&tempbuffer[0], 64); + } + else + { + for (j=0; j<10; j++) + { + Status = ft1000_write_dpram32 (ft1000dev, dpram, (u8 *)&tempbuffer[0], 64); + if (Status == STATUS_SUCCESS) + { + // Work around for ASIC bit stuffing problem. + if ( (tempbuffer[31] & 0xfe00) == 0xfe00) + { + Status = ft1000_write_dpram32(ft1000dev, dpram+12, (u8 *)&tempbuffer[24], 64); + } + // Let's check the data written + Status = ft1000_read_dpram32 (ft1000dev, dpram, (u8 *)&resultbuffer[0], 64); + if ( (tempbuffer[31] & 0xfe00) == 0xfe00) + { + if (check_buffers(tempbuffer, resultbuffer, 28, 0)) { DEBUG("FT1000:download:DPRAM write failed 1 during bootloading\n"); - usleep_range(9000, 11000); + msleep(10); + Status = STATUS_FAILURE; break; } - status = ft1000_read_dpram32(ft1000dev, - dpram+12, - (u8 *)&resultbuffer[0], 64); + Status = ft1000_read_dpram32 (ft1000dev, dpram+12, (u8 *)&resultbuffer[0], 64); - if (check_buffers(tempbuffer, resultbuffer, 16, - 24)) { + if (check_buffers(tempbuffer, resultbuffer, 16, 24)) { DEBUG("FT1000:download:DPRAM write failed 2 during bootloading\n"); - usleep_range(9000, 11000); + msleep(10); + Status = STATUS_FAILURE; break; } - } else { - if (check_buffers(tempbuffer, resultbuffer, 32, - 0)) { + + } + else + { + if (check_buffers(tempbuffer, resultbuffer, 32, 0)) { DEBUG("FT1000:download:DPRAM write failed 3 during bootloading\n"); - usleep_range(9000, 11000); + msleep(10); + Status = STATUS_FAILURE; break; } + } - if (status == 0) - break; - } - } - return status; -} -/* writes a block of DSP image to DPRAM - * Parameters: struct ft1000_usb - device structure - * u16 **pUsFile - DSP image file pointer in u16 - * u8 **pUcFile - DSP image file pointer in u8 - * long word_length - length of the buffer to be written to DPRAM - */ -static int write_blk(struct ft1000_usb *ft1000dev, u16 **pUsFile, u8 **pUcFile, - long word_length) -{ - int status = STATUS_SUCCESS; - u16 dpram; - int loopcnt, i; - u16 tempword; - u16 tempbuffer[64]; - - /*DEBUG("FT1000:download:start word_length = %d\n",(int)word_length); */ - dpram = (u16)DWNLD_MAG1_PS_HDR_LOC; - tempword = *(*pUsFile); - (*pUsFile)++; - status = ft1000_write_dpram16(ft1000dev, dpram, tempword, 0); - tempword = *(*pUsFile); - (*pUsFile)++; - status = ft1000_write_dpram16(ft1000dev, dpram++, tempword, 1); - - *pUcFile = *pUcFile + 4; - word_length--; - tempword = (u16)word_length; - word_length = (word_length / 16) + 1; - for (; word_length > 0; word_length--) { /* In words */ - loopcnt = 0; - for (i = 0; i < 32; i++) { - if (tempword != 0) { - tempbuffer[i++] = *(*pUsFile); - (*pUsFile)++; - tempbuffer[i] = *(*pUsFile); - (*pUsFile)++; - *pUcFile = *pUcFile + 4; - loopcnt++; - tempword--; - } else { - tempbuffer[i++] = 0; - tempbuffer[i] = 0; - } + if (Status == STATUS_SUCCESS) + break; + + } } - /*DEBUG("write_blk: loopcnt is %d\n", loopcnt); */ - /*DEBUG("write_blk: bootmode = %d\n", bootmode); */ - /*DEBUG("write_blk: dpram = %x\n", dpram); */ - if (ft1000dev->bootmode == 0) { - if (dpram >= 0x3F4) - status = ft1000_write_dpram32(ft1000dev, dpram, - (u8 *)&tempbuffer[0], 8); - else - status = ft1000_write_dpram32(ft1000dev, dpram, - (u8 *)&tempbuffer[0], 64); - } else { - status = write_dpram32_and_check(ft1000dev, tempbuffer, - dpram); - if (status != STATUS_SUCCESS) { - DEBUG("FT1000:download:Write failed tempbuffer[31] = 0x%x\n", tempbuffer[31]); - break; - } + if (Status != STATUS_SUCCESS) + { + DEBUG("FT1000:download:Write failed tempbuffer[31] = 0x%x\n", tempbuffer[31]); + break; } - dpram = dpram + loopcnt; - } - return status; + + } + dpram = dpram + loopcnt; + } + + return Status; } static void usb_dnld_complete (struct urb *urb) @@ -514,16 +616,27 @@ static void usb_dnld_complete (struct urb *urb) //DEBUG("****** usb_dnld_complete\n"); } -/* writes a block of DSP image to DPRAM - * Parameters: struct ft1000_usb - device structure - * u16 **pUsFile - DSP image file pointer in u16 - * u8 **pUcFile - DSP image file pointer in u8 - * long word_length - length of the buffer to be written to DPRAM - */ -static int write_blk_fifo(struct ft1000_usb *ft1000dev, u16 **pUsFile, +//--------------------------------------------------------------------------- +// Function: write_blk_fifo +// +// Parameters: struct ft1000_usb - device structure +// u16 **pUsFile - DSP image file pointer in u16 +// u8 **pUcFile - DSP image file pointer in u8 +// long word_length - length of the buffer to be written +// to DPRAM +// +// Returns: STATUS_SUCCESS - success +// STATUS_FAILURE - failure +// +// Description: This function writes a block of DSP image to DPRAM +// +// Notes: +// +//--------------------------------------------------------------------------- +static u32 write_blk_fifo(struct ft1000_usb *ft1000dev, u16 **pUsFile, u8 **pUcFile, long word_length) { - int Status = STATUS_SUCCESS; + u32 Status = STATUS_SUCCESS; int byte_length; byte_length = word_length * 4; @@ -551,71 +664,22 @@ static int write_blk_fifo(struct ft1000_usb *ft1000dev, u16 **pUsFile, return Status; } -static int scram_start_dwnld(struct ft1000_usb *ft1000dev, u16 *hshake, - u32 *state) -{ - int status = 0; - - DEBUG("FT1000:STATE_START_DWNLD\n"); - if (ft1000dev->usbboot) - *hshake = get_handshake_usb(ft1000dev, HANDSHAKE_DSP_BL_READY); - else - *hshake = get_handshake(ft1000dev, HANDSHAKE_DSP_BL_READY); - if (*hshake == HANDSHAKE_DSP_BL_READY) { - DEBUG("scram_dnldr: handshake is HANDSHAKE_DSP_BL_READY, call put_handshake(HANDSHAKE_DRIVER_READY)\n"); - put_handshake(ft1000dev, HANDSHAKE_DRIVER_READY); - } else if (*hshake == HANDSHAKE_TIMEOUT_VALUE) { - status = -ETIMEDOUT; - } else { - DEBUG("FT1000:download:Download error: Handshake failed\n"); - status = -ENETRESET; - } - *state = STATE_BOOT_DWNLD; - return status; -} - -static int request_code_segment(struct ft1000_usb *ft1000dev, u16 **s_file, - u8 **c_file, const u8 *endpoint, bool boot_case) -{ - long word_length; - int status = 0; - - /*DEBUG("FT1000:REQUEST_CODE_SEGMENT\n");i*/ - word_length = get_request_value(ft1000dev); - /*DEBUG("FT1000:word_length = 0x%x\n", (int)word_length); */ - /*NdisMSleep (100); */ - if (word_length > MAX_LENGTH) { - DEBUG("FT1000:download:Download error: Max length exceeded\n"); - return STATUS_FAILURE; - } - if ((word_length * 2 + (long)c_file) > (long)endpoint) { - /* Error, beyond boot code range.*/ - DEBUG("FT1000:download:Download error: Requested len=%d exceeds BOOT code boundary.\n", (int)word_length); - return STATUS_FAILURE; - } - if (word_length & 0x1) - word_length++; - word_length = word_length / 2; - - if (boot_case) { - status = write_blk(ft1000dev, s_file, c_file, word_length); - /*DEBUG("write_blk returned %d\n", status); */ - } else { - write_blk_fifo(ft1000dev, s_file, c_file, word_length); - if (ft1000dev->usbboot == 0) - ft1000dev->usbboot++; - if (ft1000dev->usbboot == 1) - ft1000_write_dpram16(ft1000dev, - DWNLD_MAG1_PS_HDR_LOC, 0, 0); - } - return status; -} - -/* Scramble downloader for Harley based ASIC via USB interface */ -int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart, +//--------------------------------------------------------------------------- +// +// Function: scram_dnldr +// +// Synopsis: Scramble downloader for Harley based ASIC via USB interface +// +// Arguments: pFileStart - pointer to start of file +// FileLength - file length +// +// Returns: status - return code +//--------------------------------------------------------------------------- + +u16 scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart, u32 FileLength) { - int status = STATUS_SUCCESS; + u16 status = STATUS_SUCCESS; u32 state; u16 handshake; struct pseudo_hdr *pseudo_header; @@ -623,6 +687,7 @@ int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart, long word_length; u16 request; u16 temp; + u16 tempword; struct dsp_file_hdr *file_hdr; struct dsp_image_info *dsp_img_info = NULL; @@ -668,13 +733,34 @@ int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart, loader_code_address = file_hdr->loader_code_address; loader_code_size = file_hdr->loader_code_size; - correct_version = false; + correct_version = FALSE; while ((status == STATUS_SUCCESS) && (state != STATE_DONE_FILE)) { switch (state) { case STATE_START_DWNLD: - status = scram_start_dwnld(ft1000dev, &handshake, - &state); + DEBUG("FT1000:STATE_START_DWNLD\n"); + if (ft1000dev->usbboot) + handshake = + get_handshake_usb(ft1000dev, + HANDSHAKE_DSP_BL_READY); + else + handshake = + get_handshake(ft1000dev, + HANDSHAKE_DSP_BL_READY); + + if (handshake == HANDSHAKE_DSP_BL_READY) { + DEBUG + ("scram_dnldr: handshake is HANDSHAKE_DSP_BL_READY, call put_handshake(HANDSHAKE_DRIVER_READY)\n"); + put_handshake(ft1000dev, + HANDSHAKE_DRIVER_READY); + } else { + DEBUG + ("FT1000:download:Download error: Handshake failed\n"); + status = STATUS_FAILURE; + } + + state = STATE_BOOT_DWNLD; + break; case STATE_BOOT_DWNLD: @@ -708,11 +794,41 @@ int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart, ft1000dev->fcodeldr = 1; break; case REQUEST_CODE_SEGMENT: - status = request_code_segment(ft1000dev, - &s_file, &c_file, - (const u8 *)boot_end, - true); - break; + //DEBUG("FT1000:REQUEST_CODE_SEGMENT\n"); + word_length = + get_request_value(ft1000dev); + //DEBUG("FT1000:word_length = 0x%x\n", (int)word_length); + //NdisMSleep (100); + if (word_length > MAX_LENGTH) { + DEBUG + ("FT1000:download:Download error: Max length exceeded\n"); + status = STATUS_FAILURE; + break; + } + if ((word_length * 2 + c_file) > + boot_end) { + /* + * Error, beyond boot code range. + */ + DEBUG + ("FT1000:download:Download error: Requested len=%d exceeds BOOT code boundary.\n", + (int)word_length); + status = STATUS_FAILURE; + break; + } + /* + * Position ASIC DPRAM auto-increment pointer. + */ + dpram = (u16) DWNLD_MAG1_PS_HDR_LOC; + if (word_length & 0x1) + word_length++; + word_length = word_length / 2; + + status = + write_blk(ft1000dev, &s_file, + &c_file, word_length); + //DEBUG("write_blk returned %d\n", status); + break; default: DEBUG ("FT1000:download:Download error: Bad request type=%d in BOOT download state.\n", @@ -813,10 +929,45 @@ int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart, break; } - status = request_code_segment(ft1000dev, - &s_file, &c_file, - (const u8 *)code_end, - false); + word_length = + get_request_value(ft1000dev); + //DEBUG("FT1000:download:word_length = %d\n", (int)word_length); + if (word_length > MAX_LENGTH) { + DEBUG + ("FT1000:download:Download error: Max length exceeded\n"); + status = STATUS_FAILURE; + break; + } + if ((word_length * 2 + c_file) > + code_end) { + /* + * Error, beyond boot code range. + */ + DEBUG + ("FT1000:download:Download error: Requested len=%d exceeds DSP code boundary.\n", + (int)word_length); + status = STATUS_FAILURE; + break; + } + /* + * Position ASIC DPRAM auto-increment pointer. + */ + dpram = (u16) DWNLD_MAG1_PS_HDR_LOC; + if (word_length & 0x1) + word_length++; + word_length = word_length / 2; + + write_blk_fifo(ft1000dev, &s_file, + &c_file, word_length); + if (ft1000dev->usbboot == 0) + ft1000dev->usbboot++; + if (ft1000dev->usbboot == 1) { + tempword = 0; + ft1000_write_dpram16(ft1000dev, + DWNLD_MAG1_PS_HDR_LOC, + tempword, + 0); + } break; @@ -885,7 +1036,7 @@ int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart, status = fix_ft1000_write_dpram32 (ft1000dev, dpram++, - (u8 *) &templong); + (u8 *) & templong); } break; @@ -893,7 +1044,7 @@ int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart, case REQUEST_CODE_BY_VERSION: DEBUG ("FT1000:download:REQUEST_CODE_BY_VERSION\n"); - correct_version = false; + correct_version = FALSE; requested_version = get_request_value(ft1000dev); @@ -910,7 +1061,7 @@ int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart, if (dsp_img_info->version == requested_version) { - correct_version = true; + correct_version = TRUE; DEBUG ("FT1000:download: correct_version is TRUE\n"); s_file = @@ -986,13 +1137,13 @@ int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart, if (pseudo_header->checksum == hdr_checksum(pseudo_header)) { if (pseudo_header->portdest != - 0x80 /* Dsp OAM */) { + 0x80 /* Dsp OAM */ ) { state = STATE_DONE_PROV; break; } pseudo_header_len = ntohs(pseudo_header->length); /* Byte length for PROV records */ - /* Get buffer for provisioning data */ + // Get buffer for provisioning data pbuffer = kmalloc((pseudo_header_len + sizeof(struct pseudo_hdr)), @@ -1050,8 +1201,9 @@ int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart, break; } /* End Switch */ - if (status != STATUS_SUCCESS) + if (status != STATUS_SUCCESS) { break; + } /**** // Check if Card is present @@ -1074,3 +1226,4 @@ int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart, return status; } + diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c b/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c index 0d4931b..9b8fed7 100644 --- a/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c @@ -29,7 +29,12 @@ //#define JDEBUG +static int ft1000_reset(void *ft1000dev); static int ft1000_submit_rx_urb(struct ft1000_info *info); +static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev); +static int ft1000_open (struct net_device *dev); +static struct net_device_stats *ft1000_netdev_stats(struct net_device *dev); +static int ft1000_chkcard (struct ft1000_usb *dev); static u8 tempbuffer[1600]; @@ -521,7 +526,7 @@ void card_send_command(struct ft1000_usb *ft1000dev, void *ptempbuffer, //----------------------------------------------------------------------- int dsp_reload(struct ft1000_usb *ft1000dev) { - int status; + u16 status; u16 tempword; u32 templong; @@ -628,9 +633,9 @@ static int ft1000_reset_card(struct net_device *dev) DEBUG("ft1000_hw:ft1000_reset_card called.....\n"); - ft1000dev->fCondResetPend = true; + ft1000dev->fCondResetPend = 1; info->CardReady = 0; - ft1000dev->fProvComplete = false; + ft1000dev->fProvComplete = 0; /* Make sure we free any memory reserve for provisioning */ while (list_empty(&info->prov_list) == 0) { @@ -661,216 +666,11 @@ static int ft1000_reset_card(struct net_device *dev) info->CardReady = 1; - ft1000dev->fCondResetPend = false; + ft1000dev->fCondResetPend = 0; return TRUE; } -//--------------------------------------------------------------------------- -// Function: ft1000_usb_transmit_complete -// -// Parameters: urb - transmitted usb urb -// -// -// Returns: none -// -// Description: This is the callback function when a urb is transmitted -// -// Notes: -// -//--------------------------------------------------------------------------- -static void ft1000_usb_transmit_complete(struct urb *urb) -{ - - struct ft1000_usb *ft1000dev = urb->context; - - if (urb->status) - pr_err("%s: TX status %d\n", ft1000dev->net->name, urb->status); - - netif_wake_queue(ft1000dev->net); -} - -//--------------------------------------------------------------------------- -// -// Function: ft1000_copy_down_pkt -// Description: This function will take an ethernet packet and convert it to -// a Flarion packet prior to sending it to the ASIC Downlink -// FIFO. -// Input: -// dev - device structure -// packet - address of ethernet packet -// len - length of IP packet -// Output: -// status - FAILURE -// SUCCESS -// -//--------------------------------------------------------------------------- -static int ft1000_copy_down_pkt(struct net_device *netdev, u8 * packet, u16 len) -{ - struct ft1000_info *pInfo = netdev_priv(netdev); - struct ft1000_usb *pFt1000Dev = pInfo->priv; - - int count, ret; - u8 *t; - struct pseudo_hdr hdr; - - if (!pInfo->CardReady) { - DEBUG("ft1000_copy_down_pkt::Card Not Ready\n"); - return -ENODEV; - } - - count = sizeof(struct pseudo_hdr) + len; - if (count > MAX_BUF_SIZE) { - DEBUG("Error:ft1000_copy_down_pkt:Message Size Overflow!\n"); - DEBUG("size = %d\n", count); - return -EINVAL; - } - - if (count % 4) - count = count + (4 - (count % 4)); - - memset(&hdr, 0, sizeof(struct pseudo_hdr)); - - hdr.length = ntohs(count); - hdr.source = 0x10; - hdr.destination = 0x20; - hdr.portdest = 0x20; - hdr.portsrc = 0x10; - hdr.sh_str_id = 0x91; - hdr.control = 0x00; - - hdr.checksum = hdr.length ^ hdr.source ^ hdr.destination ^ - hdr.portdest ^ hdr.portsrc ^ hdr.sh_str_id ^ hdr.control; - - memcpy(&pFt1000Dev->tx_buf[0], &hdr, sizeof(hdr)); - memcpy(&(pFt1000Dev->tx_buf[sizeof(struct pseudo_hdr)]), packet, len); - - netif_stop_queue(netdev); - - usb_fill_bulk_urb(pFt1000Dev->tx_urb, - pFt1000Dev->dev, - usb_sndbulkpipe(pFt1000Dev->dev, - pFt1000Dev->bulk_out_endpointAddr), - pFt1000Dev->tx_buf, count, - ft1000_usb_transmit_complete, (void *)pFt1000Dev); - - t = (u8 *) pFt1000Dev->tx_urb->transfer_buffer; - - ret = usb_submit_urb(pFt1000Dev->tx_urb, GFP_ATOMIC); - - if (ret) { - DEBUG("ft1000 failed tx_urb %d\n", ret); - return ret; - } else { - pInfo->stats.tx_packets++; - pInfo->stats.tx_bytes += (len + 14); - } - - return 0; -} - -//--------------------------------------------------------------------------- -// Function: ft1000_start_xmit -// -// Parameters: skb - socket buffer to be sent -// dev - network device -// -// -// Returns: none -// -// Description: transmit a ethernet packet -// -// Notes: -// -//--------------------------------------------------------------------------- -static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev) -{ - struct ft1000_info *pInfo = netdev_priv(dev); - struct ft1000_usb *pFt1000Dev = pInfo->priv; - u8 *pdata; - int maxlen, pipe; - - if (skb == NULL) { - DEBUG("ft1000_hw: ft1000_start_xmit:skb == NULL!!!\n"); - return NETDEV_TX_OK; - } - - if (pFt1000Dev->status & FT1000_STATUS_CLOSING) { - DEBUG("network driver is closed, return\n"); - goto err; - } - - pipe = - usb_sndbulkpipe(pFt1000Dev->dev, pFt1000Dev->bulk_out_endpointAddr); - maxlen = usb_maxpacket(pFt1000Dev->dev, pipe, usb_pipeout(pipe)); - - pdata = (u8 *) skb->data; - - if (pInfo->mediastate == 0) { - /* Drop packet is mediastate is down */ - DEBUG("ft1000_hw:ft1000_start_xmit:mediastate is down\n"); - goto err; - } - - if ((skb->len < ENET_HEADER_SIZE) || (skb->len > ENET_MAX_SIZE)) { - /* Drop packet which has invalid size */ - DEBUG("ft1000_hw:ft1000_start_xmit:invalid ethernet length\n"); - goto err; - } - - ft1000_copy_down_pkt(dev, (pdata + ENET_HEADER_SIZE - 2), - skb->len - ENET_HEADER_SIZE + 2); - -err: - dev_kfree_skb(skb); - - return NETDEV_TX_OK; -} - -//--------------------------------------------------------------------------- -// Function: ft1000_open -// -// Parameters: -// dev - network device -// -// -// Returns: none -// -// Description: open the network driver -// -// Notes: -// -//--------------------------------------------------------------------------- -static int ft1000_open(struct net_device *dev) -{ - struct ft1000_info *pInfo = netdev_priv(dev); - struct ft1000_usb *pFt1000Dev = pInfo->priv; - struct timeval tv; - - DEBUG("ft1000_open is called for card %d\n", pFt1000Dev->CardNumber); - - pInfo->stats.rx_bytes = 0; - pInfo->stats.tx_bytes = 0; - pInfo->stats.rx_packets = 0; - pInfo->stats.tx_packets = 0; - do_gettimeofday(&tv); - pInfo->ConTm = tv.tv_sec; - pInfo->ProgConStat = 0; - - netif_start_queue(dev); - - netif_carrier_on(dev); - - return ft1000_submit_rx_urb(pInfo); -} - -static struct net_device_stats *ft1000_netdev_stats(struct net_device *dev) -{ - struct ft1000_info *info = netdev_priv(dev); - - return &(info->stats); -} - static const struct net_device_ops ftnet_ops = { .ndo_open = &ft1000_open, @@ -879,6 +679,7 @@ static const struct net_device_ops ftnet_ops = .ndo_get_stats = &ft1000_netdev_stats, }; + //--------------------------------------------------------------------------- // Function: init_ft1000_netdev // @@ -893,13 +694,6 @@ static const struct net_device_ops ftnet_ops = // Notes: // //--------------------------------------------------------------------------- - -static int ft1000_reset(void *dev) -{ - ft1000_reset_card(dev); - return 0; -} - int init_ft1000_netdev(struct ft1000_usb *ft1000dev) { struct net_device *netdev; @@ -958,8 +752,8 @@ int init_ft1000_netdev(struct ft1000_usb *ft1000dev) pInfo->DSP_TIME[1] = 0; pInfo->DSP_TIME[2] = 0; pInfo->DSP_TIME[3] = 0; - ft1000dev->fAppMsgPend = false; - ft1000dev->fCondResetPend = false; + ft1000dev->fAppMsgPend = 0; + ft1000dev->fCondResetPend = 0; ft1000dev->usbboot = 0; ft1000dev->dspalive = 0; memset(&ft1000dev->tempbuf[0], 0, sizeof(ft1000dev->tempbuf)); @@ -1060,6 +854,175 @@ int reg_ft1000_netdev(struct ft1000_usb *ft1000dev, return 0; } +int ft1000_reset(void *dev) +{ + ft1000_reset_card(dev); + return 0; +} + +//--------------------------------------------------------------------------- +// Function: ft1000_usb_transmit_complete +// +// Parameters: urb - transmitted usb urb +// +// +// Returns: none +// +// Description: This is the callback function when a urb is transmitted +// +// Notes: +// +//--------------------------------------------------------------------------- +static void ft1000_usb_transmit_complete(struct urb *urb) +{ + + struct ft1000_usb *ft1000dev = urb->context; + + if (urb->status) + pr_err("%s: TX status %d\n", ft1000dev->net->name, urb->status); + + netif_wake_queue(ft1000dev->net); +} + +//--------------------------------------------------------------------------- +// +// Function: ft1000_copy_down_pkt +// Description: This function will take an ethernet packet and convert it to +// a Flarion packet prior to sending it to the ASIC Downlink +// FIFO. +// Input: +// dev - device structure +// packet - address of ethernet packet +// len - length of IP packet +// Output: +// status - FAILURE +// SUCCESS +// +//--------------------------------------------------------------------------- +static int ft1000_copy_down_pkt(struct net_device *netdev, u8 * packet, u16 len) +{ + struct ft1000_info *pInfo = netdev_priv(netdev); + struct ft1000_usb *pFt1000Dev = pInfo->priv; + + int count, ret; + u8 *t; + struct pseudo_hdr hdr; + + if (!pInfo->CardReady) { + DEBUG("ft1000_copy_down_pkt::Card Not Ready\n"); + return -ENODEV; + } + + count = sizeof(struct pseudo_hdr) + len; + if (count > MAX_BUF_SIZE) { + DEBUG("Error:ft1000_copy_down_pkt:Message Size Overflow!\n"); + DEBUG("size = %d\n", count); + return -EINVAL; + } + + if (count % 4) + count = count + (4 - (count % 4)); + + memset(&hdr, 0, sizeof(struct pseudo_hdr)); + + hdr.length = ntohs(count); + hdr.source = 0x10; + hdr.destination = 0x20; + hdr.portdest = 0x20; + hdr.portsrc = 0x10; + hdr.sh_str_id = 0x91; + hdr.control = 0x00; + + hdr.checksum = hdr.length ^ hdr.source ^ hdr.destination ^ + hdr.portdest ^ hdr.portsrc ^ hdr.sh_str_id ^ hdr.control; + + memcpy(&pFt1000Dev->tx_buf[0], &hdr, sizeof(hdr)); + memcpy(&(pFt1000Dev->tx_buf[sizeof(struct pseudo_hdr)]), packet, len); + + netif_stop_queue(netdev); + + usb_fill_bulk_urb(pFt1000Dev->tx_urb, + pFt1000Dev->dev, + usb_sndbulkpipe(pFt1000Dev->dev, + pFt1000Dev->bulk_out_endpointAddr), + pFt1000Dev->tx_buf, count, + ft1000_usb_transmit_complete, (void *)pFt1000Dev); + + t = (u8 *) pFt1000Dev->tx_urb->transfer_buffer; + + ret = usb_submit_urb(pFt1000Dev->tx_urb, GFP_ATOMIC); + + if (ret) { + DEBUG("ft1000 failed tx_urb %d\n", ret); + return ret; + } else { + pInfo->stats.tx_packets++; + pInfo->stats.tx_bytes += (len + 14); + } + + return 0; +} + + +//--------------------------------------------------------------------------- +// Function: ft1000_start_xmit +// +// Parameters: skb - socket buffer to be sent +// dev - network device +// +// +// Returns: none +// +// Description: transmit a ethernet packet +// +// Notes: +// +//--------------------------------------------------------------------------- +static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev) +{ + struct ft1000_info *pInfo = netdev_priv(dev); + struct ft1000_usb *pFt1000Dev = pInfo->priv; + u8 *pdata; + int maxlen, pipe; + + if (skb == NULL) { + DEBUG("ft1000_hw: ft1000_start_xmit:skb == NULL!!!\n"); + return NETDEV_TX_OK; + } + + if (pFt1000Dev->status & FT1000_STATUS_CLOSING) { + DEBUG("network driver is closed, return\n"); + goto err; + } + + pipe = + usb_sndbulkpipe(pFt1000Dev->dev, pFt1000Dev->bulk_out_endpointAddr); + maxlen = usb_maxpacket(pFt1000Dev->dev, pipe, usb_pipeout(pipe)); + + pdata = (u8 *) skb->data; + + if (pInfo->mediastate == 0) { + /* Drop packet is mediastate is down */ + DEBUG("ft1000_hw:ft1000_start_xmit:mediastate is down\n"); + goto err; + } + + if ((skb->len < ENET_HEADER_SIZE) || (skb->len > ENET_MAX_SIZE)) { + /* Drop packet which has invalid size */ + DEBUG("ft1000_hw:ft1000_start_xmit:invalid ethernet length\n"); + goto err; + } + + ft1000_copy_down_pkt(dev, (pdata + ENET_HEADER_SIZE - 2), + skb->len - ENET_HEADER_SIZE + 2); + +err: + dev_kfree_skb(skb); + + return NETDEV_TX_OK; +} + + //--------------------------------------------------------------------------- // // Function: ft1000_copy_up_pkt @@ -1196,6 +1159,44 @@ static int ft1000_submit_rx_urb(struct ft1000_info *info) return 0; } + +//--------------------------------------------------------------------------- +// Function: ft1000_open +// +// Parameters: +// dev - network device +// +// +// Returns: none +// +// Description: open the network driver +// +// Notes: +// +//--------------------------------------------------------------------------- +static int ft1000_open(struct net_device *dev) +{ + struct ft1000_info *pInfo = netdev_priv(dev); + struct ft1000_usb *pFt1000Dev = pInfo->priv; + struct timeval tv; + + DEBUG("ft1000_open is called for card %d\n", pFt1000Dev->CardNumber); + + pInfo->stats.rx_bytes = 0; + pInfo->stats.tx_bytes = 0; + pInfo->stats.rx_packets = 0; + pInfo->stats.tx_packets = 0; + do_gettimeofday(&tv); + pInfo->ConTm = tv.tv_sec; + pInfo->ProgConStat = 0; + + netif_start_queue(dev); + + netif_carrier_on(dev); + + return ft1000_submit_rx_urb(pInfo); +} + //--------------------------------------------------------------------------- // Function: ft1000_close // @@ -1227,6 +1228,14 @@ int ft1000_close(struct net_device *net) return 0; } +static struct net_device_stats *ft1000_netdev_stats(struct net_device *dev) +{ + struct ft1000_info *info = netdev_priv(dev); + + return &(info->stats); +} + + //--------------------------------------------------------------------------- // // Function: ft1000_chkcard @@ -1432,7 +1441,7 @@ static int ft1000_dsp_prov(void *arg) msleep(100); - dev->fProvComplete = true; + dev->fProvComplete = 1; info->CardReady = 1; return STATUS_SUCCESS; @@ -1558,12 +1567,12 @@ static int ft1000_proc_drvmsg(struct ft1000_usb *dev, u16 size) * Send provisioning data to DSP */ if (list_empty(&info->prov_list) == 0) { - dev->fProvComplete = false; + dev->fProvComplete = 0; status = ft1000_dsp_prov(dev); if (status != STATUS_SUCCESS) goto out; } else { - dev->fProvComplete = true; + dev->fProvComplete = 1; status = ft1000_write_register(dev, FT1000_DB_HB, FT1000_REG_DOORBELL); @@ -1912,7 +1921,7 @@ int ft1000_poll(void* dev_id) else if (tempword & FT1000_DB_COND_RESET) { DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_COND_RESET\n"); - if (!dev->fAppMsgPend) { + if (dev->fAppMsgPend == 0) { // Reset ASIC and DSP status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (u8 *)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX); @@ -1925,8 +1934,8 @@ int ft1000_poll(void* dev_id) info->ft1000_reset(dev->net); } else { - dev->fProvComplete = false; - dev->fCondResetPend = true; + dev->fProvComplete = 0; + dev->fCondResetPend = 1; } ft1000_write_register(dev, FT1000_DB_COND_RESET, FT1000_REG_DOORBELL); diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c index a8dd1e5..29a7cd2 100644 --- a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c @@ -36,7 +36,7 @@ static struct usb_device_id id_table[] = { MODULE_DEVICE_TABLE(usb, id_table); -static bool gPollingfailed = false; +static bool gPollingfailed = FALSE; static int ft1000_poll_thread(void *arg) { int ret; @@ -47,7 +47,7 @@ static int ft1000_poll_thread(void *arg) ret = ft1000_poll(arg); if (ret != STATUS_SUCCESS) { DEBUG("ft1000_poll_thread: polling failed\n"); - gPollingfailed = true; + gPollingfailed = TRUE; } } } @@ -171,7 +171,7 @@ static int ft1000_probe(struct usb_interface *interface, goto err_load; } - gPollingfailed = false; + gPollingfailed = FALSE; ft1000dev->pPollThread = kthread_run(ft1000_poll_thread, ft1000dev, "ft1000_poll"); diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h index e8d00a9..bd1da1f 100644 --- a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h @@ -125,7 +125,7 @@ extern size_t FileLength; extern int numofmsgbuf; int ft1000_close(struct net_device *dev); -int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart, +u16 scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart, u32 FileLength); extern struct list_head freercvpool; |