summaryrefslogtreecommitdiff
path: root/drivers/net/npe/IxNpeDl.c
blob: bfeac877901f7f4fd5da249e04bb49703162f211 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
/**
 * @file IxNpeDl.c
 *
 * @author Intel Corporation
 * @date 08 January 2002
 *
 * @brief This file contains the implementation of the public API for the
 *        IXP425 NPE Downloader component
 *
 *
 * @par
 * IXP400 SW Release version 2.0
 *
 * -- Copyright Notice --
 *
 * @par
 * Copyright 2001-2005, Intel Corporation.
 * All rights reserved.
 *
 * @par
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the Intel Corporation nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * @par
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * @par
 * -- End of Copyright Notice --
*/

/*
 * Put the system defined include files required
 */

/*
 * Put the user defined include files required
 */
#include "IxNpeDl.h"
#include "IxNpeDlImageMgr_p.h"
#include "IxNpeDlNpeMgr_p.h"
#include "IxNpeDlMacros_p.h"
#include "IxFeatureCtrl.h"
#include "IxOsal.h"
/*
 * #defines used in this file
 */
 #define IMAGEID_MAJOR_NUMBER_DEFAULT 0
 #define IMAGEID_MINOR_NUMBER_DEFAULT 0

/*
 * Typedefs whose scope is limited to this file.
 */
typedef struct
{
    BOOL validImage;
    IxNpeDlImageId imageId;
} IxNpeDlNpeState;

/* module statistics counters */
typedef struct
{
    UINT32 attemptedDownloads;
    UINT32 successfulDownloads;
    UINT32 criticalFailDownloads;
} IxNpeDlStats;

/*
 * Variable declarations global to this file only.  Externs are followed
 * by static variables.
 */
static IxNpeDlNpeState ixNpeDlNpeState[IX_NPEDL_NPEID_MAX] =
{
    {false, {IX_NPEDL_NPEID_MAX, 0, 0, 0}},
    {false, {IX_NPEDL_NPEID_MAX, 0, 0, 0}},
    {false, {IX_NPEDL_NPEID_MAX, 0, 0, 0}}
};

static IxNpeDlStats ixNpeDlStats;

/*
 * Software guard to prevent NPE from being started multiple times.
 */
static BOOL ixNpeDlNpeStarted[IX_NPEDL_NPEID_MAX] ={false, false, false} ;


/*
 * static function prototypes.
 */
PRIVATE IX_STATUS
ixNpeDlNpeInitAndStartInternal (UINT32 *imageLibrary, UINT32 imageId);

/*
 * Function definition: ixNpeDlImageDownload
 */
PUBLIC IX_STATUS
ixNpeDlImageDownload (IxNpeDlImageId *imageIdPtr,
                      BOOL verify)
{
    UINT32        imageSize;
    UINT32       *imageCodePtr  = NULL;
    IX_STATUS     status;
    IxNpeDlNpeId  npeId           = imageIdPtr->npeId;

    IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
                     "Entering ixNpeDlImageDownload\n");

    ixNpeDlStats.attemptedDownloads++;

    /* Check input parameters */
    if ((npeId >= IX_NPEDL_NPEID_MAX) || (npeId < 0))
    {
        status = IX_NPEDL_PARAM_ERR;
        IX_NPEDL_ERROR_REPORT ("ixNpeDlImageDownload - invalid parameter\n");
    }
    else
    {
        /* Ensure initialisation has been completed */
        ixNpeDlNpeMgrInit();

	/* If not IXP42X A0 stepping, proceed to check for existence of npe's */
	if ((IX_FEATURE_CTRL_SILICON_TYPE_A0 !=
	     (ixFeatureCtrlProductIdRead() & IX_FEATURE_CTRL_SILICON_STEPPING_MASK))
	    || (IX_FEATURE_CTRL_DEVICE_TYPE_IXP42X != ixFeatureCtrlDeviceRead ()))
	{
            if (npeId == IX_NPEDL_NPEID_NPEA)
            {
                if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEA) ==
                    IX_FEATURE_CTRL_COMPONENT_DISABLED)
                {
                    IX_NPEDL_WARNING_REPORT("Warning: the NPE A component you specified does"
                                            " not exist\n");
                    return IX_SUCCESS;
                }
            } /* end of if(npeId) */
            else if (npeId == IX_NPEDL_NPEID_NPEB)
            {
                if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEB)==
                    IX_FEATURE_CTRL_COMPONENT_DISABLED)
                {
                    IX_NPEDL_WARNING_REPORT("Warning: the NPE B component you specified"
                                            " does not exist\n");
                    return IX_SUCCESS;
                }
            } /* end of elseif(npeId) */
            else if (npeId == IX_NPEDL_NPEID_NPEC)
            {
                if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEC)==
                    IX_FEATURE_CTRL_COMPONENT_DISABLED)
                {
                    IX_NPEDL_WARNING_REPORT("Warning: the NPE C component you specified"
                                            " does not exist\n");
                    return IX_SUCCESS;
                }
            } /* end of elseif(npeId) */
        } /* end of if(IX_FEATURE_CTRL_SILICON_TYPE_B0) */ /*End of Silicon Type Check*/

        /* stop and reset the NPE */
        if (IX_SUCCESS != ixNpeDlNpeStopAndReset (npeId))
        {
            IX_NPEDL_ERROR_REPORT ("Failed to stop and reset NPE\n");
            return IX_FAIL;
        }

        /* Locate image */
        status = ixNpeDlImageMgrImageLocate (imageIdPtr, &imageCodePtr,
                                             &imageSize);
        if (IX_SUCCESS == status)
        {
            /*
             * If download was successful, store image Id in list of
             * currently loaded images. If a critical error occured
             * during download, record that the NPE has an invalid image
             */
            status = ixNpeDlNpeMgrImageLoad (npeId, imageCodePtr,
                                             verify);
            if (IX_SUCCESS == status)
            {
                ixNpeDlNpeState[npeId].imageId = *imageIdPtr;
                ixNpeDlNpeState[npeId].validImage = true;
                ixNpeDlStats.successfulDownloads++;

                status =  ixNpeDlNpeExecutionStart (npeId);
            }
            else if ((status == IX_NPEDL_CRITICAL_NPE_ERR) ||
                     (status == IX_NPEDL_CRITICAL_MICROCODE_ERR))
            {
                ixNpeDlNpeState[npeId].imageId = *imageIdPtr;
                ixNpeDlNpeState[npeId].validImage = false;
                ixNpeDlStats.criticalFailDownloads++;
            }
        } /* end of if(IX_SUCCESS) */ /* condition: image located successfully in microcode image */
    } /* end of if-else(npeId) */ /* condition: parameter checks ok */

    IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
                     "Exiting ixNpeDlImageDownload : status = %d\n", status);
    return status;
}

/*
 * Function definition: ixNpeDlAvailableImagesCountGet
 */
PUBLIC IX_STATUS
ixNpeDlAvailableImagesCountGet (UINT32 *numImagesPtr)
{
    IX_STATUS status;

    IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
                     "Entering ixNpeDlAvailableImagesCountGet\n");

    /* Check input parameters */
    if (numImagesPtr == NULL)
    {
        status = IX_NPEDL_PARAM_ERR;
        IX_NPEDL_ERROR_REPORT ("ixNpeDlAvailableImagesCountGet - "
                               "invalid parameter\n");
    }
    else
    {
        /*
         * Use ImageMgr module to get no. of images listed in Image Library Header.
         * If NULL is passed as imageListPtr parameter to following function,
         * it will only fill number of images into numImagesPtr
         */
        status = ixNpeDlImageMgrImageListExtract (NULL, numImagesPtr);
    } /* end of if-else(numImagesPtr) */

    IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
                     "Exiting ixNpeDlAvailableImagesCountGet : "
                     "status = %d\n", status);
    return status;
}

/*
 * Function definition: ixNpeDlAvailableImagesListGet
 */
PUBLIC IX_STATUS
ixNpeDlAvailableImagesListGet (IxNpeDlImageId *imageIdListPtr,
                               UINT32 *listSizePtr)
{
    IX_STATUS status;

    IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
                     "Entering ixNpeDlAvailableImagesListGet\n");

    /* Check input parameters */
    if ((imageIdListPtr == NULL) || (listSizePtr == NULL))
    {
        status = IX_NPEDL_PARAM_ERR;
        IX_NPEDL_ERROR_REPORT ("ixNpeDlAvailableImagesListGet - "
                               "invalid parameter\n");
    }
    else
    {
        /* Call ImageMgr to get list of images listed in Image Library Header */
        status = ixNpeDlImageMgrImageListExtract (imageIdListPtr,
                                                  listSizePtr);
    } /* end of if-else(imageIdListPtr) */

    IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
                     "Exiting ixNpeDlAvailableImagesListGet : status = %d\n",
                     status);
    return status;
}

/*
 * Function definition: ixNpeDlLoadedImageGet
 */
PUBLIC IX_STATUS
ixNpeDlLoadedImageGet (IxNpeDlNpeId npeId,
                       IxNpeDlImageId *imageIdPtr)
{
    IX_STATUS status = IX_SUCCESS;

    IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
                     "Entering ixNpeDlLoadedImageGet\n");

    /* Check input parameters */
    if ((npeId >= IX_NPEDL_NPEID_MAX) || (npeId < 0) || (imageIdPtr == NULL))
    {
        status = IX_NPEDL_PARAM_ERR;
        IX_NPEDL_ERROR_REPORT ("ixNpeDlLoadedImageGet - invalid parameter\n");
    }
    else
    {

         /* If not IXP42X A0 stepping, proceed to check for existence of npe's */
         if ((IX_FEATURE_CTRL_SILICON_TYPE_A0 !=
	      (ixFeatureCtrlProductIdRead() & IX_FEATURE_CTRL_SILICON_STEPPING_MASK))
	     || (IX_FEATURE_CTRL_DEVICE_TYPE_IXP42X != ixFeatureCtrlDeviceRead ()))
        {
            if (npeId == IX_NPEDL_NPEID_NPEA &&
                (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEA) ==
                 IX_FEATURE_CTRL_COMPONENT_DISABLED))
            {
                IX_NPEDL_WARNING_REPORT("Warning: the NPE A component you specified does"
                                        " not exist\n");
                return IX_SUCCESS;
            } /* end of if(npeId) */

            if (npeId == IX_NPEDL_NPEID_NPEB &&
                (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEB) ==
                 IX_FEATURE_CTRL_COMPONENT_DISABLED))
            {
                IX_NPEDL_WARNING_REPORT("Warning: the NPE B component you specified does"
                                        " not exist\n");
                return IX_SUCCESS;
            } /* end of if(npeId) */

            if (npeId == IX_NPEDL_NPEID_NPEC &&
                (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEC) ==
                 IX_FEATURE_CTRL_COMPONENT_DISABLED))
            {
                IX_NPEDL_WARNING_REPORT("Warning: the NPE C component you specified does"
                                        " not exist\n");
                return IX_SUCCESS;
            } /* end of if(npeId) */
        } /* end of if not IXP42x-A0 silicon */

        if (ixNpeDlNpeState[npeId].validImage)
        {
            /* use npeId to get imageId from list of currently loaded
               images */
            *imageIdPtr = ixNpeDlNpeState[npeId].imageId;
        }
        else
        {
            status = IX_FAIL;
        } /* end of if-else(ixNpeDlNpeState) */
    } /* end of if-else(npeId) */

    IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
                     "Exiting ixNpeDlLoadedImageGet : status = %d\n",
                     status);
    return status;
}

/*
 * Function definition: ixNpeDlLatestImageGet
 */
PUBLIC IX_STATUS
ixNpeDlLatestImageGet (
    IxNpeDlNpeId npeId,
    IxNpeDlFunctionalityId functionalityId,
    IxNpeDlImageId *imageIdPtr)
{
    IX_STATUS status;

    IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
                     "Entering ixNpeDlLatestImageGet\n");

    /* Check input parameters */
    if ((npeId >= IX_NPEDL_NPEID_MAX) ||
        (npeId < 0) ||
        (imageIdPtr == NULL))
    {
        status = IX_NPEDL_PARAM_ERR;
        IX_NPEDL_ERROR_REPORT ("ixNpeDlLatestImageGet - "
                               "invalid parameter\n");
    } /* end of if(npeId) */
    else
    {

	/* If not IXP42X A0 stepping, proceed to check for existence of npe's */
	if ((IX_FEATURE_CTRL_SILICON_TYPE_A0 !=
	     (ixFeatureCtrlProductIdRead() & IX_FEATURE_CTRL_SILICON_STEPPING_MASK))
	    || (IX_FEATURE_CTRL_DEVICE_TYPE_IXP42X != ixFeatureCtrlDeviceRead ()))
        {
            if (npeId == IX_NPEDL_NPEID_NPEA &&
                (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEA) ==
                 IX_FEATURE_CTRL_COMPONENT_DISABLED))
            {
                IX_NPEDL_WARNING_REPORT("Warning: the NPE A component you specified does"
                                        " not exist\n");
                return IX_SUCCESS;
            } /* end of if(npeId) */

            if (npeId == IX_NPEDL_NPEID_NPEB &&
                (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEB) ==
                 IX_FEATURE_CTRL_COMPONENT_DISABLED))
            {
                IX_NPEDL_WARNING_REPORT("Warning: the NPE B component you specified does"
                                        " not exist\n");
                return IX_SUCCESS;
            } /* end of if(npeId) */

            if (npeId == IX_NPEDL_NPEID_NPEC &&
                (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEC) ==
                 IX_FEATURE_CTRL_COMPONENT_DISABLED))
            {
                IX_NPEDL_WARNING_REPORT("Warning: the NPE C component you specified does"
                                        " not exist\n");
                return IX_SUCCESS;
            } /* end of if(npeId) */
        } /* end of if not IXP42x-A0 silicon */

        imageIdPtr->npeId = npeId;
        imageIdPtr->functionalityId = functionalityId;
        imageIdPtr->major = IMAGEID_MAJOR_NUMBER_DEFAULT;
        imageIdPtr->minor = IMAGEID_MINOR_NUMBER_DEFAULT;
        /* Call ImageMgr to get list of images listed in Image Library Header */
        status = ixNpeDlImageMgrLatestImageExtract(imageIdPtr);
    } /* end of if-else(npeId) */

    IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
                     "Exiting ixNpeDlLatestImageGet : status = %d\n",
                     status);

    return status;
}

/*
 * Function definition: ixNpeDlNpeStopAndReset
 */
PUBLIC IX_STATUS
ixNpeDlNpeStopAndReset (IxNpeDlNpeId npeId)
{
    IX_STATUS status = IX_SUCCESS;

    IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
                     "Entering ixNpeDlNpeStopAndReset\n");

    /* Ensure initialisation has been completed */
    ixNpeDlNpeMgrInit();

    /* If not IXP42X A0 stepping, proceed to check for existence of npe's */
    if ((IX_FEATURE_CTRL_SILICON_TYPE_A0 !=
	 (ixFeatureCtrlProductIdRead() & IX_FEATURE_CTRL_SILICON_STEPPING_MASK))
	|| (IX_FEATURE_CTRL_DEVICE_TYPE_IXP42X != ixFeatureCtrlDeviceRead ()))
    {
        /*
         * Check whether NPE is present
         */
        if (IX_NPEDL_NPEID_NPEA == npeId)
        {
            /* Check whether NPE A is present */
            if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEA)==
                IX_FEATURE_CTRL_COMPONENT_DISABLED)
            {
                /* NPE A does not present */
                IX_NPEDL_WARNING_REPORT ("ixNpeDlNpeStopAndReset - Warning:NPEA does not present.\n");
                return IX_SUCCESS;
            }
        } /* end of if(IX_NPEDL_NPEID_NPEA) */
        else if (IX_NPEDL_NPEID_NPEB == npeId)
        {
            /* Check whether NPE B is present */
            if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEB)==
                IX_FEATURE_CTRL_COMPONENT_DISABLED)
            {
                /* NPE B does not present */
                IX_NPEDL_WARNING_REPORT ("ixNpeDlNpeStopAndReset - Warning:NPEB does not present.\n");
                return IX_SUCCESS;
            }
        } /* end of elseif(IX_NPEDL_NPEID_NPEB) */
        else if (IX_NPEDL_NPEID_NPEC == npeId)
        {
            /* Check whether NPE C is present */
            if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEC)==
                IX_FEATURE_CTRL_COMPONENT_DISABLED)
            {
                /* NPE C does not present */
                IX_NPEDL_WARNING_REPORT ("ixNpeDlNpeStopAndReset - Warning:NPEC does not present.\n");
                return IX_SUCCESS;
            }
        } /* end of elseif(IX_NPEDL_NPEID_NPEC) */
        else
        {
            /* Invalid NPE ID */
            IX_NPEDL_ERROR_REPORT ("ixNpeDlNpeStopAndReset - invalid Npe ID\n");
            status = IX_NPEDL_PARAM_ERR;
        } /* end of if-else(IX_NPEDL_NPEID_NPEC) */
    } /* end of if not IXP42x-A0 Silicon */

    if (status == IX_SUCCESS)
    {
        /* call NpeMgr function to stop the NPE */
        status = ixNpeDlNpeMgrNpeStop (npeId);
        if (status == IX_SUCCESS)
        {
            /* call NpeMgr function to reset the NPE */
            status = ixNpeDlNpeMgrNpeReset (npeId);
        }
    } /* end of if(status) */

    IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
                     "Exiting ixNpeDlNpeStopAndReset : status = %d\n", status);

    if (IX_SUCCESS == status)
    {
        /* Indicate NPE has been stopped */
        ixNpeDlNpeStarted[npeId] = false ;
    }

    return status;
}

/*
 * Function definition: ixNpeDlNpeExecutionStart
 */
PUBLIC IX_STATUS
ixNpeDlNpeExecutionStart (IxNpeDlNpeId npeId)
{
    IX_STATUS status = IX_SUCCESS;

    IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
                     "Entering ixNpeDlNpeExecutionStart\n");

    /* If not IXP42X A0 stepping, proceed to check for existence of npe's */
    if ((IX_FEATURE_CTRL_SILICON_TYPE_A0 !=
	 (ixFeatureCtrlProductIdRead() & IX_FEATURE_CTRL_SILICON_STEPPING_MASK))
	|| (IX_FEATURE_CTRL_DEVICE_TYPE_IXP42X != ixFeatureCtrlDeviceRead ()))
    {
        /*
         * Check whether NPE is present
         */
        if (IX_NPEDL_NPEID_NPEA == npeId)
        {
            /* Check whether NPE A is present */
            if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEA)==
                IX_FEATURE_CTRL_COMPONENT_DISABLED)
            {
                /* NPE A does not present */
                IX_NPEDL_WARNING_REPORT ("ixNpeDlNpeExecutionStart - Warning:NPEA does not present.\n");
                return IX_SUCCESS;
            }
        } /* end of if(IX_NPEDL_NPEID_NPEA) */
        else if (IX_NPEDL_NPEID_NPEB == npeId)
        {
            /* Check whether NPE B is present */
            if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEB)==
                IX_FEATURE_CTRL_COMPONENT_DISABLED)
            {
                /* NPE B does not present */
                IX_NPEDL_WARNING_REPORT ("ixNpeDlNpeExecutionStart - Warning:NPEB does not present.\n");
                return IX_SUCCESS;
            }
        } /* end of elseif(IX_NPEDL_NPEID_NPEB) */
        else if (IX_NPEDL_NPEID_NPEC ==  npeId)
        {
            /* Check whether NPE C is present */
            if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEC)==
                IX_FEATURE_CTRL_COMPONENT_DISABLED)
            {
                /* NPE C does not present */
                IX_NPEDL_WARNING_REPORT ("ixNpeDlNpeExecutionStart - Warning:NPEC does not present.\n");
                return IX_SUCCESS;
            }
        } /* end of elseif(IX_NPEDL_NPEID_NPEC) */
        else
        {
            /* Invalid NPE ID */
            IX_NPEDL_ERROR_REPORT ("ixNpeDlNpeExecutionStart - invalid Npe ID\n");
            return IX_NPEDL_PARAM_ERR;
        } /* end of if-else(IX_NPEDL_NPEID_NPEC) */
    } /* end of if not IXP42x-A0 Silicon */

    if (true == ixNpeDlNpeStarted[npeId])
    {
        /* NPE has been started. */
        return IX_SUCCESS ;
    }

    /* Ensure initialisation has been completed */
    ixNpeDlNpeMgrInit();

    /* call NpeMgr function to start the NPE */
    status = ixNpeDlNpeMgrNpeStart (npeId);

    if (IX_SUCCESS == status)
    {
        /* Indicate NPE has started */
        ixNpeDlNpeStarted[npeId] = true ;
    }

    IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
                     "Exiting ixNpeDlNpeExecutionStart : status = %d\n",
                     status);

    return status;
}

/*
 * Function definition: ixNpeDlNpeExecutionStop
 */
PUBLIC IX_STATUS
ixNpeDlNpeExecutionStop (IxNpeDlNpeId npeId)
{
    IX_STATUS status = IX_SUCCESS;

    IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
                     "Entering ixNpeDlNpeExecutionStop\n");

    /* Ensure initialisation has been completed */
    ixNpeDlNpeMgrInit();

    /* If not IXP42X A0 stepping, proceed to check for existence of npe's */
    if ((IX_FEATURE_CTRL_SILICON_TYPE_A0 !=
	 (ixFeatureCtrlProductIdRead() & IX_FEATURE_CTRL_SILICON_STEPPING_MASK))
	|| (IX_FEATURE_CTRL_DEVICE_TYPE_IXP42X != ixFeatureCtrlDeviceRead ()))
    {
        /*
         * Check whether NPE is present
         */
        if (IX_NPEDL_NPEID_NPEA == npeId)
        {
            /* Check whether NPE A is present */
            if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEA)==
                IX_FEATURE_CTRL_COMPONENT_DISABLED)
            {
                /* NPE A does not present */
                IX_NPEDL_WARNING_REPORT ("ixNpeDlNpeExecutionStop - Warning:NPEA does not present.\n");
                return IX_SUCCESS;
            }
        } /* end of if(IX_NPEDL_NPEID_NPEA) */
        else if (IX_NPEDL_NPEID_NPEB == npeId)
        {
            /* Check whether NPE B is present */
            if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEB)==
                IX_FEATURE_CTRL_COMPONENT_DISABLED)
            {
                /* NPE B does not present */
                IX_NPEDL_WARNING_REPORT ("ixNpeDlNpeExecutionStop - Warning:NPEB does not present.\n");
                return IX_SUCCESS;
            }
        } /* end of elseif(IX_NPEDL_NPEID_NPEB) */
        else if (IX_NPEDL_NPEID_NPEC == npeId)
        {
            /* Check whether NPE C is present */
            if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEC)==
                IX_FEATURE_CTRL_COMPONENT_DISABLED)
            {
                /* NPE C does not present */
                IX_NPEDL_WARNING_REPORT ("ixNpeDlNpeExecutionStop - Warning:NPEC does not present.\n");
                return IX_SUCCESS;
            }
        } /* end of elseif(IX_NPEDL_NPEID_NPEC) */
        else
        {
            /* Invalid NPE ID */
            IX_NPEDL_ERROR_REPORT ("ixNpeDlNpeExecutionStop - invalid Npe ID\n");
            status = IX_NPEDL_PARAM_ERR;
        } /* end of if-else(IX_NPEDL_NPEID_NPEC) */
    } /* end of if not IXP42X-AO Silicon */

    if (status == IX_SUCCESS)
    {
        /* call NpeMgr function to stop the NPE */
        status = ixNpeDlNpeMgrNpeStop (npeId);
    }

    IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
                     "Exiting ixNpeDlNpeExecutionStop : status = %d\n",
                     status);

    if (IX_SUCCESS == status)
    {
        /* Indicate NPE has been stopped */
        ixNpeDlNpeStarted[npeId] = false ;
    }

    return status;
}

/*
 * Function definition: ixNpeDlUnload
 */
PUBLIC IX_STATUS
ixNpeDlUnload (void)
{
    IX_STATUS status;

    IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
                     "Entering ixNpeDlUnload\n");

    status = ixNpeDlNpeMgrUninit();

    IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
                     "Exiting ixNpeDlUnload : status = %d\n",
                     status);
    return status;
}

/*
 * Function definition: ixNpeDlStatsShow
 */
PUBLIC void
ixNpeDlStatsShow (void)
{
    ixOsalLog (IX_OSAL_LOG_LVL_USER,
               IX_OSAL_LOG_DEV_STDOUT,
               "\nixNpeDlStatsShow:\n"
               "\tDownloads Attempted by user: %u\n"
               "\tSuccessful Downloads: %u\n"
               "\tFailed Downloads (due to Critical Error): %u\n\n",
               ixNpeDlStats.attemptedDownloads,
               ixNpeDlStats.successfulDownloads,
               ixNpeDlStats.criticalFailDownloads,
               0,0,0);

    ixNpeDlImageMgrStatsShow ();
    ixNpeDlNpeMgrStatsShow ();
}

/*
 * Function definition: ixNpeDlStatsReset
 */
PUBLIC void
ixNpeDlStatsReset (void)
{
    ixNpeDlStats.attemptedDownloads = 0;
    ixNpeDlStats.successfulDownloads = 0;
    ixNpeDlStats.criticalFailDownloads = 0;

    ixNpeDlImageMgrStatsReset ();
    ixNpeDlNpeMgrStatsReset ();
}

/*
 * Function definition: ixNpeDlNpeInitAndStartInternal
 */
PRIVATE IX_STATUS
ixNpeDlNpeInitAndStartInternal (UINT32 *imageLibrary,
                                UINT32 imageId)
{
    UINT32        imageSize;
    UINT32       *imageCodePtr  = NULL;
    IX_STATUS     status;
    IxNpeDlNpeId  npeId = IX_NPEDL_NPEID_FROM_IMAGEID_GET(imageId);
    IxFeatureCtrlDeviceId deviceId = IX_NPEDL_DEVICEID_FROM_IMAGEID_GET(imageId);

    IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
                     "Entering ixNpeDlNpeInitAndStartInternal\n");

    ixNpeDlStats.attemptedDownloads++;

    /* Check input parameter device correctness */
    if ((deviceId >= IX_FEATURE_CTRL_DEVICE_TYPE_MAX) ||
        (deviceId < IX_FEATURE_CTRL_DEVICE_TYPE_IXP42X))
    {
        status = IX_NPEDL_PARAM_ERR;
        IX_NPEDL_ERROR_REPORT ("ixNpeDlNpeInitAndStartInternal - "
                               "invalid parameter\n");
    } /* End valid device id checking */

    /* Check input parameters */
    else if ((npeId >= IX_NPEDL_NPEID_MAX) || (npeId < 0))
    {
        status = IX_NPEDL_PARAM_ERR;
        IX_NPEDL_ERROR_REPORT ("ixNpeDlNpeInitAndStartInternal - "
                               "invalid parameter\n");
    }

    else
    {
        /* Ensure initialisation has been completed */
        ixNpeDlNpeMgrInit();

        /* Checking if image being loaded is meant for device that is running.
         * Image is forward compatible. i.e Image built for IXP42X should run
         * on IXP46X but not vice versa.*/
        if (deviceId > (ixFeatureCtrlDeviceRead() & IX_FEATURE_CTRL_DEVICE_TYPE_MASK))
        {
            IX_NPEDL_ERROR_REPORT ("ixNpeDlNpeInitAndStartInternal - "
                                   "Device type mismatch. NPE Image not "
                                   "meant for device in use \n");
            return IX_NPEDL_DEVICE_ERR;
        }/* if statement - matching image device and current device */

	/* If not IXP42X A0 stepping, proceed to check for existence of npe's */
	if ((IX_FEATURE_CTRL_SILICON_TYPE_A0 !=
	     (ixFeatureCtrlProductIdRead() & IX_FEATURE_CTRL_SILICON_STEPPING_MASK))
	    || (IX_FEATURE_CTRL_DEVICE_TYPE_IXP42X != ixFeatureCtrlDeviceRead ()))
        {
            if (npeId == IX_NPEDL_NPEID_NPEA)
            {
                if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEA) ==
                    IX_FEATURE_CTRL_COMPONENT_DISABLED)
                {
                    IX_NPEDL_WARNING_REPORT("Warning: the NPE A component you specified does"
                                            " not exist\n");
                    return IX_SUCCESS;
                }
            } /* end of if(npeId) */
            else if (npeId == IX_NPEDL_NPEID_NPEB)
            {
                if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEB)==
                    IX_FEATURE_CTRL_COMPONENT_DISABLED)
                {
                    IX_NPEDL_WARNING_REPORT("Warning: the NPE B component you specified"
                                            " does not exist\n");
                    return IX_SUCCESS;
                }
            } /* end of elseif(npeId) */
            else if (npeId == IX_NPEDL_NPEID_NPEC)
            {
                if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEC)==
                    IX_FEATURE_CTRL_COMPONENT_DISABLED)
                {
                    IX_NPEDL_WARNING_REPORT("Warning: the NPE C component you specified"
                                            " does not exist\n");
                    return IX_SUCCESS;
                }
            } /* end of elseif(npeId) */
        } /* end of if not IXP42X-A0 Silicon */

        /* stop and reset the NPE */
        status = ixNpeDlNpeStopAndReset (npeId);
        if (IX_SUCCESS != status)
        {
            IX_NPEDL_ERROR_REPORT ("Failed to stop and reset NPE\n");
            return status;
        }

        /* Locate image */
        status = ixNpeDlImageMgrImageFind (imageLibrary, imageId,
                                           &imageCodePtr, &imageSize);
        if (IX_SUCCESS == status)
        {
            /*
             * If download was successful, store image Id in list of
             * currently loaded images. If a critical error occured
             * during download, record that the NPE has an invalid image
             */
            status = ixNpeDlNpeMgrImageLoad (npeId, imageCodePtr, true);
            if (IX_SUCCESS == status)
            {
                ixNpeDlNpeState[npeId].validImage = true;
                ixNpeDlStats.successfulDownloads++;

                status = ixNpeDlNpeExecutionStart (npeId);
            }
            else if ((status == IX_NPEDL_CRITICAL_NPE_ERR) ||
                     (status == IX_NPEDL_CRITICAL_MICROCODE_ERR))
            {
                ixNpeDlNpeState[npeId].validImage = false;
                ixNpeDlStats.criticalFailDownloads++;
            }

            /* NOTE - The following section of code is here to support
             * a deprecated function ixNpeDlLoadedImageGet().  When that
             * function is removed from the API, this code should be revised.
             */
            ixNpeDlNpeState[npeId].imageId.npeId = npeId;
            ixNpeDlNpeState[npeId].imageId.functionalityId =
                IX_NPEDL_FUNCTIONID_FROM_IMAGEID_GET(imageId);
            ixNpeDlNpeState[npeId].imageId.major =
                IX_NPEDL_MAJOR_FROM_IMAGEID_GET(imageId);
            ixNpeDlNpeState[npeId].imageId.minor =
                IX_NPEDL_MINOR_FROM_IMAGEID_GET(imageId);
        } /* end of if(IX_SUCCESS) */ /* condition: image located successfully in microcode image */
    } /* end of if-else(npeId-deviceId) */ /* condition: parameter checks ok */

    IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
                     "Exiting ixNpeDlNpeInitAndStartInternal : "
                     "status = %d\n", status);
    return status;
}

/*
 * Function definition: ixNpeDlCustomImageNpeInitAndStart
 */
PUBLIC IX_STATUS
ixNpeDlCustomImageNpeInitAndStart (UINT32 *imageLibrary,
                                   UINT32 imageId)
{
    IX_STATUS status;

    if (imageLibrary == NULL)
    {
        status = IX_NPEDL_PARAM_ERR;
        IX_NPEDL_ERROR_REPORT ("ixNpeDlCustomImageNpeInitAndStart "
                               "- invalid parameter\n");
    }
    else
    {
        status = ixNpeDlNpeInitAndStartInternal (imageLibrary, imageId);
    } /* end of if-else(imageLibrary) */

    return status;
}

/*
 * Function definition: ixNpeDlNpeInitAndStart
 */
PUBLIC IX_STATUS
ixNpeDlNpeInitAndStart (UINT32 imageId)
{
    return ixNpeDlNpeInitAndStartInternal (NULL, imageId);
}

/*
 * Function definition: ixNpeDlLoadedImageFunctionalityGet
 */
PUBLIC IX_STATUS
ixNpeDlLoadedImageFunctionalityGet (IxNpeDlNpeId npeId,
                                    UINT8 *functionalityId)
{
    /* Check input parameters */
    if ((npeId >= IX_NPEDL_NPEID_MAX) || (npeId < 0))
    {
        IX_NPEDL_ERROR_REPORT ("ixNpeDlLoadedImageFunctionalityGet "
                               "- invalid parameter\n");
        return IX_NPEDL_PARAM_ERR;
    }
    if (functionalityId == NULL)
    {
        IX_NPEDL_ERROR_REPORT ("ixNpeDlLoadedImageFunctionalityGet "
                               "- invalid parameter\n");
        return IX_NPEDL_PARAM_ERR;
    }

    if (ixNpeDlNpeState[npeId].validImage)
    {
        *functionalityId = ixNpeDlNpeState[npeId].imageId.functionalityId;
        return IX_SUCCESS;
    }
    else
    {
        return IX_FAIL;
    }
}