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 static unsigned int ns3data;
127 static struct s3datarec s3data[S3DATA_MAX];
130 static unsigned int ns3plug;
131 static struct s3plugrec s3plug[S3PLUG_MAX];
134 static unsigned int ns3crc;
135 static struct s3crcrec s3crc[S3CRC_MAX];
138 static unsigned int ns3info;
139 static struct s3inforec s3info[S3INFO_MAX];
141 /* S7 record (there _better_ be only one) */
142 static u32 startaddr;
144 /* Load image chunks */
145 static unsigned int nfchunks;
146 static 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...] */
154 static struct pda pda;
155 static hfa384x_compident_t nicid;
156 static hfa384x_caplevel_t rfid;
157 static hfa384x_caplevel_t macid;
158 static 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 static int prism2_fwtry(struct usb_device *udev, wlandevice_t *wlandev)
206 const struct firmware *fw_entry = NULL;
208 netdev_info(wlandev->netdev, "prism2_usb: Checking for firmware %s\n",
210 if (request_ihex_firmware(&fw_entry,
211 PRISM2_USB_FWFILE, &udev->dev) != 0) {
212 netdev_info(wlandev->netdev,
213 "prism2_usb: Firmware not available, but not essential\n");
214 netdev_info(wlandev->netdev,
215 "prism2_usb: can continue to use card anyway.\n");
219 netdev_info(wlandev->netdev,
220 "prism2_usb: %s will be processed, size %zu\n",
221 PRISM2_USB_FWFILE, fw_entry->size);
222 prism2_fwapply((const struct ihex_binrec *)fw_entry->data, wlandev);
224 release_firmware(fw_entry);
228 /*----------------------------------------------------------------
231 * Apply the firmware loaded into memory
234 * rfptr firmware image in kernel memory
240 ----------------------------------------------------------------*/
241 static int prism2_fwapply(const struct ihex_binrec *rfptr,
242 wlandevice_t *wlandev)
244 signed int result = 0;
245 struct p80211msg_dot11req_mibget getmsg;
249 /* Initialize the data structures */
251 memset(s3data, 0, sizeof(s3data));
253 memset(s3plug, 0, sizeof(s3plug));
255 memset(s3crc, 0, sizeof(s3crc));
257 memset(s3info, 0, sizeof(s3info));
261 memset(fchunk, 0, sizeof(fchunk));
262 memset(&nicid, 0, sizeof(nicid));
263 memset(&rfid, 0, sizeof(rfid));
264 memset(&macid, 0, sizeof(macid));
265 memset(&priid, 0, sizeof(priid));
267 /* clear the pda and add an initial END record */
268 memset(&pda, 0, sizeof(pda));
269 pda.rec[0] = (hfa384x_pdrec_t *) pda.buf;
270 pda.rec[0]->len = cpu_to_le16(2); /* len in words */
271 pda.rec[0]->code = cpu_to_le16(HFA384x_PDR_END_OF_PDA);
274 /*-----------------------------------------------------*/
275 /* Put card into fwload state */
276 prism2sta_ifstate(wlandev, P80211ENUM_ifstate_fwload);
278 /* Build the PDA we're going to use. */
279 if (read_cardpda(&pda, wlandev)) {
280 netdev_err(wlandev->netdev, "load_cardpda failed, exiting.\n");
284 /* read the card's PRI-SUP */
285 memset(&getmsg, 0, sizeof(getmsg));
286 getmsg.msgcode = DIDmsg_dot11req_mibget;
287 getmsg.msglen = sizeof(getmsg);
288 strcpy(getmsg.devname, wlandev->name);
290 getmsg.mibattribute.did = DIDmsg_dot11req_mibget_mibattribute;
291 getmsg.mibattribute.status = P80211ENUM_msgitem_status_data_ok;
292 getmsg.resultcode.did = DIDmsg_dot11req_mibget_resultcode;
293 getmsg.resultcode.status = P80211ENUM_msgitem_status_no_value;
295 item = (p80211itemd_t *) getmsg.mibattribute.data;
296 item->did = DIDmib_p2_p2NIC_p2PRISupRange;
297 item->status = P80211ENUM_msgitem_status_no_value;
299 data = (u32 *) item->data;
301 /* DIDmsg_dot11req_mibget */
302 prism2mgmt_mibset_mibget(wlandev, &getmsg);
303 if (getmsg.resultcode.data != P80211ENUM_resultcode_success)
304 netdev_err(wlandev->netdev, "Couldn't fetch PRI-SUP info\n");
306 /* Already in host order */
307 priid.role = *data++;
309 priid.variant = *data++;
310 priid.bottom = *data++;
313 /* Read the S3 file */
314 result = read_fwfile(rfptr);
316 netdev_err(wlandev->netdev,
317 "Failed to read the data exiting.\n");
321 result = validate_identity();
324 netdev_err(wlandev->netdev, "Incompatible firmware image.\n");
328 if (startaddr == 0x00000000) {
329 netdev_err(wlandev->netdev,
330 "Can't RAM download a Flash image!\n");
334 /* Make the image chunks */
335 result = mkimage(fchunk, &nfchunks);
337 netdev_err(wlandev->netdev, "Failed to make image chunk.\n");
341 /* Do any plugging */
342 result = plugimage(fchunk, nfchunks, s3plug, ns3plug, &pda);
344 netdev_err(wlandev->netdev, "Failed to plug data.\n");
348 /* Insert any CRCs */
349 if (crcimage(fchunk, nfchunks, s3crc, ns3crc)) {
350 netdev_err(wlandev->netdev, "Failed to insert all CRCs\n");
354 /* Write the image */
355 result = writeimage(wlandev, fchunk, nfchunks);
357 netdev_err(wlandev->netdev, "Failed to ramwrite image data.\n");
361 /* clear any allocated memory */
362 free_chunks(fchunk, &nfchunks);
365 netdev_info(wlandev->netdev, "prism2_usb: firmware loading finished.\n");
370 /*----------------------------------------------------------------
373 * Adds a CRC16 in the two bytes prior to each block identified by
374 * an S3 CRC record. Currently, we don't actually do a CRC we just
375 * insert the value 0xC0DE in hfa384x order.
378 * fchunk Array of image chunks
379 * nfchunks Number of image chunks
380 * s3crc Array of crc records
381 * ns3crc Number of crc records
386 ----------------------------------------------------------------*/
387 static int crcimage(struct imgchunk *fchunk, unsigned int nfchunks,
388 struct s3crcrec *s3crc, unsigned int ns3crc)
400 for (i = 0; i < ns3crc; i++) {
401 if (!s3crc[i].dowrite)
403 crcstart = s3crc[i].addr;
404 crcend = s3crc[i].addr + s3crc[i].len;
406 for (c = 0; c < nfchunks; c++) {
407 cstart = fchunk[c].addr;
408 cend = fchunk[c].addr + fchunk[c].len;
409 /* the line below does an address & len match search */
410 /* unfortunately, I've found that the len fields of */
411 /* some crc records don't match with the length of */
412 /* the actual data, so we're not checking right now */
413 /* if (crcstart-2 >= cstart && crcend <= cend) break; */
415 /* note the -2 below, it's to make sure the chunk has */
416 /* space for the CRC value */
417 if (crcstart - 2 >= cstart && crcstart < cend)
421 pr_err("Failed to find chunk for crcrec[%d], addr=0x%06x len=%d , aborting crc.\n",
422 i, s3crc[i].addr, s3crc[i].len);
427 pr_debug("Adding crc @ 0x%06x\n", s3crc[i].addr - 2);
428 chunkoff = crcstart - cstart - 2;
429 dest = fchunk[c].data + chunkoff;
437 /*----------------------------------------------------------------
440 * Clears the chunklist data structures in preparation for a new file.
447 ----------------------------------------------------------------*/
448 static void free_chunks(struct imgchunk *fchunk, unsigned int *nfchunks)
452 for (i = 0; i < *nfchunks; i++)
453 kfree(fchunk[i].data);
456 memset(fchunk, 0, sizeof(*fchunk));
460 /*----------------------------------------------------------------
463 * Clears the srec data structures in preparation for a new file.
470 ----------------------------------------------------------------*/
471 static void free_srecs(void)
474 memset(s3data, 0, sizeof(s3data));
476 memset(s3plug, 0, sizeof(s3plug));
478 memset(s3crc, 0, sizeof(s3crc));
480 memset(s3info, 0, sizeof(s3info));
484 /*----------------------------------------------------------------
487 * Scans the currently loaded set of S records for data residing
488 * in contiguous memory regions. Each contiguous region is then
489 * made into a 'chunk'. This function assumes that we're building
490 * a new chunk list. Assumes the s3data items are in sorted order.
496 * ~0 - failure (probably an errno)
497 ----------------------------------------------------------------*/
498 static int mkimage(struct imgchunk *clist, unsigned int *ccnt)
511 /* There may already be data in the chunklist */
514 /* Establish the location and size of each chunk */
515 for (i = 0; i < ns3data; i++) {
516 if (s3data[i].addr == nextaddr) {
517 /* existing chunk, grow it */
518 clist[currchunk].len += s3data[i].len;
519 nextaddr += s3data[i].len;
523 currchunk = *ccnt - 1;
524 clist[currchunk].addr = s3data[i].addr;
525 clist[currchunk].len = s3data[i].len;
526 nextaddr = s3data[i].addr + s3data[i].len;
527 /* Expand the chunk if there is a CRC record at */
528 /* their beginning bound */
529 for (j = 0; j < ns3crc; j++) {
530 if (s3crc[j].dowrite &&
531 s3crc[j].addr == clist[currchunk].addr) {
532 clist[currchunk].addr -= 2;
533 clist[currchunk].len += 2;
539 /* We're currently assuming there aren't any overlapping chunks */
540 /* if this proves false, we'll need to add code to coalesce. */
542 /* Allocate buffer space for chunks */
543 for (i = 0; i < *ccnt; i++) {
544 clist[i].data = kzalloc(clist[i].len, GFP_KERNEL);
545 if (!clist[i].data) {
546 pr_err("failed to allocate image space, exitting.\n");
549 pr_debug("chunk[%d]: addr=0x%06x len=%d\n",
550 i, clist[i].addr, clist[i].len);
553 /* Copy srec data to chunks */
554 for (i = 0; i < ns3data; i++) {
555 s3start = s3data[i].addr;
556 s3end = s3start + s3data[i].len - 1;
557 for (j = 0; j < *ccnt; j++) {
558 cstart = clist[j].addr;
559 cend = cstart + clist[j].len - 1;
560 if (s3start >= cstart && s3end <= cend)
563 if (((unsigned int)j) >= (*ccnt)) {
564 pr_err("s3rec(a=0x%06x,l=%d), no chunk match, exiting.\n",
565 s3start, s3data[i].len);
568 coffset = s3start - cstart;
569 memcpy(clist[j].data + coffset, s3data[i].data, s3data[i].len);
575 /*----------------------------------------------------------------
578 * Reads a raw PDA and builds an array of pdrec_t structures.
581 * pda buffer containing raw PDA bytes
582 * pdrec ptr to an array of pdrec_t's. Will be filled on exit.
583 * nrec ptr to a variable that will contain the count of PDRs
587 * ~0 - failure (probably an errno)
588 ----------------------------------------------------------------*/
589 static int mkpdrlist(struct pda *pda)
591 u16 *pda16 = (u16 *) pda->buf;
592 int curroff; /* in 'words' */
596 while (curroff < (HFA384x_PDA_LEN_MAX / 2 - 1) &&
597 le16_to_cpu(pda16[curroff + 1]) != HFA384x_PDR_END_OF_PDA) {
598 pda->rec[pda->nrec] = (hfa384x_pdrec_t *) &(pda16[curroff]);
600 if (le16_to_cpu(pda->rec[pda->nrec]->code) ==
602 memcpy(&nicid, &pda->rec[pda->nrec]->data.nicid,
604 nicid.id = le16_to_cpu(nicid.id);
605 nicid.variant = le16_to_cpu(nicid.variant);
606 nicid.major = le16_to_cpu(nicid.major);
607 nicid.minor = le16_to_cpu(nicid.minor);
609 if (le16_to_cpu(pda->rec[pda->nrec]->code) ==
610 HFA384x_PDR_MFISUPRANGE) {
611 memcpy(&rfid, &pda->rec[pda->nrec]->data.mfisuprange,
613 rfid.id = le16_to_cpu(rfid.id);
614 rfid.variant = le16_to_cpu(rfid.variant);
615 rfid.bottom = le16_to_cpu(rfid.bottom);
616 rfid.top = le16_to_cpu(rfid.top);
618 if (le16_to_cpu(pda->rec[pda->nrec]->code) ==
619 HFA384x_PDR_CFISUPRANGE) {
620 memcpy(&macid, &pda->rec[pda->nrec]->data.cfisuprange,
622 macid.id = le16_to_cpu(macid.id);
623 macid.variant = le16_to_cpu(macid.variant);
624 macid.bottom = le16_to_cpu(macid.bottom);
625 macid.top = le16_to_cpu(macid.top);
629 curroff += le16_to_cpu(pda16[curroff]) + 1;
632 if (curroff >= (HFA384x_PDA_LEN_MAX / 2 - 1)) {
633 pr_err("no end record found or invalid lengths in PDR data, exiting. %x %d\n",
637 pda->rec[pda->nrec] = (hfa384x_pdrec_t *) &(pda16[curroff]);
642 /*----------------------------------------------------------------
645 * Plugs the given image using the given plug records from the given
649 * fchunk Array of image chunks
650 * nfchunks Number of image chunks
651 * s3plug Array of plug records
652 * ns3plug Number of plug records
653 * pda Current pda data
658 ----------------------------------------------------------------*/
659 static int plugimage(struct imgchunk *fchunk, unsigned int nfchunks,
660 struct s3plugrec *s3plug, unsigned int ns3plug, struct pda *pda)
663 int i; /* plug index */
664 int j; /* index of PDR or -1 if fname plug */
665 int c; /* chunk index */
673 /* for each plug record */
674 for (i = 0; i < ns3plug; i++) {
675 pstart = s3plug[i].addr;
676 pend = s3plug[i].addr + s3plug[i].len;
677 /* find the matching PDR (or filename) */
678 if (s3plug[i].itemcode != 0xffffffffUL) { /* not filename */
679 for (j = 0; j < pda->nrec; j++) {
680 if (s3plug[i].itemcode ==
681 le16_to_cpu(pda->rec[j]->code))
687 if (j >= pda->nrec && j != -1) { /* if no matching PDR, fail */
688 pr_warn("warning: Failed to find PDR for plugrec 0x%04x.\n",
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)) {
706 pr_err("error: Plug vs. PDR len mismatch for plugrec 0x%04x, abort plugging.\n",
713 * Validate plug address against
714 * chunk data and identify chunk
716 for (c = 0; c < nfchunks; c++) {
717 cstart = fchunk[c].addr;
718 cend = fchunk[c].addr + fchunk[c].len;
719 if (pstart >= cstart && pend <= cend)
723 pr_err("error: Failed to find image chunk for plugrec 0x%04x.\n",
730 chunkoff = pstart - cstart;
731 dest = fchunk[c].data + chunkoff;
732 pr_debug("Plugging item 0x%04x @ 0x%06x, len=%d, cnum=%d coff=0x%06x\n",
733 s3plug[i].itemcode, pstart, s3plug[i].len,
736 if (j == -1) { /* plug the filename */
737 memset(dest, 0, s3plug[i].len);
738 strncpy(dest, PRISM2_USB_FWFILE, s3plug[i].len - 1);
739 } else { /* plug a PDR */
740 memcpy(dest, &(pda->rec[j]->data), s3plug[i].len);
747 /*----------------------------------------------------------------
750 * Sends the command for the driver to read the pda from the card
751 * named in the device variable. Upon success, the card pda is
752 * stored in the "cardpda" variables. Note that the pda structure
753 * is considered 'well formed' after this function. That means
754 * that the nrecs is valid, the rec array has been set up, and there's
755 * a valid PDAEND record in the raw PDA data.
763 * ~0 - failure (probably an errno)
764 ----------------------------------------------------------------*/
765 static int read_cardpda(struct pda *pda, wlandevice_t *wlandev)
768 struct p80211msg_p2req_readpda *msg;
770 msg = kzalloc(sizeof(*msg), GFP_KERNEL);
775 msg->msgcode = DIDmsg_p2req_readpda;
776 msg->msglen = sizeof(msg);
777 strcpy(msg->devname, wlandev->name);
778 msg->pda.did = DIDmsg_p2req_readpda_pda;
779 msg->pda.len = HFA384x_PDA_LEN_MAX;
780 msg->pda.status = P80211ENUM_msgitem_status_no_value;
781 msg->resultcode.did = DIDmsg_p2req_readpda_resultcode;
782 msg->resultcode.len = sizeof(u32);
783 msg->resultcode.status = P80211ENUM_msgitem_status_no_value;
785 if (prism2mgmt_readpda(wlandev, msg) != 0) {
786 /* prism2mgmt_readpda prints an errno if appropriate */
788 } else if (msg->resultcode.data == P80211ENUM_resultcode_success) {
789 memcpy(pda->buf, msg->pda.data, HFA384x_PDA_LEN_MAX);
790 result = mkpdrlist(pda);
792 /* resultcode must've been something other than success */
800 /*----------------------------------------------------------------
803 * Reads the given fw file which should have been compiled from an srec
804 * file. Each record in the fw file will either be a plain data record,
805 * a start address record, or other records used for plugging.
807 * Note that data records are expected to be sorted into
808 * ascending address order in the fw file.
810 * Note also that the start address record, originally an S7 record in
811 * the srec file, is expected in the fw file to be like a data record but
812 * with a certain address to make it identifiable.
814 * Here's the SREC format that the fw should have come from:
815 * S[37]nnaaaaaaaaddd...dddcc
817 * nn - number of bytes starting with the address field
818 * aaaaaaaa - address in readable (or big endian) format
819 * dd....dd - 0-245 data bytes (two chars per byte)
822 * The S7 record's (there should be only one) address value gets
823 * converted to an S3 record with address of 0xff400000, with the
824 * start address being stored as a 4 byte data word. That address is
825 * the start execution address used for RAM downloads.
827 * The S3 records have a collection of subformats indicated by the
829 * 0xff000000 - Plug record, data field format:
830 * xxxxxxxxaaaaaaaassssssss
831 * x - PDR code number (little endian)
832 * a - Address in load image to plug (little endian)
833 * s - Length of plug data area (little endian)
835 * 0xff100000 - CRC16 generation record, data field format:
836 * aaaaaaaassssssssbbbbbbbb
837 * a - Start address for CRC calculation (little endian)
838 * s - Length of data to calculate over (little endian)
839 * b - Boolean, true=write crc, false=don't write
841 * 0xff200000 - Info record, data field format:
843 * s - Size in words (little endian)
844 * t - Info type (little endian), see #defines and
845 * struct s3inforec for details about types.
846 * d - (s - 1) little endian words giving the contents of
847 * the given info type.
849 * 0xff400000 - Start address record, data field format:
851 * a - Address in load image to plug (little endian)
854 * record firmware image (ihex record structure) in kernel memory
858 * ~0 - failure (probably an errno)
859 ----------------------------------------------------------------*/
860 static int read_fwfile(const struct ihex_binrec *record)
866 u32 *ptr32, len, addr;
868 pr_debug("Reading fw file ...\n");
874 len = be16_to_cpu(record->len);
875 addr = be32_to_cpu(record->addr);
877 /* Point into data for different word lengths */
878 ptr32 = (u32 *) record->data;
879 ptr16 = (u16 *) record->data;
881 /* parse what was an S3 srec and put it in the right array */
885 pr_debug(" S7 start addr, record=%d addr=0x%08x\n",
890 s3plug[ns3plug].itemcode = *ptr32;
891 s3plug[ns3plug].addr = *(ptr32 + 1);
892 s3plug[ns3plug].len = *(ptr32 + 2);
894 pr_debug(" S3 plugrec, record=%d itemcode=0x%08x addr=0x%08x len=%d\n",
896 s3plug[ns3plug].itemcode,
897 s3plug[ns3plug].addr,
898 s3plug[ns3plug].len);
901 if (ns3plug == S3PLUG_MAX) {
902 pr_err("S3 plugrec limit reached - aborting\n");
907 s3crc[ns3crc].addr = *ptr32;
908 s3crc[ns3crc].len = *(ptr32 + 1);
909 s3crc[ns3crc].dowrite = *(ptr32 + 2);
911 pr_debug(" S3 crcrec, record=%d addr=0x%08x len=%d write=0x%08x\n",
915 s3crc[ns3crc].dowrite);
917 if (ns3crc == S3CRC_MAX) {
918 pr_err("S3 crcrec limit reached - aborting\n");
923 s3info[ns3info].len = *ptr16;
924 s3info[ns3info].type = *(ptr16 + 1);
926 pr_debug(" S3 inforec, record=%d len=0x%04x type=0x%04x\n",
929 s3info[ns3info].type);
930 if (((s3info[ns3info].len - 1) * sizeof(u16)) >
931 sizeof(s3info[ns3info].info)) {
932 pr_err("S3 inforec length too long - aborting\n");
936 tmpinfo = (u16 *)&(s3info[ns3info].info.version);
938 for (i = 0; i < s3info[ns3info].len - 1; i++) {
939 tmpinfo[i] = *(ptr16 + 2 + i);
940 pr_debug("%04x ", tmpinfo[i]);
945 if (ns3info == S3INFO_MAX) {
946 pr_err("S3 inforec limit reached - aborting\n");
950 default: /* Data record */
951 s3data[ns3data].addr = addr;
952 s3data[ns3data].len = len;
953 s3data[ns3data].data = (uint8_t *) record->data;
955 if (ns3data == S3DATA_MAX) {
956 pr_err("S3 datarec limit reached - aborting\n");
961 record = ihex_next_binrec(record);
966 /*----------------------------------------------------------------
969 * Takes the chunks, builds p80211 messages and sends them down
970 * to the driver for writing to the card.
974 * fchunk Array of image chunks
975 * nfchunks Number of image chunks
980 ----------------------------------------------------------------*/
981 static int writeimage(wlandevice_t *wlandev, struct imgchunk *fchunk,
982 unsigned int nfchunks)
985 struct p80211msg_p2req_ramdl_state *rstmsg;
986 struct p80211msg_p2req_ramdl_write *rwrmsg;
990 unsigned int nwrites;
995 rstmsg = kzalloc(sizeof(*rstmsg), GFP_KERNEL);
996 rwrmsg = kzalloc(sizeof(*rwrmsg), GFP_KERNEL);
997 if (!rstmsg || !rwrmsg) {
1000 netdev_err(wlandev->netdev,
1001 "writeimage: no memory for firmware download, aborting download\n");
1005 /* Initialize the messages */
1006 strcpy(rstmsg->devname, wlandev->name);
1007 rstmsg->msgcode = DIDmsg_p2req_ramdl_state;
1008 rstmsg->msglen = sizeof(*rstmsg);
1009 rstmsg->enable.did = DIDmsg_p2req_ramdl_state_enable;
1010 rstmsg->exeaddr.did = DIDmsg_p2req_ramdl_state_exeaddr;
1011 rstmsg->resultcode.did = DIDmsg_p2req_ramdl_state_resultcode;
1012 rstmsg->enable.status = P80211ENUM_msgitem_status_data_ok;
1013 rstmsg->exeaddr.status = P80211ENUM_msgitem_status_data_ok;
1014 rstmsg->resultcode.status = P80211ENUM_msgitem_status_no_value;
1015 rstmsg->enable.len = sizeof(u32);
1016 rstmsg->exeaddr.len = sizeof(u32);
1017 rstmsg->resultcode.len = sizeof(u32);
1019 strcpy(rwrmsg->devname, wlandev->name);
1020 rwrmsg->msgcode = DIDmsg_p2req_ramdl_write;
1021 rwrmsg->msglen = sizeof(*rwrmsg);
1022 rwrmsg->addr.did = DIDmsg_p2req_ramdl_write_addr;
1023 rwrmsg->len.did = DIDmsg_p2req_ramdl_write_len;
1024 rwrmsg->data.did = DIDmsg_p2req_ramdl_write_data;
1025 rwrmsg->resultcode.did = DIDmsg_p2req_ramdl_write_resultcode;
1026 rwrmsg->addr.status = P80211ENUM_msgitem_status_data_ok;
1027 rwrmsg->len.status = P80211ENUM_msgitem_status_data_ok;
1028 rwrmsg->data.status = P80211ENUM_msgitem_status_data_ok;
1029 rwrmsg->resultcode.status = P80211ENUM_msgitem_status_no_value;
1030 rwrmsg->addr.len = sizeof(u32);
1031 rwrmsg->len.len = sizeof(u32);
1032 rwrmsg->data.len = WRITESIZE_MAX;
1033 rwrmsg->resultcode.len = sizeof(u32);
1035 /* Send xxx_state(enable) */
1036 pr_debug("Sending dl_state(enable) message.\n");
1037 rstmsg->enable.data = P80211ENUM_truth_true;
1038 rstmsg->exeaddr.data = startaddr;
1040 result = prism2mgmt_ramdl_state(wlandev, rstmsg);
1042 netdev_err(wlandev->netdev,
1043 "writeimage state enable failed w/ result=%d, aborting download\n",
1047 resultcode = rstmsg->resultcode.data;
1048 if (resultcode != P80211ENUM_resultcode_success) {
1049 netdev_err(wlandev->netdev,
1050 "writeimage()->xxxdl_state msg indicates failure, w/ resultcode=%d, aborting download.\n",
1056 /* Now, loop through the data chunks and send WRITESIZE_MAX data */
1057 for (i = 0; i < nfchunks; i++) {
1058 nwrites = fchunk[i].len / WRITESIZE_MAX;
1059 nwrites += (fchunk[i].len % WRITESIZE_MAX) ? 1 : 0;
1061 for (j = 0; j < nwrites; j++) {
1062 /* TODO Move this to a separate function */
1063 int lenleft = fchunk[i].len - (WRITESIZE_MAX * j);
1065 if (fchunk[i].len > WRITESIZE_MAX)
1066 currlen = WRITESIZE_MAX;
1069 curroff = j * WRITESIZE_MAX;
1070 currdaddr = fchunk[i].addr + curroff;
1071 /* Setup the message */
1072 rwrmsg->addr.data = currdaddr;
1073 rwrmsg->len.data = currlen;
1074 memcpy(rwrmsg->data.data,
1075 fchunk[i].data + curroff, currlen);
1077 /* Send flashdl_write(pda) */
1079 ("Sending xxxdl_write message addr=%06x len=%d.\n",
1080 currdaddr, currlen);
1082 result = prism2mgmt_ramdl_write(wlandev, rwrmsg);
1084 /* Check the results */
1086 netdev_err(wlandev->netdev,
1087 "writeimage chunk write failed w/ result=%d, aborting download\n",
1091 resultcode = rstmsg->resultcode.data;
1092 if (resultcode != P80211ENUM_resultcode_success) {
1093 pr_err("writeimage()->xxxdl_write msg indicates failure, w/ resultcode=%d, aborting download.\n",
1102 /* Send xxx_state(disable) */
1103 pr_debug("Sending dl_state(disable) message.\n");
1104 rstmsg->enable.data = P80211ENUM_truth_false;
1105 rstmsg->exeaddr.data = 0;
1107 result = prism2mgmt_ramdl_state(wlandev, rstmsg);
1109 netdev_err(wlandev->netdev,
1110 "writeimage state disable failed w/ result=%d, aborting download\n",
1114 resultcode = rstmsg->resultcode.data;
1115 if (resultcode != P80211ENUM_resultcode_success) {
1116 netdev_err(wlandev->netdev,
1117 "writeimage()->xxxdl_state msg indicates failure, w/ resultcode=%d, aborting download.\n",
1129 static int validate_identity(void)
1135 pr_debug("NIC ID: %#x v%d.%d.%d\n",
1136 nicid.id, nicid.major, nicid.minor, nicid.variant);
1137 pr_debug("MFI ID: %#x v%d %d->%d\n",
1138 rfid.id, rfid.variant, rfid.bottom, rfid.top);
1139 pr_debug("CFI ID: %#x v%d %d->%d\n",
1140 macid.id, macid.variant, macid.bottom, macid.top);
1141 pr_debug("PRI ID: %#x v%d %d->%d\n",
1142 priid.id, priid.variant, priid.bottom, priid.top);
1144 for (i = 0; i < ns3info; i++) {
1145 switch (s3info[i].type) {
1147 pr_debug("Version: ID %#x %d.%d.%d\n",
1148 s3info[i].info.version.id,
1149 s3info[i].info.version.major,
1150 s3info[i].info.version.minor,
1151 s3info[i].info.version.variant);
1154 pr_debug("Compat: Role %#x Id %#x v%d %d->%d\n",
1155 s3info[i].info.compat.role,
1156 s3info[i].info.compat.id,
1157 s3info[i].info.compat.variant,
1158 s3info[i].info.compat.bottom,
1159 s3info[i].info.compat.top);
1161 /* MAC compat range */
1162 if ((s3info[i].info.compat.role == 1) &&
1163 (s3info[i].info.compat.id == 2)) {
1164 if (s3info[i].info.compat.variant !=
1170 /* PRI compat range */
1171 if ((s3info[i].info.compat.role == 1) &&
1172 (s3info[i].info.compat.id == 3)) {
1173 if ((s3info[i].info.compat.bottom > priid.top)
1174 || (s3info[i].info.compat.top <
1179 /* SEC compat range */
1180 if ((s3info[i].info.compat.role == 1) &&
1181 (s3info[i].info.compat.id == 4)) {
1182 /* FIXME: isn't something missing here? */
1187 pr_debug("Seq: %#x\n", s3info[i].info.buildseq);
1191 pr_debug("Platform: ID %#x %d.%d.%d\n",
1192 s3info[i].info.version.id,
1193 s3info[i].info.version.major,
1194 s3info[i].info.version.minor,
1195 s3info[i].info.version.variant);
1197 if (nicid.id != s3info[i].info.version.id)
1199 if (nicid.major != s3info[i].info.version.major)
1201 if (nicid.minor != s3info[i].info.version.minor)
1203 if ((nicid.variant != s3info[i].info.version.variant) &&
1204 (nicid.id != 0x8008))
1210 pr_debug("name inforec len %d\n", s3info[i].len);
1214 pr_debug("Unknown inforec type %d\n", s3info[i].type);
1219 if (trump && (result != 2))