Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * |
| 20 | * File: baseband.c |
| 21 | * |
| 22 | * Purpose: Implement functions to access baseband |
| 23 | * |
| 24 | * Author: Yiching Chen |
| 25 | * |
| 26 | * Date: May 20, 2004 |
| 27 | * |
| 28 | * Functions: |
| 29 | * |
| 30 | * Revision History: |
| 31 | * |
| 32 | */ |
| 33 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 34 | #include "firmware.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 35 | #include "control.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 36 | #include "rndis.h" |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 37 | |
| 38 | /*--------------------- Static Definitions -------------------------*/ |
| 39 | |
| 40 | static int msglevel =MSG_LEVEL_INFO; |
| 41 | //static int msglevel =MSG_LEVEL_DEBUG; |
Ben Hutchings | 31d5bbf | 2011-01-09 04:16:48 +0000 | [diff] [blame^] | 42 | |
| 43 | #define FIRMWARE_VERSION 0x133 /* version 1.51 */ |
| 44 | #define FIRMWARE_NAME "vntwusb.fw" |
| 45 | |
| 46 | #define FIRMWARE_CHUNK_SIZE 0x400 |
| 47 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 48 | /*--------------------- Static Classes ----------------------------*/ |
| 49 | |
| 50 | /*--------------------- Static Variables --------------------------*/ |
| 51 | |
| 52 | /*--------------------- Static Functions --------------------------*/ |
| 53 | |
| 54 | /*--------------------- Export Variables --------------------------*/ |
| 55 | |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 56 | /*--------------------- Export Functions --------------------------*/ |
| 57 | |
| 58 | |
Jim Lieb | 193a823 | 2009-08-12 14:54:06 -0700 | [diff] [blame] | 59 | BOOL |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 60 | FIRMWAREbDownload( |
Andres More | 592ccfe | 2010-04-17 12:07:42 -0300 | [diff] [blame] | 61 | PSDevice pDevice |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 62 | ) |
| 63 | { |
Ben Hutchings | 31d5bbf | 2011-01-09 04:16:48 +0000 | [diff] [blame^] | 64 | const struct firmware *fw; |
| 65 | int NdisStatus; |
| 66 | void *pBuffer = NULL; |
| 67 | BOOL result = FALSE; |
| 68 | u16 wLength; |
| 69 | int ii; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 70 | |
Ben Hutchings | 31d5bbf | 2011-01-09 04:16:48 +0000 | [diff] [blame^] | 71 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Download firmware\n"); |
| 72 | spin_unlock_irq(&pDevice->lock); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 73 | |
Ben Hutchings | 31d5bbf | 2011-01-09 04:16:48 +0000 | [diff] [blame^] | 74 | if (!pDevice->firmware) { |
| 75 | struct device *dev = &pDevice->usb->dev; |
| 76 | int rc; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 77 | |
Ben Hutchings | 31d5bbf | 2011-01-09 04:16:48 +0000 | [diff] [blame^] | 78 | rc = request_firmware(&pDevice->firmware, FIRMWARE_NAME, dev); |
| 79 | if (rc) { |
| 80 | dev_err(dev, "firmware file %s request failed (%d)\n", |
| 81 | FIRMWARE_NAME, rc); |
| 82 | goto out; |
| 83 | } |
| 84 | } |
| 85 | fw = pDevice->firmware; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 86 | |
Ben Hutchings | 31d5bbf | 2011-01-09 04:16:48 +0000 | [diff] [blame^] | 87 | pBuffer = kmalloc(FIRMWARE_CHUNK_SIZE, GFP_KERNEL); |
| 88 | if (!pBuffer) |
| 89 | goto out; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 90 | |
Ben Hutchings | 31d5bbf | 2011-01-09 04:16:48 +0000 | [diff] [blame^] | 91 | for (ii = 0; ii < fw->size; ii += FIRMWARE_CHUNK_SIZE) { |
| 92 | wLength = min_t(int, fw->size - ii, FIRMWARE_CHUNK_SIZE); |
| 93 | memcpy(pBuffer, fw->data + ii, wLength); |
| 94 | |
| 95 | NdisStatus = CONTROLnsRequestOutAsyn(pDevice, |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 96 | 0, |
| 97 | 0x1200+ii, |
| 98 | 0x0000, |
| 99 | wLength, |
Ben Hutchings | 31d5bbf | 2011-01-09 04:16:48 +0000 | [diff] [blame^] | 100 | pBuffer |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 101 | ); |
| 102 | |
Ben Hutchings | 31d5bbf | 2011-01-09 04:16:48 +0000 | [diff] [blame^] | 103 | DBG_PRT(MSG_LEVEL_DEBUG, |
| 104 | KERN_INFO"Download firmware...%d %zu\n", ii, fw->size); |
| 105 | if (NdisStatus != STATUS_SUCCESS) |
| 106 | goto out; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 107 | } |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 108 | |
Ben Hutchings | 31d5bbf | 2011-01-09 04:16:48 +0000 | [diff] [blame^] | 109 | result = TRUE; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 110 | |
Ben Hutchings | 31d5bbf | 2011-01-09 04:16:48 +0000 | [diff] [blame^] | 111 | out: |
| 112 | if (pBuffer) |
| 113 | kfree(pBuffer); |
| 114 | |
| 115 | spin_lock_irq(&pDevice->lock); |
| 116 | return result; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 117 | } |
Ben Hutchings | 31d5bbf | 2011-01-09 04:16:48 +0000 | [diff] [blame^] | 118 | MODULE_FIRMWARE(FIRMWARE_NAME); |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 119 | |
Jim Lieb | 193a823 | 2009-08-12 14:54:06 -0700 | [diff] [blame] | 120 | BOOL |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 121 | FIRMWAREbBrach2Sram( |
Andres More | 592ccfe | 2010-04-17 12:07:42 -0300 | [diff] [blame] | 122 | PSDevice pDevice |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 123 | ) |
| 124 | { |
Andres More | 27264fb | 2010-08-05 21:18:55 -0300 | [diff] [blame] | 125 | int NdisStatus; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 126 | |
| 127 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Branch to Sram\n"); |
| 128 | |
| 129 | NdisStatus = CONTROLnsRequestOut(pDevice, |
| 130 | 1, |
| 131 | 0x1200, |
| 132 | 0x0000, |
| 133 | 0, |
| 134 | NULL |
| 135 | ); |
| 136 | |
| 137 | if (NdisStatus != STATUS_SUCCESS) { |
| 138 | return (FALSE); |
| 139 | } else { |
| 140 | return (TRUE); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | |
Jim Lieb | 193a823 | 2009-08-12 14:54:06 -0700 | [diff] [blame] | 145 | BOOL |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 146 | FIRMWAREbCheckVersion( |
Andres More | 592ccfe | 2010-04-17 12:07:42 -0300 | [diff] [blame] | 147 | PSDevice pDevice |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 148 | ) |
| 149 | { |
Andres More | 6487c49 | 2010-08-02 20:51:57 -0300 | [diff] [blame] | 150 | int ntStatus; |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 151 | |
| 152 | ntStatus = CONTROLnsRequestIn(pDevice, |
| 153 | MESSAGE_TYPE_READ, |
| 154 | 0, |
| 155 | MESSAGE_REQUEST_VERSION, |
| 156 | 2, |
| 157 | (PBYTE) &(pDevice->wFirmwareVersion)); |
| 158 | |
| 159 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Version [%04x]\n", pDevice->wFirmwareVersion); |
| 160 | if (ntStatus != STATUS_SUCCESS) { |
| 161 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Invalid.\n"); |
| 162 | return FALSE; |
| 163 | } |
| 164 | if (pDevice->wFirmwareVersion == 0xFFFF) { |
| 165 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"In Loader.\n"); |
| 166 | return FALSE; |
| 167 | } |
| 168 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Version [%04x]\n", pDevice->wFirmwareVersion); |
Ben Hutchings | 31d5bbf | 2011-01-09 04:16:48 +0000 | [diff] [blame^] | 169 | if (pDevice->wFirmwareVersion < FIRMWARE_VERSION) { |
Forest Bond | 92b9679 | 2009-06-13 07:38:31 -0400 | [diff] [blame] | 170 | // branch to loader for download new firmware |
| 171 | FIRMWAREbBrach2Sram(pDevice); |
| 172 | return FALSE; |
| 173 | } |
| 174 | return TRUE; |
| 175 | } |