mad.c 125 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434
  1. /*
  2. * Copyright(c) 2015, 2016 Intel Corporation.
  3. *
  4. * This file is provided under a dual BSD/GPLv2 license. When using or
  5. * redistributing this file, you may do so under either license.
  6. *
  7. * GPL LICENSE SUMMARY
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of version 2 of the GNU General Public License as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * BSD LICENSE
  19. *
  20. * Redistribution and use in source and binary forms, with or without
  21. * modification, are permitted provided that the following conditions
  22. * are met:
  23. *
  24. * - Redistributions of source code must retain the above copyright
  25. * notice, this list of conditions and the following disclaimer.
  26. * - Redistributions in binary form must reproduce the above copyright
  27. * notice, this list of conditions and the following disclaimer in
  28. * the documentation and/or other materials provided with the
  29. * distribution.
  30. * - Neither the name of Intel Corporation nor the names of its
  31. * contributors may be used to endorse or promote products derived
  32. * from this software without specific prior written permission.
  33. *
  34. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  35. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  36. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  37. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  38. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  39. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  40. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  41. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  42. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  44. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45. *
  46. */
  47. #include <linux/net.h>
  48. #define OPA_NUM_PKEY_BLOCKS_PER_SMP (OPA_SMP_DR_DATA_SIZE \
  49. / (OPA_PARTITION_TABLE_BLK_SIZE * sizeof(u16)))
  50. #include "hfi.h"
  51. #include "mad.h"
  52. #include "trace.h"
  53. #include "qp.h"
  54. /* the reset value from the FM is supposed to be 0xffff, handle both */
  55. #define OPA_LINK_WIDTH_RESET_OLD 0x0fff
  56. #define OPA_LINK_WIDTH_RESET 0xffff
  57. static int reply(struct ib_mad_hdr *smp)
  58. {
  59. /*
  60. * The verbs framework will handle the directed/LID route
  61. * packet changes.
  62. */
  63. smp->method = IB_MGMT_METHOD_GET_RESP;
  64. if (smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
  65. smp->status |= IB_SMP_DIRECTION;
  66. return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY;
  67. }
  68. static inline void clear_opa_smp_data(struct opa_smp *smp)
  69. {
  70. void *data = opa_get_smp_data(smp);
  71. size_t size = opa_get_smp_data_size(smp);
  72. memset(data, 0, size);
  73. }
  74. void hfi1_event_pkey_change(struct hfi1_devdata *dd, u8 port)
  75. {
  76. struct ib_event event;
  77. event.event = IB_EVENT_PKEY_CHANGE;
  78. event.device = &dd->verbs_dev.rdi.ibdev;
  79. event.element.port_num = port;
  80. ib_dispatch_event(&event);
  81. }
  82. static void send_trap(struct hfi1_ibport *ibp, void *data, unsigned len)
  83. {
  84. struct ib_mad_send_buf *send_buf;
  85. struct ib_mad_agent *agent;
  86. struct opa_smp *smp;
  87. int ret;
  88. unsigned long flags;
  89. unsigned long timeout;
  90. int pkey_idx;
  91. u32 qpn = ppd_from_ibp(ibp)->sm_trap_qp;
  92. agent = ibp->rvp.send_agent;
  93. if (!agent)
  94. return;
  95. /* o14-3.2.1 */
  96. if (ppd_from_ibp(ibp)->lstate != IB_PORT_ACTIVE)
  97. return;
  98. /* o14-2 */
  99. if (ibp->rvp.trap_timeout && time_before(jiffies,
  100. ibp->rvp.trap_timeout))
  101. return;
  102. pkey_idx = hfi1_lookup_pkey_idx(ibp, LIM_MGMT_P_KEY);
  103. if (pkey_idx < 0) {
  104. pr_warn("%s: failed to find limited mgmt pkey, defaulting 0x%x\n",
  105. __func__, hfi1_get_pkey(ibp, 1));
  106. pkey_idx = 1;
  107. }
  108. send_buf = ib_create_send_mad(agent, qpn, pkey_idx, 0,
  109. IB_MGMT_MAD_HDR, IB_MGMT_MAD_DATA,
  110. GFP_ATOMIC, IB_MGMT_BASE_VERSION);
  111. if (IS_ERR(send_buf))
  112. return;
  113. smp = send_buf->mad;
  114. smp->base_version = OPA_MGMT_BASE_VERSION;
  115. smp->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
  116. smp->class_version = OPA_SMI_CLASS_VERSION;
  117. smp->method = IB_MGMT_METHOD_TRAP;
  118. ibp->rvp.tid++;
  119. smp->tid = cpu_to_be64(ibp->rvp.tid);
  120. smp->attr_id = IB_SMP_ATTR_NOTICE;
  121. /* o14-1: smp->mkey = 0; */
  122. memcpy(smp->route.lid.data, data, len);
  123. spin_lock_irqsave(&ibp->rvp.lock, flags);
  124. if (!ibp->rvp.sm_ah) {
  125. if (ibp->rvp.sm_lid != be16_to_cpu(IB_LID_PERMISSIVE)) {
  126. struct ib_ah *ah;
  127. ah = hfi1_create_qp0_ah(ibp, ibp->rvp.sm_lid);
  128. if (IS_ERR(ah)) {
  129. ret = PTR_ERR(ah);
  130. } else {
  131. send_buf->ah = ah;
  132. ibp->rvp.sm_ah = ibah_to_rvtah(ah);
  133. ret = 0;
  134. }
  135. } else {
  136. ret = -EINVAL;
  137. }
  138. } else {
  139. send_buf->ah = &ibp->rvp.sm_ah->ibah;
  140. ret = 0;
  141. }
  142. spin_unlock_irqrestore(&ibp->rvp.lock, flags);
  143. if (!ret)
  144. ret = ib_post_send_mad(send_buf, NULL);
  145. if (!ret) {
  146. /* 4.096 usec. */
  147. timeout = (4096 * (1UL << ibp->rvp.subnet_timeout)) / 1000;
  148. ibp->rvp.trap_timeout = jiffies + usecs_to_jiffies(timeout);
  149. } else {
  150. ib_free_send_mad(send_buf);
  151. ibp->rvp.trap_timeout = 0;
  152. }
  153. }
  154. /*
  155. * Send a bad [PQ]_Key trap (ch. 14.3.8).
  156. */
  157. void hfi1_bad_pqkey(struct hfi1_ibport *ibp, __be16 trap_num, u32 key, u32 sl,
  158. u32 qp1, u32 qp2, u16 lid1, u16 lid2)
  159. {
  160. struct opa_mad_notice_attr data;
  161. u32 lid = ppd_from_ibp(ibp)->lid;
  162. u32 _lid1 = lid1;
  163. u32 _lid2 = lid2;
  164. memset(&data, 0, sizeof(data));
  165. if (trap_num == OPA_TRAP_BAD_P_KEY)
  166. ibp->rvp.pkey_violations++;
  167. else
  168. ibp->rvp.qkey_violations++;
  169. ibp->rvp.n_pkt_drops++;
  170. /* Send violation trap */
  171. data.generic_type = IB_NOTICE_TYPE_SECURITY;
  172. data.prod_type_lsb = IB_NOTICE_PROD_CA;
  173. data.trap_num = trap_num;
  174. data.issuer_lid = cpu_to_be32(lid);
  175. data.ntc_257_258.lid1 = cpu_to_be32(_lid1);
  176. data.ntc_257_258.lid2 = cpu_to_be32(_lid2);
  177. data.ntc_257_258.key = cpu_to_be32(key);
  178. data.ntc_257_258.sl = sl << 3;
  179. data.ntc_257_258.qp1 = cpu_to_be32(qp1);
  180. data.ntc_257_258.qp2 = cpu_to_be32(qp2);
  181. send_trap(ibp, &data, sizeof(data));
  182. }
  183. /*
  184. * Send a bad M_Key trap (ch. 14.3.9).
  185. */
  186. static void bad_mkey(struct hfi1_ibport *ibp, struct ib_mad_hdr *mad,
  187. __be64 mkey, __be32 dr_slid, u8 return_path[], u8 hop_cnt)
  188. {
  189. struct opa_mad_notice_attr data;
  190. u32 lid = ppd_from_ibp(ibp)->lid;
  191. memset(&data, 0, sizeof(data));
  192. /* Send violation trap */
  193. data.generic_type = IB_NOTICE_TYPE_SECURITY;
  194. data.prod_type_lsb = IB_NOTICE_PROD_CA;
  195. data.trap_num = OPA_TRAP_BAD_M_KEY;
  196. data.issuer_lid = cpu_to_be32(lid);
  197. data.ntc_256.lid = data.issuer_lid;
  198. data.ntc_256.method = mad->method;
  199. data.ntc_256.attr_id = mad->attr_id;
  200. data.ntc_256.attr_mod = mad->attr_mod;
  201. data.ntc_256.mkey = mkey;
  202. if (mad->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) {
  203. data.ntc_256.dr_slid = dr_slid;
  204. data.ntc_256.dr_trunc_hop = IB_NOTICE_TRAP_DR_NOTICE;
  205. if (hop_cnt > ARRAY_SIZE(data.ntc_256.dr_rtn_path)) {
  206. data.ntc_256.dr_trunc_hop |=
  207. IB_NOTICE_TRAP_DR_TRUNC;
  208. hop_cnt = ARRAY_SIZE(data.ntc_256.dr_rtn_path);
  209. }
  210. data.ntc_256.dr_trunc_hop |= hop_cnt;
  211. memcpy(data.ntc_256.dr_rtn_path, return_path,
  212. hop_cnt);
  213. }
  214. send_trap(ibp, &data, sizeof(data));
  215. }
  216. /*
  217. * Send a Port Capability Mask Changed trap (ch. 14.3.11).
  218. */
  219. void hfi1_cap_mask_chg(struct rvt_dev_info *rdi, u8 port_num)
  220. {
  221. struct opa_mad_notice_attr data;
  222. struct hfi1_ibdev *verbs_dev = dev_from_rdi(rdi);
  223. struct hfi1_devdata *dd = dd_from_dev(verbs_dev);
  224. struct hfi1_ibport *ibp = &dd->pport[port_num - 1].ibport_data;
  225. u32 lid = ppd_from_ibp(ibp)->lid;
  226. memset(&data, 0, sizeof(data));
  227. data.generic_type = IB_NOTICE_TYPE_INFO;
  228. data.prod_type_lsb = IB_NOTICE_PROD_CA;
  229. data.trap_num = OPA_TRAP_CHANGE_CAPABILITY;
  230. data.issuer_lid = cpu_to_be32(lid);
  231. data.ntc_144.lid = data.issuer_lid;
  232. data.ntc_144.new_cap_mask = cpu_to_be32(ibp->rvp.port_cap_flags);
  233. send_trap(ibp, &data, sizeof(data));
  234. }
  235. /*
  236. * Send a System Image GUID Changed trap (ch. 14.3.12).
  237. */
  238. void hfi1_sys_guid_chg(struct hfi1_ibport *ibp)
  239. {
  240. struct opa_mad_notice_attr data;
  241. u32 lid = ppd_from_ibp(ibp)->lid;
  242. memset(&data, 0, sizeof(data));
  243. data.generic_type = IB_NOTICE_TYPE_INFO;
  244. data.prod_type_lsb = IB_NOTICE_PROD_CA;
  245. data.trap_num = OPA_TRAP_CHANGE_SYSGUID;
  246. data.issuer_lid = cpu_to_be32(lid);
  247. data.ntc_145.new_sys_guid = ib_hfi1_sys_image_guid;
  248. data.ntc_145.lid = data.issuer_lid;
  249. send_trap(ibp, &data, sizeof(data));
  250. }
  251. /*
  252. * Send a Node Description Changed trap (ch. 14.3.13).
  253. */
  254. void hfi1_node_desc_chg(struct hfi1_ibport *ibp)
  255. {
  256. struct opa_mad_notice_attr data;
  257. u32 lid = ppd_from_ibp(ibp)->lid;
  258. memset(&data, 0, sizeof(data));
  259. data.generic_type = IB_NOTICE_TYPE_INFO;
  260. data.prod_type_lsb = IB_NOTICE_PROD_CA;
  261. data.trap_num = OPA_TRAP_CHANGE_CAPABILITY;
  262. data.issuer_lid = cpu_to_be32(lid);
  263. data.ntc_144.lid = data.issuer_lid;
  264. data.ntc_144.change_flags =
  265. cpu_to_be16(OPA_NOTICE_TRAP_NODE_DESC_CHG);
  266. send_trap(ibp, &data, sizeof(data));
  267. }
  268. static int __subn_get_opa_nodedesc(struct opa_smp *smp, u32 am,
  269. u8 *data, struct ib_device *ibdev,
  270. u8 port, u32 *resp_len)
  271. {
  272. struct opa_node_description *nd;
  273. if (am) {
  274. smp->status |= IB_SMP_INVALID_FIELD;
  275. return reply((struct ib_mad_hdr *)smp);
  276. }
  277. nd = (struct opa_node_description *)data;
  278. memcpy(nd->data, ibdev->node_desc, sizeof(nd->data));
  279. if (resp_len)
  280. *resp_len += sizeof(*nd);
  281. return reply((struct ib_mad_hdr *)smp);
  282. }
  283. static int __subn_get_opa_nodeinfo(struct opa_smp *smp, u32 am, u8 *data,
  284. struct ib_device *ibdev, u8 port,
  285. u32 *resp_len)
  286. {
  287. struct opa_node_info *ni;
  288. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  289. unsigned pidx = port - 1; /* IB number port from 1, hw from 0 */
  290. ni = (struct opa_node_info *)data;
  291. /* GUID 0 is illegal */
  292. if (am || pidx >= dd->num_pports || dd->pport[pidx].guid == 0) {
  293. smp->status |= IB_SMP_INVALID_FIELD;
  294. return reply((struct ib_mad_hdr *)smp);
  295. }
  296. ni->port_guid = cpu_to_be64(dd->pport[pidx].guid);
  297. ni->base_version = OPA_MGMT_BASE_VERSION;
  298. ni->class_version = OPA_SMI_CLASS_VERSION;
  299. ni->node_type = 1; /* channel adapter */
  300. ni->num_ports = ibdev->phys_port_cnt;
  301. /* This is already in network order */
  302. ni->system_image_guid = ib_hfi1_sys_image_guid;
  303. /* Use first-port GUID as node */
  304. ni->node_guid = cpu_to_be64(dd->pport->guid);
  305. ni->partition_cap = cpu_to_be16(hfi1_get_npkeys(dd));
  306. ni->device_id = cpu_to_be16(dd->pcidev->device);
  307. ni->revision = cpu_to_be32(dd->minrev);
  308. ni->local_port_num = port;
  309. ni->vendor_id[0] = dd->oui1;
  310. ni->vendor_id[1] = dd->oui2;
  311. ni->vendor_id[2] = dd->oui3;
  312. if (resp_len)
  313. *resp_len += sizeof(*ni);
  314. return reply((struct ib_mad_hdr *)smp);
  315. }
  316. static int subn_get_nodeinfo(struct ib_smp *smp, struct ib_device *ibdev,
  317. u8 port)
  318. {
  319. struct ib_node_info *nip = (struct ib_node_info *)&smp->data;
  320. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  321. unsigned pidx = port - 1; /* IB number port from 1, hw from 0 */
  322. /* GUID 0 is illegal */
  323. if (smp->attr_mod || pidx >= dd->num_pports ||
  324. dd->pport[pidx].guid == 0)
  325. smp->status |= IB_SMP_INVALID_FIELD;
  326. else
  327. nip->port_guid = cpu_to_be64(dd->pport[pidx].guid);
  328. nip->base_version = OPA_MGMT_BASE_VERSION;
  329. nip->class_version = OPA_SMI_CLASS_VERSION;
  330. nip->node_type = 1; /* channel adapter */
  331. nip->num_ports = ibdev->phys_port_cnt;
  332. /* This is already in network order */
  333. nip->sys_guid = ib_hfi1_sys_image_guid;
  334. /* Use first-port GUID as node */
  335. nip->node_guid = cpu_to_be64(dd->pport->guid);
  336. nip->partition_cap = cpu_to_be16(hfi1_get_npkeys(dd));
  337. nip->device_id = cpu_to_be16(dd->pcidev->device);
  338. nip->revision = cpu_to_be32(dd->minrev);
  339. nip->local_port_num = port;
  340. nip->vendor_id[0] = dd->oui1;
  341. nip->vendor_id[1] = dd->oui2;
  342. nip->vendor_id[2] = dd->oui3;
  343. return reply((struct ib_mad_hdr *)smp);
  344. }
  345. static void set_link_width_enabled(struct hfi1_pportdata *ppd, u32 w)
  346. {
  347. (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_LWID_ENB, w);
  348. }
  349. static void set_link_width_downgrade_enabled(struct hfi1_pportdata *ppd, u32 w)
  350. {
  351. (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_LWID_DG_ENB, w);
  352. }
  353. static void set_link_speed_enabled(struct hfi1_pportdata *ppd, u32 s)
  354. {
  355. (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_SPD_ENB, s);
  356. }
  357. static int check_mkey(struct hfi1_ibport *ibp, struct ib_mad_hdr *mad,
  358. int mad_flags, __be64 mkey, __be32 dr_slid,
  359. u8 return_path[], u8 hop_cnt)
  360. {
  361. int valid_mkey = 0;
  362. int ret = 0;
  363. /* Is the mkey in the process of expiring? */
  364. if (ibp->rvp.mkey_lease_timeout &&
  365. time_after_eq(jiffies, ibp->rvp.mkey_lease_timeout)) {
  366. /* Clear timeout and mkey protection field. */
  367. ibp->rvp.mkey_lease_timeout = 0;
  368. ibp->rvp.mkeyprot = 0;
  369. }
  370. if ((mad_flags & IB_MAD_IGNORE_MKEY) || ibp->rvp.mkey == 0 ||
  371. ibp->rvp.mkey == mkey)
  372. valid_mkey = 1;
  373. /* Unset lease timeout on any valid Get/Set/TrapRepress */
  374. if (valid_mkey && ibp->rvp.mkey_lease_timeout &&
  375. (mad->method == IB_MGMT_METHOD_GET ||
  376. mad->method == IB_MGMT_METHOD_SET ||
  377. mad->method == IB_MGMT_METHOD_TRAP_REPRESS))
  378. ibp->rvp.mkey_lease_timeout = 0;
  379. if (!valid_mkey) {
  380. switch (mad->method) {
  381. case IB_MGMT_METHOD_GET:
  382. /* Bad mkey not a violation below level 2 */
  383. if (ibp->rvp.mkeyprot < 2)
  384. break;
  385. case IB_MGMT_METHOD_SET:
  386. case IB_MGMT_METHOD_TRAP_REPRESS:
  387. if (ibp->rvp.mkey_violations != 0xFFFF)
  388. ++ibp->rvp.mkey_violations;
  389. if (!ibp->rvp.mkey_lease_timeout &&
  390. ibp->rvp.mkey_lease_period)
  391. ibp->rvp.mkey_lease_timeout = jiffies +
  392. ibp->rvp.mkey_lease_period * HZ;
  393. /* Generate a trap notice. */
  394. bad_mkey(ibp, mad, mkey, dr_slid, return_path,
  395. hop_cnt);
  396. ret = 1;
  397. }
  398. }
  399. return ret;
  400. }
  401. /*
  402. * The SMA caches reads from LCB registers in case the LCB is unavailable.
  403. * (The LCB is unavailable in certain link states, for example.)
  404. */
  405. struct lcb_datum {
  406. u32 off;
  407. u64 val;
  408. };
  409. static struct lcb_datum lcb_cache[] = {
  410. { DC_LCB_STS_ROUND_TRIP_LTP_CNT, 0 },
  411. };
  412. static int write_lcb_cache(u32 off, u64 val)
  413. {
  414. int i;
  415. for (i = 0; i < ARRAY_SIZE(lcb_cache); i++) {
  416. if (lcb_cache[i].off == off) {
  417. lcb_cache[i].val = val;
  418. return 0;
  419. }
  420. }
  421. pr_warn("%s bad offset 0x%x\n", __func__, off);
  422. return -1;
  423. }
  424. static int read_lcb_cache(u32 off, u64 *val)
  425. {
  426. int i;
  427. for (i = 0; i < ARRAY_SIZE(lcb_cache); i++) {
  428. if (lcb_cache[i].off == off) {
  429. *val = lcb_cache[i].val;
  430. return 0;
  431. }
  432. }
  433. pr_warn("%s bad offset 0x%x\n", __func__, off);
  434. return -1;
  435. }
  436. void read_ltp_rtt(struct hfi1_devdata *dd)
  437. {
  438. u64 reg;
  439. if (read_lcb_csr(dd, DC_LCB_STS_ROUND_TRIP_LTP_CNT, &reg))
  440. dd_dev_err(dd, "%s: unable to read LTP RTT\n", __func__);
  441. else
  442. write_lcb_cache(DC_LCB_STS_ROUND_TRIP_LTP_CNT, reg);
  443. }
  444. static int __subn_get_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data,
  445. struct ib_device *ibdev, u8 port,
  446. u32 *resp_len)
  447. {
  448. int i;
  449. struct hfi1_devdata *dd;
  450. struct hfi1_pportdata *ppd;
  451. struct hfi1_ibport *ibp;
  452. struct opa_port_info *pi = (struct opa_port_info *)data;
  453. u8 mtu;
  454. u8 credit_rate;
  455. u8 is_beaconing_active;
  456. u32 state;
  457. u32 num_ports = OPA_AM_NPORT(am);
  458. u32 start_of_sm_config = OPA_AM_START_SM_CFG(am);
  459. u32 buffer_units;
  460. u64 tmp = 0;
  461. if (num_ports != 1) {
  462. smp->status |= IB_SMP_INVALID_FIELD;
  463. return reply((struct ib_mad_hdr *)smp);
  464. }
  465. dd = dd_from_ibdev(ibdev);
  466. /* IB numbers ports from 1, hw from 0 */
  467. ppd = dd->pport + (port - 1);
  468. ibp = &ppd->ibport_data;
  469. if (ppd->vls_supported / 2 > ARRAY_SIZE(pi->neigh_mtu.pvlx_to_mtu) ||
  470. ppd->vls_supported > ARRAY_SIZE(dd->vld)) {
  471. smp->status |= IB_SMP_INVALID_FIELD;
  472. return reply((struct ib_mad_hdr *)smp);
  473. }
  474. pi->lid = cpu_to_be32(ppd->lid);
  475. /* Only return the mkey if the protection field allows it. */
  476. if (!(smp->method == IB_MGMT_METHOD_GET &&
  477. ibp->rvp.mkey != smp->mkey &&
  478. ibp->rvp.mkeyprot == 1))
  479. pi->mkey = ibp->rvp.mkey;
  480. pi->subnet_prefix = ibp->rvp.gid_prefix;
  481. pi->sm_lid = cpu_to_be32(ibp->rvp.sm_lid);
  482. pi->ib_cap_mask = cpu_to_be32(ibp->rvp.port_cap_flags);
  483. pi->mkey_lease_period = cpu_to_be16(ibp->rvp.mkey_lease_period);
  484. pi->sm_trap_qp = cpu_to_be32(ppd->sm_trap_qp);
  485. pi->sa_qp = cpu_to_be32(ppd->sa_qp);
  486. pi->link_width.enabled = cpu_to_be16(ppd->link_width_enabled);
  487. pi->link_width.supported = cpu_to_be16(ppd->link_width_supported);
  488. pi->link_width.active = cpu_to_be16(ppd->link_width_active);
  489. pi->link_width_downgrade.supported =
  490. cpu_to_be16(ppd->link_width_downgrade_supported);
  491. pi->link_width_downgrade.enabled =
  492. cpu_to_be16(ppd->link_width_downgrade_enabled);
  493. pi->link_width_downgrade.tx_active =
  494. cpu_to_be16(ppd->link_width_downgrade_tx_active);
  495. pi->link_width_downgrade.rx_active =
  496. cpu_to_be16(ppd->link_width_downgrade_rx_active);
  497. pi->link_speed.supported = cpu_to_be16(ppd->link_speed_supported);
  498. pi->link_speed.active = cpu_to_be16(ppd->link_speed_active);
  499. pi->link_speed.enabled = cpu_to_be16(ppd->link_speed_enabled);
  500. state = driver_lstate(ppd);
  501. if (start_of_sm_config && (state == IB_PORT_INIT))
  502. ppd->is_sm_config_started = 1;
  503. pi->port_phys_conf = (ppd->port_type & 0xf);
  504. pi->port_states.ledenable_offlinereason = ppd->neighbor_normal << 4;
  505. pi->port_states.ledenable_offlinereason |=
  506. ppd->is_sm_config_started << 5;
  507. /*
  508. * This pairs with the memory barrier in hfi1_start_led_override to
  509. * ensure that we read the correct state of LED beaconing represented
  510. * by led_override_timer_active
  511. */
  512. smp_rmb();
  513. is_beaconing_active = !!atomic_read(&ppd->led_override_timer_active);
  514. pi->port_states.ledenable_offlinereason |= is_beaconing_active << 6;
  515. pi->port_states.ledenable_offlinereason |=
  516. ppd->offline_disabled_reason;
  517. pi->port_states.portphysstate_portstate =
  518. (hfi1_ibphys_portstate(ppd) << 4) | state;
  519. pi->mkeyprotect_lmc = (ibp->rvp.mkeyprot << 6) | ppd->lmc;
  520. memset(pi->neigh_mtu.pvlx_to_mtu, 0, sizeof(pi->neigh_mtu.pvlx_to_mtu));
  521. for (i = 0; i < ppd->vls_supported; i++) {
  522. mtu = mtu_to_enum(dd->vld[i].mtu, HFI1_DEFAULT_ACTIVE_MTU);
  523. if ((i % 2) == 0)
  524. pi->neigh_mtu.pvlx_to_mtu[i / 2] |= (mtu << 4);
  525. else
  526. pi->neigh_mtu.pvlx_to_mtu[i / 2] |= mtu;
  527. }
  528. /* don't forget VL 15 */
  529. mtu = mtu_to_enum(dd->vld[15].mtu, 2048);
  530. pi->neigh_mtu.pvlx_to_mtu[15 / 2] |= mtu;
  531. pi->smsl = ibp->rvp.sm_sl & OPA_PI_MASK_SMSL;
  532. pi->operational_vls = hfi1_get_ib_cfg(ppd, HFI1_IB_CFG_OP_VLS);
  533. pi->partenforce_filterraw |=
  534. (ppd->linkinit_reason & OPA_PI_MASK_LINKINIT_REASON);
  535. if (ppd->part_enforce & HFI1_PART_ENFORCE_IN)
  536. pi->partenforce_filterraw |= OPA_PI_MASK_PARTITION_ENFORCE_IN;
  537. if (ppd->part_enforce & HFI1_PART_ENFORCE_OUT)
  538. pi->partenforce_filterraw |= OPA_PI_MASK_PARTITION_ENFORCE_OUT;
  539. pi->mkey_violations = cpu_to_be16(ibp->rvp.mkey_violations);
  540. /* P_KeyViolations are counted by hardware. */
  541. pi->pkey_violations = cpu_to_be16(ibp->rvp.pkey_violations);
  542. pi->qkey_violations = cpu_to_be16(ibp->rvp.qkey_violations);
  543. pi->vl.cap = ppd->vls_supported;
  544. pi->vl.high_limit = cpu_to_be16(ibp->rvp.vl_high_limit);
  545. pi->vl.arb_high_cap = (u8)hfi1_get_ib_cfg(ppd, HFI1_IB_CFG_VL_HIGH_CAP);
  546. pi->vl.arb_low_cap = (u8)hfi1_get_ib_cfg(ppd, HFI1_IB_CFG_VL_LOW_CAP);
  547. pi->clientrereg_subnettimeout = ibp->rvp.subnet_timeout;
  548. pi->port_link_mode = cpu_to_be16(OPA_PORT_LINK_MODE_OPA << 10 |
  549. OPA_PORT_LINK_MODE_OPA << 5 |
  550. OPA_PORT_LINK_MODE_OPA);
  551. pi->port_ltp_crc_mode = cpu_to_be16(ppd->port_ltp_crc_mode);
  552. pi->port_mode = cpu_to_be16(
  553. ppd->is_active_optimize_enabled ?
  554. OPA_PI_MASK_PORT_ACTIVE_OPTOMIZE : 0);
  555. pi->port_packet_format.supported =
  556. cpu_to_be16(OPA_PORT_PACKET_FORMAT_9B);
  557. pi->port_packet_format.enabled =
  558. cpu_to_be16(OPA_PORT_PACKET_FORMAT_9B);
  559. /* flit_control.interleave is (OPA V1, version .76):
  560. * bits use
  561. * ---- ---
  562. * 2 res
  563. * 2 DistanceSupported
  564. * 2 DistanceEnabled
  565. * 5 MaxNextLevelTxEnabled
  566. * 5 MaxNestLevelRxSupported
  567. *
  568. * HFI supports only "distance mode 1" (see OPA V1, version .76,
  569. * section 9.6.2), so set DistanceSupported, DistanceEnabled
  570. * to 0x1.
  571. */
  572. pi->flit_control.interleave = cpu_to_be16(0x1400);
  573. pi->link_down_reason = ppd->local_link_down_reason.sma;
  574. pi->neigh_link_down_reason = ppd->neigh_link_down_reason.sma;
  575. pi->port_error_action = cpu_to_be32(ppd->port_error_action);
  576. pi->mtucap = mtu_to_enum(hfi1_max_mtu, IB_MTU_4096);
  577. /* 32.768 usec. response time (guessing) */
  578. pi->resptimevalue = 3;
  579. pi->local_port_num = port;
  580. /* buffer info for FM */
  581. pi->overall_buffer_space = cpu_to_be16(dd->link_credits);
  582. pi->neigh_node_guid = cpu_to_be64(ppd->neighbor_guid);
  583. pi->neigh_port_num = ppd->neighbor_port_number;
  584. pi->port_neigh_mode =
  585. (ppd->neighbor_type & OPA_PI_MASK_NEIGH_NODE_TYPE) |
  586. (ppd->mgmt_allowed ? OPA_PI_MASK_NEIGH_MGMT_ALLOWED : 0) |
  587. (ppd->neighbor_fm_security ?
  588. OPA_PI_MASK_NEIGH_FW_AUTH_BYPASS : 0);
  589. /* HFIs shall always return VL15 credits to their
  590. * neighbor in a timely manner, without any credit return pacing.
  591. */
  592. credit_rate = 0;
  593. buffer_units = (dd->vau) & OPA_PI_MASK_BUF_UNIT_BUF_ALLOC;
  594. buffer_units |= (dd->vcu << 3) & OPA_PI_MASK_BUF_UNIT_CREDIT_ACK;
  595. buffer_units |= (credit_rate << 6) &
  596. OPA_PI_MASK_BUF_UNIT_VL15_CREDIT_RATE;
  597. buffer_units |= (dd->vl15_init << 11) & OPA_PI_MASK_BUF_UNIT_VL15_INIT;
  598. pi->buffer_units = cpu_to_be32(buffer_units);
  599. pi->opa_cap_mask = cpu_to_be16(OPA_CAP_MASK3_IsSharedSpaceSupported);
  600. /* HFI supports a replay buffer 128 LTPs in size */
  601. pi->replay_depth.buffer = 0x80;
  602. /* read the cached value of DC_LCB_STS_ROUND_TRIP_LTP_CNT */
  603. read_lcb_cache(DC_LCB_STS_ROUND_TRIP_LTP_CNT, &tmp);
  604. /*
  605. * this counter is 16 bits wide, but the replay_depth.wire
  606. * variable is only 8 bits
  607. */
  608. if (tmp > 0xff)
  609. tmp = 0xff;
  610. pi->replay_depth.wire = tmp;
  611. if (resp_len)
  612. *resp_len += sizeof(struct opa_port_info);
  613. return reply((struct ib_mad_hdr *)smp);
  614. }
  615. /**
  616. * get_pkeys - return the PKEY table
  617. * @dd: the hfi1_ib device
  618. * @port: the IB port number
  619. * @pkeys: the pkey table is placed here
  620. */
  621. static int get_pkeys(struct hfi1_devdata *dd, u8 port, u16 *pkeys)
  622. {
  623. struct hfi1_pportdata *ppd = dd->pport + port - 1;
  624. memcpy(pkeys, ppd->pkeys, sizeof(ppd->pkeys));
  625. return 0;
  626. }
  627. static int __subn_get_opa_pkeytable(struct opa_smp *smp, u32 am, u8 *data,
  628. struct ib_device *ibdev, u8 port,
  629. u32 *resp_len)
  630. {
  631. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  632. u32 n_blocks_req = OPA_AM_NBLK(am);
  633. u32 start_block = am & 0x7ff;
  634. __be16 *p;
  635. u16 *q;
  636. int i;
  637. u16 n_blocks_avail;
  638. unsigned npkeys = hfi1_get_npkeys(dd);
  639. size_t size;
  640. if (n_blocks_req == 0) {
  641. pr_warn("OPA Get PKey AM Invalid : P = %d; B = 0x%x; N = 0x%x\n",
  642. port, start_block, n_blocks_req);
  643. smp->status |= IB_SMP_INVALID_FIELD;
  644. return reply((struct ib_mad_hdr *)smp);
  645. }
  646. n_blocks_avail = (u16)(npkeys / OPA_PARTITION_TABLE_BLK_SIZE) + 1;
  647. size = (n_blocks_req * OPA_PARTITION_TABLE_BLK_SIZE) * sizeof(u16);
  648. if (start_block + n_blocks_req > n_blocks_avail ||
  649. n_blocks_req > OPA_NUM_PKEY_BLOCKS_PER_SMP) {
  650. pr_warn("OPA Get PKey AM Invalid : s 0x%x; req 0x%x; "
  651. "avail 0x%x; blk/smp 0x%lx\n",
  652. start_block, n_blocks_req, n_blocks_avail,
  653. OPA_NUM_PKEY_BLOCKS_PER_SMP);
  654. smp->status |= IB_SMP_INVALID_FIELD;
  655. return reply((struct ib_mad_hdr *)smp);
  656. }
  657. p = (__be16 *)data;
  658. q = (u16 *)data;
  659. /* get the real pkeys if we are requesting the first block */
  660. if (start_block == 0) {
  661. get_pkeys(dd, port, q);
  662. for (i = 0; i < npkeys; i++)
  663. p[i] = cpu_to_be16(q[i]);
  664. if (resp_len)
  665. *resp_len += size;
  666. } else {
  667. smp->status |= IB_SMP_INVALID_FIELD;
  668. }
  669. return reply((struct ib_mad_hdr *)smp);
  670. }
  671. enum {
  672. HFI_TRANSITION_DISALLOWED,
  673. HFI_TRANSITION_IGNORED,
  674. HFI_TRANSITION_ALLOWED,
  675. HFI_TRANSITION_UNDEFINED,
  676. };
  677. /*
  678. * Use shortened names to improve readability of
  679. * {logical,physical}_state_transitions
  680. */
  681. enum {
  682. __D = HFI_TRANSITION_DISALLOWED,
  683. __I = HFI_TRANSITION_IGNORED,
  684. __A = HFI_TRANSITION_ALLOWED,
  685. __U = HFI_TRANSITION_UNDEFINED,
  686. };
  687. /*
  688. * IB_PORTPHYSSTATE_POLLING (2) through OPA_PORTPHYSSTATE_MAX (11) are
  689. * represented in physical_state_transitions.
  690. */
  691. #define __N_PHYSTATES (OPA_PORTPHYSSTATE_MAX - IB_PORTPHYSSTATE_POLLING + 1)
  692. /*
  693. * Within physical_state_transitions, rows represent "old" states,
  694. * columns "new" states, and physical_state_transitions.allowed[old][new]
  695. * indicates if the transition from old state to new state is legal (see
  696. * OPAg1v1, Table 6-4).
  697. */
  698. static const struct {
  699. u8 allowed[__N_PHYSTATES][__N_PHYSTATES];
  700. } physical_state_transitions = {
  701. {
  702. /* 2 3 4 5 6 7 8 9 10 11 */
  703. /* 2 */ { __A, __A, __D, __D, __D, __D, __D, __D, __D, __D },
  704. /* 3 */ { __A, __I, __D, __D, __D, __D, __D, __D, __D, __A },
  705. /* 4 */ { __U, __U, __U, __U, __U, __U, __U, __U, __U, __U },
  706. /* 5 */ { __A, __A, __D, __I, __D, __D, __D, __D, __D, __D },
  707. /* 6 */ { __U, __U, __U, __U, __U, __U, __U, __U, __U, __U },
  708. /* 7 */ { __D, __A, __D, __D, __D, __I, __D, __D, __D, __D },
  709. /* 8 */ { __U, __U, __U, __U, __U, __U, __U, __U, __U, __U },
  710. /* 9 */ { __I, __A, __D, __D, __D, __D, __D, __I, __D, __D },
  711. /*10 */ { __U, __U, __U, __U, __U, __U, __U, __U, __U, __U },
  712. /*11 */ { __D, __A, __D, __D, __D, __D, __D, __D, __D, __I },
  713. }
  714. };
  715. /*
  716. * IB_PORT_DOWN (1) through IB_PORT_ACTIVE_DEFER (5) are represented
  717. * logical_state_transitions
  718. */
  719. #define __N_LOGICAL_STATES (IB_PORT_ACTIVE_DEFER - IB_PORT_DOWN + 1)
  720. /*
  721. * Within logical_state_transitions rows represent "old" states,
  722. * columns "new" states, and logical_state_transitions.allowed[old][new]
  723. * indicates if the transition from old state to new state is legal (see
  724. * OPAg1v1, Table 9-12).
  725. */
  726. static const struct {
  727. u8 allowed[__N_LOGICAL_STATES][__N_LOGICAL_STATES];
  728. } logical_state_transitions = {
  729. {
  730. /* 1 2 3 4 5 */
  731. /* 1 */ { __I, __D, __D, __D, __U},
  732. /* 2 */ { __D, __I, __A, __D, __U},
  733. /* 3 */ { __D, __D, __I, __A, __U},
  734. /* 4 */ { __D, __D, __I, __I, __U},
  735. /* 5 */ { __U, __U, __U, __U, __U},
  736. }
  737. };
  738. static int logical_transition_allowed(int old, int new)
  739. {
  740. if (old < IB_PORT_NOP || old > IB_PORT_ACTIVE_DEFER ||
  741. new < IB_PORT_NOP || new > IB_PORT_ACTIVE_DEFER) {
  742. pr_warn("invalid logical state(s) (old %d new %d)\n",
  743. old, new);
  744. return HFI_TRANSITION_UNDEFINED;
  745. }
  746. if (new == IB_PORT_NOP)
  747. return HFI_TRANSITION_ALLOWED; /* always allowed */
  748. /* adjust states for indexing into logical_state_transitions */
  749. old -= IB_PORT_DOWN;
  750. new -= IB_PORT_DOWN;
  751. if (old < 0 || new < 0)
  752. return HFI_TRANSITION_UNDEFINED;
  753. return logical_state_transitions.allowed[old][new];
  754. }
  755. static int physical_transition_allowed(int old, int new)
  756. {
  757. if (old < IB_PORTPHYSSTATE_NOP || old > OPA_PORTPHYSSTATE_MAX ||
  758. new < IB_PORTPHYSSTATE_NOP || new > OPA_PORTPHYSSTATE_MAX) {
  759. pr_warn("invalid physical state(s) (old %d new %d)\n",
  760. old, new);
  761. return HFI_TRANSITION_UNDEFINED;
  762. }
  763. if (new == IB_PORTPHYSSTATE_NOP)
  764. return HFI_TRANSITION_ALLOWED; /* always allowed */
  765. /* adjust states for indexing into physical_state_transitions */
  766. old -= IB_PORTPHYSSTATE_POLLING;
  767. new -= IB_PORTPHYSSTATE_POLLING;
  768. if (old < 0 || new < 0)
  769. return HFI_TRANSITION_UNDEFINED;
  770. return physical_state_transitions.allowed[old][new];
  771. }
  772. static int port_states_transition_allowed(struct hfi1_pportdata *ppd,
  773. u32 logical_new, u32 physical_new)
  774. {
  775. u32 physical_old = driver_physical_state(ppd);
  776. u32 logical_old = driver_logical_state(ppd);
  777. int ret, logical_allowed, physical_allowed;
  778. ret = logical_transition_allowed(logical_old, logical_new);
  779. logical_allowed = ret;
  780. if (ret == HFI_TRANSITION_DISALLOWED ||
  781. ret == HFI_TRANSITION_UNDEFINED) {
  782. pr_warn("invalid logical state transition %s -> %s\n",
  783. opa_lstate_name(logical_old),
  784. opa_lstate_name(logical_new));
  785. return ret;
  786. }
  787. ret = physical_transition_allowed(physical_old, physical_new);
  788. physical_allowed = ret;
  789. if (ret == HFI_TRANSITION_DISALLOWED ||
  790. ret == HFI_TRANSITION_UNDEFINED) {
  791. pr_warn("invalid physical state transition %s -> %s\n",
  792. opa_pstate_name(physical_old),
  793. opa_pstate_name(physical_new));
  794. return ret;
  795. }
  796. if (logical_allowed == HFI_TRANSITION_IGNORED &&
  797. physical_allowed == HFI_TRANSITION_IGNORED)
  798. return HFI_TRANSITION_IGNORED;
  799. /*
  800. * A change request of Physical Port State from
  801. * 'Offline' to 'Polling' should be ignored.
  802. */
  803. if ((physical_old == OPA_PORTPHYSSTATE_OFFLINE) &&
  804. (physical_new == IB_PORTPHYSSTATE_POLLING))
  805. return HFI_TRANSITION_IGNORED;
  806. /*
  807. * Either physical_allowed or logical_allowed is
  808. * HFI_TRANSITION_ALLOWED.
  809. */
  810. return HFI_TRANSITION_ALLOWED;
  811. }
  812. static int set_port_states(struct hfi1_pportdata *ppd, struct opa_smp *smp,
  813. u32 logical_state, u32 phys_state,
  814. int suppress_idle_sma)
  815. {
  816. struct hfi1_devdata *dd = ppd->dd;
  817. u32 link_state;
  818. int ret;
  819. ret = port_states_transition_allowed(ppd, logical_state, phys_state);
  820. if (ret == HFI_TRANSITION_DISALLOWED ||
  821. ret == HFI_TRANSITION_UNDEFINED) {
  822. /* error message emitted above */
  823. smp->status |= IB_SMP_INVALID_FIELD;
  824. return 0;
  825. }
  826. if (ret == HFI_TRANSITION_IGNORED)
  827. return 0;
  828. if ((phys_state != IB_PORTPHYSSTATE_NOP) &&
  829. !(logical_state == IB_PORT_DOWN ||
  830. logical_state == IB_PORT_NOP)){
  831. pr_warn("SubnSet(OPA_PortInfo) port state invalid: logical_state 0x%x physical_state 0x%x\n",
  832. logical_state, phys_state);
  833. smp->status |= IB_SMP_INVALID_FIELD;
  834. }
  835. /*
  836. * Logical state changes are summarized in OPAv1g1 spec.,
  837. * Table 9-12; physical state changes are summarized in
  838. * OPAv1g1 spec., Table 6.4.
  839. */
  840. switch (logical_state) {
  841. case IB_PORT_NOP:
  842. if (phys_state == IB_PORTPHYSSTATE_NOP)
  843. break;
  844. /* FALLTHROUGH */
  845. case IB_PORT_DOWN:
  846. if (phys_state == IB_PORTPHYSSTATE_NOP) {
  847. link_state = HLS_DN_DOWNDEF;
  848. } else if (phys_state == IB_PORTPHYSSTATE_POLLING) {
  849. link_state = HLS_DN_POLL;
  850. set_link_down_reason(ppd, OPA_LINKDOWN_REASON_FM_BOUNCE,
  851. 0, OPA_LINKDOWN_REASON_FM_BOUNCE);
  852. } else if (phys_state == IB_PORTPHYSSTATE_DISABLED) {
  853. link_state = HLS_DN_DISABLE;
  854. } else {
  855. pr_warn("SubnSet(OPA_PortInfo) invalid physical state 0x%x\n",
  856. phys_state);
  857. smp->status |= IB_SMP_INVALID_FIELD;
  858. break;
  859. }
  860. if ((link_state == HLS_DN_POLL ||
  861. link_state == HLS_DN_DOWNDEF)) {
  862. /*
  863. * Going to poll. No matter what the current state,
  864. * always move offline first, then tune and start the
  865. * link. This correctly handles a FM link bounce and
  866. * a link enable. Going offline is a no-op if already
  867. * offline.
  868. */
  869. set_link_state(ppd, HLS_DN_OFFLINE);
  870. tune_serdes(ppd);
  871. start_link(ppd);
  872. } else {
  873. set_link_state(ppd, link_state);
  874. }
  875. if (link_state == HLS_DN_DISABLE &&
  876. (ppd->offline_disabled_reason >
  877. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_SMA_DISABLED) ||
  878. ppd->offline_disabled_reason ==
  879. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE)))
  880. ppd->offline_disabled_reason =
  881. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_SMA_DISABLED);
  882. /*
  883. * Don't send a reply if the response would be sent
  884. * through the disabled port.
  885. */
  886. if (link_state == HLS_DN_DISABLE && smp->hop_cnt)
  887. return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
  888. break;
  889. case IB_PORT_ARMED:
  890. ret = set_link_state(ppd, HLS_UP_ARMED);
  891. if ((ret == 0) && (suppress_idle_sma == 0))
  892. send_idle_sma(dd, SMA_IDLE_ARM);
  893. break;
  894. case IB_PORT_ACTIVE:
  895. if (ppd->neighbor_normal) {
  896. ret = set_link_state(ppd, HLS_UP_ACTIVE);
  897. if (ret == 0)
  898. send_idle_sma(dd, SMA_IDLE_ACTIVE);
  899. } else {
  900. pr_warn("SubnSet(OPA_PortInfo) Cannot move to Active with NeighborNormal 0\n");
  901. smp->status |= IB_SMP_INVALID_FIELD;
  902. }
  903. break;
  904. default:
  905. pr_warn("SubnSet(OPA_PortInfo) invalid logical state 0x%x\n",
  906. logical_state);
  907. smp->status |= IB_SMP_INVALID_FIELD;
  908. }
  909. return 0;
  910. }
  911. /**
  912. * subn_set_opa_portinfo - set port information
  913. * @smp: the incoming SM packet
  914. * @ibdev: the infiniband device
  915. * @port: the port on the device
  916. *
  917. */
  918. static int __subn_set_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data,
  919. struct ib_device *ibdev, u8 port,
  920. u32 *resp_len)
  921. {
  922. struct opa_port_info *pi = (struct opa_port_info *)data;
  923. struct ib_event event;
  924. struct hfi1_devdata *dd;
  925. struct hfi1_pportdata *ppd;
  926. struct hfi1_ibport *ibp;
  927. u8 clientrereg;
  928. unsigned long flags;
  929. u32 smlid, opa_lid; /* tmp vars to hold LID values */
  930. u16 lid;
  931. u8 ls_old, ls_new, ps_new;
  932. u8 vls;
  933. u8 msl;
  934. u8 crc_enabled;
  935. u16 lse, lwe, mtu;
  936. u32 num_ports = OPA_AM_NPORT(am);
  937. u32 start_of_sm_config = OPA_AM_START_SM_CFG(am);
  938. int ret, i, invalid = 0, call_set_mtu = 0;
  939. int call_link_downgrade_policy = 0;
  940. if (num_ports != 1) {
  941. smp->status |= IB_SMP_INVALID_FIELD;
  942. return reply((struct ib_mad_hdr *)smp);
  943. }
  944. opa_lid = be32_to_cpu(pi->lid);
  945. if (opa_lid & 0xFFFF0000) {
  946. pr_warn("OPA_PortInfo lid out of range: %X\n", opa_lid);
  947. smp->status |= IB_SMP_INVALID_FIELD;
  948. goto get_only;
  949. }
  950. lid = (u16)(opa_lid & 0x0000FFFF);
  951. smlid = be32_to_cpu(pi->sm_lid);
  952. if (smlid & 0xFFFF0000) {
  953. pr_warn("OPA_PortInfo SM lid out of range: %X\n", smlid);
  954. smp->status |= IB_SMP_INVALID_FIELD;
  955. goto get_only;
  956. }
  957. smlid &= 0x0000FFFF;
  958. clientrereg = (pi->clientrereg_subnettimeout &
  959. OPA_PI_MASK_CLIENT_REREGISTER);
  960. dd = dd_from_ibdev(ibdev);
  961. /* IB numbers ports from 1, hw from 0 */
  962. ppd = dd->pport + (port - 1);
  963. ibp = &ppd->ibport_data;
  964. event.device = ibdev;
  965. event.element.port_num = port;
  966. ls_old = driver_lstate(ppd);
  967. ibp->rvp.mkey = pi->mkey;
  968. ibp->rvp.gid_prefix = pi->subnet_prefix;
  969. ibp->rvp.mkey_lease_period = be16_to_cpu(pi->mkey_lease_period);
  970. /* Must be a valid unicast LID address. */
  971. if ((lid == 0 && ls_old > IB_PORT_INIT) ||
  972. lid >= be16_to_cpu(IB_MULTICAST_LID_BASE)) {
  973. smp->status |= IB_SMP_INVALID_FIELD;
  974. pr_warn("SubnSet(OPA_PortInfo) lid invalid 0x%x\n",
  975. lid);
  976. } else if (ppd->lid != lid ||
  977. ppd->lmc != (pi->mkeyprotect_lmc & OPA_PI_MASK_LMC)) {
  978. if (ppd->lid != lid)
  979. hfi1_set_uevent_bits(ppd, _HFI1_EVENT_LID_CHANGE_BIT);
  980. if (ppd->lmc != (pi->mkeyprotect_lmc & OPA_PI_MASK_LMC))
  981. hfi1_set_uevent_bits(ppd, _HFI1_EVENT_LMC_CHANGE_BIT);
  982. hfi1_set_lid(ppd, lid, pi->mkeyprotect_lmc & OPA_PI_MASK_LMC);
  983. event.event = IB_EVENT_LID_CHANGE;
  984. ib_dispatch_event(&event);
  985. }
  986. msl = pi->smsl & OPA_PI_MASK_SMSL;
  987. if (pi->partenforce_filterraw & OPA_PI_MASK_LINKINIT_REASON)
  988. ppd->linkinit_reason =
  989. (pi->partenforce_filterraw &
  990. OPA_PI_MASK_LINKINIT_REASON);
  991. /* enable/disable SW pkey checking as per FM control */
  992. if (pi->partenforce_filterraw & OPA_PI_MASK_PARTITION_ENFORCE_IN)
  993. ppd->part_enforce |= HFI1_PART_ENFORCE_IN;
  994. else
  995. ppd->part_enforce &= ~HFI1_PART_ENFORCE_IN;
  996. if (pi->partenforce_filterraw & OPA_PI_MASK_PARTITION_ENFORCE_OUT)
  997. ppd->part_enforce |= HFI1_PART_ENFORCE_OUT;
  998. else
  999. ppd->part_enforce &= ~HFI1_PART_ENFORCE_OUT;
  1000. /* Must be a valid unicast LID address. */
  1001. if ((smlid == 0 && ls_old > IB_PORT_INIT) ||
  1002. smlid >= be16_to_cpu(IB_MULTICAST_LID_BASE)) {
  1003. smp->status |= IB_SMP_INVALID_FIELD;
  1004. pr_warn("SubnSet(OPA_PortInfo) smlid invalid 0x%x\n", smlid);
  1005. } else if (smlid != ibp->rvp.sm_lid || msl != ibp->rvp.sm_sl) {
  1006. pr_warn("SubnSet(OPA_PortInfo) smlid 0x%x\n", smlid);
  1007. spin_lock_irqsave(&ibp->rvp.lock, flags);
  1008. if (ibp->rvp.sm_ah) {
  1009. if (smlid != ibp->rvp.sm_lid)
  1010. ibp->rvp.sm_ah->attr.dlid = smlid;
  1011. if (msl != ibp->rvp.sm_sl)
  1012. ibp->rvp.sm_ah->attr.sl = msl;
  1013. }
  1014. spin_unlock_irqrestore(&ibp->rvp.lock, flags);
  1015. if (smlid != ibp->rvp.sm_lid)
  1016. ibp->rvp.sm_lid = smlid;
  1017. if (msl != ibp->rvp.sm_sl)
  1018. ibp->rvp.sm_sl = msl;
  1019. event.event = IB_EVENT_SM_CHANGE;
  1020. ib_dispatch_event(&event);
  1021. }
  1022. if (pi->link_down_reason == 0) {
  1023. ppd->local_link_down_reason.sma = 0;
  1024. ppd->local_link_down_reason.latest = 0;
  1025. }
  1026. if (pi->neigh_link_down_reason == 0) {
  1027. ppd->neigh_link_down_reason.sma = 0;
  1028. ppd->neigh_link_down_reason.latest = 0;
  1029. }
  1030. ppd->sm_trap_qp = be32_to_cpu(pi->sm_trap_qp);
  1031. ppd->sa_qp = be32_to_cpu(pi->sa_qp);
  1032. ppd->port_error_action = be32_to_cpu(pi->port_error_action);
  1033. lwe = be16_to_cpu(pi->link_width.enabled);
  1034. if (lwe) {
  1035. if (lwe == OPA_LINK_WIDTH_RESET ||
  1036. lwe == OPA_LINK_WIDTH_RESET_OLD)
  1037. set_link_width_enabled(ppd, ppd->link_width_supported);
  1038. else if ((lwe & ~ppd->link_width_supported) == 0)
  1039. set_link_width_enabled(ppd, lwe);
  1040. else
  1041. smp->status |= IB_SMP_INVALID_FIELD;
  1042. }
  1043. lwe = be16_to_cpu(pi->link_width_downgrade.enabled);
  1044. /* LWD.E is always applied - 0 means "disabled" */
  1045. if (lwe == OPA_LINK_WIDTH_RESET ||
  1046. lwe == OPA_LINK_WIDTH_RESET_OLD) {
  1047. set_link_width_downgrade_enabled(ppd,
  1048. ppd->
  1049. link_width_downgrade_supported
  1050. );
  1051. } else if ((lwe & ~ppd->link_width_downgrade_supported) == 0) {
  1052. /* only set and apply if something changed */
  1053. if (lwe != ppd->link_width_downgrade_enabled) {
  1054. set_link_width_downgrade_enabled(ppd, lwe);
  1055. call_link_downgrade_policy = 1;
  1056. }
  1057. } else {
  1058. smp->status |= IB_SMP_INVALID_FIELD;
  1059. }
  1060. lse = be16_to_cpu(pi->link_speed.enabled);
  1061. if (lse) {
  1062. if (lse & be16_to_cpu(pi->link_speed.supported))
  1063. set_link_speed_enabled(ppd, lse);
  1064. else
  1065. smp->status |= IB_SMP_INVALID_FIELD;
  1066. }
  1067. ibp->rvp.mkeyprot =
  1068. (pi->mkeyprotect_lmc & OPA_PI_MASK_MKEY_PROT_BIT) >> 6;
  1069. ibp->rvp.vl_high_limit = be16_to_cpu(pi->vl.high_limit) & 0xFF;
  1070. (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_VL_HIGH_LIMIT,
  1071. ibp->rvp.vl_high_limit);
  1072. if (ppd->vls_supported / 2 > ARRAY_SIZE(pi->neigh_mtu.pvlx_to_mtu) ||
  1073. ppd->vls_supported > ARRAY_SIZE(dd->vld)) {
  1074. smp->status |= IB_SMP_INVALID_FIELD;
  1075. return reply((struct ib_mad_hdr *)smp);
  1076. }
  1077. for (i = 0; i < ppd->vls_supported; i++) {
  1078. if ((i % 2) == 0)
  1079. mtu = enum_to_mtu((pi->neigh_mtu.pvlx_to_mtu[i / 2] >>
  1080. 4) & 0xF);
  1081. else
  1082. mtu = enum_to_mtu(pi->neigh_mtu.pvlx_to_mtu[i / 2] &
  1083. 0xF);
  1084. if (mtu == 0xffff) {
  1085. pr_warn("SubnSet(OPA_PortInfo) mtu invalid %d (0x%x)\n",
  1086. mtu,
  1087. (pi->neigh_mtu.pvlx_to_mtu[0] >> 4) & 0xF);
  1088. smp->status |= IB_SMP_INVALID_FIELD;
  1089. mtu = hfi1_max_mtu; /* use a valid MTU */
  1090. }
  1091. if (dd->vld[i].mtu != mtu) {
  1092. dd_dev_info(dd,
  1093. "MTU change on vl %d from %d to %d\n",
  1094. i, dd->vld[i].mtu, mtu);
  1095. dd->vld[i].mtu = mtu;
  1096. call_set_mtu++;
  1097. }
  1098. }
  1099. /* As per OPAV1 spec: VL15 must support and be configured
  1100. * for operation with a 2048 or larger MTU.
  1101. */
  1102. mtu = enum_to_mtu(pi->neigh_mtu.pvlx_to_mtu[15 / 2] & 0xF);
  1103. if (mtu < 2048 || mtu == 0xffff)
  1104. mtu = 2048;
  1105. if (dd->vld[15].mtu != mtu) {
  1106. dd_dev_info(dd,
  1107. "MTU change on vl 15 from %d to %d\n",
  1108. dd->vld[15].mtu, mtu);
  1109. dd->vld[15].mtu = mtu;
  1110. call_set_mtu++;
  1111. }
  1112. if (call_set_mtu)
  1113. set_mtu(ppd);
  1114. /* Set operational VLs */
  1115. vls = pi->operational_vls & OPA_PI_MASK_OPERATIONAL_VL;
  1116. if (vls) {
  1117. if (vls > ppd->vls_supported) {
  1118. pr_warn("SubnSet(OPA_PortInfo) VL's supported invalid %d\n",
  1119. pi->operational_vls);
  1120. smp->status |= IB_SMP_INVALID_FIELD;
  1121. } else {
  1122. if (hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_OP_VLS,
  1123. vls) == -EINVAL)
  1124. smp->status |= IB_SMP_INVALID_FIELD;
  1125. }
  1126. }
  1127. if (pi->mkey_violations == 0)
  1128. ibp->rvp.mkey_violations = 0;
  1129. if (pi->pkey_violations == 0)
  1130. ibp->rvp.pkey_violations = 0;
  1131. if (pi->qkey_violations == 0)
  1132. ibp->rvp.qkey_violations = 0;
  1133. ibp->rvp.subnet_timeout =
  1134. pi->clientrereg_subnettimeout & OPA_PI_MASK_SUBNET_TIMEOUT;
  1135. crc_enabled = be16_to_cpu(pi->port_ltp_crc_mode);
  1136. crc_enabled >>= 4;
  1137. crc_enabled &= 0xf;
  1138. if (crc_enabled != 0)
  1139. ppd->port_crc_mode_enabled = port_ltp_to_cap(crc_enabled);
  1140. ppd->is_active_optimize_enabled =
  1141. !!(be16_to_cpu(pi->port_mode)
  1142. & OPA_PI_MASK_PORT_ACTIVE_OPTOMIZE);
  1143. ls_new = pi->port_states.portphysstate_portstate &
  1144. OPA_PI_MASK_PORT_STATE;
  1145. ps_new = (pi->port_states.portphysstate_portstate &
  1146. OPA_PI_MASK_PORT_PHYSICAL_STATE) >> 4;
  1147. if (ls_old == IB_PORT_INIT) {
  1148. if (start_of_sm_config) {
  1149. if (ls_new == ls_old || (ls_new == IB_PORT_ARMED))
  1150. ppd->is_sm_config_started = 1;
  1151. } else if (ls_new == IB_PORT_ARMED) {
  1152. if (ppd->is_sm_config_started == 0)
  1153. invalid = 1;
  1154. }
  1155. }
  1156. /* Handle CLIENT_REREGISTER event b/c SM asked us for it */
  1157. if (clientrereg) {
  1158. event.event = IB_EVENT_CLIENT_REREGISTER;
  1159. ib_dispatch_event(&event);
  1160. }
  1161. /*
  1162. * Do the port state change now that the other link parameters
  1163. * have been set.
  1164. * Changing the port physical state only makes sense if the link
  1165. * is down or is being set to down.
  1166. */
  1167. ret = set_port_states(ppd, smp, ls_new, ps_new, invalid);
  1168. if (ret)
  1169. return ret;
  1170. ret = __subn_get_opa_portinfo(smp, am, data, ibdev, port, resp_len);
  1171. /* restore re-reg bit per o14-12.2.1 */
  1172. pi->clientrereg_subnettimeout |= clientrereg;
  1173. /*
  1174. * Apply the new link downgrade policy. This may result in a link
  1175. * bounce. Do this after everything else so things are settled.
  1176. * Possible problem: if setting the port state above fails, then
  1177. * the policy change is not applied.
  1178. */
  1179. if (call_link_downgrade_policy)
  1180. apply_link_downgrade_policy(ppd, 0);
  1181. return ret;
  1182. get_only:
  1183. return __subn_get_opa_portinfo(smp, am, data, ibdev, port, resp_len);
  1184. }
  1185. /**
  1186. * set_pkeys - set the PKEY table for ctxt 0
  1187. * @dd: the hfi1_ib device
  1188. * @port: the IB port number
  1189. * @pkeys: the PKEY table
  1190. */
  1191. static int set_pkeys(struct hfi1_devdata *dd, u8 port, u16 *pkeys)
  1192. {
  1193. struct hfi1_pportdata *ppd;
  1194. int i;
  1195. int changed = 0;
  1196. int update_includes_mgmt_partition = 0;
  1197. /*
  1198. * IB port one/two always maps to context zero/one,
  1199. * always a kernel context, no locking needed
  1200. * If we get here with ppd setup, no need to check
  1201. * that rcd is valid.
  1202. */
  1203. ppd = dd->pport + (port - 1);
  1204. /*
  1205. * If the update does not include the management pkey, don't do it.
  1206. */
  1207. for (i = 0; i < ARRAY_SIZE(ppd->pkeys); i++) {
  1208. if (pkeys[i] == LIM_MGMT_P_KEY) {
  1209. update_includes_mgmt_partition = 1;
  1210. break;
  1211. }
  1212. }
  1213. if (!update_includes_mgmt_partition)
  1214. return 1;
  1215. for (i = 0; i < ARRAY_SIZE(ppd->pkeys); i++) {
  1216. u16 key = pkeys[i];
  1217. u16 okey = ppd->pkeys[i];
  1218. if (key == okey)
  1219. continue;
  1220. /*
  1221. * Don't update pkeys[2], if an HFI port without MgmtAllowed
  1222. * by neighbor is a switch.
  1223. */
  1224. if (i == 2 && !ppd->mgmt_allowed && ppd->neighbor_type == 1)
  1225. continue;
  1226. /*
  1227. * The SM gives us the complete PKey table. We have
  1228. * to ensure that we put the PKeys in the matching
  1229. * slots.
  1230. */
  1231. ppd->pkeys[i] = key;
  1232. changed = 1;
  1233. }
  1234. if (changed) {
  1235. (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0);
  1236. hfi1_event_pkey_change(dd, port);
  1237. }
  1238. return 0;
  1239. }
  1240. static int __subn_set_opa_pkeytable(struct opa_smp *smp, u32 am, u8 *data,
  1241. struct ib_device *ibdev, u8 port,
  1242. u32 *resp_len)
  1243. {
  1244. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  1245. u32 n_blocks_sent = OPA_AM_NBLK(am);
  1246. u32 start_block = am & 0x7ff;
  1247. u16 *p = (u16 *)data;
  1248. __be16 *q = (__be16 *)data;
  1249. int i;
  1250. u16 n_blocks_avail;
  1251. unsigned npkeys = hfi1_get_npkeys(dd);
  1252. if (n_blocks_sent == 0) {
  1253. pr_warn("OPA Get PKey AM Invalid : P = %d; B = 0x%x; N = 0x%x\n",
  1254. port, start_block, n_blocks_sent);
  1255. smp->status |= IB_SMP_INVALID_FIELD;
  1256. return reply((struct ib_mad_hdr *)smp);
  1257. }
  1258. n_blocks_avail = (u16)(npkeys / OPA_PARTITION_TABLE_BLK_SIZE) + 1;
  1259. if (start_block + n_blocks_sent > n_blocks_avail ||
  1260. n_blocks_sent > OPA_NUM_PKEY_BLOCKS_PER_SMP) {
  1261. pr_warn("OPA Set PKey AM Invalid : s 0x%x; req 0x%x; avail 0x%x; blk/smp 0x%lx\n",
  1262. start_block, n_blocks_sent, n_blocks_avail,
  1263. OPA_NUM_PKEY_BLOCKS_PER_SMP);
  1264. smp->status |= IB_SMP_INVALID_FIELD;
  1265. return reply((struct ib_mad_hdr *)smp);
  1266. }
  1267. for (i = 0; i < n_blocks_sent * OPA_PARTITION_TABLE_BLK_SIZE; i++)
  1268. p[i] = be16_to_cpu(q[i]);
  1269. if (start_block == 0 && set_pkeys(dd, port, p) != 0) {
  1270. smp->status |= IB_SMP_INVALID_FIELD;
  1271. return reply((struct ib_mad_hdr *)smp);
  1272. }
  1273. return __subn_get_opa_pkeytable(smp, am, data, ibdev, port, resp_len);
  1274. }
  1275. static int get_sc2vlt_tables(struct hfi1_devdata *dd, void *data)
  1276. {
  1277. u64 *val = data;
  1278. *val++ = read_csr(dd, SEND_SC2VLT0);
  1279. *val++ = read_csr(dd, SEND_SC2VLT1);
  1280. *val++ = read_csr(dd, SEND_SC2VLT2);
  1281. *val++ = read_csr(dd, SEND_SC2VLT3);
  1282. return 0;
  1283. }
  1284. #define ILLEGAL_VL 12
  1285. /*
  1286. * filter_sc2vlt changes mappings to VL15 to ILLEGAL_VL (except
  1287. * for SC15, which must map to VL15). If we don't remap things this
  1288. * way it is possible for VL15 counters to increment when we try to
  1289. * send on a SC which is mapped to an invalid VL.
  1290. */
  1291. static void filter_sc2vlt(void *data)
  1292. {
  1293. int i;
  1294. u8 *pd = data;
  1295. for (i = 0; i < OPA_MAX_SCS; i++) {
  1296. if (i == 15)
  1297. continue;
  1298. if ((pd[i] & 0x1f) == 0xf)
  1299. pd[i] = ILLEGAL_VL;
  1300. }
  1301. }
  1302. static int set_sc2vlt_tables(struct hfi1_devdata *dd, void *data)
  1303. {
  1304. u64 *val = data;
  1305. filter_sc2vlt(data);
  1306. write_csr(dd, SEND_SC2VLT0, *val++);
  1307. write_csr(dd, SEND_SC2VLT1, *val++);
  1308. write_csr(dd, SEND_SC2VLT2, *val++);
  1309. write_csr(dd, SEND_SC2VLT3, *val++);
  1310. write_seqlock_irq(&dd->sc2vl_lock);
  1311. memcpy(dd->sc2vl, data, sizeof(dd->sc2vl));
  1312. write_sequnlock_irq(&dd->sc2vl_lock);
  1313. return 0;
  1314. }
  1315. static int __subn_get_opa_sl_to_sc(struct opa_smp *smp, u32 am, u8 *data,
  1316. struct ib_device *ibdev, u8 port,
  1317. u32 *resp_len)
  1318. {
  1319. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  1320. u8 *p = data;
  1321. size_t size = ARRAY_SIZE(ibp->sl_to_sc); /* == 32 */
  1322. unsigned i;
  1323. if (am) {
  1324. smp->status |= IB_SMP_INVALID_FIELD;
  1325. return reply((struct ib_mad_hdr *)smp);
  1326. }
  1327. for (i = 0; i < ARRAY_SIZE(ibp->sl_to_sc); i++)
  1328. *p++ = ibp->sl_to_sc[i];
  1329. if (resp_len)
  1330. *resp_len += size;
  1331. return reply((struct ib_mad_hdr *)smp);
  1332. }
  1333. static int __subn_set_opa_sl_to_sc(struct opa_smp *smp, u32 am, u8 *data,
  1334. struct ib_device *ibdev, u8 port,
  1335. u32 *resp_len)
  1336. {
  1337. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  1338. u8 *p = data;
  1339. int i;
  1340. u8 sc;
  1341. if (am) {
  1342. smp->status |= IB_SMP_INVALID_FIELD;
  1343. return reply((struct ib_mad_hdr *)smp);
  1344. }
  1345. for (i = 0; i < ARRAY_SIZE(ibp->sl_to_sc); i++) {
  1346. sc = *p++;
  1347. if (ibp->sl_to_sc[i] != sc) {
  1348. ibp->sl_to_sc[i] = sc;
  1349. /* Put all stale qps into error state */
  1350. hfi1_error_port_qps(ibp, i);
  1351. }
  1352. }
  1353. return __subn_get_opa_sl_to_sc(smp, am, data, ibdev, port, resp_len);
  1354. }
  1355. static int __subn_get_opa_sc_to_sl(struct opa_smp *smp, u32 am, u8 *data,
  1356. struct ib_device *ibdev, u8 port,
  1357. u32 *resp_len)
  1358. {
  1359. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  1360. u8 *p = data;
  1361. size_t size = ARRAY_SIZE(ibp->sc_to_sl); /* == 32 */
  1362. unsigned i;
  1363. if (am) {
  1364. smp->status |= IB_SMP_INVALID_FIELD;
  1365. return reply((struct ib_mad_hdr *)smp);
  1366. }
  1367. for (i = 0; i < ARRAY_SIZE(ibp->sc_to_sl); i++)
  1368. *p++ = ibp->sc_to_sl[i];
  1369. if (resp_len)
  1370. *resp_len += size;
  1371. return reply((struct ib_mad_hdr *)smp);
  1372. }
  1373. static int __subn_set_opa_sc_to_sl(struct opa_smp *smp, u32 am, u8 *data,
  1374. struct ib_device *ibdev, u8 port,
  1375. u32 *resp_len)
  1376. {
  1377. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  1378. u8 *p = data;
  1379. int i;
  1380. if (am) {
  1381. smp->status |= IB_SMP_INVALID_FIELD;
  1382. return reply((struct ib_mad_hdr *)smp);
  1383. }
  1384. for (i = 0; i < ARRAY_SIZE(ibp->sc_to_sl); i++)
  1385. ibp->sc_to_sl[i] = *p++;
  1386. return __subn_get_opa_sc_to_sl(smp, am, data, ibdev, port, resp_len);
  1387. }
  1388. static int __subn_get_opa_sc_to_vlt(struct opa_smp *smp, u32 am, u8 *data,
  1389. struct ib_device *ibdev, u8 port,
  1390. u32 *resp_len)
  1391. {
  1392. u32 n_blocks = OPA_AM_NBLK(am);
  1393. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  1394. void *vp = (void *)data;
  1395. size_t size = 4 * sizeof(u64);
  1396. if (n_blocks != 1) {
  1397. smp->status |= IB_SMP_INVALID_FIELD;
  1398. return reply((struct ib_mad_hdr *)smp);
  1399. }
  1400. get_sc2vlt_tables(dd, vp);
  1401. if (resp_len)
  1402. *resp_len += size;
  1403. return reply((struct ib_mad_hdr *)smp);
  1404. }
  1405. static int __subn_set_opa_sc_to_vlt(struct opa_smp *smp, u32 am, u8 *data,
  1406. struct ib_device *ibdev, u8 port,
  1407. u32 *resp_len)
  1408. {
  1409. u32 n_blocks = OPA_AM_NBLK(am);
  1410. int async_update = OPA_AM_ASYNC(am);
  1411. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  1412. void *vp = (void *)data;
  1413. struct hfi1_pportdata *ppd;
  1414. int lstate;
  1415. if (n_blocks != 1 || async_update) {
  1416. smp->status |= IB_SMP_INVALID_FIELD;
  1417. return reply((struct ib_mad_hdr *)smp);
  1418. }
  1419. /* IB numbers ports from 1, hw from 0 */
  1420. ppd = dd->pport + (port - 1);
  1421. lstate = driver_lstate(ppd);
  1422. /*
  1423. * it's known that async_update is 0 by this point, but include
  1424. * the explicit check for clarity
  1425. */
  1426. if (!async_update &&
  1427. (lstate == IB_PORT_ARMED || lstate == IB_PORT_ACTIVE)) {
  1428. smp->status |= IB_SMP_INVALID_FIELD;
  1429. return reply((struct ib_mad_hdr *)smp);
  1430. }
  1431. set_sc2vlt_tables(dd, vp);
  1432. return __subn_get_opa_sc_to_vlt(smp, am, data, ibdev, port, resp_len);
  1433. }
  1434. static int __subn_get_opa_sc_to_vlnt(struct opa_smp *smp, u32 am, u8 *data,
  1435. struct ib_device *ibdev, u8 port,
  1436. u32 *resp_len)
  1437. {
  1438. u32 n_blocks = OPA_AM_NPORT(am);
  1439. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  1440. struct hfi1_pportdata *ppd;
  1441. void *vp = (void *)data;
  1442. int size;
  1443. if (n_blocks != 1) {
  1444. smp->status |= IB_SMP_INVALID_FIELD;
  1445. return reply((struct ib_mad_hdr *)smp);
  1446. }
  1447. ppd = dd->pport + (port - 1);
  1448. size = fm_get_table(ppd, FM_TBL_SC2VLNT, vp);
  1449. if (resp_len)
  1450. *resp_len += size;
  1451. return reply((struct ib_mad_hdr *)smp);
  1452. }
  1453. static int __subn_set_opa_sc_to_vlnt(struct opa_smp *smp, u32 am, u8 *data,
  1454. struct ib_device *ibdev, u8 port,
  1455. u32 *resp_len)
  1456. {
  1457. u32 n_blocks = OPA_AM_NPORT(am);
  1458. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  1459. struct hfi1_pportdata *ppd;
  1460. void *vp = (void *)data;
  1461. int lstate;
  1462. if (n_blocks != 1) {
  1463. smp->status |= IB_SMP_INVALID_FIELD;
  1464. return reply((struct ib_mad_hdr *)smp);
  1465. }
  1466. /* IB numbers ports from 1, hw from 0 */
  1467. ppd = dd->pport + (port - 1);
  1468. lstate = driver_lstate(ppd);
  1469. if (lstate == IB_PORT_ARMED || lstate == IB_PORT_ACTIVE) {
  1470. smp->status |= IB_SMP_INVALID_FIELD;
  1471. return reply((struct ib_mad_hdr *)smp);
  1472. }
  1473. ppd = dd->pport + (port - 1);
  1474. fm_set_table(ppd, FM_TBL_SC2VLNT, vp);
  1475. return __subn_get_opa_sc_to_vlnt(smp, am, data, ibdev, port,
  1476. resp_len);
  1477. }
  1478. static int __subn_get_opa_psi(struct opa_smp *smp, u32 am, u8 *data,
  1479. struct ib_device *ibdev, u8 port,
  1480. u32 *resp_len)
  1481. {
  1482. u32 nports = OPA_AM_NPORT(am);
  1483. u32 start_of_sm_config = OPA_AM_START_SM_CFG(am);
  1484. u32 lstate;
  1485. struct hfi1_ibport *ibp;
  1486. struct hfi1_pportdata *ppd;
  1487. struct opa_port_state_info *psi = (struct opa_port_state_info *)data;
  1488. if (nports != 1) {
  1489. smp->status |= IB_SMP_INVALID_FIELD;
  1490. return reply((struct ib_mad_hdr *)smp);
  1491. }
  1492. ibp = to_iport(ibdev, port);
  1493. ppd = ppd_from_ibp(ibp);
  1494. lstate = driver_lstate(ppd);
  1495. if (start_of_sm_config && (lstate == IB_PORT_INIT))
  1496. ppd->is_sm_config_started = 1;
  1497. psi->port_states.ledenable_offlinereason = ppd->neighbor_normal << 4;
  1498. psi->port_states.ledenable_offlinereason |=
  1499. ppd->is_sm_config_started << 5;
  1500. psi->port_states.ledenable_offlinereason |=
  1501. ppd->offline_disabled_reason;
  1502. psi->port_states.portphysstate_portstate =
  1503. (hfi1_ibphys_portstate(ppd) << 4) | (lstate & 0xf);
  1504. psi->link_width_downgrade_tx_active =
  1505. cpu_to_be16(ppd->link_width_downgrade_tx_active);
  1506. psi->link_width_downgrade_rx_active =
  1507. cpu_to_be16(ppd->link_width_downgrade_rx_active);
  1508. if (resp_len)
  1509. *resp_len += sizeof(struct opa_port_state_info);
  1510. return reply((struct ib_mad_hdr *)smp);
  1511. }
  1512. static int __subn_set_opa_psi(struct opa_smp *smp, u32 am, u8 *data,
  1513. struct ib_device *ibdev, u8 port,
  1514. u32 *resp_len)
  1515. {
  1516. u32 nports = OPA_AM_NPORT(am);
  1517. u32 start_of_sm_config = OPA_AM_START_SM_CFG(am);
  1518. u32 ls_old;
  1519. u8 ls_new, ps_new;
  1520. struct hfi1_ibport *ibp;
  1521. struct hfi1_pportdata *ppd;
  1522. struct opa_port_state_info *psi = (struct opa_port_state_info *)data;
  1523. int ret, invalid = 0;
  1524. if (nports != 1) {
  1525. smp->status |= IB_SMP_INVALID_FIELD;
  1526. return reply((struct ib_mad_hdr *)smp);
  1527. }
  1528. ibp = to_iport(ibdev, port);
  1529. ppd = ppd_from_ibp(ibp);
  1530. ls_old = driver_lstate(ppd);
  1531. ls_new = port_states_to_logical_state(&psi->port_states);
  1532. ps_new = port_states_to_phys_state(&psi->port_states);
  1533. if (ls_old == IB_PORT_INIT) {
  1534. if (start_of_sm_config) {
  1535. if (ls_new == ls_old || (ls_new == IB_PORT_ARMED))
  1536. ppd->is_sm_config_started = 1;
  1537. } else if (ls_new == IB_PORT_ARMED) {
  1538. if (ppd->is_sm_config_started == 0)
  1539. invalid = 1;
  1540. }
  1541. }
  1542. ret = set_port_states(ppd, smp, ls_new, ps_new, invalid);
  1543. if (ret)
  1544. return ret;
  1545. if (invalid)
  1546. smp->status |= IB_SMP_INVALID_FIELD;
  1547. return __subn_get_opa_psi(smp, am, data, ibdev, port, resp_len);
  1548. }
  1549. static int __subn_get_opa_cable_info(struct opa_smp *smp, u32 am, u8 *data,
  1550. struct ib_device *ibdev, u8 port,
  1551. u32 *resp_len)
  1552. {
  1553. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  1554. u32 addr = OPA_AM_CI_ADDR(am);
  1555. u32 len = OPA_AM_CI_LEN(am) + 1;
  1556. int ret;
  1557. if (dd->pport->port_type != PORT_TYPE_QSFP) {
  1558. smp->status |= IB_SMP_INVALID_FIELD;
  1559. return reply((struct ib_mad_hdr *)smp);
  1560. }
  1561. #define __CI_PAGE_SIZE BIT(7) /* 128 bytes */
  1562. #define __CI_PAGE_MASK ~(__CI_PAGE_SIZE - 1)
  1563. #define __CI_PAGE_NUM(a) ((a) & __CI_PAGE_MASK)
  1564. /*
  1565. * check that addr is within spec, and
  1566. * addr and (addr + len - 1) are on the same "page"
  1567. */
  1568. if (addr >= 4096 ||
  1569. (__CI_PAGE_NUM(addr) != __CI_PAGE_NUM(addr + len - 1))) {
  1570. smp->status |= IB_SMP_INVALID_FIELD;
  1571. return reply((struct ib_mad_hdr *)smp);
  1572. }
  1573. ret = get_cable_info(dd, port, addr, len, data);
  1574. if (ret == -ENODEV) {
  1575. smp->status |= IB_SMP_UNSUP_METH_ATTR;
  1576. return reply((struct ib_mad_hdr *)smp);
  1577. }
  1578. /* The address range for the CableInfo SMA query is wider than the
  1579. * memory available on the QSFP cable. We want to return a valid
  1580. * response, albeit zeroed out, for address ranges beyond available
  1581. * memory but that are within the CableInfo query spec
  1582. */
  1583. if (ret < 0 && ret != -ERANGE) {
  1584. smp->status |= IB_SMP_INVALID_FIELD;
  1585. return reply((struct ib_mad_hdr *)smp);
  1586. }
  1587. if (resp_len)
  1588. *resp_len += len;
  1589. return reply((struct ib_mad_hdr *)smp);
  1590. }
  1591. static int __subn_get_opa_bct(struct opa_smp *smp, u32 am, u8 *data,
  1592. struct ib_device *ibdev, u8 port, u32 *resp_len)
  1593. {
  1594. u32 num_ports = OPA_AM_NPORT(am);
  1595. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  1596. struct hfi1_pportdata *ppd;
  1597. struct buffer_control *p = (struct buffer_control *)data;
  1598. int size;
  1599. if (num_ports != 1) {
  1600. smp->status |= IB_SMP_INVALID_FIELD;
  1601. return reply((struct ib_mad_hdr *)smp);
  1602. }
  1603. ppd = dd->pport + (port - 1);
  1604. size = fm_get_table(ppd, FM_TBL_BUFFER_CONTROL, p);
  1605. trace_bct_get(dd, p);
  1606. if (resp_len)
  1607. *resp_len += size;
  1608. return reply((struct ib_mad_hdr *)smp);
  1609. }
  1610. static int __subn_set_opa_bct(struct opa_smp *smp, u32 am, u8 *data,
  1611. struct ib_device *ibdev, u8 port, u32 *resp_len)
  1612. {
  1613. u32 num_ports = OPA_AM_NPORT(am);
  1614. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  1615. struct hfi1_pportdata *ppd;
  1616. struct buffer_control *p = (struct buffer_control *)data;
  1617. if (num_ports != 1) {
  1618. smp->status |= IB_SMP_INVALID_FIELD;
  1619. return reply((struct ib_mad_hdr *)smp);
  1620. }
  1621. ppd = dd->pport + (port - 1);
  1622. trace_bct_set(dd, p);
  1623. if (fm_set_table(ppd, FM_TBL_BUFFER_CONTROL, p) < 0) {
  1624. smp->status |= IB_SMP_INVALID_FIELD;
  1625. return reply((struct ib_mad_hdr *)smp);
  1626. }
  1627. return __subn_get_opa_bct(smp, am, data, ibdev, port, resp_len);
  1628. }
  1629. static int __subn_get_opa_vl_arb(struct opa_smp *smp, u32 am, u8 *data,
  1630. struct ib_device *ibdev, u8 port,
  1631. u32 *resp_len)
  1632. {
  1633. struct hfi1_pportdata *ppd = ppd_from_ibp(to_iport(ibdev, port));
  1634. u32 num_ports = OPA_AM_NPORT(am);
  1635. u8 section = (am & 0x00ff0000) >> 16;
  1636. u8 *p = data;
  1637. int size = 0;
  1638. if (num_ports != 1) {
  1639. smp->status |= IB_SMP_INVALID_FIELD;
  1640. return reply((struct ib_mad_hdr *)smp);
  1641. }
  1642. switch (section) {
  1643. case OPA_VLARB_LOW_ELEMENTS:
  1644. size = fm_get_table(ppd, FM_TBL_VL_LOW_ARB, p);
  1645. break;
  1646. case OPA_VLARB_HIGH_ELEMENTS:
  1647. size = fm_get_table(ppd, FM_TBL_VL_HIGH_ARB, p);
  1648. break;
  1649. case OPA_VLARB_PREEMPT_ELEMENTS:
  1650. size = fm_get_table(ppd, FM_TBL_VL_PREEMPT_ELEMS, p);
  1651. break;
  1652. case OPA_VLARB_PREEMPT_MATRIX:
  1653. size = fm_get_table(ppd, FM_TBL_VL_PREEMPT_MATRIX, p);
  1654. break;
  1655. default:
  1656. pr_warn("OPA SubnGet(VL Arb) AM Invalid : 0x%x\n",
  1657. be32_to_cpu(smp->attr_mod));
  1658. smp->status |= IB_SMP_INVALID_FIELD;
  1659. break;
  1660. }
  1661. if (size > 0 && resp_len)
  1662. *resp_len += size;
  1663. return reply((struct ib_mad_hdr *)smp);
  1664. }
  1665. static int __subn_set_opa_vl_arb(struct opa_smp *smp, u32 am, u8 *data,
  1666. struct ib_device *ibdev, u8 port,
  1667. u32 *resp_len)
  1668. {
  1669. struct hfi1_pportdata *ppd = ppd_from_ibp(to_iport(ibdev, port));
  1670. u32 num_ports = OPA_AM_NPORT(am);
  1671. u8 section = (am & 0x00ff0000) >> 16;
  1672. u8 *p = data;
  1673. if (num_ports != 1) {
  1674. smp->status |= IB_SMP_INVALID_FIELD;
  1675. return reply((struct ib_mad_hdr *)smp);
  1676. }
  1677. switch (section) {
  1678. case OPA_VLARB_LOW_ELEMENTS:
  1679. (void)fm_set_table(ppd, FM_TBL_VL_LOW_ARB, p);
  1680. break;
  1681. case OPA_VLARB_HIGH_ELEMENTS:
  1682. (void)fm_set_table(ppd, FM_TBL_VL_HIGH_ARB, p);
  1683. break;
  1684. /*
  1685. * neither OPA_VLARB_PREEMPT_ELEMENTS, or OPA_VLARB_PREEMPT_MATRIX
  1686. * can be changed from the default values
  1687. */
  1688. case OPA_VLARB_PREEMPT_ELEMENTS:
  1689. /* FALLTHROUGH */
  1690. case OPA_VLARB_PREEMPT_MATRIX:
  1691. smp->status |= IB_SMP_UNSUP_METH_ATTR;
  1692. break;
  1693. default:
  1694. pr_warn("OPA SubnSet(VL Arb) AM Invalid : 0x%x\n",
  1695. be32_to_cpu(smp->attr_mod));
  1696. smp->status |= IB_SMP_INVALID_FIELD;
  1697. break;
  1698. }
  1699. return __subn_get_opa_vl_arb(smp, am, data, ibdev, port, resp_len);
  1700. }
  1701. struct opa_pma_mad {
  1702. struct ib_mad_hdr mad_hdr;
  1703. u8 data[2024];
  1704. } __packed;
  1705. struct opa_class_port_info {
  1706. u8 base_version;
  1707. u8 class_version;
  1708. __be16 cap_mask;
  1709. __be32 cap_mask2_resp_time;
  1710. u8 redirect_gid[16];
  1711. __be32 redirect_tc_fl;
  1712. __be32 redirect_lid;
  1713. __be32 redirect_sl_qp;
  1714. __be32 redirect_qkey;
  1715. u8 trap_gid[16];
  1716. __be32 trap_tc_fl;
  1717. __be32 trap_lid;
  1718. __be32 trap_hl_qp;
  1719. __be32 trap_qkey;
  1720. __be16 trap_pkey;
  1721. __be16 redirect_pkey;
  1722. u8 trap_sl_rsvd;
  1723. u8 reserved[3];
  1724. } __packed;
  1725. struct opa_port_status_req {
  1726. __u8 port_num;
  1727. __u8 reserved[3];
  1728. __be32 vl_select_mask;
  1729. };
  1730. #define VL_MASK_ALL 0x000080ff
  1731. struct opa_port_status_rsp {
  1732. __u8 port_num;
  1733. __u8 reserved[3];
  1734. __be32 vl_select_mask;
  1735. /* Data counters */
  1736. __be64 port_xmit_data;
  1737. __be64 port_rcv_data;
  1738. __be64 port_xmit_pkts;
  1739. __be64 port_rcv_pkts;
  1740. __be64 port_multicast_xmit_pkts;
  1741. __be64 port_multicast_rcv_pkts;
  1742. __be64 port_xmit_wait;
  1743. __be64 sw_port_congestion;
  1744. __be64 port_rcv_fecn;
  1745. __be64 port_rcv_becn;
  1746. __be64 port_xmit_time_cong;
  1747. __be64 port_xmit_wasted_bw;
  1748. __be64 port_xmit_wait_data;
  1749. __be64 port_rcv_bubble;
  1750. __be64 port_mark_fecn;
  1751. /* Error counters */
  1752. __be64 port_rcv_constraint_errors;
  1753. __be64 port_rcv_switch_relay_errors;
  1754. __be64 port_xmit_discards;
  1755. __be64 port_xmit_constraint_errors;
  1756. __be64 port_rcv_remote_physical_errors;
  1757. __be64 local_link_integrity_errors;
  1758. __be64 port_rcv_errors;
  1759. __be64 excessive_buffer_overruns;
  1760. __be64 fm_config_errors;
  1761. __be32 link_error_recovery;
  1762. __be32 link_downed;
  1763. u8 uncorrectable_errors;
  1764. u8 link_quality_indicator; /* 5res, 3bit */
  1765. u8 res2[6];
  1766. struct _vls_pctrs {
  1767. /* per-VL Data counters */
  1768. __be64 port_vl_xmit_data;
  1769. __be64 port_vl_rcv_data;
  1770. __be64 port_vl_xmit_pkts;
  1771. __be64 port_vl_rcv_pkts;
  1772. __be64 port_vl_xmit_wait;
  1773. __be64 sw_port_vl_congestion;
  1774. __be64 port_vl_rcv_fecn;
  1775. __be64 port_vl_rcv_becn;
  1776. __be64 port_xmit_time_cong;
  1777. __be64 port_vl_xmit_wasted_bw;
  1778. __be64 port_vl_xmit_wait_data;
  1779. __be64 port_vl_rcv_bubble;
  1780. __be64 port_vl_mark_fecn;
  1781. __be64 port_vl_xmit_discards;
  1782. } vls[0]; /* real array size defined by # bits set in vl_select_mask */
  1783. };
  1784. enum counter_selects {
  1785. CS_PORT_XMIT_DATA = (1 << 31),
  1786. CS_PORT_RCV_DATA = (1 << 30),
  1787. CS_PORT_XMIT_PKTS = (1 << 29),
  1788. CS_PORT_RCV_PKTS = (1 << 28),
  1789. CS_PORT_MCAST_XMIT_PKTS = (1 << 27),
  1790. CS_PORT_MCAST_RCV_PKTS = (1 << 26),
  1791. CS_PORT_XMIT_WAIT = (1 << 25),
  1792. CS_SW_PORT_CONGESTION = (1 << 24),
  1793. CS_PORT_RCV_FECN = (1 << 23),
  1794. CS_PORT_RCV_BECN = (1 << 22),
  1795. CS_PORT_XMIT_TIME_CONG = (1 << 21),
  1796. CS_PORT_XMIT_WASTED_BW = (1 << 20),
  1797. CS_PORT_XMIT_WAIT_DATA = (1 << 19),
  1798. CS_PORT_RCV_BUBBLE = (1 << 18),
  1799. CS_PORT_MARK_FECN = (1 << 17),
  1800. CS_PORT_RCV_CONSTRAINT_ERRORS = (1 << 16),
  1801. CS_PORT_RCV_SWITCH_RELAY_ERRORS = (1 << 15),
  1802. CS_PORT_XMIT_DISCARDS = (1 << 14),
  1803. CS_PORT_XMIT_CONSTRAINT_ERRORS = (1 << 13),
  1804. CS_PORT_RCV_REMOTE_PHYSICAL_ERRORS = (1 << 12),
  1805. CS_LOCAL_LINK_INTEGRITY_ERRORS = (1 << 11),
  1806. CS_PORT_RCV_ERRORS = (1 << 10),
  1807. CS_EXCESSIVE_BUFFER_OVERRUNS = (1 << 9),
  1808. CS_FM_CONFIG_ERRORS = (1 << 8),
  1809. CS_LINK_ERROR_RECOVERY = (1 << 7),
  1810. CS_LINK_DOWNED = (1 << 6),
  1811. CS_UNCORRECTABLE_ERRORS = (1 << 5),
  1812. };
  1813. struct opa_clear_port_status {
  1814. __be64 port_select_mask[4];
  1815. __be32 counter_select_mask;
  1816. };
  1817. struct opa_aggregate {
  1818. __be16 attr_id;
  1819. __be16 err_reqlength; /* 1 bit, 8 res, 7 bit */
  1820. __be32 attr_mod;
  1821. u8 data[0];
  1822. };
  1823. #define MSK_LLI 0x000000f0
  1824. #define MSK_LLI_SFT 4
  1825. #define MSK_LER 0x0000000f
  1826. #define MSK_LER_SFT 0
  1827. #define ADD_LLI 8
  1828. #define ADD_LER 2
  1829. /* Request contains first three fields, response contains those plus the rest */
  1830. struct opa_port_data_counters_msg {
  1831. __be64 port_select_mask[4];
  1832. __be32 vl_select_mask;
  1833. __be32 resolution;
  1834. /* Response fields follow */
  1835. struct _port_dctrs {
  1836. u8 port_number;
  1837. u8 reserved2[3];
  1838. __be32 link_quality_indicator; /* 29res, 3bit */
  1839. /* Data counters */
  1840. __be64 port_xmit_data;
  1841. __be64 port_rcv_data;
  1842. __be64 port_xmit_pkts;
  1843. __be64 port_rcv_pkts;
  1844. __be64 port_multicast_xmit_pkts;
  1845. __be64 port_multicast_rcv_pkts;
  1846. __be64 port_xmit_wait;
  1847. __be64 sw_port_congestion;
  1848. __be64 port_rcv_fecn;
  1849. __be64 port_rcv_becn;
  1850. __be64 port_xmit_time_cong;
  1851. __be64 port_xmit_wasted_bw;
  1852. __be64 port_xmit_wait_data;
  1853. __be64 port_rcv_bubble;
  1854. __be64 port_mark_fecn;
  1855. __be64 port_error_counter_summary;
  1856. /* Sum of error counts/port */
  1857. struct _vls_dctrs {
  1858. /* per-VL Data counters */
  1859. __be64 port_vl_xmit_data;
  1860. __be64 port_vl_rcv_data;
  1861. __be64 port_vl_xmit_pkts;
  1862. __be64 port_vl_rcv_pkts;
  1863. __be64 port_vl_xmit_wait;
  1864. __be64 sw_port_vl_congestion;
  1865. __be64 port_vl_rcv_fecn;
  1866. __be64 port_vl_rcv_becn;
  1867. __be64 port_xmit_time_cong;
  1868. __be64 port_vl_xmit_wasted_bw;
  1869. __be64 port_vl_xmit_wait_data;
  1870. __be64 port_vl_rcv_bubble;
  1871. __be64 port_vl_mark_fecn;
  1872. } vls[0];
  1873. /* array size defined by #bits set in vl_select_mask*/
  1874. } port[1]; /* array size defined by #ports in attribute modifier */
  1875. };
  1876. struct opa_port_error_counters64_msg {
  1877. /*
  1878. * Request contains first two fields, response contains the
  1879. * whole magilla
  1880. */
  1881. __be64 port_select_mask[4];
  1882. __be32 vl_select_mask;
  1883. /* Response-only fields follow */
  1884. __be32 reserved1;
  1885. struct _port_ectrs {
  1886. u8 port_number;
  1887. u8 reserved2[7];
  1888. __be64 port_rcv_constraint_errors;
  1889. __be64 port_rcv_switch_relay_errors;
  1890. __be64 port_xmit_discards;
  1891. __be64 port_xmit_constraint_errors;
  1892. __be64 port_rcv_remote_physical_errors;
  1893. __be64 local_link_integrity_errors;
  1894. __be64 port_rcv_errors;
  1895. __be64 excessive_buffer_overruns;
  1896. __be64 fm_config_errors;
  1897. __be32 link_error_recovery;
  1898. __be32 link_downed;
  1899. u8 uncorrectable_errors;
  1900. u8 reserved3[7];
  1901. struct _vls_ectrs {
  1902. __be64 port_vl_xmit_discards;
  1903. } vls[0];
  1904. /* array size defined by #bits set in vl_select_mask */
  1905. } port[1]; /* array size defined by #ports in attribute modifier */
  1906. };
  1907. struct opa_port_error_info_msg {
  1908. __be64 port_select_mask[4];
  1909. __be32 error_info_select_mask;
  1910. __be32 reserved1;
  1911. struct _port_ei {
  1912. u8 port_number;
  1913. u8 reserved2[7];
  1914. /* PortRcvErrorInfo */
  1915. struct {
  1916. u8 status_and_code;
  1917. union {
  1918. u8 raw[17];
  1919. struct {
  1920. /* EI1to12 format */
  1921. u8 packet_flit1[8];
  1922. u8 packet_flit2[8];
  1923. u8 remaining_flit_bits12;
  1924. } ei1to12;
  1925. struct {
  1926. u8 packet_bytes[8];
  1927. u8 remaining_flit_bits;
  1928. } ei13;
  1929. } ei;
  1930. u8 reserved3[6];
  1931. } __packed port_rcv_ei;
  1932. /* ExcessiveBufferOverrunInfo */
  1933. struct {
  1934. u8 status_and_sc;
  1935. u8 reserved4[7];
  1936. } __packed excessive_buffer_overrun_ei;
  1937. /* PortXmitConstraintErrorInfo */
  1938. struct {
  1939. u8 status;
  1940. u8 reserved5;
  1941. __be16 pkey;
  1942. __be32 slid;
  1943. } __packed port_xmit_constraint_ei;
  1944. /* PortRcvConstraintErrorInfo */
  1945. struct {
  1946. u8 status;
  1947. u8 reserved6;
  1948. __be16 pkey;
  1949. __be32 slid;
  1950. } __packed port_rcv_constraint_ei;
  1951. /* PortRcvSwitchRelayErrorInfo */
  1952. struct {
  1953. u8 status_and_code;
  1954. u8 reserved7[3];
  1955. __u32 error_info;
  1956. } __packed port_rcv_switch_relay_ei;
  1957. /* UncorrectableErrorInfo */
  1958. struct {
  1959. u8 status_and_code;
  1960. u8 reserved8;
  1961. } __packed uncorrectable_ei;
  1962. /* FMConfigErrorInfo */
  1963. struct {
  1964. u8 status_and_code;
  1965. u8 error_info;
  1966. } __packed fm_config_ei;
  1967. __u32 reserved9;
  1968. } port[1]; /* actual array size defined by #ports in attr modifier */
  1969. };
  1970. /* opa_port_error_info_msg error_info_select_mask bit definitions */
  1971. enum error_info_selects {
  1972. ES_PORT_RCV_ERROR_INFO = (1 << 31),
  1973. ES_EXCESSIVE_BUFFER_OVERRUN_INFO = (1 << 30),
  1974. ES_PORT_XMIT_CONSTRAINT_ERROR_INFO = (1 << 29),
  1975. ES_PORT_RCV_CONSTRAINT_ERROR_INFO = (1 << 28),
  1976. ES_PORT_RCV_SWITCH_RELAY_ERROR_INFO = (1 << 27),
  1977. ES_UNCORRECTABLE_ERROR_INFO = (1 << 26),
  1978. ES_FM_CONFIG_ERROR_INFO = (1 << 25)
  1979. };
  1980. static int pma_get_opa_classportinfo(struct opa_pma_mad *pmp,
  1981. struct ib_device *ibdev, u32 *resp_len)
  1982. {
  1983. struct opa_class_port_info *p =
  1984. (struct opa_class_port_info *)pmp->data;
  1985. memset(pmp->data, 0, sizeof(pmp->data));
  1986. if (pmp->mad_hdr.attr_mod != 0)
  1987. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  1988. p->base_version = OPA_MGMT_BASE_VERSION;
  1989. p->class_version = OPA_SMI_CLASS_VERSION;
  1990. /*
  1991. * Expected response time is 4.096 usec. * 2^18 == 1.073741824 sec.
  1992. */
  1993. p->cap_mask2_resp_time = cpu_to_be32(18);
  1994. if (resp_len)
  1995. *resp_len += sizeof(*p);
  1996. return reply((struct ib_mad_hdr *)pmp);
  1997. }
  1998. static void a0_portstatus(struct hfi1_pportdata *ppd,
  1999. struct opa_port_status_rsp *rsp, u32 vl_select_mask)
  2000. {
  2001. if (!is_bx(ppd->dd)) {
  2002. unsigned long vl;
  2003. u64 sum_vl_xmit_wait = 0;
  2004. u32 vl_all_mask = VL_MASK_ALL;
  2005. for_each_set_bit(vl, (unsigned long *)&(vl_all_mask),
  2006. 8 * sizeof(vl_all_mask)) {
  2007. u64 tmp = sum_vl_xmit_wait +
  2008. read_port_cntr(ppd, C_TX_WAIT_VL,
  2009. idx_from_vl(vl));
  2010. if (tmp < sum_vl_xmit_wait) {
  2011. /* we wrapped */
  2012. sum_vl_xmit_wait = (u64)~0;
  2013. break;
  2014. }
  2015. sum_vl_xmit_wait = tmp;
  2016. }
  2017. if (be64_to_cpu(rsp->port_xmit_wait) > sum_vl_xmit_wait)
  2018. rsp->port_xmit_wait = cpu_to_be64(sum_vl_xmit_wait);
  2019. }
  2020. }
  2021. static int pma_get_opa_portstatus(struct opa_pma_mad *pmp,
  2022. struct ib_device *ibdev,
  2023. u8 port, u32 *resp_len)
  2024. {
  2025. struct opa_port_status_req *req =
  2026. (struct opa_port_status_req *)pmp->data;
  2027. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  2028. struct opa_port_status_rsp *rsp;
  2029. u32 vl_select_mask = be32_to_cpu(req->vl_select_mask);
  2030. unsigned long vl;
  2031. size_t response_data_size;
  2032. u32 nports = be32_to_cpu(pmp->mad_hdr.attr_mod) >> 24;
  2033. u8 port_num = req->port_num;
  2034. u8 num_vls = hweight32(vl_select_mask);
  2035. struct _vls_pctrs *vlinfo;
  2036. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  2037. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  2038. int vfi;
  2039. u64 tmp, tmp2;
  2040. response_data_size = sizeof(struct opa_port_status_rsp) +
  2041. num_vls * sizeof(struct _vls_pctrs);
  2042. if (response_data_size > sizeof(pmp->data)) {
  2043. pmp->mad_hdr.status |= OPA_PM_STATUS_REQUEST_TOO_LARGE;
  2044. return reply((struct ib_mad_hdr *)pmp);
  2045. }
  2046. if (nports != 1 || (port_num && port_num != port) ||
  2047. num_vls > OPA_MAX_VLS || (vl_select_mask & ~VL_MASK_ALL)) {
  2048. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  2049. return reply((struct ib_mad_hdr *)pmp);
  2050. }
  2051. memset(pmp->data, 0, sizeof(pmp->data));
  2052. rsp = (struct opa_port_status_rsp *)pmp->data;
  2053. if (port_num)
  2054. rsp->port_num = port_num;
  2055. else
  2056. rsp->port_num = port;
  2057. rsp->port_rcv_constraint_errors =
  2058. cpu_to_be64(read_port_cntr(ppd, C_SW_RCV_CSTR_ERR,
  2059. CNTR_INVALID_VL));
  2060. hfi1_read_link_quality(dd, &rsp->link_quality_indicator);
  2061. rsp->vl_select_mask = cpu_to_be32(vl_select_mask);
  2062. rsp->port_xmit_data = cpu_to_be64(read_dev_cntr(dd, C_DC_XMIT_FLITS,
  2063. CNTR_INVALID_VL));
  2064. rsp->port_rcv_data = cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FLITS,
  2065. CNTR_INVALID_VL));
  2066. rsp->port_xmit_pkts = cpu_to_be64(read_dev_cntr(dd, C_DC_XMIT_PKTS,
  2067. CNTR_INVALID_VL));
  2068. rsp->port_rcv_pkts = cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_PKTS,
  2069. CNTR_INVALID_VL));
  2070. rsp->port_multicast_xmit_pkts =
  2071. cpu_to_be64(read_dev_cntr(dd, C_DC_MC_XMIT_PKTS,
  2072. CNTR_INVALID_VL));
  2073. rsp->port_multicast_rcv_pkts =
  2074. cpu_to_be64(read_dev_cntr(dd, C_DC_MC_RCV_PKTS,
  2075. CNTR_INVALID_VL));
  2076. rsp->port_xmit_wait =
  2077. cpu_to_be64(read_port_cntr(ppd, C_TX_WAIT, CNTR_INVALID_VL));
  2078. rsp->port_rcv_fecn =
  2079. cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FCN, CNTR_INVALID_VL));
  2080. rsp->port_rcv_becn =
  2081. cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_BCN, CNTR_INVALID_VL));
  2082. rsp->port_xmit_discards =
  2083. cpu_to_be64(read_port_cntr(ppd, C_SW_XMIT_DSCD,
  2084. CNTR_INVALID_VL));
  2085. rsp->port_xmit_constraint_errors =
  2086. cpu_to_be64(read_port_cntr(ppd, C_SW_XMIT_CSTR_ERR,
  2087. CNTR_INVALID_VL));
  2088. rsp->port_rcv_remote_physical_errors =
  2089. cpu_to_be64(read_dev_cntr(dd, C_DC_RMT_PHY_ERR,
  2090. CNTR_INVALID_VL));
  2091. rsp->local_link_integrity_errors =
  2092. cpu_to_be64(read_dev_cntr(dd, C_DC_RX_REPLAY,
  2093. CNTR_INVALID_VL));
  2094. tmp = read_dev_cntr(dd, C_DC_SEQ_CRC_CNT, CNTR_INVALID_VL);
  2095. tmp2 = tmp + read_dev_cntr(dd, C_DC_REINIT_FROM_PEER_CNT,
  2096. CNTR_INVALID_VL);
  2097. if (tmp2 > (u32)UINT_MAX || tmp2 < tmp) {
  2098. /* overflow/wrapped */
  2099. rsp->link_error_recovery = cpu_to_be32(~0);
  2100. } else {
  2101. rsp->link_error_recovery = cpu_to_be32(tmp2);
  2102. }
  2103. rsp->port_rcv_errors =
  2104. cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_ERR, CNTR_INVALID_VL));
  2105. rsp->excessive_buffer_overruns =
  2106. cpu_to_be64(read_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL));
  2107. rsp->fm_config_errors =
  2108. cpu_to_be64(read_dev_cntr(dd, C_DC_FM_CFG_ERR,
  2109. CNTR_INVALID_VL));
  2110. rsp->link_downed = cpu_to_be32(read_port_cntr(ppd, C_SW_LINK_DOWN,
  2111. CNTR_INVALID_VL));
  2112. /* rsp->uncorrectable_errors is 8 bits wide, and it pegs at 0xff */
  2113. tmp = read_dev_cntr(dd, C_DC_UNC_ERR, CNTR_INVALID_VL);
  2114. rsp->uncorrectable_errors = tmp < 0x100 ? (tmp & 0xff) : 0xff;
  2115. vlinfo = &rsp->vls[0];
  2116. vfi = 0;
  2117. /* The vl_select_mask has been checked above, and we know
  2118. * that it contains only entries which represent valid VLs.
  2119. * So in the for_each_set_bit() loop below, we don't need
  2120. * any additional checks for vl.
  2121. */
  2122. for_each_set_bit(vl, (unsigned long *)&(vl_select_mask),
  2123. 8 * sizeof(vl_select_mask)) {
  2124. memset(vlinfo, 0, sizeof(*vlinfo));
  2125. tmp = read_dev_cntr(dd, C_DC_RX_FLIT_VL, idx_from_vl(vl));
  2126. rsp->vls[vfi].port_vl_rcv_data = cpu_to_be64(tmp);
  2127. rsp->vls[vfi].port_vl_rcv_pkts =
  2128. cpu_to_be64(read_dev_cntr(dd, C_DC_RX_PKT_VL,
  2129. idx_from_vl(vl)));
  2130. rsp->vls[vfi].port_vl_xmit_data =
  2131. cpu_to_be64(read_port_cntr(ppd, C_TX_FLIT_VL,
  2132. idx_from_vl(vl)));
  2133. rsp->vls[vfi].port_vl_xmit_pkts =
  2134. cpu_to_be64(read_port_cntr(ppd, C_TX_PKT_VL,
  2135. idx_from_vl(vl)));
  2136. rsp->vls[vfi].port_vl_xmit_wait =
  2137. cpu_to_be64(read_port_cntr(ppd, C_TX_WAIT_VL,
  2138. idx_from_vl(vl)));
  2139. rsp->vls[vfi].port_vl_rcv_fecn =
  2140. cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FCN_VL,
  2141. idx_from_vl(vl)));
  2142. rsp->vls[vfi].port_vl_rcv_becn =
  2143. cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_BCN_VL,
  2144. idx_from_vl(vl)));
  2145. rsp->vls[vfi].port_vl_xmit_discards =
  2146. cpu_to_be64(read_port_cntr(ppd, C_SW_XMIT_DSCD_VL,
  2147. idx_from_vl(vl)));
  2148. vlinfo++;
  2149. vfi++;
  2150. }
  2151. a0_portstatus(ppd, rsp, vl_select_mask);
  2152. if (resp_len)
  2153. *resp_len += response_data_size;
  2154. return reply((struct ib_mad_hdr *)pmp);
  2155. }
  2156. static u64 get_error_counter_summary(struct ib_device *ibdev, u8 port,
  2157. u8 res_lli, u8 res_ler)
  2158. {
  2159. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  2160. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  2161. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  2162. u64 error_counter_summary = 0, tmp;
  2163. error_counter_summary += read_port_cntr(ppd, C_SW_RCV_CSTR_ERR,
  2164. CNTR_INVALID_VL);
  2165. /* port_rcv_switch_relay_errors is 0 for HFIs */
  2166. error_counter_summary += read_port_cntr(ppd, C_SW_XMIT_DSCD,
  2167. CNTR_INVALID_VL);
  2168. error_counter_summary += read_port_cntr(ppd, C_SW_XMIT_CSTR_ERR,
  2169. CNTR_INVALID_VL);
  2170. error_counter_summary += read_dev_cntr(dd, C_DC_RMT_PHY_ERR,
  2171. CNTR_INVALID_VL);
  2172. /* local link integrity must be right-shifted by the lli resolution */
  2173. error_counter_summary += (read_dev_cntr(dd, C_DC_RX_REPLAY,
  2174. CNTR_INVALID_VL) >> res_lli);
  2175. /* link error recovery must b right-shifted by the ler resolution */
  2176. tmp = read_dev_cntr(dd, C_DC_SEQ_CRC_CNT, CNTR_INVALID_VL);
  2177. tmp += read_dev_cntr(dd, C_DC_REINIT_FROM_PEER_CNT, CNTR_INVALID_VL);
  2178. error_counter_summary += (tmp >> res_ler);
  2179. error_counter_summary += read_dev_cntr(dd, C_DC_RCV_ERR,
  2180. CNTR_INVALID_VL);
  2181. error_counter_summary += read_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL);
  2182. error_counter_summary += read_dev_cntr(dd, C_DC_FM_CFG_ERR,
  2183. CNTR_INVALID_VL);
  2184. /* ppd->link_downed is a 32-bit value */
  2185. error_counter_summary += read_port_cntr(ppd, C_SW_LINK_DOWN,
  2186. CNTR_INVALID_VL);
  2187. tmp = read_dev_cntr(dd, C_DC_UNC_ERR, CNTR_INVALID_VL);
  2188. /* this is an 8-bit quantity */
  2189. error_counter_summary += tmp < 0x100 ? (tmp & 0xff) : 0xff;
  2190. return error_counter_summary;
  2191. }
  2192. static void a0_datacounters(struct hfi1_pportdata *ppd, struct _port_dctrs *rsp,
  2193. u32 vl_select_mask)
  2194. {
  2195. if (!is_bx(ppd->dd)) {
  2196. unsigned long vl;
  2197. u64 sum_vl_xmit_wait = 0;
  2198. u32 vl_all_mask = VL_MASK_ALL;
  2199. for_each_set_bit(vl, (unsigned long *)&(vl_all_mask),
  2200. 8 * sizeof(vl_all_mask)) {
  2201. u64 tmp = sum_vl_xmit_wait +
  2202. read_port_cntr(ppd, C_TX_WAIT_VL,
  2203. idx_from_vl(vl));
  2204. if (tmp < sum_vl_xmit_wait) {
  2205. /* we wrapped */
  2206. sum_vl_xmit_wait = (u64)~0;
  2207. break;
  2208. }
  2209. sum_vl_xmit_wait = tmp;
  2210. }
  2211. if (be64_to_cpu(rsp->port_xmit_wait) > sum_vl_xmit_wait)
  2212. rsp->port_xmit_wait = cpu_to_be64(sum_vl_xmit_wait);
  2213. }
  2214. }
  2215. static void pma_get_opa_port_dctrs(struct ib_device *ibdev,
  2216. struct _port_dctrs *rsp)
  2217. {
  2218. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  2219. rsp->port_xmit_data = cpu_to_be64(read_dev_cntr(dd, C_DC_XMIT_FLITS,
  2220. CNTR_INVALID_VL));
  2221. rsp->port_rcv_data = cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FLITS,
  2222. CNTR_INVALID_VL));
  2223. rsp->port_xmit_pkts = cpu_to_be64(read_dev_cntr(dd, C_DC_XMIT_PKTS,
  2224. CNTR_INVALID_VL));
  2225. rsp->port_rcv_pkts = cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_PKTS,
  2226. CNTR_INVALID_VL));
  2227. rsp->port_multicast_xmit_pkts =
  2228. cpu_to_be64(read_dev_cntr(dd, C_DC_MC_XMIT_PKTS,
  2229. CNTR_INVALID_VL));
  2230. rsp->port_multicast_rcv_pkts =
  2231. cpu_to_be64(read_dev_cntr(dd, C_DC_MC_RCV_PKTS,
  2232. CNTR_INVALID_VL));
  2233. }
  2234. static int pma_get_opa_datacounters(struct opa_pma_mad *pmp,
  2235. struct ib_device *ibdev,
  2236. u8 port, u32 *resp_len)
  2237. {
  2238. struct opa_port_data_counters_msg *req =
  2239. (struct opa_port_data_counters_msg *)pmp->data;
  2240. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  2241. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  2242. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  2243. struct _port_dctrs *rsp;
  2244. struct _vls_dctrs *vlinfo;
  2245. size_t response_data_size;
  2246. u32 num_ports;
  2247. u8 num_pslm;
  2248. u8 lq, num_vls;
  2249. u8 res_lli, res_ler;
  2250. u64 port_mask;
  2251. unsigned long port_num;
  2252. unsigned long vl;
  2253. u32 vl_select_mask;
  2254. int vfi;
  2255. num_ports = be32_to_cpu(pmp->mad_hdr.attr_mod) >> 24;
  2256. num_pslm = hweight64(be64_to_cpu(req->port_select_mask[3]));
  2257. num_vls = hweight32(be32_to_cpu(req->vl_select_mask));
  2258. vl_select_mask = be32_to_cpu(req->vl_select_mask);
  2259. res_lli = (u8)(be32_to_cpu(req->resolution) & MSK_LLI) >> MSK_LLI_SFT;
  2260. res_lli = res_lli ? res_lli + ADD_LLI : 0;
  2261. res_ler = (u8)(be32_to_cpu(req->resolution) & MSK_LER) >> MSK_LER_SFT;
  2262. res_ler = res_ler ? res_ler + ADD_LER : 0;
  2263. if (num_ports != 1 || (vl_select_mask & ~VL_MASK_ALL)) {
  2264. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  2265. return reply((struct ib_mad_hdr *)pmp);
  2266. }
  2267. /* Sanity check */
  2268. response_data_size = sizeof(struct opa_port_data_counters_msg) +
  2269. num_vls * sizeof(struct _vls_dctrs);
  2270. if (response_data_size > sizeof(pmp->data)) {
  2271. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  2272. return reply((struct ib_mad_hdr *)pmp);
  2273. }
  2274. /*
  2275. * The bit set in the mask needs to be consistent with the
  2276. * port the request came in on.
  2277. */
  2278. port_mask = be64_to_cpu(req->port_select_mask[3]);
  2279. port_num = find_first_bit((unsigned long *)&port_mask,
  2280. sizeof(port_mask));
  2281. if ((u8)port_num != port) {
  2282. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  2283. return reply((struct ib_mad_hdr *)pmp);
  2284. }
  2285. rsp = &req->port[0];
  2286. memset(rsp, 0, sizeof(*rsp));
  2287. rsp->port_number = port;
  2288. /*
  2289. * Note that link_quality_indicator is a 32 bit quantity in
  2290. * 'datacounters' queries (as opposed to 'portinfo' queries,
  2291. * where it's a byte).
  2292. */
  2293. hfi1_read_link_quality(dd, &lq);
  2294. rsp->link_quality_indicator = cpu_to_be32((u32)lq);
  2295. pma_get_opa_port_dctrs(ibdev, rsp);
  2296. rsp->port_xmit_wait =
  2297. cpu_to_be64(read_port_cntr(ppd, C_TX_WAIT, CNTR_INVALID_VL));
  2298. rsp->port_rcv_fecn =
  2299. cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FCN, CNTR_INVALID_VL));
  2300. rsp->port_rcv_becn =
  2301. cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_BCN, CNTR_INVALID_VL));
  2302. rsp->port_error_counter_summary =
  2303. cpu_to_be64(get_error_counter_summary(ibdev, port,
  2304. res_lli, res_ler));
  2305. vlinfo = &rsp->vls[0];
  2306. vfi = 0;
  2307. /* The vl_select_mask has been checked above, and we know
  2308. * that it contains only entries which represent valid VLs.
  2309. * So in the for_each_set_bit() loop below, we don't need
  2310. * any additional checks for vl.
  2311. */
  2312. for_each_set_bit(vl, (unsigned long *)&(vl_select_mask),
  2313. 8 * sizeof(req->vl_select_mask)) {
  2314. memset(vlinfo, 0, sizeof(*vlinfo));
  2315. rsp->vls[vfi].port_vl_xmit_data =
  2316. cpu_to_be64(read_port_cntr(ppd, C_TX_FLIT_VL,
  2317. idx_from_vl(vl)));
  2318. rsp->vls[vfi].port_vl_rcv_data =
  2319. cpu_to_be64(read_dev_cntr(dd, C_DC_RX_FLIT_VL,
  2320. idx_from_vl(vl)));
  2321. rsp->vls[vfi].port_vl_xmit_pkts =
  2322. cpu_to_be64(read_port_cntr(ppd, C_TX_PKT_VL,
  2323. idx_from_vl(vl)));
  2324. rsp->vls[vfi].port_vl_rcv_pkts =
  2325. cpu_to_be64(read_dev_cntr(dd, C_DC_RX_PKT_VL,
  2326. idx_from_vl(vl)));
  2327. rsp->vls[vfi].port_vl_xmit_wait =
  2328. cpu_to_be64(read_port_cntr(ppd, C_TX_WAIT_VL,
  2329. idx_from_vl(vl)));
  2330. rsp->vls[vfi].port_vl_rcv_fecn =
  2331. cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FCN_VL,
  2332. idx_from_vl(vl)));
  2333. rsp->vls[vfi].port_vl_rcv_becn =
  2334. cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_BCN_VL,
  2335. idx_from_vl(vl)));
  2336. /* rsp->port_vl_xmit_time_cong is 0 for HFIs */
  2337. /* rsp->port_vl_xmit_wasted_bw ??? */
  2338. /* port_vl_xmit_wait_data - TXE (table 13-9 HFI spec) ???
  2339. * does this differ from rsp->vls[vfi].port_vl_xmit_wait
  2340. */
  2341. /*rsp->vls[vfi].port_vl_mark_fecn =
  2342. * cpu_to_be64(read_csr(dd, DCC_PRF_PORT_VL_MARK_FECN_CNT
  2343. * + offset));
  2344. */
  2345. vlinfo++;
  2346. vfi++;
  2347. }
  2348. a0_datacounters(ppd, rsp, vl_select_mask);
  2349. if (resp_len)
  2350. *resp_len += response_data_size;
  2351. return reply((struct ib_mad_hdr *)pmp);
  2352. }
  2353. static int pma_get_ib_portcounters_ext(struct ib_pma_mad *pmp,
  2354. struct ib_device *ibdev, u8 port)
  2355. {
  2356. struct ib_pma_portcounters_ext *p = (struct ib_pma_portcounters_ext *)
  2357. pmp->data;
  2358. struct _port_dctrs rsp;
  2359. if (pmp->mad_hdr.attr_mod != 0 || p->port_select != port) {
  2360. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  2361. goto bail;
  2362. }
  2363. memset(&rsp, 0, sizeof(rsp));
  2364. pma_get_opa_port_dctrs(ibdev, &rsp);
  2365. p->port_xmit_data = rsp.port_xmit_data;
  2366. p->port_rcv_data = rsp.port_rcv_data;
  2367. p->port_xmit_packets = rsp.port_xmit_pkts;
  2368. p->port_rcv_packets = rsp.port_rcv_pkts;
  2369. p->port_unicast_xmit_packets = 0;
  2370. p->port_unicast_rcv_packets = 0;
  2371. p->port_multicast_xmit_packets = rsp.port_multicast_xmit_pkts;
  2372. p->port_multicast_rcv_packets = rsp.port_multicast_rcv_pkts;
  2373. bail:
  2374. return reply((struct ib_mad_hdr *)pmp);
  2375. }
  2376. static void pma_get_opa_port_ectrs(struct ib_device *ibdev,
  2377. struct _port_ectrs *rsp, u8 port)
  2378. {
  2379. u64 tmp, tmp2;
  2380. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  2381. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  2382. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  2383. tmp = read_dev_cntr(dd, C_DC_SEQ_CRC_CNT, CNTR_INVALID_VL);
  2384. tmp2 = tmp + read_dev_cntr(dd, C_DC_REINIT_FROM_PEER_CNT,
  2385. CNTR_INVALID_VL);
  2386. if (tmp2 > (u32)UINT_MAX || tmp2 < tmp) {
  2387. /* overflow/wrapped */
  2388. rsp->link_error_recovery = cpu_to_be32(~0);
  2389. } else {
  2390. rsp->link_error_recovery = cpu_to_be32(tmp2);
  2391. }
  2392. rsp->link_downed = cpu_to_be32(read_port_cntr(ppd, C_SW_LINK_DOWN,
  2393. CNTR_INVALID_VL));
  2394. rsp->port_rcv_errors =
  2395. cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_ERR, CNTR_INVALID_VL));
  2396. rsp->port_rcv_remote_physical_errors =
  2397. cpu_to_be64(read_dev_cntr(dd, C_DC_RMT_PHY_ERR,
  2398. CNTR_INVALID_VL));
  2399. rsp->port_rcv_switch_relay_errors = 0;
  2400. rsp->port_xmit_discards =
  2401. cpu_to_be64(read_port_cntr(ppd, C_SW_XMIT_DSCD,
  2402. CNTR_INVALID_VL));
  2403. rsp->port_xmit_constraint_errors =
  2404. cpu_to_be64(read_port_cntr(ppd, C_SW_XMIT_CSTR_ERR,
  2405. CNTR_INVALID_VL));
  2406. rsp->port_rcv_constraint_errors =
  2407. cpu_to_be64(read_port_cntr(ppd, C_SW_RCV_CSTR_ERR,
  2408. CNTR_INVALID_VL));
  2409. rsp->local_link_integrity_errors =
  2410. cpu_to_be64(read_dev_cntr(dd, C_DC_RX_REPLAY,
  2411. CNTR_INVALID_VL));
  2412. rsp->excessive_buffer_overruns =
  2413. cpu_to_be64(read_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL));
  2414. }
  2415. static int pma_get_opa_porterrors(struct opa_pma_mad *pmp,
  2416. struct ib_device *ibdev,
  2417. u8 port, u32 *resp_len)
  2418. {
  2419. size_t response_data_size;
  2420. struct _port_ectrs *rsp;
  2421. u8 port_num;
  2422. struct opa_port_error_counters64_msg *req;
  2423. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  2424. u32 num_ports;
  2425. u8 num_pslm;
  2426. u8 num_vls;
  2427. struct hfi1_ibport *ibp;
  2428. struct hfi1_pportdata *ppd;
  2429. struct _vls_ectrs *vlinfo;
  2430. unsigned long vl;
  2431. u64 port_mask, tmp;
  2432. u32 vl_select_mask;
  2433. int vfi;
  2434. req = (struct opa_port_error_counters64_msg *)pmp->data;
  2435. num_ports = be32_to_cpu(pmp->mad_hdr.attr_mod) >> 24;
  2436. num_pslm = hweight64(be64_to_cpu(req->port_select_mask[3]));
  2437. num_vls = hweight32(be32_to_cpu(req->vl_select_mask));
  2438. if (num_ports != 1 || num_ports != num_pslm) {
  2439. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  2440. return reply((struct ib_mad_hdr *)pmp);
  2441. }
  2442. response_data_size = sizeof(struct opa_port_error_counters64_msg) +
  2443. num_vls * sizeof(struct _vls_ectrs);
  2444. if (response_data_size > sizeof(pmp->data)) {
  2445. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  2446. return reply((struct ib_mad_hdr *)pmp);
  2447. }
  2448. /*
  2449. * The bit set in the mask needs to be consistent with the
  2450. * port the request came in on.
  2451. */
  2452. port_mask = be64_to_cpu(req->port_select_mask[3]);
  2453. port_num = find_first_bit((unsigned long *)&port_mask,
  2454. sizeof(port_mask));
  2455. if (port_num != port) {
  2456. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  2457. return reply((struct ib_mad_hdr *)pmp);
  2458. }
  2459. rsp = &req->port[0];
  2460. ibp = to_iport(ibdev, port_num);
  2461. ppd = ppd_from_ibp(ibp);
  2462. memset(rsp, 0, sizeof(*rsp));
  2463. rsp->port_number = port_num;
  2464. pma_get_opa_port_ectrs(ibdev, rsp, port_num);
  2465. rsp->port_rcv_remote_physical_errors =
  2466. cpu_to_be64(read_dev_cntr(dd, C_DC_RMT_PHY_ERR,
  2467. CNTR_INVALID_VL));
  2468. rsp->fm_config_errors =
  2469. cpu_to_be64(read_dev_cntr(dd, C_DC_FM_CFG_ERR,
  2470. CNTR_INVALID_VL));
  2471. tmp = read_dev_cntr(dd, C_DC_UNC_ERR, CNTR_INVALID_VL);
  2472. rsp->uncorrectable_errors = tmp < 0x100 ? (tmp & 0xff) : 0xff;
  2473. rsp->port_rcv_errors =
  2474. cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_ERR, CNTR_INVALID_VL));
  2475. vlinfo = &rsp->vls[0];
  2476. vfi = 0;
  2477. vl_select_mask = be32_to_cpu(req->vl_select_mask);
  2478. for_each_set_bit(vl, (unsigned long *)&(vl_select_mask),
  2479. 8 * sizeof(req->vl_select_mask)) {
  2480. memset(vlinfo, 0, sizeof(*vlinfo));
  2481. rsp->vls[vfi].port_vl_xmit_discards =
  2482. cpu_to_be64(read_port_cntr(ppd, C_SW_XMIT_DSCD_VL,
  2483. idx_from_vl(vl)));
  2484. vlinfo += 1;
  2485. vfi++;
  2486. }
  2487. if (resp_len)
  2488. *resp_len += response_data_size;
  2489. return reply((struct ib_mad_hdr *)pmp);
  2490. }
  2491. static int pma_get_ib_portcounters(struct ib_pma_mad *pmp,
  2492. struct ib_device *ibdev, u8 port)
  2493. {
  2494. struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
  2495. pmp->data;
  2496. struct _port_ectrs rsp;
  2497. u64 temp_link_overrun_errors;
  2498. u64 temp_64;
  2499. u32 temp_32;
  2500. memset(&rsp, 0, sizeof(rsp));
  2501. pma_get_opa_port_ectrs(ibdev, &rsp, port);
  2502. if (pmp->mad_hdr.attr_mod != 0 || p->port_select != port) {
  2503. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  2504. goto bail;
  2505. }
  2506. p->symbol_error_counter = 0; /* N/A for OPA */
  2507. temp_32 = be32_to_cpu(rsp.link_error_recovery);
  2508. if (temp_32 > 0xFFUL)
  2509. p->link_error_recovery_counter = 0xFF;
  2510. else
  2511. p->link_error_recovery_counter = (u8)temp_32;
  2512. temp_32 = be32_to_cpu(rsp.link_downed);
  2513. if (temp_32 > 0xFFUL)
  2514. p->link_downed_counter = 0xFF;
  2515. else
  2516. p->link_downed_counter = (u8)temp_32;
  2517. temp_64 = be64_to_cpu(rsp.port_rcv_errors);
  2518. if (temp_64 > 0xFFFFUL)
  2519. p->port_rcv_errors = cpu_to_be16(0xFFFF);
  2520. else
  2521. p->port_rcv_errors = cpu_to_be16((u16)temp_64);
  2522. temp_64 = be64_to_cpu(rsp.port_rcv_remote_physical_errors);
  2523. if (temp_64 > 0xFFFFUL)
  2524. p->port_rcv_remphys_errors = cpu_to_be16(0xFFFF);
  2525. else
  2526. p->port_rcv_remphys_errors = cpu_to_be16((u16)temp_64);
  2527. temp_64 = be64_to_cpu(rsp.port_rcv_switch_relay_errors);
  2528. p->port_rcv_switch_relay_errors = cpu_to_be16((u16)temp_64);
  2529. temp_64 = be64_to_cpu(rsp.port_xmit_discards);
  2530. if (temp_64 > 0xFFFFUL)
  2531. p->port_xmit_discards = cpu_to_be16(0xFFFF);
  2532. else
  2533. p->port_xmit_discards = cpu_to_be16((u16)temp_64);
  2534. temp_64 = be64_to_cpu(rsp.port_xmit_constraint_errors);
  2535. if (temp_64 > 0xFFUL)
  2536. p->port_xmit_constraint_errors = 0xFF;
  2537. else
  2538. p->port_xmit_constraint_errors = (u8)temp_64;
  2539. temp_64 = be64_to_cpu(rsp.port_rcv_constraint_errors);
  2540. if (temp_64 > 0xFFUL)
  2541. p->port_rcv_constraint_errors = 0xFFUL;
  2542. else
  2543. p->port_rcv_constraint_errors = (u8)temp_64;
  2544. /* LocalLink: 7:4, BufferOverrun: 3:0 */
  2545. temp_64 = be64_to_cpu(rsp.local_link_integrity_errors);
  2546. if (temp_64 > 0xFUL)
  2547. temp_64 = 0xFUL;
  2548. temp_link_overrun_errors = temp_64 << 4;
  2549. temp_64 = be64_to_cpu(rsp.excessive_buffer_overruns);
  2550. if (temp_64 > 0xFUL)
  2551. temp_64 = 0xFUL;
  2552. temp_link_overrun_errors |= temp_64;
  2553. p->link_overrun_errors = (u8)temp_link_overrun_errors;
  2554. p->vl15_dropped = 0; /* N/A for OPA */
  2555. bail:
  2556. return reply((struct ib_mad_hdr *)pmp);
  2557. }
  2558. static int pma_get_opa_errorinfo(struct opa_pma_mad *pmp,
  2559. struct ib_device *ibdev,
  2560. u8 port, u32 *resp_len)
  2561. {
  2562. size_t response_data_size;
  2563. struct _port_ei *rsp;
  2564. struct opa_port_error_info_msg *req;
  2565. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  2566. u64 port_mask;
  2567. u32 num_ports;
  2568. u8 port_num;
  2569. u8 num_pslm;
  2570. u64 reg;
  2571. req = (struct opa_port_error_info_msg *)pmp->data;
  2572. rsp = &req->port[0];
  2573. num_ports = OPA_AM_NPORT(be32_to_cpu(pmp->mad_hdr.attr_mod));
  2574. num_pslm = hweight64(be64_to_cpu(req->port_select_mask[3]));
  2575. memset(rsp, 0, sizeof(*rsp));
  2576. if (num_ports != 1 || num_ports != num_pslm) {
  2577. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  2578. return reply((struct ib_mad_hdr *)pmp);
  2579. }
  2580. /* Sanity check */
  2581. response_data_size = sizeof(struct opa_port_error_info_msg);
  2582. if (response_data_size > sizeof(pmp->data)) {
  2583. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  2584. return reply((struct ib_mad_hdr *)pmp);
  2585. }
  2586. /*
  2587. * The bit set in the mask needs to be consistent with the port
  2588. * the request came in on.
  2589. */
  2590. port_mask = be64_to_cpu(req->port_select_mask[3]);
  2591. port_num = find_first_bit((unsigned long *)&port_mask,
  2592. sizeof(port_mask));
  2593. if (port_num != port) {
  2594. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  2595. return reply((struct ib_mad_hdr *)pmp);
  2596. }
  2597. /* PortRcvErrorInfo */
  2598. rsp->port_rcv_ei.status_and_code =
  2599. dd->err_info_rcvport.status_and_code;
  2600. memcpy(&rsp->port_rcv_ei.ei.ei1to12.packet_flit1,
  2601. &dd->err_info_rcvport.packet_flit1, sizeof(u64));
  2602. memcpy(&rsp->port_rcv_ei.ei.ei1to12.packet_flit2,
  2603. &dd->err_info_rcvport.packet_flit2, sizeof(u64));
  2604. /* ExcessiverBufferOverrunInfo */
  2605. reg = read_csr(dd, RCV_ERR_INFO);
  2606. if (reg & RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SMASK) {
  2607. /*
  2608. * if the RcvExcessBufferOverrun bit is set, save SC of
  2609. * first pkt that encountered an excess buffer overrun
  2610. */
  2611. u8 tmp = (u8)reg;
  2612. tmp &= RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SC_SMASK;
  2613. tmp <<= 2;
  2614. rsp->excessive_buffer_overrun_ei.status_and_sc = tmp;
  2615. /* set the status bit */
  2616. rsp->excessive_buffer_overrun_ei.status_and_sc |= 0x80;
  2617. }
  2618. rsp->port_xmit_constraint_ei.status =
  2619. dd->err_info_xmit_constraint.status;
  2620. rsp->port_xmit_constraint_ei.pkey =
  2621. cpu_to_be16(dd->err_info_xmit_constraint.pkey);
  2622. rsp->port_xmit_constraint_ei.slid =
  2623. cpu_to_be32(dd->err_info_xmit_constraint.slid);
  2624. rsp->port_rcv_constraint_ei.status =
  2625. dd->err_info_rcv_constraint.status;
  2626. rsp->port_rcv_constraint_ei.pkey =
  2627. cpu_to_be16(dd->err_info_rcv_constraint.pkey);
  2628. rsp->port_rcv_constraint_ei.slid =
  2629. cpu_to_be32(dd->err_info_rcv_constraint.slid);
  2630. /* UncorrectableErrorInfo */
  2631. rsp->uncorrectable_ei.status_and_code = dd->err_info_uncorrectable;
  2632. /* FMConfigErrorInfo */
  2633. rsp->fm_config_ei.status_and_code = dd->err_info_fmconfig;
  2634. if (resp_len)
  2635. *resp_len += response_data_size;
  2636. return reply((struct ib_mad_hdr *)pmp);
  2637. }
  2638. static int pma_set_opa_portstatus(struct opa_pma_mad *pmp,
  2639. struct ib_device *ibdev,
  2640. u8 port, u32 *resp_len)
  2641. {
  2642. struct opa_clear_port_status *req =
  2643. (struct opa_clear_port_status *)pmp->data;
  2644. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  2645. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  2646. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  2647. u32 nports = be32_to_cpu(pmp->mad_hdr.attr_mod) >> 24;
  2648. u64 portn = be64_to_cpu(req->port_select_mask[3]);
  2649. u32 counter_select = be32_to_cpu(req->counter_select_mask);
  2650. u32 vl_select_mask = VL_MASK_ALL; /* clear all per-vl cnts */
  2651. unsigned long vl;
  2652. if ((nports != 1) || (portn != 1 << port)) {
  2653. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  2654. return reply((struct ib_mad_hdr *)pmp);
  2655. }
  2656. /*
  2657. * only counters returned by pma_get_opa_portstatus() are
  2658. * handled, so when pma_get_opa_portstatus() gets a fix,
  2659. * the corresponding change should be made here as well.
  2660. */
  2661. if (counter_select & CS_PORT_XMIT_DATA)
  2662. write_dev_cntr(dd, C_DC_XMIT_FLITS, CNTR_INVALID_VL, 0);
  2663. if (counter_select & CS_PORT_RCV_DATA)
  2664. write_dev_cntr(dd, C_DC_RCV_FLITS, CNTR_INVALID_VL, 0);
  2665. if (counter_select & CS_PORT_XMIT_PKTS)
  2666. write_dev_cntr(dd, C_DC_XMIT_PKTS, CNTR_INVALID_VL, 0);
  2667. if (counter_select & CS_PORT_RCV_PKTS)
  2668. write_dev_cntr(dd, C_DC_RCV_PKTS, CNTR_INVALID_VL, 0);
  2669. if (counter_select & CS_PORT_MCAST_XMIT_PKTS)
  2670. write_dev_cntr(dd, C_DC_MC_XMIT_PKTS, CNTR_INVALID_VL, 0);
  2671. if (counter_select & CS_PORT_MCAST_RCV_PKTS)
  2672. write_dev_cntr(dd, C_DC_MC_RCV_PKTS, CNTR_INVALID_VL, 0);
  2673. if (counter_select & CS_PORT_XMIT_WAIT)
  2674. write_port_cntr(ppd, C_TX_WAIT, CNTR_INVALID_VL, 0);
  2675. /* ignore cs_sw_portCongestion for HFIs */
  2676. if (counter_select & CS_PORT_RCV_FECN)
  2677. write_dev_cntr(dd, C_DC_RCV_FCN, CNTR_INVALID_VL, 0);
  2678. if (counter_select & CS_PORT_RCV_BECN)
  2679. write_dev_cntr(dd, C_DC_RCV_BCN, CNTR_INVALID_VL, 0);
  2680. /* ignore cs_port_xmit_time_cong for HFIs */
  2681. /* ignore cs_port_xmit_wasted_bw for now */
  2682. /* ignore cs_port_xmit_wait_data for now */
  2683. if (counter_select & CS_PORT_RCV_BUBBLE)
  2684. write_dev_cntr(dd, C_DC_RCV_BBL, CNTR_INVALID_VL, 0);
  2685. /* Only applicable for switch */
  2686. /* if (counter_select & CS_PORT_MARK_FECN)
  2687. * write_csr(dd, DCC_PRF_PORT_MARK_FECN_CNT, 0);
  2688. */
  2689. if (counter_select & CS_PORT_RCV_CONSTRAINT_ERRORS)
  2690. write_port_cntr(ppd, C_SW_RCV_CSTR_ERR, CNTR_INVALID_VL, 0);
  2691. /* ignore cs_port_rcv_switch_relay_errors for HFIs */
  2692. if (counter_select & CS_PORT_XMIT_DISCARDS)
  2693. write_port_cntr(ppd, C_SW_XMIT_DSCD, CNTR_INVALID_VL, 0);
  2694. if (counter_select & CS_PORT_XMIT_CONSTRAINT_ERRORS)
  2695. write_port_cntr(ppd, C_SW_XMIT_CSTR_ERR, CNTR_INVALID_VL, 0);
  2696. if (counter_select & CS_PORT_RCV_REMOTE_PHYSICAL_ERRORS)
  2697. write_dev_cntr(dd, C_DC_RMT_PHY_ERR, CNTR_INVALID_VL, 0);
  2698. if (counter_select & CS_LOCAL_LINK_INTEGRITY_ERRORS)
  2699. write_dev_cntr(dd, C_DC_RX_REPLAY, CNTR_INVALID_VL, 0);
  2700. if (counter_select & CS_LINK_ERROR_RECOVERY) {
  2701. write_dev_cntr(dd, C_DC_SEQ_CRC_CNT, CNTR_INVALID_VL, 0);
  2702. write_dev_cntr(dd, C_DC_REINIT_FROM_PEER_CNT,
  2703. CNTR_INVALID_VL, 0);
  2704. }
  2705. if (counter_select & CS_PORT_RCV_ERRORS)
  2706. write_dev_cntr(dd, C_DC_RCV_ERR, CNTR_INVALID_VL, 0);
  2707. if (counter_select & CS_EXCESSIVE_BUFFER_OVERRUNS) {
  2708. write_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL, 0);
  2709. dd->rcv_ovfl_cnt = 0;
  2710. }
  2711. if (counter_select & CS_FM_CONFIG_ERRORS)
  2712. write_dev_cntr(dd, C_DC_FM_CFG_ERR, CNTR_INVALID_VL, 0);
  2713. if (counter_select & CS_LINK_DOWNED)
  2714. write_port_cntr(ppd, C_SW_LINK_DOWN, CNTR_INVALID_VL, 0);
  2715. if (counter_select & CS_UNCORRECTABLE_ERRORS)
  2716. write_dev_cntr(dd, C_DC_UNC_ERR, CNTR_INVALID_VL, 0);
  2717. for_each_set_bit(vl, (unsigned long *)&(vl_select_mask),
  2718. 8 * sizeof(vl_select_mask)) {
  2719. if (counter_select & CS_PORT_XMIT_DATA)
  2720. write_port_cntr(ppd, C_TX_FLIT_VL, idx_from_vl(vl), 0);
  2721. if (counter_select & CS_PORT_RCV_DATA)
  2722. write_dev_cntr(dd, C_DC_RX_FLIT_VL, idx_from_vl(vl), 0);
  2723. if (counter_select & CS_PORT_XMIT_PKTS)
  2724. write_port_cntr(ppd, C_TX_PKT_VL, idx_from_vl(vl), 0);
  2725. if (counter_select & CS_PORT_RCV_PKTS)
  2726. write_dev_cntr(dd, C_DC_RX_PKT_VL, idx_from_vl(vl), 0);
  2727. if (counter_select & CS_PORT_XMIT_WAIT)
  2728. write_port_cntr(ppd, C_TX_WAIT_VL, idx_from_vl(vl), 0);
  2729. /* sw_port_vl_congestion is 0 for HFIs */
  2730. if (counter_select & CS_PORT_RCV_FECN)
  2731. write_dev_cntr(dd, C_DC_RCV_FCN_VL, idx_from_vl(vl), 0);
  2732. if (counter_select & CS_PORT_RCV_BECN)
  2733. write_dev_cntr(dd, C_DC_RCV_BCN_VL, idx_from_vl(vl), 0);
  2734. /* port_vl_xmit_time_cong is 0 for HFIs */
  2735. /* port_vl_xmit_wasted_bw ??? */
  2736. /* port_vl_xmit_wait_data - TXE (table 13-9 HFI spec) ??? */
  2737. if (counter_select & CS_PORT_RCV_BUBBLE)
  2738. write_dev_cntr(dd, C_DC_RCV_BBL_VL, idx_from_vl(vl), 0);
  2739. /* if (counter_select & CS_PORT_MARK_FECN)
  2740. * write_csr(dd, DCC_PRF_PORT_VL_MARK_FECN_CNT + offset, 0);
  2741. */
  2742. if (counter_select & C_SW_XMIT_DSCD_VL)
  2743. write_port_cntr(ppd, C_SW_XMIT_DSCD_VL,
  2744. idx_from_vl(vl), 0);
  2745. }
  2746. if (resp_len)
  2747. *resp_len += sizeof(*req);
  2748. return reply((struct ib_mad_hdr *)pmp);
  2749. }
  2750. static int pma_set_opa_errorinfo(struct opa_pma_mad *pmp,
  2751. struct ib_device *ibdev,
  2752. u8 port, u32 *resp_len)
  2753. {
  2754. struct _port_ei *rsp;
  2755. struct opa_port_error_info_msg *req;
  2756. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  2757. u64 port_mask;
  2758. u32 num_ports;
  2759. u8 port_num;
  2760. u8 num_pslm;
  2761. u32 error_info_select;
  2762. req = (struct opa_port_error_info_msg *)pmp->data;
  2763. rsp = &req->port[0];
  2764. num_ports = OPA_AM_NPORT(be32_to_cpu(pmp->mad_hdr.attr_mod));
  2765. num_pslm = hweight64(be64_to_cpu(req->port_select_mask[3]));
  2766. memset(rsp, 0, sizeof(*rsp));
  2767. if (num_ports != 1 || num_ports != num_pslm) {
  2768. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  2769. return reply((struct ib_mad_hdr *)pmp);
  2770. }
  2771. /*
  2772. * The bit set in the mask needs to be consistent with the port
  2773. * the request came in on.
  2774. */
  2775. port_mask = be64_to_cpu(req->port_select_mask[3]);
  2776. port_num = find_first_bit((unsigned long *)&port_mask,
  2777. sizeof(port_mask));
  2778. if (port_num != port) {
  2779. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  2780. return reply((struct ib_mad_hdr *)pmp);
  2781. }
  2782. error_info_select = be32_to_cpu(req->error_info_select_mask);
  2783. /* PortRcvErrorInfo */
  2784. if (error_info_select & ES_PORT_RCV_ERROR_INFO)
  2785. /* turn off status bit */
  2786. dd->err_info_rcvport.status_and_code &= ~OPA_EI_STATUS_SMASK;
  2787. /* ExcessiverBufferOverrunInfo */
  2788. if (error_info_select & ES_EXCESSIVE_BUFFER_OVERRUN_INFO)
  2789. /*
  2790. * status bit is essentially kept in the h/w - bit 5 of
  2791. * RCV_ERR_INFO
  2792. */
  2793. write_csr(dd, RCV_ERR_INFO,
  2794. RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SMASK);
  2795. if (error_info_select & ES_PORT_XMIT_CONSTRAINT_ERROR_INFO)
  2796. dd->err_info_xmit_constraint.status &= ~OPA_EI_STATUS_SMASK;
  2797. if (error_info_select & ES_PORT_RCV_CONSTRAINT_ERROR_INFO)
  2798. dd->err_info_rcv_constraint.status &= ~OPA_EI_STATUS_SMASK;
  2799. /* UncorrectableErrorInfo */
  2800. if (error_info_select & ES_UNCORRECTABLE_ERROR_INFO)
  2801. /* turn off status bit */
  2802. dd->err_info_uncorrectable &= ~OPA_EI_STATUS_SMASK;
  2803. /* FMConfigErrorInfo */
  2804. if (error_info_select & ES_FM_CONFIG_ERROR_INFO)
  2805. /* turn off status bit */
  2806. dd->err_info_fmconfig &= ~OPA_EI_STATUS_SMASK;
  2807. if (resp_len)
  2808. *resp_len += sizeof(*req);
  2809. return reply((struct ib_mad_hdr *)pmp);
  2810. }
  2811. struct opa_congestion_info_attr {
  2812. __be16 congestion_info;
  2813. u8 control_table_cap; /* Multiple of 64 entry unit CCTs */
  2814. u8 congestion_log_length;
  2815. } __packed;
  2816. static int __subn_get_opa_cong_info(struct opa_smp *smp, u32 am, u8 *data,
  2817. struct ib_device *ibdev, u8 port,
  2818. u32 *resp_len)
  2819. {
  2820. struct opa_congestion_info_attr *p =
  2821. (struct opa_congestion_info_attr *)data;
  2822. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  2823. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  2824. p->congestion_info = 0;
  2825. p->control_table_cap = ppd->cc_max_table_entries;
  2826. p->congestion_log_length = OPA_CONG_LOG_ELEMS;
  2827. if (resp_len)
  2828. *resp_len += sizeof(*p);
  2829. return reply((struct ib_mad_hdr *)smp);
  2830. }
  2831. static int __subn_get_opa_cong_setting(struct opa_smp *smp, u32 am,
  2832. u8 *data, struct ib_device *ibdev,
  2833. u8 port, u32 *resp_len)
  2834. {
  2835. int i;
  2836. struct opa_congestion_setting_attr *p =
  2837. (struct opa_congestion_setting_attr *)data;
  2838. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  2839. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  2840. struct opa_congestion_setting_entry_shadow *entries;
  2841. struct cc_state *cc_state;
  2842. rcu_read_lock();
  2843. cc_state = get_cc_state(ppd);
  2844. if (!cc_state) {
  2845. rcu_read_unlock();
  2846. return reply((struct ib_mad_hdr *)smp);
  2847. }
  2848. entries = cc_state->cong_setting.entries;
  2849. p->port_control = cpu_to_be16(cc_state->cong_setting.port_control);
  2850. p->control_map = cpu_to_be32(cc_state->cong_setting.control_map);
  2851. for (i = 0; i < OPA_MAX_SLS; i++) {
  2852. p->entries[i].ccti_increase = entries[i].ccti_increase;
  2853. p->entries[i].ccti_timer = cpu_to_be16(entries[i].ccti_timer);
  2854. p->entries[i].trigger_threshold =
  2855. entries[i].trigger_threshold;
  2856. p->entries[i].ccti_min = entries[i].ccti_min;
  2857. }
  2858. rcu_read_unlock();
  2859. if (resp_len)
  2860. *resp_len += sizeof(*p);
  2861. return reply((struct ib_mad_hdr *)smp);
  2862. }
  2863. /*
  2864. * Apply congestion control information stored in the ppd to the
  2865. * active structure.
  2866. */
  2867. static void apply_cc_state(struct hfi1_pportdata *ppd)
  2868. {
  2869. struct cc_state *old_cc_state, *new_cc_state;
  2870. new_cc_state = kzalloc(sizeof(*new_cc_state), GFP_KERNEL);
  2871. if (!new_cc_state)
  2872. return;
  2873. /*
  2874. * Hold the lock for updating *and* to prevent ppd information
  2875. * from changing during the update.
  2876. */
  2877. spin_lock(&ppd->cc_state_lock);
  2878. old_cc_state = get_cc_state_protected(ppd);
  2879. if (!old_cc_state) {
  2880. /* never active, or shutting down */
  2881. spin_unlock(&ppd->cc_state_lock);
  2882. kfree(new_cc_state);
  2883. return;
  2884. }
  2885. *new_cc_state = *old_cc_state;
  2886. new_cc_state->cct.ccti_limit = ppd->total_cct_entry - 1;
  2887. memcpy(new_cc_state->cct.entries, ppd->ccti_entries,
  2888. ppd->total_cct_entry * sizeof(struct ib_cc_table_entry));
  2889. new_cc_state->cong_setting.port_control = IB_CC_CCS_PC_SL_BASED;
  2890. new_cc_state->cong_setting.control_map = ppd->cc_sl_control_map;
  2891. memcpy(new_cc_state->cong_setting.entries, ppd->congestion_entries,
  2892. OPA_MAX_SLS * sizeof(struct opa_congestion_setting_entry));
  2893. rcu_assign_pointer(ppd->cc_state, new_cc_state);
  2894. spin_unlock(&ppd->cc_state_lock);
  2895. kfree_rcu(old_cc_state, rcu);
  2896. }
  2897. static int __subn_set_opa_cong_setting(struct opa_smp *smp, u32 am, u8 *data,
  2898. struct ib_device *ibdev, u8 port,
  2899. u32 *resp_len)
  2900. {
  2901. struct opa_congestion_setting_attr *p =
  2902. (struct opa_congestion_setting_attr *)data;
  2903. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  2904. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  2905. struct opa_congestion_setting_entry_shadow *entries;
  2906. int i;
  2907. /*
  2908. * Save details from packet into the ppd. Hold the cc_state_lock so
  2909. * our information is consistent with anyone trying to apply the state.
  2910. */
  2911. spin_lock(&ppd->cc_state_lock);
  2912. ppd->cc_sl_control_map = be32_to_cpu(p->control_map);
  2913. entries = ppd->congestion_entries;
  2914. for (i = 0; i < OPA_MAX_SLS; i++) {
  2915. entries[i].ccti_increase = p->entries[i].ccti_increase;
  2916. entries[i].ccti_timer = be16_to_cpu(p->entries[i].ccti_timer);
  2917. entries[i].trigger_threshold =
  2918. p->entries[i].trigger_threshold;
  2919. entries[i].ccti_min = p->entries[i].ccti_min;
  2920. }
  2921. spin_unlock(&ppd->cc_state_lock);
  2922. /* now apply the information */
  2923. apply_cc_state(ppd);
  2924. return __subn_get_opa_cong_setting(smp, am, data, ibdev, port,
  2925. resp_len);
  2926. }
  2927. static int __subn_get_opa_hfi1_cong_log(struct opa_smp *smp, u32 am,
  2928. u8 *data, struct ib_device *ibdev,
  2929. u8 port, u32 *resp_len)
  2930. {
  2931. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  2932. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  2933. struct opa_hfi1_cong_log *cong_log = (struct opa_hfi1_cong_log *)data;
  2934. s64 ts;
  2935. int i;
  2936. if (am != 0) {
  2937. smp->status |= IB_SMP_INVALID_FIELD;
  2938. return reply((struct ib_mad_hdr *)smp);
  2939. }
  2940. spin_lock_irq(&ppd->cc_log_lock);
  2941. cong_log->log_type = OPA_CC_LOG_TYPE_HFI;
  2942. cong_log->congestion_flags = 0;
  2943. cong_log->threshold_event_counter =
  2944. cpu_to_be16(ppd->threshold_event_counter);
  2945. memcpy(cong_log->threshold_cong_event_map,
  2946. ppd->threshold_cong_event_map,
  2947. sizeof(cong_log->threshold_cong_event_map));
  2948. /* keep timestamp in units of 1.024 usec */
  2949. ts = ktime_to_ns(ktime_get()) / 1024;
  2950. cong_log->current_time_stamp = cpu_to_be32(ts);
  2951. for (i = 0; i < OPA_CONG_LOG_ELEMS; i++) {
  2952. struct opa_hfi1_cong_log_event_internal *cce =
  2953. &ppd->cc_events[ppd->cc_mad_idx++];
  2954. if (ppd->cc_mad_idx == OPA_CONG_LOG_ELEMS)
  2955. ppd->cc_mad_idx = 0;
  2956. /*
  2957. * Entries which are older than twice the time
  2958. * required to wrap the counter are supposed to
  2959. * be zeroed (CA10-49 IBTA, release 1.2.1, V1).
  2960. */
  2961. if ((u64)(ts - cce->timestamp) > (2 * UINT_MAX))
  2962. continue;
  2963. memcpy(cong_log->events[i].local_qp_cn_entry, &cce->lqpn, 3);
  2964. memcpy(cong_log->events[i].remote_qp_number_cn_entry,
  2965. &cce->rqpn, 3);
  2966. cong_log->events[i].sl_svc_type_cn_entry =
  2967. ((cce->sl & 0x1f) << 3) | (cce->svc_type & 0x7);
  2968. cong_log->events[i].remote_lid_cn_entry =
  2969. cpu_to_be32(cce->rlid);
  2970. cong_log->events[i].timestamp_cn_entry =
  2971. cpu_to_be32(cce->timestamp);
  2972. }
  2973. /*
  2974. * Reset threshold_cong_event_map, and threshold_event_counter
  2975. * to 0 when log is read.
  2976. */
  2977. memset(ppd->threshold_cong_event_map, 0x0,
  2978. sizeof(ppd->threshold_cong_event_map));
  2979. ppd->threshold_event_counter = 0;
  2980. spin_unlock_irq(&ppd->cc_log_lock);
  2981. if (resp_len)
  2982. *resp_len += sizeof(struct opa_hfi1_cong_log);
  2983. return reply((struct ib_mad_hdr *)smp);
  2984. }
  2985. static int __subn_get_opa_cc_table(struct opa_smp *smp, u32 am, u8 *data,
  2986. struct ib_device *ibdev, u8 port,
  2987. u32 *resp_len)
  2988. {
  2989. struct ib_cc_table_attr *cc_table_attr =
  2990. (struct ib_cc_table_attr *)data;
  2991. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  2992. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  2993. u32 start_block = OPA_AM_START_BLK(am);
  2994. u32 n_blocks = OPA_AM_NBLK(am);
  2995. struct ib_cc_table_entry_shadow *entries;
  2996. int i, j;
  2997. u32 sentry, eentry;
  2998. struct cc_state *cc_state;
  2999. /* sanity check n_blocks, start_block */
  3000. if (n_blocks == 0 ||
  3001. start_block + n_blocks > ppd->cc_max_table_entries) {
  3002. smp->status |= IB_SMP_INVALID_FIELD;
  3003. return reply((struct ib_mad_hdr *)smp);
  3004. }
  3005. rcu_read_lock();
  3006. cc_state = get_cc_state(ppd);
  3007. if (!cc_state) {
  3008. rcu_read_unlock();
  3009. return reply((struct ib_mad_hdr *)smp);
  3010. }
  3011. sentry = start_block * IB_CCT_ENTRIES;
  3012. eentry = sentry + (IB_CCT_ENTRIES * n_blocks);
  3013. cc_table_attr->ccti_limit = cpu_to_be16(cc_state->cct.ccti_limit);
  3014. entries = cc_state->cct.entries;
  3015. /* return n_blocks, though the last block may not be full */
  3016. for (j = 0, i = sentry; i < eentry; j++, i++)
  3017. cc_table_attr->ccti_entries[j].entry =
  3018. cpu_to_be16(entries[i].entry);
  3019. rcu_read_unlock();
  3020. if (resp_len)
  3021. *resp_len += sizeof(u16) * (IB_CCT_ENTRIES * n_blocks + 1);
  3022. return reply((struct ib_mad_hdr *)smp);
  3023. }
  3024. static int __subn_set_opa_cc_table(struct opa_smp *smp, u32 am, u8 *data,
  3025. struct ib_device *ibdev, u8 port,
  3026. u32 *resp_len)
  3027. {
  3028. struct ib_cc_table_attr *p = (struct ib_cc_table_attr *)data;
  3029. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  3030. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  3031. u32 start_block = OPA_AM_START_BLK(am);
  3032. u32 n_blocks = OPA_AM_NBLK(am);
  3033. struct ib_cc_table_entry_shadow *entries;
  3034. int i, j;
  3035. u32 sentry, eentry;
  3036. u16 ccti_limit;
  3037. /* sanity check n_blocks, start_block */
  3038. if (n_blocks == 0 ||
  3039. start_block + n_blocks > ppd->cc_max_table_entries) {
  3040. smp->status |= IB_SMP_INVALID_FIELD;
  3041. return reply((struct ib_mad_hdr *)smp);
  3042. }
  3043. sentry = start_block * IB_CCT_ENTRIES;
  3044. eentry = sentry + ((n_blocks - 1) * IB_CCT_ENTRIES) +
  3045. (be16_to_cpu(p->ccti_limit)) % IB_CCT_ENTRIES + 1;
  3046. /* sanity check ccti_limit */
  3047. ccti_limit = be16_to_cpu(p->ccti_limit);
  3048. if (ccti_limit + 1 > eentry) {
  3049. smp->status |= IB_SMP_INVALID_FIELD;
  3050. return reply((struct ib_mad_hdr *)smp);
  3051. }
  3052. /*
  3053. * Save details from packet into the ppd. Hold the cc_state_lock so
  3054. * our information is consistent with anyone trying to apply the state.
  3055. */
  3056. spin_lock(&ppd->cc_state_lock);
  3057. ppd->total_cct_entry = ccti_limit + 1;
  3058. entries = ppd->ccti_entries;
  3059. for (j = 0, i = sentry; i < eentry; j++, i++)
  3060. entries[i].entry = be16_to_cpu(p->ccti_entries[j].entry);
  3061. spin_unlock(&ppd->cc_state_lock);
  3062. /* now apply the information */
  3063. apply_cc_state(ppd);
  3064. return __subn_get_opa_cc_table(smp, am, data, ibdev, port, resp_len);
  3065. }
  3066. struct opa_led_info {
  3067. __be32 rsvd_led_mask;
  3068. __be32 rsvd;
  3069. };
  3070. #define OPA_LED_SHIFT 31
  3071. #define OPA_LED_MASK BIT(OPA_LED_SHIFT)
  3072. static int __subn_get_opa_led_info(struct opa_smp *smp, u32 am, u8 *data,
  3073. struct ib_device *ibdev, u8 port,
  3074. u32 *resp_len)
  3075. {
  3076. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  3077. struct hfi1_pportdata *ppd = dd->pport;
  3078. struct opa_led_info *p = (struct opa_led_info *)data;
  3079. u32 nport = OPA_AM_NPORT(am);
  3080. u32 is_beaconing_active;
  3081. if (nport != 1) {
  3082. smp->status |= IB_SMP_INVALID_FIELD;
  3083. return reply((struct ib_mad_hdr *)smp);
  3084. }
  3085. /*
  3086. * This pairs with the memory barrier in hfi1_start_led_override to
  3087. * ensure that we read the correct state of LED beaconing represented
  3088. * by led_override_timer_active
  3089. */
  3090. smp_rmb();
  3091. is_beaconing_active = !!atomic_read(&ppd->led_override_timer_active);
  3092. p->rsvd_led_mask = cpu_to_be32(is_beaconing_active << OPA_LED_SHIFT);
  3093. if (resp_len)
  3094. *resp_len += sizeof(struct opa_led_info);
  3095. return reply((struct ib_mad_hdr *)smp);
  3096. }
  3097. static int __subn_set_opa_led_info(struct opa_smp *smp, u32 am, u8 *data,
  3098. struct ib_device *ibdev, u8 port,
  3099. u32 *resp_len)
  3100. {
  3101. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  3102. struct opa_led_info *p = (struct opa_led_info *)data;
  3103. u32 nport = OPA_AM_NPORT(am);
  3104. int on = !!(be32_to_cpu(p->rsvd_led_mask) & OPA_LED_MASK);
  3105. if (nport != 1) {
  3106. smp->status |= IB_SMP_INVALID_FIELD;
  3107. return reply((struct ib_mad_hdr *)smp);
  3108. }
  3109. if (on)
  3110. hfi1_start_led_override(dd->pport, 2000, 1500);
  3111. else
  3112. shutdown_led_override(dd->pport);
  3113. return __subn_get_opa_led_info(smp, am, data, ibdev, port, resp_len);
  3114. }
  3115. static int subn_get_opa_sma(__be16 attr_id, struct opa_smp *smp, u32 am,
  3116. u8 *data, struct ib_device *ibdev, u8 port,
  3117. u32 *resp_len)
  3118. {
  3119. int ret;
  3120. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  3121. switch (attr_id) {
  3122. case IB_SMP_ATTR_NODE_DESC:
  3123. ret = __subn_get_opa_nodedesc(smp, am, data, ibdev, port,
  3124. resp_len);
  3125. break;
  3126. case IB_SMP_ATTR_NODE_INFO:
  3127. ret = __subn_get_opa_nodeinfo(smp, am, data, ibdev, port,
  3128. resp_len);
  3129. break;
  3130. case IB_SMP_ATTR_PORT_INFO:
  3131. ret = __subn_get_opa_portinfo(smp, am, data, ibdev, port,
  3132. resp_len);
  3133. break;
  3134. case IB_SMP_ATTR_PKEY_TABLE:
  3135. ret = __subn_get_opa_pkeytable(smp, am, data, ibdev, port,
  3136. resp_len);
  3137. break;
  3138. case OPA_ATTRIB_ID_SL_TO_SC_MAP:
  3139. ret = __subn_get_opa_sl_to_sc(smp, am, data, ibdev, port,
  3140. resp_len);
  3141. break;
  3142. case OPA_ATTRIB_ID_SC_TO_SL_MAP:
  3143. ret = __subn_get_opa_sc_to_sl(smp, am, data, ibdev, port,
  3144. resp_len);
  3145. break;
  3146. case OPA_ATTRIB_ID_SC_TO_VLT_MAP:
  3147. ret = __subn_get_opa_sc_to_vlt(smp, am, data, ibdev, port,
  3148. resp_len);
  3149. break;
  3150. case OPA_ATTRIB_ID_SC_TO_VLNT_MAP:
  3151. ret = __subn_get_opa_sc_to_vlnt(smp, am, data, ibdev, port,
  3152. resp_len);
  3153. break;
  3154. case OPA_ATTRIB_ID_PORT_STATE_INFO:
  3155. ret = __subn_get_opa_psi(smp, am, data, ibdev, port,
  3156. resp_len);
  3157. break;
  3158. case OPA_ATTRIB_ID_BUFFER_CONTROL_TABLE:
  3159. ret = __subn_get_opa_bct(smp, am, data, ibdev, port,
  3160. resp_len);
  3161. break;
  3162. case OPA_ATTRIB_ID_CABLE_INFO:
  3163. ret = __subn_get_opa_cable_info(smp, am, data, ibdev, port,
  3164. resp_len);
  3165. break;
  3166. case IB_SMP_ATTR_VL_ARB_TABLE:
  3167. ret = __subn_get_opa_vl_arb(smp, am, data, ibdev, port,
  3168. resp_len);
  3169. break;
  3170. case OPA_ATTRIB_ID_CONGESTION_INFO:
  3171. ret = __subn_get_opa_cong_info(smp, am, data, ibdev, port,
  3172. resp_len);
  3173. break;
  3174. case OPA_ATTRIB_ID_HFI_CONGESTION_SETTING:
  3175. ret = __subn_get_opa_cong_setting(smp, am, data, ibdev,
  3176. port, resp_len);
  3177. break;
  3178. case OPA_ATTRIB_ID_HFI_CONGESTION_LOG:
  3179. ret = __subn_get_opa_hfi1_cong_log(smp, am, data, ibdev,
  3180. port, resp_len);
  3181. break;
  3182. case OPA_ATTRIB_ID_CONGESTION_CONTROL_TABLE:
  3183. ret = __subn_get_opa_cc_table(smp, am, data, ibdev, port,
  3184. resp_len);
  3185. break;
  3186. case IB_SMP_ATTR_LED_INFO:
  3187. ret = __subn_get_opa_led_info(smp, am, data, ibdev, port,
  3188. resp_len);
  3189. break;
  3190. case IB_SMP_ATTR_SM_INFO:
  3191. if (ibp->rvp.port_cap_flags & IB_PORT_SM_DISABLED)
  3192. return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
  3193. if (ibp->rvp.port_cap_flags & IB_PORT_SM)
  3194. return IB_MAD_RESULT_SUCCESS;
  3195. /* FALLTHROUGH */
  3196. default:
  3197. smp->status |= IB_SMP_UNSUP_METH_ATTR;
  3198. ret = reply((struct ib_mad_hdr *)smp);
  3199. break;
  3200. }
  3201. return ret;
  3202. }
  3203. static int subn_set_opa_sma(__be16 attr_id, struct opa_smp *smp, u32 am,
  3204. u8 *data, struct ib_device *ibdev, u8 port,
  3205. u32 *resp_len)
  3206. {
  3207. int ret;
  3208. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  3209. switch (attr_id) {
  3210. case IB_SMP_ATTR_PORT_INFO:
  3211. ret = __subn_set_opa_portinfo(smp, am, data, ibdev, port,
  3212. resp_len);
  3213. break;
  3214. case IB_SMP_ATTR_PKEY_TABLE:
  3215. ret = __subn_set_opa_pkeytable(smp, am, data, ibdev, port,
  3216. resp_len);
  3217. break;
  3218. case OPA_ATTRIB_ID_SL_TO_SC_MAP:
  3219. ret = __subn_set_opa_sl_to_sc(smp, am, data, ibdev, port,
  3220. resp_len);
  3221. break;
  3222. case OPA_ATTRIB_ID_SC_TO_SL_MAP:
  3223. ret = __subn_set_opa_sc_to_sl(smp, am, data, ibdev, port,
  3224. resp_len);
  3225. break;
  3226. case OPA_ATTRIB_ID_SC_TO_VLT_MAP:
  3227. ret = __subn_set_opa_sc_to_vlt(smp, am, data, ibdev, port,
  3228. resp_len);
  3229. break;
  3230. case OPA_ATTRIB_ID_SC_TO_VLNT_MAP:
  3231. ret = __subn_set_opa_sc_to_vlnt(smp, am, data, ibdev, port,
  3232. resp_len);
  3233. break;
  3234. case OPA_ATTRIB_ID_PORT_STATE_INFO:
  3235. ret = __subn_set_opa_psi(smp, am, data, ibdev, port,
  3236. resp_len);
  3237. break;
  3238. case OPA_ATTRIB_ID_BUFFER_CONTROL_TABLE:
  3239. ret = __subn_set_opa_bct(smp, am, data, ibdev, port,
  3240. resp_len);
  3241. break;
  3242. case IB_SMP_ATTR_VL_ARB_TABLE:
  3243. ret = __subn_set_opa_vl_arb(smp, am, data, ibdev, port,
  3244. resp_len);
  3245. break;
  3246. case OPA_ATTRIB_ID_HFI_CONGESTION_SETTING:
  3247. ret = __subn_set_opa_cong_setting(smp, am, data, ibdev,
  3248. port, resp_len);
  3249. break;
  3250. case OPA_ATTRIB_ID_CONGESTION_CONTROL_TABLE:
  3251. ret = __subn_set_opa_cc_table(smp, am, data, ibdev, port,
  3252. resp_len);
  3253. break;
  3254. case IB_SMP_ATTR_LED_INFO:
  3255. ret = __subn_set_opa_led_info(smp, am, data, ibdev, port,
  3256. resp_len);
  3257. break;
  3258. case IB_SMP_ATTR_SM_INFO:
  3259. if (ibp->rvp.port_cap_flags & IB_PORT_SM_DISABLED)
  3260. return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
  3261. if (ibp->rvp.port_cap_flags & IB_PORT_SM)
  3262. return IB_MAD_RESULT_SUCCESS;
  3263. /* FALLTHROUGH */
  3264. default:
  3265. smp->status |= IB_SMP_UNSUP_METH_ATTR;
  3266. ret = reply((struct ib_mad_hdr *)smp);
  3267. break;
  3268. }
  3269. return ret;
  3270. }
  3271. static inline void set_aggr_error(struct opa_aggregate *ag)
  3272. {
  3273. ag->err_reqlength |= cpu_to_be16(0x8000);
  3274. }
  3275. static int subn_get_opa_aggregate(struct opa_smp *smp,
  3276. struct ib_device *ibdev, u8 port,
  3277. u32 *resp_len)
  3278. {
  3279. int i;
  3280. u32 num_attr = be32_to_cpu(smp->attr_mod) & 0x000000ff;
  3281. u8 *next_smp = opa_get_smp_data(smp);
  3282. if (num_attr < 1 || num_attr > 117) {
  3283. smp->status |= IB_SMP_INVALID_FIELD;
  3284. return reply((struct ib_mad_hdr *)smp);
  3285. }
  3286. for (i = 0; i < num_attr; i++) {
  3287. struct opa_aggregate *agg;
  3288. size_t agg_data_len;
  3289. size_t agg_size;
  3290. u32 am;
  3291. agg = (struct opa_aggregate *)next_smp;
  3292. agg_data_len = (be16_to_cpu(agg->err_reqlength) & 0x007f) * 8;
  3293. agg_size = sizeof(*agg) + agg_data_len;
  3294. am = be32_to_cpu(agg->attr_mod);
  3295. *resp_len += agg_size;
  3296. if (next_smp + agg_size > ((u8 *)smp) + sizeof(*smp)) {
  3297. smp->status |= IB_SMP_INVALID_FIELD;
  3298. return reply((struct ib_mad_hdr *)smp);
  3299. }
  3300. /* zero the payload for this segment */
  3301. memset(next_smp + sizeof(*agg), 0, agg_data_len);
  3302. (void)subn_get_opa_sma(agg->attr_id, smp, am, agg->data,
  3303. ibdev, port, NULL);
  3304. if (smp->status & ~IB_SMP_DIRECTION) {
  3305. set_aggr_error(agg);
  3306. return reply((struct ib_mad_hdr *)smp);
  3307. }
  3308. next_smp += agg_size;
  3309. }
  3310. return reply((struct ib_mad_hdr *)smp);
  3311. }
  3312. static int subn_set_opa_aggregate(struct opa_smp *smp,
  3313. struct ib_device *ibdev, u8 port,
  3314. u32 *resp_len)
  3315. {
  3316. int i;
  3317. u32 num_attr = be32_to_cpu(smp->attr_mod) & 0x000000ff;
  3318. u8 *next_smp = opa_get_smp_data(smp);
  3319. if (num_attr < 1 || num_attr > 117) {
  3320. smp->status |= IB_SMP_INVALID_FIELD;
  3321. return reply((struct ib_mad_hdr *)smp);
  3322. }
  3323. for (i = 0; i < num_attr; i++) {
  3324. struct opa_aggregate *agg;
  3325. size_t agg_data_len;
  3326. size_t agg_size;
  3327. u32 am;
  3328. agg = (struct opa_aggregate *)next_smp;
  3329. agg_data_len = (be16_to_cpu(agg->err_reqlength) & 0x007f) * 8;
  3330. agg_size = sizeof(*agg) + agg_data_len;
  3331. am = be32_to_cpu(agg->attr_mod);
  3332. *resp_len += agg_size;
  3333. if (next_smp + agg_size > ((u8 *)smp) + sizeof(*smp)) {
  3334. smp->status |= IB_SMP_INVALID_FIELD;
  3335. return reply((struct ib_mad_hdr *)smp);
  3336. }
  3337. (void)subn_set_opa_sma(agg->attr_id, smp, am, agg->data,
  3338. ibdev, port, NULL);
  3339. if (smp->status & ~IB_SMP_DIRECTION) {
  3340. set_aggr_error(agg);
  3341. return reply((struct ib_mad_hdr *)smp);
  3342. }
  3343. next_smp += agg_size;
  3344. }
  3345. return reply((struct ib_mad_hdr *)smp);
  3346. }
  3347. /*
  3348. * OPAv1 specifies that, on the transition to link up, these counters
  3349. * are cleared:
  3350. * PortRcvErrors [*]
  3351. * LinkErrorRecovery
  3352. * LocalLinkIntegrityErrors
  3353. * ExcessiveBufferOverruns [*]
  3354. *
  3355. * [*] Error info associated with these counters is retained, but the
  3356. * error info status is reset to 0.
  3357. */
  3358. void clear_linkup_counters(struct hfi1_devdata *dd)
  3359. {
  3360. /* PortRcvErrors */
  3361. write_dev_cntr(dd, C_DC_RCV_ERR, CNTR_INVALID_VL, 0);
  3362. dd->err_info_rcvport.status_and_code &= ~OPA_EI_STATUS_SMASK;
  3363. /* LinkErrorRecovery */
  3364. write_dev_cntr(dd, C_DC_SEQ_CRC_CNT, CNTR_INVALID_VL, 0);
  3365. write_dev_cntr(dd, C_DC_REINIT_FROM_PEER_CNT, CNTR_INVALID_VL, 0);
  3366. /* LocalLinkIntegrityErrors */
  3367. write_dev_cntr(dd, C_DC_RX_REPLAY, CNTR_INVALID_VL, 0);
  3368. /* ExcessiveBufferOverruns */
  3369. write_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL, 0);
  3370. dd->rcv_ovfl_cnt = 0;
  3371. dd->err_info_xmit_constraint.status &= ~OPA_EI_STATUS_SMASK;
  3372. }
  3373. /*
  3374. * is_local_mad() returns 1 if 'mad' is sent from, and destined to the
  3375. * local node, 0 otherwise.
  3376. */
  3377. static int is_local_mad(struct hfi1_ibport *ibp, const struct opa_mad *mad,
  3378. const struct ib_wc *in_wc)
  3379. {
  3380. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  3381. const struct opa_smp *smp = (const struct opa_smp *)mad;
  3382. if (smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) {
  3383. return (smp->hop_cnt == 0 &&
  3384. smp->route.dr.dr_slid == OPA_LID_PERMISSIVE &&
  3385. smp->route.dr.dr_dlid == OPA_LID_PERMISSIVE);
  3386. }
  3387. return (in_wc->slid == ppd->lid);
  3388. }
  3389. /*
  3390. * opa_local_smp_check() should only be called on MADs for which
  3391. * is_local_mad() returns true. It applies the SMP checks that are
  3392. * specific to SMPs which are sent from, and destined to this node.
  3393. * opa_local_smp_check() returns 0 if the SMP passes its checks, 1
  3394. * otherwise.
  3395. *
  3396. * SMPs which arrive from other nodes are instead checked by
  3397. * opa_smp_check().
  3398. */
  3399. static int opa_local_smp_check(struct hfi1_ibport *ibp,
  3400. const struct ib_wc *in_wc)
  3401. {
  3402. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  3403. u16 slid = in_wc->slid;
  3404. u16 pkey;
  3405. if (in_wc->pkey_index >= ARRAY_SIZE(ppd->pkeys))
  3406. return 1;
  3407. pkey = ppd->pkeys[in_wc->pkey_index];
  3408. /*
  3409. * We need to do the "node-local" checks specified in OPAv1,
  3410. * rev 0.90, section 9.10.26, which are:
  3411. * - pkey is 0x7fff, or 0xffff
  3412. * - Source QPN == 0 || Destination QPN == 0
  3413. * - the MAD header's management class is either
  3414. * IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE or
  3415. * IB_MGMT_CLASS_SUBN_LID_ROUTED
  3416. * - SLID != 0
  3417. *
  3418. * However, we know (and so don't need to check again) that,
  3419. * for local SMPs, the MAD stack passes MADs with:
  3420. * - Source QPN of 0
  3421. * - MAD mgmt_class is IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
  3422. * - SLID is either: OPA_LID_PERMISSIVE (0xFFFFFFFF), or
  3423. * our own port's lid
  3424. *
  3425. */
  3426. if (pkey == LIM_MGMT_P_KEY || pkey == FULL_MGMT_P_KEY)
  3427. return 0;
  3428. ingress_pkey_table_fail(ppd, pkey, slid);
  3429. return 1;
  3430. }
  3431. static int process_subn_opa(struct ib_device *ibdev, int mad_flags,
  3432. u8 port, const struct opa_mad *in_mad,
  3433. struct opa_mad *out_mad,
  3434. u32 *resp_len)
  3435. {
  3436. struct opa_smp *smp = (struct opa_smp *)out_mad;
  3437. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  3438. u8 *data;
  3439. u32 am;
  3440. __be16 attr_id;
  3441. int ret;
  3442. *out_mad = *in_mad;
  3443. data = opa_get_smp_data(smp);
  3444. am = be32_to_cpu(smp->attr_mod);
  3445. attr_id = smp->attr_id;
  3446. if (smp->class_version != OPA_SMI_CLASS_VERSION) {
  3447. smp->status |= IB_SMP_UNSUP_VERSION;
  3448. ret = reply((struct ib_mad_hdr *)smp);
  3449. return ret;
  3450. }
  3451. ret = check_mkey(ibp, (struct ib_mad_hdr *)smp, mad_flags, smp->mkey,
  3452. smp->route.dr.dr_slid, smp->route.dr.return_path,
  3453. smp->hop_cnt);
  3454. if (ret) {
  3455. u32 port_num = be32_to_cpu(smp->attr_mod);
  3456. /*
  3457. * If this is a get/set portinfo, we already check the
  3458. * M_Key if the MAD is for another port and the M_Key
  3459. * is OK on the receiving port. This check is needed
  3460. * to increment the error counters when the M_Key
  3461. * fails to match on *both* ports.
  3462. */
  3463. if (attr_id == IB_SMP_ATTR_PORT_INFO &&
  3464. (smp->method == IB_MGMT_METHOD_GET ||
  3465. smp->method == IB_MGMT_METHOD_SET) &&
  3466. port_num && port_num <= ibdev->phys_port_cnt &&
  3467. port != port_num)
  3468. (void)check_mkey(to_iport(ibdev, port_num),
  3469. (struct ib_mad_hdr *)smp, 0,
  3470. smp->mkey, smp->route.dr.dr_slid,
  3471. smp->route.dr.return_path,
  3472. smp->hop_cnt);
  3473. ret = IB_MAD_RESULT_FAILURE;
  3474. return ret;
  3475. }
  3476. *resp_len = opa_get_smp_header_size(smp);
  3477. switch (smp->method) {
  3478. case IB_MGMT_METHOD_GET:
  3479. switch (attr_id) {
  3480. default:
  3481. clear_opa_smp_data(smp);
  3482. ret = subn_get_opa_sma(attr_id, smp, am, data,
  3483. ibdev, port, resp_len);
  3484. break;
  3485. case OPA_ATTRIB_ID_AGGREGATE:
  3486. ret = subn_get_opa_aggregate(smp, ibdev, port,
  3487. resp_len);
  3488. break;
  3489. }
  3490. break;
  3491. case IB_MGMT_METHOD_SET:
  3492. switch (attr_id) {
  3493. default:
  3494. ret = subn_set_opa_sma(attr_id, smp, am, data,
  3495. ibdev, port, resp_len);
  3496. break;
  3497. case OPA_ATTRIB_ID_AGGREGATE:
  3498. ret = subn_set_opa_aggregate(smp, ibdev, port,
  3499. resp_len);
  3500. break;
  3501. }
  3502. break;
  3503. case IB_MGMT_METHOD_TRAP:
  3504. case IB_MGMT_METHOD_REPORT:
  3505. case IB_MGMT_METHOD_REPORT_RESP:
  3506. case IB_MGMT_METHOD_GET_RESP:
  3507. /*
  3508. * The ib_mad module will call us to process responses
  3509. * before checking for other consumers.
  3510. * Just tell the caller to process it normally.
  3511. */
  3512. ret = IB_MAD_RESULT_SUCCESS;
  3513. break;
  3514. default:
  3515. smp->status |= IB_SMP_UNSUP_METHOD;
  3516. ret = reply((struct ib_mad_hdr *)smp);
  3517. break;
  3518. }
  3519. return ret;
  3520. }
  3521. static int process_subn(struct ib_device *ibdev, int mad_flags,
  3522. u8 port, const struct ib_mad *in_mad,
  3523. struct ib_mad *out_mad)
  3524. {
  3525. struct ib_smp *smp = (struct ib_smp *)out_mad;
  3526. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  3527. int ret;
  3528. *out_mad = *in_mad;
  3529. if (smp->class_version != 1) {
  3530. smp->status |= IB_SMP_UNSUP_VERSION;
  3531. ret = reply((struct ib_mad_hdr *)smp);
  3532. return ret;
  3533. }
  3534. ret = check_mkey(ibp, (struct ib_mad_hdr *)smp, mad_flags,
  3535. smp->mkey, (__force __be32)smp->dr_slid,
  3536. smp->return_path, smp->hop_cnt);
  3537. if (ret) {
  3538. u32 port_num = be32_to_cpu(smp->attr_mod);
  3539. /*
  3540. * If this is a get/set portinfo, we already check the
  3541. * M_Key if the MAD is for another port and the M_Key
  3542. * is OK on the receiving port. This check is needed
  3543. * to increment the error counters when the M_Key
  3544. * fails to match on *both* ports.
  3545. */
  3546. if (in_mad->mad_hdr.attr_id == IB_SMP_ATTR_PORT_INFO &&
  3547. (smp->method == IB_MGMT_METHOD_GET ||
  3548. smp->method == IB_MGMT_METHOD_SET) &&
  3549. port_num && port_num <= ibdev->phys_port_cnt &&
  3550. port != port_num)
  3551. (void)check_mkey(to_iport(ibdev, port_num),
  3552. (struct ib_mad_hdr *)smp, 0,
  3553. smp->mkey,
  3554. (__force __be32)smp->dr_slid,
  3555. smp->return_path, smp->hop_cnt);
  3556. ret = IB_MAD_RESULT_FAILURE;
  3557. return ret;
  3558. }
  3559. switch (smp->method) {
  3560. case IB_MGMT_METHOD_GET:
  3561. switch (smp->attr_id) {
  3562. case IB_SMP_ATTR_NODE_INFO:
  3563. ret = subn_get_nodeinfo(smp, ibdev, port);
  3564. break;
  3565. default:
  3566. smp->status |= IB_SMP_UNSUP_METH_ATTR;
  3567. ret = reply((struct ib_mad_hdr *)smp);
  3568. break;
  3569. }
  3570. break;
  3571. }
  3572. return ret;
  3573. }
  3574. static int process_perf(struct ib_device *ibdev, u8 port,
  3575. const struct ib_mad *in_mad,
  3576. struct ib_mad *out_mad)
  3577. {
  3578. struct ib_pma_mad *pmp = (struct ib_pma_mad *)out_mad;
  3579. struct ib_class_port_info *cpi = (struct ib_class_port_info *)
  3580. &pmp->data;
  3581. int ret = IB_MAD_RESULT_FAILURE;
  3582. *out_mad = *in_mad;
  3583. if (pmp->mad_hdr.class_version != 1) {
  3584. pmp->mad_hdr.status |= IB_SMP_UNSUP_VERSION;
  3585. ret = reply((struct ib_mad_hdr *)pmp);
  3586. return ret;
  3587. }
  3588. switch (pmp->mad_hdr.method) {
  3589. case IB_MGMT_METHOD_GET:
  3590. switch (pmp->mad_hdr.attr_id) {
  3591. case IB_PMA_PORT_COUNTERS:
  3592. ret = pma_get_ib_portcounters(pmp, ibdev, port);
  3593. break;
  3594. case IB_PMA_PORT_COUNTERS_EXT:
  3595. ret = pma_get_ib_portcounters_ext(pmp, ibdev, port);
  3596. break;
  3597. case IB_PMA_CLASS_PORT_INFO:
  3598. cpi->capability_mask = IB_PMA_CLASS_CAP_EXT_WIDTH;
  3599. ret = reply((struct ib_mad_hdr *)pmp);
  3600. break;
  3601. default:
  3602. pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR;
  3603. ret = reply((struct ib_mad_hdr *)pmp);
  3604. break;
  3605. }
  3606. break;
  3607. case IB_MGMT_METHOD_SET:
  3608. if (pmp->mad_hdr.attr_id) {
  3609. pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR;
  3610. ret = reply((struct ib_mad_hdr *)pmp);
  3611. }
  3612. break;
  3613. case IB_MGMT_METHOD_TRAP:
  3614. case IB_MGMT_METHOD_GET_RESP:
  3615. /*
  3616. * The ib_mad module will call us to process responses
  3617. * before checking for other consumers.
  3618. * Just tell the caller to process it normally.
  3619. */
  3620. ret = IB_MAD_RESULT_SUCCESS;
  3621. break;
  3622. default:
  3623. pmp->mad_hdr.status |= IB_SMP_UNSUP_METHOD;
  3624. ret = reply((struct ib_mad_hdr *)pmp);
  3625. break;
  3626. }
  3627. return ret;
  3628. }
  3629. static int process_perf_opa(struct ib_device *ibdev, u8 port,
  3630. const struct opa_mad *in_mad,
  3631. struct opa_mad *out_mad, u32 *resp_len)
  3632. {
  3633. struct opa_pma_mad *pmp = (struct opa_pma_mad *)out_mad;
  3634. int ret;
  3635. *out_mad = *in_mad;
  3636. if (pmp->mad_hdr.class_version != OPA_SMI_CLASS_VERSION) {
  3637. pmp->mad_hdr.status |= IB_SMP_UNSUP_VERSION;
  3638. return reply((struct ib_mad_hdr *)pmp);
  3639. }
  3640. *resp_len = sizeof(pmp->mad_hdr);
  3641. switch (pmp->mad_hdr.method) {
  3642. case IB_MGMT_METHOD_GET:
  3643. switch (pmp->mad_hdr.attr_id) {
  3644. case IB_PMA_CLASS_PORT_INFO:
  3645. ret = pma_get_opa_classportinfo(pmp, ibdev, resp_len);
  3646. break;
  3647. case OPA_PM_ATTRIB_ID_PORT_STATUS:
  3648. ret = pma_get_opa_portstatus(pmp, ibdev, port,
  3649. resp_len);
  3650. break;
  3651. case OPA_PM_ATTRIB_ID_DATA_PORT_COUNTERS:
  3652. ret = pma_get_opa_datacounters(pmp, ibdev, port,
  3653. resp_len);
  3654. break;
  3655. case OPA_PM_ATTRIB_ID_ERROR_PORT_COUNTERS:
  3656. ret = pma_get_opa_porterrors(pmp, ibdev, port,
  3657. resp_len);
  3658. break;
  3659. case OPA_PM_ATTRIB_ID_ERROR_INFO:
  3660. ret = pma_get_opa_errorinfo(pmp, ibdev, port,
  3661. resp_len);
  3662. break;
  3663. default:
  3664. pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR;
  3665. ret = reply((struct ib_mad_hdr *)pmp);
  3666. break;
  3667. }
  3668. break;
  3669. case IB_MGMT_METHOD_SET:
  3670. switch (pmp->mad_hdr.attr_id) {
  3671. case OPA_PM_ATTRIB_ID_CLEAR_PORT_STATUS:
  3672. ret = pma_set_opa_portstatus(pmp, ibdev, port,
  3673. resp_len);
  3674. break;
  3675. case OPA_PM_ATTRIB_ID_ERROR_INFO:
  3676. ret = pma_set_opa_errorinfo(pmp, ibdev, port,
  3677. resp_len);
  3678. break;
  3679. default:
  3680. pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR;
  3681. ret = reply((struct ib_mad_hdr *)pmp);
  3682. break;
  3683. }
  3684. break;
  3685. case IB_MGMT_METHOD_TRAP:
  3686. case IB_MGMT_METHOD_GET_RESP:
  3687. /*
  3688. * The ib_mad module will call us to process responses
  3689. * before checking for other consumers.
  3690. * Just tell the caller to process it normally.
  3691. */
  3692. ret = IB_MAD_RESULT_SUCCESS;
  3693. break;
  3694. default:
  3695. pmp->mad_hdr.status |= IB_SMP_UNSUP_METHOD;
  3696. ret = reply((struct ib_mad_hdr *)pmp);
  3697. break;
  3698. }
  3699. return ret;
  3700. }
  3701. static int hfi1_process_opa_mad(struct ib_device *ibdev, int mad_flags,
  3702. u8 port, const struct ib_wc *in_wc,
  3703. const struct ib_grh *in_grh,
  3704. const struct opa_mad *in_mad,
  3705. struct opa_mad *out_mad, size_t *out_mad_size,
  3706. u16 *out_mad_pkey_index)
  3707. {
  3708. int ret;
  3709. int pkey_idx;
  3710. u32 resp_len = 0;
  3711. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  3712. pkey_idx = hfi1_lookup_pkey_idx(ibp, LIM_MGMT_P_KEY);
  3713. if (pkey_idx < 0) {
  3714. pr_warn("failed to find limited mgmt pkey, defaulting 0x%x\n",
  3715. hfi1_get_pkey(ibp, 1));
  3716. pkey_idx = 1;
  3717. }
  3718. *out_mad_pkey_index = (u16)pkey_idx;
  3719. switch (in_mad->mad_hdr.mgmt_class) {
  3720. case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE:
  3721. case IB_MGMT_CLASS_SUBN_LID_ROUTED:
  3722. if (is_local_mad(ibp, in_mad, in_wc)) {
  3723. ret = opa_local_smp_check(ibp, in_wc);
  3724. if (ret)
  3725. return IB_MAD_RESULT_FAILURE;
  3726. }
  3727. ret = process_subn_opa(ibdev, mad_flags, port, in_mad,
  3728. out_mad, &resp_len);
  3729. goto bail;
  3730. case IB_MGMT_CLASS_PERF_MGMT:
  3731. ret = process_perf_opa(ibdev, port, in_mad, out_mad,
  3732. &resp_len);
  3733. goto bail;
  3734. default:
  3735. ret = IB_MAD_RESULT_SUCCESS;
  3736. }
  3737. bail:
  3738. if (ret & IB_MAD_RESULT_REPLY)
  3739. *out_mad_size = round_up(resp_len, 8);
  3740. else if (ret & IB_MAD_RESULT_SUCCESS)
  3741. *out_mad_size = in_wc->byte_len - sizeof(struct ib_grh);
  3742. return ret;
  3743. }
  3744. static int hfi1_process_ib_mad(struct ib_device *ibdev, int mad_flags, u8 port,
  3745. const struct ib_wc *in_wc,
  3746. const struct ib_grh *in_grh,
  3747. const struct ib_mad *in_mad,
  3748. struct ib_mad *out_mad)
  3749. {
  3750. int ret;
  3751. switch (in_mad->mad_hdr.mgmt_class) {
  3752. case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE:
  3753. case IB_MGMT_CLASS_SUBN_LID_ROUTED:
  3754. ret = process_subn(ibdev, mad_flags, port, in_mad, out_mad);
  3755. break;
  3756. case IB_MGMT_CLASS_PERF_MGMT:
  3757. ret = process_perf(ibdev, port, in_mad, out_mad);
  3758. break;
  3759. default:
  3760. ret = IB_MAD_RESULT_SUCCESS;
  3761. break;
  3762. }
  3763. return ret;
  3764. }
  3765. /**
  3766. * hfi1_process_mad - process an incoming MAD packet
  3767. * @ibdev: the infiniband device this packet came in on
  3768. * @mad_flags: MAD flags
  3769. * @port: the port number this packet came in on
  3770. * @in_wc: the work completion entry for this packet
  3771. * @in_grh: the global route header for this packet
  3772. * @in_mad: the incoming MAD
  3773. * @out_mad: any outgoing MAD reply
  3774. *
  3775. * Returns IB_MAD_RESULT_SUCCESS if this is a MAD that we are not
  3776. * interested in processing.
  3777. *
  3778. * Note that the verbs framework has already done the MAD sanity checks,
  3779. * and hop count/pointer updating for IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
  3780. * MADs.
  3781. *
  3782. * This is called by the ib_mad module.
  3783. */
  3784. int hfi1_process_mad(struct ib_device *ibdev, int mad_flags, u8 port,
  3785. const struct ib_wc *in_wc, const struct ib_grh *in_grh,
  3786. const struct ib_mad_hdr *in_mad, size_t in_mad_size,
  3787. struct ib_mad_hdr *out_mad, size_t *out_mad_size,
  3788. u16 *out_mad_pkey_index)
  3789. {
  3790. switch (in_mad->base_version) {
  3791. case OPA_MGMT_BASE_VERSION:
  3792. if (unlikely(in_mad_size != sizeof(struct opa_mad))) {
  3793. dev_err(ibdev->dma_device, "invalid in_mad_size\n");
  3794. return IB_MAD_RESULT_FAILURE;
  3795. }
  3796. return hfi1_process_opa_mad(ibdev, mad_flags, port,
  3797. in_wc, in_grh,
  3798. (struct opa_mad *)in_mad,
  3799. (struct opa_mad *)out_mad,
  3800. out_mad_size,
  3801. out_mad_pkey_index);
  3802. case IB_MGMT_BASE_VERSION:
  3803. return hfi1_process_ib_mad(ibdev, mad_flags, port,
  3804. in_wc, in_grh,
  3805. (const struct ib_mad *)in_mad,
  3806. (struct ib_mad *)out_mad);
  3807. default:
  3808. break;
  3809. }
  3810. return IB_MAD_RESULT_FAILURE;
  3811. }