include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[linux-2.6-block.git] / drivers / staging / wlan-ng / prism2fw.c
CommitLineData
76e3e7c4
KR
1/* from src/prism2/download/prism2dl.c
2*
3* utility for downloading prism2 images moved into kernelspace
4*
5* Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
6* --------------------------------------------------------------------
7*
8* linux-wlan
9*
10* The contents of this file are subject to the Mozilla Public
11* License Version 1.1 (the "License"); you may not use this file
12* except in compliance with the License. You may obtain a copy of
13* the License at http://www.mozilla.org/MPL/
14*
15* Software distributed under the License is distributed on an "AS
16* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
17* implied. See the License for the specific language governing
18* rights and limitations under the License.
19*
20* Alternatively, the contents of this file may be used under the
21* terms of the GNU Public License version 2 (the "GPL"), in which
22* case the provisions of the GPL are applicable instead of the
23* above. If you wish to allow the use of your version of this file
24* only under the terms of the GPL and not to allow others to use
25* your version of this file under the MPL, indicate your decision
26* by deleting the provisions above and replace them with the notice
27* and other provisions required by the GPL. If you do not delete
28* the provisions above, a recipient may use your version of this
29* file under either the MPL or the GPL.
30*
31* --------------------------------------------------------------------
32*
33* Inquiries regarding the linux-wlan Open Source project can be
34* made directly to:
35*
36* AbsoluteValue Systems Inc.
37* info@linux-wlan.com
38* http://www.linux-wlan.com
39*
40* --------------------------------------------------------------------
41*
42* Portions of the development of this software were funded by
43* Intersil Corporation as part of PRISM(R) chipset product development.
44*
45* --------------------------------------------------------------------
46*/
47
48/*================================================================*/
49/* System Includes */
d8950599 50#include <linux/ihex.h>
5a0e3ad6 51#include <linux/slab.h>
76e3e7c4 52
76e3e7c4
KR
53/*================================================================*/
54/* Local Constants */
55
d8950599 56#define PRISM2_USB_FWFILE "prism2_ru.fw"
5d929a71 57MODULE_FIRMWARE(PRISM2_USB_FWFILE);
76e3e7c4
KR
58
59#define S3DATA_MAX 5000
60#define S3PLUG_MAX 200
61#define S3CRC_MAX 200
62#define S3INFO_MAX 50
76e3e7c4
KR
63
64#define S3ADDR_PLUG (0xff000000UL)
65#define S3ADDR_CRC (0xff100000UL)
66#define S3ADDR_INFO (0xff200000UL)
d8950599 67#define S3ADDR_START (0xff400000UL)
76e3e7c4
KR
68
69#define CHUNKS_MAX 100
70
71#define WRITESIZE_MAX 4096
72
76e3e7c4
KR
73/*================================================================*/
74/* Local Types */
75
75f49e07
MT
76typedef struct s3datarec {
77 u32 len;
78 u32 addr;
79 u8 checksum;
80 u8 *data;
76e3e7c4
KR
81} s3datarec_t;
82
75f49e07
MT
83typedef struct s3plugrec {
84 u32 itemcode;
85 u32 addr;
86 u32 len;
76e3e7c4
KR
87} s3plugrec_t;
88
75f49e07
MT
89typedef struct s3crcrec {
90 u32 addr;
91 u32 len;
92 unsigned int dowrite;
76e3e7c4
KR
93} s3crcrec_t;
94
75f49e07
MT
95typedef struct s3inforec {
96 u16 len;
97 u16 type;
76e3e7c4 98 union {
75f49e07
MT
99 hfa384x_compident_t version;
100 hfa384x_caplevel_t compat;
101 u16 buildseq;
102 hfa384x_compident_t platform;
103 } info;
76e3e7c4
KR
104} s3inforec_t;
105
75f49e07
MT
106typedef struct pda {
107 u8 buf[HFA384x_PDA_LEN_MAX];
108 hfa384x_pdrec_t *rec[HFA384x_PDA_RECS_MAX];
109 unsigned int nrec;
76e3e7c4
KR
110} pda_t;
111
75f49e07 112typedef struct imgchunk {
ef1a0ed7
AE
113 u32 addr; /* start address */
114 u32 len; /* in bytes */
115 u16 crc; /* CRC value (if it falls at a chunk boundary) */
75f49e07 116 u8 *data;
76e3e7c4
KR
117} imgchunk_t;
118
119/*================================================================*/
120/* Local Static Definitions */
121
76e3e7c4
KR
122/*----------------------------------------------------------------*/
123/* s-record image processing */
124
125/* Data records */
297f06ce 126unsigned int ns3data;
75f49e07 127s3datarec_t s3data[S3DATA_MAX];
76e3e7c4
KR
128
129/* Plug records */
297f06ce 130unsigned int ns3plug;
75f49e07 131s3plugrec_t s3plug[S3PLUG_MAX];
76e3e7c4
KR
132
133/* CRC records */
297f06ce 134unsigned int ns3crc;
75f49e07 135s3crcrec_t s3crc[S3CRC_MAX];
76e3e7c4
KR
136
137/* Info records */
297f06ce 138unsigned int ns3info;
75f49e07 139s3inforec_t s3info[S3INFO_MAX];
76e3e7c4
KR
140
141/* S7 record (there _better_ be only one) */
75f49e07 142u32 startaddr;
76e3e7c4
KR
143
144/* Load image chunks */
75f49e07
MT
145unsigned int nfchunks;
146imgchunk_t fchunk[CHUNKS_MAX];
76e3e7c4
KR
147
148/* Note that for the following pdrec_t arrays, the len and code */
149/* fields are stored in HOST byte order. The mkpdrlist() function */
150/* does the conversion. */
151/*----------------------------------------------------------------*/
152/* PDA, built from [card|newfile]+[addfile1+addfile2...] */
153
75f49e07 154pda_t pda;
76e3e7c4 155hfa384x_compident_t nicid;
75f49e07
MT
156hfa384x_caplevel_t rfid;
157hfa384x_caplevel_t macid;
158hfa384x_caplevel_t priid;
76e3e7c4
KR
159
160/*================================================================*/
161/* Local Function Declarations */
162
d8950599
KR
163int prism2_fwapply(const struct ihex_binrec *rfptr, wlandevice_t *wlandev);
164int read_fwfile(const struct ihex_binrec *rfptr);
297f06ce
MT
165int mkimage(imgchunk_t *clist, unsigned int *ccnt);
166int read_cardpda(pda_t *pda, wlandevice_t *wlandev);
167int mkpdrlist(pda_t *pda);
297f06ce
MT
168int plugimage(imgchunk_t *fchunk, unsigned int nfchunks,
169 s3plugrec_t *s3plug, unsigned int ns3plug, pda_t * pda);
170int crcimage(imgchunk_t *fchunk, unsigned int nfchunks,
171 s3crcrec_t *s3crc, unsigned int ns3crc);
172int writeimage(wlandevice_t *wlandev, imgchunk_t *fchunk,
75f49e07 173 unsigned int nfchunks);
297f06ce 174void free_chunks(imgchunk_t *fchunk, unsigned int *nfchunks);
75f49e07
MT
175void free_srecs(void);
176
177int validate_identity(void);
76e3e7c4
KR
178
179/*================================================================*/
180/* Function Definitions */
181
76e3e7c4
KR
182/*----------------------------------------------------------------
183* prism2_fwtry
184*
185* Try and get firmware into memory
186*
187* Arguments:
188* udev usb device structure
189* wlandev wlan device structure
190*
191* Returns:
192* 0 - success
193* ~0 - failure
194----------------------------------------------------------------*/
297f06ce 195int prism2_fwtry(struct usb_device *udev, wlandevice_t *wlandev)
76e3e7c4
KR
196{
197 const struct firmware *fw_entry = NULL;
198
75f49e07
MT
199 printk(KERN_INFO "prism2_usb: Checking for firmware %s\n",
200 PRISM2_USB_FWFILE);
d8950599 201 if (request_ihex_firmware(&fw_entry, PRISM2_USB_FWFILE, &udev->dev) != 0) {
76e3e7c4
KR
202 printk(KERN_INFO
203 "prism2_usb: Firmware not available, but not essential\n");
204 printk(KERN_INFO
205 "prism2_usb: can continue to use card anyway.\n");
206 return 1;
207 }
208
83a0f9bc 209 printk(KERN_INFO "prism2_usb: %s will be processed, size %zu\n",
75f49e07 210 PRISM2_USB_FWFILE, fw_entry->size);
d8950599 211 prism2_fwapply((const struct ihex_binrec *)fw_entry->data, wlandev);
76e3e7c4
KR
212
213 release_firmware(fw_entry);
214 return 0;
215}
216
76e3e7c4
KR
217/*----------------------------------------------------------------
218* prism2_fwapply
219*
220* Apply the firmware loaded into memory
221*
222* Arguments:
223* rfptr firmware image in kernel memory
76e3e7c4
KR
224* wlandev device
225*
226* Returns:
227* 0 - success
228* ~0 - failure
229----------------------------------------------------------------*/
d8950599 230int prism2_fwapply(const struct ihex_binrec *rfptr, wlandevice_t *wlandev)
76e3e7c4 231{
75f49e07 232 signed int result = 0;
76e3e7c4
KR
233 p80211msg_dot11req_mibget_t getmsg;
234 p80211itemd_t *item;
75f49e07 235 u32 *data;
76e3e7c4
KR
236
237 /* Initialize the data structures */
238 ns3data = 0;
239 memset(s3data, 0, sizeof(s3data));
240 ns3plug = 0;
241 memset(s3plug, 0, sizeof(s3plug));
242 ns3crc = 0;
243 memset(s3crc, 0, sizeof(s3crc));
244 ns3info = 0;
245 memset(s3info, 0, sizeof(s3info));
246 startaddr = 0;
247
248 nfchunks = 0;
75f49e07
MT
249 memset(fchunk, 0, sizeof(fchunk));
250 memset(&nicid, 0, sizeof(nicid));
251 memset(&rfid, 0, sizeof(rfid));
252 memset(&macid, 0, sizeof(macid));
253 memset(&priid, 0, sizeof(priid));
76e3e7c4
KR
254
255 /* clear the pda and add an initial END record */
256 memset(&pda, 0, sizeof(pda));
75f49e07
MT
257 pda.rec[0] = (hfa384x_pdrec_t *) pda.buf;
258 pda.rec[0]->len = cpu_to_le16(2); /* len in words *//* len in words */
76e3e7c4
KR
259 pda.rec[0]->code = cpu_to_le16(HFA384x_PDR_END_OF_PDA);
260 pda.nrec = 1;
261
76e3e7c4
KR
262 /*-----------------------------------------------------*/
263 /* Put card into fwload state */
264 prism2sta_ifstate(wlandev, P80211ENUM_ifstate_fwload);
265
266 /* Build the PDA we're going to use. */
267 if (read_cardpda(&pda, wlandev)) {
268 printk(KERN_ERR "load_cardpda failed, exiting.\n");
5dd8acc8 269 return 1;
76e3e7c4
KR
270 }
271
272 /* read the card's PRI-SUP */
273 memset(&getmsg, 0, sizeof(getmsg));
274 getmsg.msgcode = DIDmsg_dot11req_mibget;
275 getmsg.msglen = sizeof(getmsg);
276 strcpy(getmsg.devname, wlandev->name);
277
278 getmsg.mibattribute.did = DIDmsg_dot11req_mibget_mibattribute;
279 getmsg.mibattribute.status = P80211ENUM_msgitem_status_data_ok;
280 getmsg.resultcode.did = DIDmsg_dot11req_mibget_resultcode;
281 getmsg.resultcode.status = P80211ENUM_msgitem_status_no_value;
282
283 item = (p80211itemd_t *) getmsg.mibattribute.data;
284 item->did = DIDmib_p2_p2NIC_p2PRISupRange;
285 item->status = P80211ENUM_msgitem_status_no_value;
286
75f49e07 287 data = (u32 *) item->data;
76e3e7c4
KR
288
289 /* DIDmsg_dot11req_mibget */
290 prism2mgmt_mibset_mibget(wlandev, &getmsg);
5dd8acc8 291 if (getmsg.resultcode.data != P80211ENUM_resultcode_success)
76e3e7c4 292 printk(KERN_ERR "Couldn't fetch PRI-SUP info\n");
76e3e7c4
KR
293
294 /* Already in host order */
295 priid.role = *data++;
296 priid.id = *data++;
297 priid.variant = *data++;
298 priid.bottom = *data++;
299 priid.top = *data++;
300
76e3e7c4 301 /* Read the S3 file */
d8950599 302 result = read_fwfile(rfptr);
75f49e07 303 if (result) {
76e3e7c4 304 printk(KERN_ERR "Failed to read the data exiting.\n");
5dd8acc8 305 return 1;
76e3e7c4 306 }
76e3e7c4
KR
307
308 result = validate_identity();
309
75f49e07 310 if (result) {
76e3e7c4 311 printk(KERN_ERR "Incompatible firmware image.\n");
5dd8acc8 312 return 1;
76e3e7c4
KR
313 }
314
315 if (startaddr == 0x00000000) {
316 printk(KERN_ERR "Can't RAM download a Flash image!\n");
5dd8acc8 317 return 1;
76e3e7c4
KR
318 }
319
320 /* Make the image chunks */
321 result = mkimage(fchunk, &nfchunks);
322
323 /* Do any plugging */
75f49e07
MT
324 result = plugimage(fchunk, nfchunks, s3plug, ns3plug, &pda);
325 if (result) {
76e3e7c4 326 printk(KERN_ERR "Failed to plug data.\n");
5dd8acc8 327 return 1;
76e3e7c4
KR
328 }
329
330 /* Insert any CRCs */
75f49e07 331 if (crcimage(fchunk, nfchunks, s3crc, ns3crc)) {
76e3e7c4 332 printk(KERN_ERR "Failed to insert all CRCs\n");
5dd8acc8 333 return 1;
76e3e7c4
KR
334 }
335
336 /* Write the image */
337 result = writeimage(wlandev, fchunk, nfchunks);
75f49e07 338 if (result) {
76e3e7c4 339 printk(KERN_ERR "Failed to ramwrite image data.\n");
5dd8acc8 340 return 1;
76e3e7c4
KR
341 }
342
343 /* clear any allocated memory */
344 free_chunks(fchunk, &nfchunks);
345 free_srecs();
346
347 printk(KERN_INFO "prism2_usb: firmware loading finished.\n");
348
349 return result;
350}
351
76e3e7c4
KR
352/*----------------------------------------------------------------
353* crcimage
354*
355* Adds a CRC16 in the two bytes prior to each block identified by
356* an S3 CRC record. Currently, we don't actually do a CRC we just
357* insert the value 0xC0DE in hfa384x order.
358*
359* Arguments:
360* fchunk Array of image chunks
361* nfchunks Number of image chunks
362* s3crc Array of crc records
363* ns3crc Number of crc records
364*
365* Returns:
366* 0 success
367* ~0 failure
368----------------------------------------------------------------*/
297f06ce 369int crcimage(imgchunk_t *fchunk, unsigned int nfchunks, s3crcrec_t *s3crc,
76e3e7c4
KR
370 unsigned int ns3crc)
371{
75f49e07
MT
372 int result = 0;
373 int i;
374 int c;
375 u32 crcstart;
376 u32 crcend;
377 u32 cstart = 0;
378 u32 cend;
379 u8 *dest;
380 u32 chunkoff;
381
382 for (i = 0; i < ns3crc; i++) {
383 if (!s3crc[i].dowrite)
384 continue;
76e3e7c4 385 crcstart = s3crc[i].addr;
75f49e07 386 crcend = s3crc[i].addr + s3crc[i].len;
76e3e7c4 387 /* Find chunk */
75f49e07 388 for (c = 0; c < nfchunks; c++) {
76e3e7c4 389 cstart = fchunk[c].addr;
75f49e07 390 cend = fchunk[c].addr + fchunk[c].len;
76e3e7c4
KR
391 /* the line below does an address & len match search */
392 /* unfortunately, I've found that the len fields of */
393 /* some crc records don't match with the length of */
394 /* the actual data, so we're not checking right */
395 /* now */
75f49e07 396 /* if ( crcstart-2 >= cstart && crcend <= cend ) break; */
76e3e7c4
KR
397
398 /* note the -2 below, it's to make sure the chunk has */
399 /* space for the CRC value */
75f49e07
MT
400 if (crcstart - 2 >= cstart && crcstart < cend)
401 break;
76e3e7c4 402 }
75f49e07 403 if (c >= nfchunks) {
76e3e7c4 404 printk(KERN_ERR
75f49e07
MT
405 "Failed to find chunk for "
406 "crcrec[%d], addr=0x%06x len=%d , "
407 "aborting crc.\n",
408 i, s3crc[i].addr, s3crc[i].len);
76e3e7c4
KR
409 return 1;
410 }
411
412 /* Insert crc */
75f49e07 413 pr_debug("Adding crc @ 0x%06x\n", s3crc[i].addr - 2);
76e3e7c4
KR
414 chunkoff = crcstart - cstart - 2;
415 dest = fchunk[c].data + chunkoff;
75f49e07
MT
416 *dest = 0xde;
417 *(dest + 1) = 0xc0;
76e3e7c4
KR
418
419 }
420 return result;
421}
422
76e3e7c4
KR
423/*----------------------------------------------------------------
424* free_chunks
425*
426* Clears the chunklist data structures in preparation for a new file.
427*
428* Arguments:
429* none
430*
431* Returns:
432* nothing
433----------------------------------------------------------------*/
297f06ce 434void free_chunks(imgchunk_t *fchunk, unsigned int *nfchunks)
76e3e7c4
KR
435{
436 int i;
75f49e07 437 for (i = 0; i < *nfchunks; i++) {
5dd8acc8 438 if (fchunk[i].data != NULL)
76e3e7c4 439 kfree(fchunk[i].data);
76e3e7c4
KR
440 }
441 *nfchunks = 0;
4068fe8b 442 memset(fchunk, 0, sizeof(*fchunk));
76e3e7c4
KR
443
444}
445
76e3e7c4
KR
446/*----------------------------------------------------------------
447* free_srecs
448*
449* Clears the srec data structures in preparation for a new file.
450*
451* Arguments:
452* none
453*
454* Returns:
455* nothing
456----------------------------------------------------------------*/
457void free_srecs(void)
458{
76e3e7c4
KR
459 ns3data = 0;
460 memset(s3data, 0, sizeof(s3data));
461 ns3plug = 0;
462 memset(s3plug, 0, sizeof(s3plug));
463 ns3crc = 0;
464 memset(s3crc, 0, sizeof(s3crc));
465 ns3info = 0;
466 memset(s3info, 0, sizeof(s3info));
467 startaddr = 0;
468}
469
76e3e7c4
KR
470/*----------------------------------------------------------------
471* mkimage
472*
473* Scans the currently loaded set of S records for data residing
474* in contiguous memory regions. Each contiguous region is then
475* made into a 'chunk'. This function assumes that we're building
476* a new chunk list. Assumes the s3data items are in sorted order.
477*
478* Arguments: none
479*
480* Returns:
481* 0 - success
482* ~0 - failure (probably an errno)
483----------------------------------------------------------------*/
297f06ce 484int mkimage(imgchunk_t *clist, unsigned int *ccnt)
76e3e7c4 485{
75f49e07
MT
486 int result = 0;
487 int i;
488 int j;
489 int currchunk = 0;
490 u32 nextaddr = 0;
491 u32 s3start;
492 u32 s3end;
493 u32 cstart = 0;
494 u32 cend;
495 u32 coffset;
76e3e7c4
KR
496
497 /* There may already be data in the chunklist */
498 *ccnt = 0;
499
500 /* Establish the location and size of each chunk */
75f49e07
MT
501 for (i = 0; i < ns3data; i++) {
502 if (s3data[i].addr == nextaddr) {
76e3e7c4
KR
503 /* existing chunk, grow it */
504 clist[currchunk].len += s3data[i].len;
505 nextaddr += s3data[i].len;
506 } else {
507 /* New chunk */
508 (*ccnt)++;
509 currchunk = *ccnt - 1;
510 clist[currchunk].addr = s3data[i].addr;
511 clist[currchunk].len = s3data[i].len;
512 nextaddr = s3data[i].addr + s3data[i].len;
513 /* Expand the chunk if there is a CRC record at */
514 /* their beginning bound */
75f49e07
MT
515 for (j = 0; j < ns3crc; j++) {
516 if (s3crc[j].dowrite &&
517 s3crc[j].addr == clist[currchunk].addr) {
76e3e7c4
KR
518 clist[currchunk].addr -= 2;
519 clist[currchunk].len += 2;
520 }
521 }
522 }
523 }
524
525 /* We're currently assuming there aren't any overlapping chunks */
526 /* if this proves false, we'll need to add code to coalesce. */
527
528 /* Allocate buffer space for chunks */
75f49e07 529 for (i = 0; i < *ccnt; i++) {
76e3e7c4 530 clist[i].data = kmalloc(clist[i].len, GFP_KERNEL);
75f49e07
MT
531 if (clist[i].data == NULL) {
532 printk(KERN_ERR
533 "failed to allocate image space, exitting.\n");
5dd8acc8 534 return 1;
76e3e7c4
KR
535 }
536 memset(clist[i].data, 0, clist[i].len);
76e3e7c4 537 pr_debug("chunk[%d]: addr=0x%06x len=%d\n",
75f49e07 538 i, clist[i].addr, clist[i].len);
76e3e7c4
KR
539 }
540
541 /* Copy srec data to chunks */
75f49e07 542 for (i = 0; i < ns3data; i++) {
76e3e7c4 543 s3start = s3data[i].addr;
75f49e07
MT
544 s3end = s3start + s3data[i].len - 1;
545 for (j = 0; j < *ccnt; j++) {
76e3e7c4
KR
546 cstart = clist[j].addr;
547 cend = cstart + clist[j].len - 1;
5dd8acc8 548 if (s3start >= cstart && s3end <= cend)
76e3e7c4 549 break;
76e3e7c4 550 }
75f49e07 551 if (((unsigned int)j) >= (*ccnt)) {
76e3e7c4 552 printk(KERN_ERR
75f49e07
MT
553 "s3rec(a=0x%06x,l=%d), no chunk match, exiting.\n",
554 s3start, s3data[i].len);
5dd8acc8 555 return 1;
76e3e7c4
KR
556 }
557 coffset = s3start - cstart;
75f49e07 558 memcpy(clist[j].data + coffset, s3data[i].data, s3data[i].len);
76e3e7c4
KR
559 }
560
561 return result;
562}
563
564/*----------------------------------------------------------------
565* mkpdrlist
566*
567* Reads a raw PDA and builds an array of pdrec_t structures.
568*
569* Arguments:
570* pda buffer containing raw PDA bytes
571* pdrec ptr to an array of pdrec_t's. Will be filled on exit.
572* nrec ptr to a variable that will contain the count of PDRs
573*
574* Returns:
575* 0 - success
576* ~0 - failure (probably an errno)
577----------------------------------------------------------------*/
297f06ce 578int mkpdrlist(pda_t *pda)
76e3e7c4 579{
75f49e07
MT
580 int result = 0;
581 u16 *pda16 = (u16 *) pda->buf;
582 int curroff; /* in 'words' */
76e3e7c4
KR
583
584 pda->nrec = 0;
585 curroff = 0;
75f49e07
MT
586 while (curroff < (HFA384x_PDA_LEN_MAX / 2) &&
587 le16_to_cpu(pda16[curroff + 1]) != HFA384x_PDR_END_OF_PDA) {
5dd8acc8 588 pda->rec[pda->nrec] = (hfa384x_pdrec_t *) &(pda16[curroff]);
76e3e7c4 589
75f49e07 590 if (le16_to_cpu(pda->rec[pda->nrec]->code) == HFA384x_PDR_NICID) {
76e3e7c4
KR
591 memcpy(&nicid, &pda->rec[pda->nrec]->data.nicid,
592 sizeof(nicid));
593 nicid.id = le16_to_cpu(nicid.id);
594 nicid.variant = le16_to_cpu(nicid.variant);
595 nicid.major = le16_to_cpu(nicid.major);
596 nicid.minor = le16_to_cpu(nicid.minor);
597 }
598 if (le16_to_cpu(pda->rec[pda->nrec]->code) ==
75f49e07 599 HFA384x_PDR_MFISUPRANGE) {
76e3e7c4
KR
600 memcpy(&rfid, &pda->rec[pda->nrec]->data.mfisuprange,
601 sizeof(rfid));
602 rfid.id = le16_to_cpu(rfid.id);
603 rfid.variant = le16_to_cpu(rfid.variant);
604 rfid.bottom = le16_to_cpu(rfid.bottom);
605 rfid.top = le16_to_cpu(rfid.top);
606 }
607 if (le16_to_cpu(pda->rec[pda->nrec]->code) ==
75f49e07 608 HFA384x_PDR_CFISUPRANGE) {
76e3e7c4
KR
609 memcpy(&macid, &pda->rec[pda->nrec]->data.cfisuprange,
610 sizeof(macid));
611 macid.id = le16_to_cpu(macid.id);
612 macid.variant = le16_to_cpu(macid.variant);
613 macid.bottom = le16_to_cpu(macid.bottom);
614 macid.top = le16_to_cpu(macid.top);
615 }
616
617 (pda->nrec)++;
618 curroff += le16_to_cpu(pda16[curroff]) + 1;
619
620 }
75f49e07 621 if (curroff >= (HFA384x_PDA_LEN_MAX / 2)) {
76e3e7c4 622 printk(KERN_ERR
75f49e07
MT
623 "no end record found or invalid lengths in "
624 "PDR data, exiting. %x %d\n", curroff, pda->nrec);
5dd8acc8 625 return 1;
76e3e7c4 626 }
75f49e07 627 if (le16_to_cpu(pda16[curroff + 1]) == HFA384x_PDR_END_OF_PDA) {
5dd8acc8 628 pda->rec[pda->nrec] = (hfa384x_pdrec_t *) &(pda16[curroff]);
76e3e7c4
KR
629 (pda->nrec)++;
630 }
631 return result;
632}
633
76e3e7c4
KR
634/*----------------------------------------------------------------
635* plugimage
636*
637* Plugs the given image using the given plug records from the given
638* PDA and filename.
639*
640* Arguments:
641* fchunk Array of image chunks
642* nfchunks Number of image chunks
643* s3plug Array of plug records
644* ns3plug Number of plug records
645* pda Current pda data
646*
647* Returns:
648* 0 success
649* ~0 failure
650----------------------------------------------------------------*/
297f06ce
MT
651int plugimage(imgchunk_t *fchunk, unsigned int nfchunks,
652 s3plugrec_t *s3plug, unsigned int ns3plug, pda_t * pda)
76e3e7c4 653{
75f49e07
MT
654 int result = 0;
655 int i; /* plug index */
656 int j; /* index of PDR or -1 if fname plug */
657 int c; /* chunk index */
658 u32 pstart;
659 u32 pend;
660 u32 cstart = 0;
661 u32 cend;
662 u32 chunkoff;
663 u8 *dest;
76e3e7c4
KR
664
665 /* for each plug record */
75f49e07 666 for (i = 0; i < ns3plug; i++) {
76e3e7c4 667 pstart = s3plug[i].addr;
75f49e07 668 pend = s3plug[i].addr + s3plug[i].len;
76e3e7c4 669 /* find the matching PDR (or filename) */
75f49e07
MT
670 if (s3plug[i].itemcode != 0xffffffffUL) { /* not filename */
671 for (j = 0; j < pda->nrec; j++) {
672 if (s3plug[i].itemcode ==
673 le16_to_cpu(pda->rec[j]->code))
674 break;
76e3e7c4
KR
675 }
676 } else {
677 j = -1;
678 }
75f49e07 679 if (j >= pda->nrec && j != -1) { /* if no matching PDR, fail */
76e3e7c4 680 printk(KERN_WARNING
75f49e07
MT
681 "warning: Failed to find PDR for "
682 "plugrec 0x%04x.\n", s3plug[i].itemcode);
683 continue; /* and move on to the next PDR */
76e3e7c4
KR
684#if 0
685 /* MSM: They swear that unless it's the MAC address,
686 * the serial number, or the TX calibration records,
687 * then there's reasonable defaults in the f/w
688 * image. Therefore, missing PDRs in the card
689 * should only be a warning, not fatal.
690 * TODO: add fatals for the PDRs mentioned above.
691 */
692 result = 1;
693 continue;
694#endif
695 }
696
697 /* Validate plug len against PDR len */
75f49e07 698 if (j != -1 && s3plug[i].len < le16_to_cpu(pda->rec[j]->len)) {
76e3e7c4 699 printk(KERN_ERR
75f49e07
MT
700 "error: Plug vs. PDR len mismatch for "
701 "plugrec 0x%04x, abort plugging.\n",
702 s3plug[i].itemcode);
76e3e7c4
KR
703 result = 1;
704 continue;
705 }
706
707 /* Validate plug address against chunk data and identify chunk */
75f49e07 708 for (c = 0; c < nfchunks; c++) {
76e3e7c4 709 cstart = fchunk[c].addr;
75f49e07
MT
710 cend = fchunk[c].addr + fchunk[c].len;
711 if (pstart >= cstart && pend <= cend)
712 break;
76e3e7c4 713 }
75f49e07 714 if (c >= nfchunks) {
76e3e7c4 715 printk(KERN_ERR
75f49e07
MT
716 "error: Failed to find image chunk for "
717 "plugrec 0x%04x.\n", s3plug[i].itemcode);
76e3e7c4
KR
718 result = 1;
719 continue;
720 }
721
722 /* Plug data */
723 chunkoff = pstart - cstart;
724 dest = fchunk[c].data + chunkoff;
725 pr_debug("Plugging item 0x%04x @ 0x%06x, len=%d, "
75f49e07
MT
726 "cnum=%d coff=0x%06x\n",
727 s3plug[i].itemcode, pstart, s3plug[i].len,
728 c, chunkoff);
76e3e7c4 729
75f49e07 730 if (j == -1) { /* plug the filename */
76e3e7c4
KR
731 memset(dest, 0, s3plug[i].len);
732 strncpy(dest, PRISM2_USB_FWFILE, s3plug[i].len - 1);
75f49e07
MT
733 } else { /* plug a PDR */
734 memcpy(dest, &(pda->rec[j]->data), s3plug[i].len);
76e3e7c4
KR
735 }
736 }
737 return result;
738
739}
740
76e3e7c4
KR
741/*----------------------------------------------------------------
742* read_cardpda
743*
744* Sends the command for the driver to read the pda from the card
745* named in the device variable. Upon success, the card pda is
746* stored in the "cardpda" variables. Note that the pda structure
747* is considered 'well formed' after this function. That means
748* that the nrecs is valid, the rec array has been set up, and there's
749* a valid PDAEND record in the raw PDA data.
750*
751* Arguments:
752* pda pda structure
753* wlandev device
754*
755* Returns:
756* 0 - success
757* ~0 - failure (probably an errno)
758----------------------------------------------------------------*/
297f06ce 759int read_cardpda(pda_t *pda, wlandevice_t *wlandev)
76e3e7c4 760{
75f49e07
MT
761 int result = 0;
762 p80211msg_p2req_readpda_t msg;
76e3e7c4
KR
763
764 /* set up the msg */
765 msg.msgcode = DIDmsg_p2req_readpda;
766 msg.msglen = sizeof(msg);
767 strcpy(msg.devname, wlandev->name);
768 msg.pda.did = DIDmsg_p2req_readpda_pda;
769 msg.pda.len = HFA384x_PDA_LEN_MAX;
770 msg.pda.status = P80211ENUM_msgitem_status_no_value;
771 msg.resultcode.did = DIDmsg_p2req_readpda_resultcode;
772 msg.resultcode.len = sizeof(u32);
773 msg.resultcode.status = P80211ENUM_msgitem_status_no_value;
774
75f49e07 775 if (prism2mgmt_readpda(wlandev, &msg) != 0) {
76e3e7c4
KR
776 /* prism2mgmt_readpda prints an errno if appropriate */
777 result = -1;
75f49e07 778 } else if (msg.resultcode.data == P80211ENUM_resultcode_success) {
76e3e7c4
KR
779 memcpy(pda->buf, msg.pda.data, HFA384x_PDA_LEN_MAX);
780 result = mkpdrlist(pda);
781 } else {
782 /* resultcode must've been something other than success */
783 result = -1;
784 }
785
786 return result;
787}
788
76e3e7c4 789/*----------------------------------------------------------------
d8950599 790* read_fwfile
76e3e7c4 791*
d8950599
KR
792* Reads the given fw file which should have been compiled from an srec
793* file. Each record in the fw file will either be a plain data record,
794* a start address record, or other records used for plugging.
76e3e7c4 795*
d8950599
KR
796* Note that data records are expected to be sorted into
797* ascending address order in the fw file.
76e3e7c4 798*
d8950599
KR
799* Note also that the start address record, originally an S7 record in
800* the srec file, is expected in the fw file to be like a data record but
801* with a certain address to make it identiable.
76e3e7c4 802*
d8950599 803* Here's the SREC format that the fw should have come from:
76e3e7c4
KR
804* S[37]nnaaaaaaaaddd...dddcc
805*
806* nn - number of bytes starting with the address field
807* aaaaaaaa - address in readable (or big endian) format
808* dd....dd - 0-245 data bytes (two chars per byte)
809* cc - checksum
810*
811* The S7 record's (there should be only one) address value gets
d8950599
KR
812* converted to an S3 record with address of 0xff400000, with the
813* start address being stored as a 4 byte data word. That address is
814* the start execution address used for RAM downloads.
76e3e7c4
KR
815*
816* The S3 records have a collection of subformats indicated by the
817* value of aaaaaaaa:
818* 0xff000000 - Plug record, data field format:
819* xxxxxxxxaaaaaaaassssssss
820* x - PDR code number (little endian)
821* a - Address in load image to plug (little endian)
822* s - Length of plug data area (little endian)
823*
824* 0xff100000 - CRC16 generation record, data field format:
825* aaaaaaaassssssssbbbbbbbb
826* a - Start address for CRC calculation (little endian)
827* s - Length of data to calculate over (little endian)
828* b - Boolean, true=write crc, false=don't write
829*
830* 0xff200000 - Info record, data field format:
831* ssssttttdd..dd
832* s - Size in words (little endian)
833* t - Info type (little endian), see #defines and
834* s3inforec_t for details about types.
835* d - (s - 1) little endian words giving the contents of
836* the given info type.
837*
d8950599
KR
838* 0xff400000 - Start address record, data field format:
839* aaaaaaaa
840* a - Address in load image to plug (little endian)
841*
76e3e7c4 842* Arguments:
d8950599 843* record firmware image (ihex record structure) in kernel memory
76e3e7c4
KR
844*
845* Returns:
846* 0 - success
847* ~0 - failure (probably an errno)
848----------------------------------------------------------------*/
d8950599 849int read_fwfile(const struct ihex_binrec *record)
76e3e7c4 850{
d8950599
KR
851 int i;
852 int rcnt = 0;
853 u16 *tmpinfo;
854 u16 *ptr16;
855 u32 *ptr32, len, addr;
76e3e7c4 856
d8950599 857 pr_debug("Reading fw file ...\n");
76e3e7c4 858
d8950599
KR
859 while (record) {
860
861 rcnt++;
862
863 len = be16_to_cpu(record->len);
864 addr = be32_to_cpu(record->addr);
865
866 /* Point into data for different word lengths */
867 ptr32 = (u32 *) record->data;
868 ptr16 = (u16 *) record->data;
869
870 /* parse what was an S3 srec and put it in the right array */
5dd8acc8 871 switch (addr) {
d8950599
KR
872 case S3ADDR_START:
873 startaddr = *ptr32;
874 pr_debug(" S7 start addr, record=%d "
875 " addr=0x%08x\n",
876 rcnt,
877 startaddr);
878 break;
879 case S3ADDR_PLUG:
880 s3plug[ns3plug].itemcode = *ptr32;
881 s3plug[ns3plug].addr = *(ptr32 + 1);
882 s3plug[ns3plug].len = *(ptr32 + 2);
883
884 pr_debug(" S3 plugrec, record=%d "
885 "itemcode=0x%08x addr=0x%08x len=%d\n",
886 rcnt,
887 s3plug[ns3plug].itemcode,
888 s3plug[ns3plug].addr,
889 s3plug[ns3plug].len);
890
891 ns3plug++;
5dd8acc8 892 if (ns3plug == S3PLUG_MAX) {
d8950599
KR
893 printk(KERN_ERR "S3 plugrec limit reached - aborting\n");
894 return 1;
76e3e7c4 895 }
d8950599
KR
896 break;
897 case S3ADDR_CRC:
898 s3crc[ns3crc].addr = *ptr32;
899 s3crc[ns3crc].len = *(ptr32 + 1);
900 s3crc[ns3crc].dowrite = *(ptr32 + 2);
901
902 pr_debug(" S3 crcrec, record=%d "
903 "addr=0x%08x len=%d write=0x%08x\n",
904 rcnt,
905 s3crc[ns3crc].addr,
906 s3crc[ns3crc].len,
907 s3crc[ns3crc].dowrite);
908 ns3crc++;
5dd8acc8 909 if (ns3crc == S3CRC_MAX) {
d8950599
KR
910 printk(KERN_ERR "S3 crcrec limit reached - aborting\n");
911 return 1;
912 }
913 break;
914 case S3ADDR_INFO:
915 s3info[ns3info].len = *ptr16;
916 s3info[ns3info].type = *(ptr16 + 1);
917
918 pr_debug(" S3 inforec, record=%d "
919 "len=0x%04x type=0x%04x\n",
920 rcnt,
921 s3info[ns3info].len,
922 s3info[ns3info].type);
5dd8acc8 923 if (((s3info[ns3info].len - 1) * sizeof(u16)) > sizeof(s3info[ns3info].info)) {
d8950599
KR
924 printk(KERN_ERR " S3 inforec length too long - aborting\n");
925 return 1;
926 }
927
5dd8acc8 928 tmpinfo = (u16 *)&(s3info[ns3info].info.version);
d8950599
KR
929 pr_debug(" info=");
930 for (i = 0; i < s3info[ns3info].len - 1; i++) {
931 tmpinfo[i] = *(ptr16 + 2 + i);
932 pr_debug("%04x ", tmpinfo[i]);
933 }
934 pr_debug("\n");
935
936 ns3info++;
5dd8acc8 937 if (ns3info == S3INFO_MAX) {
d8950599
KR
938 printk(KERN_ERR "S3 inforec limit reached - aborting\n");
939 return 1;
940 }
941 break;
942 default: /* Data record */
943 s3data[ns3data].addr = addr;
944 s3data[ns3data].len = len;
945 s3data[ns3data].data = (uint8_t *) record->data;
946 ns3data++;
5dd8acc8 947 if (ns3data == S3DATA_MAX) {
d8950599
KR
948 printk(KERN_ERR "S3 datarec limit reached - aborting\n");
949 return 1;
950 }
951 break;
76e3e7c4 952 }
d8950599 953 record = ihex_next_binrec(record);
76e3e7c4 954 }
d8950599 955 return 0;
76e3e7c4
KR
956}
957
76e3e7c4
KR
958/*----------------------------------------------------------------
959* writeimage
960*
961* Takes the chunks, builds p80211 messages and sends them down
962* to the driver for writing to the card.
963*
964* Arguments:
965* wlandev device
966* fchunk Array of image chunks
967* nfchunks Number of image chunks
968*
969* Returns:
970* 0 success
971* ~0 failure
972----------------------------------------------------------------*/
297f06ce 973int writeimage(wlandevice_t *wlandev, imgchunk_t *fchunk,
75f49e07 974 unsigned int nfchunks)
76e3e7c4 975{
75f49e07
MT
976 int result = 0;
977 p80211msg_p2req_ramdl_state_t rstatemsg;
978 p80211msg_p2req_ramdl_write_t rwritemsg;
979 p80211msg_t *msgp;
980 u32 resultcode;
981 int i;
982 int j;
983 unsigned int nwrites;
984 u32 curroff;
985 u32 currlen;
986 u32 currdaddr;
76e3e7c4
KR
987
988 /* Initialize the messages */
989 memset(&rstatemsg, 0, sizeof(rstatemsg));
990 strcpy(rstatemsg.devname, wlandev->name);
75f49e07
MT
991 rstatemsg.msgcode = DIDmsg_p2req_ramdl_state;
992 rstatemsg.msglen = sizeof(rstatemsg);
993 rstatemsg.enable.did = DIDmsg_p2req_ramdl_state_enable;
994 rstatemsg.exeaddr.did = DIDmsg_p2req_ramdl_state_exeaddr;
995 rstatemsg.resultcode.did = DIDmsg_p2req_ramdl_state_resultcode;
996 rstatemsg.enable.status = P80211ENUM_msgitem_status_data_ok;
997 rstatemsg.exeaddr.status = P80211ENUM_msgitem_status_data_ok;
998 rstatemsg.resultcode.status = P80211ENUM_msgitem_status_no_value;
999 rstatemsg.enable.len = sizeof(u32);
1000 rstatemsg.exeaddr.len = sizeof(u32);
1001 rstatemsg.resultcode.len = sizeof(u32);
76e3e7c4
KR
1002
1003 memset(&rwritemsg, 0, sizeof(rwritemsg));
1004 strcpy(rwritemsg.devname, wlandev->name);
75f49e07
MT
1005 rwritemsg.msgcode = DIDmsg_p2req_ramdl_write;
1006 rwritemsg.msglen = sizeof(rwritemsg);
1007 rwritemsg.addr.did = DIDmsg_p2req_ramdl_write_addr;
1008 rwritemsg.len.did = DIDmsg_p2req_ramdl_write_len;
1009 rwritemsg.data.did = DIDmsg_p2req_ramdl_write_data;
1010 rwritemsg.resultcode.did = DIDmsg_p2req_ramdl_write_resultcode;
1011 rwritemsg.addr.status = P80211ENUM_msgitem_status_data_ok;
1012 rwritemsg.len.status = P80211ENUM_msgitem_status_data_ok;
1013 rwritemsg.data.status = P80211ENUM_msgitem_status_data_ok;
1014 rwritemsg.resultcode.status = P80211ENUM_msgitem_status_no_value;
1015 rwritemsg.addr.len = sizeof(u32);
1016 rwritemsg.len.len = sizeof(u32);
1017 rwritemsg.data.len = WRITESIZE_MAX;
1018 rwritemsg.resultcode.len = sizeof(u32);
76e3e7c4
KR
1019
1020 /* Send xxx_state(enable) */
1021 pr_debug("Sending dl_state(enable) message.\n");
1022 rstatemsg.enable.data = P80211ENUM_truth_true;
1023 rstatemsg.exeaddr.data = startaddr;
1024
5dd8acc8 1025 msgp = (p80211msg_t *) &rstatemsg;
76e3e7c4 1026 result = prism2mgmt_ramdl_state(wlandev, msgp);
75f49e07 1027 if (result) {
76e3e7c4 1028 printk(KERN_ERR
75f49e07
MT
1029 "writeimage state enable failed w/ result=%d, "
1030 "aborting download\n", result);
76e3e7c4
KR
1031 return result;
1032 }
1033 resultcode = rstatemsg.resultcode.data;
75f49e07 1034 if (resultcode != P80211ENUM_resultcode_success) {
76e3e7c4 1035 printk(KERN_ERR
75f49e07
MT
1036 "writeimage()->xxxdl_state msg indicates failure, "
1037 "w/ resultcode=%d, aborting download.\n", resultcode);
76e3e7c4
KR
1038 return 1;
1039 }
1040
1041 /* Now, loop through the data chunks and send WRITESIZE_MAX data */
75f49e07 1042 for (i = 0; i < nfchunks; i++) {
76e3e7c4
KR
1043 nwrites = fchunk[i].len / WRITESIZE_MAX;
1044 nwrites += (fchunk[i].len % WRITESIZE_MAX) ? 1 : 0;
1045 curroff = 0;
75f49e07 1046 for (j = 0; j < nwrites; j++) {
76e3e7c4 1047 currlen =
75f49e07
MT
1048 (fchunk[i].len - (WRITESIZE_MAX * j)) >
1049 WRITESIZE_MAX ? WRITESIZE_MAX : (fchunk[i].len -
1050 (WRITESIZE_MAX *
1051 j));
76e3e7c4
KR
1052 curroff = j * WRITESIZE_MAX;
1053 currdaddr = fchunk[i].addr + curroff;
1054 /* Setup the message */
1055 rwritemsg.addr.data = currdaddr;
1056 rwritemsg.len.data = currlen;
1057 memcpy(rwritemsg.data.data,
75f49e07 1058 fchunk[i].data + curroff, currlen);
76e3e7c4
KR
1059
1060 /* Send flashdl_write(pda) */
75f49e07
MT
1061 pr_debug
1062 ("Sending xxxdl_write message addr=%06x len=%d.\n",
1063 currdaddr, currlen);
76e3e7c4 1064
5dd8acc8 1065 msgp = (p80211msg_t *) &rwritemsg;
76e3e7c4
KR
1066 result = prism2mgmt_ramdl_write(wlandev, msgp);
1067
1068 /* Check the results */
75f49e07 1069 if (result) {
76e3e7c4 1070 printk(KERN_ERR
75f49e07
MT
1071 "writeimage chunk write failed w/ result=%d, "
1072 "aborting download\n", result);
76e3e7c4
KR
1073 return result;
1074 }
1075 resultcode = rstatemsg.resultcode.data;
75f49e07 1076 if (resultcode != P80211ENUM_resultcode_success) {
76e3e7c4 1077 printk(KERN_ERR
75f49e07
MT
1078 "writeimage()->xxxdl_write msg indicates failure, "
1079 "w/ resultcode=%d, aborting download.\n",
1080 resultcode);
76e3e7c4
KR
1081 return 1;
1082 }
1083
1084 }
1085 }
1086
1087 /* Send xxx_state(disable) */
1088 pr_debug("Sending dl_state(disable) message.\n");
1089 rstatemsg.enable.data = P80211ENUM_truth_false;
1090 rstatemsg.exeaddr.data = 0;
1091
5dd8acc8 1092 msgp = (p80211msg_t *) &rstatemsg;
76e3e7c4 1093 result = prism2mgmt_ramdl_state(wlandev, msgp);
75f49e07 1094 if (result) {
76e3e7c4 1095 printk(KERN_ERR
75f49e07
MT
1096 "writeimage state disable failed w/ result=%d, "
1097 "aborting download\n", result);
76e3e7c4
KR
1098 return result;
1099 }
1100 resultcode = rstatemsg.resultcode.data;
75f49e07 1101 if (resultcode != P80211ENUM_resultcode_success) {
76e3e7c4 1102 printk(KERN_ERR
75f49e07
MT
1103 "writeimage()->xxxdl_state msg indicates failure, "
1104 "w/ resultcode=%d, aborting download.\n", resultcode);
76e3e7c4
KR
1105 return 1;
1106 }
1107 return result;
1108}
1109
76e3e7c4
KR
1110int validate_identity(void)
1111{
1112 int i;
1113 int result = 1;
d8950599 1114 int trump = 0;
76e3e7c4
KR
1115
1116 pr_debug("NIC ID: %#x v%d.%d.%d\n",
75f49e07 1117 nicid.id, nicid.major, nicid.minor, nicid.variant);
76e3e7c4 1118 pr_debug("MFI ID: %#x v%d %d->%d\n",
75f49e07 1119 rfid.id, rfid.variant, rfid.bottom, rfid.top);
76e3e7c4 1120 pr_debug("CFI ID: %#x v%d %d->%d\n",
75f49e07 1121 macid.id, macid.variant, macid.bottom, macid.top);
76e3e7c4 1122 pr_debug("PRI ID: %#x v%d %d->%d\n",
75f49e07 1123 priid.id, priid.variant, priid.bottom, priid.top);
76e3e7c4 1124
75f49e07 1125 for (i = 0; i < ns3info; i++) {
76e3e7c4
KR
1126 switch (s3info[i].type) {
1127 case 1:
1128 pr_debug("Version: ID %#x %d.%d.%d\n",
75f49e07
MT
1129 s3info[i].info.version.id,
1130 s3info[i].info.version.major,
1131 s3info[i].info.version.minor,
1132 s3info[i].info.version.variant);
76e3e7c4
KR
1133 break;
1134 case 2:
1135 pr_debug("Compat: Role %#x Id %#x v%d %d->%d\n",
75f49e07
MT
1136 s3info[i].info.compat.role,
1137 s3info[i].info.compat.id,
1138 s3info[i].info.compat.variant,
1139 s3info[i].info.compat.bottom,
1140 s3info[i].info.compat.top);
76e3e7c4
KR
1141
1142 /* MAC compat range */
1143 if ((s3info[i].info.compat.role == 1) &&
1144 (s3info[i].info.compat.id == 2)) {
1145 if (s3info[i].info.compat.variant !=
1146 macid.variant) {
1147 result = 2;
1148 }
1149 }
1150
1151 /* PRI compat range */
1152 if ((s3info[i].info.compat.role == 1) &&
1153 (s3info[i].info.compat.id == 3)) {
75f49e07
MT
1154 if ((s3info[i].info.compat.bottom > priid.top)
1155 || (s3info[i].info.compat.top <
1156 priid.bottom)) {
76e3e7c4
KR
1157 result = 3;
1158 }
1159 }
1160 /* SEC compat range */
1161 if ((s3info[i].info.compat.role == 1) &&
1162 (s3info[i].info.compat.id == 4)) {
b02957d5 1163 /* FIXME: isn't something missing here? */
76e3e7c4
KR
1164 }
1165
1166 break;
1167 case 3:
75f49e07 1168 pr_debug("Seq: %#x\n", s3info[i].info.buildseq);
76e3e7c4 1169
75f49e07 1170 break;
76e3e7c4
KR
1171 case 4:
1172 pr_debug("Platform: ID %#x %d.%d.%d\n",
75f49e07
MT
1173 s3info[i].info.version.id,
1174 s3info[i].info.version.major,
1175 s3info[i].info.version.minor,
1176 s3info[i].info.version.variant);
76e3e7c4
KR
1177
1178 if (nicid.id != s3info[i].info.version.id)
1179 continue;
1180 if (nicid.major != s3info[i].info.version.major)
1181 continue;
1182 if (nicid.minor != s3info[i].info.version.minor)
1183 continue;
1184 if ((nicid.variant != s3info[i].info.version.variant) &&
1185 (nicid.id != 0x8008))
1186 continue;
1187
d8950599 1188 trump = 1;
76e3e7c4
KR
1189 break;
1190 case 0x8001:
1191 pr_debug("name inforec len %d\n", s3info[i].len);
1192
1193 break;
1194 default:
1195 pr_debug("Unknown inforec type %d\n", s3info[i].type);
1196 }
1197 }
5dd8acc8 1198 /* walk through */
76e3e7c4 1199
5dd8acc8
SK
1200 if (trump && (result != 2))
1201 result = 0;
76e3e7c4
KR
1202 return result;
1203}