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;
143 static UINT32* getIxNpeMicroCodeImageLibrary(void)
146 if ((s = getenv("npe_ucode")) != NULL)
147 return (UINT32*) simple_strtoul(s, NULL, 16);
149 return IxNpeMicroCodeImageLibrary;
153 * static function prototypes.
156 ixNpeDlImageMgrSignatureCheck (UINT32 *microCodeImageLibrary);
159 ixNpeDlImageMgrImageIdFormat (UINT32 rawImageId, IxNpeDlImageId *imageId);
162 ixNpeDlImageMgrImageIdCompare (IxNpeDlImageId *imageIdA,
163 IxNpeDlImageId *imageIdB);
166 ixNpeDlImageMgrNpeFunctionIdCompare (IxNpeDlImageId *imageIdA,
167 IxNpeDlImageId *imageIdB);
171 ixNpeDlImageMgrImageFind_legacy (UINT32 *imageLibrary,
177 * Function definition: ixNpeDlImageMgrMicrocodeImageLibraryOverride
179 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
180 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
183 ixNpeDlImageMgrMicrocodeImageLibraryOverride (
184 UINT32 *clientImageLibrary)
186 IX_STATUS status = IX_SUCCESS;
188 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
189 "Entering ixNpeDlImageMgrMicrocodeImageLibraryOverride\n");
191 if (ixNpeDlImageMgrSignatureCheck (clientImageLibrary))
193 IxNpeMicroCodeImageLibrary = clientImageLibrary;
197 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrMicrocodeImageLibraryOverride: "
198 "Client-supplied image has invalid signature\n");
202 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
203 "Exiting ixNpeDlImageMgrMicrocodeImageLibraryOverride: status = %d\n",
210 * Function definition: ixNpeDlImageMgrImageListExtract
212 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
213 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
216 ixNpeDlImageMgrImageListExtract (
217 IxNpeDlImageId *imageListPtr,
221 IxNpeDlImageId formattedImageId;
222 IX_STATUS status = IX_SUCCESS;
223 UINT32 imageCount = 0;
224 IxNpeDlImageMgrImageLibraryHeader *header;
226 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
227 "Entering ixNpeDlImageMgrImageListExtract\n");
229 header = (IxNpeDlImageMgrImageLibraryHeader *) getIxNpeMicroCodeImageLibrary();
231 if (ixNpeDlImageMgrSignatureCheck (getIxNpeMicroCodeImageLibrary()))
233 /* for each image entry in the image header ... */
234 while (header->entry[imageCount].eohMarker !=
235 IX_NPEDL_IMAGEMGR_END_OF_HEADER)
238 * if the image list container from calling function has capacity,
239 * add the image id to the list
241 if ((imageListPtr != NULL) && (imageCount < *numImages))
243 rawImageId = header->entry[imageCount].image.id;
244 ixNpeDlImageMgrImageIdFormat (rawImageId, &formattedImageId);
245 imageListPtr[imageCount] = formattedImageId;
247 /* imageCount reflects no. of image entries in image library header */
252 * if image list container from calling function was too small to
253 * contain all image ids in the header, set return status to FAIL
255 if ((imageListPtr != NULL) && (imageCount > *numImages))
258 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageListExtract: "
259 "number of Ids found exceeds list capacity\n");
260 ixNpeDlImageMgrStats.imageIdListOverflow++;
262 /* return number of image ids found in image library header */
263 *numImages = imageCount;
268 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageListExtract: "
269 "invalid signature in image\n");
272 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
273 "Exiting ixNpeDlImageMgrImageListExtract: status = %d\n",
280 * Function definition: ixNpeDlImageMgrImageLocate
282 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
283 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
286 ixNpeDlImageMgrImageLocate (
287 IxNpeDlImageId *imageId,
293 IxNpeDlImageId formattedImageId;
294 /* used to index image entries in image library header */
295 UINT32 imageCount = 0;
296 IX_STATUS status = IX_FAIL;
297 IxNpeDlImageMgrImageLibraryHeader *header;
299 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
300 "Entering ixNpeDlImageMgrImageLocate\n");
302 header = (IxNpeDlImageMgrImageLibraryHeader *) getIxNpeMicroCodeImageLibrary();
304 if (ixNpeDlImageMgrSignatureCheck (getIxNpeMicroCodeImageLibrary()))
306 /* for each image entry in the image library header ... */
307 while (header->entry[imageCount].eohMarker !=
308 IX_NPEDL_IMAGEMGR_END_OF_HEADER)
310 rawImageId = header->entry[imageCount].image.id;
311 ixNpeDlImageMgrImageIdFormat (rawImageId, &formattedImageId);
312 /* if a match for imageId is found in the image library header... */
313 if (ixNpeDlImageMgrImageIdCompare (imageId, &formattedImageId))
316 * get pointer to the image in the image library using offset from
317 * 1st word in image library
319 UINT32 *tmp=getIxNpeMicroCodeImageLibrary();
320 imageOffset = header->entry[imageCount].image.offset;
321 *imagePtr = &tmp[imageOffset];
322 /* get the image size */
323 *imageSize = header->entry[imageCount].image.size;
329 if (status != IX_SUCCESS)
331 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageLocate: "
332 "imageId not found in image library header\n");
333 ixNpeDlImageMgrStats.imageIdNotFound++;
338 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageLocate: "
339 "invalid signature in image library\n");
342 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
343 "Exiting ixNpeDlImageMgrImageLocate: status = %d\n", status);
348 * Function definition: ixNpeDlImageMgrLatestImageExtract
350 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
351 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
354 ixNpeDlImageMgrLatestImageExtract (IxNpeDlImageId *imageId)
356 UINT32 imageCount = 0;
358 IxNpeDlImageId formattedImageId;
359 IX_STATUS status = IX_FAIL;
360 IxNpeDlImageMgrImageLibraryHeader *header;
363 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
364 "Entering ixNpeDlImageMgrLatestImageExtract\n");
366 header = (IxNpeDlImageMgrImageLibraryHeader *) getIxNpeMicroCodeImageLibrary();
368 if (ixNpeDlImageMgrSignatureCheck (getIxNpeMicroCodeImageLibrary()))
370 /* for each image entry in the image library header ... */
371 while (header->entry[imageCount].eohMarker !=
372 IX_NPEDL_IMAGEMGR_END_OF_HEADER)
374 rawImageId = header->entry[imageCount].image.id;
375 ixNpeDlImageMgrImageIdFormat (rawImageId, &formattedImageId);
377 * if a match for the npe Id and functionality Id of the imageId is
378 * found in the image library header...
380 if(ixNpeDlImageMgrNpeFunctionIdCompare(imageId, &formattedImageId))
382 if(imageId->major <= formattedImageId.major)
384 if(imageId->minor < formattedImageId.minor)
386 imageId->minor = formattedImageId.minor;
388 imageId->major = formattedImageId.major;
394 if (status != IX_SUCCESS)
396 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrLatestImageExtract: "
397 "imageId not found in image library header\n");
398 ixNpeDlImageMgrStats.imageIdNotFound++;
403 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrLatestImageGet: "
404 "invalid signature in image library\n");
407 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
408 "Exiting ixNpeDlImageMgrLatestImageGet: status = %d\n", status);
413 * Function definition: ixNpeDlImageMgrSignatureCheck
415 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
416 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
419 ixNpeDlImageMgrSignatureCheck (UINT32 *microCodeImageLibrary)
421 IxNpeDlImageMgrImageLibraryHeader *header =
422 (IxNpeDlImageMgrImageLibraryHeader *) microCodeImageLibrary;
425 if (header->signature != IX_NPEDL_IMAGEMGR_SIGNATURE)
428 ixNpeDlImageMgrStats.invalidSignature++;
436 * Function definition: ixNpeDlImageMgrImageIdFormat
438 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
439 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
442 ixNpeDlImageMgrImageIdFormat (
444 IxNpeDlImageId *imageId)
446 imageId->npeId = (rawImageId >>
447 IX_NPEDL_IMAGEID_NPEID_OFFSET) &
448 IX_NPEDL_NPEIMAGE_FIELD_MASK;
449 imageId->functionalityId = (rawImageId >>
450 IX_NPEDL_IMAGEID_FUNCTIONID_OFFSET) &
451 IX_NPEDL_NPEIMAGE_FIELD_MASK;
452 imageId->major = (rawImageId >>
453 IX_NPEDL_IMAGEID_MAJOR_OFFSET) &
454 IX_NPEDL_NPEIMAGE_FIELD_MASK;
455 imageId->minor = (rawImageId >>
456 IX_NPEDL_IMAGEID_MINOR_OFFSET) &
457 IX_NPEDL_NPEIMAGE_FIELD_MASK;
463 * Function definition: ixNpeDlImageMgrImageIdCompare
465 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
466 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
469 ixNpeDlImageMgrImageIdCompare (
470 IxNpeDlImageId *imageIdA,
471 IxNpeDlImageId *imageIdB)
473 if ((imageIdA->npeId == imageIdB->npeId) &&
474 (imageIdA->functionalityId == imageIdB->functionalityId) &&
475 (imageIdA->major == imageIdB->major) &&
476 (imageIdA->minor == imageIdB->minor))
487 * Function definition: ixNpeDlImageMgrNpeFunctionIdCompare
489 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
490 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
493 ixNpeDlImageMgrNpeFunctionIdCompare (
494 IxNpeDlImageId *imageIdA,
495 IxNpeDlImageId *imageIdB)
497 if ((imageIdA->npeId == imageIdB->npeId) &&
498 (imageIdA->functionalityId == imageIdB->functionalityId))
510 * Function definition: ixNpeDlImageMgrStatsShow
513 ixNpeDlImageMgrStatsShow (void)
515 ixOsalLog (IX_OSAL_LOG_LVL_USER,
516 IX_OSAL_LOG_DEV_STDOUT,
517 "\nixNpeDlImageMgrStatsShow:\n"
518 "\tInvalid Image Signatures: %u\n"
519 "\tImage Id List capacity too small: %u\n"
520 "\tImage Id not found: %u\n\n",
521 ixNpeDlImageMgrStats.invalidSignature,
522 ixNpeDlImageMgrStats.imageIdListOverflow,
523 ixNpeDlImageMgrStats.imageIdNotFound,
529 * Function definition: ixNpeDlImageMgrStatsReset
532 ixNpeDlImageMgrStatsReset (void)
534 ixNpeDlImageMgrStats.invalidSignature = 0;
535 ixNpeDlImageMgrStats.imageIdListOverflow = 0;
536 ixNpeDlImageMgrStats.imageIdNotFound = 0;
542 * Function definition: ixNpeDlImageMgrImageFind_legacy
544 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
545 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
548 ixNpeDlImageMgrImageFind_legacy (
549 UINT32 *imageLibrary,
555 /* used to index image entries in image library header */
556 UINT32 imageCount = 0;
557 IX_STATUS status = IX_FAIL;
558 IxNpeDlImageMgrImageLibraryHeader *header;
559 BOOL imageFound = FALSE;
561 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
562 "Entering ixNpeDlImageMgrImageFind\n");
565 /* If user didn't specify a library to use, use the default
566 * one from IxNpeMicrocode.h
568 if (imageLibrary == NULL)
570 imageLibrary = IxNpeMicroCodeImageLibrary;
573 if (ixNpeDlImageMgrSignatureCheck (imageLibrary))
575 header = (IxNpeDlImageMgrImageLibraryHeader *) imageLibrary;
577 /* for each image entry in the image library header ... */
578 while ((header->entry[imageCount].eohMarker !=
579 IX_NPEDL_IMAGEMGR_END_OF_HEADER) && !(imageFound))
581 /* if a match for imageId is found in the image library header... */
582 if (imageId == header->entry[imageCount].image.id)
585 * get pointer to the image in the image library using offset from
586 * 1st word in image library
588 imageOffset = header->entry[imageCount].image.offset;
589 *imagePtr = &imageLibrary[imageOffset];
590 /* get the image size */
591 *imageSize = header->entry[imageCount].image.size;
597 if (status != IX_SUCCESS)
599 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
600 "imageId not found in image library header\n");
601 ixNpeDlImageMgrStats.imageIdNotFound++;
606 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
607 "invalid signature in image library\n");
610 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
611 "Exiting ixNpeDlImageMgrImageFind: status = %d\n", status);
617 * Function definition: ixNpeDlImageMgrImageFind
620 ixNpeDlImageMgrImageFind (
621 UINT32 *imageLibrary,
626 IxNpeDlImageMgrImageHeader *image;
629 /* If user didn't specify a library to use, use the default
630 * one from IxNpeMicrocode.h
632 if (imageLibrary == NULL)
634 #ifdef IX_NPEDL_READ_MICROCODE_FROM_FILE
635 if (ixNpeMicrocode_binaryArray == NULL)
637 printk (KERN_ERR "ixp400.o: ERROR, no Microcode found in memory\n");
642 imageLibrary = ixNpeMicrocode_binaryArray;
645 imageLibrary = getIxNpeMicroCodeImageLibrary();
646 #endif /* IX_NPEDL_READ_MICROCODE_FROM_FILE */
650 /* For backward's compatibility with previous image format */
651 if (ixNpeDlImageMgrSignatureCheck(imageLibrary))
653 return ixNpeDlImageMgrImageFind_legacy(imageLibrary,
660 while (*(imageLibrary+offset) == NPE_IMAGE_MARKER)
662 image = (IxNpeDlImageMgrImageHeader *)(imageLibrary+offset);
663 offset += sizeof(IxNpeDlImageMgrImageHeader)/sizeof(UINT32);
665 if (image->id == imageId)
667 *imagePtr = imageLibrary + offset;
668 *imageSize = image->size;
671 /* 2 consecutive NPE_IMAGE_MARKER's indicates end of library */
672 else if (image->id == NPE_IMAGE_MARKER)
674 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
675 "imageId not found in image library header\n");
676 ixNpeDlImageMgrStats.imageIdNotFound++;
677 /* reached end of library, image not found */
680 offset += image->size;
683 /* If we get here, our image library may be corrupted */
684 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
685 "image library format may be invalid or corrupted\n");