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