2 * @file IxNpeDlImageMgr.c
4 * @author Intel Corporation
5 * @date 09 January 2002
7 * @brief This file contains the implementation of the private API for the
8 * IXP425 NPE Downloader ImageMgr module
12 * IXP400 SW Release version 2.0
14 * -- Copyright Notice --
17 * Copyright 2001-2005, Intel Corporation.
18 * All rights reserved.
21 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions
24 * 1. Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * 2. Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in the
28 * documentation and/or other materials provided with the distribution.
29 * 3. Neither the name of the Intel Corporation nor the names of its contributors
30 * may be used to endorse or promote products derived from this software
31 * without specific prior written permission.
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
35 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
38 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
40 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
43 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47 * -- End of Copyright Notice --
52 * Put the system defined include files required.
57 * Put the user defined include files required.
59 #include "IxNpeDlImageMgr_p.h"
60 #include "IxNpeDlMacros_p.h"
63 * define the flag which toggles the firmare inclusion
65 #define IX_NPE_MICROCODE_FIRMWARE_INCLUDED 1
66 #include "IxNpeMicrocode.h"
69 * Indicates the start of an NPE Image, in new NPE Image Library format.
70 * 2 consecutive occurances indicates the end of the NPE Image Library
72 #define NPE_IMAGE_MARKER 0xfeedf00d
75 * Typedefs whose scope is limited to this file.
79 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
80 * TO BE DEPRECATED IN A FUTURE RELEASE
87 } IxNpeDlImageMgrImageEntry;
90 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
91 * TO BE DEPRECATED IN A FUTURE RELEASE
95 IxNpeDlImageMgrImageEntry image;
97 } IxNpeDlImageMgrHeaderEntry;
100 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
101 * TO BE DEPRECATED IN A FUTURE RELEASE
106 /* 1st entry in the header (there may be more than one) */
107 IxNpeDlImageMgrHeaderEntry entry[1];
108 } IxNpeDlImageMgrImageLibraryHeader;
112 * NPE Image Header definition, used in new NPE Image Library format
119 } IxNpeDlImageMgrImageHeader;
121 /* module statistics counters */
124 UINT32 invalidSignature;
125 UINT32 imageIdListOverflow;
126 UINT32 imageIdNotFound;
127 } IxNpeDlImageMgrStats;
131 * Variable declarations global to this file only. Externs are followed by
134 static IxNpeDlImageMgrStats ixNpeDlImageMgrStats;
137 #ifdef CONFIG_IXP4XX_NPE_EXT_UCODE_BASE
138 static UINT32 *IxNpeMicroCodeImageLibrary = (UINT32 *)CONFIG_IXP4XX_NPE_EXT_UCODE_BASE;
140 static UINT32 *IxNpeMicroCodeImageLibrary = (UINT32 *)IxNpeMicrocode_array;
145 * static function prototypes.
148 ixNpeDlImageMgrSignatureCheck (UINT32 *microCodeImageLibrary);
151 ixNpeDlImageMgrImageIdFormat (UINT32 rawImageId, IxNpeDlImageId *imageId);
154 ixNpeDlImageMgrImageIdCompare (IxNpeDlImageId *imageIdA,
155 IxNpeDlImageId *imageIdB);
158 ixNpeDlImageMgrNpeFunctionIdCompare (IxNpeDlImageId *imageIdA,
159 IxNpeDlImageId *imageIdB);
163 ixNpeDlImageMgrImageFind_legacy (UINT32 *imageLibrary,
169 * Function definition: ixNpeDlImageMgrMicrocodeImageLibraryOverride
171 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
172 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
175 ixNpeDlImageMgrMicrocodeImageLibraryOverride (
176 UINT32 *clientImageLibrary)
178 IX_STATUS status = IX_SUCCESS;
180 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
181 "Entering ixNpeDlImageMgrMicrocodeImageLibraryOverride\n");
183 if (ixNpeDlImageMgrSignatureCheck (clientImageLibrary))
185 IxNpeMicroCodeImageLibrary = clientImageLibrary;
189 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrMicrocodeImageLibraryOverride: "
190 "Client-supplied image has invalid signature\n");
194 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
195 "Exiting ixNpeDlImageMgrMicrocodeImageLibraryOverride: status = %d\n",
202 * Function definition: ixNpeDlImageMgrImageListExtract
204 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
205 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
208 ixNpeDlImageMgrImageListExtract (
209 IxNpeDlImageId *imageListPtr,
213 IxNpeDlImageId formattedImageId;
214 IX_STATUS status = IX_SUCCESS;
215 UINT32 imageCount = 0;
216 IxNpeDlImageMgrImageLibraryHeader *header;
218 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
219 "Entering ixNpeDlImageMgrImageListExtract\n");
221 header = (IxNpeDlImageMgrImageLibraryHeader *) IxNpeMicroCodeImageLibrary;
223 if (ixNpeDlImageMgrSignatureCheck (IxNpeMicroCodeImageLibrary))
225 /* for each image entry in the image header ... */
226 while (header->entry[imageCount].eohMarker !=
227 IX_NPEDL_IMAGEMGR_END_OF_HEADER)
230 * if the image list container from calling function has capacity,
231 * add the image id to the list
233 if ((imageListPtr != NULL) && (imageCount < *numImages))
235 rawImageId = header->entry[imageCount].image.id;
236 ixNpeDlImageMgrImageIdFormat (rawImageId, &formattedImageId);
237 imageListPtr[imageCount] = formattedImageId;
239 /* imageCount reflects no. of image entries in image library header */
244 * if image list container from calling function was too small to
245 * contain all image ids in the header, set return status to FAIL
247 if ((imageListPtr != NULL) && (imageCount > *numImages))
250 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageListExtract: "
251 "number of Ids found exceeds list capacity\n");
252 ixNpeDlImageMgrStats.imageIdListOverflow++;
254 /* return number of image ids found in image library header */
255 *numImages = imageCount;
260 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageListExtract: "
261 "invalid signature in image\n");
264 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
265 "Exiting ixNpeDlImageMgrImageListExtract: status = %d\n",
272 * Function definition: ixNpeDlImageMgrImageLocate
274 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
275 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
278 ixNpeDlImageMgrImageLocate (
279 IxNpeDlImageId *imageId,
285 IxNpeDlImageId formattedImageId;
286 /* used to index image entries in image library header */
287 UINT32 imageCount = 0;
288 IX_STATUS status = IX_FAIL;
289 IxNpeDlImageMgrImageLibraryHeader *header;
291 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
292 "Entering ixNpeDlImageMgrImageLocate\n");
294 header = (IxNpeDlImageMgrImageLibraryHeader *) IxNpeMicroCodeImageLibrary;
296 if (ixNpeDlImageMgrSignatureCheck (IxNpeMicroCodeImageLibrary))
298 /* for each image entry in the image library header ... */
299 while (header->entry[imageCount].eohMarker !=
300 IX_NPEDL_IMAGEMGR_END_OF_HEADER)
302 rawImageId = header->entry[imageCount].image.id;
303 ixNpeDlImageMgrImageIdFormat (rawImageId, &formattedImageId);
304 /* if a match for imageId is found in the image library header... */
305 if (ixNpeDlImageMgrImageIdCompare (imageId, &formattedImageId))
308 * get pointer to the image in the image library using offset from
309 * 1st word in image library
311 imageOffset = header->entry[imageCount].image.offset;
312 *imagePtr = &IxNpeMicroCodeImageLibrary[imageOffset];
313 /* get the image size */
314 *imageSize = header->entry[imageCount].image.size;
320 if (status != IX_SUCCESS)
322 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageLocate: "
323 "imageId not found in image library header\n");
324 ixNpeDlImageMgrStats.imageIdNotFound++;
329 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageLocate: "
330 "invalid signature in image library\n");
333 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
334 "Exiting ixNpeDlImageMgrImageLocate: status = %d\n", status);
339 * Function definition: ixNpeDlImageMgrLatestImageExtract
341 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
342 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
345 ixNpeDlImageMgrLatestImageExtract (IxNpeDlImageId *imageId)
347 UINT32 imageCount = 0;
349 IxNpeDlImageId formattedImageId;
350 IX_STATUS status = IX_FAIL;
351 IxNpeDlImageMgrImageLibraryHeader *header;
354 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
355 "Entering ixNpeDlImageMgrLatestImageExtract\n");
357 header = (IxNpeDlImageMgrImageLibraryHeader *) IxNpeMicroCodeImageLibrary;
359 if (ixNpeDlImageMgrSignatureCheck (IxNpeMicroCodeImageLibrary))
361 /* for each image entry in the image library header ... */
362 while (header->entry[imageCount].eohMarker !=
363 IX_NPEDL_IMAGEMGR_END_OF_HEADER)
365 rawImageId = header->entry[imageCount].image.id;
366 ixNpeDlImageMgrImageIdFormat (rawImageId, &formattedImageId);
368 * if a match for the npe Id and functionality Id of the imageId is
369 * found in the image library header...
371 if(ixNpeDlImageMgrNpeFunctionIdCompare(imageId, &formattedImageId))
373 if(imageId->major <= formattedImageId.major)
375 if(imageId->minor < formattedImageId.minor)
377 imageId->minor = formattedImageId.minor;
379 imageId->major = formattedImageId.major;
385 if (status != IX_SUCCESS)
387 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrLatestImageExtract: "
388 "imageId not found in image library header\n");
389 ixNpeDlImageMgrStats.imageIdNotFound++;
394 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrLatestImageGet: "
395 "invalid signature in image library\n");
398 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
399 "Exiting ixNpeDlImageMgrLatestImageGet: status = %d\n", status);
404 * Function definition: ixNpeDlImageMgrSignatureCheck
406 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
407 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
410 ixNpeDlImageMgrSignatureCheck (UINT32 *microCodeImageLibrary)
412 IxNpeDlImageMgrImageLibraryHeader *header =
413 (IxNpeDlImageMgrImageLibraryHeader *) microCodeImageLibrary;
416 if (header->signature != IX_NPEDL_IMAGEMGR_SIGNATURE)
419 ixNpeDlImageMgrStats.invalidSignature++;
427 * Function definition: ixNpeDlImageMgrImageIdFormat
429 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
430 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
433 ixNpeDlImageMgrImageIdFormat (
435 IxNpeDlImageId *imageId)
437 imageId->npeId = (rawImageId >>
438 IX_NPEDL_IMAGEID_NPEID_OFFSET) &
439 IX_NPEDL_NPEIMAGE_FIELD_MASK;
440 imageId->functionalityId = (rawImageId >>
441 IX_NPEDL_IMAGEID_FUNCTIONID_OFFSET) &
442 IX_NPEDL_NPEIMAGE_FIELD_MASK;
443 imageId->major = (rawImageId >>
444 IX_NPEDL_IMAGEID_MAJOR_OFFSET) &
445 IX_NPEDL_NPEIMAGE_FIELD_MASK;
446 imageId->minor = (rawImageId >>
447 IX_NPEDL_IMAGEID_MINOR_OFFSET) &
448 IX_NPEDL_NPEIMAGE_FIELD_MASK;
454 * Function definition: ixNpeDlImageMgrImageIdCompare
456 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
457 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
460 ixNpeDlImageMgrImageIdCompare (
461 IxNpeDlImageId *imageIdA,
462 IxNpeDlImageId *imageIdB)
464 if ((imageIdA->npeId == imageIdB->npeId) &&
465 (imageIdA->functionalityId == imageIdB->functionalityId) &&
466 (imageIdA->major == imageIdB->major) &&
467 (imageIdA->minor == imageIdB->minor))
478 * Function definition: ixNpeDlImageMgrNpeFunctionIdCompare
480 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
481 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
484 ixNpeDlImageMgrNpeFunctionIdCompare (
485 IxNpeDlImageId *imageIdA,
486 IxNpeDlImageId *imageIdB)
488 if ((imageIdA->npeId == imageIdB->npeId) &&
489 (imageIdA->functionalityId == imageIdB->functionalityId))
501 * Function definition: ixNpeDlImageMgrStatsShow
504 ixNpeDlImageMgrStatsShow (void)
506 ixOsalLog (IX_OSAL_LOG_LVL_USER,
507 IX_OSAL_LOG_DEV_STDOUT,
508 "\nixNpeDlImageMgrStatsShow:\n"
509 "\tInvalid Image Signatures: %u\n"
510 "\tImage Id List capacity too small: %u\n"
511 "\tImage Id not found: %u\n\n",
512 ixNpeDlImageMgrStats.invalidSignature,
513 ixNpeDlImageMgrStats.imageIdListOverflow,
514 ixNpeDlImageMgrStats.imageIdNotFound,
520 * Function definition: ixNpeDlImageMgrStatsReset
523 ixNpeDlImageMgrStatsReset (void)
525 ixNpeDlImageMgrStats.invalidSignature = 0;
526 ixNpeDlImageMgrStats.imageIdListOverflow = 0;
527 ixNpeDlImageMgrStats.imageIdNotFound = 0;
533 * Function definition: ixNpeDlImageMgrImageFind_legacy
535 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
536 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
539 ixNpeDlImageMgrImageFind_legacy (
540 UINT32 *imageLibrary,
546 /* used to index image entries in image library header */
547 UINT32 imageCount = 0;
548 IX_STATUS status = IX_FAIL;
549 IxNpeDlImageMgrImageLibraryHeader *header;
550 BOOL imageFound = FALSE;
552 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
553 "Entering ixNpeDlImageMgrImageFind\n");
556 /* If user didn't specify a library to use, use the default
557 * one from IxNpeMicrocode.h
559 if (imageLibrary == NULL)
561 imageLibrary = IxNpeMicroCodeImageLibrary;
564 if (ixNpeDlImageMgrSignatureCheck (imageLibrary))
566 header = (IxNpeDlImageMgrImageLibraryHeader *) imageLibrary;
568 /* for each image entry in the image library header ... */
569 while ((header->entry[imageCount].eohMarker !=
570 IX_NPEDL_IMAGEMGR_END_OF_HEADER) && !(imageFound))
572 /* if a match for imageId is found in the image library header... */
573 if (imageId == header->entry[imageCount].image.id)
576 * get pointer to the image in the image library using offset from
577 * 1st word in image library
579 imageOffset = header->entry[imageCount].image.offset;
580 *imagePtr = &imageLibrary[imageOffset];
581 /* get the image size */
582 *imageSize = header->entry[imageCount].image.size;
588 if (status != IX_SUCCESS)
590 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
591 "imageId not found in image library header\n");
592 ixNpeDlImageMgrStats.imageIdNotFound++;
597 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
598 "invalid signature in image library\n");
601 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
602 "Exiting ixNpeDlImageMgrImageFind: status = %d\n", status);
608 * Function definition: ixNpeDlImageMgrImageFind
611 ixNpeDlImageMgrImageFind (
612 UINT32 *imageLibrary,
617 IxNpeDlImageMgrImageHeader *image;
620 /* If user didn't specify a library to use, use the default
621 * one from IxNpeMicrocode.h
623 if (imageLibrary == NULL)
625 #ifdef IX_NPEDL_READ_MICROCODE_FROM_FILE
626 if (ixNpeMicrocode_binaryArray == NULL)
628 printk (KERN_ERR "ixp400.o: ERROR, no Microcode found in memory\n");
633 imageLibrary = ixNpeMicrocode_binaryArray;
636 imageLibrary = IxNpeMicroCodeImageLibrary;
637 #endif /* IX_NPEDL_READ_MICROCODE_FROM_FILE */
641 /* For backward's compatibility with previous image format */
642 if (ixNpeDlImageMgrSignatureCheck(imageLibrary))
644 return ixNpeDlImageMgrImageFind_legacy(imageLibrary,
651 while (*(imageLibrary+offset) == NPE_IMAGE_MARKER)
653 image = (IxNpeDlImageMgrImageHeader *)(imageLibrary+offset);
654 offset += sizeof(IxNpeDlImageMgrImageHeader)/sizeof(UINT32);
656 if (image->id == imageId)
658 *imagePtr = imageLibrary + offset;
659 *imageSize = image->size;
662 /* 2 consecutive NPE_IMAGE_MARKER's indicates end of library */
663 else if (image->id == NPE_IMAGE_MARKER)
665 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
666 "imageId not found in image library header\n");
667 ixNpeDlImageMgrStats.imageIdNotFound++;
668 /* reached end of library, image not found */
671 offset += image->size;
674 /* If we get here, our image library may be corrupted */
675 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
676 "image library format may be invalid or corrupted\n");