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