1 /* from src/prism2/download/prism2dl.c
3 * utility for downloading prism2 images moved into kernelspace
5 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
6 * --------------------------------------------------------------------
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/
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.
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.
31 * --------------------------------------------------------------------
33 * Inquiries regarding the linux-wlan Open Source project can be
36 * AbsoluteValue Systems Inc.
38 * http://www.linux-wlan.com
40 * --------------------------------------------------------------------
42 * Portions of the development of this software were funded by
43 * Intersil Corporation as part of PRISM(R) chipset product development.
45 * --------------------------------------------------------------------
48 /*================================================================*/
50 #include <linux/ihex.h>
51 #include <linux/slab.h>
53 /*================================================================*/
56 #define PRISM2_USB_FWFILE "prism2_ru.fw"
57 MODULE_FIRMWARE(PRISM2_USB_FWFILE);
59 #define S3DATA_MAX 5000
60 #define S3PLUG_MAX 200
64 #define S3ADDR_PLUG (0xff000000UL)
65 #define S3ADDR_CRC (0xff100000UL)
66 #define S3ADDR_INFO (0xff200000UL)
67 #define S3ADDR_START (0xff400000UL)
69 #define CHUNKS_MAX 100
71 #define WRITESIZE_MAX 4096
73 /*================================================================*/
99 hfa384x_compident_t version;
100 hfa384x_caplevel_t compat;
102 hfa384x_compident_t platform;
107 u8 buf[HFA384x_PDA_LEN_MAX];
108 hfa384x_pdrec_t *rec[HFA384x_PDA_RECS_MAX];
113 u32 addr; /* start address */
114 u32 len; /* in bytes */
115 u16 crc; /* CRC value (if it falls at a chunk boundary) */
119 /*================================================================*/
120 /* Local Static Definitions */
122 /*----------------------------------------------------------------*/
123 /* s-record image processing */
126 unsigned int ns3data;
127 struct s3datarec s3data[S3DATA_MAX];
130 unsigned int ns3plug;
131 struct s3plugrec s3plug[S3PLUG_MAX];
135 struct s3crcrec s3crc[S3CRC_MAX];
138 unsigned int ns3info;
139 struct s3inforec s3info[S3INFO_MAX];
141 /* S7 record (there _better_ be only one) */
144 /* Load image chunks */
145 unsigned int nfchunks;
146 struct imgchunk fchunk[CHUNKS_MAX];
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...] */
155 hfa384x_compident_t nicid;
156 hfa384x_caplevel_t rfid;
157 hfa384x_caplevel_t macid;
158 hfa384x_caplevel_t priid;
160 /*================================================================*/
161 /* Local Function Declarations */
163 static int prism2_fwapply(const struct ihex_binrec *rfptr,
164 wlandevice_t *wlandev);
166 static int read_fwfile(const struct ihex_binrec *rfptr);
168 static int mkimage(struct imgchunk *clist, unsigned int *ccnt);
170 static int read_cardpda(struct pda *pda, wlandevice_t *wlandev);
172 static int mkpdrlist(struct pda *pda);
174 static int plugimage(struct imgchunk *fchunk, unsigned int nfchunks,
175 struct s3plugrec *s3plug, unsigned int ns3plug, struct pda * pda);
177 static int crcimage(struct imgchunk *fchunk, unsigned int nfchunks,
178 struct s3crcrec *s3crc, unsigned int ns3crc);
180 static int writeimage(wlandevice_t *wlandev, struct imgchunk *fchunk,
181 unsigned int nfchunks);
182 static void free_chunks(struct imgchunk *fchunk, unsigned int *nfchunks);
184 static void free_srecs(void);
186 static int validate_identity(void);
188 /*================================================================*/
189 /* Function Definitions */
191 /*----------------------------------------------------------------
194 * Try and get firmware into memory
197 * udev usb device structure
198 * wlandev wlan device structure
203 ----------------------------------------------------------------*/
204 int prism2_fwtry(struct usb_device *udev, wlandevice_t *wlandev)
206 const struct firmware *fw_entry = NULL;
208 printk(KERN_INFO "prism2_usb: Checking for firmware %s\n",
210 if (request_ihex_firmware(&fw_entry, PRISM2_USB_FWFILE, &udev->dev) != 0) {
212 "prism2_usb: Firmware not available, but not essential\n");
214 "prism2_usb: can continue to use card anyway.\n");
218 printk(KERN_INFO "prism2_usb: %s will be processed, size %zu\n",
219 PRISM2_USB_FWFILE, fw_entry->size);
220 prism2_fwapply((const struct ihex_binrec *)fw_entry->data, wlandev);
222 release_firmware(fw_entry);
226 /*----------------------------------------------------------------
229 * Apply the firmware loaded into memory
232 * rfptr firmware image in kernel memory
238 ----------------------------------------------------------------*/
239 int prism2_fwapply(const struct ihex_binrec *rfptr, wlandevice_t *wlandev)
241 signed int result = 0;
242 struct p80211msg_dot11req_mibget getmsg;
246 /* Initialize the data structures */
248 memset(s3data, 0, sizeof(s3data));
250 memset(s3plug, 0, sizeof(s3plug));
252 memset(s3crc, 0, sizeof(s3crc));
254 memset(s3info, 0, sizeof(s3info));
258 memset(fchunk, 0, sizeof(fchunk));
259 memset(&nicid, 0, sizeof(nicid));
260 memset(&rfid, 0, sizeof(rfid));
261 memset(&macid, 0, sizeof(macid));
262 memset(&priid, 0, sizeof(priid));
264 /* clear the pda and add an initial END record */
265 memset(&pda, 0, sizeof(pda));
266 pda.rec[0] = (hfa384x_pdrec_t *) pda.buf;
267 pda.rec[0]->len = cpu_to_le16(2); /* len in words */
268 pda.rec[0]->code = cpu_to_le16(HFA384x_PDR_END_OF_PDA);
271 /*-----------------------------------------------------*/
272 /* Put card into fwload state */
273 prism2sta_ifstate(wlandev, P80211ENUM_ifstate_fwload);
275 /* Build the PDA we're going to use. */
276 if (read_cardpda(&pda, wlandev)) {
277 printk(KERN_ERR "load_cardpda failed, exiting.\n");
281 /* read the card's PRI-SUP */
282 memset(&getmsg, 0, sizeof(getmsg));
283 getmsg.msgcode = DIDmsg_dot11req_mibget;
284 getmsg.msglen = sizeof(getmsg);
285 strcpy(getmsg.devname, wlandev->name);
287 getmsg.mibattribute.did = DIDmsg_dot11req_mibget_mibattribute;
288 getmsg.mibattribute.status = P80211ENUM_msgitem_status_data_ok;
289 getmsg.resultcode.did = DIDmsg_dot11req_mibget_resultcode;
290 getmsg.resultcode.status = P80211ENUM_msgitem_status_no_value;
292 item = (p80211itemd_t *) getmsg.mibattribute.data;
293 item->did = DIDmib_p2_p2NIC_p2PRISupRange;
294 item->status = P80211ENUM_msgitem_status_no_value;
296 data = (u32 *) item->data;
298 /* DIDmsg_dot11req_mibget */
299 prism2mgmt_mibset_mibget(wlandev, &getmsg);
300 if (getmsg.resultcode.data != P80211ENUM_resultcode_success)
301 printk(KERN_ERR "Couldn't fetch PRI-SUP info\n");
303 /* Already in host order */
304 priid.role = *data++;
306 priid.variant = *data++;
307 priid.bottom = *data++;
310 /* Read the S3 file */
311 result = read_fwfile(rfptr);
313 printk(KERN_ERR "Failed to read the data exiting.\n");
317 result = validate_identity();
320 printk(KERN_ERR "Incompatible firmware image.\n");
324 if (startaddr == 0x00000000) {
325 printk(KERN_ERR "Can't RAM download a Flash image!\n");
329 /* Make the image chunks */
330 result = mkimage(fchunk, &nfchunks);
332 /* Do any plugging */
333 result = plugimage(fchunk, nfchunks, s3plug, ns3plug, &pda);
335 printk(KERN_ERR "Failed to plug data.\n");
339 /* Insert any CRCs */
340 if (crcimage(fchunk, nfchunks, s3crc, ns3crc)) {
341 printk(KERN_ERR "Failed to insert all CRCs\n");
345 /* Write the image */
346 result = writeimage(wlandev, fchunk, nfchunks);
348 printk(KERN_ERR "Failed to ramwrite image data.\n");
352 /* clear any allocated memory */
353 free_chunks(fchunk, &nfchunks);
356 printk(KERN_INFO "prism2_usb: firmware loading finished.\n");
361 /*----------------------------------------------------------------
364 * Adds a CRC16 in the two bytes prior to each block identified by
365 * an S3 CRC record. Currently, we don't actually do a CRC we just
366 * insert the value 0xC0DE in hfa384x order.
369 * fchunk Array of image chunks
370 * nfchunks Number of image chunks
371 * s3crc Array of crc records
372 * ns3crc Number of crc records
377 ----------------------------------------------------------------*/
378 int crcimage(struct imgchunk *fchunk, unsigned int nfchunks,
379 struct s3crcrec *s3crc, unsigned int ns3crc)
391 for (i = 0; i < ns3crc; i++) {
392 if (!s3crc[i].dowrite)
394 crcstart = s3crc[i].addr;
395 crcend = s3crc[i].addr + s3crc[i].len;
397 for (c = 0; c < nfchunks; c++) {
398 cstart = fchunk[c].addr;
399 cend = fchunk[c].addr + fchunk[c].len;
400 /* the line below does an address & len match search */
401 /* unfortunately, I've found that the len fields of */
402 /* some crc records don't match with the length of */
403 /* the actual data, so we're not checking right now */
404 /* if (crcstart-2 >= cstart && crcend <= cend) break; */
406 /* note the -2 below, it's to make sure the chunk has */
407 /* space for the CRC value */
408 if (crcstart - 2 >= cstart && crcstart < cend)
413 "Failed to find chunk for "
414 "crcrec[%d], addr=0x%06x len=%d , "
416 i, s3crc[i].addr, s3crc[i].len);
421 pr_debug("Adding crc @ 0x%06x\n", s3crc[i].addr - 2);
422 chunkoff = crcstart - cstart - 2;
423 dest = fchunk[c].data + chunkoff;
431 /*----------------------------------------------------------------
434 * Clears the chunklist data structures in preparation for a new file.
441 ----------------------------------------------------------------*/
442 void free_chunks(struct imgchunk *fchunk, unsigned int *nfchunks)
445 for (i = 0; i < *nfchunks; i++) {
446 if (fchunk[i].data != NULL)
447 kfree(fchunk[i].data);
450 memset(fchunk, 0, sizeof(*fchunk));
454 /*----------------------------------------------------------------
457 * Clears the srec data structures in preparation for a new file.
464 ----------------------------------------------------------------*/
465 void free_srecs(void)
468 memset(s3data, 0, sizeof(s3data));
470 memset(s3plug, 0, sizeof(s3plug));
472 memset(s3crc, 0, sizeof(s3crc));
474 memset(s3info, 0, sizeof(s3info));
478 /*----------------------------------------------------------------
481 * Scans the currently loaded set of S records for data residing
482 * in contiguous memory regions. Each contiguous region is then
483 * made into a 'chunk'. This function assumes that we're building
484 * a new chunk list. Assumes the s3data items are in sorted order.
490 * ~0 - failure (probably an errno)
491 ----------------------------------------------------------------*/
492 int mkimage(struct imgchunk *clist, unsigned int *ccnt)
505 /* There may already be data in the chunklist */
508 /* Establish the location and size of each chunk */
509 for (i = 0; i < ns3data; i++) {
510 if (s3data[i].addr == nextaddr) {
511 /* existing chunk, grow it */
512 clist[currchunk].len += s3data[i].len;
513 nextaddr += s3data[i].len;
517 currchunk = *ccnt - 1;
518 clist[currchunk].addr = s3data[i].addr;
519 clist[currchunk].len = s3data[i].len;
520 nextaddr = s3data[i].addr + s3data[i].len;
521 /* Expand the chunk if there is a CRC record at */
522 /* their beginning bound */
523 for (j = 0; j < ns3crc; j++) {
524 if (s3crc[j].dowrite &&
525 s3crc[j].addr == clist[currchunk].addr) {
526 clist[currchunk].addr -= 2;
527 clist[currchunk].len += 2;
533 /* We're currently assuming there aren't any overlapping chunks */
534 /* if this proves false, we'll need to add code to coalesce. */
536 /* Allocate buffer space for chunks */
537 for (i = 0; i < *ccnt; i++) {
538 clist[i].data = kzalloc(clist[i].len, GFP_KERNEL);
539 if (clist[i].data == NULL) {
541 "failed to allocate image space, exitting.\n");
544 pr_debug("chunk[%d]: addr=0x%06x len=%d\n",
545 i, clist[i].addr, clist[i].len);
548 /* Copy srec data to chunks */
549 for (i = 0; i < ns3data; i++) {
550 s3start = s3data[i].addr;
551 s3end = s3start + s3data[i].len - 1;
552 for (j = 0; j < *ccnt; j++) {
553 cstart = clist[j].addr;
554 cend = cstart + clist[j].len - 1;
555 if (s3start >= cstart && s3end <= cend)
558 if (((unsigned int)j) >= (*ccnt)) {
560 "s3rec(a=0x%06x,l=%d), no chunk match, exiting.\n",
561 s3start, s3data[i].len);
564 coffset = s3start - cstart;
565 memcpy(clist[j].data + coffset, s3data[i].data, s3data[i].len);
571 /*----------------------------------------------------------------
574 * Reads a raw PDA and builds an array of pdrec_t structures.
577 * pda buffer containing raw PDA bytes
578 * pdrec ptr to an array of pdrec_t's. Will be filled on exit.
579 * nrec ptr to a variable that will contain the count of PDRs
583 * ~0 - failure (probably an errno)
584 ----------------------------------------------------------------*/
585 int mkpdrlist(struct pda *pda)
588 u16 *pda16 = (u16 *) pda->buf;
589 int curroff; /* in 'words' */
593 while (curroff < (HFA384x_PDA_LEN_MAX / 2) &&
594 le16_to_cpu(pda16[curroff + 1]) != HFA384x_PDR_END_OF_PDA) {
595 pda->rec[pda->nrec] = (hfa384x_pdrec_t *) &(pda16[curroff]);
597 if (le16_to_cpu(pda->rec[pda->nrec]->code) == HFA384x_PDR_NICID) {
598 memcpy(&nicid, &pda->rec[pda->nrec]->data.nicid,
600 nicid.id = le16_to_cpu(nicid.id);
601 nicid.variant = le16_to_cpu(nicid.variant);
602 nicid.major = le16_to_cpu(nicid.major);
603 nicid.minor = le16_to_cpu(nicid.minor);
605 if (le16_to_cpu(pda->rec[pda->nrec]->code) ==
606 HFA384x_PDR_MFISUPRANGE) {
607 memcpy(&rfid, &pda->rec[pda->nrec]->data.mfisuprange,
609 rfid.id = le16_to_cpu(rfid.id);
610 rfid.variant = le16_to_cpu(rfid.variant);
611 rfid.bottom = le16_to_cpu(rfid.bottom);
612 rfid.top = le16_to_cpu(rfid.top);
614 if (le16_to_cpu(pda->rec[pda->nrec]->code) ==
615 HFA384x_PDR_CFISUPRANGE) {
616 memcpy(&macid, &pda->rec[pda->nrec]->data.cfisuprange,
618 macid.id = le16_to_cpu(macid.id);
619 macid.variant = le16_to_cpu(macid.variant);
620 macid.bottom = le16_to_cpu(macid.bottom);
621 macid.top = le16_to_cpu(macid.top);
625 curroff += le16_to_cpu(pda16[curroff]) + 1;
628 if (curroff >= (HFA384x_PDA_LEN_MAX / 2)) {
630 "no end record found or invalid lengths in "
631 "PDR data, exiting. %x %d\n", curroff, pda->nrec);
634 if (le16_to_cpu(pda16[curroff + 1]) == HFA384x_PDR_END_OF_PDA) {
635 pda->rec[pda->nrec] = (hfa384x_pdrec_t *) &(pda16[curroff]);
641 /*----------------------------------------------------------------
644 * Plugs the given image using the given plug records from the given
648 * fchunk Array of image chunks
649 * nfchunks Number of image chunks
650 * s3plug Array of plug records
651 * ns3plug Number of plug records
652 * pda Current pda data
657 ----------------------------------------------------------------*/
658 int plugimage(struct imgchunk *fchunk, unsigned int nfchunks,
659 struct s3plugrec *s3plug, unsigned int ns3plug, struct pda * pda)
662 int i; /* plug index */
663 int j; /* index of PDR or -1 if fname plug */
664 int c; /* chunk index */
672 /* for each plug record */
673 for (i = 0; i < ns3plug; i++) {
674 pstart = s3plug[i].addr;
675 pend = s3plug[i].addr + s3plug[i].len;
676 /* find the matching PDR (or filename) */
677 if (s3plug[i].itemcode != 0xffffffffUL) { /* not filename */
678 for (j = 0; j < pda->nrec; j++) {
679 if (s3plug[i].itemcode ==
680 le16_to_cpu(pda->rec[j]->code))
686 if (j >= pda->nrec && j != -1) { /* if no matching PDR, fail */
688 "warning: Failed to find PDR for "
689 "plugrec 0x%04x.\n", s3plug[i].itemcode);
690 continue; /* and move on to the next PDR */
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.
704 /* Validate plug len against PDR len */
705 if (j != -1 && s3plug[i].len < le16_to_cpu(pda->rec[j]->len)) {
707 "error: Plug vs. PDR len mismatch for "
708 "plugrec 0x%04x, abort plugging.\n",
714 /* Validate plug address against chunk data and identify chunk */
715 for (c = 0; c < nfchunks; c++) {
716 cstart = fchunk[c].addr;
717 cend = fchunk[c].addr + fchunk[c].len;
718 if (pstart >= cstart && pend <= cend)
723 "error: Failed to find image chunk for "
724 "plugrec 0x%04x.\n", s3plug[i].itemcode);
730 chunkoff = pstart - cstart;
731 dest = fchunk[c].data + chunkoff;
732 pr_debug("Plugging item 0x%04x @ 0x%06x, len=%d, "
733 "cnum=%d coff=0x%06x\n",
734 s3plug[i].itemcode, pstart, s3plug[i].len,
737 if (j == -1) { /* plug the filename */
738 memset(dest, 0, s3plug[i].len);
739 strncpy(dest, PRISM2_USB_FWFILE, s3plug[i].len - 1);
740 } else { /* plug a PDR */
741 memcpy(dest, &(pda->rec[j]->data), s3plug[i].len);
748 /*----------------------------------------------------------------
751 * Sends the command for the driver to read the pda from the card
752 * named in the device variable. Upon success, the card pda is
753 * stored in the "cardpda" variables. Note that the pda structure
754 * is considered 'well formed' after this function. That means
755 * that the nrecs is valid, the rec array has been set up, and there's
756 * a valid PDAEND record in the raw PDA data.
764 * ~0 - failure (probably an errno)
765 ----------------------------------------------------------------*/
766 int read_cardpda(struct pda *pda, wlandevice_t *wlandev)
769 struct p80211msg_p2req_readpda msg;
772 msg.msgcode = DIDmsg_p2req_readpda;
773 msg.msglen = sizeof(msg);
774 strcpy(msg.devname, wlandev->name);
775 msg.pda.did = DIDmsg_p2req_readpda_pda;
776 msg.pda.len = HFA384x_PDA_LEN_MAX;
777 msg.pda.status = P80211ENUM_msgitem_status_no_value;
778 msg.resultcode.did = DIDmsg_p2req_readpda_resultcode;
779 msg.resultcode.len = sizeof(u32);
780 msg.resultcode.status = P80211ENUM_msgitem_status_no_value;
782 if (prism2mgmt_readpda(wlandev, &msg) != 0) {
783 /* prism2mgmt_readpda prints an errno if appropriate */
785 } else if (msg.resultcode.data == P80211ENUM_resultcode_success) {
786 memcpy(pda->buf, msg.pda.data, HFA384x_PDA_LEN_MAX);
787 result = mkpdrlist(pda);
789 /* resultcode must've been something other than success */
796 /*----------------------------------------------------------------
799 * Reads the given fw file which should have been compiled from an srec
800 * file. Each record in the fw file will either be a plain data record,
801 * a start address record, or other records used for plugging.
803 * Note that data records are expected to be sorted into
804 * ascending address order in the fw file.
806 * Note also that the start address record, originally an S7 record in
807 * the srec file, is expected in the fw file to be like a data record but
808 * with a certain address to make it identiable.
810 * Here's the SREC format that the fw should have come from:
811 * S[37]nnaaaaaaaaddd...dddcc
813 * nn - number of bytes starting with the address field
814 * aaaaaaaa - address in readable (or big endian) format
815 * dd....dd - 0-245 data bytes (two chars per byte)
818 * The S7 record's (there should be only one) address value gets
819 * converted to an S3 record with address of 0xff400000, with the
820 * start address being stored as a 4 byte data word. That address is
821 * the start execution address used for RAM downloads.
823 * The S3 records have a collection of subformats indicated by the
825 * 0xff000000 - Plug record, data field format:
826 * xxxxxxxxaaaaaaaassssssss
827 * x - PDR code number (little endian)
828 * a - Address in load image to plug (little endian)
829 * s - Length of plug data area (little endian)
831 * 0xff100000 - CRC16 generation record, data field format:
832 * aaaaaaaassssssssbbbbbbbb
833 * a - Start address for CRC calculation (little endian)
834 * s - Length of data to calculate over (little endian)
835 * b - Boolean, true=write crc, false=don't write
837 * 0xff200000 - Info record, data field format:
839 * s - Size in words (little endian)
840 * t - Info type (little endian), see #defines and
841 * struct s3inforec for details about types.
842 * d - (s - 1) little endian words giving the contents of
843 * the given info type.
845 * 0xff400000 - Start address record, data field format:
847 * a - Address in load image to plug (little endian)
850 * record firmware image (ihex record structure) in kernel memory
854 * ~0 - failure (probably an errno)
855 ----------------------------------------------------------------*/
856 int read_fwfile(const struct ihex_binrec *record)
862 u32 *ptr32, len, addr;
864 pr_debug("Reading fw file ...\n");
870 len = be16_to_cpu(record->len);
871 addr = be32_to_cpu(record->addr);
873 /* Point into data for different word lengths */
874 ptr32 = (u32 *) record->data;
875 ptr16 = (u16 *) record->data;
877 /* parse what was an S3 srec and put it in the right array */
881 pr_debug(" S7 start addr, record=%d "
887 s3plug[ns3plug].itemcode = *ptr32;
888 s3plug[ns3plug].addr = *(ptr32 + 1);
889 s3plug[ns3plug].len = *(ptr32 + 2);
891 pr_debug(" S3 plugrec, record=%d "
892 "itemcode=0x%08x addr=0x%08x len=%d\n",
894 s3plug[ns3plug].itemcode,
895 s3plug[ns3plug].addr,
896 s3plug[ns3plug].len);
899 if (ns3plug == S3PLUG_MAX) {
900 printk(KERN_ERR "S3 plugrec limit reached - aborting\n");
905 s3crc[ns3crc].addr = *ptr32;
906 s3crc[ns3crc].len = *(ptr32 + 1);
907 s3crc[ns3crc].dowrite = *(ptr32 + 2);
909 pr_debug(" S3 crcrec, record=%d "
910 "addr=0x%08x len=%d write=0x%08x\n",
914 s3crc[ns3crc].dowrite);
916 if (ns3crc == S3CRC_MAX) {
917 printk(KERN_ERR "S3 crcrec limit reached - aborting\n");
922 s3info[ns3info].len = *ptr16;
923 s3info[ns3info].type = *(ptr16 + 1);
925 pr_debug(" S3 inforec, record=%d "
926 "len=0x%04x type=0x%04x\n",
929 s3info[ns3info].type);
930 if (((s3info[ns3info].len - 1) * sizeof(u16)) > sizeof(s3info[ns3info].info)) {
931 printk(KERN_ERR " S3 inforec length too long - aborting\n");
935 tmpinfo = (u16 *)&(s3info[ns3info].info.version);
937 for (i = 0; i < s3info[ns3info].len - 1; i++) {
938 tmpinfo[i] = *(ptr16 + 2 + i);
939 pr_debug("%04x ", tmpinfo[i]);
944 if (ns3info == S3INFO_MAX) {
945 printk(KERN_ERR "S3 inforec limit reached - aborting\n");
949 default: /* Data record */
950 s3data[ns3data].addr = addr;
951 s3data[ns3data].len = len;
952 s3data[ns3data].data = (uint8_t *) record->data;
954 if (ns3data == S3DATA_MAX) {
955 printk(KERN_ERR "S3 datarec limit reached - aborting\n");
960 record = ihex_next_binrec(record);
965 /*----------------------------------------------------------------
968 * Takes the chunks, builds p80211 messages and sends them down
969 * to the driver for writing to the card.
973 * fchunk Array of image chunks
974 * nfchunks Number of image chunks
979 ----------------------------------------------------------------*/
980 int writeimage(wlandevice_t *wlandev, struct imgchunk *fchunk,
981 unsigned int nfchunks)
984 struct p80211msg_p2req_ramdl_state rstatemsg;
985 struct p80211msg_p2req_ramdl_write rwritemsg;
986 struct p80211msg *msgp;
990 unsigned int nwrites;
995 /* Initialize the messages */
996 memset(&rstatemsg, 0, sizeof(rstatemsg));
997 strcpy(rstatemsg.devname, wlandev->name);
998 rstatemsg.msgcode = DIDmsg_p2req_ramdl_state;
999 rstatemsg.msglen = sizeof(rstatemsg);
1000 rstatemsg.enable.did = DIDmsg_p2req_ramdl_state_enable;
1001 rstatemsg.exeaddr.did = DIDmsg_p2req_ramdl_state_exeaddr;
1002 rstatemsg.resultcode.did = DIDmsg_p2req_ramdl_state_resultcode;
1003 rstatemsg.enable.status = P80211ENUM_msgitem_status_data_ok;
1004 rstatemsg.exeaddr.status = P80211ENUM_msgitem_status_data_ok;
1005 rstatemsg.resultcode.status = P80211ENUM_msgitem_status_no_value;
1006 rstatemsg.enable.len = sizeof(u32);
1007 rstatemsg.exeaddr.len = sizeof(u32);
1008 rstatemsg.resultcode.len = sizeof(u32);
1010 memset(&rwritemsg, 0, sizeof(rwritemsg));
1011 strcpy(rwritemsg.devname, wlandev->name);
1012 rwritemsg.msgcode = DIDmsg_p2req_ramdl_write;
1013 rwritemsg.msglen = sizeof(rwritemsg);
1014 rwritemsg.addr.did = DIDmsg_p2req_ramdl_write_addr;
1015 rwritemsg.len.did = DIDmsg_p2req_ramdl_write_len;
1016 rwritemsg.data.did = DIDmsg_p2req_ramdl_write_data;
1017 rwritemsg.resultcode.did = DIDmsg_p2req_ramdl_write_resultcode;
1018 rwritemsg.addr.status = P80211ENUM_msgitem_status_data_ok;
1019 rwritemsg.len.status = P80211ENUM_msgitem_status_data_ok;
1020 rwritemsg.data.status = P80211ENUM_msgitem_status_data_ok;
1021 rwritemsg.resultcode.status = P80211ENUM_msgitem_status_no_value;
1022 rwritemsg.addr.len = sizeof(u32);
1023 rwritemsg.len.len = sizeof(u32);
1024 rwritemsg.data.len = WRITESIZE_MAX;
1025 rwritemsg.resultcode.len = sizeof(u32);
1027 /* Send xxx_state(enable) */
1028 pr_debug("Sending dl_state(enable) message.\n");
1029 rstatemsg.enable.data = P80211ENUM_truth_true;
1030 rstatemsg.exeaddr.data = startaddr;
1032 msgp = (struct p80211msg *) &rstatemsg;
1033 result = prism2mgmt_ramdl_state(wlandev, msgp);
1036 "writeimage state enable failed w/ result=%d, "
1037 "aborting download\n", result);
1040 resultcode = rstatemsg.resultcode.data;
1041 if (resultcode != P80211ENUM_resultcode_success) {
1043 "writeimage()->xxxdl_state msg indicates failure, "
1044 "w/ resultcode=%d, aborting download.\n", resultcode);
1048 /* Now, loop through the data chunks and send WRITESIZE_MAX data */
1049 for (i = 0; i < nfchunks; i++) {
1050 nwrites = fchunk[i].len / WRITESIZE_MAX;
1051 nwrites += (fchunk[i].len % WRITESIZE_MAX) ? 1 : 0;
1053 for (j = 0; j < nwrites; j++) {
1054 /* TODO Move this to a separate function */
1055 int lenleft = fchunk[i].len - (WRITESIZE_MAX * j);
1056 if (fchunk[i].len > WRITESIZE_MAX)
1057 currlen = WRITESIZE_MAX;
1060 curroff = j * WRITESIZE_MAX;
1061 currdaddr = fchunk[i].addr + curroff;
1062 /* Setup the message */
1063 rwritemsg.addr.data = currdaddr;
1064 rwritemsg.len.data = currlen;
1065 memcpy(rwritemsg.data.data,
1066 fchunk[i].data + curroff, currlen);
1068 /* Send flashdl_write(pda) */
1070 ("Sending xxxdl_write message addr=%06x len=%d.\n",
1071 currdaddr, currlen);
1073 msgp = (struct p80211msg *) &rwritemsg;
1074 result = prism2mgmt_ramdl_write(wlandev, msgp);
1076 /* Check the results */
1079 "writeimage chunk write failed w/ result=%d, "
1080 "aborting download\n", result);
1083 resultcode = rstatemsg.resultcode.data;
1084 if (resultcode != P80211ENUM_resultcode_success) {
1086 "writeimage()->xxxdl_write msg indicates failure, "
1087 "w/ resultcode=%d, aborting download.\n",
1095 /* Send xxx_state(disable) */
1096 pr_debug("Sending dl_state(disable) message.\n");
1097 rstatemsg.enable.data = P80211ENUM_truth_false;
1098 rstatemsg.exeaddr.data = 0;
1100 msgp = (struct p80211msg *) &rstatemsg;
1101 result = prism2mgmt_ramdl_state(wlandev, msgp);
1104 "writeimage state disable failed w/ result=%d, "
1105 "aborting download\n", result);
1108 resultcode = rstatemsg.resultcode.data;
1109 if (resultcode != P80211ENUM_resultcode_success) {
1111 "writeimage()->xxxdl_state msg indicates failure, "
1112 "w/ resultcode=%d, aborting download.\n", resultcode);
1118 int validate_identity(void)
1124 pr_debug("NIC ID: %#x v%d.%d.%d\n",
1125 nicid.id, nicid.major, nicid.minor, nicid.variant);
1126 pr_debug("MFI ID: %#x v%d %d->%d\n",
1127 rfid.id, rfid.variant, rfid.bottom, rfid.top);
1128 pr_debug("CFI ID: %#x v%d %d->%d\n",
1129 macid.id, macid.variant, macid.bottom, macid.top);
1130 pr_debug("PRI ID: %#x v%d %d->%d\n",
1131 priid.id, priid.variant, priid.bottom, priid.top);
1133 for (i = 0; i < ns3info; i++) {
1134 switch (s3info[i].type) {
1136 pr_debug("Version: ID %#x %d.%d.%d\n",
1137 s3info[i].info.version.id,
1138 s3info[i].info.version.major,
1139 s3info[i].info.version.minor,
1140 s3info[i].info.version.variant);
1143 pr_debug("Compat: Role %#x Id %#x v%d %d->%d\n",
1144 s3info[i].info.compat.role,
1145 s3info[i].info.compat.id,
1146 s3info[i].info.compat.variant,
1147 s3info[i].info.compat.bottom,
1148 s3info[i].info.compat.top);
1150 /* MAC compat range */
1151 if ((s3info[i].info.compat.role == 1) &&
1152 (s3info[i].info.compat.id == 2)) {
1153 if (s3info[i].info.compat.variant !=
1159 /* PRI compat range */
1160 if ((s3info[i].info.compat.role == 1) &&
1161 (s3info[i].info.compat.id == 3)) {
1162 if ((s3info[i].info.compat.bottom > priid.top)
1163 || (s3info[i].info.compat.top <
1168 /* SEC compat range */
1169 if ((s3info[i].info.compat.role == 1) &&
1170 (s3info[i].info.compat.id == 4)) {
1171 /* FIXME: isn't something missing here? */
1176 pr_debug("Seq: %#x\n", s3info[i].info.buildseq);
1180 pr_debug("Platform: ID %#x %d.%d.%d\n",
1181 s3info[i].info.version.id,
1182 s3info[i].info.version.major,
1183 s3info[i].info.version.minor,
1184 s3info[i].info.version.variant);
1186 if (nicid.id != s3info[i].info.version.id)
1188 if (nicid.major != s3info[i].info.version.major)
1190 if (nicid.minor != s3info[i].info.version.minor)
1192 if ((nicid.variant != s3info[i].info.version.variant) &&
1193 (nicid.id != 0x8008))
1199 pr_debug("name inforec len %d\n", s3info[i].len);
1203 pr_debug("Unknown inforec type %d\n", s3info[i].type);
1208 if (trump && (result != 2))