Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 1 | /*--------------------------------------------------------------------------- |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 2 | FT1000 driver for Flarion Flash OFDM NIC Device |
Greg Kroah-Hartman | bf3146c | 2010-09-22 08:34:49 -0700 | [diff] [blame] | 3 | |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 4 | Copyright (C) 2002 Flarion Technologies, All rights reserved. |
Greg Kroah-Hartman | bf3146c | 2010-09-22 08:34:49 -0700 | [diff] [blame] | 5 | |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms of the GNU General Public License as published by the Free |
| 8 | Software Foundation; either version 2 of the License, or (at your option) any |
| 9 | later version. This program is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 11 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | more details. You should have received a copy of the GNU General Public |
| 13 | License along with this program; if not, write to the |
| 14 | Free Software Foundation, Inc., 59 Temple Place - |
| 15 | Suite 330, Boston, MA 02111-1307, USA. |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 16 | -------------------------------------------------------------------------- |
| 17 | |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 18 | Description: This module will handshake with the DSP bootloader to |
| 19 | download the DSP runtime image. |
Greg Kroah-Hartman | bf3146c | 2010-09-22 08:34:49 -0700 | [diff] [blame] | 20 | |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 21 | ---------------------------------------------------------------------------*/ |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 22 | |
Joe Perches | b5d8204 | 2014-11-03 16:25:44 -0800 | [diff] [blame] | 23 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 24 | |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 25 | #define __KERNEL_SYSCALLS__ |
| 26 | |
| 27 | #include <linux/module.h> |
| 28 | #include <linux/fs.h> |
| 29 | #include <linux/mm.h> |
| 30 | #include <linux/slab.h> |
| 31 | #include <linux/unistd.h> |
| 32 | #include <linux/netdevice.h> |
| 33 | #include <linux/timer.h> |
| 34 | #include <linux/delay.h> |
Gulsah Kose | 56a2839 | 2014-09-26 22:55:59 +0300 | [diff] [blame] | 35 | #include <linux/io.h> |
| 36 | #include <linux/uaccess.h> |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 37 | #include <linux/vmalloc.h> |
| 38 | |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 39 | #include "ft1000.h" |
| 40 | #include "boot.h" |
| 41 | |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 42 | #define MAX_DSP_WAIT_LOOPS 100 |
| 43 | #define DSP_WAIT_SLEEP_TIME 1 /* 1 millisecond */ |
| 44 | |
| 45 | #define MAX_LENGTH 0x7f0 |
| 46 | |
| 47 | #define DWNLD_MAG_HANDSHAKE_LOC 0x00 |
| 48 | #define DWNLD_MAG_TYPE_LOC 0x01 |
| 49 | #define DWNLD_MAG_SIZE_LOC 0x02 |
| 50 | #define DWNLD_MAG_PS_HDR_LOC 0x03 |
| 51 | |
| 52 | #define DWNLD_HANDSHAKE_LOC 0x02 |
| 53 | #define DWNLD_TYPE_LOC 0x04 |
| 54 | #define DWNLD_SIZE_MSW_LOC 0x06 |
| 55 | #define DWNLD_SIZE_LSW_LOC 0x08 |
| 56 | #define DWNLD_PS_HDR_LOC 0x0A |
| 57 | |
| 58 | #define HANDSHAKE_TIMEOUT_VALUE 0xF1F1 |
| 59 | #define HANDSHAKE_RESET_VALUE 0xFEFE /* When DSP requests startover */ |
| 60 | #define HANDSHAKE_DSP_BL_READY 0xFEFE /* At start DSP writes this when bootloader ready */ |
| 61 | #define HANDSHAKE_DRIVER_READY 0xFFFF /* Driver writes after receiving 0xFEFE */ |
| 62 | #define HANDSHAKE_SEND_DATA 0x0000 /* DSP writes this when ready for more data */ |
| 63 | |
| 64 | #define HANDSHAKE_REQUEST 0x0001 /* Request from DSP */ |
| 65 | #define HANDSHAKE_RESPONSE 0x0000 /* Satisfied DSP request */ |
| 66 | |
| 67 | #define REQUEST_CODE_LENGTH 0x0000 |
| 68 | #define REQUEST_RUN_ADDRESS 0x0001 |
| 69 | #define REQUEST_CODE_SEGMENT 0x0002 /* In WORD count */ |
| 70 | #define REQUEST_DONE_BL 0x0003 |
| 71 | #define REQUEST_DONE_CL 0x0004 |
| 72 | #define REQUEST_VERSION_INFO 0x0005 |
| 73 | #define REQUEST_CODE_BY_VERSION 0x0006 |
| 74 | #define REQUEST_MAILBOX_DATA 0x0007 |
| 75 | #define REQUEST_FILE_CHECKSUM 0x0008 |
| 76 | |
| 77 | #define STATE_START_DWNLD 0x01 |
| 78 | #define STATE_BOOT_DWNLD 0x02 |
| 79 | #define STATE_CODE_DWNLD 0x03 |
| 80 | #define STATE_DONE_DWNLD 0x04 |
| 81 | #define STATE_SECTION_PROV 0x05 |
| 82 | #define STATE_DONE_PROV 0x06 |
| 83 | #define STATE_DONE_FILE 0x07 |
| 84 | |
Ondrej Zary | ca14527 | 2011-07-01 00:03:47 +0200 | [diff] [blame] | 85 | u16 get_handshake(struct net_device *dev, u16 expected_value); |
| 86 | void put_handshake(struct net_device *dev, u16 handshake_value); |
| 87 | u16 get_request_type(struct net_device *dev); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 88 | long get_request_value(struct net_device *dev); |
| 89 | void put_request_value(struct net_device *dev, long lvalue); |
Ondrej Zary | ca14527 | 2011-07-01 00:03:47 +0200 | [diff] [blame] | 90 | u16 hdr_checksum(struct pseudo_hdr *pHdr); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 91 | |
Ondrej Zary | 8e0fd2c | 2011-07-01 00:03:45 +0200 | [diff] [blame] | 92 | struct dsp_file_hdr { |
Devendra Naga | ad13963 | 2012-09-16 13:49:40 -0400 | [diff] [blame] | 93 | u32 version_id; /* Version ID of this image format. */ |
| 94 | u32 package_id; /* Package ID of code release. */ |
| 95 | u32 build_date; /* Date/time stamp when file was built. */ |
| 96 | u32 commands_offset; /* Offset to attached commands in Pseudo Hdr format. */ |
| 97 | u32 loader_offset; /* Offset to bootloader code. */ |
| 98 | u32 loader_code_address; /* Start address of bootloader. */ |
| 99 | u32 loader_code_end; /* Where bootloader code ends. */ |
pixo | 14e5d8e | 2011-03-23 08:08:08 +0100 | [diff] [blame] | 100 | u32 loader_code_size; |
Devendra Naga | ad13963 | 2012-09-16 13:49:40 -0400 | [diff] [blame] | 101 | u32 version_data_offset; /* Offset were scrambled version data begins. */ |
| 102 | u32 version_data_size; /* Size, in words, of scrambled version data. */ |
| 103 | u32 nDspImages; /* Number of DSP images in file. */ |
Geoff Darst | 0a005d5 | 2014-11-29 13:17:22 -0700 | [diff] [blame] | 104 | } __packed; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 105 | |
Ondrej Zary | 8e0fd2c | 2011-07-01 00:03:45 +0200 | [diff] [blame] | 106 | struct dsp_image_info { |
Devendra Naga | ad13963 | 2012-09-16 13:49:40 -0400 | [diff] [blame] | 107 | u32 coff_date; /* Date/time when DSP Coff image was built. */ |
| 108 | u32 begin_offset; /* Offset in file where image begins. */ |
| 109 | u32 end_offset; /* Offset in file where image begins. */ |
| 110 | u32 run_address; /* On chip Start address of DSP code. */ |
| 111 | u32 image_size; /* Size of image. */ |
| 112 | u32 version; /* Embedded version # of DSP code. */ |
| 113 | unsigned short checksum; /* Dsp File checksum */ |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 114 | unsigned short pad1; |
Geoff Darst | 0a005d5 | 2014-11-29 13:17:22 -0700 | [diff] [blame] | 115 | } __packed; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 116 | |
| 117 | void card_bootload(struct net_device *dev) |
| 118 | { |
Julia Lawall | a4820ac | 2015-03-29 14:54:14 +0200 | [diff] [blame] | 119 | struct ft1000_info *info = netdev_priv(dev); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 120 | unsigned long flags; |
Ondrej Zary | ca14527 | 2011-07-01 00:03:47 +0200 | [diff] [blame] | 121 | u32 *pdata; |
| 122 | u32 size; |
| 123 | u32 i; |
| 124 | u32 templong; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 125 | |
Catalina Mocanu | 8f3a2e0 | 2014-09-22 15:14:18 -0700 | [diff] [blame] | 126 | netdev_dbg(dev, "card_bootload is called\n"); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 127 | |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 128 | pdata = (u32 *)bootimage; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 129 | size = sizeof(bootimage); |
| 130 | |
Dylan Socolobsky | 8671438 | 2013-05-13 19:47:33 -0300 | [diff] [blame] | 131 | /* check for odd word */ |
Dylan Socolobsky | 6fb3c2b | 2013-05-13 19:42:28 -0300 | [diff] [blame] | 132 | if (size & 0x0003) |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 133 | size += 4; |
Dylan Socolobsky | 6fb3c2b | 2013-05-13 19:42:28 -0300 | [diff] [blame] | 134 | |
Dylan Socolobsky | 8671438 | 2013-05-13 19:47:33 -0300 | [diff] [blame] | 135 | /* Provide mutual exclusive access while reading ASIC registers. */ |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 136 | spin_lock_irqsave(&info->dpram_lock, flags); |
| 137 | |
Dylan Socolobsky | 8671438 | 2013-05-13 19:47:33 -0300 | [diff] [blame] | 138 | /* need to set i/o base address initially and hardware will autoincrement */ |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 139 | ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR, FT1000_DPRAM_BASE); |
Dylan Socolobsky | 8671438 | 2013-05-13 19:47:33 -0300 | [diff] [blame] | 140 | /* write bytes */ |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 141 | for (i = 0; i < (size >> 2); i++) { |
| 142 | templong = *pdata++; |
| 143 | outl(templong, dev->base_addr + FT1000_REG_MAG_DPDATA); |
| 144 | } |
| 145 | |
| 146 | spin_unlock_irqrestore(&info->dpram_lock, flags); |
| 147 | } |
| 148 | |
Ondrej Zary | ca14527 | 2011-07-01 00:03:47 +0200 | [diff] [blame] | 149 | u16 get_handshake(struct net_device *dev, u16 expected_value) |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 150 | { |
Julia Lawall | a4820ac | 2015-03-29 14:54:14 +0200 | [diff] [blame] | 151 | struct ft1000_info *info = netdev_priv(dev); |
Ondrej Zary | ca14527 | 2011-07-01 00:03:47 +0200 | [diff] [blame] | 152 | u16 handshake; |
| 153 | u32 tempx; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 154 | int loopcnt; |
| 155 | |
| 156 | loopcnt = 0; |
| 157 | while (loopcnt < MAX_DSP_WAIT_LOOPS) { |
| 158 | if (info->AsicID == ELECTRABUZZ_ID) { |
| 159 | ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR, |
| 160 | DWNLD_HANDSHAKE_LOC); |
| 161 | |
| 162 | handshake = ft1000_read_reg(dev, FT1000_REG_DPRAM_DATA); |
| 163 | } else { |
| 164 | tempx = |
| 165 | ntohl(ft1000_read_dpram_mag_32 |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 166 | (dev, DWNLD_MAG_HANDSHAKE_LOC)); |
| 167 | handshake = (u16)tempx; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | if ((handshake == expected_value) |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 171 | || (handshake == HANDSHAKE_RESET_VALUE)) { |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 172 | return handshake; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 173 | } |
Gulsah Kose | 96bcbea | 2014-09-26 22:49:26 +0300 | [diff] [blame] | 174 | loopcnt++; |
| 175 | mdelay(DSP_WAIT_SLEEP_TIME); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 176 | |
| 177 | } |
| 178 | |
| 179 | return HANDSHAKE_TIMEOUT_VALUE; |
| 180 | |
| 181 | } |
| 182 | |
Ondrej Zary | ca14527 | 2011-07-01 00:03:47 +0200 | [diff] [blame] | 183 | void put_handshake(struct net_device *dev, u16 handshake_value) |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 184 | { |
Julia Lawall | a4820ac | 2015-03-29 14:54:14 +0200 | [diff] [blame] | 185 | struct ft1000_info *info = netdev_priv(dev); |
Ondrej Zary | ca14527 | 2011-07-01 00:03:47 +0200 | [diff] [blame] | 186 | u32 tempx; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 187 | |
| 188 | if (info->AsicID == ELECTRABUZZ_ID) { |
| 189 | ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR, |
| 190 | DWNLD_HANDSHAKE_LOC); |
| 191 | ft1000_write_reg(dev, FT1000_REG_DPRAM_DATA, handshake_value); /* Handshake */ |
| 192 | } else { |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 193 | tempx = (u32)handshake_value; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 194 | tempx = ntohl(tempx); |
| 195 | ft1000_write_dpram_mag_32(dev, DWNLD_MAG_HANDSHAKE_LOC, tempx); /* Handshake */ |
| 196 | } |
| 197 | } |
| 198 | |
Ondrej Zary | ca14527 | 2011-07-01 00:03:47 +0200 | [diff] [blame] | 199 | u16 get_request_type(struct net_device *dev) |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 200 | { |
Julia Lawall | a4820ac | 2015-03-29 14:54:14 +0200 | [diff] [blame] | 201 | struct ft1000_info *info = netdev_priv(dev); |
Ondrej Zary | ca14527 | 2011-07-01 00:03:47 +0200 | [diff] [blame] | 202 | u16 request_type; |
| 203 | u32 tempx; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 204 | |
| 205 | if (info->AsicID == ELECTRABUZZ_ID) { |
| 206 | ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR, DWNLD_TYPE_LOC); |
| 207 | request_type = ft1000_read_reg(dev, FT1000_REG_DPRAM_DATA); |
| 208 | } else { |
| 209 | tempx = ft1000_read_dpram_mag_32(dev, DWNLD_MAG_TYPE_LOC); |
| 210 | tempx = ntohl(tempx); |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 211 | request_type = (u16)tempx; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | return request_type; |
| 215 | |
| 216 | } |
| 217 | |
| 218 | long get_request_value(struct net_device *dev) |
| 219 | { |
Julia Lawall | a4820ac | 2015-03-29 14:54:14 +0200 | [diff] [blame] | 220 | struct ft1000_info *info = netdev_priv(dev); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 221 | long value; |
Ondrej Zary | ca14527 | 2011-07-01 00:03:47 +0200 | [diff] [blame] | 222 | u16 w_val; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 223 | |
| 224 | if (info->AsicID == ELECTRABUZZ_ID) { |
| 225 | ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR, |
| 226 | DWNLD_SIZE_MSW_LOC); |
| 227 | |
| 228 | w_val = ft1000_read_reg(dev, FT1000_REG_DPRAM_DATA); |
| 229 | |
| 230 | value = (long)(w_val << 16); |
| 231 | |
| 232 | ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR, |
| 233 | DWNLD_SIZE_LSW_LOC); |
| 234 | |
| 235 | w_val = ft1000_read_reg(dev, FT1000_REG_DPRAM_DATA); |
| 236 | |
| 237 | value = (long)(value | w_val); |
| 238 | } else { |
| 239 | value = ft1000_read_dpram_mag_32(dev, DWNLD_MAG_SIZE_LOC); |
| 240 | value = ntohl(value); |
| 241 | } |
| 242 | |
| 243 | return value; |
| 244 | |
| 245 | } |
| 246 | |
| 247 | void put_request_value(struct net_device *dev, long lvalue) |
| 248 | { |
Julia Lawall | a4820ac | 2015-03-29 14:54:14 +0200 | [diff] [blame] | 249 | struct ft1000_info *info = netdev_priv(dev); |
Ondrej Zary | ca14527 | 2011-07-01 00:03:47 +0200 | [diff] [blame] | 250 | u16 size; |
| 251 | u32 tempx; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 252 | |
| 253 | if (info->AsicID == ELECTRABUZZ_ID) { |
Ondrej Zary | ca14527 | 2011-07-01 00:03:47 +0200 | [diff] [blame] | 254 | size = (u16) (lvalue >> 16); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 255 | |
| 256 | ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR, |
| 257 | DWNLD_SIZE_MSW_LOC); |
| 258 | |
| 259 | ft1000_write_reg(dev, FT1000_REG_DPRAM_DATA, size); |
| 260 | |
Ondrej Zary | ca14527 | 2011-07-01 00:03:47 +0200 | [diff] [blame] | 261 | size = (u16) (lvalue); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 262 | |
| 263 | ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR, |
| 264 | DWNLD_SIZE_LSW_LOC); |
| 265 | |
| 266 | ft1000_write_reg(dev, FT1000_REG_DPRAM_DATA, size); |
| 267 | } else { |
| 268 | tempx = ntohl(lvalue); |
| 269 | ft1000_write_dpram_mag_32(dev, DWNLD_MAG_SIZE_LOC, tempx); /* Handshake */ |
| 270 | } |
| 271 | |
| 272 | } |
| 273 | |
Ondrej Zary | ca14527 | 2011-07-01 00:03:47 +0200 | [diff] [blame] | 274 | u16 hdr_checksum(struct pseudo_hdr *pHdr) |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 275 | { |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 276 | u16 *usPtr = (u16 *)pHdr; |
Ondrej Zary | ca14527 | 2011-07-01 00:03:47 +0200 | [diff] [blame] | 277 | u16 chksum; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 278 | |
Haneen Mohammed | 964308a | 2015-03-13 20:51:17 +0300 | [diff] [blame] | 279 | chksum = (((((usPtr[0] ^ usPtr[1]) ^ usPtr[2]) ^ usPtr[3]) ^ |
| 280 | usPtr[4]) ^ usPtr[5]) ^ usPtr[6]; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 281 | |
| 282 | return chksum; |
| 283 | } |
| 284 | |
Randy Dunlap | eb93ca4 | 2011-08-08 11:31:48 -0700 | [diff] [blame] | 285 | int card_download(struct net_device *dev, const u8 *pFileStart, |
| 286 | size_t FileLength) |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 287 | { |
Julia Lawall | a4820ac | 2015-03-29 14:54:14 +0200 | [diff] [blame] | 288 | struct ft1000_info *info = netdev_priv(dev); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 289 | int Status = SUCCESS; |
Ondrej Zary | ca14527 | 2011-07-01 00:03:47 +0200 | [diff] [blame] | 290 | u32 uiState; |
| 291 | u16 handshake; |
Ondrej Zary | 2c9bf83 | 2011-07-01 00:03:34 +0200 | [diff] [blame] | 292 | struct pseudo_hdr *pHdr; |
Ondrej Zary | ca14527 | 2011-07-01 00:03:47 +0200 | [diff] [blame] | 293 | u16 usHdrLength; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 294 | long word_length; |
Ondrej Zary | ca14527 | 2011-07-01 00:03:47 +0200 | [diff] [blame] | 295 | u16 request; |
| 296 | u16 temp; |
Ondrej Zary | 3aaf807 | 2011-07-01 00:03:41 +0200 | [diff] [blame] | 297 | struct prov_record *pprov_record; |
Ondrej Zary | ca14527 | 2011-07-01 00:03:47 +0200 | [diff] [blame] | 298 | u8 *pbuffer; |
Ondrej Zary | e161a44 | 2011-07-01 00:03:57 +0200 | [diff] [blame] | 299 | struct dsp_file_hdr *pFileHdr5; |
| 300 | struct dsp_image_info *pDspImageInfoV6 = NULL; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 301 | long requested_version; |
Rashika Kheria | 93b2a6c | 2013-10-27 19:53:36 +0530 | [diff] [blame] | 302 | bool bGoodVersion = false; |
Ondrej Zary | 8bc0d6f | 2011-07-01 00:03:35 +0200 | [diff] [blame] | 303 | struct drv_msg *pMailBoxData; |
Ondrej Zary | ca14527 | 2011-07-01 00:03:47 +0200 | [diff] [blame] | 304 | u16 *pUsData = NULL; |
| 305 | u16 *pUsFile = NULL; |
| 306 | u8 *pUcFile = NULL; |
| 307 | u8 *pBootEnd = NULL; |
| 308 | u8 *pCodeEnd = NULL; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 309 | int imageN; |
| 310 | long file_version; |
| 311 | long loader_code_address = 0; |
| 312 | long loader_code_size = 0; |
| 313 | long run_address = 0; |
| 314 | long run_size = 0; |
| 315 | unsigned long flags; |
| 316 | unsigned long templong; |
| 317 | unsigned long image_chksum = 0; |
| 318 | |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 319 | file_version = *(long *)pFileStart; |
Ondrej Zary | e161a44 | 2011-07-01 00:03:57 +0200 | [diff] [blame] | 320 | if (file_version != 6) { |
Joe Perches | b5d8204 | 2014-11-03 16:25:44 -0800 | [diff] [blame] | 321 | pr_err("unsupported firmware version %ld\n", file_version); |
Ondrej Zary | e161a44 | 2011-07-01 00:03:57 +0200 | [diff] [blame] | 322 | Status = FAILURE; |
| 323 | } |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 324 | |
| 325 | uiState = STATE_START_DWNLD; |
| 326 | |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 327 | pFileHdr5 = (struct dsp_file_hdr *)pFileStart; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 328 | |
Ondrej Zary | e161a44 | 2011-07-01 00:03:57 +0200 | [diff] [blame] | 329 | pUsFile = (u16 *) ((long)pFileStart + pFileHdr5->loader_offset); |
| 330 | pUcFile = (u8 *) ((long)pFileStart + pFileHdr5->loader_offset); |
| 331 | pBootEnd = (u8 *) ((long)pFileStart + pFileHdr5->loader_code_end); |
| 332 | loader_code_address = pFileHdr5->loader_code_address; |
| 333 | loader_code_size = pFileHdr5->loader_code_size; |
| 334 | bGoodVersion = false; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 335 | |
| 336 | while ((Status == SUCCESS) && (uiState != STATE_DONE_FILE)) { |
| 337 | |
| 338 | switch (uiState) { |
| 339 | case STATE_START_DWNLD: |
| 340 | |
| 341 | handshake = get_handshake(dev, HANDSHAKE_DSP_BL_READY); |
| 342 | |
Dylan Socolobsky | 6fb3c2b | 2013-05-13 19:42:28 -0300 | [diff] [blame] | 343 | if (handshake == HANDSHAKE_DSP_BL_READY) |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 344 | put_handshake(dev, HANDSHAKE_DRIVER_READY); |
Dylan Socolobsky | 6fb3c2b | 2013-05-13 19:42:28 -0300 | [diff] [blame] | 345 | else |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 346 | Status = FAILURE; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 347 | |
| 348 | uiState = STATE_BOOT_DWNLD; |
| 349 | |
| 350 | break; |
| 351 | |
| 352 | case STATE_BOOT_DWNLD: |
| 353 | handshake = get_handshake(dev, HANDSHAKE_REQUEST); |
| 354 | if (handshake == HANDSHAKE_REQUEST) { |
| 355 | /* |
| 356 | * Get type associated with the request. |
| 357 | */ |
| 358 | request = get_request_type(dev); |
| 359 | switch (request) { |
| 360 | case REQUEST_RUN_ADDRESS: |
| 361 | put_request_value(dev, |
| 362 | loader_code_address); |
| 363 | break; |
| 364 | case REQUEST_CODE_LENGTH: |
| 365 | put_request_value(dev, |
| 366 | loader_code_size); |
| 367 | break; |
| 368 | case REQUEST_DONE_BL: |
| 369 | /* Reposition ptrs to beginning of code section */ |
Ondrej Zary | ca14527 | 2011-07-01 00:03:47 +0200 | [diff] [blame] | 370 | pUsFile = (u16 *) ((long)pBootEnd); |
| 371 | pUcFile = (u8 *) ((long)pBootEnd); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 372 | uiState = STATE_CODE_DWNLD; |
| 373 | break; |
| 374 | case REQUEST_CODE_SEGMENT: |
| 375 | word_length = get_request_value(dev); |
| 376 | if (word_length > MAX_LENGTH) { |
| 377 | Status = FAILURE; |
| 378 | break; |
| 379 | } |
| 380 | if ((word_length * 2 + (long)pUcFile) > |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 381 | (long)pBootEnd) { |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 382 | /* |
| 383 | * Error, beyond boot code range. |
| 384 | */ |
| 385 | Status = FAILURE; |
| 386 | break; |
| 387 | } |
Dylan Socolobsky | 8671438 | 2013-05-13 19:47:33 -0300 | [diff] [blame] | 388 | /* Provide mutual exclusive access while reading ASIC registers. */ |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 389 | spin_lock_irqsave(&info->dpram_lock, |
| 390 | flags); |
Ondrej Zary | e161a44 | 2011-07-01 00:03:57 +0200 | [diff] [blame] | 391 | /* |
| 392 | * Position ASIC DPRAM auto-increment pointer. |
| 393 | */ |
| 394 | outw(DWNLD_MAG_PS_HDR_LOC, |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 395 | dev->base_addr + |
| 396 | FT1000_REG_DPRAM_ADDR); |
Ondrej Zary | e161a44 | 2011-07-01 00:03:57 +0200 | [diff] [blame] | 397 | if (word_length & 0x01) |
| 398 | word_length++; |
| 399 | word_length = word_length / 2; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 400 | |
Ondrej Zary | e161a44 | 2011-07-01 00:03:57 +0200 | [diff] [blame] | 401 | for (; word_length > 0; word_length--) { /* In words */ |
| 402 | templong = *pUsFile++; |
| 403 | templong |= |
| 404 | (*pUsFile++ << 16); |
| 405 | pUcFile += 4; |
| 406 | outl(templong, |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 407 | dev->base_addr + |
| 408 | FT1000_REG_MAG_DPDATAL); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 409 | } |
| 410 | spin_unlock_irqrestore(&info-> |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 411 | dpram_lock, |
| 412 | flags); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 413 | break; |
| 414 | default: |
| 415 | Status = FAILURE; |
| 416 | break; |
| 417 | } |
| 418 | put_handshake(dev, HANDSHAKE_RESPONSE); |
| 419 | } else { |
| 420 | Status = FAILURE; |
| 421 | } |
| 422 | |
| 423 | break; |
| 424 | |
| 425 | case STATE_CODE_DWNLD: |
| 426 | handshake = get_handshake(dev, HANDSHAKE_REQUEST); |
| 427 | if (handshake == HANDSHAKE_REQUEST) { |
| 428 | /* |
| 429 | * Get type associated with the request. |
| 430 | */ |
| 431 | request = get_request_type(dev); |
| 432 | switch (request) { |
| 433 | case REQUEST_FILE_CHECKSUM: |
Catalina Mocanu | 8f3a2e0 | 2014-09-22 15:14:18 -0700 | [diff] [blame] | 434 | netdev_dbg(dev, |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 435 | "ft1000_dnld: REQUEST_FOR_CHECKSUM\n"); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 436 | put_request_value(dev, image_chksum); |
| 437 | break; |
| 438 | case REQUEST_RUN_ADDRESS: |
| 439 | if (bGoodVersion) { |
| 440 | put_request_value(dev, |
| 441 | run_address); |
| 442 | } else { |
| 443 | Status = FAILURE; |
| 444 | break; |
| 445 | } |
| 446 | break; |
| 447 | case REQUEST_CODE_LENGTH: |
| 448 | if (bGoodVersion) { |
| 449 | put_request_value(dev, |
| 450 | run_size); |
| 451 | } else { |
| 452 | Status = FAILURE; |
| 453 | break; |
| 454 | } |
| 455 | break; |
| 456 | case REQUEST_DONE_CL: |
| 457 | /* Reposition ptrs to beginning of provisioning section */ |
Ondrej Zary | e161a44 | 2011-07-01 00:03:57 +0200 | [diff] [blame] | 458 | pUsFile = (u16 *) ((long)pFileStart + pFileHdr5->commands_offset); |
| 459 | pUcFile = (u8 *) ((long)pFileStart + pFileHdr5->commands_offset); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 460 | uiState = STATE_DONE_DWNLD; |
| 461 | break; |
| 462 | case REQUEST_CODE_SEGMENT: |
| 463 | if (!bGoodVersion) { |
| 464 | Status = FAILURE; |
| 465 | break; |
| 466 | } |
| 467 | word_length = get_request_value(dev); |
| 468 | if (word_length > MAX_LENGTH) { |
| 469 | Status = FAILURE; |
| 470 | break; |
| 471 | } |
| 472 | if ((word_length * 2 + (long)pUcFile) > |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 473 | (long)pCodeEnd) { |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 474 | /* |
| 475 | * Error, beyond boot code range. |
| 476 | */ |
| 477 | Status = FAILURE; |
| 478 | break; |
| 479 | } |
Ondrej Zary | e161a44 | 2011-07-01 00:03:57 +0200 | [diff] [blame] | 480 | /* |
| 481 | * Position ASIC DPRAM auto-increment pointer. |
| 482 | */ |
| 483 | outw(DWNLD_MAG_PS_HDR_LOC, |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 484 | dev->base_addr + |
| 485 | FT1000_REG_DPRAM_ADDR); |
Ondrej Zary | e161a44 | 2011-07-01 00:03:57 +0200 | [diff] [blame] | 486 | if (word_length & 0x01) |
| 487 | word_length++; |
| 488 | word_length = word_length / 2; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 489 | |
Ondrej Zary | e161a44 | 2011-07-01 00:03:57 +0200 | [diff] [blame] | 490 | for (; word_length > 0; word_length--) { /* In words */ |
| 491 | templong = *pUsFile++; |
| 492 | templong |= |
| 493 | (*pUsFile++ << 16); |
| 494 | pUcFile += 4; |
| 495 | outl(templong, |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 496 | dev->base_addr + |
| 497 | FT1000_REG_MAG_DPDATAL); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 498 | } |
| 499 | break; |
| 500 | |
| 501 | case REQUEST_MAILBOX_DATA: |
Dylan Socolobsky | 8671438 | 2013-05-13 19:47:33 -0300 | [diff] [blame] | 502 | /* Convert length from byte count to word count. Make sure we round up. */ |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 503 | word_length = |
| 504 | (long)(info->DSPInfoBlklen + 1) / 2; |
| 505 | put_request_value(dev, word_length); |
| 506 | pMailBoxData = |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 507 | (struct drv_msg *)&info->DSPInfoBlk[0]; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 508 | pUsData = |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 509 | (u16 *)&pMailBoxData->data[0]; |
Dylan Socolobsky | 8671438 | 2013-05-13 19:47:33 -0300 | [diff] [blame] | 510 | /* Provide mutual exclusive access while reading ASIC registers. */ |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 511 | spin_lock_irqsave(&info->dpram_lock, |
| 512 | flags); |
| 513 | if (file_version == 5) { |
| 514 | /* |
| 515 | * Position ASIC DPRAM auto-increment pointer. |
| 516 | */ |
| 517 | ft1000_write_reg(dev, |
| 518 | FT1000_REG_DPRAM_ADDR, |
| 519 | DWNLD_PS_HDR_LOC); |
| 520 | |
| 521 | for (; word_length > 0; word_length--) { /* In words */ |
| 522 | temp = ntohs(*pUsData); |
| 523 | ft1000_write_reg(dev, |
| 524 | FT1000_REG_DPRAM_DATA, |
| 525 | temp); |
| 526 | pUsData++; |
| 527 | } |
| 528 | } else { |
| 529 | /* |
| 530 | * Position ASIC DPRAM auto-increment pointer. |
| 531 | */ |
| 532 | outw(DWNLD_MAG_PS_HDR_LOC, |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 533 | dev->base_addr + |
| 534 | FT1000_REG_DPRAM_ADDR); |
Dylan Socolobsky | 6fb3c2b | 2013-05-13 19:42:28 -0300 | [diff] [blame] | 535 | if (word_length & 0x01) |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 536 | word_length++; |
Dylan Socolobsky | 6fb3c2b | 2013-05-13 19:42:28 -0300 | [diff] [blame] | 537 | |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 538 | word_length = word_length / 2; |
| 539 | |
| 540 | for (; word_length > 0; word_length--) { /* In words */ |
| 541 | templong = *pUsData++; |
| 542 | templong |= |
| 543 | (*pUsData++ << 16); |
| 544 | outl(templong, |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 545 | dev->base_addr + |
| 546 | FT1000_REG_MAG_DPDATAL); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 547 | } |
| 548 | } |
| 549 | spin_unlock_irqrestore(&info-> |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 550 | dpram_lock, |
| 551 | flags); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 552 | break; |
| 553 | |
| 554 | case REQUEST_VERSION_INFO: |
| 555 | word_length = |
| 556 | pFileHdr5->version_data_size; |
| 557 | put_request_value(dev, word_length); |
| 558 | pUsFile = |
Ondrej Zary | ca14527 | 2011-07-01 00:03:47 +0200 | [diff] [blame] | 559 | (u16 *) ((long)pFileStart + |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 560 | pFileHdr5-> |
| 561 | version_data_offset); |
Dylan Socolobsky | 8671438 | 2013-05-13 19:47:33 -0300 | [diff] [blame] | 562 | /* Provide mutual exclusive access while reading ASIC registers. */ |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 563 | spin_lock_irqsave(&info->dpram_lock, |
| 564 | flags); |
Ondrej Zary | e161a44 | 2011-07-01 00:03:57 +0200 | [diff] [blame] | 565 | /* |
| 566 | * Position ASIC DPRAM auto-increment pointer. |
| 567 | */ |
| 568 | outw(DWNLD_MAG_PS_HDR_LOC, |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 569 | dev->base_addr + |
| 570 | FT1000_REG_DPRAM_ADDR); |
Ondrej Zary | e161a44 | 2011-07-01 00:03:57 +0200 | [diff] [blame] | 571 | if (word_length & 0x01) |
| 572 | word_length++; |
| 573 | word_length = word_length / 2; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 574 | |
Ondrej Zary | e161a44 | 2011-07-01 00:03:57 +0200 | [diff] [blame] | 575 | for (; word_length > 0; word_length--) { /* In words */ |
| 576 | templong = |
| 577 | ntohs(*pUsFile++); |
| 578 | temp = |
| 579 | ntohs(*pUsFile++); |
| 580 | templong |= |
| 581 | (temp << 16); |
| 582 | outl(templong, |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 583 | dev->base_addr + |
| 584 | FT1000_REG_MAG_DPDATAL); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 585 | } |
| 586 | spin_unlock_irqrestore(&info-> |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 587 | dpram_lock, |
| 588 | flags); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 589 | break; |
| 590 | |
| 591 | case REQUEST_CODE_BY_VERSION: |
Ondrej Zary | ca14527 | 2011-07-01 00:03:47 +0200 | [diff] [blame] | 592 | bGoodVersion = false; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 593 | requested_version = |
| 594 | get_request_value(dev); |
Ondrej Zary | e161a44 | 2011-07-01 00:03:57 +0200 | [diff] [blame] | 595 | pDspImageInfoV6 = |
| 596 | (struct dsp_image_info *) ((long) |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 597 | pFileStart |
| 598 | + |
| 599 | sizeof |
| 600 | (struct dsp_file_hdr)); |
Ondrej Zary | e161a44 | 2011-07-01 00:03:57 +0200 | [diff] [blame] | 601 | for (imageN = 0; |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 602 | imageN < |
| 603 | pFileHdr5->nDspImages; |
| 604 | imageN++) { |
Ondrej Zary | e161a44 | 2011-07-01 00:03:57 +0200 | [diff] [blame] | 605 | temp = (u16) |
| 606 | (pDspImageInfoV6-> |
| 607 | version); |
| 608 | templong = temp; |
| 609 | temp = (u16) |
| 610 | (pDspImageInfoV6-> |
| 611 | version >> 16); |
| 612 | templong |= |
| 613 | (temp << 16); |
| 614 | if (templong == |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 615 | requested_version) { |
Ondrej Zary | e161a44 | 2011-07-01 00:03:57 +0200 | [diff] [blame] | 616 | bGoodVersion = |
| 617 | true; |
| 618 | pUsFile = |
| 619 | (u16 |
| 620 | *) ((long) |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 621 | pFileStart |
| 622 | + |
| 623 | pDspImageInfoV6-> |
| 624 | begin_offset); |
Ondrej Zary | e161a44 | 2011-07-01 00:03:57 +0200 | [diff] [blame] | 625 | pUcFile = |
| 626 | (u8 |
| 627 | *) ((long) |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 628 | pFileStart |
| 629 | + |
| 630 | pDspImageInfoV6-> |
| 631 | begin_offset); |
Ondrej Zary | e161a44 | 2011-07-01 00:03:57 +0200 | [diff] [blame] | 632 | pCodeEnd = |
| 633 | (u8 |
| 634 | *) ((long) |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 635 | pFileStart |
| 636 | + |
| 637 | pDspImageInfoV6-> |
| 638 | end_offset); |
Ondrej Zary | e161a44 | 2011-07-01 00:03:57 +0200 | [diff] [blame] | 639 | run_address = |
| 640 | pDspImageInfoV6-> |
| 641 | run_address; |
| 642 | run_size = |
| 643 | pDspImageInfoV6-> |
| 644 | image_size; |
| 645 | image_chksum = |
| 646 | (u32) |
| 647 | pDspImageInfoV6-> |
| 648 | checksum; |
Catalina Mocanu | 8f3a2e0 | 2014-09-22 15:14:18 -0700 | [diff] [blame] | 649 | netdev_dbg(dev, |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 650 | "ft1000_dnld: image_chksum = 0x%8x\n", |
| 651 | (unsigned |
| 652 | int) |
| 653 | image_chksum); |
Ondrej Zary | e161a44 | 2011-07-01 00:03:57 +0200 | [diff] [blame] | 654 | break; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 655 | } |
Ondrej Zary | e161a44 | 2011-07-01 00:03:57 +0200 | [diff] [blame] | 656 | pDspImageInfoV6++; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 657 | } |
| 658 | if (!bGoodVersion) { |
| 659 | /* |
| 660 | * Error, beyond boot code range. |
| 661 | */ |
| 662 | Status = FAILURE; |
| 663 | break; |
| 664 | } |
| 665 | break; |
| 666 | |
| 667 | default: |
| 668 | Status = FAILURE; |
| 669 | break; |
| 670 | } |
| 671 | put_handshake(dev, HANDSHAKE_RESPONSE); |
| 672 | } else { |
| 673 | Status = FAILURE; |
| 674 | } |
| 675 | |
| 676 | break; |
| 677 | |
| 678 | case STATE_DONE_DWNLD: |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 679 | if (((unsigned long)(pUcFile) - (unsigned long) pFileStart) >= |
| 680 | (unsigned long)FileLength) { |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 681 | uiState = STATE_DONE_FILE; |
| 682 | break; |
| 683 | } |
| 684 | |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 685 | pHdr = (struct pseudo_hdr *)pUsFile; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 686 | |
| 687 | if (pHdr->portdest == 0x80 /* DspOAM */ |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 688 | && (pHdr->portsrc == 0x00 /* Driver */ |
Aldo Iljazi | 2dad6e4 | 2013-06-06 22:52:12 +0300 | [diff] [blame] | 689 | || pHdr->portsrc == 0x10 /* FMM */)) { |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 690 | uiState = STATE_SECTION_PROV; |
| 691 | } else { |
Catalina Mocanu | 8f3a2e0 | 2014-09-22 15:14:18 -0700 | [diff] [blame] | 692 | netdev_dbg(dev, |
Joe Perches | b5d8204 | 2014-11-03 16:25:44 -0800 | [diff] [blame] | 693 | "Download error: Bad Port IDs in Pseudo Record\n"); |
Catalina Mocanu | 8f3a2e0 | 2014-09-22 15:14:18 -0700 | [diff] [blame] | 694 | netdev_dbg(dev, "\t Port Source = 0x%2.2x\n", |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 695 | pHdr->portsrc); |
Catalina Mocanu | 8f3a2e0 | 2014-09-22 15:14:18 -0700 | [diff] [blame] | 696 | netdev_dbg(dev, "\t Port Destination = 0x%2.2x\n", |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 697 | pHdr->portdest); |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 698 | Status = FAILURE; |
| 699 | } |
| 700 | |
| 701 | break; |
| 702 | |
| 703 | case STATE_SECTION_PROV: |
| 704 | |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 705 | pHdr = (struct pseudo_hdr *)pUcFile; |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 706 | |
| 707 | if (pHdr->checksum == hdr_checksum(pHdr)) { |
Aldo Iljazi | 2dad6e4 | 2013-06-06 22:52:12 +0300 | [diff] [blame] | 708 | if (pHdr->portdest != 0x80 /* Dsp OAM */) { |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 709 | uiState = STATE_DONE_PROV; |
| 710 | break; |
| 711 | } |
| 712 | usHdrLength = ntohs(pHdr->length); /* Byte length for PROV records */ |
| 713 | |
Dylan Socolobsky | 8671438 | 2013-05-13 19:47:33 -0300 | [diff] [blame] | 714 | /* Get buffer for provisioning data */ |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 715 | pbuffer = |
Aya Mahfouz | 08a02cb | 2015-03-10 19:00:53 +0200 | [diff] [blame] | 716 | kmalloc(usHdrLength + sizeof(struct pseudo_hdr), |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 717 | GFP_ATOMIC); |
| 718 | if (pbuffer) { |
Aya Mahfouz | 08a02cb | 2015-03-10 19:00:53 +0200 | [diff] [blame] | 719 | memcpy(pbuffer, pUcFile, |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 720 | (u32) (usHdrLength + |
| 721 | sizeof(struct pseudo_hdr))); |
Dylan Socolobsky | 8671438 | 2013-05-13 19:47:33 -0300 | [diff] [blame] | 722 | /* link provisioning data */ |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 723 | pprov_record = |
Ondrej Zary | 3aaf807 | 2011-07-01 00:03:41 +0200 | [diff] [blame] | 724 | kmalloc(sizeof(struct prov_record), |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 725 | GFP_ATOMIC); |
| 726 | if (pprov_record) { |
| 727 | pprov_record->pprov_data = |
| 728 | pbuffer; |
| 729 | list_add_tail(&pprov_record-> |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 730 | list, |
| 731 | &info->prov_list); |
Dylan Socolobsky | 8671438 | 2013-05-13 19:47:33 -0300 | [diff] [blame] | 732 | /* Move to next entry if available */ |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 733 | pUcFile = |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 734 | (u8 *)((unsigned long) pUcFile + |
| 735 | (unsigned long) ((usHdrLength + 1) & 0xFFFFFFFE) + sizeof(struct pseudo_hdr)); |
pixo | 14e5d8e | 2011-03-23 08:08:08 +0100 | [diff] [blame] | 736 | if ((unsigned long) (pUcFile) - |
Joe Perches | ecdd21c | 2014-11-03 16:25:43 -0800 | [diff] [blame] | 737 | (unsigned long) (pFileStart) >= |
| 738 | (unsigned long)FileLength) { |
Marek Belisko | f7c1be0 | 2010-09-22 07:56:27 +0200 | [diff] [blame] | 739 | uiState = |
| 740 | STATE_DONE_FILE; |
| 741 | } |
| 742 | } else { |
| 743 | kfree(pbuffer); |
| 744 | Status = FAILURE; |
| 745 | } |
| 746 | } else { |
| 747 | Status = FAILURE; |
| 748 | } |
| 749 | } else { |
| 750 | /* Checksum did not compute */ |
| 751 | Status = FAILURE; |
| 752 | } |
| 753 | |
| 754 | break; |
| 755 | |
| 756 | case STATE_DONE_PROV: |
| 757 | uiState = STATE_DONE_FILE; |
| 758 | break; |
| 759 | |
| 760 | default: |
| 761 | Status = FAILURE; |
| 762 | break; |
| 763 | } /* End Switch */ |
| 764 | |
| 765 | } /* End while */ |
| 766 | |
| 767 | return Status; |
| 768 | |
| 769 | } |