IxNpeDl.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  1. /**
  2. * @file IxNpeDl.c
  3. *
  4. * @author Intel Corporation
  5. * @date 08 January 2002
  6. *
  7. * @brief This file contains the implementation of the public API for the
  8. * IXP425 NPE Downloader component
  9. *
  10. *
  11. * @par
  12. * IXP400 SW Release version 2.0
  13. *
  14. * -- Copyright Notice --
  15. *
  16. * @par
  17. * Copyright 2001-2005, Intel Corporation.
  18. * All rights reserved.
  19. *
  20. * @par
  21. * Redistribution and use in source and binary forms, with or without
  22. * modification, are permitted provided that the following conditions
  23. * are met:
  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.
  32. *
  33. * @par
  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
  44. * SUCH DAMAGE.
  45. *
  46. * @par
  47. * -- End of Copyright Notice --
  48. */
  49. /*
  50. * Put the system defined include files required
  51. */
  52. /*
  53. * Put the user defined include files required
  54. */
  55. #include "IxNpeDl.h"
  56. #include "IxNpeDlImageMgr_p.h"
  57. #include "IxNpeDlNpeMgr_p.h"
  58. #include "IxNpeDlMacros_p.h"
  59. #include "IxFeatureCtrl.h"
  60. #include "IxOsal.h"
  61. /*
  62. * #defines used in this file
  63. */
  64. #define IMAGEID_MAJOR_NUMBER_DEFAULT 0
  65. #define IMAGEID_MINOR_NUMBER_DEFAULT 0
  66. /*
  67. * Typedefs whose scope is limited to this file.
  68. */
  69. typedef struct
  70. {
  71. BOOL validImage;
  72. IxNpeDlImageId imageId;
  73. } IxNpeDlNpeState;
  74. /* module statistics counters */
  75. typedef struct
  76. {
  77. UINT32 attemptedDownloads;
  78. UINT32 successfulDownloads;
  79. UINT32 criticalFailDownloads;
  80. } IxNpeDlStats;
  81. /*
  82. * Variable declarations global to this file only. Externs are followed
  83. * by static variables.
  84. */
  85. static IxNpeDlNpeState ixNpeDlNpeState[IX_NPEDL_NPEID_MAX] =
  86. {
  87. {false, {IX_NPEDL_NPEID_MAX, 0, 0, 0}},
  88. {false, {IX_NPEDL_NPEID_MAX, 0, 0, 0}},
  89. {false, {IX_NPEDL_NPEID_MAX, 0, 0, 0}}
  90. };
  91. static IxNpeDlStats ixNpeDlStats;
  92. /*
  93. * Software guard to prevent NPE from being started multiple times.
  94. */
  95. static BOOL ixNpeDlNpeStarted[IX_NPEDL_NPEID_MAX] ={false, false, false} ;
  96. /*
  97. * static function prototypes.
  98. */
  99. PRIVATE IX_STATUS
  100. ixNpeDlNpeInitAndStartInternal (UINT32 *imageLibrary, UINT32 imageId);
  101. /*
  102. * Function definition: ixNpeDlImageDownload
  103. */
  104. PUBLIC IX_STATUS
  105. ixNpeDlImageDownload (IxNpeDlImageId *imageIdPtr,
  106. BOOL verify)
  107. {
  108. UINT32 imageSize;
  109. UINT32 *imageCodePtr = NULL;
  110. IX_STATUS status;
  111. IxNpeDlNpeId npeId = imageIdPtr->npeId;
  112. IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
  113. "Entering ixNpeDlImageDownload\n");
  114. ixNpeDlStats.attemptedDownloads++;
  115. /* Check input parameters */
  116. if ((npeId >= IX_NPEDL_NPEID_MAX) || (npeId < 0))
  117. {
  118. status = IX_NPEDL_PARAM_ERR;
  119. IX_NPEDL_ERROR_REPORT ("ixNpeDlImageDownload - invalid parameter\n");
  120. }
  121. else
  122. {
  123. /* Ensure initialisation has been completed */
  124. ixNpeDlNpeMgrInit();
  125. /* If not IXP42X A0 stepping, proceed to check for existence of npe's */
  126. if ((IX_FEATURE_CTRL_SILICON_TYPE_A0 !=
  127. (ixFeatureCtrlProductIdRead() & IX_FEATURE_CTRL_SILICON_STEPPING_MASK))
  128. || (IX_FEATURE_CTRL_DEVICE_TYPE_IXP42X != ixFeatureCtrlDeviceRead ()))
  129. {
  130. if (npeId == IX_NPEDL_NPEID_NPEA)
  131. {
  132. if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEA) ==
  133. IX_FEATURE_CTRL_COMPONENT_DISABLED)
  134. {
  135. IX_NPEDL_WARNING_REPORT("Warning: the NPE A component you specified does"
  136. " not exist\n");
  137. return IX_SUCCESS;
  138. }
  139. } /* end of if(npeId) */
  140. else if (npeId == IX_NPEDL_NPEID_NPEB)
  141. {
  142. if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEB)==
  143. IX_FEATURE_CTRL_COMPONENT_DISABLED)
  144. {
  145. IX_NPEDL_WARNING_REPORT("Warning: the NPE B component you specified"
  146. " does not exist\n");
  147. return IX_SUCCESS;
  148. }
  149. } /* end of elseif(npeId) */
  150. else if (npeId == IX_NPEDL_NPEID_NPEC)
  151. {
  152. if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEC)==
  153. IX_FEATURE_CTRL_COMPONENT_DISABLED)
  154. {
  155. IX_NPEDL_WARNING_REPORT("Warning: the NPE C component you specified"
  156. " does not exist\n");
  157. return IX_SUCCESS;
  158. }
  159. } /* end of elseif(npeId) */
  160. } /* end of if(IX_FEATURE_CTRL_SILICON_TYPE_B0) */ /*End of Silicon Type Check*/
  161. /* stop and reset the NPE */
  162. if (IX_SUCCESS != ixNpeDlNpeStopAndReset (npeId))
  163. {
  164. IX_NPEDL_ERROR_REPORT ("Failed to stop and reset NPE\n");
  165. return IX_FAIL;
  166. }
  167. /* Locate image */
  168. status = ixNpeDlImageMgrImageLocate (imageIdPtr, &imageCodePtr,
  169. &imageSize);
  170. if (IX_SUCCESS == status)
  171. {
  172. /*
  173. * If download was successful, store image Id in list of
  174. * currently loaded images. If a critical error occured
  175. * during download, record that the NPE has an invalid image
  176. */
  177. status = ixNpeDlNpeMgrImageLoad (npeId, imageCodePtr,
  178. verify);
  179. if (IX_SUCCESS == status)
  180. {
  181. ixNpeDlNpeState[npeId].imageId = *imageIdPtr;
  182. ixNpeDlNpeState[npeId].validImage = true;
  183. ixNpeDlStats.successfulDownloads++;
  184. status = ixNpeDlNpeExecutionStart (npeId);
  185. }
  186. else if ((status == IX_NPEDL_CRITICAL_NPE_ERR) ||
  187. (status == IX_NPEDL_CRITICAL_MICROCODE_ERR))
  188. {
  189. ixNpeDlNpeState[npeId].imageId = *imageIdPtr;
  190. ixNpeDlNpeState[npeId].validImage = false;
  191. ixNpeDlStats.criticalFailDownloads++;
  192. }
  193. } /* end of if(IX_SUCCESS) */ /* condition: image located successfully in microcode image */
  194. } /* end of if-else(npeId) */ /* condition: parameter checks ok */
  195. IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
  196. "Exiting ixNpeDlImageDownload : status = %d\n", status);
  197. return status;
  198. }
  199. /*
  200. * Function definition: ixNpeDlAvailableImagesCountGet
  201. */
  202. PUBLIC IX_STATUS
  203. ixNpeDlAvailableImagesCountGet (UINT32 *numImagesPtr)
  204. {
  205. IX_STATUS status;
  206. IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
  207. "Entering ixNpeDlAvailableImagesCountGet\n");
  208. /* Check input parameters */
  209. if (numImagesPtr == NULL)
  210. {
  211. status = IX_NPEDL_PARAM_ERR;
  212. IX_NPEDL_ERROR_REPORT ("ixNpeDlAvailableImagesCountGet - "
  213. "invalid parameter\n");
  214. }
  215. else
  216. {
  217. /*
  218. * Use ImageMgr module to get no. of images listed in Image Library Header.
  219. * If NULL is passed as imageListPtr parameter to following function,
  220. * it will only fill number of images into numImagesPtr
  221. */
  222. status = ixNpeDlImageMgrImageListExtract (NULL, numImagesPtr);
  223. } /* end of if-else(numImagesPtr) */
  224. IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
  225. "Exiting ixNpeDlAvailableImagesCountGet : "
  226. "status = %d\n", status);
  227. return status;
  228. }
  229. /*
  230. * Function definition: ixNpeDlAvailableImagesListGet
  231. */
  232. PUBLIC IX_STATUS
  233. ixNpeDlAvailableImagesListGet (IxNpeDlImageId *imageIdListPtr,
  234. UINT32 *listSizePtr)
  235. {
  236. IX_STATUS status;
  237. IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
  238. "Entering ixNpeDlAvailableImagesListGet\n");
  239. /* Check input parameters */
  240. if ((imageIdListPtr == NULL) || (listSizePtr == NULL))
  241. {
  242. status = IX_NPEDL_PARAM_ERR;
  243. IX_NPEDL_ERROR_REPORT ("ixNpeDlAvailableImagesListGet - "
  244. "invalid parameter\n");
  245. }
  246. else
  247. {
  248. /* Call ImageMgr to get list of images listed in Image Library Header */
  249. status = ixNpeDlImageMgrImageListExtract (imageIdListPtr,
  250. listSizePtr);
  251. } /* end of if-else(imageIdListPtr) */
  252. IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
  253. "Exiting ixNpeDlAvailableImagesListGet : status = %d\n",
  254. status);
  255. return status;
  256. }
  257. /*
  258. * Function definition: ixNpeDlLoadedImageGet
  259. */
  260. PUBLIC IX_STATUS
  261. ixNpeDlLoadedImageGet (IxNpeDlNpeId npeId,
  262. IxNpeDlImageId *imageIdPtr)
  263. {
  264. IX_STATUS status = IX_SUCCESS;
  265. IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
  266. "Entering ixNpeDlLoadedImageGet\n");
  267. /* Check input parameters */
  268. if ((npeId >= IX_NPEDL_NPEID_MAX) || (npeId < 0) || (imageIdPtr == NULL))
  269. {
  270. status = IX_NPEDL_PARAM_ERR;
  271. IX_NPEDL_ERROR_REPORT ("ixNpeDlLoadedImageGet - invalid parameter\n");
  272. }
  273. else
  274. {
  275. /* If not IXP42X A0 stepping, proceed to check for existence of npe's */
  276. if ((IX_FEATURE_CTRL_SILICON_TYPE_A0 !=
  277. (ixFeatureCtrlProductIdRead() & IX_FEATURE_CTRL_SILICON_STEPPING_MASK))
  278. || (IX_FEATURE_CTRL_DEVICE_TYPE_IXP42X != ixFeatureCtrlDeviceRead ()))
  279. {
  280. if (npeId == IX_NPEDL_NPEID_NPEA &&
  281. (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEA) ==
  282. IX_FEATURE_CTRL_COMPONENT_DISABLED))
  283. {
  284. IX_NPEDL_WARNING_REPORT("Warning: the NPE A component you specified does"
  285. " not exist\n");
  286. return IX_SUCCESS;
  287. } /* end of if(npeId) */
  288. if (npeId == IX_NPEDL_NPEID_NPEB &&
  289. (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEB) ==
  290. IX_FEATURE_CTRL_COMPONENT_DISABLED))
  291. {
  292. IX_NPEDL_WARNING_REPORT("Warning: the NPE B component you specified does"
  293. " not exist\n");
  294. return IX_SUCCESS;
  295. } /* end of if(npeId) */
  296. if (npeId == IX_NPEDL_NPEID_NPEC &&
  297. (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEC) ==
  298. IX_FEATURE_CTRL_COMPONENT_DISABLED))
  299. {
  300. IX_NPEDL_WARNING_REPORT("Warning: the NPE C component you specified does"
  301. " not exist\n");
  302. return IX_SUCCESS;
  303. } /* end of if(npeId) */
  304. } /* end of if not IXP42x-A0 silicon */
  305. if (ixNpeDlNpeState[npeId].validImage)
  306. {
  307. /* use npeId to get imageId from list of currently loaded
  308. images */
  309. *imageIdPtr = ixNpeDlNpeState[npeId].imageId;
  310. }
  311. else
  312. {
  313. status = IX_FAIL;
  314. } /* end of if-else(ixNpeDlNpeState) */
  315. } /* end of if-else(npeId) */
  316. IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
  317. "Exiting ixNpeDlLoadedImageGet : status = %d\n",
  318. status);
  319. return status;
  320. }
  321. /*
  322. * Function definition: ixNpeDlLatestImageGet
  323. */
  324. PUBLIC IX_STATUS
  325. ixNpeDlLatestImageGet (
  326. IxNpeDlNpeId npeId,
  327. IxNpeDlFunctionalityId functionalityId,
  328. IxNpeDlImageId *imageIdPtr)
  329. {
  330. IX_STATUS status;
  331. IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
  332. "Entering ixNpeDlLatestImageGet\n");
  333. /* Check input parameters */
  334. if ((npeId >= IX_NPEDL_NPEID_MAX) ||
  335. (npeId < 0) ||
  336. (imageIdPtr == NULL))
  337. {
  338. status = IX_NPEDL_PARAM_ERR;
  339. IX_NPEDL_ERROR_REPORT ("ixNpeDlLatestImageGet - "
  340. "invalid parameter\n");
  341. } /* end of if(npeId) */
  342. else
  343. {
  344. /* If not IXP42X A0 stepping, proceed to check for existence of npe's */
  345. if ((IX_FEATURE_CTRL_SILICON_TYPE_A0 !=
  346. (ixFeatureCtrlProductIdRead() & IX_FEATURE_CTRL_SILICON_STEPPING_MASK))
  347. || (IX_FEATURE_CTRL_DEVICE_TYPE_IXP42X != ixFeatureCtrlDeviceRead ()))
  348. {
  349. if (npeId == IX_NPEDL_NPEID_NPEA &&
  350. (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEA) ==
  351. IX_FEATURE_CTRL_COMPONENT_DISABLED))
  352. {
  353. IX_NPEDL_WARNING_REPORT("Warning: the NPE A component you specified does"
  354. " not exist\n");
  355. return IX_SUCCESS;
  356. } /* end of if(npeId) */
  357. if (npeId == IX_NPEDL_NPEID_NPEB &&
  358. (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEB) ==
  359. IX_FEATURE_CTRL_COMPONENT_DISABLED))
  360. {
  361. IX_NPEDL_WARNING_REPORT("Warning: the NPE B component you specified does"
  362. " not exist\n");
  363. return IX_SUCCESS;
  364. } /* end of if(npeId) */
  365. if (npeId == IX_NPEDL_NPEID_NPEC &&
  366. (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEC) ==
  367. IX_FEATURE_CTRL_COMPONENT_DISABLED))
  368. {
  369. IX_NPEDL_WARNING_REPORT("Warning: the NPE C component you specified does"
  370. " not exist\n");
  371. return IX_SUCCESS;
  372. } /* end of if(npeId) */
  373. } /* end of if not IXP42x-A0 silicon */
  374. imageIdPtr->npeId = npeId;
  375. imageIdPtr->functionalityId = functionalityId;
  376. imageIdPtr->major = IMAGEID_MAJOR_NUMBER_DEFAULT;
  377. imageIdPtr->minor = IMAGEID_MINOR_NUMBER_DEFAULT;
  378. /* Call ImageMgr to get list of images listed in Image Library Header */
  379. status = ixNpeDlImageMgrLatestImageExtract(imageIdPtr);
  380. } /* end of if-else(npeId) */
  381. IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
  382. "Exiting ixNpeDlLatestImageGet : status = %d\n",
  383. status);
  384. return status;
  385. }
  386. /*
  387. * Function definition: ixNpeDlNpeStopAndReset
  388. */
  389. PUBLIC IX_STATUS
  390. ixNpeDlNpeStopAndReset (IxNpeDlNpeId npeId)
  391. {
  392. IX_STATUS status = IX_SUCCESS;
  393. IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
  394. "Entering ixNpeDlNpeStopAndReset\n");
  395. /* Ensure initialisation has been completed */
  396. ixNpeDlNpeMgrInit();
  397. /* If not IXP42X A0 stepping, proceed to check for existence of npe's */
  398. if ((IX_FEATURE_CTRL_SILICON_TYPE_A0 !=
  399. (ixFeatureCtrlProductIdRead() & IX_FEATURE_CTRL_SILICON_STEPPING_MASK))
  400. || (IX_FEATURE_CTRL_DEVICE_TYPE_IXP42X != ixFeatureCtrlDeviceRead ()))
  401. {
  402. /*
  403. * Check whether NPE is present
  404. */
  405. if (IX_NPEDL_NPEID_NPEA == npeId)
  406. {
  407. /* Check whether NPE A is present */
  408. if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEA)==
  409. IX_FEATURE_CTRL_COMPONENT_DISABLED)
  410. {
  411. /* NPE A does not present */
  412. IX_NPEDL_WARNING_REPORT ("ixNpeDlNpeStopAndReset - Warning:NPEA does not present.\n");
  413. return IX_SUCCESS;
  414. }
  415. } /* end of if(IX_NPEDL_NPEID_NPEA) */
  416. else if (IX_NPEDL_NPEID_NPEB == npeId)
  417. {
  418. /* Check whether NPE B is present */
  419. if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEB)==
  420. IX_FEATURE_CTRL_COMPONENT_DISABLED)
  421. {
  422. /* NPE B does not present */
  423. IX_NPEDL_WARNING_REPORT ("ixNpeDlNpeStopAndReset - Warning:NPEB does not present.\n");
  424. return IX_SUCCESS;
  425. }
  426. } /* end of elseif(IX_NPEDL_NPEID_NPEB) */
  427. else if (IX_NPEDL_NPEID_NPEC == npeId)
  428. {
  429. /* Check whether NPE C is present */
  430. if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEC)==
  431. IX_FEATURE_CTRL_COMPONENT_DISABLED)
  432. {
  433. /* NPE C does not present */
  434. IX_NPEDL_WARNING_REPORT ("ixNpeDlNpeStopAndReset - Warning:NPEC does not present.\n");
  435. return IX_SUCCESS;
  436. }
  437. } /* end of elseif(IX_NPEDL_NPEID_NPEC) */
  438. else
  439. {
  440. /* Invalid NPE ID */
  441. IX_NPEDL_ERROR_REPORT ("ixNpeDlNpeStopAndReset - invalid Npe ID\n");
  442. status = IX_NPEDL_PARAM_ERR;
  443. } /* end of if-else(IX_NPEDL_NPEID_NPEC) */
  444. } /* end of if not IXP42x-A0 Silicon */
  445. if (status == IX_SUCCESS)
  446. {
  447. /* call NpeMgr function to stop the NPE */
  448. status = ixNpeDlNpeMgrNpeStop (npeId);
  449. if (status == IX_SUCCESS)
  450. {
  451. /* call NpeMgr function to reset the NPE */
  452. status = ixNpeDlNpeMgrNpeReset (npeId);
  453. }
  454. } /* end of if(status) */
  455. IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
  456. "Exiting ixNpeDlNpeStopAndReset : status = %d\n", status);
  457. if (IX_SUCCESS == status)
  458. {
  459. /* Indicate NPE has been stopped */
  460. ixNpeDlNpeStarted[npeId] = false ;
  461. }
  462. return status;
  463. }
  464. /*
  465. * Function definition: ixNpeDlNpeExecutionStart
  466. */
  467. PUBLIC IX_STATUS
  468. ixNpeDlNpeExecutionStart (IxNpeDlNpeId npeId)
  469. {
  470. IX_STATUS status = IX_SUCCESS;
  471. IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
  472. "Entering ixNpeDlNpeExecutionStart\n");
  473. /* If not IXP42X A0 stepping, proceed to check for existence of npe's */
  474. if ((IX_FEATURE_CTRL_SILICON_TYPE_A0 !=
  475. (ixFeatureCtrlProductIdRead() & IX_FEATURE_CTRL_SILICON_STEPPING_MASK))
  476. || (IX_FEATURE_CTRL_DEVICE_TYPE_IXP42X != ixFeatureCtrlDeviceRead ()))
  477. {
  478. /*
  479. * Check whether NPE is present
  480. */
  481. if (IX_NPEDL_NPEID_NPEA == npeId)
  482. {
  483. /* Check whether NPE A is present */
  484. if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEA)==
  485. IX_FEATURE_CTRL_COMPONENT_DISABLED)
  486. {
  487. /* NPE A does not present */
  488. IX_NPEDL_WARNING_REPORT ("ixNpeDlNpeExecutionStart - Warning:NPEA does not present.\n");
  489. return IX_SUCCESS;
  490. }
  491. } /* end of if(IX_NPEDL_NPEID_NPEA) */
  492. else if (IX_NPEDL_NPEID_NPEB == npeId)
  493. {
  494. /* Check whether NPE B is present */
  495. if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEB)==
  496. IX_FEATURE_CTRL_COMPONENT_DISABLED)
  497. {
  498. /* NPE B does not present */
  499. IX_NPEDL_WARNING_REPORT ("ixNpeDlNpeExecutionStart - Warning:NPEB does not present.\n");
  500. return IX_SUCCESS;
  501. }
  502. } /* end of elseif(IX_NPEDL_NPEID_NPEB) */
  503. else if (IX_NPEDL_NPEID_NPEC == npeId)
  504. {
  505. /* Check whether NPE C is present */
  506. if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEC)==
  507. IX_FEATURE_CTRL_COMPONENT_DISABLED)
  508. {
  509. /* NPE C does not present */
  510. IX_NPEDL_WARNING_REPORT ("ixNpeDlNpeExecutionStart - Warning:NPEC does not present.\n");
  511. return IX_SUCCESS;
  512. }
  513. } /* end of elseif(IX_NPEDL_NPEID_NPEC) */
  514. else
  515. {
  516. /* Invalid NPE ID */
  517. IX_NPEDL_ERROR_REPORT ("ixNpeDlNpeExecutionStart - invalid Npe ID\n");
  518. return IX_NPEDL_PARAM_ERR;
  519. } /* end of if-else(IX_NPEDL_NPEID_NPEC) */
  520. } /* end of if not IXP42x-A0 Silicon */
  521. if (true == ixNpeDlNpeStarted[npeId])
  522. {
  523. /* NPE has been started. */
  524. return IX_SUCCESS ;
  525. }
  526. /* Ensure initialisation has been completed */
  527. ixNpeDlNpeMgrInit();
  528. /* call NpeMgr function to start the NPE */
  529. status = ixNpeDlNpeMgrNpeStart (npeId);
  530. if (IX_SUCCESS == status)
  531. {
  532. /* Indicate NPE has started */
  533. ixNpeDlNpeStarted[npeId] = true ;
  534. }
  535. IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
  536. "Exiting ixNpeDlNpeExecutionStart : status = %d\n",
  537. status);
  538. return status;
  539. }
  540. /*
  541. * Function definition: ixNpeDlNpeExecutionStop
  542. */
  543. PUBLIC IX_STATUS
  544. ixNpeDlNpeExecutionStop (IxNpeDlNpeId npeId)
  545. {
  546. IX_STATUS status = IX_SUCCESS;
  547. IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
  548. "Entering ixNpeDlNpeExecutionStop\n");
  549. /* Ensure initialisation has been completed */
  550. ixNpeDlNpeMgrInit();
  551. /* If not IXP42X A0 stepping, proceed to check for existence of npe's */
  552. if ((IX_FEATURE_CTRL_SILICON_TYPE_A0 !=
  553. (ixFeatureCtrlProductIdRead() & IX_FEATURE_CTRL_SILICON_STEPPING_MASK))
  554. || (IX_FEATURE_CTRL_DEVICE_TYPE_IXP42X != ixFeatureCtrlDeviceRead ()))
  555. {
  556. /*
  557. * Check whether NPE is present
  558. */
  559. if (IX_NPEDL_NPEID_NPEA == npeId)
  560. {
  561. /* Check whether NPE A is present */
  562. if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEA)==
  563. IX_FEATURE_CTRL_COMPONENT_DISABLED)
  564. {
  565. /* NPE A does not present */
  566. IX_NPEDL_WARNING_REPORT ("ixNpeDlNpeExecutionStop - Warning:NPEA does not present.\n");
  567. return IX_SUCCESS;
  568. }
  569. } /* end of if(IX_NPEDL_NPEID_NPEA) */
  570. else if (IX_NPEDL_NPEID_NPEB == npeId)
  571. {
  572. /* Check whether NPE B is present */
  573. if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEB)==
  574. IX_FEATURE_CTRL_COMPONENT_DISABLED)
  575. {
  576. /* NPE B does not present */
  577. IX_NPEDL_WARNING_REPORT ("ixNpeDlNpeExecutionStop - Warning:NPEB does not present.\n");
  578. return IX_SUCCESS;
  579. }
  580. } /* end of elseif(IX_NPEDL_NPEID_NPEB) */
  581. else if (IX_NPEDL_NPEID_NPEC == npeId)
  582. {
  583. /* Check whether NPE C is present */
  584. if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEC)==
  585. IX_FEATURE_CTRL_COMPONENT_DISABLED)
  586. {
  587. /* NPE C does not present */
  588. IX_NPEDL_WARNING_REPORT ("ixNpeDlNpeExecutionStop - Warning:NPEC does not present.\n");
  589. return IX_SUCCESS;
  590. }
  591. } /* end of elseif(IX_NPEDL_NPEID_NPEC) */
  592. else
  593. {
  594. /* Invalid NPE ID */
  595. IX_NPEDL_ERROR_REPORT ("ixNpeDlNpeExecutionStop - invalid Npe ID\n");
  596. status = IX_NPEDL_PARAM_ERR;
  597. } /* end of if-else(IX_NPEDL_NPEID_NPEC) */
  598. } /* end of if not IXP42X-AO Silicon */
  599. if (status == IX_SUCCESS)
  600. {
  601. /* call NpeMgr function to stop the NPE */
  602. status = ixNpeDlNpeMgrNpeStop (npeId);
  603. }
  604. IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
  605. "Exiting ixNpeDlNpeExecutionStop : status = %d\n",
  606. status);
  607. if (IX_SUCCESS == status)
  608. {
  609. /* Indicate NPE has been stopped */
  610. ixNpeDlNpeStarted[npeId] = false ;
  611. }
  612. return status;
  613. }
  614. /*
  615. * Function definition: ixNpeDlUnload
  616. */
  617. PUBLIC IX_STATUS
  618. ixNpeDlUnload (void)
  619. {
  620. IX_STATUS status;
  621. IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
  622. "Entering ixNpeDlUnload\n");
  623. status = ixNpeDlNpeMgrUninit();
  624. IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
  625. "Exiting ixNpeDlUnload : status = %d\n",
  626. status);
  627. return status;
  628. }
  629. /*
  630. * Function definition: ixNpeDlStatsShow
  631. */
  632. PUBLIC void
  633. ixNpeDlStatsShow (void)
  634. {
  635. ixOsalLog (IX_OSAL_LOG_LVL_USER,
  636. IX_OSAL_LOG_DEV_STDOUT,
  637. "\nixNpeDlStatsShow:\n"
  638. "\tDownloads Attempted by user: %u\n"
  639. "\tSuccessful Downloads: %u\n"
  640. "\tFailed Downloads (due to Critical Error): %u\n\n",
  641. ixNpeDlStats.attemptedDownloads,
  642. ixNpeDlStats.successfulDownloads,
  643. ixNpeDlStats.criticalFailDownloads,
  644. 0,0,0);
  645. ixNpeDlImageMgrStatsShow ();
  646. ixNpeDlNpeMgrStatsShow ();
  647. }
  648. /*
  649. * Function definition: ixNpeDlStatsReset
  650. */
  651. PUBLIC void
  652. ixNpeDlStatsReset (void)
  653. {
  654. ixNpeDlStats.attemptedDownloads = 0;
  655. ixNpeDlStats.successfulDownloads = 0;
  656. ixNpeDlStats.criticalFailDownloads = 0;
  657. ixNpeDlImageMgrStatsReset ();
  658. ixNpeDlNpeMgrStatsReset ();
  659. }
  660. /*
  661. * Function definition: ixNpeDlNpeInitAndStartInternal
  662. */
  663. PRIVATE IX_STATUS
  664. ixNpeDlNpeInitAndStartInternal (UINT32 *imageLibrary,
  665. UINT32 imageId)
  666. {
  667. UINT32 imageSize;
  668. UINT32 *imageCodePtr = NULL;
  669. IX_STATUS status;
  670. IxNpeDlNpeId npeId = IX_NPEDL_NPEID_FROM_IMAGEID_GET(imageId);
  671. IxFeatureCtrlDeviceId deviceId = IX_NPEDL_DEVICEID_FROM_IMAGEID_GET(imageId);
  672. IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
  673. "Entering ixNpeDlNpeInitAndStartInternal\n");
  674. ixNpeDlStats.attemptedDownloads++;
  675. /* Check input parameter device correctness */
  676. if ((deviceId >= IX_FEATURE_CTRL_DEVICE_TYPE_MAX) ||
  677. (deviceId < IX_FEATURE_CTRL_DEVICE_TYPE_IXP42X))
  678. {
  679. status = IX_NPEDL_PARAM_ERR;
  680. IX_NPEDL_ERROR_REPORT ("ixNpeDlNpeInitAndStartInternal - "
  681. "invalid parameter\n");
  682. } /* End valid device id checking */
  683. /* Check input parameters */
  684. else if ((npeId >= IX_NPEDL_NPEID_MAX) || (npeId < 0))
  685. {
  686. status = IX_NPEDL_PARAM_ERR;
  687. IX_NPEDL_ERROR_REPORT ("ixNpeDlNpeInitAndStartInternal - "
  688. "invalid parameter\n");
  689. }
  690. else
  691. {
  692. /* Ensure initialisation has been completed */
  693. ixNpeDlNpeMgrInit();
  694. /* Checking if image being loaded is meant for device that is running.
  695. * Image is forward compatible. i.e Image built for IXP42X should run
  696. * on IXP46X but not vice versa.*/
  697. if (deviceId > (ixFeatureCtrlDeviceRead() & IX_FEATURE_CTRL_DEVICE_TYPE_MASK))
  698. {
  699. IX_NPEDL_ERROR_REPORT ("ixNpeDlNpeInitAndStartInternal - "
  700. "Device type mismatch. NPE Image not "
  701. "meant for device in use \n");
  702. return IX_NPEDL_DEVICE_ERR;
  703. }/* if statement - matching image device and current device */
  704. /* If not IXP42X A0 stepping, proceed to check for existence of npe's */
  705. if ((IX_FEATURE_CTRL_SILICON_TYPE_A0 !=
  706. (ixFeatureCtrlProductIdRead() & IX_FEATURE_CTRL_SILICON_STEPPING_MASK))
  707. || (IX_FEATURE_CTRL_DEVICE_TYPE_IXP42X != ixFeatureCtrlDeviceRead ()))
  708. {
  709. if (npeId == IX_NPEDL_NPEID_NPEA)
  710. {
  711. if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEA) ==
  712. IX_FEATURE_CTRL_COMPONENT_DISABLED)
  713. {
  714. IX_NPEDL_WARNING_REPORT("Warning: the NPE A component you specified does"
  715. " not exist\n");
  716. return IX_SUCCESS;
  717. }
  718. } /* end of if(npeId) */
  719. else if (npeId == IX_NPEDL_NPEID_NPEB)
  720. {
  721. if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEB)==
  722. IX_FEATURE_CTRL_COMPONENT_DISABLED)
  723. {
  724. IX_NPEDL_WARNING_REPORT("Warning: the NPE B component you specified"
  725. " does not exist\n");
  726. return IX_SUCCESS;
  727. }
  728. } /* end of elseif(npeId) */
  729. else if (npeId == IX_NPEDL_NPEID_NPEC)
  730. {
  731. if (ixFeatureCtrlComponentCheck(IX_FEATURECTRL_NPEC)==
  732. IX_FEATURE_CTRL_COMPONENT_DISABLED)
  733. {
  734. IX_NPEDL_WARNING_REPORT("Warning: the NPE C component you specified"
  735. " does not exist\n");
  736. return IX_SUCCESS;
  737. }
  738. } /* end of elseif(npeId) */
  739. } /* end of if not IXP42X-A0 Silicon */
  740. /* stop and reset the NPE */
  741. status = ixNpeDlNpeStopAndReset (npeId);
  742. if (IX_SUCCESS != status)
  743. {
  744. IX_NPEDL_ERROR_REPORT ("Failed to stop and reset NPE\n");
  745. return status;
  746. }
  747. /* Locate image */
  748. status = ixNpeDlImageMgrImageFind (imageLibrary, imageId,
  749. &imageCodePtr, &imageSize);
  750. if (IX_SUCCESS == status)
  751. {
  752. /*
  753. * If download was successful, store image Id in list of
  754. * currently loaded images. If a critical error occured
  755. * during download, record that the NPE has an invalid image
  756. */
  757. status = ixNpeDlNpeMgrImageLoad (npeId, imageCodePtr, true);
  758. if (IX_SUCCESS == status)
  759. {
  760. ixNpeDlNpeState[npeId].validImage = true;
  761. ixNpeDlStats.successfulDownloads++;
  762. status = ixNpeDlNpeExecutionStart (npeId);
  763. }
  764. else if ((status == IX_NPEDL_CRITICAL_NPE_ERR) ||
  765. (status == IX_NPEDL_CRITICAL_MICROCODE_ERR))
  766. {
  767. ixNpeDlNpeState[npeId].validImage = false;
  768. ixNpeDlStats.criticalFailDownloads++;
  769. }
  770. /* NOTE - The following section of code is here to support
  771. * a deprecated function ixNpeDlLoadedImageGet(). When that
  772. * function is removed from the API, this code should be revised.
  773. */
  774. ixNpeDlNpeState[npeId].imageId.npeId = npeId;
  775. ixNpeDlNpeState[npeId].imageId.functionalityId =
  776. IX_NPEDL_FUNCTIONID_FROM_IMAGEID_GET(imageId);
  777. ixNpeDlNpeState[npeId].imageId.major =
  778. IX_NPEDL_MAJOR_FROM_IMAGEID_GET(imageId);
  779. ixNpeDlNpeState[npeId].imageId.minor =
  780. IX_NPEDL_MINOR_FROM_IMAGEID_GET(imageId);
  781. } /* end of if(IX_SUCCESS) */ /* condition: image located successfully in microcode image */
  782. } /* end of if-else(npeId-deviceId) */ /* condition: parameter checks ok */
  783. IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
  784. "Exiting ixNpeDlNpeInitAndStartInternal : "
  785. "status = %d\n", status);
  786. return status;
  787. }
  788. /*
  789. * Function definition: ixNpeDlCustomImageNpeInitAndStart
  790. */
  791. PUBLIC IX_STATUS
  792. ixNpeDlCustomImageNpeInitAndStart (UINT32 *imageLibrary,
  793. UINT32 imageId)
  794. {
  795. IX_STATUS status;
  796. if (imageLibrary == NULL)
  797. {
  798. status = IX_NPEDL_PARAM_ERR;
  799. IX_NPEDL_ERROR_REPORT ("ixNpeDlCustomImageNpeInitAndStart "
  800. "- invalid parameter\n");
  801. }
  802. else
  803. {
  804. status = ixNpeDlNpeInitAndStartInternal (imageLibrary, imageId);
  805. } /* end of if-else(imageLibrary) */
  806. return status;
  807. }
  808. /*
  809. * Function definition: ixNpeDlNpeInitAndStart
  810. */
  811. PUBLIC IX_STATUS
  812. ixNpeDlNpeInitAndStart (UINT32 imageId)
  813. {
  814. return ixNpeDlNpeInitAndStartInternal (NULL, imageId);
  815. }
  816. /*
  817. * Function definition: ixNpeDlLoadedImageFunctionalityGet
  818. */
  819. PUBLIC IX_STATUS
  820. ixNpeDlLoadedImageFunctionalityGet (IxNpeDlNpeId npeId,
  821. UINT8 *functionalityId)
  822. {
  823. /* Check input parameters */
  824. if ((npeId >= IX_NPEDL_NPEID_MAX) || (npeId < 0))
  825. {
  826. IX_NPEDL_ERROR_REPORT ("ixNpeDlLoadedImageFunctionalityGet "
  827. "- invalid parameter\n");
  828. return IX_NPEDL_PARAM_ERR;
  829. }
  830. if (functionalityId == NULL)
  831. {
  832. IX_NPEDL_ERROR_REPORT ("ixNpeDlLoadedImageFunctionalityGet "
  833. "- invalid parameter\n");
  834. return IX_NPEDL_PARAM_ERR;
  835. }
  836. if (ixNpeDlNpeState[npeId].validImage)
  837. {
  838. *functionalityId = ixNpeDlNpeState[npeId].imageId.functionalityId;
  839. return IX_SUCCESS;
  840. }
  841. else
  842. {
  843. return IX_FAIL;
  844. }
  845. }