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; |
Lisa Nguyen | 2fef7e1 | 2013-10-29 14:19:50 -0700 | [diff] [blame] | 9 | struct bcm_interface_adapter *psIntfAdapter = 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) { |
Gokulnath A | 8f5157b | 2013-12-18 23:12:37 +0530 | [diff] [blame] | 23 | if (len < 0) |
Marcos Paulo de Souza | 43664e1 | 2011-09-23 00:20:09 -0300 | [diff] [blame] | 24 | errno = len; |
Gokulnath A | 8f5157b | 2013-12-18 23:12:37 +0530 | [diff] [blame] | 25 | else |
Marcos Paulo de Souza | 43664e1 | 2011-09-23 00:20:09 -0300 | [diff] [blame] | 26 | errno = 0; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 27 | break; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 28 | } |
Marcos Paulo de Souza | 43664e1 | 2011-09-23 00:20:09 -0300 | [diff] [blame] | 29 | /* BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_INITEXIT, MP_INIT, |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 30 | * DBG_LVL_ALL, buff, |
| 31 | * MAX_TRANSFER_CTRL_BYTE_USB); |
| 32 | */ |
Marcos Paulo de Souza | 43664e1 | 2011-09-23 00:20:09 -0300 | [diff] [blame] | 33 | errno = InterfaceWRM(psIntfAdapter, on_chip_loc, buff, len); |
Gokulnath A | 8f5157b | 2013-12-18 23:12:37 +0530 | [diff] [blame] | 34 | if (errno) |
Marcos Paulo de Souza | 43664e1 | 2011-09-23 00:20:09 -0300 | [diff] [blame] | 35 | break; |
Marcos Paulo de Souza | 43664e1 | 2011-09-23 00:20:09 -0300 | [diff] [blame] | 36 | on_chip_loc += MAX_TRANSFER_CTRL_BYTE_USB; |
| 37 | } |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 38 | |
Stephen Hemminger | 082e889 | 2010-11-01 09:35:21 -0400 | [diff] [blame] | 39 | kfree(buff); |
Marcos Paulo de Souza | 43664e1 | 2011-09-23 00:20:09 -0300 | [diff] [blame] | 40 | return errno; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 41 | } |
| 42 | |
Gokulnath A | b3a5388 | 2013-12-18 23:12:38 +0530 | [diff] [blame] | 43 | int InterfaceFileReadbackFromChip(PVOID arg, struct file *flp, |
| 44 | unsigned int on_chip_loc) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 45 | { |
Marcos Paulo de Souza | 43664e1 | 2011-09-23 00:20:09 -0300 | [diff] [blame] | 46 | char *buff, *buff_readback; |
| 47 | unsigned int reg = 0; |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 48 | mm_segment_t oldfs = {0}; |
| 49 | int errno = 0, len = 0, is_config_file = 0; |
| 50 | loff_t pos = 0; |
Kevin McKinney | a865818 | 2011-10-20 08:15:23 -0400 | [diff] [blame] | 51 | static int fw_down; |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 52 | INT Status = STATUS_SUCCESS; |
Lisa Nguyen | 2fef7e1 | 2013-10-29 14:19:50 -0700 | [diff] [blame] | 53 | struct bcm_interface_adapter *psIntfAdapter = arg; |
Kevin McKinney | 41c7b7c | 2011-11-06 09:40:11 -0500 | [diff] [blame] | 54 | int bytes; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 55 | |
Daeseok Youn | 87755c0 | 2014-05-07 15:01:04 +0900 | [diff] [blame] | 56 | buff = kzalloc(MAX_TRANSFER_CTRL_BYTE_USB, GFP_DMA); |
| 57 | buff_readback = kzalloc(MAX_TRANSFER_CTRL_BYTE_USB , GFP_DMA); |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 58 | if (!buff || !buff_readback) { |
| 59 | kfree(buff); |
| 60 | kfree(buff_readback); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 61 | |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 62 | return -ENOMEM; |
| 63 | } |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 64 | |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 65 | is_config_file = (on_chip_loc == CONFIG_BEGIN_ADDR) ? 1 : 0; |
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 | while (1) { |
| 68 | oldfs = get_fs(); |
| 69 | set_fs(get_ds()); |
Gokulnath A | b3a5388 | 2013-12-18 23:12:38 +0530 | [diff] [blame] | 70 | len = vfs_read(flp, (void __force __user *)buff, |
| 71 | MAX_TRANSFER_CTRL_BYTE_USB, &pos); |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 72 | set_fs(oldfs); |
| 73 | fw_down++; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 74 | |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 75 | if (len <= 0) { |
Gokulnath A | 8f5157b | 2013-12-18 23:12:37 +0530 | [diff] [blame] | 76 | if (len < 0) |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 77 | errno = len; |
Gokulnath A | 8f5157b | 2013-12-18 23:12:37 +0530 | [diff] [blame] | 78 | else |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 79 | errno = 0; |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 80 | break; |
| 81 | } |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 82 | |
Gokulnath A | b3a5388 | 2013-12-18 23:12:38 +0530 | [diff] [blame] | 83 | bytes = InterfaceRDM(psIntfAdapter, on_chip_loc, |
| 84 | buff_readback, len); |
Kevin McKinney | 41c7b7c | 2011-11-06 09:40:11 -0500 | [diff] [blame] | 85 | if (bytes < 0) { |
| 86 | Status = bytes; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 87 | goto exit; |
| 88 | } |
| 89 | reg++; |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 90 | if ((len-sizeof(unsigned int)) < 4) { |
| 91 | if (memcmp(buff_readback, buff, len)) { |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 92 | Status = -EIO; |
| 93 | goto exit; |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 94 | } |
| 95 | } else { |
| 96 | len -= 4; |
| 97 | |
| 98 | while (len) { |
Gokulnath A | b3a5388 | 2013-12-18 23:12:38 +0530 | [diff] [blame] | 99 | if (*(unsigned int *)&buff_readback[len] != |
| 100 | *(unsigned int *)&buff[len]) { |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 101 | Status = -EIO; |
| 102 | goto exit; |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 103 | } |
| 104 | len -= 4; |
| 105 | } |
| 106 | } |
| 107 | on_chip_loc += MAX_TRANSFER_CTRL_BYTE_USB; |
| 108 | } /* End of while(1) */ |
| 109 | |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 110 | exit: |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 111 | kfree(buff); |
| 112 | kfree(buff_readback); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 113 | return Status; |
| 114 | } |
| 115 | |
Gokulnath A | b3a5388 | 2013-12-18 23:12:38 +0530 | [diff] [blame] | 116 | static int bcm_download_config_file(struct bcm_mini_adapter *Adapter, |
| 117 | struct bcm_firmware_info *psFwInfo) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 118 | { |
| 119 | int retval = STATUS_SUCCESS; |
| 120 | B_UINT32 value = 0; |
| 121 | |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 122 | if (Adapter->pstargetparams == NULL) { |
Gokulnath A | b3a5388 | 2013-12-18 23:12:38 +0530 | [diff] [blame] | 123 | Adapter->pstargetparams = |
| 124 | kmalloc(sizeof(struct bcm_target_params), GFP_KERNEL); |
Kevin McKinney | a865818 | 2011-10-20 08:15:23 -0400 | [diff] [blame] | 125 | if (Adapter->pstargetparams == NULL) |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 126 | return -ENOMEM; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 127 | } |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 128 | |
Kevin McKinney | c818233 | 2012-12-17 17:35:20 -0500 | [diff] [blame] | 129 | if (psFwInfo->u32FirmwareLength != sizeof(struct bcm_target_params)) |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 130 | return -EIO; |
| 131 | |
Gokulnath A | b3a5388 | 2013-12-18 23:12:38 +0530 | [diff] [blame] | 132 | retval = copy_from_user(Adapter->pstargetparams, |
| 133 | psFwInfo->pvMappedFirmwareAddress, |
| 134 | psFwInfo->u32FirmwareLength); |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 135 | if (retval) { |
Stephen Hemminger | 082e889 | 2010-11-01 09:35:21 -0400 | [diff] [blame] | 136 | kfree(Adapter->pstargetparams); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 137 | Adapter->pstargetparams = NULL; |
Dan Carpenter | ef5d205 | 2010-10-08 14:56:58 +0200 | [diff] [blame] | 138 | return -EFAULT; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 139 | } |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 140 | |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 141 | /* Parse the structure and then Download the Firmware */ |
| 142 | beceem_parse_target_struct(Adapter); |
| 143 | |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 144 | /* Initializing the NVM. */ |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 145 | BcmInitNVM(Adapter); |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 146 | retval = InitLedSettings(Adapter); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 147 | |
Gokulnath A | 8f5157b | 2013-12-18 23:12:37 +0530 | [diff] [blame] | 148 | if (retval) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 149 | return retval; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 150 | |
Gokulnath A | b3a5388 | 2013-12-18 23:12:38 +0530 | [diff] [blame] | 151 | if (Adapter->LEDInfo.led_thread_running & |
| 152 | BCM_LED_THREAD_RUNNING_ACTIVELY) { |
Lisa Nguyen | f70c8a9 | 2013-10-28 01:36:19 -0700 | [diff] [blame] | 153 | Adapter->LEDInfo.bLedInitDone = false; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 154 | Adapter->DriverState = DRIVER_INIT; |
| 155 | wake_up(&Adapter->LEDInfo.notify_led_event); |
| 156 | } |
| 157 | |
Gokulnath A | b3a5388 | 2013-12-18 23:12:38 +0530 | [diff] [blame] | 158 | if (Adapter->LEDInfo.led_thread_running & |
| 159 | BCM_LED_THREAD_RUNNING_ACTIVELY) { |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 160 | Adapter->DriverState = FW_DOWNLOAD; |
| 161 | wake_up(&Adapter->LEDInfo.notify_led_event); |
| 162 | } |
| 163 | |
| 164 | /* Initialize the DDR Controller */ |
| 165 | retval = ddr_init(Adapter); |
Gokulnath A | 8f5157b | 2013-12-18 23:12:37 +0530 | [diff] [blame] | 166 | if (retval) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 167 | return retval; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 168 | |
| 169 | value = 0; |
Gokulnath A | b3a5388 | 2013-12-18 23:12:38 +0530 | [diff] [blame] | 170 | wrmalt(Adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 4, |
| 171 | &value, sizeof(value)); |
| 172 | wrmalt(Adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 8, |
| 173 | &value, sizeof(value)); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 174 | |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 175 | if (Adapter->eNVMType == NVM_FLASH) { |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 176 | retval = PropagateCalParamsFromFlashToMemory(Adapter); |
Gokulnath A | 8f5157b | 2013-12-18 23:12:37 +0530 | [diff] [blame] | 177 | if (retval) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 178 | return retval; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Gokulnath A | b3a5388 | 2013-12-18 23:12:38 +0530 | [diff] [blame] | 181 | retval = buffDnldVerify(Adapter, (PUCHAR)Adapter->pstargetparams, |
| 182 | sizeof(struct bcm_target_params), CONFIG_BEGIN_ADDR); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 183 | |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 184 | if (retval) |
Gokulnath A | b3a5388 | 2013-12-18 23:12:38 +0530 | [diff] [blame] | 185 | BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, |
| 186 | MP_INIT, DBG_LVL_ALL, |
| 187 | "configuration file not downloaded properly"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 188 | else |
| 189 | Adapter->bCfgDownloaded = TRUE; |
| 190 | |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 191 | return retval; |
| 192 | } |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 193 | |
Gokulnath A | b3a5388 | 2013-12-18 23:12:38 +0530 | [diff] [blame] | 194 | int bcm_ioctl_fw_download(struct bcm_mini_adapter *Adapter, |
| 195 | struct bcm_firmware_info *psFwInfo) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 196 | { |
| 197 | int retval = STATUS_SUCCESS; |
| 198 | PUCHAR buff = NULL; |
| 199 | |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 200 | /* Config File is needed for the Driver to download the Config file and |
| 201 | * Firmware. Check for the Config file to be first to be sent from the |
| 202 | * Application |
| 203 | */ |
Lisa Nguyen | f70c8a9 | 2013-10-28 01:36:19 -0700 | [diff] [blame] | 204 | atomic_set(&Adapter->uiMBupdate, false); |
Gokulnath A | b3a5388 | 2013-12-18 23:12:38 +0530 | [diff] [blame] | 205 | if (!Adapter->bCfgDownloaded && |
| 206 | psFwInfo->u32StartingAddress != CONFIG_BEGIN_ADDR) { |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 207 | /* Can't Download Firmware. */ |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 208 | return -EINVAL; |
| 209 | } |
| 210 | |
| 211 | /* If Config File, Finish the DDR Settings and then Download CFG File */ |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 212 | if (psFwInfo->u32StartingAddress == CONFIG_BEGIN_ADDR) { |
| 213 | retval = bcm_download_config_file(Adapter, psFwInfo); |
| 214 | } else { |
| 215 | buff = kzalloc(psFwInfo->u32FirmwareLength, GFP_KERNEL); |
Gokulnath A | 8f5157b | 2013-12-18 23:12:37 +0530 | [diff] [blame] | 216 | if (buff == NULL) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 217 | return -ENOMEM; |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 218 | |
Gokulnath A | b3a5388 | 2013-12-18 23:12:38 +0530 | [diff] [blame] | 219 | retval = copy_from_user(buff, |
| 220 | psFwInfo->pvMappedFirmwareAddress, |
| 221 | psFwInfo->u32FirmwareLength); |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 222 | if (retval != STATUS_SUCCESS) { |
Dan Carpenter | ef5d205 | 2010-10-08 14:56:58 +0200 | [diff] [blame] | 223 | retval = -EFAULT; |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 224 | goto error; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 227 | retval = buffDnldVerify(Adapter, |
| 228 | buff, |
| 229 | psFwInfo->u32FirmwareLength, |
| 230 | psFwInfo->u32StartingAddress); |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 231 | |
Gokulnath A | 8f5157b | 2013-12-18 23:12:37 +0530 | [diff] [blame] | 232 | if (retval != STATUS_SUCCESS) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 233 | goto error; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 234 | } |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 235 | |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 236 | error: |
Stephen Hemminger | 082e889 | 2010-11-01 09:35:21 -0400 | [diff] [blame] | 237 | kfree(buff); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 238 | return retval; |
| 239 | } |
| 240 | |
Gokulnath A | b3a5388 | 2013-12-18 23:12:38 +0530 | [diff] [blame] | 241 | static INT buffDnld(struct bcm_mini_adapter *Adapter, |
| 242 | PUCHAR mappedbuffer, UINT u32FirmwareLength, |
| 243 | ULONG u32StartingAddress) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 244 | { |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 245 | unsigned int len = 0; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 246 | int retval = STATUS_SUCCESS; |
Pawel Lebioda | 89fa037 | 2014-07-09 17:59:29 +0200 | [diff] [blame] | 247 | |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 248 | len = u32FirmwareLength; |
| 249 | |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 250 | while (u32FirmwareLength) { |
| 251 | len = MIN_VAL(u32FirmwareLength, MAX_TRANSFER_CTRL_BYTE_USB); |
| 252 | retval = wrm(Adapter, u32StartingAddress, mappedbuffer, len); |
| 253 | |
Gokulnath A | 8f5157b | 2013-12-18 23:12:37 +0530 | [diff] [blame] | 254 | if (retval) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 255 | break; |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 256 | u32StartingAddress += len; |
| 257 | u32FirmwareLength -= len; |
| 258 | mappedbuffer += len; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 259 | } |
| 260 | return retval; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Gokulnath A | b3a5388 | 2013-12-18 23:12:38 +0530 | [diff] [blame] | 263 | static INT buffRdbkVerify(struct bcm_mini_adapter *Adapter, |
| 264 | PUCHAR mappedbuffer, UINT u32FirmwareLength, |
| 265 | ULONG u32StartingAddress) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 266 | { |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 267 | UINT len = u32FirmwareLength; |
| 268 | INT retval = STATUS_SUCCESS; |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 269 | PUCHAR readbackbuff = kzalloc(MAX_TRANSFER_CTRL_BYTE_USB, GFP_KERNEL); |
Kevin McKinney | 41c7b7c | 2011-11-06 09:40:11 -0500 | [diff] [blame] | 270 | int bytes; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 271 | |
Gokulnath A | 8f5157b | 2013-12-18 23:12:37 +0530 | [diff] [blame] | 272 | if (NULL == readbackbuff) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 273 | return -ENOMEM; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 274 | |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 275 | while (u32FirmwareLength && !retval) { |
| 276 | len = MIN_VAL(u32FirmwareLength, MAX_TRANSFER_CTRL_BYTE_USB); |
Kevin McKinney | 41c7b7c | 2011-11-06 09:40:11 -0500 | [diff] [blame] | 277 | bytes = rdm(Adapter, u32StartingAddress, readbackbuff, len); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 278 | |
Kevin McKinney | 41c7b7c | 2011-11-06 09:40:11 -0500 | [diff] [blame] | 279 | if (bytes < 0) { |
| 280 | retval = bytes; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 281 | break; |
| 282 | } |
| 283 | |
Dan Carpenter | 2c5270a | 2013-03-01 23:28:06 +0300 | [diff] [blame] | 284 | if (memcmp(readbackbuff, mappedbuffer, len) != 0) { |
| 285 | pr_err("%s() failed. The firmware doesn't match what was written", |
| 286 | __func__); |
| 287 | retval = -EIO; |
| 288 | } |
Kevin McKinney | a5e4b81 | 2011-10-20 08:15:22 -0400 | [diff] [blame] | 289 | |
| 290 | u32StartingAddress += len; |
| 291 | u32FirmwareLength -= len; |
| 292 | mappedbuffer += len; |
| 293 | |
| 294 | } /* end of while (u32FirmwareLength && !retval) */ |
Stephen Hemminger | 082e889 | 2010-11-01 09:35:21 -0400 | [diff] [blame] | 295 | kfree(readbackbuff); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 296 | return retval; |
| 297 | } |
| 298 | |
Gokulnath A | b3a5388 | 2013-12-18 23:12:38 +0530 | [diff] [blame] | 299 | INT buffDnldVerify(struct bcm_mini_adapter *Adapter, |
| 300 | unsigned char *mappedbuffer, |
| 301 | unsigned int u32FirmwareLength, |
| 302 | unsigned long u32StartingAddress) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 303 | { |
| 304 | INT status = STATUS_SUCCESS; |
| 305 | |
Gokulnath A | b3a5388 | 2013-12-18 23:12:38 +0530 | [diff] [blame] | 306 | status = buffDnld(Adapter, mappedbuffer, |
| 307 | u32FirmwareLength, u32StartingAddress); |
Gokulnath A | 8f5157b | 2013-12-18 23:12:37 +0530 | [diff] [blame] | 308 | if (status != STATUS_SUCCESS) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 309 | goto error; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 310 | |
Gokulnath A | b3a5388 | 2013-12-18 23:12:38 +0530 | [diff] [blame] | 311 | status = buffRdbkVerify(Adapter, mappedbuffer, |
| 312 | u32FirmwareLength, u32StartingAddress); |
Gokulnath A | 8f5157b | 2013-12-18 23:12:37 +0530 | [diff] [blame] | 313 | if (status != STATUS_SUCCESS) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 314 | goto error; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 315 | error: |
| 316 | return status; |
| 317 | } |