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