1 // SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
2 /* from src/prism2/download/prism2dl.c
4 * utility for downloading prism2 images moved into kernelspace
6 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
7 * --------------------------------------------------------------------
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/
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.
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.
32 * --------------------------------------------------------------------
34 * Inquiries regarding the linux-wlan Open Source project can be
37 * AbsoluteValue Systems Inc.
39 * http://www.linux-wlan.com
41 * --------------------------------------------------------------------
43 * Portions of the development of this software were funded by
44 * Intersil Corporation as part of PRISM(R) chipset product development.
46 * --------------------------------------------------------------------
49 /*================================================================*/
51 #include <linux/ihex.h>
52 #include <linux/slab.h>
54 /*================================================================*/
57 #define PRISM2_USB_FWFILE "prism2_ru.fw"
58 MODULE_FIRMWARE(PRISM2_USB_FWFILE
);
60 #define S3DATA_MAX 5000
61 #define S3PLUG_MAX 200
65 #define S3ADDR_PLUG (0xff000000UL)
66 #define S3ADDR_CRC (0xff100000UL)
67 #define S3ADDR_INFO (0xff200000UL)
68 #define S3ADDR_START (0xff400000UL)
70 #define CHUNKS_MAX 100
72 #define WRITESIZE_MAX 4096
74 /*================================================================*/
100 struct hfa384x_compident version
;
101 struct hfa384x_caplevel compat
;
103 struct hfa384x_compident platform
;
108 u8 buf
[HFA384x_PDA_LEN_MAX
];
109 struct hfa384x_pdrec
*rec
[HFA384x_PDA_RECS_MAX
];
114 u32 addr
; /* start address */
115 u32 len
; /* in bytes */
116 u16 crc
; /* CRC value (if it falls at a chunk boundary) */
120 /*================================================================*/
121 /* Local Static Definitions */
123 /*----------------------------------------------------------------*/
124 /* s-record image processing */
127 static unsigned int ns3data
;
128 static struct s3datarec
*s3data
;
131 static unsigned int ns3plug
;
132 static struct s3plugrec s3plug
[S3PLUG_MAX
];
135 static unsigned int ns3crc
;
136 static struct s3crcrec s3crc
[S3CRC_MAX
];
139 static unsigned int ns3info
;
140 static struct s3inforec s3info
[S3INFO_MAX
];
142 /* S7 record (there _better_ be only one) */
143 static u32 startaddr
;
145 /* Load image chunks */
146 static unsigned int nfchunks
;
147 static struct imgchunk fchunk
[CHUNKS_MAX
];
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...] */
155 static struct pda pda
;
156 static struct hfa384x_compident nicid
;
157 static struct hfa384x_caplevel rfid
;
158 static struct hfa384x_caplevel macid
;
159 static struct hfa384x_caplevel priid
;
161 /*================================================================*/
162 /* Local Function Declarations */
164 static int prism2_fwapply(const struct ihex_binrec
*rfptr
,
165 struct wlandevice
*wlandev
);
167 static int read_fwfile(const struct ihex_binrec
*rfptr
);
169 static int mkimage(struct imgchunk
*clist
, unsigned int *ccnt
);
171 static int read_cardpda(struct pda
*pda
, struct wlandevice
*wlandev
);
173 static int mkpdrlist(struct pda
*pda
);
175 static int plugimage(struct imgchunk
*fchunk
, unsigned int nfchunks
,
176 struct s3plugrec
*s3plug
, unsigned int ns3plug
,
179 static int crcimage(struct imgchunk
*fchunk
, unsigned int nfchunks
,
180 struct s3crcrec
*s3crc
, unsigned int ns3crc
);
182 static int writeimage(struct wlandevice
*wlandev
, struct imgchunk
*fchunk
,
183 unsigned int nfchunks
);
185 static void free_chunks(struct imgchunk
*fchunk
, unsigned int *nfchunks
);
187 static void free_srecs(void);
189 static int validate_identity(void);
191 /*================================================================*/
192 /* Function Definitions */
194 /*----------------------------------------------------------------
197 * Try and get firmware into memory
200 * udev usb device structure
201 * wlandev wlan device structure
206 *----------------------------------------------------------------
208 static int prism2_fwtry(struct usb_device
*udev
, struct wlandevice
*wlandev
)
210 const struct firmware
*fw_entry
= NULL
;
212 netdev_info(wlandev
->netdev
, "prism2_usb: Checking for firmware %s\n",
214 if (request_ihex_firmware(&fw_entry
,
215 PRISM2_USB_FWFILE
, &udev
->dev
) != 0) {
216 netdev_info(wlandev
->netdev
,
217 "prism2_usb: Firmware not available, but not essential\n");
218 netdev_info(wlandev
->netdev
,
219 "prism2_usb: can continue to use card anyway.\n");
223 netdev_info(wlandev
->netdev
,
224 "prism2_usb: %s will be processed, size %zu\n",
225 PRISM2_USB_FWFILE
, fw_entry
->size
);
226 prism2_fwapply((const struct ihex_binrec
*)fw_entry
->data
, wlandev
);
228 release_firmware(fw_entry
);
232 /*----------------------------------------------------------------
235 * Apply the firmware loaded into memory
238 * rfptr firmware image in kernel memory
244 *----------------------------------------------------------------
246 static int prism2_fwapply(const struct ihex_binrec
*rfptr
,
247 struct wlandevice
*wlandev
)
249 signed int result
= 0;
250 struct p80211msg_dot11req_mibget getmsg
;
251 struct p80211itemd
*item
;
254 /* Initialize the data structures */
256 s3data
= kcalloc(S3DATA_MAX
, sizeof(*s3data
), GFP_KERNEL
);
263 memset(s3plug
, 0, sizeof(s3plug
));
265 memset(s3crc
, 0, sizeof(s3crc
));
267 memset(s3info
, 0, sizeof(s3info
));
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
));
277 /* clear the pda and add an initial END record */
278 memset(&pda
, 0, sizeof(pda
));
279 pda
.rec
[0] = (struct hfa384x_pdrec
*)pda
.buf
;
280 pda
.rec
[0]->len
= cpu_to_le16(2); /* len in words */
281 pda
.rec
[0]->code
= cpu_to_le16(HFA384x_PDR_END_OF_PDA
);
284 /*-----------------------------------------------------*/
285 /* Put card into fwload state */
286 prism2sta_ifstate(wlandev
, P80211ENUM_ifstate_fwload
);
288 /* Build the PDA we're going to use. */
289 if (read_cardpda(&pda
, wlandev
)) {
290 netdev_err(wlandev
->netdev
, "load_cardpda failed, exiting.\n");
295 /* read the card's PRI-SUP */
296 memset(&getmsg
, 0, sizeof(getmsg
));
297 getmsg
.msgcode
= DIDMSG_DOT11REQ_MIBGET
;
298 getmsg
.msglen
= sizeof(getmsg
);
299 strcpy(getmsg
.devname
, wlandev
->name
);
301 getmsg
.mibattribute
.did
= DIDMSG_DOT11REQ_MIBGET_MIBATTRIBUTE
;
302 getmsg
.mibattribute
.status
= P80211ENUM_msgitem_status_data_ok
;
303 getmsg
.resultcode
.did
= DIDMSG_DOT11REQ_MIBGET_RESULTCODE
;
304 getmsg
.resultcode
.status
= P80211ENUM_msgitem_status_no_value
;
306 item
= (struct p80211itemd
*)getmsg
.mibattribute
.data
;
307 item
->did
= DIDMIB_P2_NIC_PRISUPRANGE
;
308 item
->status
= P80211ENUM_msgitem_status_no_value
;
310 data
= (u32
*)item
->data
;
312 /* DIDmsg_dot11req_mibget */
313 prism2mgmt_mibset_mibget(wlandev
, &getmsg
);
314 if (getmsg
.resultcode
.data
!= P80211ENUM_resultcode_success
)
315 netdev_err(wlandev
->netdev
, "Couldn't fetch PRI-SUP info\n");
317 /* Already in host order */
318 priid
.role
= *data
++;
320 priid
.variant
= *data
++;
321 priid
.bottom
= *data
++;
324 /* Read the S3 file */
325 result
= read_fwfile(rfptr
);
327 netdev_err(wlandev
->netdev
,
328 "Failed to read the data exiting.\n");
332 result
= validate_identity();
334 netdev_err(wlandev
->netdev
, "Incompatible firmware image.\n");
338 if (startaddr
== 0x00000000) {
339 netdev_err(wlandev
->netdev
,
340 "Can't RAM download a Flash image!\n");
345 /* Make the image chunks */
346 result
= mkimage(fchunk
, &nfchunks
);
348 netdev_err(wlandev
->netdev
, "Failed to make image chunk.\n");
352 /* Do any plugging */
353 result
= plugimage(fchunk
, nfchunks
, s3plug
, ns3plug
, &pda
);
355 netdev_err(wlandev
->netdev
, "Failed to plug data.\n");
359 /* Insert any CRCs */
360 result
= crcimage(fchunk
, nfchunks
, s3crc
, ns3crc
);
362 netdev_err(wlandev
->netdev
, "Failed to insert all CRCs\n");
366 /* Write the image */
367 result
= writeimage(wlandev
, fchunk
, nfchunks
);
369 netdev_err(wlandev
->netdev
, "Failed to ramwrite image data.\n");
373 netdev_info(wlandev
->netdev
, "prism2_usb: firmware loading finished.\n");
376 /* clear any allocated memory */
377 free_chunks(fchunk
, &nfchunks
);
384 /*----------------------------------------------------------------
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.
392 * fchunk Array of image chunks
393 * nfchunks Number of image chunks
394 * s3crc Array of crc records
395 * ns3crc Number of crc records
400 *----------------------------------------------------------------
402 static int crcimage(struct imgchunk
*fchunk
, unsigned int nfchunks
,
403 struct s3crcrec
*s3crc
, unsigned int ns3crc
)
414 for (i
= 0; i
< ns3crc
; i
++) {
415 if (!s3crc
[i
].dowrite
)
417 crcstart
= s3crc
[i
].addr
;
419 for (c
= 0; c
< nfchunks
; c
++) {
420 cstart
= fchunk
[c
].addr
;
421 cend
= fchunk
[c
].addr
+ fchunk
[c
].len
;
422 /* the line below does an address & len match search */
423 /* unfortunately, I've found that the len fields of */
424 /* some crc records don't match with the length of */
425 /* the actual data, so we're not checking right now */
426 /* if (crcstart-2 >= cstart && crcend <= cend) break; */
428 /* note the -2 below, it's to make sure the chunk has */
429 /* space for the CRC value */
430 if (crcstart
- 2 >= cstart
&& crcstart
< cend
)
434 pr_err("Failed to find chunk for crcrec[%d], addr=0x%06x len=%d , aborting crc.\n",
435 i
, s3crc
[i
].addr
, s3crc
[i
].len
);
440 pr_debug("Adding crc @ 0x%06x\n", s3crc
[i
].addr
- 2);
441 chunkoff
= crcstart
- cstart
- 2;
442 dest
= fchunk
[c
].data
+ chunkoff
;
449 /*----------------------------------------------------------------
452 * Clears the chunklist data structures in preparation for a new file.
459 *----------------------------------------------------------------
461 static void free_chunks(struct imgchunk
*fchunk
, unsigned int *nfchunks
)
465 for (i
= 0; i
< *nfchunks
; i
++)
466 kfree(fchunk
[i
].data
);
469 memset(fchunk
, 0, sizeof(*fchunk
));
472 /*----------------------------------------------------------------
475 * Clears the srec data structures in preparation for a new file.
482 *----------------------------------------------------------------
484 static void free_srecs(void)
489 memset(s3plug
, 0, sizeof(s3plug
));
491 memset(s3crc
, 0, sizeof(s3crc
));
493 memset(s3info
, 0, sizeof(s3info
));
497 /*----------------------------------------------------------------
500 * Scans the currently loaded set of S records for data residing
501 * in contiguous memory regions. Each contiguous region is then
502 * made into a 'chunk'. This function assumes that we're building
503 * a new chunk list. Assumes the s3data items are in sorted order.
509 * ~0 - failure (probably an errno)
510 *----------------------------------------------------------------
512 static int mkimage(struct imgchunk
*clist
, unsigned int *ccnt
)
525 /* There may already be data in the chunklist */
528 /* Establish the location and size of each chunk */
529 for (i
= 0; i
< ns3data
; i
++) {
530 if (s3data
[i
].addr
== nextaddr
) {
531 /* existing chunk, grow it */
532 clist
[currchunk
].len
+= s3data
[i
].len
;
533 nextaddr
+= s3data
[i
].len
;
537 currchunk
= *ccnt
- 1;
538 clist
[currchunk
].addr
= s3data
[i
].addr
;
539 clist
[currchunk
].len
= s3data
[i
].len
;
540 nextaddr
= s3data
[i
].addr
+ s3data
[i
].len
;
541 /* Expand the chunk if there is a CRC record at */
542 /* their beginning bound */
543 for (j
= 0; j
< ns3crc
; j
++) {
544 if (s3crc
[j
].dowrite
&&
545 s3crc
[j
].addr
== clist
[currchunk
].addr
) {
546 clist
[currchunk
].addr
-= 2;
547 clist
[currchunk
].len
+= 2;
553 /* We're currently assuming there aren't any overlapping chunks */
554 /* if this proves false, we'll need to add code to coalesce. */
556 /* Allocate buffer space for chunks */
557 for (i
= 0; i
< *ccnt
; i
++) {
558 clist
[i
].data
= kzalloc(clist
[i
].len
, GFP_KERNEL
);
562 pr_debug("chunk[%d]: addr=0x%06x len=%d\n",
563 i
, clist
[i
].addr
, clist
[i
].len
);
566 /* Copy srec data to chunks */
567 for (i
= 0; i
< ns3data
; i
++) {
568 s3start
= s3data
[i
].addr
;
569 s3end
= s3start
+ s3data
[i
].len
- 1;
570 for (j
= 0; j
< *ccnt
; j
++) {
571 cstart
= clist
[j
].addr
;
572 cend
= cstart
+ clist
[j
].len
- 1;
573 if (s3start
>= cstart
&& s3end
<= cend
)
576 if (((unsigned int)j
) >= (*ccnt
)) {
577 pr_err("s3rec(a=0x%06x,l=%d), no chunk match, exiting.\n",
578 s3start
, s3data
[i
].len
);
581 coffset
= s3start
- cstart
;
582 memcpy(clist
[j
].data
+ coffset
, s3data
[i
].data
, s3data
[i
].len
);
588 /*----------------------------------------------------------------
591 * Reads a raw PDA and builds an array of pdrec_t structures.
594 * pda buffer containing raw PDA bytes
595 * pdrec ptr to an array of pdrec_t's. Will be filled on exit.
596 * nrec ptr to a variable that will contain the count of PDRs
600 * ~0 - failure (probably an errno)
601 *----------------------------------------------------------------
603 static int mkpdrlist(struct pda
*pda
)
605 __le16
*pda16
= (__le16
*)pda
->buf
;
606 int curroff
; /* in 'words' */
610 while (curroff
< (HFA384x_PDA_LEN_MAX
/ 2 - 1) &&
611 le16_to_cpu(pda16
[curroff
+ 1]) != HFA384x_PDR_END_OF_PDA
) {
612 pda
->rec
[pda
->nrec
] = (struct hfa384x_pdrec
*)&pda16
[curroff
];
614 if (le16_to_cpu(pda
->rec
[pda
->nrec
]->code
) ==
616 memcpy(&nicid
, &pda
->rec
[pda
->nrec
]->data
.nicid
,
618 le16_to_cpus(&nicid
.id
);
619 le16_to_cpus(&nicid
.variant
);
620 le16_to_cpus(&nicid
.major
);
621 le16_to_cpus(&nicid
.minor
);
623 if (le16_to_cpu(pda
->rec
[pda
->nrec
]->code
) ==
624 HFA384x_PDR_MFISUPRANGE
) {
625 memcpy(&rfid
, &pda
->rec
[pda
->nrec
]->data
.mfisuprange
,
627 le16_to_cpus(&rfid
.id
);
628 le16_to_cpus(&rfid
.variant
);
629 le16_to_cpus(&rfid
.bottom
);
630 le16_to_cpus(&rfid
.top
);
632 if (le16_to_cpu(pda
->rec
[pda
->nrec
]->code
) ==
633 HFA384x_PDR_CFISUPRANGE
) {
634 memcpy(&macid
, &pda
->rec
[pda
->nrec
]->data
.cfisuprange
,
636 le16_to_cpus(&macid
.id
);
637 le16_to_cpus(&macid
.variant
);
638 le16_to_cpus(&macid
.bottom
);
639 le16_to_cpus(&macid
.top
);
643 curroff
+= le16_to_cpu(pda16
[curroff
]) + 1;
645 if (curroff
>= (HFA384x_PDA_LEN_MAX
/ 2 - 1)) {
646 pr_err("no end record found or invalid lengths in PDR data, exiting. %x %d\n",
650 pda
->rec
[pda
->nrec
] = (struct hfa384x_pdrec
*)&pda16
[curroff
];
655 /*----------------------------------------------------------------
658 * Plugs the given image using the given plug records from the given
662 * fchunk Array of image chunks
663 * nfchunks Number of image chunks
664 * s3plug Array of plug records
665 * ns3plug Number of plug records
666 * pda Current pda data
671 *----------------------------------------------------------------
673 static int plugimage(struct imgchunk
*fchunk
, unsigned int nfchunks
,
674 struct s3plugrec
*s3plug
, unsigned int ns3plug
,
678 int i
; /* plug index */
679 int j
; /* index of PDR or -1 if fname plug */
680 int c
; /* chunk index */
688 /* for each plug record */
689 for (i
= 0; i
< ns3plug
; i
++) {
690 pstart
= s3plug
[i
].addr
;
691 pend
= s3plug
[i
].addr
+ s3plug
[i
].len
;
692 /* find the matching PDR (or filename) */
693 if (s3plug
[i
].itemcode
!= 0xffffffffUL
) { /* not filename */
694 for (j
= 0; j
< pda
->nrec
; j
++) {
695 if (s3plug
[i
].itemcode
==
696 le16_to_cpu(pda
->rec
[j
]->code
))
702 if (j
>= pda
->nrec
&& j
!= -1) { /* if no matching PDR, fail */
703 pr_warn("warning: Failed to find PDR for plugrec 0x%04x.\n",
705 continue; /* and move on to the next PDR */
707 /* MSM: They swear that unless it's the MAC address,
708 * the serial number, or the TX calibration records,
709 * then there's reasonable defaults in the f/w
710 * image. Therefore, missing PDRs in the card
711 * should only be a warning, not fatal.
712 * TODO: add fatals for the PDRs mentioned above.
716 /* Validate plug len against PDR len */
717 if (j
!= -1 && s3plug
[i
].len
< le16_to_cpu(pda
->rec
[j
]->len
)) {
718 pr_err("error: Plug vs. PDR len mismatch for plugrec 0x%04x, abort plugging.\n",
725 * Validate plug address against
726 * chunk data and identify chunk
728 for (c
= 0; c
< nfchunks
; c
++) {
729 cstart
= fchunk
[c
].addr
;
730 cend
= fchunk
[c
].addr
+ fchunk
[c
].len
;
731 if (pstart
>= cstart
&& pend
<= cend
)
735 pr_err("error: Failed to find image chunk for plugrec 0x%04x.\n",
742 chunkoff
= pstart
- cstart
;
743 dest
= fchunk
[c
].data
+ chunkoff
;
744 pr_debug("Plugging item 0x%04x @ 0x%06x, len=%d, cnum=%d coff=0x%06x\n",
745 s3plug
[i
].itemcode
, pstart
, s3plug
[i
].len
,
748 if (j
== -1) { /* plug the filename */
749 memset(dest
, 0, s3plug
[i
].len
);
750 strncpy(dest
, PRISM2_USB_FWFILE
, s3plug
[i
].len
- 1);
751 } else { /* plug a PDR */
752 memcpy(dest
, &pda
->rec
[j
]->data
, s3plug
[i
].len
);
758 /*----------------------------------------------------------------
761 * Sends the command for the driver to read the pda from the card
762 * named in the device variable. Upon success, the card pda is
763 * stored in the "cardpda" variables. Note that the pda structure
764 * is considered 'well formed' after this function. That means
765 * that the nrecs is valid, the rec array has been set up, and there's
766 * a valid PDAEND record in the raw PDA data.
774 * ~0 - failure (probably an errno)
775 *----------------------------------------------------------------
777 static int read_cardpda(struct pda
*pda
, struct wlandevice
*wlandev
)
780 struct p80211msg_p2req_readpda
*msg
;
782 msg
= kzalloc(sizeof(*msg
), GFP_KERNEL
);
787 msg
->msgcode
= DIDMSG_P2REQ_READPDA
;
788 msg
->msglen
= sizeof(msg
);
789 strcpy(msg
->devname
, wlandev
->name
);
790 msg
->pda
.did
= DIDMSG_P2REQ_READPDA_PDA
;
791 msg
->pda
.len
= HFA384x_PDA_LEN_MAX
;
792 msg
->pda
.status
= P80211ENUM_msgitem_status_no_value
;
793 msg
->resultcode
.did
= DIDMSG_P2REQ_READPDA_RESULTCODE
;
794 msg
->resultcode
.len
= sizeof(u32
);
795 msg
->resultcode
.status
= P80211ENUM_msgitem_status_no_value
;
797 if (prism2mgmt_readpda(wlandev
, msg
) != 0) {
798 /* prism2mgmt_readpda prints an errno if appropriate */
800 } else if (msg
->resultcode
.data
== P80211ENUM_resultcode_success
) {
801 memcpy(pda
->buf
, msg
->pda
.data
, HFA384x_PDA_LEN_MAX
);
802 result
= mkpdrlist(pda
);
804 /* resultcode must've been something other than success */
812 /*----------------------------------------------------------------
815 * Reads the given fw file which should have been compiled from an srec
816 * file. Each record in the fw file will either be a plain data record,
817 * a start address record, or other records used for plugging.
819 * Note that data records are expected to be sorted into
820 * ascending address order in the fw file.
822 * Note also that the start address record, originally an S7 record in
823 * the srec file, is expected in the fw file to be like a data record but
824 * with a certain address to make it identifiable.
826 * Here's the SREC format that the fw should have come from:
827 * S[37]nnaaaaaaaaddd...dddcc
829 * nn - number of bytes starting with the address field
830 * aaaaaaaa - address in readable (or big endian) format
831 * dd....dd - 0-245 data bytes (two chars per byte)
834 * The S7 record's (there should be only one) address value gets
835 * converted to an S3 record with address of 0xff400000, with the
836 * start address being stored as a 4 byte data word. That address is
837 * the start execution address used for RAM downloads.
839 * The S3 records have a collection of subformats indicated by the
841 * 0xff000000 - Plug record, data field format:
842 * xxxxxxxxaaaaaaaassssssss
843 * x - PDR code number (little endian)
844 * a - Address in load image to plug (little endian)
845 * s - Length of plug data area (little endian)
847 * 0xff100000 - CRC16 generation record, data field format:
848 * aaaaaaaassssssssbbbbbbbb
849 * a - Start address for CRC calculation (little endian)
850 * s - Length of data to calculate over (little endian)
851 * b - Boolean, true=write crc, false=don't write
853 * 0xff200000 - Info record, data field format:
855 * s - Size in words (little endian)
856 * t - Info type (little endian), see #defines and
857 * struct s3inforec for details about types.
858 * d - (s - 1) little endian words giving the contents of
859 * the given info type.
861 * 0xff400000 - Start address record, data field format:
863 * a - Address in load image to plug (little endian)
866 * record firmware image (ihex record structure) in kernel memory
870 * ~0 - failure (probably an errno)
871 *----------------------------------------------------------------
873 static int read_fwfile(const struct ihex_binrec
*record
)
879 u32
*ptr32
, len
, addr
;
881 pr_debug("Reading fw file ...\n");
886 len
= be16_to_cpu(record
->len
);
887 addr
= be32_to_cpu(record
->addr
);
889 /* Point into data for different word lengths */
890 ptr32
= (u32
*)record
->data
;
891 ptr16
= (u16
*)record
->data
;
893 /* parse what was an S3 srec and put it in the right array */
897 pr_debug(" S7 start addr, record=%d addr=0x%08x\n",
902 s3plug
[ns3plug
].itemcode
= *ptr32
;
903 s3plug
[ns3plug
].addr
= *(ptr32
+ 1);
904 s3plug
[ns3plug
].len
= *(ptr32
+ 2);
906 pr_debug(" S3 plugrec, record=%d itemcode=0x%08x addr=0x%08x len=%d\n",
908 s3plug
[ns3plug
].itemcode
,
909 s3plug
[ns3plug
].addr
,
910 s3plug
[ns3plug
].len
);
913 if (ns3plug
== S3PLUG_MAX
) {
914 pr_err("S3 plugrec limit reached - aborting\n");
919 s3crc
[ns3crc
].addr
= *ptr32
;
920 s3crc
[ns3crc
].len
= *(ptr32
+ 1);
921 s3crc
[ns3crc
].dowrite
= *(ptr32
+ 2);
923 pr_debug(" S3 crcrec, record=%d addr=0x%08x len=%d write=0x%08x\n",
927 s3crc
[ns3crc
].dowrite
);
929 if (ns3crc
== S3CRC_MAX
) {
930 pr_err("S3 crcrec limit reached - aborting\n");
935 s3info
[ns3info
].len
= *ptr16
;
936 s3info
[ns3info
].type
= *(ptr16
+ 1);
938 pr_debug(" S3 inforec, record=%d len=0x%04x type=0x%04x\n",
941 s3info
[ns3info
].type
);
942 if (((s3info
[ns3info
].len
- 1) * sizeof(u16
)) >
943 sizeof(s3info
[ns3info
].info
)) {
944 pr_err("S3 inforec length too long - aborting\n");
948 tmpinfo
= (u16
*)&s3info
[ns3info
].info
.version
;
950 for (i
= 0; i
< s3info
[ns3info
].len
- 1; i
++) {
951 tmpinfo
[i
] = *(ptr16
+ 2 + i
);
952 pr_debug("%04x ", tmpinfo
[i
]);
957 if (ns3info
== S3INFO_MAX
) {
958 pr_err("S3 inforec limit reached - aborting\n");
962 default: /* Data record */
963 s3data
[ns3data
].addr
= addr
;
964 s3data
[ns3data
].len
= len
;
965 s3data
[ns3data
].data
= (uint8_t *)record
->data
;
967 if (ns3data
== S3DATA_MAX
) {
968 pr_err("S3 datarec limit reached - aborting\n");
973 record
= ihex_next_binrec(record
);
978 /*----------------------------------------------------------------
981 * Takes the chunks, builds p80211 messages and sends them down
982 * to the driver for writing to the card.
986 * fchunk Array of image chunks
987 * nfchunks Number of image chunks
992 *----------------------------------------------------------------
994 static int writeimage(struct wlandevice
*wlandev
, struct imgchunk
*fchunk
,
995 unsigned int nfchunks
)
998 struct p80211msg_p2req_ramdl_state
*rstmsg
;
999 struct p80211msg_p2req_ramdl_write
*rwrmsg
;
1003 unsigned int nwrites
;
1008 rstmsg
= kzalloc(sizeof(*rstmsg
), GFP_KERNEL
);
1009 rwrmsg
= kzalloc(sizeof(*rwrmsg
), GFP_KERNEL
);
1010 if (!rstmsg
|| !rwrmsg
) {
1013 netdev_err(wlandev
->netdev
,
1014 "%s: no memory for firmware download, aborting download\n",
1019 /* Initialize the messages */
1020 strcpy(rstmsg
->devname
, wlandev
->name
);
1021 rstmsg
->msgcode
= DIDMSG_P2REQ_RAMDL_STATE
;
1022 rstmsg
->msglen
= sizeof(*rstmsg
);
1023 rstmsg
->enable
.did
= DIDMSG_P2REQ_RAMDL_STATE_ENABLE
;
1024 rstmsg
->exeaddr
.did
= DIDMSG_P2REQ_RAMDL_STATE_EXEADDR
;
1025 rstmsg
->resultcode
.did
= DIDMSG_P2REQ_RAMDL_STATE_RESULTCODE
;
1026 rstmsg
->enable
.status
= P80211ENUM_msgitem_status_data_ok
;
1027 rstmsg
->exeaddr
.status
= P80211ENUM_msgitem_status_data_ok
;
1028 rstmsg
->resultcode
.status
= P80211ENUM_msgitem_status_no_value
;
1029 rstmsg
->enable
.len
= sizeof(u32
);
1030 rstmsg
->exeaddr
.len
= sizeof(u32
);
1031 rstmsg
->resultcode
.len
= sizeof(u32
);
1033 strcpy(rwrmsg
->devname
, wlandev
->name
);
1034 rwrmsg
->msgcode
= DIDMSG_P2REQ_RAMDL_WRITE
;
1035 rwrmsg
->msglen
= sizeof(*rwrmsg
);
1036 rwrmsg
->addr
.did
= DIDMSG_P2REQ_RAMDL_WRITE_ADDR
;
1037 rwrmsg
->len
.did
= DIDMSG_P2REQ_RAMDL_WRITE_LEN
;
1038 rwrmsg
->data
.did
= DIDMSG_P2REQ_RAMDL_WRITE_DATA
;
1039 rwrmsg
->resultcode
.did
= DIDMSG_P2REQ_RAMDL_WRITE_RESULTCODE
;
1040 rwrmsg
->addr
.status
= P80211ENUM_msgitem_status_data_ok
;
1041 rwrmsg
->len
.status
= P80211ENUM_msgitem_status_data_ok
;
1042 rwrmsg
->data
.status
= P80211ENUM_msgitem_status_data_ok
;
1043 rwrmsg
->resultcode
.status
= P80211ENUM_msgitem_status_no_value
;
1044 rwrmsg
->addr
.len
= sizeof(u32
);
1045 rwrmsg
->len
.len
= sizeof(u32
);
1046 rwrmsg
->data
.len
= WRITESIZE_MAX
;
1047 rwrmsg
->resultcode
.len
= sizeof(u32
);
1049 /* Send xxx_state(enable) */
1050 pr_debug("Sending dl_state(enable) message.\n");
1051 rstmsg
->enable
.data
= P80211ENUM_truth_true
;
1052 rstmsg
->exeaddr
.data
= startaddr
;
1054 result
= prism2mgmt_ramdl_state(wlandev
, rstmsg
);
1056 netdev_err(wlandev
->netdev
,
1057 "%s state enable failed w/ result=%d, aborting download\n",
1061 resultcode
= rstmsg
->resultcode
.data
;
1062 if (resultcode
!= P80211ENUM_resultcode_success
) {
1063 netdev_err(wlandev
->netdev
,
1064 "%s()->xxxdl_state msg indicates failure, w/ resultcode=%d, aborting download.\n",
1065 __func__
, resultcode
);
1070 /* Now, loop through the data chunks and send WRITESIZE_MAX data */
1071 for (i
= 0; i
< nfchunks
; i
++) {
1072 nwrites
= fchunk
[i
].len
/ WRITESIZE_MAX
;
1073 nwrites
+= (fchunk
[i
].len
% WRITESIZE_MAX
) ? 1 : 0;
1075 for (j
= 0; j
< nwrites
; j
++) {
1076 /* TODO Move this to a separate function */
1077 int lenleft
= fchunk
[i
].len
- (WRITESIZE_MAX
* j
);
1079 if (fchunk
[i
].len
> WRITESIZE_MAX
)
1080 currlen
= WRITESIZE_MAX
;
1083 curroff
= j
* WRITESIZE_MAX
;
1084 currdaddr
= fchunk
[i
].addr
+ curroff
;
1085 /* Setup the message */
1086 rwrmsg
->addr
.data
= currdaddr
;
1087 rwrmsg
->len
.data
= currlen
;
1088 memcpy(rwrmsg
->data
.data
,
1089 fchunk
[i
].data
+ curroff
, currlen
);
1091 /* Send flashdl_write(pda) */
1093 ("Sending xxxdl_write message addr=%06x len=%d.\n",
1094 currdaddr
, currlen
);
1096 result
= prism2mgmt_ramdl_write(wlandev
, rwrmsg
);
1098 /* Check the results */
1100 netdev_err(wlandev
->netdev
,
1101 "%s chunk write failed w/ result=%d, aborting download\n",
1105 resultcode
= rstmsg
->resultcode
.data
;
1106 if (resultcode
!= P80211ENUM_resultcode_success
) {
1107 pr_err("%s()->xxxdl_write msg indicates failure, w/ resultcode=%d, aborting download.\n",
1108 __func__
, resultcode
);
1115 /* Send xxx_state(disable) */
1116 pr_debug("Sending dl_state(disable) message.\n");
1117 rstmsg
->enable
.data
= P80211ENUM_truth_false
;
1118 rstmsg
->exeaddr
.data
= 0;
1120 result
= prism2mgmt_ramdl_state(wlandev
, rstmsg
);
1122 netdev_err(wlandev
->netdev
,
1123 "%s state disable failed w/ result=%d, aborting download\n",
1127 resultcode
= rstmsg
->resultcode
.data
;
1128 if (resultcode
!= P80211ENUM_resultcode_success
) {
1129 netdev_err(wlandev
->netdev
,
1130 "%s()->xxxdl_state msg indicates failure, w/ resultcode=%d, aborting download.\n",
1131 __func__
, resultcode
);
1142 static int validate_identity(void)
1148 pr_debug("NIC ID: %#x v%d.%d.%d\n",
1149 nicid
.id
, nicid
.major
, nicid
.minor
, nicid
.variant
);
1150 pr_debug("MFI ID: %#x v%d %d->%d\n",
1151 rfid
.id
, rfid
.variant
, rfid
.bottom
, rfid
.top
);
1152 pr_debug("CFI ID: %#x v%d %d->%d\n",
1153 macid
.id
, macid
.variant
, macid
.bottom
, macid
.top
);
1154 pr_debug("PRI ID: %#x v%d %d->%d\n",
1155 priid
.id
, priid
.variant
, priid
.bottom
, priid
.top
);
1157 for (i
= 0; i
< ns3info
; i
++) {
1158 switch (s3info
[i
].type
) {
1160 pr_debug("Version: ID %#x %d.%d.%d\n",
1161 s3info
[i
].info
.version
.id
,
1162 s3info
[i
].info
.version
.major
,
1163 s3info
[i
].info
.version
.minor
,
1164 s3info
[i
].info
.version
.variant
);
1167 pr_debug("Compat: Role %#x Id %#x v%d %d->%d\n",
1168 s3info
[i
].info
.compat
.role
,
1169 s3info
[i
].info
.compat
.id
,
1170 s3info
[i
].info
.compat
.variant
,
1171 s3info
[i
].info
.compat
.bottom
,
1172 s3info
[i
].info
.compat
.top
);
1174 /* MAC compat range */
1175 if ((s3info
[i
].info
.compat
.role
== 1) &&
1176 (s3info
[i
].info
.compat
.id
== 2)) {
1177 if (s3info
[i
].info
.compat
.variant
!=
1183 /* PRI compat range */
1184 if ((s3info
[i
].info
.compat
.role
== 1) &&
1185 (s3info
[i
].info
.compat
.id
== 3)) {
1186 if ((s3info
[i
].info
.compat
.bottom
>
1188 (s3info
[i
].info
.compat
.top
<
1193 /* SEC compat range */
1194 if ((s3info
[i
].info
.compat
.role
== 1) &&
1195 (s3info
[i
].info
.compat
.id
== 4)) {
1196 /* FIXME: isn't something missing here? */
1201 pr_debug("Seq: %#x\n", s3info
[i
].info
.buildseq
);
1205 pr_debug("Platform: ID %#x %d.%d.%d\n",
1206 s3info
[i
].info
.version
.id
,
1207 s3info
[i
].info
.version
.major
,
1208 s3info
[i
].info
.version
.minor
,
1209 s3info
[i
].info
.version
.variant
);
1211 if (nicid
.id
!= s3info
[i
].info
.version
.id
)
1213 if (nicid
.major
!= s3info
[i
].info
.version
.major
)
1215 if (nicid
.minor
!= s3info
[i
].info
.version
.minor
)
1217 if ((nicid
.variant
!= s3info
[i
].info
.version
.variant
) &&
1218 (nicid
.id
!= 0x8008))
1224 pr_debug("name inforec len %d\n", s3info
[i
].len
);
1228 pr_debug("Unknown inforec type %d\n", s3info
[i
].type
);
1233 if (trump
&& (result
!= 2))