IxNpeDl.c 30 KB

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