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