ipmi_ekanalyzer.c 136 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195
  1. /*
  2. * Copyright (c) 2007 Kontron Canada, Inc. All Rights Reserved.
  3. *
  4. * Base on code from
  5. * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * Redistribution of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * Redistribution in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. *
  18. * Neither the name of Sun Microsystems, Inc. or the names of
  19. * contributors may be used to endorse or promote products derived
  20. * from this software without specific prior written permission.
  21. *
  22. * This software is provided "AS IS," without a warranty of any kind.
  23. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
  24. * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
  25. * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
  26. * SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE
  27. * FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  28. * OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
  29. * SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
  30. * OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
  31. * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
  32. * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
  33. * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  34. */
  35. #include <ipmitool/ipmi_ekanalyzer.h>
  36. #include <ipmitool/log.h>
  37. #include <ipmitool/helper.h>
  38. #include <ipmitool/ipmi_strings.h>
  39. #include <stdlib.h>
  40. #include <string.h>
  41. #include <time.h>
  42. #define NO_MORE_INFO_FIELD 0xc1
  43. #define TYPE_CODE 0xc0 /*Language code*/
  44. /*
  45. * CONSTANT
  46. */
  47. const int ERROR_STATUS = -1;
  48. const int OK_STATUS = 0;
  49. const char * STAR_LINE_LIMITER =
  50. "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*";
  51. const char * EQUAL_LINE_LIMITER =
  52. "=================================================================";
  53. const int SIZE_OF_FILE_TYPE = 3;
  54. const unsigned char AMC_MODULE = 0x80;
  55. const int PICMG_ID_OFFSET = 3;
  56. const unsigned int COMPARE_CANDIDATE = 2;
  57. /* In AMC.0 or PICMG 3.0 specification offset start from 0 with 3 bytes of
  58. * Mfg.ID, 1 byte of Picmg record Id, and
  59. * 1 byte of format version, so the data offset start from 5
  60. */
  61. const int START_DATA_OFFSET = 5;
  62. const int LOWER_OEM_TYPE = 0xf0;
  63. const int UPPER_OEM_TYPE = 0xfe;
  64. const unsigned char DISABLE_PORT = 0x1f;
  65. const struct valstr ipmi_ekanalyzer_module_type[] = {
  66. { ON_CARRIER_FRU_FILE, "On-Carrier Device" },
  67. { A1_AMC_FRU_FILE, "AMC slot A1" },
  68. { A2_AMC_FRU_FILE, "AMC slot A2" },
  69. { A3_AMC_FRU_FILE, "AMC slot A3" },
  70. { A4_AMC_FRU_FILE, "AMC slot A4" },
  71. { B1_AMC_FRU_FILE, "AMC slot B1" },
  72. { B2_AMC_FRU_FILE, "AMC slot B2" },
  73. { B3_AMC_FRU_FILE, "AMC slot B3" },
  74. { B4_AMC_FRU_FILE, "AMC slot B4" },
  75. { RTM_FRU_FILE, "RTM" }, /*This is OEM specific module*/
  76. { CONFIG_FILE, "Configuration file" },
  77. { SHELF_MANAGER_FRU_FILE, "Shelf Manager" },
  78. { 0xffff , NULL },
  79. };
  80. const struct valstr ipmi_ekanalyzer_IPMBL_addr[] = {
  81. { 0x72, "AMC slot A1" },
  82. { 0x74, "AMC slot A2" },
  83. { 0x76, "AMC slot A3" },
  84. { 0x78, "AMC slot A4" },
  85. { 0x7a, "AMC slot B1" },
  86. { 0x7c, "AMC slot B2" },
  87. { 0x7e, "AMC slot B3" },
  88. { 0x80, "AMC slot B4" },
  89. { 0x90, "RTM"}, /*This is OEM specific module*/
  90. { 0xffff , NULL },
  91. };
  92. const struct valstr ipmi_ekanalyzer_link_type[] = {
  93. { 0x00, "Reserved" },
  94. { 0x01, "Reserved" },
  95. { 0x02, "AMC.1 PCI Express" },
  96. { 0x03, "AMC.1 PCI Express Advanced Switching" },
  97. { 0x04, "AMC.1 PCI Express Advanced Switching" },
  98. { 0x05, "AMC.2 Ethernet" },
  99. { 0x06, "AMC.4 Serial RapidIO" },
  100. { 0x07, "AMC.3 Storage" },
  101. /*This is OEM specific module*/
  102. { 0xf0, "OEM Type 0"},
  103. { 0xf1, "OEM Type 1"},
  104. { 0xf2, "OEM Type 2"},
  105. { 0xf3, "OEM Type 3"},
  106. { 0xf4, "OEM Type 4"},
  107. { 0xf5, "OEM Type 5"},
  108. { 0xf6, "OEM Type 6"},
  109. { 0xf7, "OEM Type 7"},
  110. { 0xf8, "OEM Type 8"},
  111. { 0xf9, "OEM Type 9"},
  112. { 0xfa, "OEM Type 10"},
  113. { 0xfb, "OEM Type 11"},
  114. { 0xfc, "OEM Type 12"},
  115. { 0xfd, "OEM Type 13"},
  116. { 0xfe, "OEM Type 14"},
  117. { 0xff , "Reserved" },
  118. };
  119. /*Reference: AMC.1 specification*/
  120. const struct valstr ipmi_ekanalyzer_extension_PCIE[] = {
  121. { 0x00, "Gen 1 capable - non SSC" },
  122. { 0x01, "Gen 1 capable - SSC" },
  123. { 0x02, "Gen 2 capable - non SSC" },
  124. { 0x03, "Gen 3 capable - SSC" },
  125. { 0x0f, "Reserved"},
  126. };
  127. /*Reference: AMC.2 specification*/
  128. const struct valstr ipmi_ekanalyzer_extension_ETHERNET[] = {
  129. { 0x00, "1000BASE-BX (SerDES Gigabit) Ethernet link" },
  130. { 0x01, "10GBASE-BX4 10 Gigabit Ethernet link" },
  131. };
  132. /*Reference: AMC.3 specification*/
  133. const struct valstr ipmi_ekanalyzer_extension_STORAGE[] = {
  134. { 0x00, "Fibre Channel (FC)" },
  135. { 0x01, "Serial ATA (SATA)" },
  136. { 0x02, "Serial Attached SCSI (SAS/SATA)" },
  137. };
  138. const struct valstr ipmi_ekanalyzer_asym_PCIE[] = {
  139. { 0x00, "exact match"},
  140. { 0x01, "provides a Primary PCI Express Port" },
  141. { 0x02, "provides a Secondary PCI Express Port" },
  142. };
  143. const struct valstr ipmi_ekanalyzer_asym_STORAGE[] = {
  144. { 0x00, "FC or SAS interface {exact match}" },
  145. { 0x01, "SATA Server interface" },
  146. { 0x02, "SATA Client interface" },
  147. { 0x03, "Reserved" },
  148. };
  149. const struct valstr ipmi_ekanalyzer_picmg_record_id[] = {
  150. { 0x04, "Backplane Point to Point Connectivity Record" },
  151. { 0x10, "Address Table Record" },
  152. { 0x11, "Shelf Power Distribution Record" },
  153. { 0x12, "Shelf Activation and Power Management Record" },
  154. { 0x13, "Shelf Manager IP Connection Record" },
  155. { 0x14, "Board Point to Point Connectivity Record" },
  156. { 0x15, "Radial IPMB-0 Link Mapping Record" },
  157. { 0x16, "Module Current Requirements Record" },
  158. { 0x17, "Carrier Activation and Power Management Record" },
  159. { 0x18, "Carrier Point-to-Point Connectivity Record" },
  160. { 0x19, "AdvancedMC Point-to-Point Connectivity Record" },
  161. { 0x1a, "Carrier Information Table" },
  162. { 0x1b, "Shelf Fan Geography Record" },
  163. { 0x2c, "Carrier Clock Point-to-Point Connectivity Record" },
  164. { 0x2d, "Clock Configuration Record" },
  165. };
  166. extern int verbose;
  167. struct ipmi_ek_multi_header {
  168. struct fru_multirec_header header;
  169. unsigned char * data;
  170. struct ipmi_ek_multi_header * prev;
  171. struct ipmi_ek_multi_header * next;
  172. };
  173. struct ipmi_ek_amc_p2p_connectivity_record{
  174. unsigned char guid_count;
  175. struct fru_picmgext_guid * oem_guid;
  176. unsigned char rsc_id;
  177. unsigned char ch_count;
  178. struct fru_picmgext_amc_channel_desc_record * ch_desc;
  179. unsigned char link_desc_count;
  180. struct fru_picmgext_amc_link_desc_record * link_desc;
  181. int * matching_result; /*For link descriptor comparision*/
  182. };
  183. /*****************************************************************************
  184. * Function prototype
  185. ******************************************************************************/
  186. /****************************************************************************
  187. * command Functions
  188. *****************************************************************************/
  189. static int ipmi_ekanalyzer_print( int argc, char * opt,
  190. char ** filename, int * file_type );
  191. static tboolean ipmi_ekanalyzer_ekeying_match( int argc, char * opt,
  192. char ** filename, int * file_type );
  193. /****************************************************************************
  194. * Linked list Functions
  195. *****************************************************************************/
  196. static void ipmi_ek_add_record2list( struct ipmi_ek_multi_header ** record,
  197. struct ipmi_ek_multi_header ** list_head,
  198. struct ipmi_ek_multi_header ** list_last );
  199. static void ipmi_ek_display_record( struct ipmi_ek_multi_header * record,
  200. struct ipmi_ek_multi_header * list_head,
  201. struct ipmi_ek_multi_header * list_last );
  202. static void ipmi_ek_remove_record_from_list(
  203. struct ipmi_ek_multi_header * record,
  204. struct ipmi_ek_multi_header ** list_head,
  205. struct ipmi_ek_multi_header ** list_last );
  206. static int ipmi_ekanalyzer_fru_file2structure( char * filename,
  207. struct ipmi_ek_multi_header ** list_head,
  208. struct ipmi_ek_multi_header ** list_record,
  209. struct ipmi_ek_multi_header ** list_last );
  210. /****************************************************************************
  211. * Ekeying match Functions
  212. *****************************************************************************/
  213. static int ipmi_ek_matching_process( int * file_type, int index1, int index2,
  214. struct ipmi_ek_multi_header ** list_head,
  215. struct ipmi_ek_multi_header ** list_last, char * opt,
  216. struct ipmi_ek_multi_header * pphysical );
  217. static int ipmi_ek_get_resource_descriptor( int port_count, int index,
  218. struct fru_picmgext_carrier_p2p_descriptor * port_desc,
  219. struct ipmi_ek_multi_header * record );
  220. static int ipmi_ek_create_amc_p2p_record( struct ipmi_ek_multi_header * record,
  221. struct ipmi_ek_amc_p2p_connectivity_record * amc_record );
  222. static int ipmi_ek_compare_link( struct ipmi_ek_multi_header * physic_record,
  223. struct ipmi_ek_amc_p2p_connectivity_record record1,
  224. struct ipmi_ek_amc_p2p_connectivity_record record2,
  225. char * opt, int file_type1, int file_type2 );
  226. static tboolean ipmi_ek_compare_channel_descriptor(
  227. struct fru_picmgext_amc_channel_desc_record ch_desc1,
  228. struct fru_picmgext_amc_channel_desc_record ch_desc2,
  229. struct fru_picmgext_carrier_p2p_descriptor * port_desc,
  230. int index_port, unsigned char rsc_id );
  231. static int ipmi_ek_compare_link_descriptor(
  232. struct ipmi_ek_amc_p2p_connectivity_record record1, int index1,
  233. struct ipmi_ek_amc_p2p_connectivity_record record2, int index2 );
  234. static int ipmi_ek_compare_asym( unsigned char asym[COMPARE_CANDIDATE] );
  235. static int ipmi_ek_compare_number_of_enable_port(
  236. struct fru_picmgext_amc_link_desc_record link_desc[COMPARE_CANDIDATE] );
  237. static int ipmi_ek_check_physical_connectivity(
  238. struct ipmi_ek_amc_p2p_connectivity_record record1, int index1,
  239. struct ipmi_ek_amc_p2p_connectivity_record record2, int index2,
  240. struct ipmi_ek_multi_header * record,
  241. int filetype1, int filetype2, char * option );
  242. /****************************************************************************
  243. * Display Functions
  244. *****************************************************************************/
  245. static int ipmi_ek_display_fru_header( char * filename );
  246. static int ipmi_ek_display_fru_header_detail(char * filename);
  247. static int ipmi_ek_display_chassis_info_area(FILE * input_file, long offset);
  248. static size_t ipmi_ek_display_board_info_area( FILE * input_file,
  249. char * board_type, unsigned int * board_length );
  250. static int ipmi_ek_display_product_info_area(FILE * input_file, long offset);
  251. static tboolean ipmi_ek_display_link_descriptor( int file_type,
  252. unsigned char rsc_id, char * str,
  253. struct fru_picmgext_amc_link_desc_record link_desc );
  254. static void ipmi_ek_display_oem_guid(
  255. struct ipmi_ek_amc_p2p_connectivity_record amc_record1 );
  256. static int ipmi_ek_display_carrier_connectivity(
  257. struct ipmi_ek_multi_header * record );
  258. static int ipmi_ek_display_power( int argc, char * opt,
  259. char ** filename, int * file_type );
  260. static void ipmi_ek_display_current_descriptor(
  261. struct fru_picmgext_carrier_activation_record car,
  262. struct fru_picmgext_activation_record * cur_desc, char * filename );
  263. static void ipmi_ek_display_backplane_p2p_record(
  264. struct ipmi_ek_multi_header * record );
  265. static void ipmi_ek_display_address_table_record(
  266. struct ipmi_ek_multi_header * record );
  267. static void ipmi_ek_display_shelf_power_distribution_record(
  268. struct ipmi_ek_multi_header * record );
  269. static void ipmi_ek_display_shelf_activation_record(
  270. struct ipmi_ek_multi_header * record );
  271. static void ipmi_ek_display_shelf_ip_connection_record(
  272. struct ipmi_ek_multi_header * record );
  273. static void ipmi_ek_display_shelf_fan_geography_record(
  274. struct ipmi_ek_multi_header * record );
  275. static void ipmi_ek_display_board_p2p_record(
  276. struct ipmi_ek_multi_header * record );
  277. static void ipmi_ek_display_radial_ipmb0_record(
  278. struct ipmi_ek_multi_header * record );
  279. static void ipmi_ek_display_amc_current_record(
  280. struct ipmi_ek_multi_header * record );
  281. static void ipmi_ek_display_amc_activation_record (
  282. struct ipmi_ek_multi_header * record );
  283. static void ipmi_ek_display_amc_p2p_record(
  284. struct ipmi_ek_multi_header * record );
  285. static void ipmi_ek_display_amc_carrier_info_record(
  286. struct ipmi_ek_multi_header * record );
  287. static void ipmi_ek_display_clock_carrier_p2p_record(
  288. struct ipmi_ek_multi_header * record );
  289. static void ipmi_ek_display_clock_config_record(
  290. struct ipmi_ek_multi_header * record );
  291. /**************************************************************************
  292. *
  293. * Function name: ipmi_ekanalyzer_usage
  294. *
  295. * Description : Print the usage (help menu) of ekeying analyzer tool
  296. *
  297. * Restriction : None
  298. *
  299. * Input : None
  300. *
  301. * Output : None
  302. *
  303. * Global : None
  304. *
  305. * Return : None
  306. *
  307. ***************************************************************************/
  308. static void
  309. ipmi_ekanalyzer_usage(void)
  310. {
  311. lprintf(LOG_NOTICE,
  312. "Ekeying analyzer tool version 1.00");
  313. lprintf(LOG_NOTICE,
  314. "ekanalyzer Commands:");
  315. lprintf(LOG_NOTICE,
  316. " print [carrier | power | all] <oc=filename1> <b1=filename2>...");
  317. lprintf(LOG_NOTICE,
  318. " frushow <b2=filename>");
  319. lprintf(LOG_NOTICE,
  320. " summary [match | unmatch | all] <oc=filename1> <b1=filename2>...");
  321. }
  322. /**************************************************************************
  323. *
  324. * Function name: ipmi_ek_get_file_type
  325. *
  326. * Description: this function takes an argument, then xtract the file type and
  327. * convert into module type (on carrier, AMC,...) value.
  328. *
  329. *
  330. * Restriction: None
  331. *
  332. * Input: argument: strings contain the type and the name of the file
  333. * together
  334. *
  335. * Output: None
  336. *
  337. * Global: None
  338. *
  339. * Return: Return value of module type: On carrier FRU file, A1 FRUM file...
  340. * if the file type is invalid, it return -1. See structure
  341. * ipmi_ekanalyzer_module_type for a list of valid type.
  342. ***************************************************************************/
  343. static int
  344. ipmi_ek_get_file_type(char *argument)
  345. {
  346. int filetype = ERROR_STATUS;
  347. if (strlen(argument) <= MIN_ARGUMENT) {
  348. return filetype;
  349. }
  350. if (strncmp(argument, "oc=", SIZE_OF_FILE_TYPE) == 0) {
  351. filetype = ON_CARRIER_FRU_FILE;
  352. } else if (strncmp(argument, "a1=", SIZE_OF_FILE_TYPE) == 0) {
  353. filetype = A1_AMC_FRU_FILE;
  354. } else if (strncmp(argument, "a2=", SIZE_OF_FILE_TYPE) == 0) {
  355. filetype = A2_AMC_FRU_FILE;
  356. } else if (strncmp(argument, "a3=", SIZE_OF_FILE_TYPE) == 0) {
  357. filetype = A3_AMC_FRU_FILE;
  358. } else if (strncmp(argument, "a4=", SIZE_OF_FILE_TYPE) == 0) {
  359. filetype = A4_AMC_FRU_FILE;
  360. } else if (strncmp(argument, "b1=", SIZE_OF_FILE_TYPE) == 0) {
  361. filetype = B1_AMC_FRU_FILE;
  362. } else if (strncmp(argument, "b2=", SIZE_OF_FILE_TYPE) == 0) {
  363. filetype = B2_AMC_FRU_FILE;
  364. } else if (strncmp(argument, "b3=", SIZE_OF_FILE_TYPE) == 0) {
  365. filetype = B3_AMC_FRU_FILE;
  366. } else if (strncmp(argument, "b4=", SIZE_OF_FILE_TYPE) == 0) {
  367. filetype = B4_AMC_FRU_FILE;
  368. } else if (strncmp(argument, "rt=", SIZE_OF_FILE_TYPE) == 0) {
  369. filetype = RTM_FRU_FILE;
  370. } else if (strncmp(argument, "rc=", SIZE_OF_FILE_TYPE) == 0) {
  371. filetype = CONFIG_FILE;
  372. } else if (strncmp(argument, "sm=", SIZE_OF_FILE_TYPE) == 0) {
  373. filetype = SHELF_MANAGER_FRU_FILE;
  374. } else {
  375. filetype = ERROR_STATUS;
  376. }
  377. return filetype;
  378. }
  379. /**************************************************************************
  380. *
  381. * Function name: ipmi_ekanalyzer_main
  382. *
  383. * Description: Main program of ekeying analyzer. It calls the appropriate
  384. * function according to the command received.
  385. *
  386. * Restriction: None
  387. *
  388. * Input: ipmi_intf * intf: ?
  389. * int argc : number of argument received
  390. * int ** argv: argument strings
  391. *
  392. * Output: None
  393. *
  394. * Global: None
  395. *
  396. * Return: OK_STATUS as succes or ERROR_STATUS as error
  397. *
  398. ***************************************************************************/
  399. int
  400. ipmi_ekanalyzer_main(struct ipmi_intf *intf, int argc, char **argv)
  401. {
  402. int rc = ERROR_STATUS;
  403. int file_type[MAX_FILE_NUMBER];
  404. char *filename[MAX_FILE_NUMBER];
  405. unsigned int argument_offset = 0;
  406. unsigned int type_offset = 0;
  407. /* list des multi record */
  408. struct ipmi_ek_multi_header *list_head = NULL;
  409. struct ipmi_ek_multi_header *list_record = NULL;
  410. struct ipmi_ek_multi_header *list_last = NULL;
  411. if (argc == 0) {
  412. lprintf(LOG_ERR, "Not enough parameters given.");
  413. ipmi_ekanalyzer_usage();
  414. return (-1);
  415. } else if ((argc - 1) > MAX_FILE_NUMBER) {
  416. lprintf(LOG_ERR, "Too too many parameters given.");
  417. return (-1);
  418. }
  419. if (strcmp(argv[argument_offset], "help") == 0) {
  420. ipmi_ekanalyzer_usage();
  421. return 0;
  422. } else if ((strcmp(argv[argument_offset], "frushow") == 0)
  423. && (argc > (MIN_ARGUMENT-1))) {
  424. for (type_offset = 0; type_offset < (argc-1); type_offset++ ) {
  425. argument_offset++;
  426. file_type[type_offset] = ipmi_ek_get_file_type(argv[argument_offset]);
  427. if (file_type[type_offset] == ERROR_STATUS
  428. || file_type[type_offset] == CONFIG_FILE) {
  429. lprintf(LOG_ERR, "Invalid file type!");
  430. lprintf(LOG_ERR, " ekanalyzer frushow <xx=frufile> ...");
  431. return (-1);
  432. }
  433. /* because of strlen doesn't count '\0',
  434. * we need to add 1 byte for this character
  435. * to filename size
  436. */
  437. filename[type_offset] = malloc(strlen(argv[argument_offset])
  438. + 1 - SIZE_OF_FILE_TYPE);
  439. if (filename[type_offset] == NULL) {
  440. lprintf(LOG_ERR, "malloc failure");
  441. return (-1);
  442. }
  443. strcpy(filename[type_offset],
  444. &argv[argument_offset][SIZE_OF_FILE_TYPE]);
  445. printf("Start converting file '%s'...\n",
  446. filename[type_offset]);
  447. /* Display FRU header offset */
  448. rc = ipmi_ek_display_fru_header (filename[type_offset]);
  449. if (rc != ERROR_STATUS) {
  450. /* Display FRU header info in detail record */
  451. rc = ipmi_ek_display_fru_header_detail(filename[type_offset]);
  452. /* Convert from binary data into multi record structure */
  453. rc = ipmi_ekanalyzer_fru_file2structure (filename[type_offset],
  454. &list_head, &list_record, &list_last );
  455. ipmi_ek_display_record(list_record, list_head, list_last);
  456. /* Remove record of list */
  457. while (list_head != NULL) {
  458. ipmi_ek_remove_record_from_list(list_head,
  459. &list_head,&list_last );
  460. if (verbose > 1) {
  461. printf("record has been removed!\n");
  462. }
  463. }
  464. }
  465. free(filename[type_offset]);
  466. filename[type_offset] = NULL;
  467. }
  468. } else if ((strcmp(argv[argument_offset], "print") == 0)
  469. || (strcmp(argv[argument_offset], "summary") == 0)) {
  470. /* Display help text for corresponding command
  471. * if not enough parameters were given.
  472. */
  473. char * option;
  474. /* index=1 indicates start position of first file
  475. * name in command line
  476. */
  477. int index = 1;
  478. int filename_size=0;
  479. if (argc < MIN_ARGUMENT) {
  480. lprintf(LOG_ERR, "Not enough parameters given.");
  481. if (strcmp(argv[argument_offset], "print") == 0) {
  482. lprintf(LOG_ERR,
  483. " ekanalyzer print [carrier/power/all]"
  484. " <xx=frufile> <xx=frufile> [xx=frufile]");
  485. } else {
  486. lprintf(LOG_ERR,
  487. " ekanalyzer summary [match/ unmatch/ all]"
  488. " <xx=frufile> <xx=frufile> [xx=frufile]");
  489. }
  490. return ERROR_STATUS;
  491. }
  492. argument_offset++;
  493. if ((strcmp(argv[argument_offset], "carrier") == 0)
  494. || (strcmp(argv[argument_offset], "power") == 0)
  495. || (strcmp(argv[argument_offset], "all") == 0)) {
  496. option = argv[argument_offset];
  497. index ++;
  498. argc--;
  499. } else if ((strcmp(argv[argument_offset], "match") == 0)
  500. || ( strcmp(argv[argument_offset], "unmatch") == 0)) {
  501. option = argv[argument_offset];
  502. index ++;
  503. argc--;
  504. } else if ( strncmp(&argv[argument_offset][2], "=", 1) == 0) {
  505. /* since the command line must receive xx=filename,
  506. * so the position of "=" sign is 2
  507. */
  508. option = "default";
  509. /* Since there is no option from user, the first argument
  510. * becomes first file type
  511. */
  512. index = 1; /* index of argument */
  513. } else {
  514. option = "invalid";
  515. printf("Invalid option '%s'\n", argv[argument_offset]);
  516. argument_offset--;
  517. if (strcmp(argv[0], "print") == 0) {
  518. lprintf (LOG_ERR,
  519. " ekanalyzer print [carrier/power/all]"
  520. " <xx=frufile> <xx=frufile> [xx=frufile]");
  521. } else {
  522. lprintf (LOG_ERR,
  523. " ekanalyzer summary [match/ unmatch/ all]"
  524. " <xx=frufile> <xx=frufile> [xx=frufile]");
  525. }
  526. rc = ERROR_STATUS;
  527. }
  528. if (strcmp(option, "invalid") != 0) {
  529. int i=0;
  530. for (i = 0; i < (argc-1); i++) {
  531. file_type[i] = ipmi_ek_get_file_type (argv[index]);
  532. if (file_type[i] == ERROR_STATUS) {
  533. /* display the first 2 charactors (file type) of argument */
  534. lprintf(LOG_ERR, "Invalid file type: %c%c\n",
  535. argv[index][0],
  536. argv[index][1]);
  537. ipmi_ekanalyzer_usage();
  538. rc = ERROR_STATUS;
  539. break;
  540. }
  541. /* size is equal to string size minus 3 bytes of file type plus
  542. * 1 byte of '\0' since the strlen doesn't count the '\0'
  543. */
  544. filename_size = strlen(argv[index]) - SIZE_OF_FILE_TYPE + 1;
  545. if (filename_size > 0) {
  546. filename[i] = malloc( filename_size );
  547. if (filename[i] != NULL) {
  548. strcpy(filename[i], &argv[index][SIZE_OF_FILE_TYPE]);
  549. } else {
  550. lprintf(LOG_ERR, "ipmitool: malloc failure");
  551. rc = ERROR_STATUS;
  552. break;
  553. }
  554. }
  555. rc = OK_STATUS;
  556. index++;
  557. }
  558. if (rc != ERROR_STATUS) {
  559. if (verbose > 0) {
  560. for (i = 0; i < (argc-1); i++) {
  561. printf ("Type: %s, ",
  562. val2str(file_type[i],
  563. ipmi_ekanalyzer_module_type));
  564. printf("file name: %s\n", filename[i]);
  565. }
  566. }
  567. if (strcmp(argv[0], "print") == 0) {
  568. rc = ipmi_ekanalyzer_print((argc-1),
  569. option, filename, file_type);
  570. } else {
  571. rc = ipmi_ekanalyzer_ekeying_match((argc-1),
  572. option, filename, file_type);
  573. }
  574. for (i = 0; i < (argc-1); i++) {
  575. if (filename[i] != NULL) {
  576. free(filename[i]);
  577. filename[i] = NULL;
  578. }
  579. }
  580. } /* End of ERROR_STATUS */
  581. } /* End of comparison of invalid option */
  582. } else {
  583. lprintf(LOG_ERR, "Invalid ekanalyzer command: %s", argv[0]);
  584. ipmi_ekanalyzer_usage();
  585. rc = ERROR_STATUS;
  586. }
  587. return rc;
  588. }
  589. /**************************************************************************
  590. *
  591. * Function name: ipmi_ekanalyzer_print
  592. *
  593. * Description: this function will display the topology, power or both
  594. * information together according to the option that it received.
  595. *
  596. * Restriction: None
  597. *
  598. * Input: int argc: number of the argument received
  599. * char* opt: option string that will tell what to display
  600. * char** filename: strings that contained filename of FRU data binary file
  601. * int* file_type: a pointer that contain file type (on carrier file,
  602. * a1 file, b1 file...). See structure
  603. * ipmi_ekanalyzer_module_type for a list of valid type
  604. *
  605. * Output: None
  606. *
  607. * Global: None
  608. *
  609. * Return: return 0 as success and -1 as error.
  610. *
  611. ***************************************************************************/
  612. static int
  613. ipmi_ekanalyzer_print(int argc, char *opt, char **filename, int *file_type)
  614. {
  615. int return_value = OK_STATUS;
  616. /* Display carrier topology */
  617. if ((strcmp(opt, "carrier") == 0) || (strcmp(opt, "default") == 0)) {
  618. tboolean found_flag = FALSE;
  619. int index = 0;
  620. int index_name[argc];
  621. int list = 0;
  622. /* list of multi record */
  623. struct ipmi_ek_multi_header *list_head[argc];
  624. struct ipmi_ek_multi_header *list_record[argc];
  625. struct ipmi_ek_multi_header *list_last[argc];
  626. for (list=0; list < argc; list++) {
  627. list_head[list] = NULL;
  628. list_record[list] = NULL;
  629. list_last[list] = NULL;
  630. }
  631. /* reset list count */
  632. list = 0;
  633. for (index = 0; index < argc; index++) {
  634. if (file_type[index] != ON_CARRIER_FRU_FILE) {
  635. continue;
  636. }
  637. index_name[list] = index;
  638. return_value = ipmi_ekanalyzer_fru_file2structure(filename[index],
  639. &list_head[list],
  640. &list_record[list],
  641. &list_last[list]);
  642. list++;
  643. found_flag = TRUE;
  644. }
  645. if (!found_flag) {
  646. printf("No carrier file has been found\n");
  647. return_value = ERROR_STATUS;
  648. } else {
  649. int i = 0;
  650. for (i = 0; i < argc; i++) {
  651. /* this is a flag to advoid displaying
  652. * the same data multiple time
  653. */
  654. tboolean first_data = TRUE;
  655. for (list_record[i] = list_head[i];
  656. list_record[i] != NULL;
  657. list_record[i] = list_record[i]->next) {
  658. if (list_record[i]->data[PICMG_ID_OFFSET] == FRU_AMC_CARRIER_P2P) {
  659. if (first_data) {
  660. printf("%s\n", STAR_LINE_LIMITER);
  661. printf("From Carrier file: %s\n", filename[index_name[i]]);
  662. first_data = FALSE;
  663. }
  664. return_value = ipmi_ek_display_carrier_connectivity(list_record[i]);
  665. } else if (list_record[i]->data[PICMG_ID_OFFSET] == FRU_AMC_CARRIER_INFO) {
  666. /*See AMC.0 specification Table3-3 for mor detail*/
  667. #define COUNT_OFFSET 6
  668. if (first_data) {
  669. printf("From Carrier file: %s\n", filename[index_name[i]]);
  670. first_data = FALSE;
  671. }
  672. printf(" Number of AMC bays supported by Carrier: %d\n",
  673. list_record[i]->data[COUNT_OFFSET]);
  674. }
  675. }
  676. }
  677. /*Destroy the list of record*/
  678. for (i = 0; i < argc; i++) {
  679. while (list_head[i] != NULL) {
  680. ipmi_ek_remove_record_from_list(list_head[i],
  681. &list_head[i], &list_last[i]);
  682. }
  683. /* display deleted result when we
  684. * reach the last record
  685. */
  686. if ((i == (list-1)) && verbose) {
  687. printf("Record list has been removed successfully\n");
  688. }
  689. }
  690. }
  691. } else if (strcmp(opt, "power") == 0) {
  692. printf("Print power information\n");
  693. return_value = ipmi_ek_display_power(argc, opt, filename, file_type);
  694. } else if (strcmp(opt, "all") == 0) {
  695. printf("Print all information\n");
  696. return_value = ipmi_ek_display_power(argc, opt, filename, file_type);
  697. } else {
  698. lprintf(LOG_ERR, "Invalid option %s", opt);
  699. return_value = ERROR_STATUS;
  700. }
  701. return return_value;
  702. }
  703. /**************************************************************************
  704. *
  705. * Function name: ipmi_ek_display_carrier_connectivity
  706. *
  707. * Description: Display the topology between a Carrier and all AMC modules by
  708. * using carrier p2p connectivity record
  709. *
  710. * Restriction: Ref: AMC.0 Specification: Table 3-13 and Table 3-14
  711. *
  712. * Input: struct ipmi_ek_multi_header* record: a pointer to the carrier p2p
  713. * connectivity record.
  714. *
  715. * Output: None
  716. *
  717. * Global: None
  718. *
  719. * Return: return 0 on success and -1 if the record doesn't exist.
  720. *
  721. ***************************************************************************/
  722. static int
  723. ipmi_ek_display_carrier_connectivity(struct ipmi_ek_multi_header *record)
  724. {
  725. int offset = START_DATA_OFFSET;
  726. struct fru_picmgext_carrier_p2p_record rsc_desc;
  727. struct fru_picmgext_carrier_p2p_descriptor *port_desc;
  728. if (record == NULL) {
  729. lprintf(LOG_ERR, "P2P connectivity record is invalid\n");
  730. return ERROR_STATUS;
  731. }
  732. if (verbose > 1) {
  733. int k = 0;
  734. printf("Binary data of Carrier p2p connectivity"\
  735. " record starting from mfg id\n");
  736. for (k = 0; k < (record->header.len); k++) {
  737. printf("%02x ", record->data[k]);
  738. }
  739. printf("\n");
  740. }
  741. while (offset <= (record->header.len - START_DATA_OFFSET)) {
  742. rsc_desc.resource_id = record->data[offset++];
  743. rsc_desc.p2p_count = record->data[offset++];
  744. if (verbose > 0) {
  745. printf("resource id= %02x port count= %d\n",
  746. rsc_desc.resource_id, rsc_desc.p2p_count);
  747. }
  748. /* check if it is an AMC Module */
  749. if ((rsc_desc.resource_id & AMC_MODULE) == AMC_MODULE) {
  750. /* check if it is an RTM module */
  751. if (rsc_desc.resource_id == AMC_MODULE) {
  752. printf(" %s topology:\n",
  753. val2str(RTM_IPMB_L,
  754. ipmi_ekanalyzer_IPMBL_addr));
  755. } else {
  756. /* The last four bits of resource ID
  757. * represent site number (mask = 0x0f)
  758. */
  759. printf(" %s topology:\n",
  760. val2str((rsc_desc.resource_id & 0x0f),
  761. ipmi_ekanalyzer_module_type));
  762. }
  763. } else {
  764. printf(" On Carrier Device ID %d topology: \n",
  765. (rsc_desc.resource_id & 0x0f));
  766. }
  767. while (rsc_desc.p2p_count > 0) {
  768. unsigned char data[3];
  769. # ifndef WORDS_BIGENDIAN
  770. data[0] = record->data[offset + 0];
  771. data[1] = record->data[offset + 1];
  772. data[2] = record->data[offset + 2];
  773. # else
  774. data[0] = record->data[offset + 2];
  775. data[1] = record->data[offset + 1];
  776. data[2] = record->data[offset + 0];
  777. # endif
  778. port_desc = (struct fru_picmgext_carrier_p2p_descriptor*)data;
  779. offset += sizeof(struct fru_picmgext_carrier_p2p_descriptor);
  780. if ((port_desc->remote_resource_id & AMC_MODULE) == AMC_MODULE) {
  781. printf("\tPort %d =====> %s, Port %d\n",
  782. port_desc->local_port,
  783. val2str((port_desc->remote_resource_id & 0x0f),
  784. ipmi_ekanalyzer_module_type),
  785. port_desc->remote_port);
  786. } else {
  787. printf("\tPort %d =====> On Carrier Device ID %d, Port %d\n",
  788. port_desc->local_port,
  789. (port_desc->remote_resource_id & 0x0f),
  790. port_desc->remote_port);
  791. }
  792. rsc_desc.p2p_count--;
  793. }
  794. }
  795. return OK_STATUS;
  796. }
  797. /**************************************************************************
  798. *
  799. * Function name: ipmi_ek_display_power
  800. *
  801. * Description: Display the power management of the Carrier and AMC module by
  802. * using current management record. If the display option equal to all,
  803. * it will display power and carrier topology together.
  804. *
  805. * Restriction: Reference: AMC.0 Specification, Table 3-11
  806. *
  807. * Input: int argc: number of the argument received
  808. * char* opt: option string that will tell what to display
  809. * char** filename: strings that contained filename of FRU data binary file
  810. * int* file_type: a pointer that contain file type (on carrier file,
  811. * a1 file, b1 file...)
  812. *
  813. * Output: None
  814. *
  815. * Global: None
  816. *
  817. * Return: return 0 on success and -1 if the record doesn't exist.
  818. *
  819. ***************************************************************************/
  820. static int
  821. ipmi_ek_display_power( int argc, char * opt, char ** filename, int * file_type )
  822. {
  823. int num_file=0;
  824. int return_value = ERROR_STATUS;
  825. int index = 0;
  826. /*list des multi record*/
  827. struct ipmi_ek_multi_header * list_head[argc];
  828. struct ipmi_ek_multi_header * list_record[argc];
  829. struct ipmi_ek_multi_header * list_last[argc];
  830. for ( num_file = 0; num_file < argc; num_file++ ){
  831. list_head[num_file] = NULL;
  832. list_record[num_file] = NULL;
  833. list_last[num_file] = NULL;
  834. }
  835. for ( num_file = 0; num_file < argc; num_file++ ){
  836. tboolean is_first_data = TRUE;
  837. if ( file_type[num_file] == CONFIG_FILE ){
  838. num_file++;
  839. }
  840. if ( is_first_data ){
  841. printf("%s\n", STAR_LINE_LIMITER);
  842. printf("\nFrom %s file '%s'\n",
  843. val2str( file_type[num_file], ipmi_ekanalyzer_module_type),
  844. filename[num_file]);
  845. is_first_data = FALSE;
  846. }
  847. return_value = ipmi_ekanalyzer_fru_file2structure( filename[num_file],
  848. &list_head[num_file], &list_record[num_file], &list_last[num_file]);
  849. if ( list_head[num_file] != NULL ){
  850. for ( list_record[num_file] = list_head[num_file];
  851. list_record[num_file] != NULL;
  852. list_record[num_file] = list_record[num_file]->next
  853. ){
  854. if ( ( strcmp(opt, "all") == 0 )
  855. && ( file_type[num_file] == ON_CARRIER_FRU_FILE )
  856. ){
  857. if ( list_record[num_file]->data[PICMG_ID_OFFSET]
  858. ==
  859. FRU_AMC_CARRIER_P2P
  860. ){
  861. return_value = ipmi_ek_display_carrier_connectivity(
  862. list_record[num_file] );
  863. }
  864. else if ( list_record[num_file]->data[PICMG_ID_OFFSET]
  865. ==
  866. FRU_AMC_CARRIER_INFO
  867. ){
  868. /*Ref: See AMC.0 Specification Table 3-3: Carrier Information
  869. * Table about offset value
  870. */
  871. printf( " Number of AMC bays supported by Carrier: %d\n",
  872. list_record[num_file]->data[START_DATA_OFFSET+1] );
  873. }
  874. }
  875. /*Ref: AMC.0 Specification: Table 3-11
  876. * Carrier Activation and Current Management Record
  877. */
  878. if ( list_record[num_file]->data[PICMG_ID_OFFSET]
  879. ==
  880. FRU_AMC_ACTIVATION
  881. ){
  882. int index_data = START_DATA_OFFSET;
  883. struct fru_picmgext_carrier_activation_record car;
  884. struct fru_picmgext_activation_record * cur_desc;
  885. memcpy ( &car, &list_record[num_file]->data[index_data],
  886. sizeof (struct fru_picmgext_carrier_activation_record) );
  887. index_data +=
  888. sizeof (struct fru_picmgext_carrier_activation_record);
  889. cur_desc = malloc (car.module_activation_record_count * \
  890. sizeof (struct fru_picmgext_activation_record) );
  891. for(index=0; index<car.module_activation_record_count; index++){
  892. memcpy( &cur_desc[index],
  893. &list_record[num_file]->data[index_data],
  894. sizeof (struct fru_picmgext_activation_record) );
  895. index_data += sizeof (struct fru_picmgext_activation_record);
  896. }
  897. /*Display the current*/
  898. ipmi_ek_display_current_descriptor( car,
  899. cur_desc, filename[num_file] );
  900. free(cur_desc);
  901. cur_desc = NULL;
  902. }
  903. /*Ref: AMC.0 specification, Table 3-10: Module Current Requirement*/
  904. else if ( list_record[num_file]->data[PICMG_ID_OFFSET]
  905. == FRU_AMC_CURRENT
  906. ){
  907. float power_in_watt = 0;
  908. float current_in_amp = 0;
  909. printf(" %s power required (Current Draw): ",
  910. val2str ( file_type[num_file], ipmi_ekanalyzer_module_type) );
  911. current_in_amp =
  912. list_record[num_file]->data[START_DATA_OFFSET]*0.1;
  913. power_in_watt = current_in_amp * AMC_VOLTAGE;
  914. printf("%.2f Watts (%.2f Amps)\n",power_in_watt, current_in_amp);
  915. }
  916. }
  917. return_value = OK_STATUS;
  918. /*Destroy the list of record*/
  919. for ( index = 0; index < argc; index++ ){
  920. while ( list_head[index] != NULL ){
  921. ipmi_ek_remove_record_from_list ( list_head[index],
  922. &list_head[index],&list_last[index] );
  923. }
  924. if ( verbose > 1 )
  925. printf("Record list has been removed successfully\n");
  926. }
  927. }
  928. }
  929. printf("%s\n", STAR_LINE_LIMITER);
  930. return return_value;
  931. }
  932. /**************************************************************************
  933. *
  934. * Function name: ipmi_ek_display_current_descriptor
  935. *
  936. * Description: Display the current descriptor under format xx Watts (xx Amps)
  937. *
  938. * Restriction: None
  939. *
  940. * Input: struct fru_picmgext_carrier_activation_record car: contain binary data
  941. * of carrier activation record
  942. * struct fru_picmgext_activation_record * cur_desc: contain current
  943. * descriptor
  944. * char* filename: strings that contained filename of FRU data binary file
  945. *
  946. * Output: None
  947. *
  948. * Global: None
  949. *
  950. * Return: None
  951. *
  952. ***************************************************************************/
  953. static void
  954. ipmi_ek_display_current_descriptor(
  955. struct fru_picmgext_carrier_activation_record car,
  956. struct fru_picmgext_activation_record *cur_desc,
  957. char *filename)
  958. {
  959. int index = 0;
  960. float power_in_watt = 0.0;
  961. float current_in_amp = 0.0;
  962. for (index = 0; index < car.module_activation_record_count; index++) {
  963. /* See AMC.0 specification, Table 3-12 for
  964. * detail about calculation
  965. */
  966. current_in_amp = (float)cur_desc[index].max_module_curr * 0.1;
  967. power_in_watt = (float)current_in_amp * AMC_VOLTAGE;
  968. printf(" Carrier AMC power available on %s:\n",
  969. val2str( cur_desc[index].ibmb_addr,
  970. ipmi_ekanalyzer_IPMBL_addr));
  971. printf("\t- Local IPMB Address \t: %02x\n",
  972. cur_desc[index].ibmb_addr);
  973. printf("\t- Maximum module Current\t: %.2f Watts (%.2f Amps)\n",
  974. power_in_watt, current_in_amp);
  975. }
  976. /* Display total power on Carrier */
  977. current_in_amp = (float)car.max_internal_curr * 0.1;
  978. power_in_watt = (float)current_in_amp * AMC_VOLTAGE;
  979. printf(" Carrier AMC total power available for all bays from file '%s':",
  980. filename);
  981. printf(" %.2f Watts (%.2f Amps)\n", power_in_watt, current_in_amp);
  982. }
  983. /**************************************************************************
  984. *
  985. * Function name: ipmi_ekanalyzer_ekeying_match
  986. *
  987. * Description: Check for possible Ekeying match between two FRU files
  988. *
  989. * Restriction: None
  990. *
  991. * Input: argc: number of the argument received
  992. * opt: string that contains display option received from user.
  993. * filename: strings that contained filename of FRU data binary file
  994. * file_type: a pointer that contain file type (on carrier file,
  995. * a1 file, b1 file...)
  996. *
  997. * Output: None
  998. *
  999. * Global: None
  1000. *
  1001. * Return: return TRUE on success and FALSE if the record doesn't exist.
  1002. *
  1003. ***************************************************************************/
  1004. static tboolean
  1005. ipmi_ekanalyzer_ekeying_match( int argc, char * opt,
  1006. char ** filename, int * file_type )
  1007. {
  1008. tboolean return_value = FALSE;
  1009. if ( (strcmp(opt, "carrier") == 0 ) || (strcmp(opt, "power") == 0) ){
  1010. lprintf(LOG_ERR, " ekanalyzer summary [match/ unmatch/ all]"\
  1011. " <xx=frufile> <xx=frufile> [xx=frufile]");
  1012. return_value = ERROR_STATUS;
  1013. }
  1014. else{
  1015. int num_file=0;
  1016. tboolean amc_file = FALSE; /*used to indicate the present of AMC file*/
  1017. tboolean oc_file = FALSE; /*used to indicate the present of Carrier file*/
  1018. /*Check for possible ekeying match between files*/
  1019. for ( num_file=0; num_file < argc; num_file++ ){
  1020. if ( ( file_type[num_file] == ON_CARRIER_FRU_FILE )
  1021. || ( file_type[num_file] == CONFIG_FILE )
  1022. || ( file_type[num_file] == SHELF_MANAGER_FRU_FILE )
  1023. ){
  1024. amc_file = FALSE;
  1025. }
  1026. else { /*there is an amc file*/
  1027. amc_file = TRUE;
  1028. break;
  1029. }
  1030. }
  1031. if ( amc_file == FALSE ){
  1032. printf("\nNo AMC FRU file is provided --->" \
  1033. " No possible ekeying match!\n");
  1034. return_value = ERROR_STATUS;
  1035. }
  1036. else{
  1037. /*If no carrier file is provided, return error*/
  1038. for ( num_file=0; num_file < argc; num_file++ ){
  1039. if ( (file_type[num_file] == ON_CARRIER_FRU_FILE )
  1040. || ( file_type[num_file] == CONFIG_FILE )
  1041. || ( file_type[num_file] == SHELF_MANAGER_FRU_FILE )
  1042. ){
  1043. oc_file = TRUE;
  1044. break;
  1045. }
  1046. }
  1047. if ( !oc_file ){
  1048. printf("\nNo Carrier FRU file is provided" \
  1049. " ---> No possible ekeying match!\n");
  1050. return_value = ERROR_STATUS;
  1051. }
  1052. else{
  1053. /*list des multi record*/
  1054. struct ipmi_ek_multi_header * list_head[argc];
  1055. struct ipmi_ek_multi_header * list_record[argc];
  1056. struct ipmi_ek_multi_header * list_last[argc];
  1057. struct ipmi_ek_multi_header * pcarrier_p2p;
  1058. int list = 0;
  1059. int match_pair = 0;
  1060. /*Create an empty list*/
  1061. for ( list=0; list<argc; list++ ){
  1062. list_head[list] = NULL;
  1063. list_record[list] = NULL;
  1064. list_last[list] = NULL;
  1065. }
  1066. list=0;
  1067. for ( num_file=0; num_file < argc; num_file++ ){
  1068. if (file_type[num_file] != CONFIG_FILE){
  1069. return_value = ipmi_ekanalyzer_fru_file2structure(
  1070. filename[num_file], &list_head[num_file],
  1071. &list_record[num_file], &list_last[num_file]);
  1072. }
  1073. }
  1074. /*Get Carrier p2p connectivity record for physical check*/
  1075. for (num_file=0; num_file < argc; num_file++){
  1076. if (file_type[num_file] == ON_CARRIER_FRU_FILE ){
  1077. for ( pcarrier_p2p=list_head[num_file];
  1078. pcarrier_p2p != NULL ;
  1079. pcarrier_p2p = pcarrier_p2p->next
  1080. ){
  1081. if ( pcarrier_p2p->data[PICMG_ID_OFFSET]
  1082. == FRU_AMC_CARRIER_P2P
  1083. ){
  1084. break;
  1085. }
  1086. }
  1087. break;
  1088. }
  1089. }
  1090. /*Determine the match making pair*/
  1091. while ( match_pair < argc ){
  1092. for ( num_file = (match_pair+1); num_file<argc; num_file++ ){
  1093. if ( ( file_type[match_pair] != CONFIG_FILE )
  1094. && ( file_type[num_file] != CONFIG_FILE )
  1095. ){
  1096. if ( ( file_type[match_pair] != ON_CARRIER_FRU_FILE )
  1097. || ( file_type[num_file] != ON_CARRIER_FRU_FILE )
  1098. ){
  1099. printf("%s vs %s\n",
  1100. val2str(file_type[match_pair],
  1101. ipmi_ekanalyzer_module_type),
  1102. val2str(file_type[num_file],
  1103. ipmi_ekanalyzer_module_type));
  1104. /*Ekeying match between 2 files*/
  1105. if (verbose>0){
  1106. printf("Start matching process\n");
  1107. }
  1108. return_value = ipmi_ek_matching_process( file_type,
  1109. match_pair, num_file, list_head,
  1110. list_last, opt, pcarrier_p2p);
  1111. }
  1112. }
  1113. }
  1114. match_pair ++;
  1115. }
  1116. for( num_file=0; num_file < argc; num_file++ ){
  1117. if (list_head[num_file] != NULL ){
  1118. ipmi_ek_remove_record_from_list( list_head[num_file],
  1119. &list_record[num_file], &list_last[num_file]);
  1120. }
  1121. if ( ( num_file == argc-1 ) && verbose )
  1122. printf("Record list has been removed successfully\n");
  1123. }
  1124. return_value = OK_STATUS;
  1125. }
  1126. }
  1127. }
  1128. return return_value;
  1129. }
  1130. /**************************************************************************
  1131. *
  1132. * Function name: ipmi_ek_matching_process
  1133. *
  1134. * Description: This function process the OEM check, Physical Connectivity check,
  1135. * and Link Descriptor comparison to do Ekeying match
  1136. *
  1137. * Restriction: None
  1138. *
  1139. * Input: file_type: a pointer that contain file type (on carrier file,
  1140. * a1 file, b1 file...)
  1141. * index1: position of the first record in the list of the record
  1142. * index2: position of the second record in the list of the record
  1143. * ipmi_ek_multi_header ** list_head: pointer to the header of a
  1144. * linked list that contain FRU multi record
  1145. * ipmi_ek_multi_header ** list_last: pointer to the tale of a
  1146. * linked list that contain FRU multi record
  1147. * opt: string that contain display option such as "match", "unmatch", or
  1148. * "all".
  1149. * pphysical: a pointer that contain a carrier p2p connectivity record
  1150. * to perform physical check
  1151. *
  1152. * Output: None
  1153. *
  1154. * Global: None
  1155. *
  1156. * Return: return OK_STATUS on success and ERROR_STATUS if the record doesn't
  1157. * exist.
  1158. *
  1159. ***************************************************************************/
  1160. static int ipmi_ek_matching_process( int * file_type, int index1, int index2,
  1161. struct ipmi_ek_multi_header ** list_head,
  1162. struct ipmi_ek_multi_header ** list_last, char * opt,
  1163. struct ipmi_ek_multi_header * pphysical )
  1164. {
  1165. int result = ERROR_STATUS;
  1166. struct ipmi_ek_multi_header * record;
  1167. int num_amc_record1 = 0;/*Number of AMC records in the first module*/
  1168. int num_amc_record2 = 0;/*Number of AMC records in the second module*/
  1169. /* Comparison between an On-Carrier and an AMC*/
  1170. if ( file_type[index2] == ON_CARRIER_FRU_FILE ){
  1171. int index_temp = 0;
  1172. index_temp = index1;
  1173. index1 = index2; /*index1 indicate on carrier*/
  1174. index2 = index_temp; /*index2 indcate an AMC*/
  1175. }
  1176. /*Calculate record size for Carrier file*/
  1177. for ( record=list_head[index1]; record != NULL;record = record->next ){
  1178. if ( record->data[PICMG_ID_OFFSET] == FRU_AMC_P2P ){
  1179. num_amc_record2++;
  1180. }
  1181. }
  1182. /*Calculate record size for amc file*/
  1183. for ( record=list_head[index2]; record != NULL;record = record->next){
  1184. if ( record->data[PICMG_ID_OFFSET] == FRU_AMC_P2P ){
  1185. num_amc_record1++;
  1186. }
  1187. }
  1188. if ( (num_amc_record1 > 0) && (num_amc_record2 > 0) ){
  1189. int index_record1 = 0;
  1190. int index_record2 = 0;
  1191. /* Multi records of AMC module */
  1192. struct ipmi_ek_amc_p2p_connectivity_record * amc_record1 = NULL;
  1193. /* Multi records of Carrier or an AMC module */
  1194. struct ipmi_ek_amc_p2p_connectivity_record * amc_record2 = NULL;
  1195. amc_record1 = malloc ( num_amc_record1 * \
  1196. sizeof(struct ipmi_ek_amc_p2p_connectivity_record));
  1197. amc_record2 = malloc ( num_amc_record2 * \
  1198. sizeof(struct ipmi_ek_amc_p2p_connectivity_record));
  1199. for (record=list_head[index2]; record != NULL;record = record->next){
  1200. if ( record->data[PICMG_ID_OFFSET] == FRU_AMC_P2P ){
  1201. result = ipmi_ek_create_amc_p2p_record( record,
  1202. &amc_record1[index_record1] );
  1203. if (result != ERROR_STATUS){
  1204. struct ipmi_ek_multi_header * current_record = NULL;
  1205. for ( current_record=list_head[index1];
  1206. current_record != NULL ;
  1207. current_record = current_record->next
  1208. ){
  1209. if ( current_record->data[PICMG_ID_OFFSET] == FRU_AMC_P2P ){
  1210. result = ipmi_ek_create_amc_p2p_record( current_record,
  1211. &amc_record2[index_record2] );
  1212. if ( result != ERROR_STATUS ){
  1213. if ( result == OK_STATUS ){
  1214. /*Compare Link descriptor*/
  1215. result = ipmi_ek_compare_link ( pphysical,
  1216. amc_record1[index_record1],
  1217. amc_record2[index_record2],
  1218. opt, file_type[index1], file_type[index2]);
  1219. }
  1220. index_record2++;
  1221. }
  1222. } /*end of FRU_AMC_P2P */
  1223. } /* end of for loop */
  1224. index_record1++;
  1225. }
  1226. }
  1227. }
  1228. free(amc_record1) ;
  1229. amc_record1 = NULL;
  1230. free(amc_record2) ;
  1231. amc_record2 = NULL;
  1232. }
  1233. else{
  1234. printf("No amc record is found!\n");
  1235. }
  1236. return result;
  1237. }
  1238. /**************************************************************************
  1239. *
  1240. * Function name: ipmi_ek_check_physical_connectivity
  1241. *
  1242. * Description: This function check for point to point connectivity between
  1243. * two modules by comparing each enable port in link descriptor
  1244. * with local and remote ports of port descriptor in
  1245. * carrier point-to-point connectivity record according to the
  1246. * corresponding file type ( a1, b1, b2...).
  1247. *
  1248. * Restriction: In order to perform physical check connectivity, it needs to
  1249. * compare between 2 AMC Modules, so the use of index ( 1 and 2 )
  1250. * can facilitate the comparison in this case.
  1251. *
  1252. * Input: record1: is an AMC p2p record for an AMC module
  1253. * record2 is an AMC p2p record for an On-Carrier record or an AMC module
  1254. * char* opt: option string that will tell if a matching result, unmatched
  1255. * result or all the results will be displayed.
  1256. * file_type1: indicates type of the first module
  1257. * file_type2: indicates type of the second module
  1258. *
  1259. * Output: None
  1260. *
  1261. * Global: None
  1262. *
  1263. * Return: return OK_STATUS if both link are matched, otherwise
  1264. * return ERROR_STATUS
  1265. *
  1266. ***************************************************************************/
  1267. static int
  1268. ipmi_ek_check_physical_connectivity(
  1269. struct ipmi_ek_amc_p2p_connectivity_record record1, int index1,
  1270. struct ipmi_ek_amc_p2p_connectivity_record record2, int index2,
  1271. struct ipmi_ek_multi_header * record,
  1272. int filetype1, int filetype2, char * option )
  1273. {
  1274. int return_status = OK_STATUS;
  1275. if ( record == NULL ){
  1276. printf("NO Carrier p2p connectivity !\n");
  1277. return_status = ERROR_STATUS;
  1278. }
  1279. else{
  1280. #define INVALID_AMC_SITE_NUMBER -1
  1281. int index = START_DATA_OFFSET;
  1282. int amc_site = INVALID_AMC_SITE_NUMBER;
  1283. struct fru_picmgext_carrier_p2p_record rsc_desc;
  1284. struct fru_picmgext_carrier_p2p_descriptor * port_desc = NULL;
  1285. /* Get the physical connectivity record */
  1286. while ( index < record->header.len ) {
  1287. rsc_desc.resource_id = record->data[index++];
  1288. rsc_desc.p2p_count = record->data[index++];
  1289. /* carrier p2p record starts with on-carrier device */
  1290. if ( (rsc_desc.resource_id == record1.rsc_id)
  1291. ||
  1292. (rsc_desc.resource_id == record2.rsc_id)
  1293. ){
  1294. if (rsc_desc.p2p_count <= 0){
  1295. printf("No p2p count\n");
  1296. return_status = ERROR_STATUS;
  1297. }
  1298. else{
  1299. port_desc = malloc ( rsc_desc.p2p_count *
  1300. sizeof(struct fru_picmgext_carrier_p2p_descriptor) );
  1301. index = ipmi_ek_get_resource_descriptor( rsc_desc.p2p_count,
  1302. index, port_desc, record );
  1303. amc_site = INVALID_AMC_SITE_NUMBER;
  1304. break;
  1305. }
  1306. }
  1307. else{ /* carrier p2p record starts with AMC module */
  1308. if (rsc_desc.resource_id == AMC_MODULE){
  1309. if (filetype1 != ON_CARRIER_FRU_FILE){
  1310. amc_site = filetype1;
  1311. }
  1312. else{
  1313. amc_site = filetype2;
  1314. }
  1315. }
  1316. else{
  1317. amc_site = rsc_desc.resource_id & 0x0f;
  1318. }
  1319. if ( amc_site > 0 ){
  1320. if ( (amc_site == filetype1) || (amc_site == filetype2) ){
  1321. port_desc = malloc ( rsc_desc.p2p_count *
  1322. sizeof(struct fru_picmgext_carrier_p2p_descriptor) );
  1323. index = ipmi_ek_get_resource_descriptor( rsc_desc.p2p_count,
  1324. index, port_desc, record );
  1325. break;
  1326. }
  1327. }
  1328. else{
  1329. return_status = ERROR_STATUS;
  1330. }
  1331. }
  1332. /*If the record doesn't contain the same AMC site number in command
  1333. * line, go to the next record
  1334. */
  1335. index += ( sizeof(struct fru_picmgext_carrier_p2p_descriptor) *
  1336. rsc_desc.p2p_count );
  1337. }
  1338. if ( (port_desc != NULL) && (return_status != ERROR_STATUS) ){
  1339. int j=0;
  1340. for ( j = 0; j < rsc_desc.p2p_count; j++ ){
  1341. /* Compare only enable channel descriptor */
  1342. if ( record1.ch_desc[index1].lane0port != DISABLE_PORT ){
  1343. /* matching result from channel descriptor comparison */
  1344. tboolean match_lane = FALSE;
  1345. match_lane = ipmi_ek_compare_channel_descriptor (
  1346. record1.ch_desc[index1], record2.ch_desc[index2],
  1347. port_desc, j, rsc_desc.resource_id );
  1348. if ( match_lane ){
  1349. if ( filetype1 != ON_CARRIER_FRU_FILE ){
  1350. if ( (
  1351. (filetype1 == (rsc_desc.resource_id & 0x0f))
  1352. &&
  1353. (filetype2 ==(port_desc[j].remote_resource_id &0x0f))
  1354. )
  1355. ||
  1356. (
  1357. (filetype2 == (rsc_desc.resource_id & 0x0f))
  1358. &&
  1359. (filetype1 ==(port_desc[j].remote_resource_id &0x0f))
  1360. )
  1361. ){
  1362. if ( ! (strcmp(option, "unmatch") == 0) ){
  1363. printf("%s port %d ==> %s port %d\n",
  1364. val2str(filetype2, ipmi_ekanalyzer_module_type),
  1365. record1.ch_desc[index1].lane0port,
  1366. val2str(filetype1, ipmi_ekanalyzer_module_type),
  1367. record2.ch_desc[index2].lane0port);
  1368. }
  1369. return_status = OK_STATUS;
  1370. break;
  1371. }
  1372. else{
  1373. if (verbose == LOG_DEBUG){
  1374. printf("No point 2 point connectivity\n");
  1375. }
  1376. return_status = ERROR_STATUS;
  1377. }
  1378. }
  1379. else{
  1380. if ( (record2.rsc_id == (rsc_desc.resource_id) )
  1381. &&
  1382. (filetype2 == (port_desc[j].remote_resource_id & 0x0f))
  1383. ){
  1384. if ( ! (strcmp(option, "unmatch") == 0) ){
  1385. printf("%s port %d ==> %s port %d\n",
  1386. val2str(filetype2, ipmi_ekanalyzer_module_type),
  1387. record1.ch_desc[index1].lane0port,
  1388. val2str(filetype1, ipmi_ekanalyzer_module_type),
  1389. record2.ch_desc[index2].lane0port);
  1390. }
  1391. return_status = OK_STATUS;
  1392. break;
  1393. }
  1394. else if ( (filetype2 == (rsc_desc.resource_id & 0x0f) )
  1395. &&
  1396. (record2.rsc_id == (port_desc[j].remote_resource_id))
  1397. ){
  1398. if ( ! (strcmp(option, "unmatch") == 0) ){
  1399. printf("%s port %d ==> %s %x port %d\n",
  1400. val2str(filetype2, ipmi_ekanalyzer_module_type),
  1401. record1.ch_desc[index1].lane0port,
  1402. val2str(filetype1, ipmi_ekanalyzer_module_type),
  1403. record2.rsc_id,record2.ch_desc[index2].lane0port);
  1404. }
  1405. return_status = OK_STATUS;
  1406. break;
  1407. }
  1408. else{
  1409. if (verbose == LOG_DEBUG){
  1410. printf("No point 2 point connectivity\n");
  1411. }
  1412. return_status = ERROR_STATUS;
  1413. }
  1414. }
  1415. }
  1416. else{
  1417. if (verbose == LOG_DEBUG){
  1418. printf("No point 2 point connectivity\n");
  1419. }
  1420. return_status = ERROR_STATUS;
  1421. }
  1422. }
  1423. else{ /*If the link is disable, the result is always true*/
  1424. return_status = OK_STATUS;
  1425. }
  1426. }
  1427. }
  1428. else{
  1429. if (verbose == LOG_WARN){
  1430. printf("Invalid Carrier p2p connectivity record\n");
  1431. }
  1432. return_status = ERROR_STATUS;
  1433. }
  1434. if (port_desc != NULL){
  1435. free(port_desc);
  1436. port_desc = NULL;
  1437. }
  1438. }
  1439. return return_status;
  1440. }
  1441. /**************************************************************************
  1442. *
  1443. * Function name: ipmi_ek_compare_link
  1444. *
  1445. * Description: This function compares link grouping id of each
  1446. * amc p2p connectiviy record
  1447. *
  1448. * Restriction: None
  1449. *
  1450. * Input: record1: is an AMC p2p record for an AMC module
  1451. * record2 is an AMC p2p record for an On-Carrier record or an AMC module
  1452. * char* opt: option string that will tell if a matching result, unmatched
  1453. * result or all the results will be displayed.
  1454. * file_type1: indicates type of the first module
  1455. * file_type2: indicates type of the second module
  1456. *
  1457. * Output: None
  1458. *
  1459. * Global: None
  1460. *
  1461. * Return: return 0 if both link are matched, otherwise return -1
  1462. *
  1463. ***************************************************************************/
  1464. static int
  1465. ipmi_ek_compare_link( struct ipmi_ek_multi_header * physic_record,
  1466. struct ipmi_ek_amc_p2p_connectivity_record record1,
  1467. struct ipmi_ek_amc_p2p_connectivity_record record2, char * opt,
  1468. int file_type1, int file_type2 )
  1469. {
  1470. int result = ERROR_STATUS;
  1471. int index1 = 0; /*index for AMC module*/
  1472. int index2 = 0; /*index for On-carrier type*/
  1473. record1.matching_result = malloc ( record1.link_desc_count * sizeof(int) );
  1474. record2.matching_result = malloc ( record2.link_desc_count * sizeof(int) );
  1475. /*Initialize all the matching_result to false*/
  1476. for( index2 = 0; index2 < record2.link_desc_count; index2++ ){
  1477. record2.matching_result[index2] = FALSE;
  1478. }
  1479. for( index1 = 0; index1 < record1.link_desc_count; index1++ ){
  1480. for( index2 = 0; index2 < record2.link_desc_count; index2++ ){
  1481. if( record1.link_desc[index1].group_id == 0 ){
  1482. if( record2.link_desc[index2].group_id == 0 ){
  1483. result = ipmi_ek_compare_link_descriptor(
  1484. record1, index1, record2, index2 );
  1485. if ( result == OK_STATUS ){
  1486. /*Calculate the index for Channel descriptor in function of
  1487. * link designator channel ID
  1488. */
  1489. /*first channel_id in the AMC Link descriptor of record1*/
  1490. static int flag_first_link1;
  1491. int index_ch_desc1; /*index of channel descriptor */
  1492. /*first channel_id in the AMC Link descriptor of record2*/
  1493. static int flag_first_link2;
  1494. int index_ch_desc2; /*index of channel descriptor*/
  1495. if (index1==0){ /*this indicate the first link is encounter*/
  1496. flag_first_link1 = record1.link_desc[index1].channel_id;
  1497. }
  1498. index_ch_desc1 = record1.link_desc[index1].channel_id -
  1499. flag_first_link1;
  1500. if (index2==0){
  1501. flag_first_link2 = record2.link_desc[index2].channel_id;
  1502. }
  1503. index_ch_desc2 = record2.link_desc[index2].channel_id -
  1504. flag_first_link2;
  1505. /*Check for physical connectivity for each link*/
  1506. result = ipmi_ek_check_physical_connectivity ( record1,
  1507. index_ch_desc1, record2, index_ch_desc2,
  1508. physic_record, file_type1, file_type2, opt );
  1509. if ( result == OK_STATUS ){
  1510. /*Display the result if option = match or all*/
  1511. if ( (strcmp( opt, "match" ) == 0)
  1512. || (strcmp( opt, "all" ) == 0)
  1513. || (strcmp( opt, "default" ) == 0)
  1514. ){
  1515. tboolean isOEMtype = FALSE;
  1516. printf(" Matching Result\n");
  1517. isOEMtype = ipmi_ek_display_link_descriptor( file_type1,
  1518. record2.rsc_id,
  1519. "From", record2.link_desc[index2]);
  1520. if (isOEMtype){
  1521. ipmi_ek_display_oem_guid (record2);
  1522. }
  1523. isOEMtype = ipmi_ek_display_link_descriptor( file_type2,
  1524. record1.rsc_id,
  1525. "To", record1.link_desc[index1] );
  1526. if (isOEMtype){
  1527. ipmi_ek_display_oem_guid (record1);
  1528. }
  1529. printf(" %s\n", STAR_LINE_LIMITER);
  1530. }
  1531. record2.matching_result[index2] = TRUE;
  1532. record1.matching_result[index1] = TRUE;
  1533. /*quit the fist loop since the match is found*/
  1534. index2 = record2.link_desc_count;
  1535. }
  1536. }
  1537. }
  1538. }
  1539. else { /*Link Grouping ID is non zero, Compare all link descriptor
  1540. * that has non-zero link grouping id together
  1541. */
  1542. if (record2.link_desc[index2].group_id != 0 ){
  1543. result = ipmi_ek_compare_link_descriptor(
  1544. record1, index1, record2, index2 );
  1545. if ( result == OK_STATUS ){
  1546. /*Calculate the index for Channel descriptor in function of
  1547. * link designator channel ID
  1548. */
  1549. /*first channel_id in the AMC Link descriptor of record1*/
  1550. static int flag_first_link1;
  1551. int index_ch_desc1; /*index of channel descriptor */
  1552. /*first channel_id in the AMC Link descriptor of record2*/
  1553. static int flag_first_link2;
  1554. int index_ch_desc2; /*index of channel descriptor*/
  1555. if (index1==0){ /*this indicate the first link is encounter*/
  1556. flag_first_link1 = record1.link_desc[index1].channel_id;
  1557. }
  1558. index_ch_desc1 = record1.link_desc[index1].channel_id -
  1559. flag_first_link1;
  1560. if (index2==0){
  1561. flag_first_link2 = record2.link_desc[index2].channel_id;
  1562. }
  1563. index_ch_desc2 = record2.link_desc[index2].channel_id -
  1564. flag_first_link2;
  1565. /*Check for physical connectivity for each link*/
  1566. result = ipmi_ek_check_physical_connectivity (
  1567. record1, index_ch_desc1, record2, index_ch_desc2,
  1568. physic_record, file_type1, file_type2, opt );
  1569. if ( result == OK_STATUS ){
  1570. if ( (strcmp( opt, "match" ) == 0)
  1571. || (strcmp( opt, "all" ) == 0)
  1572. || (strcmp( opt, "default" ) == 0)
  1573. ){
  1574. tboolean isOEMtype = FALSE;
  1575. printf(" Matching Result\n");
  1576. isOEMtype = ipmi_ek_display_link_descriptor( file_type1,
  1577. record2.rsc_id,
  1578. "From", record2.link_desc[index2] );
  1579. if ( isOEMtype ){
  1580. ipmi_ek_display_oem_guid (record2);
  1581. }
  1582. isOEMtype = ipmi_ek_display_link_descriptor( file_type2,
  1583. record1.rsc_id,
  1584. "To", record1.link_desc[index1] );
  1585. if (isOEMtype){
  1586. ipmi_ek_display_oem_guid (record1);
  1587. }
  1588. printf(" %s\n", STAR_LINE_LIMITER);
  1589. }
  1590. record2.matching_result[index2] = TRUE;
  1591. record1.matching_result[index1] = TRUE;
  1592. /*leave the fist loop since the match is found*/
  1593. index2 = record2.link_desc_count;
  1594. }
  1595. }
  1596. }
  1597. }
  1598. }
  1599. }
  1600. if ( (strcmp(opt, "unmatch") == 0) || (strcmp(opt, "all") == 0) ){
  1601. int isOEMtype = FALSE;
  1602. printf(" Unmatching result\n");
  1603. for (index1 = 0; index1 < record1.link_desc_count; index1++){
  1604. isOEMtype = ipmi_ek_display_link_descriptor( file_type2,
  1605. record1.rsc_id, "", record1.link_desc[index1] );
  1606. if ( isOEMtype ){
  1607. ipmi_ek_display_oem_guid (record1);
  1608. }
  1609. printf(" %s\n", STAR_LINE_LIMITER);
  1610. }
  1611. for ( index2 = 0; index2 < record2.link_desc_count; index2++){
  1612. if ( !record2.matching_result[index2] ){
  1613. isOEMtype = ipmi_ek_display_link_descriptor( file_type1,
  1614. record2.rsc_id, "", record2.link_desc[index2] );
  1615. if ( isOEMtype ){
  1616. ipmi_ek_display_oem_guid (record2);
  1617. }
  1618. printf(" %s\n", STAR_LINE_LIMITER);
  1619. }
  1620. }
  1621. }
  1622. free(record1.matching_result);
  1623. record1.matching_result = NULL;
  1624. free(record2.matching_result);
  1625. record2.matching_result = NULL;
  1626. return result;
  1627. }
  1628. /**************************************************************************
  1629. *
  1630. * Function name: ipmi_ek_compare_channel_descriptor
  1631. *
  1632. * Description: This function compares 2 channel descriptors of 2 AMC
  1633. * point-to-point connectivity records with port descriptor of
  1634. * carrier point-to-point connectivity record. The comparison is
  1635. * made between each enable port only.
  1636. *
  1637. * Restriction: Reference: AMC.0 specification:
  1638. * - Table 3-14 for port descriptor
  1639. * - Table 3-17 for channel descriptor
  1640. *
  1641. * Input: ch_desc1: first channel descriptor
  1642. * ch_desc2: second channel descriptor
  1643. * port_desc: a pointer that contain a list of port descriptor
  1644. * index_port: index of the port descriptor
  1645. * rsc_id: resource id that represents as local resource id in the
  1646. * resource descriptor table.
  1647. *
  1648. * Output: None
  1649. *
  1650. * Global: None
  1651. *
  1652. * Return: return TRUE if both channel descriptor are matched,
  1653. * or FALSE otherwise
  1654. *
  1655. ***************************************************************************/
  1656. static tboolean
  1657. ipmi_ek_compare_channel_descriptor(
  1658. struct fru_picmgext_amc_channel_desc_record ch_desc1,
  1659. struct fru_picmgext_amc_channel_desc_record ch_desc2,
  1660. struct fru_picmgext_carrier_p2p_descriptor * port_desc,
  1661. int index_port, unsigned char rsc_id )
  1662. {
  1663. tboolean match_lane = FALSE;
  1664. /* carrier p2p record start with AMC_MODULE as local port */
  1665. if ( (rsc_id & AMC_MODULE) == AMC_MODULE ){
  1666. if ( (ch_desc1.lane0port == port_desc[index_port].local_port)
  1667. &&
  1668. (ch_desc2.lane0port == port_desc[index_port].remote_port)
  1669. ){
  1670. /*check if the port is enable*/
  1671. if (ch_desc1.lane1port != DISABLE_PORT){
  1672. index_port ++;
  1673. if ( (ch_desc1.lane1port == port_desc[index_port].local_port)
  1674. &&
  1675. (ch_desc2.lane1port == port_desc[index_port].remote_port)
  1676. ){
  1677. if (ch_desc1.lane2port != DISABLE_PORT){
  1678. index_port++;
  1679. if ( (ch_desc1.lane2port == port_desc[index_port].local_port)
  1680. &&
  1681. (ch_desc2.lane2port == port_desc[index_port].remote_port)
  1682. ){
  1683. if (ch_desc1.lane3port != DISABLE_PORT){
  1684. index_port++;
  1685. if ( (ch_desc1.lane3port ==
  1686. port_desc[index_port].local_port)
  1687. &&
  1688. (ch_desc2.lane3port ==
  1689. port_desc[index_port].remote_port)
  1690. ){
  1691. match_lane = TRUE;
  1692. }
  1693. }
  1694. else{
  1695. match_lane = TRUE;
  1696. }
  1697. } /* end of if lane2port */
  1698. }
  1699. else{
  1700. match_lane = TRUE;
  1701. }
  1702. } /* end of if lane1port */
  1703. }
  1704. else{ /*if the port is disable, the compare result is always true*/
  1705. match_lane = TRUE;
  1706. }
  1707. }/* end of if lane0port */
  1708. }
  1709. /* carrier p2p record start with Carrier as local port */
  1710. else{
  1711. if ( (ch_desc1.lane0port == port_desc[index_port].remote_port)
  1712. &&
  1713. (ch_desc2.lane0port == port_desc[index_port].local_port)
  1714. ){
  1715. if (ch_desc1.lane1port != DISABLE_PORT){
  1716. index_port ++;
  1717. if ( (ch_desc1.lane1port == port_desc[index_port].remote_port)
  1718. &&
  1719. (ch_desc2.lane1port == port_desc[index_port].local_port)
  1720. ){
  1721. if (ch_desc1.lane2port != DISABLE_PORT){
  1722. index_port++;
  1723. if ( (ch_desc1.lane2port == port_desc[index_port].remote_port)
  1724. &&
  1725. (ch_desc2.lane2port == port_desc[index_port].local_port)
  1726. ){
  1727. if (ch_desc1.lane3port != DISABLE_PORT){
  1728. index_port++;
  1729. if ( (ch_desc1.lane3port ==
  1730. port_desc[index_port].remote_port)
  1731. &&
  1732. (ch_desc2.lane3port ==
  1733. port_desc[index_port].local_port)
  1734. ){
  1735. match_lane = TRUE;
  1736. }
  1737. }
  1738. else{
  1739. match_lane = TRUE;
  1740. }
  1741. } /* end of if lane2port */
  1742. }
  1743. else{
  1744. match_lane = TRUE;
  1745. }
  1746. } /* end of if lane1port */
  1747. }
  1748. else{
  1749. match_lane = TRUE;
  1750. }
  1751. } /* end of if lane0port */
  1752. }
  1753. return match_lane;
  1754. }
  1755. /**************************************************************************
  1756. *
  1757. * Function name: ipmi_ek_compare_link_descriptor
  1758. *
  1759. * Description: This function compares 2 link descriptors of 2
  1760. * amc p2p connectiviy record
  1761. *
  1762. * Restriction: None
  1763. *
  1764. * Input: record1: AMC p2p connectivity record of the 1rst AMC or Carrier Module
  1765. * index1: index of AMC link descriptor in 1rst record
  1766. * record2: AMC p2p connectivity record of the 2nd AMC or Carrier Module
  1767. * index1: index of AMC link descriptor in 2nd record
  1768. *
  1769. * Output: None
  1770. *
  1771. * Global: None
  1772. *
  1773. * Return: return OK_STATUS if both link are matched,
  1774. * otherwise return ERROR_STATUS
  1775. *
  1776. ***************************************************************************/
  1777. static int
  1778. ipmi_ek_compare_link_descriptor(
  1779. struct ipmi_ek_amc_p2p_connectivity_record record1,
  1780. int index1,
  1781. struct ipmi_ek_amc_p2p_connectivity_record record2,
  1782. int index2)
  1783. {
  1784. int result = ERROR_STATUS;
  1785. if (record1.link_desc[index1].type != record2.link_desc[index2].type) {
  1786. return ERROR_STATUS;
  1787. }
  1788. /* if it is an OEM type, we compare the OEM GUID */
  1789. if ((record1.link_desc[index1].type >= LOWER_OEM_TYPE)
  1790. && (record1.link_desc[index1].type <= UPPER_OEM_TYPE)) {
  1791. if ((record1.guid_count == 0) && (record2.guid_count == 0)) {
  1792. /*there is no GUID for comparison, so the result is always OK*/
  1793. result = OK_STATUS;
  1794. } else {
  1795. int i = 0;
  1796. int j = 0;
  1797. for (i = 0; i < record1.guid_count; i++) {
  1798. for (j = 0; j < record2.guid_count; j++) {
  1799. if (memcmp(&record1.oem_guid[i],
  1800. &record2.oem_guid[j],
  1801. SIZE_OF_GUID) == 0) {
  1802. result = OK_STATUS;
  1803. break;
  1804. }
  1805. }
  1806. }
  1807. }
  1808. } else {
  1809. result = OK_STATUS;
  1810. }
  1811. if (result != OK_STATUS) {
  1812. return result;
  1813. }
  1814. if (record1.link_desc[index1].type_ext == record2.link_desc[index2].type_ext) {
  1815. unsigned char asym[COMPARE_CANDIDATE];
  1816. int offset = 0;
  1817. asym[offset++] = record1.link_desc[index1].asym_match;
  1818. asym[offset] = record2.link_desc[index2].asym_match;
  1819. result = ipmi_ek_compare_asym (asym);
  1820. if (result == OK_STATUS){
  1821. struct fru_picmgext_amc_link_desc_record link[COMPARE_CANDIDATE];
  1822. int index = 0;
  1823. link[index++] = record1.link_desc[index1];
  1824. link[index] = record2.link_desc[index2];
  1825. result = ipmi_ek_compare_number_of_enable_port(link);
  1826. } else {
  1827. result = ERROR_STATUS;
  1828. }
  1829. } else {
  1830. result = ERROR_STATUS;
  1831. }
  1832. return result;
  1833. }
  1834. /**************************************************************************
  1835. *
  1836. * Function name: ipmi_ek_compare_asym
  1837. *
  1838. * Description: This function compares 2 asymetric match of 2
  1839. * amc link descriptors
  1840. *
  1841. * Restriction: None
  1842. *
  1843. * Input: asym[COMPARE_CANDIDATE]: Contain 2 asymetric match for comparison
  1844. *
  1845. * Output: None
  1846. *
  1847. * Global: None
  1848. *
  1849. * Return: return 0 if both asym. match are matched, otherwise return -1
  1850. *
  1851. ***************************************************************************/
  1852. static int
  1853. ipmi_ek_compare_asym(unsigned char asym[COMPARE_CANDIDATE])
  1854. {
  1855. int return_value = ERROR_STATUS;
  1856. int first_index = 0;
  1857. int second_index = 1;
  1858. if ((asym[first_index] == 0) && (asym[second_index] == 0)) {
  1859. return_value = OK_STATUS;
  1860. } else if ((asym[first_index] & asym[second_index]) == 0) {
  1861. return_value = OK_STATUS;
  1862. } else {
  1863. return_value = ERROR_STATUS;
  1864. }
  1865. return return_value;
  1866. }
  1867. /**************************************************************************
  1868. *
  1869. * Function name: ipmi_ek_compare_link_descriptor
  1870. *
  1871. * Description: This function compare number of enble port of Link designator
  1872. *
  1873. * Restriction: None
  1874. *
  1875. * Input: link_designator1: first link designator
  1876. * link_designator2: second link designator
  1877. *
  1878. * Output: None
  1879. *
  1880. * Global: None
  1881. *
  1882. * Return: return 0 if both link are matched, otherwise return -1
  1883. *
  1884. ***************************************************************************/
  1885. static int
  1886. ipmi_ek_compare_number_of_enable_port(
  1887. struct fru_picmgext_amc_link_desc_record link_desc[COMPARE_CANDIDATE])
  1888. {
  1889. int amc_port_count = 0;
  1890. int carrier_port_count = 0;
  1891. int return_value = ERROR_STATUS;
  1892. int index = 0;
  1893. if (link_desc[index].port_flag_0) {
  1894. /*bit 0 indicates port 0*/
  1895. amc_port_count++;
  1896. }
  1897. if (link_desc[index].port_flag_1) {
  1898. /*bit 1 indicates port 1*/
  1899. amc_port_count++;
  1900. }
  1901. if (link_desc[index].port_flag_2) {
  1902. /*bit 2 indicates port 2*/
  1903. amc_port_count++;
  1904. }
  1905. if (link_desc[index++].port_flag_3) {
  1906. /*bit 3 indicates port 3*/
  1907. amc_port_count++;
  1908. }
  1909. /* 2nd link designator */
  1910. if (link_desc[index].port_flag_0) {
  1911. /*bit 0 indicates port 0*/
  1912. carrier_port_count++;
  1913. }
  1914. if (link_desc[index].port_flag_1) {
  1915. /*bit 1 indicates port 1*/
  1916. carrier_port_count++;
  1917. }
  1918. if (link_desc[index].port_flag_2) {
  1919. /*bit 2 indicates port 2*/
  1920. carrier_port_count++;
  1921. }
  1922. if (link_desc[index].port_flag_3) {
  1923. /*bit 3 indicates port 3*/
  1924. carrier_port_count++;
  1925. }
  1926. if (carrier_port_count == amc_port_count) {
  1927. return_value = OK_STATUS;
  1928. } else {
  1929. return_value = ERROR_STATUS;
  1930. }
  1931. return return_value;
  1932. }
  1933. /**************************************************************************
  1934. *
  1935. * Function name: ipmi_ek_display_link_descriptor
  1936. *
  1937. * Description: Display the link descriptor of an AMC p2p connectivity record
  1938. *
  1939. * Restriction: See AMC.0 or PICMG 3.0 specification for detail about bit masks
  1940. *
  1941. * Input: file_type: module type.
  1942. * rsc_id: resource id
  1943. * char* str: indicates if it is a source (its value= "From") or a
  1944. * destination (its value = "To"). ( it is set to "" if it is not
  1945. * a source nor destination
  1946. * link_desc: AMC link descriptor
  1947. * asym: asymetric match
  1948. *
  1949. * Output: None
  1950. *
  1951. * Global: None
  1952. *
  1953. * Return: None
  1954. *
  1955. ***************************************************************************/
  1956. static tboolean
  1957. ipmi_ek_display_link_descriptor(int file_type, unsigned char rsc_id,
  1958. char *str,
  1959. struct fru_picmgext_amc_link_desc_record link_desc)
  1960. {
  1961. tboolean isOEMtype = FALSE;
  1962. if (file_type == ON_CARRIER_FRU_FILE) {
  1963. printf(" - %s On-Carrier Device ID %d\n", str,
  1964. (rsc_id & 0x0f));
  1965. } else {
  1966. printf(" - %s %s\n", str, val2str(file_type,
  1967. ipmi_ekanalyzer_module_type));
  1968. }
  1969. printf(" - Channel ID %d || ", link_desc.channel_id);
  1970. printf("%s", link_desc.port_flag_0 ? "Lane 0: enable" : "");
  1971. printf("%s", link_desc.port_flag_1 ? ", Lane 1: enable" : "");
  1972. printf("%s", link_desc.port_flag_2 ? ", Lane 2: enable" : "");
  1973. printf("%s", link_desc.port_flag_3 ? ", Lane 3: enable" : "");
  1974. printf("\n");
  1975. printf(" - Link Type: %s \n", val2str(link_desc.type,
  1976. ipmi_ekanalyzer_link_type));
  1977. switch (link_desc.type) {
  1978. case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE:
  1979. case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE_AS1:
  1980. case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE_AS2:
  1981. printf(" - Link Type extension: %s\n",
  1982. val2str(link_desc.type_ext,
  1983. ipmi_ekanalyzer_extension_PCIE));
  1984. printf(" - Link Group ID: %d || ", link_desc.group_id);
  1985. printf("Link Asym. Match: %d - %s\n",
  1986. link_desc.asym_match,
  1987. val2str(link_desc.asym_match,
  1988. ipmi_ekanalyzer_asym_PCIE));
  1989. break;
  1990. case FRU_PICMGEXT_AMC_LINK_TYPE_ETHERNET:
  1991. printf(" - Link Type extension: %s\n",
  1992. val2str(link_desc.type_ext,
  1993. ipmi_ekanalyzer_extension_ETHERNET));
  1994. printf(" - Link Group ID: %d || ", link_desc.group_id);
  1995. printf("Link Asym. Match: %d - %s\n",
  1996. link_desc.asym_match,
  1997. val2str(link_desc.asym_match,
  1998. ipmi_ekanalyzer_asym_PCIE));
  1999. break;
  2000. case FRU_PICMGEXT_AMC_LINK_TYPE_STORAGE:
  2001. printf(" - Link Type extension: %s\n",
  2002. val2str(link_desc.type_ext,
  2003. ipmi_ekanalyzer_extension_STORAGE));
  2004. printf(" - Link Group ID: %d || ",
  2005. link_desc.group_id);
  2006. printf("Link Asym. Match: %d - %s\n",
  2007. link_desc.asym_match,
  2008. val2str(link_desc.asym_match,
  2009. ipmi_ekanalyzer_asym_STORAGE));
  2010. break;
  2011. default:
  2012. printf(" - Link Type extension: %i\n",
  2013. link_desc.type_ext);
  2014. printf(" - Link Group ID: %d || ",
  2015. link_desc.group_id);
  2016. printf("Link Asym. Match: %i\n",
  2017. link_desc.asym_match);
  2018. break;
  2019. }
  2020. /* return as OEM type if link type indicates OEM */
  2021. if ((link_desc.type >= LOWER_OEM_TYPE)
  2022. && (link_desc.type <= UPPER_OEM_TYPE)) {
  2023. isOEMtype = TRUE;
  2024. }
  2025. return isOEMtype;
  2026. }
  2027. /**************************************************************************
  2028. *
  2029. * Function name: ipmi_ek_display_oem_guid
  2030. *
  2031. * Description: Display the oem guid of an AMC p2p connectivity record
  2032. *
  2033. * Restriction: None
  2034. *
  2035. * Input: amc_record: AMC p2p connectivity record
  2036. *
  2037. * Output: None
  2038. *
  2039. * Global: None
  2040. *
  2041. * Return: None
  2042. *
  2043. ***************************************************************************/
  2044. static void
  2045. ipmi_ek_display_oem_guid(struct ipmi_ek_amc_p2p_connectivity_record amc_record)
  2046. {
  2047. int index_oem = 0;
  2048. int index = 0;
  2049. if (amc_record.guid_count == 0) {
  2050. printf("\tThere is no OEM GUID for this module\n");
  2051. }
  2052. for (index_oem = 0; index_oem < amc_record.guid_count; index_oem++) {
  2053. printf(" - GUID: ");
  2054. for (index = 0; index < SIZE_OF_GUID; index++) {
  2055. printf("%02x",
  2056. amc_record.oem_guid[index_oem].guid[index]);
  2057. /* For a better look: putting a "-" after displaying
  2058. * four bytes of GUID
  2059. */
  2060. if (!(index % 4)){
  2061. printf("-");
  2062. }
  2063. }
  2064. printf("\n");
  2065. }
  2066. }
  2067. /**************************************************************************
  2068. *
  2069. * Function name: ipmi_ek_create_amc_p2p_record
  2070. *
  2071. * Description: this function create an AMC point 2 point connectivity record
  2072. * that contain link descriptor, channel descriptor, oem guid
  2073. *
  2074. * Restriction: Reference: AMC.0 Specification Table 3-16
  2075. *
  2076. * Input: record: a pointer to FRU multi record
  2077. *
  2078. * Output: amc_record: a pointer to the created AMC p2p record
  2079. *
  2080. * Global: None
  2081. *
  2082. * Return: Return OK_STATUS on success, or ERROR_STATUS if no record has been
  2083. * created.
  2084. *
  2085. ***************************************************************************/
  2086. static int
  2087. ipmi_ek_create_amc_p2p_record(struct ipmi_ek_multi_header *record,
  2088. struct ipmi_ek_amc_p2p_connectivity_record *amc_record)
  2089. {
  2090. int index_data = START_DATA_OFFSET;
  2091. int return_status = OK_STATUS;
  2092. amc_record->guid_count = record->data[index_data++];
  2093. if (amc_record->guid_count > 0) {
  2094. int index_oem = 0;
  2095. amc_record->oem_guid = malloc(amc_record->guid_count * \
  2096. sizeof(struct fru_picmgext_guid));
  2097. if (amc_record->oem_guid == NULL) {
  2098. return ERROR_STATUS;
  2099. }
  2100. for (index_oem = 0; index_oem < amc_record->guid_count;
  2101. index_oem++) {
  2102. memcpy(&amc_record->oem_guid[index_oem].guid,
  2103. &record->data[index_data],
  2104. SIZE_OF_GUID);
  2105. index_data += (int)SIZE_OF_GUID;
  2106. }
  2107. amc_record->rsc_id = record->data[index_data++];
  2108. amc_record->ch_count = record->data[index_data++];
  2109. /* Calculate link descriptor count */
  2110. amc_record->link_desc_count = ((record->header.len) - 8 -
  2111. (SIZE_OF_GUID*amc_record->guid_count) -
  2112. (FRU_PICMGEXT_AMC_CHANNEL_DESC_RECORD_SIZE *
  2113. amc_record->ch_count)) / 5 ;
  2114. } else {
  2115. amc_record->rsc_id = record->data[index_data++];
  2116. amc_record->ch_count = record->data[index_data++];
  2117. /* Calculate link descriptor count see spec AMC.0 for detail */
  2118. amc_record->link_desc_count = ((record->header.len) - 8 -
  2119. (FRU_PICMGEXT_AMC_CHANNEL_DESC_RECORD_SIZE *
  2120. amc_record->ch_count)) / 5;
  2121. }
  2122. if (amc_record->ch_count > 0) {
  2123. int ch_index = 0;
  2124. amc_record->ch_desc = malloc((amc_record->ch_count) * \
  2125. sizeof(struct fru_picmgext_amc_channel_desc_record));
  2126. if (amc_record->ch_desc == NULL) {
  2127. return ERROR_STATUS;
  2128. }
  2129. for (ch_index = 0; ch_index < amc_record->ch_count;
  2130. ch_index++) {
  2131. unsigned int data;
  2132. struct fru_picmgext_amc_channel_desc_record *src, *dst;
  2133. data = record->data[index_data] |
  2134. (record->data[index_data + 1] << 8) |
  2135. (record->data[index_data + 2] << 16);
  2136. src = (struct fru_picmgext_amc_channel_desc_record *)&data;
  2137. dst = (struct fru_picmgext_amc_channel_desc_record *)
  2138. &amc_record->ch_desc[ch_index];
  2139. dst->lane0port = src->lane0port;
  2140. dst->lane1port = src->lane1port;
  2141. dst->lane2port = src->lane2port;
  2142. dst->lane3port = src->lane3port;
  2143. index_data += FRU_PICMGEXT_AMC_CHANNEL_DESC_RECORD_SIZE;
  2144. }
  2145. }
  2146. if (amc_record->link_desc_count > 0) {
  2147. int i=0;
  2148. amc_record->link_desc = malloc(amc_record->link_desc_count * \
  2149. sizeof(struct fru_picmgext_amc_link_desc_record));
  2150. if (amc_record->link_desc == NULL) {
  2151. return ERROR_STATUS;
  2152. }
  2153. for (i = 0; i< amc_record->link_desc_count; i++) {
  2154. unsigned int data[2];
  2155. struct fru_picmgext_amc_link_desc_record *src, *dst;
  2156. data[0] = record->data[index_data] |
  2157. (record->data[index_data + 1] << 8) |
  2158. (record->data[index_data + 2] << 16) |
  2159. (record->data[index_data + 3] << 24);
  2160. data[1] = record->data[index_data + 4];
  2161. src = (struct fru_picmgext_amc_link_desc_record*)&data;
  2162. dst = (struct fru_picmgext_amc_link_desc_record*)
  2163. &amc_record->link_desc[i];
  2164. dst->channel_id = src->channel_id;
  2165. dst->port_flag_0 = src->port_flag_0;
  2166. dst->port_flag_1 = src->port_flag_1;
  2167. dst->port_flag_2 = src->port_flag_2;
  2168. dst->port_flag_3 = src->port_flag_3;
  2169. dst->type = src->type;
  2170. dst->type_ext = src->type_ext;
  2171. dst->group_id = src->group_id;
  2172. dst->asym_match = src->asym_match;
  2173. index_data += FRU_PICMGEXT_AMC_LINK_DESC_RECORD_SIZE;
  2174. }
  2175. } else {
  2176. return_status = ERROR_STATUS;
  2177. }
  2178. return return_status;
  2179. }
  2180. /**************************************************************************
  2181. *
  2182. * Function name: ipmi_ek_get_resource_descriptor
  2183. *
  2184. * Description: this function create the resource descriptor of Carrier p2p
  2185. * connectivity record.
  2186. *
  2187. * Restriction: None
  2188. *
  2189. * Input: port_count: number of port count
  2190. * index: index to the position of data start offset
  2191. * record: a pointer to FRU multi record
  2192. *
  2193. * Output: port_desc: a pointer to the created resource descriptor
  2194. *
  2195. * Global: None
  2196. *
  2197. * Return: Return index that indicates the current position of data in record.
  2198. *
  2199. ***************************************************************************/
  2200. static int
  2201. ipmi_ek_get_resource_descriptor(int port_count, int index,
  2202. struct fru_picmgext_carrier_p2p_descriptor *port_desc,
  2203. struct ipmi_ek_multi_header *record)
  2204. {
  2205. int num_port = 0;
  2206. while (num_port < port_count) {
  2207. memcpy(&port_desc[num_port], &record->data[index],
  2208. sizeof (struct fru_picmgext_carrier_p2p_descriptor));
  2209. index += sizeof (struct fru_picmgext_carrier_p2p_descriptor);
  2210. num_port++;
  2211. }
  2212. return index;
  2213. }
  2214. /**************************************************************************
  2215. *
  2216. * Function name: ipmi_ek_display_fru_header
  2217. *
  2218. * Description: this function display FRU header offset from a FRU binary file
  2219. *
  2220. * Restriction: Reference: IPMI Platform Management FRU Information Storage
  2221. * Definition V1.0, Section 8
  2222. *
  2223. * Input: filename: name of FRU binary file
  2224. *
  2225. * Output: None
  2226. *
  2227. * Global: None
  2228. *
  2229. * Return: Return OK_STATUS on sucess, ERROR_STATUS on error
  2230. *
  2231. ***************************************************************************/
  2232. static int
  2233. ipmi_ek_display_fru_header(char *filename)
  2234. {
  2235. FILE *input_file;
  2236. struct fru_header header;
  2237. int ret = 0;
  2238. input_file = fopen(filename, "r");
  2239. if (input_file == NULL) {
  2240. lprintf(LOG_ERR, "File '%s' not found.", filename);
  2241. return (ERROR_STATUS);
  2242. }
  2243. ret = fread(&header, sizeof (struct fru_header), 1, input_file);
  2244. if ((ret != 1) || ferror(input_file)) {
  2245. lprintf(LOG_ERR, "Failed to read FRU header!");
  2246. fclose(input_file);
  2247. return (ERROR_STATUS);
  2248. }
  2249. printf("%s\n", EQUAL_LINE_LIMITER);
  2250. printf("FRU Header Info\n");
  2251. printf("%s\n", EQUAL_LINE_LIMITER);
  2252. printf("Format Version :0x%02x %s\n",
  2253. (header.version & 0x0f),
  2254. ((header.version & 0x0f) == 1) ? "" : "{unsupported}");
  2255. printf("Internal Use Offset :0x%02x\n", header.offset.internal);
  2256. printf("Chassis Info Offset :0x%02x\n", header.offset.chassis);
  2257. printf("Board Info Offset :0x%02x\n", header.offset.board);
  2258. printf("Product Info Offset :0x%02x\n", header.offset.product);
  2259. printf("MultiRecord Offset :0x%02x\n", header.offset.multi);
  2260. printf("Common header Checksum :0x%02x\n", header.checksum);
  2261. fclose(input_file);
  2262. return OK_STATUS;
  2263. }
  2264. /**************************************************************************
  2265. *
  2266. * Function name: ipmi_ek_display_fru_header_detail
  2267. *
  2268. * Description: this function display detail FRU header information
  2269. * from a FRU binary file.
  2270. *
  2271. * Restriction: Reference: IPMI Platform Management FRU Information Storage
  2272. * Definition V1.0, Section 8
  2273. *
  2274. * Input: filename: name of FRU binary file
  2275. *
  2276. * Output: None
  2277. *
  2278. * Global: None
  2279. *
  2280. * Return: None
  2281. *
  2282. ***************************************************************************/
  2283. static int
  2284. ipmi_ek_display_fru_header_detail(char *filename)
  2285. {
  2286. # define FACTOR_OFFSET 8
  2287. # define SIZE_MFG_DATE 3
  2288. FILE *input_file;
  2289. size_t file_offset = 0;
  2290. struct fru_header header;
  2291. time_t tval;
  2292. int ret = 0;
  2293. unsigned char data = 0;
  2294. unsigned char lan_code = 0;
  2295. unsigned char mfg_date[SIZE_MFG_DATE];
  2296. unsigned int board_length = 0;
  2297. input_file = fopen(filename, "r");
  2298. if (input_file == NULL) {
  2299. lprintf(LOG_ERR, "File '%s' not found.", filename);
  2300. return (-1);
  2301. }
  2302. /* The offset in each fru is in multiple of 8 bytes
  2303. * See IPMI Platform Management FRU Information Storage Definition
  2304. * for detail
  2305. */
  2306. ret = fread(&header, sizeof(struct fru_header), 1, input_file);
  2307. if ((ret != 1) || ferror(input_file)) {
  2308. lprintf(LOG_ERR, "Failed to read FRU header!");
  2309. fclose(input_file);
  2310. return (-1);
  2311. }
  2312. /*** Display FRU Internal Use Info ***/
  2313. if (header.offset.internal != 0) {
  2314. unsigned char format_version;
  2315. unsigned long len = 0;
  2316. printf("%s\n", EQUAL_LINE_LIMITER);
  2317. printf("FRU Internal Use Info\n");
  2318. printf("%s\n", EQUAL_LINE_LIMITER);
  2319. ret = fread(&format_version, 1, 1, input_file);
  2320. if ((ret != 1) || ferror(input_file)) {
  2321. lprintf(LOG_ERR, "Invalid format version!");
  2322. fclose(input_file);
  2323. return (-1);
  2324. }
  2325. printf("Format Version: %d\n", (format_version & 0x0f));
  2326. if (header.offset.chassis > 0) {
  2327. len = (header.offset.chassis * FACTOR_OFFSET)
  2328. - (header.offset.internal * FACTOR_OFFSET);
  2329. } else {
  2330. len = (header.offset.board * FACTOR_OFFSET)
  2331. - (header.offset.internal * FACTOR_OFFSET);
  2332. }
  2333. printf("Length: %ld\n", len);
  2334. printf("Data dump:\n");
  2335. while ((len > 0) && (!feof(input_file))) {
  2336. unsigned char data;
  2337. ret = fread(&data, 1, 1, input_file);
  2338. if ((ret != 1) || ferror(input_file)) {
  2339. lprintf(LOG_ERR, "Invalid data!");
  2340. fclose(input_file);
  2341. return (-1);
  2342. }
  2343. printf("0x%02x ", data);
  2344. len--;
  2345. }
  2346. printf("\n");
  2347. }
  2348. /*** Chassis Info Area ***/
  2349. if (header.offset.chassis != 0) {
  2350. long offset = 0;
  2351. offset = header.offset.chassis * FACTOR_OFFSET;
  2352. ret = ipmi_ek_display_chassis_info_area(input_file, offset);
  2353. }
  2354. /*** Display FRU Board Info Area ***/
  2355. while (1) {
  2356. if (header.offset.board == 0) {
  2357. break;
  2358. }
  2359. ret = fseek(input_file,
  2360. (header.offset.board * FACTOR_OFFSET),
  2361. SEEK_SET);
  2362. if (feof(input_file)) {
  2363. break;
  2364. }
  2365. file_offset = ftell(input_file);
  2366. printf("%s\n", EQUAL_LINE_LIMITER);
  2367. printf("FRU Board Info Area\n");
  2368. printf("%s\n", EQUAL_LINE_LIMITER);
  2369. ret = fread(&data, 1, 1, input_file); /* Format version */
  2370. if ((ret != 1) || ferror(input_file)) {
  2371. lprintf(LOG_ERR, "Invalid FRU Format Version!");
  2372. fclose(input_file);
  2373. return (-1);
  2374. }
  2375. printf("Format Version: %d\n", (data & 0x0f));
  2376. if (feof(input_file)) {
  2377. break;
  2378. }
  2379. ret = fread(&data, 1, 1, input_file); /* Board Area Length */
  2380. if ((ret != 1) || ferror(input_file)) {
  2381. lprintf(LOG_ERR, "Invalid Board Area Length!");
  2382. fclose(input_file);
  2383. return (-1);
  2384. }
  2385. board_length = (data * FACTOR_OFFSET);
  2386. printf("Area Length: %d\n", board_length);
  2387. /* Decrease the length of board area by 1 byte of format version
  2388. * and 1 byte for area length itself. the rest of this length will
  2389. * be used to check for additional custom mfg. byte
  2390. */
  2391. board_length -= 2;
  2392. if (feof(input_file)) {
  2393. break;
  2394. }
  2395. ret = fread(&lan_code, 1, 1, input_file); /* Language Code */
  2396. if ((ret != 1) || ferror(input_file)) {
  2397. lprintf(LOG_ERR, "Invalid Language Code in input");
  2398. fclose(input_file);
  2399. return (-1);
  2400. }
  2401. printf("Language Code: %d\n", lan_code);
  2402. board_length--;
  2403. /* Board Mfg Date */
  2404. if (feof(input_file)) {
  2405. break;
  2406. }
  2407. ret = fread(mfg_date, SIZE_MFG_DATE, 1, input_file);
  2408. if (ret != 1) {
  2409. lprintf(LOG_ERR, "Invalid Board Data.");
  2410. fclose(input_file);
  2411. return (-1);
  2412. }
  2413. tval = ((mfg_date[2] << 16) + (mfg_date[1] << 8)
  2414. + (mfg_date[0]));
  2415. tval = tval * 60;
  2416. tval = tval + secs_from_1970_1996;
  2417. printf("Board Mfg Date: %ld, %s", tval,
  2418. asctime(localtime(&tval)));
  2419. board_length -= SIZE_MFG_DATE;
  2420. /* Board Mfg */
  2421. file_offset = ipmi_ek_display_board_info_area(
  2422. input_file, "Board Manufacture Data", &board_length);
  2423. ret = fseek(input_file, file_offset, SEEK_SET);
  2424. /* Board Product */
  2425. file_offset = ipmi_ek_display_board_info_area(
  2426. input_file, "Board Product Name", &board_length);
  2427. ret = fseek(input_file, file_offset, SEEK_SET);
  2428. /* Board Serial */
  2429. file_offset = ipmi_ek_display_board_info_area(
  2430. input_file, "Board Serial Number", &board_length);
  2431. ret = fseek(input_file, file_offset, SEEK_SET);
  2432. /* Board Part */
  2433. file_offset = ipmi_ek_display_board_info_area(
  2434. input_file, "Board Part Number", &board_length);
  2435. ret = fseek(input_file, file_offset, SEEK_SET);
  2436. /* FRU file ID */
  2437. file_offset = ipmi_ek_display_board_info_area(
  2438. input_file, "FRU File ID", &board_length);
  2439. ret = fseek(input_file, file_offset, SEEK_SET);
  2440. /* Additional Custom Mfg. */
  2441. file_offset = ipmi_ek_display_board_info_area(
  2442. input_file, "Custom", &board_length);
  2443. break;
  2444. }
  2445. /* Product Info Area */
  2446. if (header.offset.product && (!feof(input_file))) {
  2447. long offset = 0;
  2448. offset = header.offset.product * FACTOR_OFFSET;
  2449. ret = ipmi_ek_display_product_info_area(input_file,
  2450. offset);
  2451. }
  2452. fclose(input_file);
  2453. return 0;
  2454. }
  2455. /**************************************************************************
  2456. *
  2457. * Function name: ipmi_ek_display_chassis_info_area
  2458. *
  2459. * Description: this function displays detail format of product info area record
  2460. * into humain readable text format
  2461. *
  2462. * Restriction: Reference: IPMI Platform Management FRU Information Storage
  2463. * Definition V1.0, Section 10
  2464. *
  2465. * Input: input_file: pointer to file stream
  2466. * offset: start offset of chassis info area
  2467. *
  2468. * Output: None
  2469. *
  2470. * Global: None
  2471. *
  2472. * Return: None
  2473. *
  2474. ***************************************************************************/
  2475. static int
  2476. ipmi_ek_display_chassis_info_area(FILE *input_file, long offset)
  2477. {
  2478. size_t file_offset;
  2479. int ret = 0;
  2480. unsigned char data = 0;
  2481. unsigned char ch_len = 0;
  2482. unsigned char ch_type = 0;
  2483. unsigned int len;
  2484. if (input_file == NULL) {
  2485. lprintf(LOG_ERR, "No file stream to read.");
  2486. return (-1);
  2487. }
  2488. printf("%s\n", EQUAL_LINE_LIMITER);
  2489. printf("Chassis Info Area\n");
  2490. printf("%s\n", EQUAL_LINE_LIMITER);
  2491. ret = fseek(input_file, offset, SEEK_SET);
  2492. if (feof(input_file)) {
  2493. lprintf(LOG_ERR, "Invalid Chassis Info Area!");
  2494. return (-1);
  2495. }
  2496. ret = fread(&data, 1, 1, input_file);
  2497. if ((ret != 1) || ferror(input_file)) {
  2498. lprintf(LOG_ERR, "Invalid Version Number!");
  2499. return (-1);
  2500. }
  2501. printf("Format Version Number: %d\n", (data & 0x0f));
  2502. ret = fread(&ch_len, 1, 1, input_file);
  2503. if ((ret != 1) || ferror(input_file)) {
  2504. lprintf(LOG_ERR, "Invalid length!");
  2505. return (-1);
  2506. }
  2507. /* len is in factor of 8 bytes */
  2508. len = ch_len * 8;
  2509. printf("Area Length: %d\n", len);
  2510. len -= 2;
  2511. if (feof(input_file)) {
  2512. return (-1);
  2513. }
  2514. /* Chassis Type*/
  2515. ret = fread(&ch_type, 1, 1, input_file);
  2516. if ((ret != 1) || ferror(input_file)) {
  2517. lprintf(LOG_ERR, "Invalid Chassis Type!");
  2518. return (-1);
  2519. }
  2520. printf("Chassis Type: %d\n", ch_type);
  2521. len--;
  2522. /* Chassis Part Number*/
  2523. file_offset = ipmi_ek_display_board_info_area(input_file,
  2524. "Chassis Part Number", &len);
  2525. ret = fseek(input_file, file_offset, SEEK_SET);
  2526. /* Chassis Serial */
  2527. file_offset = ipmi_ek_display_board_info_area(input_file,
  2528. "Chassis Serial Number", &len);
  2529. ret = fseek(input_file, file_offset, SEEK_SET);
  2530. /* Custom product info area */
  2531. file_offset = ipmi_ek_display_board_info_area(input_file,
  2532. "Custom", &len);
  2533. return 0;
  2534. }
  2535. /**************************************************************************
  2536. *
  2537. * Function name: ipmi_ek_display_board_info_area
  2538. *
  2539. * Description: this function displays board info area depending on board type
  2540. * that pass in argument. Board type can be:
  2541. * Manufacturer, Serial, Product or Part...
  2542. *
  2543. * Restriction: IPMI Platform Management FRU Information Storage
  2544. * Definition V1.0, Section 11
  2545. *
  2546. * Input: input_file: pointer to file stream
  2547. * board_type: a string that contain board type
  2548. * board_length: length of info area
  2549. *
  2550. * Output: None
  2551. *
  2552. * Global: None
  2553. *
  2554. * Return: the current position of input_file
  2555. *
  2556. ***************************************************************************/
  2557. static size_t
  2558. ipmi_ek_display_board_info_area(FILE *input_file, char *board_type,
  2559. unsigned int *board_length)
  2560. {
  2561. size_t file_offset;
  2562. int ret = 0;
  2563. unsigned char len = 0;
  2564. unsigned int size_board = 0;
  2565. if (input_file == NULL || board_type == NULL
  2566. || board_length == NULL) {
  2567. return (size_t)(-1);
  2568. }
  2569. file_offset = ftell(input_file);
  2570. /* Board length*/
  2571. ret = fread(&len, 1, 1, input_file);
  2572. if ((ret != 1) || ferror(input_file)) {
  2573. lprintf(LOG_ERR, "Invalid Length!");
  2574. goto out;
  2575. }
  2576. (*board_length)--;
  2577. /* Bit 5:0 of Board Mfg type represent legnth */
  2578. size_board = (len & 0x3f);
  2579. if (size_board == 0) {
  2580. printf("%s: None\n", board_type);
  2581. goto out;
  2582. }
  2583. if (strncmp(board_type, "Custom", 6 ) != 0) {
  2584. unsigned char *data;
  2585. unsigned int i = 0;
  2586. data = malloc(size_board);
  2587. if (data == NULL) {
  2588. lprintf(LOG_ERR, "ipmitool: malloc failure");
  2589. return (size_t)(-1);
  2590. }
  2591. ret = fread(data, size_board, 1, input_file);
  2592. if ((ret != 1) || ferror(input_file)) {
  2593. lprintf(LOG_ERR, "Invalid board type size!");
  2594. free(data);
  2595. data = NULL;
  2596. goto out;
  2597. }
  2598. printf("%s type: 0x%02x\n", board_type, len);
  2599. printf("%s: ", board_type);
  2600. for (i = 0; i < size_board; i++) {
  2601. if ((len & TYPE_CODE) == TYPE_CODE) {
  2602. printf("%c", data[i]);
  2603. } else {
  2604. /* other than language code (binary, BCD,
  2605. * ASCII 6 bit...) is not supported
  2606. */
  2607. printf("%02x", data[i]);
  2608. }
  2609. }
  2610. printf("\n");
  2611. free(data);
  2612. data = NULL;
  2613. (*board_length) -= size_board;
  2614. goto out;
  2615. }
  2616. while (!feof(input_file)) {
  2617. if (len == NO_MORE_INFO_FIELD) {
  2618. unsigned char padding;
  2619. unsigned char checksum = 0;
  2620. /* take the rest of data in the area minus 1 byte of
  2621. * checksum
  2622. */
  2623. printf("Additional Custom Mfg. length: 0x%02x\n", len);
  2624. padding = (*board_length) - 1;
  2625. if ((padding > 0) && (!feof(input_file))) {
  2626. printf("Unused space: %d (bytes)\n", padding);
  2627. fseek(input_file, padding, SEEK_CUR);
  2628. }
  2629. ret = fread(&checksum, 1, 1, input_file);
  2630. if ((ret != 1) || ferror(input_file)) {
  2631. lprintf(LOG_ERR, "Invalid Checksum!");
  2632. goto out;
  2633. }
  2634. printf("Checksum: 0x%02x\n", checksum);
  2635. goto out;
  2636. }
  2637. printf("Additional Custom Mfg. length: 0x%02x\n", len);
  2638. if ((size_board > 0) && (size_board < (*board_length))) {
  2639. unsigned char * additional_data = NULL;
  2640. unsigned int i = 0;
  2641. additional_data = malloc(size_board);
  2642. if (additional_data == NULL) {
  2643. lprintf(LOG_ERR, "ipmitool: malloc failure");
  2644. return (size_t)(-1);
  2645. }
  2646. ret = fread(additional_data, size_board, 1, input_file);
  2647. if ((ret != 1) || ferror(input_file)) {
  2648. lprintf(LOG_ERR, "Invalid Additional Data!");
  2649. if (additional_data != NULL) {
  2650. free(additional_data);
  2651. additional_data = NULL;
  2652. }
  2653. goto out;
  2654. }
  2655. printf("Additional Custom Mfg. Data: %02x",
  2656. additional_data[0]);
  2657. for (i = 1; i < size_board; i++) {
  2658. printf("-%02x", additional_data[i]);
  2659. }
  2660. printf("\n");
  2661. free(additional_data);
  2662. additional_data = NULL;
  2663. (*board_length) -= size_board;
  2664. }
  2665. else {
  2666. printf("No Additional Custom Mfg. %d\n", *board_length);
  2667. goto out;
  2668. }
  2669. }
  2670. out:
  2671. file_offset = ftell(input_file);
  2672. return file_offset;
  2673. }
  2674. /**************************************************************************
  2675. *
  2676. * Function name: ipmi_ek_display_product_info_area
  2677. *
  2678. * Description: this function displays detail format of product info area record
  2679. * into humain readable text format
  2680. *
  2681. * Restriction: Reference: IPMI Platform Management FRU Information Storage
  2682. * Definition V1.0, Section 12
  2683. *
  2684. * Input: input_file: pointer to file stream
  2685. * offset: start offset of product info area
  2686. *
  2687. * Output: None
  2688. *
  2689. * Global: None
  2690. *
  2691. * Return: None
  2692. *
  2693. ***************************************************************************/
  2694. static int
  2695. ipmi_ek_display_product_info_area(FILE *input_file, long offset)
  2696. {
  2697. size_t file_offset;
  2698. int ret = 0;
  2699. unsigned char ch_len = 0;
  2700. unsigned char data = 0;
  2701. unsigned int len = 0;
  2702. if (input_file == NULL) {
  2703. lprintf(LOG_ERR, "No file stream to read.");
  2704. return (-1);
  2705. }
  2706. file_offset = ftell(input_file);
  2707. printf("%s\n", EQUAL_LINE_LIMITER);
  2708. printf("Product Info Area\n");
  2709. printf("%s\n", EQUAL_LINE_LIMITER);
  2710. ret = fseek(input_file, offset, SEEK_SET);
  2711. if (feof(input_file)) {
  2712. lprintf(LOG_ERR, "Invalid Product Info Area!");
  2713. return (-1);
  2714. }
  2715. ret = fread(&data, 1, 1, input_file);
  2716. if ((ret != 1) || ferror(input_file)) {
  2717. lprintf(LOG_ERR, "Invalid Data!");
  2718. return (-1);
  2719. }
  2720. printf("Format Version Number: %d\n", (data & 0x0f));
  2721. if (feof(input_file)) {
  2722. return (-1);
  2723. }
  2724. /* Have to read this into a char or else
  2725. * it ends up byte swapped on big endian machines */
  2726. ret = fread(&ch_len, 1, 1, input_file);
  2727. if ((ret != 1) || ferror(input_file)) {
  2728. lprintf(LOG_ERR, "Invalid Length!");
  2729. return (-1);
  2730. }
  2731. /* length is in factor of 8 bytes */
  2732. len = ch_len * 8;
  2733. printf("Area Length: %d\n", len);
  2734. len -= 2; /* -1 byte of format version and -1 byte itself */
  2735. ret = fread(&data, 1, 1, input_file);
  2736. if ((ret != 1) || ferror(input_file)) {
  2737. lprintf(LOG_ERR, "Invalid Length!");
  2738. return (-1);
  2739. }
  2740. printf("Language Code: %d\n", data);
  2741. len--;
  2742. /* Product Mfg */
  2743. file_offset = ipmi_ek_display_board_info_area(input_file,
  2744. "Product Manufacture Data", &len);
  2745. ret = fseek(input_file, file_offset, SEEK_SET);
  2746. /* Product Name */
  2747. file_offset = ipmi_ek_display_board_info_area(input_file,
  2748. "Product Name", &len);
  2749. ret = fseek(input_file, file_offset, SEEK_SET);
  2750. /* Product Part */
  2751. file_offset = ipmi_ek_display_board_info_area(input_file,
  2752. "Product Part/Model Number", &len);
  2753. ret = fseek(input_file, file_offset, SEEK_SET);
  2754. /* Product Version */
  2755. file_offset = ipmi_ek_display_board_info_area(input_file,
  2756. "Product Version", &len);
  2757. ret = fseek(input_file, file_offset, SEEK_SET);
  2758. /* Product Serial */
  2759. file_offset = ipmi_ek_display_board_info_area(input_file,
  2760. "Product Serial Number", &len);
  2761. ret = fseek(input_file, file_offset, SEEK_SET);
  2762. /* Product Asset Tag */
  2763. file_offset = ipmi_ek_display_board_info_area(input_file,
  2764. "Asset Tag", &len);
  2765. ret = fseek(input_file, file_offset, SEEK_SET);
  2766. /* FRU file ID */
  2767. file_offset = ipmi_ek_display_board_info_area(input_file,
  2768. "FRU File ID", &len);
  2769. ret = fseek(input_file, file_offset, SEEK_SET);
  2770. /* Custom product info area */
  2771. file_offset = ipmi_ek_display_board_info_area(input_file,
  2772. "Custom", &len);
  2773. return 0;
  2774. }
  2775. /**************************************************************************
  2776. *
  2777. * Function name: ipmi_ek_display_record
  2778. *
  2779. * Description: this function displays FRU multi record information.
  2780. *
  2781. * Restriction: None
  2782. *
  2783. * Input: record: a pointer to current record
  2784. * list_head: a pointer to header of the list
  2785. * list_last: a pointer to tale of the list
  2786. *
  2787. * Output: None
  2788. *
  2789. * Global: None
  2790. *
  2791. * Return: None
  2792. *
  2793. ***************************************************************************/
  2794. static void
  2795. ipmi_ek_display_record(struct ipmi_ek_multi_header *record,
  2796. struct ipmi_ek_multi_header *list_head,
  2797. struct ipmi_ek_multi_header *list_last)
  2798. {
  2799. if (list_head == NULL) {
  2800. printf("***empty list***\n");
  2801. return;
  2802. }
  2803. printf("%s\n", EQUAL_LINE_LIMITER);
  2804. printf("FRU Multi Info area\n");
  2805. printf("%s\n", EQUAL_LINE_LIMITER);
  2806. for (record = list_head; record != NULL; record = record->next) {
  2807. printf("Record Type ID: 0x%02x\n", record->header.type);
  2808. printf("Record Format version: 0x%02x\n",
  2809. record->header.format);
  2810. if (record->header.len <= PICMG_ID_OFFSET) {
  2811. continue;
  2812. }
  2813. /* In picmg3.0 specification, picmg record
  2814. * id lower than 4 or greater than 0x2d
  2815. * isn't supported
  2816. */
  2817. #define PICMG_ID_LOWER_LIMIT 0x04
  2818. #define PICMG_ID_UPPER_LIMIT 0x2d
  2819. unsigned char picmg_id;
  2820. picmg_id = record->data[PICMG_ID_OFFSET];
  2821. printf("Manufacturer ID: %02x%02x%02x h\n",
  2822. record->data[2], record->data[1],
  2823. record->data[0]);
  2824. if ((picmg_id < PICMG_ID_LOWER_LIMIT)
  2825. || (picmg_id > PICMG_ID_UPPER_LIMIT)) {
  2826. printf("Picmg record ID: Unsupported {0x%02x}\n", picmg_id);
  2827. } else {
  2828. printf("Picmg record ID: %s {0x%02x}\n",
  2829. val2str(picmg_id, ipmi_ekanalyzer_picmg_record_id),
  2830. picmg_id);
  2831. }
  2832. switch (picmg_id) {
  2833. case FRU_PICMG_BACKPLANE_P2P: /*0x04*/
  2834. ipmi_ek_display_backplane_p2p_record (record);
  2835. break;
  2836. case FRU_PICMG_ADDRESS_TABLE: /*0x10*/
  2837. ipmi_ek_display_address_table_record (record);
  2838. break;
  2839. case FRU_PICMG_SHELF_POWER_DIST: /*0x11*/
  2840. ipmi_ek_display_shelf_power_distribution_record (record);
  2841. break;
  2842. case FRU_PICMG_SHELF_ACTIVATION: /*/0x12*/
  2843. ipmi_ek_display_shelf_activation_record (record);
  2844. break;
  2845. case FRU_PICMG_SHMC_IP_CONN: /*0x13*/
  2846. ipmi_ek_display_shelf_ip_connection_record (record);
  2847. break;
  2848. case FRU_PICMG_BOARD_P2P: /*0x14*/
  2849. ipmi_ek_display_board_p2p_record (record);
  2850. break;
  2851. case FRU_RADIAL_IPMB0_LINK_MAPPING: /*0x15*/
  2852. ipmi_ek_display_radial_ipmb0_record (record);
  2853. break;
  2854. case FRU_AMC_CURRENT: /*0x16*/
  2855. ipmi_ek_display_amc_current_record (record);
  2856. break;
  2857. case FRU_AMC_ACTIVATION: /*0x17*/
  2858. ipmi_ek_display_amc_activation_record (record);
  2859. break;
  2860. case FRU_AMC_CARRIER_P2P: /*0x18*/
  2861. ipmi_ek_display_carrier_connectivity (record);
  2862. break;
  2863. case FRU_AMC_P2P: /*0x19*/
  2864. ipmi_ek_display_amc_p2p_record (record);
  2865. break;
  2866. case FRU_AMC_CARRIER_INFO: /*0x1a*/
  2867. ipmi_ek_display_amc_carrier_info_record (record);
  2868. break;
  2869. case FRU_PICMG_CLK_CARRIER_P2P: /*0x2c*/
  2870. ipmi_ek_display_clock_carrier_p2p_record (record);
  2871. break;
  2872. case FRU_PICMG_CLK_CONFIG: /*0x2d*/
  2873. ipmi_ek_display_clock_config_record (record);
  2874. break;
  2875. default:
  2876. if (verbose > 0) {
  2877. int i;
  2878. printf("%02x %02x %02x %02x %02x ",
  2879. record->header.type,
  2880. record->header.format,
  2881. record->header.len,
  2882. record->header.record_checksum,
  2883. record->header.header_checksum);
  2884. for (i = 0; i < record->header.len; i++) {
  2885. printf("%02x ", record->data[i]);
  2886. }
  2887. printf("\n");
  2888. }
  2889. break;
  2890. }
  2891. printf("%s\n", STAR_LINE_LIMITER);
  2892. }
  2893. }
  2894. /**************************************************************************
  2895. *
  2896. * Function name: ipmi_ek_display_backplane_p2p_record
  2897. *
  2898. * Description: this function displays backplane p2p record.
  2899. *
  2900. * Restriction: Reference: PICMG 3.0 Specification Table 3-40
  2901. *
  2902. * Input: record: a pointer to current record to be displayed
  2903. *
  2904. * Output: None
  2905. *
  2906. * Global: None
  2907. *
  2908. * Return: None
  2909. *
  2910. ***************************************************************************/
  2911. static void
  2912. ipmi_ek_display_backplane_p2p_record(struct ipmi_ek_multi_header *record)
  2913. {
  2914. uint8_t index;
  2915. int offset = START_DATA_OFFSET;
  2916. struct fru_picmgext_slot_desc *slot_d =
  2917. (struct fru_picmgext_slot_desc*)&record->data[offset];
  2918. offset += sizeof(struct fru_picmgext_slot_desc);
  2919. while (offset <= record->header.len) {
  2920. printf(" Channel Type: ");
  2921. switch (slot_d->chan_type) {
  2922. case 0x00:
  2923. case 0x07:
  2924. printf("PICMG 2.9\n");
  2925. break;
  2926. case 0x08:
  2927. printf("Single Port Fabric IF\n");
  2928. break;
  2929. case 0x09:
  2930. printf("Double Port Fabric IF\n");
  2931. break;
  2932. case 0x0a:
  2933. printf("Full Channel Fabric IF\n");
  2934. break;
  2935. case 0x0b:
  2936. printf("Base IF\n");
  2937. break;
  2938. case 0x0c:
  2939. printf("Update Channel IF\n");
  2940. break;
  2941. default:
  2942. printf("Unknown IF\n");
  2943. break;
  2944. }
  2945. printf(" Slot Address: %02x\n", slot_d->slot_addr);
  2946. printf(" Channel Count: %i\n", slot_d->chn_count);
  2947. for (index = 0; index < (slot_d->chn_count); index++) {
  2948. struct fru_picmgext_chn_desc *d =
  2949. (struct fru_picmgext_chn_desc *)&record->data[offset];
  2950. if (verbose) {
  2951. printf("\t"
  2952. "Chn: %02x --> "
  2953. "Chn: %02x in "
  2954. "Slot: %02x\n",
  2955. d->local_chn,
  2956. d->remote_chn,
  2957. d->remote_slot);
  2958. }
  2959. offset += sizeof(struct fru_picmgext_chn_desc);
  2960. }
  2961. slot_d = (struct fru_picmgext_slot_desc*)&record->data[offset];
  2962. offset += sizeof(struct fru_picmgext_slot_desc);
  2963. }
  2964. }
  2965. /**************************************************************************
  2966. *
  2967. * Function name: ipmi_ek_display_address_table_record
  2968. *
  2969. * Description: this function displays address table record.
  2970. *
  2971. * Restriction: Reference: PICMG 3.0 Specification Table 3-6
  2972. *
  2973. * Input: record: a pointer to current record to be displayed
  2974. *
  2975. * Output: None
  2976. *
  2977. * Global: None
  2978. *
  2979. * Return: None
  2980. *
  2981. ***************************************************************************/
  2982. static void
  2983. ipmi_ek_display_address_table_record(struct ipmi_ek_multi_header *record)
  2984. {
  2985. #define SIZE_SHELF_ADDRESS_BYTE 20
  2986. unsigned char entries = 0;
  2987. unsigned char i;
  2988. int offset = START_DATA_OFFSET;
  2989. printf(" Type/Len: 0x%02x\n", record->data[offset++]);
  2990. printf(" Shelf Addr: ");
  2991. for (i = 0; i < SIZE_SHELF_ADDRESS_BYTE; i++) {
  2992. printf("0x%02x ", record->data[offset++]);
  2993. }
  2994. printf("\n");
  2995. entries = record->data[offset++];
  2996. printf(" Addr Table Entries count: 0x%02x\n", entries);
  2997. for (i = 0; i < entries; i++) {
  2998. printf("\tHWAddr: 0x%02x - SiteNum: 0x%02x - SiteType: 0x%02x \n",
  2999. record->data[offset+0],
  3000. record->data[offset+1],
  3001. record->data[offset+2]);
  3002. offset += 3;
  3003. }
  3004. }
  3005. /**************************************************************************
  3006. *
  3007. * Function name: ipmi_ek_display_shelf_power_distribution_record
  3008. *
  3009. * Description: this function displays shelf power distribution record.
  3010. *
  3011. * Restriction: Reference: PICMG 3.0 Specification Table 3-70
  3012. *
  3013. * Input: record: a pointer to current record to be displayed
  3014. *
  3015. * Output: None
  3016. *
  3017. * Global: None
  3018. *
  3019. * Return: None
  3020. *
  3021. ***************************************************************************/
  3022. static void
  3023. ipmi_ek_display_shelf_power_distribution_record(
  3024. struct ipmi_ek_multi_header *record)
  3025. {
  3026. int offset = START_DATA_OFFSET;
  3027. unsigned char i;
  3028. unsigned char j;
  3029. unsigned char feeds = 0;
  3030. feeds = record->data[offset++];
  3031. printf(" Number of Power Feeds: 0x%02x\n", feeds);
  3032. for (i = 0; i < feeds; i++) {
  3033. unsigned char entries;
  3034. unsigned long max_ext = 0;
  3035. unsigned long max_int = 0;
  3036. max_ext = record->data[offset+0]
  3037. | (record->data[offset+1] << 8);
  3038. printf(" Max External Available Current: %ld Amps\n",
  3039. (max_ext * 10));
  3040. offset += 2;
  3041. max_int = record->data[offset+0]
  3042. | (record->data[offset+1] << 8);
  3043. printf(" Max Internal Current:\t %ld Amps\n",
  3044. (max_int * 10));
  3045. offset += 2;
  3046. printf(" Min Expected Operating Voltage: %d Volts\n",
  3047. (record->data[offset++] / 2));
  3048. entries = record->data[offset++];
  3049. printf(" Feed to FRU count: 0x%02x\n", entries);
  3050. for (j = 0; j < entries; j++) {
  3051. printf("\tHW: 0x%02x", record->data[offset++]);
  3052. printf("\tFRU ID: 0x%02x\n", record->data[offset++]);
  3053. }
  3054. }
  3055. }
  3056. /**************************************************************************
  3057. *
  3058. * Function name: ipmi_ek_display_shelf_activation_record
  3059. *
  3060. * Description: this function displays shelf activation record.
  3061. *
  3062. * Restriction: Reference: PICMG 3.0 Specification Table 3-73
  3063. *
  3064. * Input: record: a pointer to current record to be displayed
  3065. *
  3066. * Output: None
  3067. *
  3068. * Global: None
  3069. *
  3070. * Return: None
  3071. *
  3072. ***************************************************************************/
  3073. static void
  3074. ipmi_ek_display_shelf_activation_record(struct ipmi_ek_multi_header *record)
  3075. {
  3076. unsigned char count = 0;
  3077. int offset = START_DATA_OFFSET;
  3078. printf(" Allowance for FRU Act Readiness: 0x%02x\n",
  3079. record->data[offset++]);
  3080. count = record->data[offset++];
  3081. printf(" FRU activation and Power Desc Cnt: 0x%02x\n", count);
  3082. while (count > 0) {
  3083. printf(" FRU activation and Power descriptor:\n");
  3084. printf("\tHardware Address:\t\t0x%02x\n",
  3085. record->data[offset++]);
  3086. printf("\tFRU Device ID:\t\t\t0x%02x\n",
  3087. record->data[offset++]);
  3088. printf("\tMax FRU Power Capability:\t0x%04x Watts\n",
  3089. (record->data[offset+0]
  3090. | (record->data[offset+1]<<8)));
  3091. offset += 2;
  3092. printf("\tConfiguration parameter:\t0x%02x\n",
  3093. record->data[offset++]);
  3094. count --;
  3095. }
  3096. }
  3097. /**************************************************************************
  3098. *
  3099. * Function name: ipmi_ek_display_shelf_ip_connection_record
  3100. *
  3101. * Description: this function displays shelf ip connection record.
  3102. *
  3103. * Restriction: Fix me: Don't test yet
  3104. * Reference: PICMG 3.0 Specification Table 3-31
  3105. *
  3106. * Input: record: a pointer to current record to be displayed
  3107. *
  3108. * Output: None
  3109. *
  3110. * Global: None
  3111. *
  3112. * Return: None
  3113. *
  3114. ***************************************************************************/
  3115. static void
  3116. ipmi_ek_display_shelf_ip_connection_record(struct ipmi_ek_multi_header *record)
  3117. {
  3118. int ioffset = START_DATA_OFFSET;
  3119. if (ioffset > record->header.len) {
  3120. printf(" Shelf Manager IP Address: %d.%d.%d.%d\n",
  3121. record->data[ioffset+0],
  3122. record->data[ioffset+1],
  3123. record->data[ioffset+2],
  3124. record->data[ioffset+3]);
  3125. ioffset += 4;
  3126. }
  3127. if (ioffset > record->header.len) {
  3128. printf(" Default Gateway Address: %d.%d.%d.%d\n",
  3129. record->data[ioffset+0],
  3130. record->data[ioffset+1],
  3131. record->data[ioffset+2],
  3132. record->data[ioffset+3]);
  3133. ioffset += 4;
  3134. }
  3135. if (ioffset > record->header.len) {
  3136. printf(" Subnet Mask: %d.%d.%d.%d\n",
  3137. record->data[ioffset+0],
  3138. record->data[ioffset+1],
  3139. record->data[ioffset+2],
  3140. record->data[ioffset+3]);
  3141. ioffset += 4;
  3142. }
  3143. }
  3144. /**************************************************************************
  3145. *
  3146. * Function name: ipmi_ek_display_shelf_fan_geography_record
  3147. *
  3148. * Description: this function displays shelf fan geography record.
  3149. *
  3150. * Restriction: Fix me: Don't test yet
  3151. * Reference: PICMG 3.0 Specification Table 3-75
  3152. *
  3153. * Input: record: a pointer to current record to be displayed
  3154. *
  3155. * Output: None
  3156. *
  3157. * Global: None
  3158. *
  3159. * Return: None
  3160. *
  3161. ***************************************************************************/
  3162. static void
  3163. ipmi_ek_display_shelf_fan_geography_record(struct ipmi_ek_multi_header *record)
  3164. {
  3165. int ioffset = START_DATA_OFFSET;
  3166. unsigned char fan_count = 0;
  3167. fan_count = record->data[ioffset];
  3168. ioffset++;
  3169. printf(" Fan-to-FRU Entry Count: 0x%02x\n", fan_count);
  3170. while ((fan_count > 0) && (ioffset <= record->header.len)) {
  3171. printf(" Fan-to-FRU Mapping Entry: {%2x%2x%2x%2x}\n",
  3172. record->data[ioffset],
  3173. record->data[ioffset+1],
  3174. record->data[ioffset+2],
  3175. record->data[ioffset+3]);
  3176. printf(" Hardware Address: 0x%02x\n",
  3177. record->data[ioffset++]);
  3178. printf(" FRU device ID: 0x%02x\n",
  3179. record->data[ioffset++]);
  3180. printf(" Site Number: 0x%02x\n",
  3181. record->data[ioffset++]);
  3182. printf(" Site Type: 0x%02x\n",
  3183. record->data[ioffset++]);
  3184. fan_count --;
  3185. }
  3186. }
  3187. /**************************************************************************
  3188. *
  3189. * Function name: ipmi_ek_display_board_p2p_record
  3190. *
  3191. * Description: this function displays board pont-to-point record.
  3192. *
  3193. * Restriction: Reference: PICMG 3.0 Specification Table 3-44
  3194. *
  3195. * Input: record: a pointer to current record to be displayed
  3196. *
  3197. * Output: None
  3198. *
  3199. * Global: None
  3200. *
  3201. * Return: None
  3202. *
  3203. ***************************************************************************/
  3204. static void
  3205. ipmi_ek_display_board_p2p_record(struct ipmi_ek_multi_header *record)
  3206. {
  3207. unsigned char guid_count;
  3208. int offset = START_DATA_OFFSET;
  3209. int i = 0;
  3210. guid_count = record->data[offset++];
  3211. printf(" GUID count: %2d\n", guid_count);
  3212. for (i = 0 ; i < guid_count; i++) {
  3213. int j;
  3214. printf("\tGUID: ");
  3215. for (j = 0; j < sizeof(struct fru_picmgext_guid); j++) {
  3216. printf("%02x", record->data[offset+j]);
  3217. }
  3218. printf("\n");
  3219. offset += sizeof(struct fru_picmgext_guid);
  3220. }
  3221. for (offset = offset;
  3222. offset < record->header.len;
  3223. offset += sizeof(struct fru_picmgext_link_desc)) {
  3224. /* to solve little endian/big endian problem */
  3225. unsigned long data;
  3226. struct fru_picmgext_link_desc * d;
  3227. data = (record->data[offset+0])
  3228. | (record->data[offset+1] << 8)\
  3229. | (record->data[offset+2] << 16)\
  3230. | (record->data[offset+3] << 24);
  3231. d = (struct fru_picmgext_link_desc *)&data;
  3232. printf(" Link Descriptor\n");
  3233. printf("\tLink Grouping ID:\t0x%02x\n", d->grouping);
  3234. printf("\tLink Type Extension:\t0x%02x - ", d->ext);
  3235. if (d->type == FRU_PICMGEXT_LINK_TYPE_BASE) {
  3236. switch (d->ext) {
  3237. case 0:
  3238. printf("10/100/1000BASE-T Link (four-pair)\n");
  3239. break;
  3240. case 1:
  3241. printf("ShMC Cross-connect (two-pair)\n");
  3242. break;
  3243. default:
  3244. printf("Unknwon\n");
  3245. break;
  3246. }
  3247. } else if (d->type == FRU_PICMGEXT_LINK_TYPE_FABRIC_ETHERNET) {
  3248. switch (d->ext) {
  3249. case 0:
  3250. printf("Fixed 1000Base-BX\n");
  3251. break;
  3252. case 1:
  3253. printf("Fixed 10GBASE-BX4 [XAUI]\n");
  3254. break;
  3255. case 2:
  3256. printf("FC-PI\n");
  3257. break;
  3258. default:
  3259. printf("Unknwon\n");
  3260. break;
  3261. }
  3262. } else if (d->type == FRU_PICMGEXT_LINK_TYPE_FABRIC_INFINIBAND) {
  3263. printf("Unknwon\n");
  3264. } else if (d->type == FRU_PICMGEXT_LINK_TYPE_FABRIC_STAR) {
  3265. printf("Unknwon\n");
  3266. } else if (d->type == FRU_PICMGEXT_LINK_TYPE_PCIE) {
  3267. printf("Unknwon\n");
  3268. } else {
  3269. printf("Unknwon\n");
  3270. }
  3271. printf("\tLink Type:\t\t0x%02x - ", d->type);
  3272. if (d->type == 0 || d->type == 0xff) {
  3273. printf("Reserved\n");
  3274. } else if (d->type >= 0x06 && d->type <= 0xef) {
  3275. printf("Reserved\n");
  3276. } else if (d->type >= LOWER_OEM_TYPE && d->type <= UPPER_OEM_TYPE) {
  3277. printf("OEM GUID Definition\n");
  3278. } else {
  3279. switch (d->type){
  3280. case FRU_PICMGEXT_LINK_TYPE_BASE:
  3281. printf("PICMG 3.0 Base Interface 10/100/1000\n");
  3282. break;
  3283. case FRU_PICMGEXT_LINK_TYPE_FABRIC_ETHERNET:
  3284. printf("PICMG 3.1 Ethernet Fabric Interface\n");
  3285. break;
  3286. case FRU_PICMGEXT_LINK_TYPE_FABRIC_INFINIBAND:
  3287. printf("PICMG 3.2 Infiniband Fabric Interface\n");
  3288. break;
  3289. case FRU_PICMGEXT_LINK_TYPE_FABRIC_STAR:
  3290. printf("PICMG 3.3 Star Fabric Interface\n");
  3291. break;
  3292. case FRU_PICMGEXT_LINK_TYPE_PCIE:
  3293. printf("PICMG 3.4 PCI Express Fabric Interface\n");
  3294. break;
  3295. default:
  3296. printf("Invalid\n");
  3297. break;
  3298. }
  3299. }
  3300. printf("\tLink Designator: \n");
  3301. printf("\t Port 0 Flag: %s\n",
  3302. (d->desig_port & 0x01) ? "enable" : "disable");
  3303. printf("\t Port 1 Flag: %s\n",
  3304. (d->desig_port & 0x02) ? "enable" : "disable");
  3305. printf("\t Port 2 Flag: %s\n",
  3306. (d->desig_port & 0x04) ? "enable" : "disable");
  3307. printf("\t Port 3 Flag: %s\n",
  3308. (d->desig_port & 0x08) ? "enable" : "disable");
  3309. printf("\t Interface: 0x%02x - ", d->desig_if);
  3310. switch (d->desig_if) {
  3311. case FRU_PICMGEXT_DESIGN_IF_BASE:
  3312. printf("Base Interface\n");
  3313. break;
  3314. case FRU_PICMGEXT_DESIGN_IF_FABRIC:
  3315. printf("Fabric Interface\n");
  3316. break;
  3317. case FRU_PICMGEXT_DESIGN_IF_UPDATE_CHANNEL:
  3318. printf("Update Channel\n");
  3319. break;
  3320. case FRU_PICMGEXT_DESIGN_IF_RESERVED:
  3321. printf("Reserved\n");
  3322. break;
  3323. default:
  3324. printf("Invalid");
  3325. break;
  3326. }
  3327. printf("\t Channel Number: 0x%02x\n",
  3328. d->desig_channel);
  3329. }
  3330. }
  3331. /**************************************************************************
  3332. *
  3333. * Function name: ipmi_ek_display_radial_ipmb0_record
  3334. *
  3335. * Description: this function displays radial IPMB-0 record.
  3336. *
  3337. * Restriction: Fix me: Don't test yet
  3338. *
  3339. * Input: record: a pointer to current record to be displayed
  3340. *
  3341. * Output: None
  3342. *
  3343. * Global: None
  3344. *
  3345. * Return: None
  3346. *
  3347. ***************************************************************************/
  3348. static void
  3349. ipmi_ek_display_radial_ipmb0_record(struct ipmi_ek_multi_header *record)
  3350. {
  3351. #define SIZE_OF_CONNECTOR_DEFINER 3; /*bytes*/
  3352. int offset = START_DATA_OFFSET;
  3353. /* Ref: PICMG 3.0 Specification Revision 2.0, Table 3-59 */
  3354. printf(" IPMB-0 Connector Definer: ");
  3355. #ifndef WORDS_BIGENDIAN
  3356. printf("%02x %02x %02x h\n", record->data[offset],
  3357. record->data[offset+1], record->data[offset+2]);
  3358. #else
  3359. printf("%02x %02x %02x h\n", record->data[offset+2],
  3360. record->data[offset+1], record->data[offset]);
  3361. #endif
  3362. /* 3 bytes of connector definer was used */
  3363. offset += SIZE_OF_CONNECTOR_DEFINER;
  3364. printf(" IPMB-0 Connector version ID: ");
  3365. #ifndef WORDS_BIGENDIAN
  3366. printf("%02x %02x h\n", record->data[offset],
  3367. record->data[offset+1]);
  3368. #else
  3369. printf("%02x %02x h\n", record->data[offset+1],
  3370. record->data[offset]);
  3371. #endif
  3372. offset += 2;
  3373. printf(" IPMB-0 Hub Descriptor Count: 0x%02x",
  3374. record->data[offset++]);
  3375. if (record->data[offset] < 1) {
  3376. return;
  3377. }
  3378. for (offset = offset; offset < record->header.len;) {
  3379. unsigned char entry_count = 0;
  3380. printf(" IPMB-0 Hub Descriptor\n");
  3381. printf("\tHardware Address: 0x%02x\n",
  3382. record->data[offset++]);
  3383. printf("\tHub Info {0x%02x}: ", record->data[offset]);
  3384. /* Bit mask specified in Table 3-59
  3385. * of PICMG 3.0 Specification
  3386. */
  3387. if ((record->data[offset] & 0x01) == 0x01) {
  3388. printf("IPMB-A only\n");
  3389. } else if ((record->data[offset] & 0x02) == 0x02) {
  3390. printf("IPMB-B only\n");
  3391. } else if ((record->data[offset] & 0x03) == 0x03) {
  3392. printf("IPMB-A and IPMB-B\n");
  3393. } else {
  3394. printf("Reserved.\n");
  3395. }
  3396. offset ++;
  3397. entry_count = record->data[offset++];
  3398. printf("\tAddress Entry count: 0x%02x", entry_count);
  3399. while (entry_count > 0) {
  3400. printf("\t Hardware Address: 0x%02x\n",
  3401. record->data[offset++]);
  3402. printf("\t IPMB-0 Link Entry: 0x%02x\n",
  3403. record->data[offset++]);
  3404. entry_count --;
  3405. }
  3406. }
  3407. }
  3408. /**************************************************************************
  3409. *
  3410. * Function name: ipmi_ek_display_amc_current_record
  3411. *
  3412. * Description: this function displays AMC current record.
  3413. *
  3414. * Restriction: None
  3415. *
  3416. * Input: record: a pointer to current record to be displayed
  3417. *
  3418. * Output: None
  3419. *
  3420. * Global: None
  3421. *
  3422. * Return: None
  3423. *
  3424. ***************************************************************************/
  3425. static void
  3426. ipmi_ek_display_amc_current_record(struct ipmi_ek_multi_header *record)
  3427. {
  3428. unsigned char current;
  3429. current = record->data[START_DATA_OFFSET];
  3430. printf(" Current draw: %.1f A @ 12V => %.2f Watt\n",
  3431. (float)current / 10.0,
  3432. ((float)current / 10.0) * 12.0);
  3433. printf("\n");
  3434. }
  3435. /**************************************************************************
  3436. *
  3437. * Function name: ipmi_ek_display_amc_activation_record
  3438. *
  3439. * Description: this function displays carrier activation and current management
  3440. * record.
  3441. *
  3442. * Restriction: Reference: AMC.0 Specification Table 3-11 and Table 3-12
  3443. *
  3444. * Input: record: a pointer to current record to be displayed
  3445. *
  3446. * Output: None
  3447. *
  3448. * Global: None
  3449. *
  3450. * Return: None
  3451. *
  3452. ***************************************************************************/
  3453. static void
  3454. ipmi_ek_display_amc_activation_record(struct ipmi_ek_multi_header *record)
  3455. {
  3456. uint16_t max_current;
  3457. int offset = START_DATA_OFFSET;
  3458. max_current = record->data[offset];
  3459. max_current |= record->data[++offset] << 8;
  3460. printf(" Maximum Internal Current(@12V): %.2f A [ %.2f Watt ]\n",
  3461. (float) max_current / 10,
  3462. (float) max_current / 10 * 12);
  3463. printf(" Module Activation Readiness: %i sec.\n",
  3464. record->data[++offset]);
  3465. printf(" Descriptor Count: %i\n", record->data[++offset]);
  3466. for (++offset; (offset < record->header.len); offset += 3) {
  3467. struct fru_picmgext_activation_record *a =
  3468. (struct fru_picmgext_activation_record *)&record->data[offset];
  3469. printf("\tIPMB-Address:\t\t0x%x\n", a->ibmb_addr);
  3470. printf("\tMax. Module Current:\t%.2f A\n",
  3471. (float)a->max_module_curr / 10);
  3472. printf("\n");
  3473. }
  3474. }
  3475. /**************************************************************************
  3476. *
  3477. * Function name: ipmi_ek_display_amc_p2p_record
  3478. *
  3479. * Description: this function display amc p2p connectivity record in humain
  3480. * readable text format
  3481. *
  3482. * Restriction: Reference: AMC.0 Specification Table 3-16
  3483. *
  3484. * Input: record: a pointer to current record to be displayed
  3485. *
  3486. * Output: None
  3487. *
  3488. * Global: None
  3489. *
  3490. * Return: None
  3491. *
  3492. ***************************************************************************/
  3493. static void
  3494. ipmi_ek_display_amc_p2p_record(struct ipmi_ek_multi_header *record)
  3495. {
  3496. int index_data = START_DATA_OFFSET;
  3497. int oem_count = 0;
  3498. int ch_count = 0;
  3499. int index=0;
  3500. oem_count = record->data[index_data++];
  3501. printf("OEM GUID count: %02x\n", oem_count);
  3502. if (oem_count > 0) {
  3503. while (oem_count > 0) {
  3504. printf("OEM GUID: ");
  3505. for (index = 1; index <= SIZE_OF_GUID; index++) {
  3506. printf("%02x", record->data[index_data++]);
  3507. /* For a better look, display a "-" character
  3508. * after each 5 bytes of OEM GUID
  3509. */
  3510. if (!(index % 5)) {
  3511. printf("-");
  3512. }
  3513. }
  3514. printf("\n");
  3515. oem_count--;
  3516. }
  3517. }
  3518. if ((record->data[index_data] & AMC_MODULE) == AMC_MODULE) {
  3519. printf("AMC module connection\n");
  3520. } else {
  3521. printf("On-Carrier Device %02x h\n",
  3522. (record->data[index_data] & 0x0f));
  3523. }
  3524. index_data ++;
  3525. ch_count = record->data[index_data++];
  3526. printf("AMC Channel Descriptor count: %02x h\n", ch_count);
  3527. if (ch_count > 0) {
  3528. for (index = 0; index < ch_count; index++) {
  3529. unsigned int data;
  3530. struct fru_picmgext_amc_channel_desc_record *ch_desc;
  3531. printf(" AMC Channel Descriptor {%02x%02x%02x}\n",
  3532. record->data[index_data+2],
  3533. record->data[index_data+1],
  3534. record->data[index_data]);
  3535. data = record->data[index_data]
  3536. | (record->data[index_data + 1] << 8)
  3537. | (record->data[index_data + 2] << 16);
  3538. ch_desc = (struct fru_picmgext_amc_channel_desc_record *)&data;
  3539. printf(" Lane 0 Port: %d\n", ch_desc->lane0port);
  3540. printf(" Lane 1 Port: %d\n", ch_desc->lane1port);
  3541. printf(" Lane 2 Port: %d\n", ch_desc->lane2port);
  3542. printf(" Lane 3 Port: %d\n\n", ch_desc->lane3port);
  3543. index_data += FRU_PICMGEXT_AMC_CHANNEL_DESC_RECORD_SIZE;
  3544. }
  3545. }
  3546. while (index_data < record->header.len) {
  3547. /* Warning: This code doesn't work with gcc version
  3548. * between 4.0 and 4.3
  3549. */
  3550. unsigned int data[2];
  3551. struct fru_picmgext_amc_link_desc_record *link_desc;
  3552. data[0] = record->data[index_data]
  3553. | (record->data[index_data + 1] << 8)
  3554. | (record->data[index_data + 2] << 16)
  3555. | (record->data[index_data + 3] << 24);
  3556. data[1] = record->data[index_data + 4];
  3557. link_desc = (struct fru_picmgext_amc_link_desc_record *)&data[0];
  3558. printf(" AMC Link Descriptor:\n");
  3559. printf("\t- Link Type: %s \n",
  3560. val2str(link_desc->type, ipmi_ekanalyzer_link_type));
  3561. switch (link_desc->type) {
  3562. case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE:
  3563. case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE_AS1:
  3564. case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE_AS2:
  3565. printf("\t- Link Type extension: %s\n",
  3566. val2str(link_desc->type_ext,
  3567. ipmi_ekanalyzer_extension_PCIE));
  3568. printf("\t- Link Group ID: %d\n ",
  3569. link_desc->group_id);
  3570. printf("\t- Link Asym. Match: %d - %s\n",
  3571. link_desc->asym_match,
  3572. val2str(link_desc->asym_match,
  3573. ipmi_ekanalyzer_asym_PCIE));
  3574. break;
  3575. case FRU_PICMGEXT_AMC_LINK_TYPE_ETHERNET:
  3576. printf("\t- Link Type extension: %s\n",
  3577. val2str (link_desc->type_ext,
  3578. ipmi_ekanalyzer_extension_ETHERNET));
  3579. printf("\t- Link Group ID: %d \n",
  3580. link_desc->group_id);
  3581. printf("\t- Link Asym. Match: %d - %s\n",
  3582. link_desc->asym_match,
  3583. val2str(link_desc->asym_match,
  3584. ipmi_ekanalyzer_asym_PCIE));
  3585. break;
  3586. case FRU_PICMGEXT_AMC_LINK_TYPE_STORAGE:
  3587. printf("\t- Link Type extension: %s\n",
  3588. val2str (link_desc->type_ext,
  3589. ipmi_ekanalyzer_extension_STORAGE));
  3590. printf("\t- Link Group ID: %d \n",
  3591. link_desc->group_id);
  3592. printf("\t- Link Asym. Match: %d - %s\n",
  3593. link_desc->asym_match,
  3594. val2str(link_desc->asym_match,
  3595. ipmi_ekanalyzer_asym_STORAGE));
  3596. break;
  3597. default:
  3598. printf("\t- Link Type extension: %i (Unknown)\n",
  3599. link_desc->type_ext);
  3600. printf("\t- Link Group ID: %d \n",
  3601. link_desc->group_id);
  3602. printf("\t- Link Asym. Match: %i\n",
  3603. link_desc->asym_match);
  3604. break;
  3605. }
  3606. printf("\t- AMC Link Designator:\n");
  3607. printf("\t Channel ID: %i\n", link_desc->channel_id);
  3608. printf("\t\t Lane 0: %s\n",
  3609. (link_desc->port_flag_0) ? "enable" : "disable");
  3610. printf("\t\t Lane 1: %s\n",
  3611. (link_desc->port_flag_1) ? "enable" : "disable");
  3612. printf("\t\t Lane 2: %s\n",
  3613. (link_desc->port_flag_2) ? "enable" : "disable");
  3614. printf("\t\t Lane 3: %s\n",
  3615. (link_desc->port_flag_3) ? "enable" : "disable");
  3616. index_data += FRU_PICMGEXT_AMC_LINK_DESC_RECORD_SIZE;
  3617. }
  3618. }
  3619. /**************************************************************************
  3620. *
  3621. * Function name: ipmi_ek_display_amc_carrier_info_record
  3622. *
  3623. * Description: this function displays Carrier information table.
  3624. *
  3625. * Restriction: Reference: AMC.0 Specification Table 3-3
  3626. *
  3627. * Input: record: a pointer to current record to be displayed
  3628. *
  3629. * Output: None
  3630. *
  3631. * Global: START_DATA_OFFSET
  3632. *
  3633. * Return: None
  3634. *
  3635. ***************************************************************************/
  3636. static void
  3637. ipmi_ek_display_amc_carrier_info_record(struct ipmi_ek_multi_header *record)
  3638. {
  3639. unsigned char extVersion;
  3640. unsigned char siteCount;
  3641. int offset = START_DATA_OFFSET;
  3642. extVersion = record->data[offset++];
  3643. siteCount = record->data[offset++];
  3644. printf(" AMC.0 extension version: R%d.%d\n",
  3645. (extVersion >> 0) & 0x0F,
  3646. (extVersion >> 4) & 0x0F);
  3647. printf(" Carrier Sie Number Count: %d\n", siteCount);
  3648. while (siteCount > 0) {
  3649. printf("\tSite ID (%d): %s \n", record->data[offset],
  3650. val2str(record->data[offset], ipmi_ekanalyzer_module_type));
  3651. offset++;
  3652. siteCount--;
  3653. }
  3654. printf("\n");
  3655. }
  3656. /**************************************************************************
  3657. *
  3658. * Function name: ipmi_ek_display_clock_carrier_p2p_record
  3659. *
  3660. * Description: this function displays Carrier clock point-to-pont
  3661. * connectivity record.
  3662. *
  3663. * Restriction: the following code is copy from ipmi_fru.c with modification in
  3664. * reference to AMC.0 Specification Table 3-29
  3665. *
  3666. * Input: record: a pointer to current record to be displayed
  3667. *
  3668. * Output: None
  3669. *
  3670. * Global: None
  3671. *
  3672. * Return: None
  3673. *
  3674. ***************************************************************************/
  3675. static void
  3676. ipmi_ek_display_clock_carrier_p2p_record(struct ipmi_ek_multi_header *record)
  3677. {
  3678. unsigned char desc_count;
  3679. int i;
  3680. int j;
  3681. int offset = START_DATA_OFFSET;
  3682. desc_count = record->data[offset++];
  3683. for(i = 0; i < desc_count; i++) {
  3684. unsigned char resource_id;
  3685. unsigned char channel_count;
  3686. resource_id = record->data[offset++];
  3687. channel_count = record->data[offset++];
  3688. printf(" Clock Resource ID: 0x%02x\n", resource_id);
  3689. printf(" Type: ");
  3690. if ((resource_id & 0xC0) >> 6 == 0) {
  3691. printf("On-Carrier-Device\n");
  3692. } else if ((resource_id & 0xC0) >> 6 == 1) {
  3693. printf("AMC slot\n");
  3694. } else if ((resource_id & 0xC0) >> 6 == 2) {
  3695. printf("Backplane\n");
  3696. } else{
  3697. printf("reserved\n");
  3698. }
  3699. printf(" Channel Count: 0x%02x\n", channel_count);
  3700. for (j = 0; j < channel_count; j++) {
  3701. unsigned char loc_channel;
  3702. unsigned char rem_channel;
  3703. unsigned char rem_resource;
  3704. loc_channel = record->data[offset++];
  3705. rem_channel = record->data[offset++];
  3706. rem_resource = record->data[offset++];
  3707. printf("\tCLK-ID: 0x%02x ---> ", loc_channel);
  3708. printf(" remote CLKID: 0x%02x ", rem_channel);
  3709. if ((rem_resource & 0xC0) >> 6 == 0) {
  3710. printf("[ Carrier-Dev");
  3711. } else if ((rem_resource & 0xC0) >> 6 == 1) {
  3712. printf("[ AMC slot ");
  3713. } else if ((rem_resource & 0xC0) >> 6 == 2) {
  3714. printf("[ Backplane ");
  3715. } else {
  3716. printf("reserved ");
  3717. }
  3718. printf(" 0x%02x ]\n", rem_resource & 0xF);
  3719. }
  3720. }
  3721. printf("\n");
  3722. }
  3723. /**************************************************************************
  3724. *
  3725. * Function name: ipmi_ek_display_clock_config_record
  3726. *
  3727. * Description: this function displays clock configuration record.
  3728. *
  3729. * Restriction: the following codes are copy from ipmi_fru.c with modification
  3730. * in reference to AMC.0 Specification Table 3-35 and Table 3-36
  3731. *
  3732. * Input: record: a pointer to current record to be displayed
  3733. *
  3734. * Output: None
  3735. *
  3736. * Global: START_DATA_OFFSET
  3737. *
  3738. * Return: None
  3739. *
  3740. ***************************************************************************/
  3741. void
  3742. ipmi_ek_display_clock_config_record(struct ipmi_ek_multi_header *record)
  3743. {
  3744. unsigned char resource_id;
  3745. unsigned char descr_count;
  3746. int i;
  3747. int offset = START_DATA_OFFSET;
  3748. resource_id = record->data[offset++];
  3749. descr_count = record->data[offset++];
  3750. printf(" Clock Resource ID: 0x%02x\n", resource_id);
  3751. printf(" Clock Configuration Descriptor Count: 0x%02x\n", descr_count);
  3752. for (i = 0; i < descr_count; i++) {
  3753. int j = 0;
  3754. unsigned char channel_id;
  3755. unsigned char control;
  3756. unsigned char indirect_cnt;
  3757. unsigned char direct_cnt;
  3758. channel_id = record->data[offset++];
  3759. control = record->data[offset++];
  3760. printf("\tCLK-ID: 0x%02x - ", channel_id);
  3761. printf("CTRL 0x%02x [ %12s ]\n", control,
  3762. ((control & 0x1) == 0) ? "Carrier IPMC" : "Application");
  3763. indirect_cnt = record->data[offset++];
  3764. direct_cnt = record->data[offset++];
  3765. printf("\t Count: Indirect 0x%02x / Direct 0x%02x\n",
  3766. indirect_cnt,
  3767. direct_cnt);
  3768. /* indirect desc */
  3769. for (j = 0; j < indirect_cnt; j++) {
  3770. unsigned char feature;
  3771. unsigned char dep_chn_id;
  3772. feature = record->data[offset++];
  3773. dep_chn_id = record->data[offset++];
  3774. printf("\t\tFeature: 0x%02x [%8s] - ",
  3775. feature,
  3776. (feature & 0x1) == 1 ? "Source" : "Receiver");
  3777. printf(" Dep. CLK-ID: 0x%02x\n", dep_chn_id);
  3778. }
  3779. /* direct desc */
  3780. for (j = 0; j < direct_cnt; j++) {
  3781. unsigned char feature;
  3782. unsigned char family;
  3783. unsigned char accuracy;
  3784. unsigned long freq;
  3785. unsigned long min_freq;
  3786. unsigned long max_freq;
  3787. feature = record->data[offset++];
  3788. family = record->data[offset++];
  3789. accuracy = record->data[offset++];
  3790. freq = (record->data[offset+0] << 0)
  3791. | (record->data[offset+1] << 8)
  3792. | (record->data[offset+2] << 16)
  3793. | (record->data[offset+3] << 24);
  3794. offset += 4;
  3795. min_freq = (record->data[offset+0] << 0)
  3796. | (record->data[offset+1] << 8)
  3797. | (record->data[offset+2] << 16)
  3798. | (record->data[offset+3] << 24);
  3799. offset += 4;
  3800. max_freq = (record->data[offset+0] << 0)
  3801. | (record->data[offset+1] << 8)
  3802. | (record->data[offset+2] << 16)
  3803. | (record->data[offset+3] << 24);
  3804. offset += 4;
  3805. printf("\t- Feature: 0x%02x - PLL: %x / Asym: %s\n",
  3806. feature,
  3807. (feature > 1) & 1,
  3808. (feature & 1) ? "Source" : "Receiver");
  3809. printf("\tFamily: 0x%02x - AccLVL: 0x%02x\n",
  3810. family, accuracy);
  3811. printf("\tFRQ: %-9ld - min: %-9ld - max: %-9ld\n",
  3812. freq, min_freq, max_freq);
  3813. }
  3814. printf("\n");
  3815. }
  3816. }
  3817. /**************************************************************************
  3818. *
  3819. * Function name: ipmi_ekanalyzer_fru_file2structure
  3820. *
  3821. * Description: this function convert a FRU binary file into a linked list of
  3822. * FRU multi record
  3823. *
  3824. * Restriction: None
  3825. *
  3826. * Input/Ouput: filename1: name of the file that contain FRU binary data
  3827. * record: a pointer to current record
  3828. * list_head: a pointer to header of the list
  3829. * list_last: a pointer to tale of the list
  3830. *
  3831. * Global: None
  3832. *
  3833. * Return: return -1 as Error status, and 0 as Ok status
  3834. *
  3835. ***************************************************************************/
  3836. static int
  3837. ipmi_ekanalyzer_fru_file2structure(char *filename,
  3838. struct ipmi_ek_multi_header **list_head,
  3839. struct ipmi_ek_multi_header **list_record,
  3840. struct ipmi_ek_multi_header **list_last)
  3841. {
  3842. FILE *input_file;
  3843. unsigned char data;
  3844. unsigned char last_record = 0;
  3845. unsigned int multi_offset = 0;
  3846. int record_count = 0;
  3847. int ret = 0;
  3848. input_file = fopen(filename, "r");
  3849. if (input_file == NULL) {
  3850. lprintf(LOG_ERR, "File: '%s' is not found", filename);
  3851. return ERROR_STATUS;
  3852. }
  3853. fseek(input_file, START_DATA_OFFSET, SEEK_SET);
  3854. data = 0;
  3855. ret = fread(&data, 1, 1, input_file);
  3856. if ((ret != 1) || ferror(input_file)) {
  3857. lprintf(LOG_ERR, "Invalid Offset!");
  3858. fclose(input_file);
  3859. return ERROR_STATUS;
  3860. }
  3861. if (data == 0) {
  3862. lprintf(LOG_ERR, "There is no multi record in the file '%s'",
  3863. filename);
  3864. fclose(input_file);
  3865. return ERROR_STATUS;
  3866. }
  3867. /* the offset value is in multiple of 8 bytes. */
  3868. multi_offset = data * 8;
  3869. lprintf(LOG_DEBUG, "start multi offset = 0x%02x",
  3870. multi_offset);
  3871. fseek(input_file, multi_offset, SEEK_SET);
  3872. while (!feof(input_file)) {
  3873. *list_record = malloc(sizeof(struct ipmi_ek_multi_header));
  3874. if (*list_record == NULL) {
  3875. lprintf(LOG_ERR, "ipmitool: malloc failure");
  3876. return ERROR_STATUS;
  3877. }
  3878. ret = fread(&(*list_record)->header, START_DATA_OFFSET, 1,
  3879. input_file);
  3880. if ((ret != 1) || ferror(input_file)) {
  3881. free(*list_record);
  3882. *list_record = NULL;
  3883. fclose(input_file);
  3884. lprintf(LOG_ERR, "Invalid Header!");
  3885. return ERROR_STATUS;
  3886. }
  3887. if ((*list_record)->header.len == 0) {
  3888. record_count++;
  3889. continue;
  3890. }
  3891. (*list_record)->data = malloc((*list_record)->header.len);
  3892. if ((*list_record)->data == NULL) {
  3893. lprintf(LOG_ERR, "Failed to allocation memory size %d\n",
  3894. (*list_record)->header.len);
  3895. record_count++;
  3896. continue;
  3897. }
  3898. ret = fread((*list_record)->data, ((*list_record)->header.len),
  3899. 1, input_file);
  3900. if ((ret != 1) || ferror(input_file)) {
  3901. lprintf(LOG_ERR, "Invalid Record Data!");
  3902. fclose(input_file);
  3903. return ERROR_STATUS;
  3904. }
  3905. if (verbose > 0)
  3906. printf("Record %d has length = %02x\n", record_count,
  3907. (*list_record)->header.len);
  3908. if (verbose > 1) {
  3909. int i;
  3910. printf("Type: %02x", (*list_record)->header.type);
  3911. for (i = 0; i < ((*list_record)->header.len); i++) {
  3912. if (!(i % 8)) {
  3913. printf("\n0x%02x: ", i);
  3914. }
  3915. printf("%02x ",
  3916. (*list_record)->data[i]);
  3917. }
  3918. printf("\n\n");
  3919. }
  3920. ipmi_ek_add_record2list(list_record, list_head, list_last);
  3921. /* mask the 8th bits to see if it is the last record */
  3922. last_record = ((*list_record)->header.format) & 0x80;
  3923. if (last_record) {
  3924. break;
  3925. }
  3926. record_count++;
  3927. }
  3928. fclose(input_file);
  3929. return OK_STATUS;
  3930. }
  3931. /**************************************************************************
  3932. *
  3933. * Function name: ipmi_ek_add_record2list
  3934. *
  3935. * Description: this function adds a sigle FRU multi record to a linked list of
  3936. * FRU multi record.
  3937. *
  3938. * Restriction: None
  3939. *
  3940. * Input/Output: record: a pointer to current record
  3941. * list_head: a pointer to header of the list
  3942. * list_last: a pointer to tale of the list
  3943. *
  3944. * Global: None
  3945. *
  3946. * Return: None
  3947. *
  3948. ***************************************************************************/
  3949. static void
  3950. ipmi_ek_add_record2list(struct ipmi_ek_multi_header **record,
  3951. struct ipmi_ek_multi_header **list_head,
  3952. struct ipmi_ek_multi_header **list_last)
  3953. {
  3954. if (*list_head == NULL) {
  3955. *list_head = *record;
  3956. (*record)->prev = NULL;
  3957. if (verbose > 2) {
  3958. printf("Adding first record to list\n");
  3959. }
  3960. } else {
  3961. (*list_last)->next = *record;
  3962. (*record)->prev = *list_last;
  3963. if (verbose > 2) {
  3964. printf("Add 1 record to list\n");
  3965. }
  3966. }
  3967. *list_last = *record;
  3968. (*record)->next = NULL;
  3969. }
  3970. /**************************************************************************
  3971. *
  3972. * Function name: ipmi_ek_remove_record_from_list
  3973. *
  3974. * Description: this function removes a sigle FRU multi record from a linked
  3975. * list of FRU multi record.
  3976. *
  3977. * Restriction: None
  3978. *
  3979. * Input/Output: record: a pointer to record to be deleted
  3980. * list_head: a pointer to header of the list
  3981. * list_last: a pointer to tale of the list
  3982. *
  3983. * Global: None
  3984. *
  3985. * Return: None
  3986. *
  3987. ***************************************************************************/
  3988. static void
  3989. ipmi_ek_remove_record_from_list(struct ipmi_ek_multi_header *record,
  3990. struct ipmi_ek_multi_header **list_head,
  3991. struct ipmi_ek_multi_header **list_last)
  3992. {
  3993. if (record->prev == NULL) {
  3994. *list_head = record->next;
  3995. } else {
  3996. record->prev->next = record->next;
  3997. }
  3998. if (record->next == NULL) {
  3999. (*list_last) = record->prev;
  4000. } else {
  4001. record->next->prev = record->prev;
  4002. }
  4003. free(record);
  4004. record = NULL;
  4005. }