Merge remote-tracking branches 'spi/topic/s3c64xx', 'spi/topic/sc18is602', 'spi/topic...
[deliverable/linux.git] / drivers / staging / wlags49_h2 / dhf.c
CommitLineData
68c0bdff 1
68c0bdff
HG
2/**************************************************************************************************************
3*
4* FILE : DHF.C
5*
6* DATE : $Date: 2004/07/19 08:16:14 $ $Revision: 1.2 $
7* Original : 2004/05/28 14:05:34 Revision: 1.36 Tag: hcf7_t20040602_01
8* Original : 2004/05/11 06:22:57 Revision: 1.32 Tag: hcf7_t7_20040513_01
9* Original : 2004/04/15 09:24:42 Revision: 1.28 Tag: hcf7_t7_20040415_01
10* Original : 2004/04/08 15:18:16 Revision: 1.27 Tag: t7_20040413_01
11* Original : 2004/04/01 15:32:55 Revision: 1.25 Tag: t7_20040401_01
12* Original : 2004/03/10 15:39:28 Revision: 1.21 Tag: t20040310_01
13* Original : 2004/03/04 11:03:37 Revision: 1.19 Tag: t20040304_01
14* Original : 2004/03/02 09:27:11 Revision: 1.17 Tag: t20040302_03
15* Original : 2004/02/24 13:00:28 Revision: 1.15 Tag: t20040224_01
16* Original : 2004/02/19 10:57:28 Revision: 1.14 Tag: t20040219_01
17* Original : 2003/11/27 09:00:09 Revision: 1.3 Tag: t20021216_01
18*
19* AUTHOR : John Meertens
20* Nico Valster
21*
22* SPECIFICATION: ........
23*
24* DESC : generic functions to handle the download of NIC firmware
25* Local Support Routines for above procedures
26*
27* Customizable via HCFCFG.H, which is included by HCF.H
28*
29*
30* DHF is (intended to be) platform-independent.
31* DHF is a module that provides a number of routines to download firmware
32* images (the names primary, station, access point, secondary and tertiary
33* are used or have been used) to volatile or nonvolatile memory
34* in WaveLAN/IEEE NICs. To achieve this DHF makes use of the WaveLAN/IEEE
35* WCI as implemented by the HCF-module.
36*
37* Download to non-volatile memory is used to update a WaveLAN/IEEE NIC to new
38* firmware. Normally this will be an upgrade to newer firmware, although
39* downgrading to older firmware is possible too.
40*
41* Note: relative to Asserts, the following can be observed:
42* Since the IFB is not known inside the routine, the macro HCFASSERT is replaced with MMDASSERT.
43* Also the line number reported in the assert is raised by FILE_NAME_OFFSET (10000) to discriminate the
44* DHF Asserts from HCF and MMD asserts.
45*
46***************************************************************************************************************
47*
48*
49* SOFTWARE LICENSE
50*
51* This software is provided subject to the following terms and conditions,
52* which you should read carefully before using the software. Using this
53* software indicates your acceptance of these terms and conditions. If you do
54* not agree with these terms and conditions, do not use the software.
55*
ccc75a58
RP
56* COPYRIGHT (C) 1999 - 2000 by Lucent Technologies. All Rights Reserved
57* COPYRIGHT (C) 2001 - 2004 by Agere Systems Inc. All Rights Reserved
68c0bdff
HG
58* All rights reserved.
59*
60* Redistribution and use in source or binary forms, with or without
61* modifications, are permitted provided that the following conditions are met:
62*
63* . Redistributions of source code must retain the above copyright notice, this
64* list of conditions and the following Disclaimer as comments in the code as
65* well as in the documentation and/or other materials provided with the
66* distribution.
67*
68* . Redistributions in binary form must reproduce the above copyright notice,
69* this list of conditions and the following Disclaimer in the documentation
70* and/or other materials provided with the distribution.
71*
72* . Neither the name of Agere Systems Inc. nor the names of the contributors
73* may be used to endorse or promote products derived from this software
74* without specific prior written permission.
75*
76* Disclaimer
77*
78* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
79* INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF
80* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ANY
81* USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE IS SOLELY AT THE USERS OWN
82* RISK. IN NO EVENT SHALL AGERE SYSTEMS INC. OR CONTRIBUTORS BE LIABLE FOR ANY
83* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
84* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
85* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
86* ON ANY THEORY OF LIABILITY, INCLUDING, BUT NOT LIMITED TO, CONTRACT, STRICT
87* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
88* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
89* DAMAGE.
90*
91*
92**************************************************************************************************************/
93
94#include "hcf.h"
95#include "hcfdef.h"
96#include "dhf.h"
97#include "mmd.h"
98
fd547f1f 99/* to distinguish MMD from HCF asserts by means of line number */
68c0bdff
HG
100#undef FILE_NAME_OFFSET
101#define FILE_NAME_OFFSET MMD_FILE_NAME_OFFSET
102/*-----------------------------------------------------------------------------
103 *
104 * Defines, data structures, and global variables
105 *
106 *---------------------------------------------------------------------------*/
107
fd547f1f 108/* 12345678901234 */
68c0bdff
HG
109char signature[14] = "FUPU7D37dhfwci";
110
68c0bdff
HG
111/*-----------------------------------------------------------------------------
112 *
113 * LTV-records retrieved from the NIC to:
114 * - determine compatibility between NIC and image
115 * - ((setup the buffer size dynamically for non-volatile download (see note below) ))
116 * - supply plugging information contained in the PDA (H-I only)
117 *
118 *---------------------------------------------------------------------------*/
119
fd547f1f
RP
120/* for USB/H1 we needed a smaller value than the CFG_DL_BUF_STRCT reported 8192
121 for the time being it seems simpler to always use 2000 for USB/H1 as well as all other cases rather than
122 using the "fixed anyway" CFG_DL_BUF_STRCT. */
68c0bdff
HG
123#define DL_SIZE 2000
124
fd547f1f 125/* CFG_IDENTITY_STRCT pri_identity = { LOF(CFG_IDENTITY_STRCT), CFG_PRI_IDENTITY }; */
68c0bdff
HG
126CFG_SUP_RANGE_STRCT mfi_sup = { LOF(CFG_SUP_RANGE_STRCT), CFG_NIC_MFI_SUP_RANGE };
127CFG_SUP_RANGE_STRCT cfi_sup = { LOF(CFG_SUP_RANGE_STRCT), CFG_NIC_CFI_SUP_RANGE };
128/* Note: could be used rather than the above explained and defined DL_SIZE if need arises
129 * CFG_DL_BUF_STRCT dl_buf = { LOF(CFG_DL_BUF_STRCT), CFG_DL_BUF };
130*/
131
132/*-----------------------------------------------------------------------------
133 * Array ltv_info stores NIC information (in the form of LTV-records)
134 * needed for download. A NULL record indicates the end of the array.
135 *---------------------------------------------------------------------------*/
136
137/* The LTV_INFO_STRUCT is needed to save the sizes of the structs, because after a GET_INFO()
138 * the len field is changed to the real len of the RID by the called routine.
139 * This is only relevant if the DHF used without reloading the driver/utility.
140 */
141
142LTV_INFO_STRUCT ltv_info[] = {
143 { (LTVP)&mfi_sup, LOF(CFG_SUP_RANGE_STRCT) } ,
144 { (LTVP)&cfi_sup, LOF(CFG_SUP_RANGE_STRCT) } ,
145 { (LTVP) NULL, 0 }
146};
147
148
149/***********************************************************************************************************/
150/*************************************** PROTOTYPES ******************************************************/
151/***********************************************************************************************************/
068b561c 152static int check_comp_fw(memimage *fw);
68c0bdff
HG
153
154
155/************************************************************************************************************
156*.SUBMODULE int check_comp_fw( memimage *fw )
157*.PURPOSE Checks compatibility of CFI and MFI, NIC as supplier, station/AP firmware image as supplier.
158*
159*.ARGUMENTS
160* fw F/W image to be downloaded
161*
162*.RETURNS
163* HFC_SUCCESS - firmware OK
164* DHF_ERR_INCOMP_FW
165*
166*.DESCRIPTION
167* This function uses compatibility and identity information that has been
168* retrieved from the card which is currently inserted to check whether the
169* station firmware image to be downloaded is compatible.
170*.ENDDOC END DOCUMENTATION
171*************************************************************************************************************/
172int
068b561c 173check_comp_fw(memimage *fw)
68c0bdff
HG
174{
175CFG_RANGE20_STRCT *p;
176int rc = HCF_SUCCESS;
068b561c 177CFG_RANGE_SPEC_STRCT *i;
68c0bdff 178
068b561c
RP
179 switch (fw->identity->typ) {
180 case CFG_FW_IDENTITY: /* Station F/W */
181 case COMP_ID_FW_AP_FAKE: /* ;?is this useful (used to be: CFG_AP_IDENTITY) */
68c0bdff 182 break;
068b561c
RP
183 default:
184 MMDASSERT(DO_ASSERT, fw->identity->typ) /* unknown/unsupported firmware_type: */
68c0bdff 185 rc = DHF_ERR_INCOMP_FW;
068b561c 186 return rc; /* ;? how useful is this anyway,
68c0bdff
HG
187 * till that is sorted out might as well violate my own single exit principle
188 */
189 }
190 p = fw->compat;
191 i = NULL;
068b561c
RP
192 while (p->len && i == NULL) { /* check the MFI ranges */
193 if (p->typ == CFG_MFI_ACT_RANGES_STA) {
194 i = mmd_check_comp((void *)p, &mfi_sup);
68c0bdff
HG
195 }
196 p++;
197 }
068b561c
RP
198 MMDASSERT(i, 0) /* MFI: NIC Supplier not compatible with F/W image Actor */
199 if (i) {
68c0bdff
HG
200 p = fw->compat;
201 i = NULL;
068b561c
RP
202 while (p->len && i == NULL) { /* check the CFI ranges */
203 if (p->typ == CFG_CFI_ACT_RANGES_STA) {
204 i = mmd_check_comp((void *)p, &cfi_sup);
68c0bdff
HG
205 }
206 p++;
207 }
068b561c 208 MMDASSERT(i, 0) /* CFI: NIC Supplier not compatible with F/W image Actor */
68c0bdff 209 }
068b561c 210 if (i == NULL) {
68c0bdff
HG
211 rc = DHF_ERR_INCOMP_FW;
212 }
213 return rc;
fd547f1f 214} /* check_comp_fw */
68c0bdff
HG
215
216
217
218
219
220/*-----------------------------------------------------------------------------
221 *
222 * Exported functions
223 *
224 *---------------------------------------------------------------------------*/
225
226
227
228/*************************************************************************************************************
229*
230*.MODULE int dhf_download_binary( void *ifbp, memimage *fw )
231*.PURPOSE Downloads a complete (primary, station, or access point) firmware image to the NIC.
232*
233*.ARGUMENTS
234* ifbp address of the Interface Block
235* fw F/W image to be downloaded
236*
237*.RETURNS
238* HCF_SUCCESS - download completed successfully.
239* DHF_ERR_INCOMP_FW - firmware not compatible
240*
241*.DESCRIPTION
242* Initialize global variables
243* Connect to the DHF
244* Check the compatibility of the image (For primary firmware images it is checked first
245* whether download is necessary).
246* If everything's download the firmware.
247* Disconnect from the DHF.
248*
249*
250*.DIAGRAM
251*
252*.NOTICE:
253 MMDASSERT is unacceptable because some drivers call dhf_download_binary before hcf_connect
254
255* The old comment was:
256*.ENDDOC END DOCUMENTATION
257*************************************************************************************************************/
258int
068b561c 259dhf_download_binary(memimage *fw)
68c0bdff
HG
260{
261int rc = HCF_SUCCESS;
262CFG_PROG_STRCT *p;
263int i;
264
fd547f1f 265 /* validate the image */
437de951
RP
266 for (i = 0; i < sizeof(signature) && fw->signature[i] == signature[i]; i++)
267 ; /* NOP */
068b561c 268 if (i != sizeof(signature) ||
68c0bdff 269 fw->signature[i] != 0x01 ||
fd547f1f 270 /* test for Little/Big Endian Binary flag */
437de951
RP
271 fw->signature[i+1] != (/* HCF_BIG_ENDIAN ? 'B' : */ 'L'))
272 rc = DHF_ERR_INCOMP_FW;
fd547f1f 273 else { /* Little Endian Binary format */
5ae8cb95
GKH
274 fw->codep = (CFG_PROG_STRCT FAR*)((char *)fw->codep + (hcf_32)fw);
275 fw->identity = (CFG_IDENTITY_STRCT FAR*)((char *)fw->identity + (hcf_32)fw);
276 fw->compat = (CFG_RANGE20_STRCT FAR*)((char *)fw->compat + (hcf_32)fw);
437de951 277 for (i = 0; fw->p[i]; i++)
5ae8cb95 278 fw->p[i] = ((char *)fw->p[i] + (hcf_32)fw);
68c0bdff 279 p = fw->codep;
068b561c 280 while (p->len) {
5ae8cb95 281 p->host_addr = (char *)p->host_addr + (hcf_32)fw;
68c0bdff
HG
282 p++;
283 }
284 }
285 return rc;
fd547f1f 286} /* dhf_download_binary */
68c0bdff
HG
287
288
289/*************************************************************************************************************
290*
291*.MODULE int dhf_download_fw( void *ifbp, memimage *fw )
292*.PURPOSE Downloads a complete (primary or tertiary) firmware image to the NIC.
293*
294*.ARGUMENTS
295* ifbp address of the Interface Block
296* fw F/W image to be downloaded
297*
298*.RETURNS
299* HCF_SUCCESS - download completed successfully.
300* HCF_ERR_NO_NIC - no NIC present
301* DHF_ERR_INCOMP_FW - firmware not compatible
302*
303*.DESCRIPTION
304* - check the signature of the image
305* - get the compatibility information from the components on the NIC
306* - Primary Firmware Identity
307* - Modem - Firmware I/F
308* - Controller - Firmware I/F
309*!! - if necessary ( i.e. H-I) get the PDA contents from the NIC
310* - check the compatibility of the MFI and CFI of the NIC with the F/W image
311* Note: the Primary F/W compatibility is only relevant for the "running" HCF and is already verified in
312* hcf_connect
313*!! - if necessary ( i.e. H-I)
314*!! - verify the sumcheck of the PDA
315*!! - plug the image (based on the PDA and the default plug records)
316* - loop over all the download LTVs in the image which consists of a sequence of
317* - CFG_PROG_VOLATILE/CFG_PROG_NON_VOLATILE
318* - 1 or more sequences of CFG_PROG_ADDR, CFG_PROG_DATA,....,CFG_PROG_DATA
319* - CFG_PROG_STOP
320*
321*.DIAGRAM
322*
323*.NOTICE
324* The old comment was:
325* // Download primary firmware if necessary and allowed. This is done silently (without telling
326* // the user) and only if the firmware in the download image is newer than the firmware in the
327* // card. In Major version 4 of the primary firmware functions of Hermes and Shark were
328* // combined. Prior to that two separate versions existed. We only have to download primary
329* // firmware if major version of primary firmware in the NIC < 4.
330* // download = pri_identity.version_major < 4;
331* // if ( download ) {
332* // rc = check_comp_primary( fw );
333* // }
334* It is my understanding that Pri Variant 1 must be updated by Pri Variant 2. The test on
335* major version < 4 should amount to the same result but be "principally" less correct
336* In deliberation with the Architecture team, it was decided that this upgrade for old H-I
337* NICs, is an aspect which belongs on the WSU level not on the DHF level
338*
339*.ENDDOC END DOCUMENTATION
340*************************************************************************************************************/
341int
068b561c 342dhf_download_fw(void *ifbp, memimage *fw)
68c0bdff
HG
343{
344int rc = HCF_SUCCESS;
345LTV_INFO_STRUCT_PTR pp = ltv_info;
346CFG_PROG_STRCT *p = fw->codep;
347LTVP ltvp;
348int i;
349
068b561c 350 MMDASSERT(fw != NULL, 0)
fd547f1f 351 /* validate the image */
437de951
RP
352 for (i = 0; i < sizeof(signature) && fw->signature[i] == signature[i]; i++)
353 ; /* NOP */
068b561c 354 if (i != sizeof(signature) ||
68c0bdff 355 fw->signature[i] != 0x01 ||
fd547f1f 356 /* check for binary image */
068b561c 357 (fw->signature[i+1] != 'C' && fw->signature[i+1] != (/*HCF_BIG_ENDIAN ? 'B' : */ 'L')))
68c0bdff
HG
358 rc = DHF_ERR_INCOMP_FW;
359
fd547f1f 360/* Retrieve all information needed for download from the NIC */
068b561c 361 while ((rc == HCF_SUCCESS) && ((ltvp = pp->ltvp) != NULL)) {
fd547f1f 362 ltvp->len = pp++->len; /* Set len to original len. This len is changed to real len by GET_INFO() */
068b561c
RP
363 rc = GET_INFO(ltvp);
364 MMDASSERT(rc == HCF_SUCCESS, rc)
365 MMDASSERT(rc == HCF_SUCCESS, ltvp->typ)
366 MMDASSERT(rc == HCF_SUCCESS, ltvp->len)
68c0bdff 367 }
437de951
RP
368 if (rc == HCF_SUCCESS)
369 rc = check_comp_fw(fw);
068b561c
RP
370 if (rc == HCF_SUCCESS) {
371 while (rc == HCF_SUCCESS && p->len) {
372 rc = PUT_INFO(p);
68c0bdff
HG
373 p++;
374 }
375 }
068b561c 376 MMDASSERT(rc == HCF_SUCCESS, rc)
68c0bdff 377 return rc;
fd547f1f 378} /* dhf_download_fw */
68c0bdff
HG
379
380
This page took 0.355031 seconds and 5 git commands to generate.