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