mad.c 125 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427
  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. start_link(ppd);
  871. } else {
  872. set_link_state(ppd, link_state);
  873. }
  874. if (link_state == HLS_DN_DISABLE &&
  875. (ppd->offline_disabled_reason >
  876. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_SMA_DISABLED) ||
  877. ppd->offline_disabled_reason ==
  878. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE)))
  879. ppd->offline_disabled_reason =
  880. HFI1_ODR_MASK(OPA_LINKDOWN_REASON_SMA_DISABLED);
  881. /*
  882. * Don't send a reply if the response would be sent
  883. * through the disabled port.
  884. */
  885. if (link_state == HLS_DN_DISABLE && smp->hop_cnt)
  886. return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
  887. break;
  888. case IB_PORT_ARMED:
  889. ret = set_link_state(ppd, HLS_UP_ARMED);
  890. if ((ret == 0) && (suppress_idle_sma == 0))
  891. send_idle_sma(dd, SMA_IDLE_ARM);
  892. break;
  893. case IB_PORT_ACTIVE:
  894. if (ppd->neighbor_normal) {
  895. ret = set_link_state(ppd, HLS_UP_ACTIVE);
  896. if (ret == 0)
  897. send_idle_sma(dd, SMA_IDLE_ACTIVE);
  898. } else {
  899. pr_warn("SubnSet(OPA_PortInfo) Cannot move to Active with NeighborNormal 0\n");
  900. smp->status |= IB_SMP_INVALID_FIELD;
  901. }
  902. break;
  903. default:
  904. pr_warn("SubnSet(OPA_PortInfo) invalid logical state 0x%x\n",
  905. logical_state);
  906. smp->status |= IB_SMP_INVALID_FIELD;
  907. }
  908. return 0;
  909. }
  910. /**
  911. * subn_set_opa_portinfo - set port information
  912. * @smp: the incoming SM packet
  913. * @ibdev: the infiniband device
  914. * @port: the port on the device
  915. *
  916. */
  917. static int __subn_set_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data,
  918. struct ib_device *ibdev, u8 port,
  919. u32 *resp_len)
  920. {
  921. struct opa_port_info *pi = (struct opa_port_info *)data;
  922. struct ib_event event;
  923. struct hfi1_devdata *dd;
  924. struct hfi1_pportdata *ppd;
  925. struct hfi1_ibport *ibp;
  926. u8 clientrereg;
  927. unsigned long flags;
  928. u32 smlid, opa_lid; /* tmp vars to hold LID values */
  929. u16 lid;
  930. u8 ls_old, ls_new, ps_new;
  931. u8 vls;
  932. u8 msl;
  933. u8 crc_enabled;
  934. u16 lse, lwe, mtu;
  935. u32 num_ports = OPA_AM_NPORT(am);
  936. u32 start_of_sm_config = OPA_AM_START_SM_CFG(am);
  937. int ret, i, invalid = 0, call_set_mtu = 0;
  938. int call_link_downgrade_policy = 0;
  939. if (num_ports != 1) {
  940. smp->status |= IB_SMP_INVALID_FIELD;
  941. return reply((struct ib_mad_hdr *)smp);
  942. }
  943. opa_lid = be32_to_cpu(pi->lid);
  944. if (opa_lid & 0xFFFF0000) {
  945. pr_warn("OPA_PortInfo lid out of range: %X\n", opa_lid);
  946. smp->status |= IB_SMP_INVALID_FIELD;
  947. goto get_only;
  948. }
  949. lid = (u16)(opa_lid & 0x0000FFFF);
  950. smlid = be32_to_cpu(pi->sm_lid);
  951. if (smlid & 0xFFFF0000) {
  952. pr_warn("OPA_PortInfo SM lid out of range: %X\n", smlid);
  953. smp->status |= IB_SMP_INVALID_FIELD;
  954. goto get_only;
  955. }
  956. smlid &= 0x0000FFFF;
  957. clientrereg = (pi->clientrereg_subnettimeout &
  958. OPA_PI_MASK_CLIENT_REREGISTER);
  959. dd = dd_from_ibdev(ibdev);
  960. /* IB numbers ports from 1, hw from 0 */
  961. ppd = dd->pport + (port - 1);
  962. ibp = &ppd->ibport_data;
  963. event.device = ibdev;
  964. event.element.port_num = port;
  965. ls_old = driver_lstate(ppd);
  966. ibp->rvp.mkey = pi->mkey;
  967. ibp->rvp.gid_prefix = pi->subnet_prefix;
  968. ibp->rvp.mkey_lease_period = be16_to_cpu(pi->mkey_lease_period);
  969. /* Must be a valid unicast LID address. */
  970. if ((lid == 0 && ls_old > IB_PORT_INIT) ||
  971. lid >= be16_to_cpu(IB_MULTICAST_LID_BASE)) {
  972. smp->status |= IB_SMP_INVALID_FIELD;
  973. pr_warn("SubnSet(OPA_PortInfo) lid invalid 0x%x\n",
  974. lid);
  975. } else if (ppd->lid != lid ||
  976. ppd->lmc != (pi->mkeyprotect_lmc & OPA_PI_MASK_LMC)) {
  977. if (ppd->lid != lid)
  978. hfi1_set_uevent_bits(ppd, _HFI1_EVENT_LID_CHANGE_BIT);
  979. if (ppd->lmc != (pi->mkeyprotect_lmc & OPA_PI_MASK_LMC))
  980. hfi1_set_uevent_bits(ppd, _HFI1_EVENT_LMC_CHANGE_BIT);
  981. hfi1_set_lid(ppd, lid, pi->mkeyprotect_lmc & OPA_PI_MASK_LMC);
  982. event.event = IB_EVENT_LID_CHANGE;
  983. ib_dispatch_event(&event);
  984. }
  985. msl = pi->smsl & OPA_PI_MASK_SMSL;
  986. if (pi->partenforce_filterraw & OPA_PI_MASK_LINKINIT_REASON)
  987. ppd->linkinit_reason =
  988. (pi->partenforce_filterraw &
  989. OPA_PI_MASK_LINKINIT_REASON);
  990. /* enable/disable SW pkey checking as per FM control */
  991. if (pi->partenforce_filterraw & OPA_PI_MASK_PARTITION_ENFORCE_IN)
  992. ppd->part_enforce |= HFI1_PART_ENFORCE_IN;
  993. else
  994. ppd->part_enforce &= ~HFI1_PART_ENFORCE_IN;
  995. if (pi->partenforce_filterraw & OPA_PI_MASK_PARTITION_ENFORCE_OUT)
  996. ppd->part_enforce |= HFI1_PART_ENFORCE_OUT;
  997. else
  998. ppd->part_enforce &= ~HFI1_PART_ENFORCE_OUT;
  999. /* Must be a valid unicast LID address. */
  1000. if ((smlid == 0 && ls_old > IB_PORT_INIT) ||
  1001. smlid >= be16_to_cpu(IB_MULTICAST_LID_BASE)) {
  1002. smp->status |= IB_SMP_INVALID_FIELD;
  1003. pr_warn("SubnSet(OPA_PortInfo) smlid invalid 0x%x\n", smlid);
  1004. } else if (smlid != ibp->rvp.sm_lid || msl != ibp->rvp.sm_sl) {
  1005. pr_warn("SubnSet(OPA_PortInfo) smlid 0x%x\n", smlid);
  1006. spin_lock_irqsave(&ibp->rvp.lock, flags);
  1007. if (ibp->rvp.sm_ah) {
  1008. if (smlid != ibp->rvp.sm_lid)
  1009. ibp->rvp.sm_ah->attr.dlid = smlid;
  1010. if (msl != ibp->rvp.sm_sl)
  1011. ibp->rvp.sm_ah->attr.sl = msl;
  1012. }
  1013. spin_unlock_irqrestore(&ibp->rvp.lock, flags);
  1014. if (smlid != ibp->rvp.sm_lid)
  1015. ibp->rvp.sm_lid = smlid;
  1016. if (msl != ibp->rvp.sm_sl)
  1017. ibp->rvp.sm_sl = msl;
  1018. event.event = IB_EVENT_SM_CHANGE;
  1019. ib_dispatch_event(&event);
  1020. }
  1021. if (pi->link_down_reason == 0) {
  1022. ppd->local_link_down_reason.sma = 0;
  1023. ppd->local_link_down_reason.latest = 0;
  1024. }
  1025. if (pi->neigh_link_down_reason == 0) {
  1026. ppd->neigh_link_down_reason.sma = 0;
  1027. ppd->neigh_link_down_reason.latest = 0;
  1028. }
  1029. ppd->sm_trap_qp = be32_to_cpu(pi->sm_trap_qp);
  1030. ppd->sa_qp = be32_to_cpu(pi->sa_qp);
  1031. ppd->port_error_action = be32_to_cpu(pi->port_error_action);
  1032. lwe = be16_to_cpu(pi->link_width.enabled);
  1033. if (lwe) {
  1034. if (lwe == OPA_LINK_WIDTH_RESET ||
  1035. lwe == OPA_LINK_WIDTH_RESET_OLD)
  1036. set_link_width_enabled(ppd, ppd->link_width_supported);
  1037. else if ((lwe & ~ppd->link_width_supported) == 0)
  1038. set_link_width_enabled(ppd, lwe);
  1039. else
  1040. smp->status |= IB_SMP_INVALID_FIELD;
  1041. }
  1042. lwe = be16_to_cpu(pi->link_width_downgrade.enabled);
  1043. /* LWD.E is always applied - 0 means "disabled" */
  1044. if (lwe == OPA_LINK_WIDTH_RESET ||
  1045. lwe == OPA_LINK_WIDTH_RESET_OLD) {
  1046. set_link_width_downgrade_enabled(ppd,
  1047. ppd->
  1048. link_width_downgrade_supported
  1049. );
  1050. } else if ((lwe & ~ppd->link_width_downgrade_supported) == 0) {
  1051. /* only set and apply if something changed */
  1052. if (lwe != ppd->link_width_downgrade_enabled) {
  1053. set_link_width_downgrade_enabled(ppd, lwe);
  1054. call_link_downgrade_policy = 1;
  1055. }
  1056. } else {
  1057. smp->status |= IB_SMP_INVALID_FIELD;
  1058. }
  1059. lse = be16_to_cpu(pi->link_speed.enabled);
  1060. if (lse) {
  1061. if (lse & be16_to_cpu(pi->link_speed.supported))
  1062. set_link_speed_enabled(ppd, lse);
  1063. else
  1064. smp->status |= IB_SMP_INVALID_FIELD;
  1065. }
  1066. ibp->rvp.mkeyprot =
  1067. (pi->mkeyprotect_lmc & OPA_PI_MASK_MKEY_PROT_BIT) >> 6;
  1068. ibp->rvp.vl_high_limit = be16_to_cpu(pi->vl.high_limit) & 0xFF;
  1069. (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_VL_HIGH_LIMIT,
  1070. ibp->rvp.vl_high_limit);
  1071. if (ppd->vls_supported / 2 > ARRAY_SIZE(pi->neigh_mtu.pvlx_to_mtu) ||
  1072. ppd->vls_supported > ARRAY_SIZE(dd->vld)) {
  1073. smp->status |= IB_SMP_INVALID_FIELD;
  1074. return reply((struct ib_mad_hdr *)smp);
  1075. }
  1076. for (i = 0; i < ppd->vls_supported; i++) {
  1077. if ((i % 2) == 0)
  1078. mtu = enum_to_mtu((pi->neigh_mtu.pvlx_to_mtu[i / 2] >>
  1079. 4) & 0xF);
  1080. else
  1081. mtu = enum_to_mtu(pi->neigh_mtu.pvlx_to_mtu[i / 2] &
  1082. 0xF);
  1083. if (mtu == 0xffff) {
  1084. pr_warn("SubnSet(OPA_PortInfo) mtu invalid %d (0x%x)\n",
  1085. mtu,
  1086. (pi->neigh_mtu.pvlx_to_mtu[0] >> 4) & 0xF);
  1087. smp->status |= IB_SMP_INVALID_FIELD;
  1088. mtu = hfi1_max_mtu; /* use a valid MTU */
  1089. }
  1090. if (dd->vld[i].mtu != mtu) {
  1091. dd_dev_info(dd,
  1092. "MTU change on vl %d from %d to %d\n",
  1093. i, dd->vld[i].mtu, mtu);
  1094. dd->vld[i].mtu = mtu;
  1095. call_set_mtu++;
  1096. }
  1097. }
  1098. /* As per OPAV1 spec: VL15 must support and be configured
  1099. * for operation with a 2048 or larger MTU.
  1100. */
  1101. mtu = enum_to_mtu(pi->neigh_mtu.pvlx_to_mtu[15 / 2] & 0xF);
  1102. if (mtu < 2048 || mtu == 0xffff)
  1103. mtu = 2048;
  1104. if (dd->vld[15].mtu != mtu) {
  1105. dd_dev_info(dd,
  1106. "MTU change on vl 15 from %d to %d\n",
  1107. dd->vld[15].mtu, mtu);
  1108. dd->vld[15].mtu = mtu;
  1109. call_set_mtu++;
  1110. }
  1111. if (call_set_mtu)
  1112. set_mtu(ppd);
  1113. /* Set operational VLs */
  1114. vls = pi->operational_vls & OPA_PI_MASK_OPERATIONAL_VL;
  1115. if (vls) {
  1116. if (vls > ppd->vls_supported) {
  1117. pr_warn("SubnSet(OPA_PortInfo) VL's supported invalid %d\n",
  1118. pi->operational_vls);
  1119. smp->status |= IB_SMP_INVALID_FIELD;
  1120. } else {
  1121. if (hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_OP_VLS,
  1122. vls) == -EINVAL)
  1123. smp->status |= IB_SMP_INVALID_FIELD;
  1124. }
  1125. }
  1126. if (pi->mkey_violations == 0)
  1127. ibp->rvp.mkey_violations = 0;
  1128. if (pi->pkey_violations == 0)
  1129. ibp->rvp.pkey_violations = 0;
  1130. if (pi->qkey_violations == 0)
  1131. ibp->rvp.qkey_violations = 0;
  1132. ibp->rvp.subnet_timeout =
  1133. pi->clientrereg_subnettimeout & OPA_PI_MASK_SUBNET_TIMEOUT;
  1134. crc_enabled = be16_to_cpu(pi->port_ltp_crc_mode);
  1135. crc_enabled >>= 4;
  1136. crc_enabled &= 0xf;
  1137. if (crc_enabled != 0)
  1138. ppd->port_crc_mode_enabled = port_ltp_to_cap(crc_enabled);
  1139. ppd->is_active_optimize_enabled =
  1140. !!(be16_to_cpu(pi->port_mode)
  1141. & OPA_PI_MASK_PORT_ACTIVE_OPTOMIZE);
  1142. ls_new = pi->port_states.portphysstate_portstate &
  1143. OPA_PI_MASK_PORT_STATE;
  1144. ps_new = (pi->port_states.portphysstate_portstate &
  1145. OPA_PI_MASK_PORT_PHYSICAL_STATE) >> 4;
  1146. if (ls_old == IB_PORT_INIT) {
  1147. if (start_of_sm_config) {
  1148. if (ls_new == ls_old || (ls_new == IB_PORT_ARMED))
  1149. ppd->is_sm_config_started = 1;
  1150. } else if (ls_new == IB_PORT_ARMED) {
  1151. if (ppd->is_sm_config_started == 0)
  1152. invalid = 1;
  1153. }
  1154. }
  1155. /* Handle CLIENT_REREGISTER event b/c SM asked us for it */
  1156. if (clientrereg) {
  1157. event.event = IB_EVENT_CLIENT_REREGISTER;
  1158. ib_dispatch_event(&event);
  1159. }
  1160. /*
  1161. * Do the port state change now that the other link parameters
  1162. * have been set.
  1163. * Changing the port physical state only makes sense if the link
  1164. * is down or is being set to down.
  1165. */
  1166. ret = set_port_states(ppd, smp, ls_new, ps_new, invalid);
  1167. if (ret)
  1168. return ret;
  1169. ret = __subn_get_opa_portinfo(smp, am, data, ibdev, port, resp_len);
  1170. /* restore re-reg bit per o14-12.2.1 */
  1171. pi->clientrereg_subnettimeout |= clientrereg;
  1172. /*
  1173. * Apply the new link downgrade policy. This may result in a link
  1174. * bounce. Do this after everything else so things are settled.
  1175. * Possible problem: if setting the port state above fails, then
  1176. * the policy change is not applied.
  1177. */
  1178. if (call_link_downgrade_policy)
  1179. apply_link_downgrade_policy(ppd, 0);
  1180. return ret;
  1181. get_only:
  1182. return __subn_get_opa_portinfo(smp, am, data, ibdev, port, resp_len);
  1183. }
  1184. /**
  1185. * set_pkeys - set the PKEY table for ctxt 0
  1186. * @dd: the hfi1_ib device
  1187. * @port: the IB port number
  1188. * @pkeys: the PKEY table
  1189. */
  1190. static int set_pkeys(struct hfi1_devdata *dd, u8 port, u16 *pkeys)
  1191. {
  1192. struct hfi1_pportdata *ppd;
  1193. int i;
  1194. int changed = 0;
  1195. int update_includes_mgmt_partition = 0;
  1196. /*
  1197. * IB port one/two always maps to context zero/one,
  1198. * always a kernel context, no locking needed
  1199. * If we get here with ppd setup, no need to check
  1200. * that rcd is valid.
  1201. */
  1202. ppd = dd->pport + (port - 1);
  1203. /*
  1204. * If the update does not include the management pkey, don't do it.
  1205. */
  1206. for (i = 0; i < ARRAY_SIZE(ppd->pkeys); i++) {
  1207. if (pkeys[i] == LIM_MGMT_P_KEY) {
  1208. update_includes_mgmt_partition = 1;
  1209. break;
  1210. }
  1211. }
  1212. if (!update_includes_mgmt_partition)
  1213. return 1;
  1214. for (i = 0; i < ARRAY_SIZE(ppd->pkeys); i++) {
  1215. u16 key = pkeys[i];
  1216. u16 okey = ppd->pkeys[i];
  1217. if (key == okey)
  1218. continue;
  1219. /*
  1220. * The SM gives us the complete PKey table. We have
  1221. * to ensure that we put the PKeys in the matching
  1222. * slots.
  1223. */
  1224. ppd->pkeys[i] = key;
  1225. changed = 1;
  1226. }
  1227. if (changed) {
  1228. (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0);
  1229. hfi1_event_pkey_change(dd, port);
  1230. }
  1231. return 0;
  1232. }
  1233. static int __subn_set_opa_pkeytable(struct opa_smp *smp, u32 am, u8 *data,
  1234. struct ib_device *ibdev, u8 port,
  1235. u32 *resp_len)
  1236. {
  1237. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  1238. u32 n_blocks_sent = OPA_AM_NBLK(am);
  1239. u32 start_block = am & 0x7ff;
  1240. u16 *p = (u16 *)data;
  1241. __be16 *q = (__be16 *)data;
  1242. int i;
  1243. u16 n_blocks_avail;
  1244. unsigned npkeys = hfi1_get_npkeys(dd);
  1245. if (n_blocks_sent == 0) {
  1246. pr_warn("OPA Get PKey AM Invalid : P = %d; B = 0x%x; N = 0x%x\n",
  1247. port, start_block, n_blocks_sent);
  1248. smp->status |= IB_SMP_INVALID_FIELD;
  1249. return reply((struct ib_mad_hdr *)smp);
  1250. }
  1251. n_blocks_avail = (u16)(npkeys / OPA_PARTITION_TABLE_BLK_SIZE) + 1;
  1252. if (start_block + n_blocks_sent > n_blocks_avail ||
  1253. n_blocks_sent > OPA_NUM_PKEY_BLOCKS_PER_SMP) {
  1254. pr_warn("OPA Set PKey AM Invalid : s 0x%x; req 0x%x; avail 0x%x; blk/smp 0x%lx\n",
  1255. start_block, n_blocks_sent, n_blocks_avail,
  1256. OPA_NUM_PKEY_BLOCKS_PER_SMP);
  1257. smp->status |= IB_SMP_INVALID_FIELD;
  1258. return reply((struct ib_mad_hdr *)smp);
  1259. }
  1260. for (i = 0; i < n_blocks_sent * OPA_PARTITION_TABLE_BLK_SIZE; i++)
  1261. p[i] = be16_to_cpu(q[i]);
  1262. if (start_block == 0 && set_pkeys(dd, port, p) != 0) {
  1263. smp->status |= IB_SMP_INVALID_FIELD;
  1264. return reply((struct ib_mad_hdr *)smp);
  1265. }
  1266. return __subn_get_opa_pkeytable(smp, am, data, ibdev, port, resp_len);
  1267. }
  1268. static int get_sc2vlt_tables(struct hfi1_devdata *dd, void *data)
  1269. {
  1270. u64 *val = data;
  1271. *val++ = read_csr(dd, SEND_SC2VLT0);
  1272. *val++ = read_csr(dd, SEND_SC2VLT1);
  1273. *val++ = read_csr(dd, SEND_SC2VLT2);
  1274. *val++ = read_csr(dd, SEND_SC2VLT3);
  1275. return 0;
  1276. }
  1277. #define ILLEGAL_VL 12
  1278. /*
  1279. * filter_sc2vlt changes mappings to VL15 to ILLEGAL_VL (except
  1280. * for SC15, which must map to VL15). If we don't remap things this
  1281. * way it is possible for VL15 counters to increment when we try to
  1282. * send on a SC which is mapped to an invalid VL.
  1283. */
  1284. static void filter_sc2vlt(void *data)
  1285. {
  1286. int i;
  1287. u8 *pd = data;
  1288. for (i = 0; i < OPA_MAX_SCS; i++) {
  1289. if (i == 15)
  1290. continue;
  1291. if ((pd[i] & 0x1f) == 0xf)
  1292. pd[i] = ILLEGAL_VL;
  1293. }
  1294. }
  1295. static int set_sc2vlt_tables(struct hfi1_devdata *dd, void *data)
  1296. {
  1297. u64 *val = data;
  1298. filter_sc2vlt(data);
  1299. write_csr(dd, SEND_SC2VLT0, *val++);
  1300. write_csr(dd, SEND_SC2VLT1, *val++);
  1301. write_csr(dd, SEND_SC2VLT2, *val++);
  1302. write_csr(dd, SEND_SC2VLT3, *val++);
  1303. write_seqlock_irq(&dd->sc2vl_lock);
  1304. memcpy(dd->sc2vl, data, sizeof(dd->sc2vl));
  1305. write_sequnlock_irq(&dd->sc2vl_lock);
  1306. return 0;
  1307. }
  1308. static int __subn_get_opa_sl_to_sc(struct opa_smp *smp, u32 am, u8 *data,
  1309. struct ib_device *ibdev, u8 port,
  1310. u32 *resp_len)
  1311. {
  1312. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  1313. u8 *p = data;
  1314. size_t size = ARRAY_SIZE(ibp->sl_to_sc); /* == 32 */
  1315. unsigned i;
  1316. if (am) {
  1317. smp->status |= IB_SMP_INVALID_FIELD;
  1318. return reply((struct ib_mad_hdr *)smp);
  1319. }
  1320. for (i = 0; i < ARRAY_SIZE(ibp->sl_to_sc); i++)
  1321. *p++ = ibp->sl_to_sc[i];
  1322. if (resp_len)
  1323. *resp_len += size;
  1324. return reply((struct ib_mad_hdr *)smp);
  1325. }
  1326. static int __subn_set_opa_sl_to_sc(struct opa_smp *smp, u32 am, u8 *data,
  1327. struct ib_device *ibdev, u8 port,
  1328. u32 *resp_len)
  1329. {
  1330. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  1331. u8 *p = data;
  1332. int i;
  1333. u8 sc;
  1334. if (am) {
  1335. smp->status |= IB_SMP_INVALID_FIELD;
  1336. return reply((struct ib_mad_hdr *)smp);
  1337. }
  1338. for (i = 0; i < ARRAY_SIZE(ibp->sl_to_sc); i++) {
  1339. sc = *p++;
  1340. if (ibp->sl_to_sc[i] != sc) {
  1341. ibp->sl_to_sc[i] = sc;
  1342. /* Put all stale qps into error state */
  1343. hfi1_error_port_qps(ibp, i);
  1344. }
  1345. }
  1346. return __subn_get_opa_sl_to_sc(smp, am, data, ibdev, port, resp_len);
  1347. }
  1348. static int __subn_get_opa_sc_to_sl(struct opa_smp *smp, u32 am, u8 *data,
  1349. struct ib_device *ibdev, u8 port,
  1350. u32 *resp_len)
  1351. {
  1352. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  1353. u8 *p = data;
  1354. size_t size = ARRAY_SIZE(ibp->sc_to_sl); /* == 32 */
  1355. unsigned i;
  1356. if (am) {
  1357. smp->status |= IB_SMP_INVALID_FIELD;
  1358. return reply((struct ib_mad_hdr *)smp);
  1359. }
  1360. for (i = 0; i < ARRAY_SIZE(ibp->sc_to_sl); i++)
  1361. *p++ = ibp->sc_to_sl[i];
  1362. if (resp_len)
  1363. *resp_len += size;
  1364. return reply((struct ib_mad_hdr *)smp);
  1365. }
  1366. static int __subn_set_opa_sc_to_sl(struct opa_smp *smp, u32 am, u8 *data,
  1367. struct ib_device *ibdev, u8 port,
  1368. u32 *resp_len)
  1369. {
  1370. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  1371. u8 *p = data;
  1372. int i;
  1373. if (am) {
  1374. smp->status |= IB_SMP_INVALID_FIELD;
  1375. return reply((struct ib_mad_hdr *)smp);
  1376. }
  1377. for (i = 0; i < ARRAY_SIZE(ibp->sc_to_sl); i++)
  1378. ibp->sc_to_sl[i] = *p++;
  1379. return __subn_get_opa_sc_to_sl(smp, am, data, ibdev, port, resp_len);
  1380. }
  1381. static int __subn_get_opa_sc_to_vlt(struct opa_smp *smp, u32 am, u8 *data,
  1382. struct ib_device *ibdev, u8 port,
  1383. u32 *resp_len)
  1384. {
  1385. u32 n_blocks = OPA_AM_NBLK(am);
  1386. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  1387. void *vp = (void *)data;
  1388. size_t size = 4 * sizeof(u64);
  1389. if (n_blocks != 1) {
  1390. smp->status |= IB_SMP_INVALID_FIELD;
  1391. return reply((struct ib_mad_hdr *)smp);
  1392. }
  1393. get_sc2vlt_tables(dd, vp);
  1394. if (resp_len)
  1395. *resp_len += size;
  1396. return reply((struct ib_mad_hdr *)smp);
  1397. }
  1398. static int __subn_set_opa_sc_to_vlt(struct opa_smp *smp, u32 am, u8 *data,
  1399. struct ib_device *ibdev, u8 port,
  1400. u32 *resp_len)
  1401. {
  1402. u32 n_blocks = OPA_AM_NBLK(am);
  1403. int async_update = OPA_AM_ASYNC(am);
  1404. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  1405. void *vp = (void *)data;
  1406. struct hfi1_pportdata *ppd;
  1407. int lstate;
  1408. if (n_blocks != 1 || async_update) {
  1409. smp->status |= IB_SMP_INVALID_FIELD;
  1410. return reply((struct ib_mad_hdr *)smp);
  1411. }
  1412. /* IB numbers ports from 1, hw from 0 */
  1413. ppd = dd->pport + (port - 1);
  1414. lstate = driver_lstate(ppd);
  1415. /*
  1416. * it's known that async_update is 0 by this point, but include
  1417. * the explicit check for clarity
  1418. */
  1419. if (!async_update &&
  1420. (lstate == IB_PORT_ARMED || lstate == IB_PORT_ACTIVE)) {
  1421. smp->status |= IB_SMP_INVALID_FIELD;
  1422. return reply((struct ib_mad_hdr *)smp);
  1423. }
  1424. set_sc2vlt_tables(dd, vp);
  1425. return __subn_get_opa_sc_to_vlt(smp, am, data, ibdev, port, resp_len);
  1426. }
  1427. static int __subn_get_opa_sc_to_vlnt(struct opa_smp *smp, u32 am, u8 *data,
  1428. struct ib_device *ibdev, u8 port,
  1429. u32 *resp_len)
  1430. {
  1431. u32 n_blocks = OPA_AM_NPORT(am);
  1432. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  1433. struct hfi1_pportdata *ppd;
  1434. void *vp = (void *)data;
  1435. int size;
  1436. if (n_blocks != 1) {
  1437. smp->status |= IB_SMP_INVALID_FIELD;
  1438. return reply((struct ib_mad_hdr *)smp);
  1439. }
  1440. ppd = dd->pport + (port - 1);
  1441. size = fm_get_table(ppd, FM_TBL_SC2VLNT, vp);
  1442. if (resp_len)
  1443. *resp_len += size;
  1444. return reply((struct ib_mad_hdr *)smp);
  1445. }
  1446. static int __subn_set_opa_sc_to_vlnt(struct opa_smp *smp, u32 am, u8 *data,
  1447. struct ib_device *ibdev, u8 port,
  1448. u32 *resp_len)
  1449. {
  1450. u32 n_blocks = OPA_AM_NPORT(am);
  1451. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  1452. struct hfi1_pportdata *ppd;
  1453. void *vp = (void *)data;
  1454. int lstate;
  1455. if (n_blocks != 1) {
  1456. smp->status |= IB_SMP_INVALID_FIELD;
  1457. return reply((struct ib_mad_hdr *)smp);
  1458. }
  1459. /* IB numbers ports from 1, hw from 0 */
  1460. ppd = dd->pport + (port - 1);
  1461. lstate = driver_lstate(ppd);
  1462. if (lstate == IB_PORT_ARMED || lstate == IB_PORT_ACTIVE) {
  1463. smp->status |= IB_SMP_INVALID_FIELD;
  1464. return reply((struct ib_mad_hdr *)smp);
  1465. }
  1466. ppd = dd->pport + (port - 1);
  1467. fm_set_table(ppd, FM_TBL_SC2VLNT, vp);
  1468. return __subn_get_opa_sc_to_vlnt(smp, am, data, ibdev, port,
  1469. resp_len);
  1470. }
  1471. static int __subn_get_opa_psi(struct opa_smp *smp, u32 am, u8 *data,
  1472. struct ib_device *ibdev, u8 port,
  1473. u32 *resp_len)
  1474. {
  1475. u32 nports = OPA_AM_NPORT(am);
  1476. u32 start_of_sm_config = OPA_AM_START_SM_CFG(am);
  1477. u32 lstate;
  1478. struct hfi1_ibport *ibp;
  1479. struct hfi1_pportdata *ppd;
  1480. struct opa_port_state_info *psi = (struct opa_port_state_info *)data;
  1481. if (nports != 1) {
  1482. smp->status |= IB_SMP_INVALID_FIELD;
  1483. return reply((struct ib_mad_hdr *)smp);
  1484. }
  1485. ibp = to_iport(ibdev, port);
  1486. ppd = ppd_from_ibp(ibp);
  1487. lstate = driver_lstate(ppd);
  1488. if (start_of_sm_config && (lstate == IB_PORT_INIT))
  1489. ppd->is_sm_config_started = 1;
  1490. psi->port_states.ledenable_offlinereason = ppd->neighbor_normal << 4;
  1491. psi->port_states.ledenable_offlinereason |=
  1492. ppd->is_sm_config_started << 5;
  1493. psi->port_states.ledenable_offlinereason |=
  1494. ppd->offline_disabled_reason;
  1495. psi->port_states.portphysstate_portstate =
  1496. (hfi1_ibphys_portstate(ppd) << 4) | (lstate & 0xf);
  1497. psi->link_width_downgrade_tx_active =
  1498. cpu_to_be16(ppd->link_width_downgrade_tx_active);
  1499. psi->link_width_downgrade_rx_active =
  1500. cpu_to_be16(ppd->link_width_downgrade_rx_active);
  1501. if (resp_len)
  1502. *resp_len += sizeof(struct opa_port_state_info);
  1503. return reply((struct ib_mad_hdr *)smp);
  1504. }
  1505. static int __subn_set_opa_psi(struct opa_smp *smp, u32 am, u8 *data,
  1506. struct ib_device *ibdev, u8 port,
  1507. u32 *resp_len)
  1508. {
  1509. u32 nports = OPA_AM_NPORT(am);
  1510. u32 start_of_sm_config = OPA_AM_START_SM_CFG(am);
  1511. u32 ls_old;
  1512. u8 ls_new, ps_new;
  1513. struct hfi1_ibport *ibp;
  1514. struct hfi1_pportdata *ppd;
  1515. struct opa_port_state_info *psi = (struct opa_port_state_info *)data;
  1516. int ret, invalid = 0;
  1517. if (nports != 1) {
  1518. smp->status |= IB_SMP_INVALID_FIELD;
  1519. return reply((struct ib_mad_hdr *)smp);
  1520. }
  1521. ibp = to_iport(ibdev, port);
  1522. ppd = ppd_from_ibp(ibp);
  1523. ls_old = driver_lstate(ppd);
  1524. ls_new = port_states_to_logical_state(&psi->port_states);
  1525. ps_new = port_states_to_phys_state(&psi->port_states);
  1526. if (ls_old == IB_PORT_INIT) {
  1527. if (start_of_sm_config) {
  1528. if (ls_new == ls_old || (ls_new == IB_PORT_ARMED))
  1529. ppd->is_sm_config_started = 1;
  1530. } else if (ls_new == IB_PORT_ARMED) {
  1531. if (ppd->is_sm_config_started == 0)
  1532. invalid = 1;
  1533. }
  1534. }
  1535. ret = set_port_states(ppd, smp, ls_new, ps_new, invalid);
  1536. if (ret)
  1537. return ret;
  1538. if (invalid)
  1539. smp->status |= IB_SMP_INVALID_FIELD;
  1540. return __subn_get_opa_psi(smp, am, data, ibdev, port, resp_len);
  1541. }
  1542. static int __subn_get_opa_cable_info(struct opa_smp *smp, u32 am, u8 *data,
  1543. struct ib_device *ibdev, u8 port,
  1544. u32 *resp_len)
  1545. {
  1546. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  1547. u32 addr = OPA_AM_CI_ADDR(am);
  1548. u32 len = OPA_AM_CI_LEN(am) + 1;
  1549. int ret;
  1550. if (dd->pport->port_type != PORT_TYPE_QSFP) {
  1551. smp->status |= IB_SMP_INVALID_FIELD;
  1552. return reply((struct ib_mad_hdr *)smp);
  1553. }
  1554. #define __CI_PAGE_SIZE BIT(7) /* 128 bytes */
  1555. #define __CI_PAGE_MASK ~(__CI_PAGE_SIZE - 1)
  1556. #define __CI_PAGE_NUM(a) ((a) & __CI_PAGE_MASK)
  1557. /*
  1558. * check that addr is within spec, and
  1559. * addr and (addr + len - 1) are on the same "page"
  1560. */
  1561. if (addr >= 4096 ||
  1562. (__CI_PAGE_NUM(addr) != __CI_PAGE_NUM(addr + len - 1))) {
  1563. smp->status |= IB_SMP_INVALID_FIELD;
  1564. return reply((struct ib_mad_hdr *)smp);
  1565. }
  1566. ret = get_cable_info(dd, port, addr, len, data);
  1567. if (ret == -ENODEV) {
  1568. smp->status |= IB_SMP_UNSUP_METH_ATTR;
  1569. return reply((struct ib_mad_hdr *)smp);
  1570. }
  1571. /* The address range for the CableInfo SMA query is wider than the
  1572. * memory available on the QSFP cable. We want to return a valid
  1573. * response, albeit zeroed out, for address ranges beyond available
  1574. * memory but that are within the CableInfo query spec
  1575. */
  1576. if (ret < 0 && ret != -ERANGE) {
  1577. smp->status |= IB_SMP_INVALID_FIELD;
  1578. return reply((struct ib_mad_hdr *)smp);
  1579. }
  1580. if (resp_len)
  1581. *resp_len += len;
  1582. return reply((struct ib_mad_hdr *)smp);
  1583. }
  1584. static int __subn_get_opa_bct(struct opa_smp *smp, u32 am, u8 *data,
  1585. struct ib_device *ibdev, u8 port, u32 *resp_len)
  1586. {
  1587. u32 num_ports = OPA_AM_NPORT(am);
  1588. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  1589. struct hfi1_pportdata *ppd;
  1590. struct buffer_control *p = (struct buffer_control *)data;
  1591. int size;
  1592. if (num_ports != 1) {
  1593. smp->status |= IB_SMP_INVALID_FIELD;
  1594. return reply((struct ib_mad_hdr *)smp);
  1595. }
  1596. ppd = dd->pport + (port - 1);
  1597. size = fm_get_table(ppd, FM_TBL_BUFFER_CONTROL, p);
  1598. trace_bct_get(dd, p);
  1599. if (resp_len)
  1600. *resp_len += size;
  1601. return reply((struct ib_mad_hdr *)smp);
  1602. }
  1603. static int __subn_set_opa_bct(struct opa_smp *smp, u32 am, u8 *data,
  1604. struct ib_device *ibdev, u8 port, u32 *resp_len)
  1605. {
  1606. u32 num_ports = OPA_AM_NPORT(am);
  1607. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  1608. struct hfi1_pportdata *ppd;
  1609. struct buffer_control *p = (struct buffer_control *)data;
  1610. if (num_ports != 1) {
  1611. smp->status |= IB_SMP_INVALID_FIELD;
  1612. return reply((struct ib_mad_hdr *)smp);
  1613. }
  1614. ppd = dd->pport + (port - 1);
  1615. trace_bct_set(dd, p);
  1616. if (fm_set_table(ppd, FM_TBL_BUFFER_CONTROL, p) < 0) {
  1617. smp->status |= IB_SMP_INVALID_FIELD;
  1618. return reply((struct ib_mad_hdr *)smp);
  1619. }
  1620. return __subn_get_opa_bct(smp, am, data, ibdev, port, resp_len);
  1621. }
  1622. static int __subn_get_opa_vl_arb(struct opa_smp *smp, u32 am, u8 *data,
  1623. struct ib_device *ibdev, u8 port,
  1624. u32 *resp_len)
  1625. {
  1626. struct hfi1_pportdata *ppd = ppd_from_ibp(to_iport(ibdev, port));
  1627. u32 num_ports = OPA_AM_NPORT(am);
  1628. u8 section = (am & 0x00ff0000) >> 16;
  1629. u8 *p = data;
  1630. int size = 0;
  1631. if (num_ports != 1) {
  1632. smp->status |= IB_SMP_INVALID_FIELD;
  1633. return reply((struct ib_mad_hdr *)smp);
  1634. }
  1635. switch (section) {
  1636. case OPA_VLARB_LOW_ELEMENTS:
  1637. size = fm_get_table(ppd, FM_TBL_VL_LOW_ARB, p);
  1638. break;
  1639. case OPA_VLARB_HIGH_ELEMENTS:
  1640. size = fm_get_table(ppd, FM_TBL_VL_HIGH_ARB, p);
  1641. break;
  1642. case OPA_VLARB_PREEMPT_ELEMENTS:
  1643. size = fm_get_table(ppd, FM_TBL_VL_PREEMPT_ELEMS, p);
  1644. break;
  1645. case OPA_VLARB_PREEMPT_MATRIX:
  1646. size = fm_get_table(ppd, FM_TBL_VL_PREEMPT_MATRIX, p);
  1647. break;
  1648. default:
  1649. pr_warn("OPA SubnGet(VL Arb) AM Invalid : 0x%x\n",
  1650. be32_to_cpu(smp->attr_mod));
  1651. smp->status |= IB_SMP_INVALID_FIELD;
  1652. break;
  1653. }
  1654. if (size > 0 && resp_len)
  1655. *resp_len += size;
  1656. return reply((struct ib_mad_hdr *)smp);
  1657. }
  1658. static int __subn_set_opa_vl_arb(struct opa_smp *smp, u32 am, u8 *data,
  1659. struct ib_device *ibdev, u8 port,
  1660. u32 *resp_len)
  1661. {
  1662. struct hfi1_pportdata *ppd = ppd_from_ibp(to_iport(ibdev, port));
  1663. u32 num_ports = OPA_AM_NPORT(am);
  1664. u8 section = (am & 0x00ff0000) >> 16;
  1665. u8 *p = data;
  1666. if (num_ports != 1) {
  1667. smp->status |= IB_SMP_INVALID_FIELD;
  1668. return reply((struct ib_mad_hdr *)smp);
  1669. }
  1670. switch (section) {
  1671. case OPA_VLARB_LOW_ELEMENTS:
  1672. (void)fm_set_table(ppd, FM_TBL_VL_LOW_ARB, p);
  1673. break;
  1674. case OPA_VLARB_HIGH_ELEMENTS:
  1675. (void)fm_set_table(ppd, FM_TBL_VL_HIGH_ARB, p);
  1676. break;
  1677. /*
  1678. * neither OPA_VLARB_PREEMPT_ELEMENTS, or OPA_VLARB_PREEMPT_MATRIX
  1679. * can be changed from the default values
  1680. */
  1681. case OPA_VLARB_PREEMPT_ELEMENTS:
  1682. /* FALLTHROUGH */
  1683. case OPA_VLARB_PREEMPT_MATRIX:
  1684. smp->status |= IB_SMP_UNSUP_METH_ATTR;
  1685. break;
  1686. default:
  1687. pr_warn("OPA SubnSet(VL Arb) AM Invalid : 0x%x\n",
  1688. be32_to_cpu(smp->attr_mod));
  1689. smp->status |= IB_SMP_INVALID_FIELD;
  1690. break;
  1691. }
  1692. return __subn_get_opa_vl_arb(smp, am, data, ibdev, port, resp_len);
  1693. }
  1694. struct opa_pma_mad {
  1695. struct ib_mad_hdr mad_hdr;
  1696. u8 data[2024];
  1697. } __packed;
  1698. struct opa_class_port_info {
  1699. u8 base_version;
  1700. u8 class_version;
  1701. __be16 cap_mask;
  1702. __be32 cap_mask2_resp_time;
  1703. u8 redirect_gid[16];
  1704. __be32 redirect_tc_fl;
  1705. __be32 redirect_lid;
  1706. __be32 redirect_sl_qp;
  1707. __be32 redirect_qkey;
  1708. u8 trap_gid[16];
  1709. __be32 trap_tc_fl;
  1710. __be32 trap_lid;
  1711. __be32 trap_hl_qp;
  1712. __be32 trap_qkey;
  1713. __be16 trap_pkey;
  1714. __be16 redirect_pkey;
  1715. u8 trap_sl_rsvd;
  1716. u8 reserved[3];
  1717. } __packed;
  1718. struct opa_port_status_req {
  1719. __u8 port_num;
  1720. __u8 reserved[3];
  1721. __be32 vl_select_mask;
  1722. };
  1723. #define VL_MASK_ALL 0x000080ff
  1724. struct opa_port_status_rsp {
  1725. __u8 port_num;
  1726. __u8 reserved[3];
  1727. __be32 vl_select_mask;
  1728. /* Data counters */
  1729. __be64 port_xmit_data;
  1730. __be64 port_rcv_data;
  1731. __be64 port_xmit_pkts;
  1732. __be64 port_rcv_pkts;
  1733. __be64 port_multicast_xmit_pkts;
  1734. __be64 port_multicast_rcv_pkts;
  1735. __be64 port_xmit_wait;
  1736. __be64 sw_port_congestion;
  1737. __be64 port_rcv_fecn;
  1738. __be64 port_rcv_becn;
  1739. __be64 port_xmit_time_cong;
  1740. __be64 port_xmit_wasted_bw;
  1741. __be64 port_xmit_wait_data;
  1742. __be64 port_rcv_bubble;
  1743. __be64 port_mark_fecn;
  1744. /* Error counters */
  1745. __be64 port_rcv_constraint_errors;
  1746. __be64 port_rcv_switch_relay_errors;
  1747. __be64 port_xmit_discards;
  1748. __be64 port_xmit_constraint_errors;
  1749. __be64 port_rcv_remote_physical_errors;
  1750. __be64 local_link_integrity_errors;
  1751. __be64 port_rcv_errors;
  1752. __be64 excessive_buffer_overruns;
  1753. __be64 fm_config_errors;
  1754. __be32 link_error_recovery;
  1755. __be32 link_downed;
  1756. u8 uncorrectable_errors;
  1757. u8 link_quality_indicator; /* 5res, 3bit */
  1758. u8 res2[6];
  1759. struct _vls_pctrs {
  1760. /* per-VL Data counters */
  1761. __be64 port_vl_xmit_data;
  1762. __be64 port_vl_rcv_data;
  1763. __be64 port_vl_xmit_pkts;
  1764. __be64 port_vl_rcv_pkts;
  1765. __be64 port_vl_xmit_wait;
  1766. __be64 sw_port_vl_congestion;
  1767. __be64 port_vl_rcv_fecn;
  1768. __be64 port_vl_rcv_becn;
  1769. __be64 port_xmit_time_cong;
  1770. __be64 port_vl_xmit_wasted_bw;
  1771. __be64 port_vl_xmit_wait_data;
  1772. __be64 port_vl_rcv_bubble;
  1773. __be64 port_vl_mark_fecn;
  1774. __be64 port_vl_xmit_discards;
  1775. } vls[0]; /* real array size defined by # bits set in vl_select_mask */
  1776. };
  1777. enum counter_selects {
  1778. CS_PORT_XMIT_DATA = (1 << 31),
  1779. CS_PORT_RCV_DATA = (1 << 30),
  1780. CS_PORT_XMIT_PKTS = (1 << 29),
  1781. CS_PORT_RCV_PKTS = (1 << 28),
  1782. CS_PORT_MCAST_XMIT_PKTS = (1 << 27),
  1783. CS_PORT_MCAST_RCV_PKTS = (1 << 26),
  1784. CS_PORT_XMIT_WAIT = (1 << 25),
  1785. CS_SW_PORT_CONGESTION = (1 << 24),
  1786. CS_PORT_RCV_FECN = (1 << 23),
  1787. CS_PORT_RCV_BECN = (1 << 22),
  1788. CS_PORT_XMIT_TIME_CONG = (1 << 21),
  1789. CS_PORT_XMIT_WASTED_BW = (1 << 20),
  1790. CS_PORT_XMIT_WAIT_DATA = (1 << 19),
  1791. CS_PORT_RCV_BUBBLE = (1 << 18),
  1792. CS_PORT_MARK_FECN = (1 << 17),
  1793. CS_PORT_RCV_CONSTRAINT_ERRORS = (1 << 16),
  1794. CS_PORT_RCV_SWITCH_RELAY_ERRORS = (1 << 15),
  1795. CS_PORT_XMIT_DISCARDS = (1 << 14),
  1796. CS_PORT_XMIT_CONSTRAINT_ERRORS = (1 << 13),
  1797. CS_PORT_RCV_REMOTE_PHYSICAL_ERRORS = (1 << 12),
  1798. CS_LOCAL_LINK_INTEGRITY_ERRORS = (1 << 11),
  1799. CS_PORT_RCV_ERRORS = (1 << 10),
  1800. CS_EXCESSIVE_BUFFER_OVERRUNS = (1 << 9),
  1801. CS_FM_CONFIG_ERRORS = (1 << 8),
  1802. CS_LINK_ERROR_RECOVERY = (1 << 7),
  1803. CS_LINK_DOWNED = (1 << 6),
  1804. CS_UNCORRECTABLE_ERRORS = (1 << 5),
  1805. };
  1806. struct opa_clear_port_status {
  1807. __be64 port_select_mask[4];
  1808. __be32 counter_select_mask;
  1809. };
  1810. struct opa_aggregate {
  1811. __be16 attr_id;
  1812. __be16 err_reqlength; /* 1 bit, 8 res, 7 bit */
  1813. __be32 attr_mod;
  1814. u8 data[0];
  1815. };
  1816. #define MSK_LLI 0x000000f0
  1817. #define MSK_LLI_SFT 4
  1818. #define MSK_LER 0x0000000f
  1819. #define MSK_LER_SFT 0
  1820. #define ADD_LLI 8
  1821. #define ADD_LER 2
  1822. /* Request contains first three fields, response contains those plus the rest */
  1823. struct opa_port_data_counters_msg {
  1824. __be64 port_select_mask[4];
  1825. __be32 vl_select_mask;
  1826. __be32 resolution;
  1827. /* Response fields follow */
  1828. struct _port_dctrs {
  1829. u8 port_number;
  1830. u8 reserved2[3];
  1831. __be32 link_quality_indicator; /* 29res, 3bit */
  1832. /* Data counters */
  1833. __be64 port_xmit_data;
  1834. __be64 port_rcv_data;
  1835. __be64 port_xmit_pkts;
  1836. __be64 port_rcv_pkts;
  1837. __be64 port_multicast_xmit_pkts;
  1838. __be64 port_multicast_rcv_pkts;
  1839. __be64 port_xmit_wait;
  1840. __be64 sw_port_congestion;
  1841. __be64 port_rcv_fecn;
  1842. __be64 port_rcv_becn;
  1843. __be64 port_xmit_time_cong;
  1844. __be64 port_xmit_wasted_bw;
  1845. __be64 port_xmit_wait_data;
  1846. __be64 port_rcv_bubble;
  1847. __be64 port_mark_fecn;
  1848. __be64 port_error_counter_summary;
  1849. /* Sum of error counts/port */
  1850. struct _vls_dctrs {
  1851. /* per-VL Data counters */
  1852. __be64 port_vl_xmit_data;
  1853. __be64 port_vl_rcv_data;
  1854. __be64 port_vl_xmit_pkts;
  1855. __be64 port_vl_rcv_pkts;
  1856. __be64 port_vl_xmit_wait;
  1857. __be64 sw_port_vl_congestion;
  1858. __be64 port_vl_rcv_fecn;
  1859. __be64 port_vl_rcv_becn;
  1860. __be64 port_xmit_time_cong;
  1861. __be64 port_vl_xmit_wasted_bw;
  1862. __be64 port_vl_xmit_wait_data;
  1863. __be64 port_vl_rcv_bubble;
  1864. __be64 port_vl_mark_fecn;
  1865. } vls[0];
  1866. /* array size defined by #bits set in vl_select_mask*/
  1867. } port[1]; /* array size defined by #ports in attribute modifier */
  1868. };
  1869. struct opa_port_error_counters64_msg {
  1870. /*
  1871. * Request contains first two fields, response contains the
  1872. * whole magilla
  1873. */
  1874. __be64 port_select_mask[4];
  1875. __be32 vl_select_mask;
  1876. /* Response-only fields follow */
  1877. __be32 reserved1;
  1878. struct _port_ectrs {
  1879. u8 port_number;
  1880. u8 reserved2[7];
  1881. __be64 port_rcv_constraint_errors;
  1882. __be64 port_rcv_switch_relay_errors;
  1883. __be64 port_xmit_discards;
  1884. __be64 port_xmit_constraint_errors;
  1885. __be64 port_rcv_remote_physical_errors;
  1886. __be64 local_link_integrity_errors;
  1887. __be64 port_rcv_errors;
  1888. __be64 excessive_buffer_overruns;
  1889. __be64 fm_config_errors;
  1890. __be32 link_error_recovery;
  1891. __be32 link_downed;
  1892. u8 uncorrectable_errors;
  1893. u8 reserved3[7];
  1894. struct _vls_ectrs {
  1895. __be64 port_vl_xmit_discards;
  1896. } vls[0];
  1897. /* array size defined by #bits set in vl_select_mask */
  1898. } port[1]; /* array size defined by #ports in attribute modifier */
  1899. };
  1900. struct opa_port_error_info_msg {
  1901. __be64 port_select_mask[4];
  1902. __be32 error_info_select_mask;
  1903. __be32 reserved1;
  1904. struct _port_ei {
  1905. u8 port_number;
  1906. u8 reserved2[7];
  1907. /* PortRcvErrorInfo */
  1908. struct {
  1909. u8 status_and_code;
  1910. union {
  1911. u8 raw[17];
  1912. struct {
  1913. /* EI1to12 format */
  1914. u8 packet_flit1[8];
  1915. u8 packet_flit2[8];
  1916. u8 remaining_flit_bits12;
  1917. } ei1to12;
  1918. struct {
  1919. u8 packet_bytes[8];
  1920. u8 remaining_flit_bits;
  1921. } ei13;
  1922. } ei;
  1923. u8 reserved3[6];
  1924. } __packed port_rcv_ei;
  1925. /* ExcessiveBufferOverrunInfo */
  1926. struct {
  1927. u8 status_and_sc;
  1928. u8 reserved4[7];
  1929. } __packed excessive_buffer_overrun_ei;
  1930. /* PortXmitConstraintErrorInfo */
  1931. struct {
  1932. u8 status;
  1933. u8 reserved5;
  1934. __be16 pkey;
  1935. __be32 slid;
  1936. } __packed port_xmit_constraint_ei;
  1937. /* PortRcvConstraintErrorInfo */
  1938. struct {
  1939. u8 status;
  1940. u8 reserved6;
  1941. __be16 pkey;
  1942. __be32 slid;
  1943. } __packed port_rcv_constraint_ei;
  1944. /* PortRcvSwitchRelayErrorInfo */
  1945. struct {
  1946. u8 status_and_code;
  1947. u8 reserved7[3];
  1948. __u32 error_info;
  1949. } __packed port_rcv_switch_relay_ei;
  1950. /* UncorrectableErrorInfo */
  1951. struct {
  1952. u8 status_and_code;
  1953. u8 reserved8;
  1954. } __packed uncorrectable_ei;
  1955. /* FMConfigErrorInfo */
  1956. struct {
  1957. u8 status_and_code;
  1958. u8 error_info;
  1959. } __packed fm_config_ei;
  1960. __u32 reserved9;
  1961. } port[1]; /* actual array size defined by #ports in attr modifier */
  1962. };
  1963. /* opa_port_error_info_msg error_info_select_mask bit definitions */
  1964. enum error_info_selects {
  1965. ES_PORT_RCV_ERROR_INFO = (1 << 31),
  1966. ES_EXCESSIVE_BUFFER_OVERRUN_INFO = (1 << 30),
  1967. ES_PORT_XMIT_CONSTRAINT_ERROR_INFO = (1 << 29),
  1968. ES_PORT_RCV_CONSTRAINT_ERROR_INFO = (1 << 28),
  1969. ES_PORT_RCV_SWITCH_RELAY_ERROR_INFO = (1 << 27),
  1970. ES_UNCORRECTABLE_ERROR_INFO = (1 << 26),
  1971. ES_FM_CONFIG_ERROR_INFO = (1 << 25)
  1972. };
  1973. static int pma_get_opa_classportinfo(struct opa_pma_mad *pmp,
  1974. struct ib_device *ibdev, u32 *resp_len)
  1975. {
  1976. struct opa_class_port_info *p =
  1977. (struct opa_class_port_info *)pmp->data;
  1978. memset(pmp->data, 0, sizeof(pmp->data));
  1979. if (pmp->mad_hdr.attr_mod != 0)
  1980. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  1981. p->base_version = OPA_MGMT_BASE_VERSION;
  1982. p->class_version = OPA_SMI_CLASS_VERSION;
  1983. /*
  1984. * Expected response time is 4.096 usec. * 2^18 == 1.073741824 sec.
  1985. */
  1986. p->cap_mask2_resp_time = cpu_to_be32(18);
  1987. if (resp_len)
  1988. *resp_len += sizeof(*p);
  1989. return reply((struct ib_mad_hdr *)pmp);
  1990. }
  1991. static void a0_portstatus(struct hfi1_pportdata *ppd,
  1992. struct opa_port_status_rsp *rsp, u32 vl_select_mask)
  1993. {
  1994. if (!is_bx(ppd->dd)) {
  1995. unsigned long vl;
  1996. u64 sum_vl_xmit_wait = 0;
  1997. u32 vl_all_mask = VL_MASK_ALL;
  1998. for_each_set_bit(vl, (unsigned long *)&(vl_all_mask),
  1999. 8 * sizeof(vl_all_mask)) {
  2000. u64 tmp = sum_vl_xmit_wait +
  2001. read_port_cntr(ppd, C_TX_WAIT_VL,
  2002. idx_from_vl(vl));
  2003. if (tmp < sum_vl_xmit_wait) {
  2004. /* we wrapped */
  2005. sum_vl_xmit_wait = (u64)~0;
  2006. break;
  2007. }
  2008. sum_vl_xmit_wait = tmp;
  2009. }
  2010. if (be64_to_cpu(rsp->port_xmit_wait) > sum_vl_xmit_wait)
  2011. rsp->port_xmit_wait = cpu_to_be64(sum_vl_xmit_wait);
  2012. }
  2013. }
  2014. static int pma_get_opa_portstatus(struct opa_pma_mad *pmp,
  2015. struct ib_device *ibdev,
  2016. u8 port, u32 *resp_len)
  2017. {
  2018. struct opa_port_status_req *req =
  2019. (struct opa_port_status_req *)pmp->data;
  2020. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  2021. struct opa_port_status_rsp *rsp;
  2022. u32 vl_select_mask = be32_to_cpu(req->vl_select_mask);
  2023. unsigned long vl;
  2024. size_t response_data_size;
  2025. u32 nports = be32_to_cpu(pmp->mad_hdr.attr_mod) >> 24;
  2026. u8 port_num = req->port_num;
  2027. u8 num_vls = hweight32(vl_select_mask);
  2028. struct _vls_pctrs *vlinfo;
  2029. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  2030. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  2031. int vfi;
  2032. u64 tmp, tmp2;
  2033. response_data_size = sizeof(struct opa_port_status_rsp) +
  2034. num_vls * sizeof(struct _vls_pctrs);
  2035. if (response_data_size > sizeof(pmp->data)) {
  2036. pmp->mad_hdr.status |= OPA_PM_STATUS_REQUEST_TOO_LARGE;
  2037. return reply((struct ib_mad_hdr *)pmp);
  2038. }
  2039. if (nports != 1 || (port_num && port_num != port) ||
  2040. num_vls > OPA_MAX_VLS || (vl_select_mask & ~VL_MASK_ALL)) {
  2041. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  2042. return reply((struct ib_mad_hdr *)pmp);
  2043. }
  2044. memset(pmp->data, 0, sizeof(pmp->data));
  2045. rsp = (struct opa_port_status_rsp *)pmp->data;
  2046. if (port_num)
  2047. rsp->port_num = port_num;
  2048. else
  2049. rsp->port_num = port;
  2050. rsp->port_rcv_constraint_errors =
  2051. cpu_to_be64(read_port_cntr(ppd, C_SW_RCV_CSTR_ERR,
  2052. CNTR_INVALID_VL));
  2053. hfi1_read_link_quality(dd, &rsp->link_quality_indicator);
  2054. rsp->vl_select_mask = cpu_to_be32(vl_select_mask);
  2055. rsp->port_xmit_data = cpu_to_be64(read_dev_cntr(dd, C_DC_XMIT_FLITS,
  2056. CNTR_INVALID_VL));
  2057. rsp->port_rcv_data = cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FLITS,
  2058. CNTR_INVALID_VL));
  2059. rsp->port_xmit_pkts = cpu_to_be64(read_dev_cntr(dd, C_DC_XMIT_PKTS,
  2060. CNTR_INVALID_VL));
  2061. rsp->port_rcv_pkts = cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_PKTS,
  2062. CNTR_INVALID_VL));
  2063. rsp->port_multicast_xmit_pkts =
  2064. cpu_to_be64(read_dev_cntr(dd, C_DC_MC_XMIT_PKTS,
  2065. CNTR_INVALID_VL));
  2066. rsp->port_multicast_rcv_pkts =
  2067. cpu_to_be64(read_dev_cntr(dd, C_DC_MC_RCV_PKTS,
  2068. CNTR_INVALID_VL));
  2069. rsp->port_xmit_wait =
  2070. cpu_to_be64(read_port_cntr(ppd, C_TX_WAIT, CNTR_INVALID_VL));
  2071. rsp->port_rcv_fecn =
  2072. cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FCN, CNTR_INVALID_VL));
  2073. rsp->port_rcv_becn =
  2074. cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_BCN, CNTR_INVALID_VL));
  2075. rsp->port_xmit_discards =
  2076. cpu_to_be64(read_port_cntr(ppd, C_SW_XMIT_DSCD,
  2077. CNTR_INVALID_VL));
  2078. rsp->port_xmit_constraint_errors =
  2079. cpu_to_be64(read_port_cntr(ppd, C_SW_XMIT_CSTR_ERR,
  2080. CNTR_INVALID_VL));
  2081. rsp->port_rcv_remote_physical_errors =
  2082. cpu_to_be64(read_dev_cntr(dd, C_DC_RMT_PHY_ERR,
  2083. CNTR_INVALID_VL));
  2084. rsp->local_link_integrity_errors =
  2085. cpu_to_be64(read_dev_cntr(dd, C_DC_RX_REPLAY,
  2086. CNTR_INVALID_VL));
  2087. tmp = read_dev_cntr(dd, C_DC_SEQ_CRC_CNT, CNTR_INVALID_VL);
  2088. tmp2 = tmp + read_dev_cntr(dd, C_DC_REINIT_FROM_PEER_CNT,
  2089. CNTR_INVALID_VL);
  2090. if (tmp2 > (u32)UINT_MAX || tmp2 < tmp) {
  2091. /* overflow/wrapped */
  2092. rsp->link_error_recovery = cpu_to_be32(~0);
  2093. } else {
  2094. rsp->link_error_recovery = cpu_to_be32(tmp2);
  2095. }
  2096. rsp->port_rcv_errors =
  2097. cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_ERR, CNTR_INVALID_VL));
  2098. rsp->excessive_buffer_overruns =
  2099. cpu_to_be64(read_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL));
  2100. rsp->fm_config_errors =
  2101. cpu_to_be64(read_dev_cntr(dd, C_DC_FM_CFG_ERR,
  2102. CNTR_INVALID_VL));
  2103. rsp->link_downed = cpu_to_be32(read_port_cntr(ppd, C_SW_LINK_DOWN,
  2104. CNTR_INVALID_VL));
  2105. /* rsp->uncorrectable_errors is 8 bits wide, and it pegs at 0xff */
  2106. tmp = read_dev_cntr(dd, C_DC_UNC_ERR, CNTR_INVALID_VL);
  2107. rsp->uncorrectable_errors = tmp < 0x100 ? (tmp & 0xff) : 0xff;
  2108. vlinfo = &rsp->vls[0];
  2109. vfi = 0;
  2110. /* The vl_select_mask has been checked above, and we know
  2111. * that it contains only entries which represent valid VLs.
  2112. * So in the for_each_set_bit() loop below, we don't need
  2113. * any additional checks for vl.
  2114. */
  2115. for_each_set_bit(vl, (unsigned long *)&(vl_select_mask),
  2116. 8 * sizeof(vl_select_mask)) {
  2117. memset(vlinfo, 0, sizeof(*vlinfo));
  2118. tmp = read_dev_cntr(dd, C_DC_RX_FLIT_VL, idx_from_vl(vl));
  2119. rsp->vls[vfi].port_vl_rcv_data = cpu_to_be64(tmp);
  2120. rsp->vls[vfi].port_vl_rcv_pkts =
  2121. cpu_to_be64(read_dev_cntr(dd, C_DC_RX_PKT_VL,
  2122. idx_from_vl(vl)));
  2123. rsp->vls[vfi].port_vl_xmit_data =
  2124. cpu_to_be64(read_port_cntr(ppd, C_TX_FLIT_VL,
  2125. idx_from_vl(vl)));
  2126. rsp->vls[vfi].port_vl_xmit_pkts =
  2127. cpu_to_be64(read_port_cntr(ppd, C_TX_PKT_VL,
  2128. idx_from_vl(vl)));
  2129. rsp->vls[vfi].port_vl_xmit_wait =
  2130. cpu_to_be64(read_port_cntr(ppd, C_TX_WAIT_VL,
  2131. idx_from_vl(vl)));
  2132. rsp->vls[vfi].port_vl_rcv_fecn =
  2133. cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FCN_VL,
  2134. idx_from_vl(vl)));
  2135. rsp->vls[vfi].port_vl_rcv_becn =
  2136. cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_BCN_VL,
  2137. idx_from_vl(vl)));
  2138. rsp->vls[vfi].port_vl_xmit_discards =
  2139. cpu_to_be64(read_port_cntr(ppd, C_SW_XMIT_DSCD_VL,
  2140. idx_from_vl(vl)));
  2141. vlinfo++;
  2142. vfi++;
  2143. }
  2144. a0_portstatus(ppd, rsp, vl_select_mask);
  2145. if (resp_len)
  2146. *resp_len += response_data_size;
  2147. return reply((struct ib_mad_hdr *)pmp);
  2148. }
  2149. static u64 get_error_counter_summary(struct ib_device *ibdev, u8 port,
  2150. u8 res_lli, u8 res_ler)
  2151. {
  2152. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  2153. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  2154. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  2155. u64 error_counter_summary = 0, tmp;
  2156. error_counter_summary += read_port_cntr(ppd, C_SW_RCV_CSTR_ERR,
  2157. CNTR_INVALID_VL);
  2158. /* port_rcv_switch_relay_errors is 0 for HFIs */
  2159. error_counter_summary += read_port_cntr(ppd, C_SW_XMIT_DSCD,
  2160. CNTR_INVALID_VL);
  2161. error_counter_summary += read_port_cntr(ppd, C_SW_XMIT_CSTR_ERR,
  2162. CNTR_INVALID_VL);
  2163. error_counter_summary += read_dev_cntr(dd, C_DC_RMT_PHY_ERR,
  2164. CNTR_INVALID_VL);
  2165. /* local link integrity must be right-shifted by the lli resolution */
  2166. error_counter_summary += (read_dev_cntr(dd, C_DC_RX_REPLAY,
  2167. CNTR_INVALID_VL) >> res_lli);
  2168. /* link error recovery must b right-shifted by the ler resolution */
  2169. tmp = read_dev_cntr(dd, C_DC_SEQ_CRC_CNT, CNTR_INVALID_VL);
  2170. tmp += read_dev_cntr(dd, C_DC_REINIT_FROM_PEER_CNT, CNTR_INVALID_VL);
  2171. error_counter_summary += (tmp >> res_ler);
  2172. error_counter_summary += read_dev_cntr(dd, C_DC_RCV_ERR,
  2173. CNTR_INVALID_VL);
  2174. error_counter_summary += read_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL);
  2175. error_counter_summary += read_dev_cntr(dd, C_DC_FM_CFG_ERR,
  2176. CNTR_INVALID_VL);
  2177. /* ppd->link_downed is a 32-bit value */
  2178. error_counter_summary += read_port_cntr(ppd, C_SW_LINK_DOWN,
  2179. CNTR_INVALID_VL);
  2180. tmp = read_dev_cntr(dd, C_DC_UNC_ERR, CNTR_INVALID_VL);
  2181. /* this is an 8-bit quantity */
  2182. error_counter_summary += tmp < 0x100 ? (tmp & 0xff) : 0xff;
  2183. return error_counter_summary;
  2184. }
  2185. static void a0_datacounters(struct hfi1_pportdata *ppd, struct _port_dctrs *rsp,
  2186. u32 vl_select_mask)
  2187. {
  2188. if (!is_bx(ppd->dd)) {
  2189. unsigned long vl;
  2190. u64 sum_vl_xmit_wait = 0;
  2191. u32 vl_all_mask = VL_MASK_ALL;
  2192. for_each_set_bit(vl, (unsigned long *)&(vl_all_mask),
  2193. 8 * sizeof(vl_all_mask)) {
  2194. u64 tmp = sum_vl_xmit_wait +
  2195. read_port_cntr(ppd, C_TX_WAIT_VL,
  2196. idx_from_vl(vl));
  2197. if (tmp < sum_vl_xmit_wait) {
  2198. /* we wrapped */
  2199. sum_vl_xmit_wait = (u64)~0;
  2200. break;
  2201. }
  2202. sum_vl_xmit_wait = tmp;
  2203. }
  2204. if (be64_to_cpu(rsp->port_xmit_wait) > sum_vl_xmit_wait)
  2205. rsp->port_xmit_wait = cpu_to_be64(sum_vl_xmit_wait);
  2206. }
  2207. }
  2208. static void pma_get_opa_port_dctrs(struct ib_device *ibdev,
  2209. struct _port_dctrs *rsp)
  2210. {
  2211. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  2212. rsp->port_xmit_data = cpu_to_be64(read_dev_cntr(dd, C_DC_XMIT_FLITS,
  2213. CNTR_INVALID_VL));
  2214. rsp->port_rcv_data = cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FLITS,
  2215. CNTR_INVALID_VL));
  2216. rsp->port_xmit_pkts = cpu_to_be64(read_dev_cntr(dd, C_DC_XMIT_PKTS,
  2217. CNTR_INVALID_VL));
  2218. rsp->port_rcv_pkts = cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_PKTS,
  2219. CNTR_INVALID_VL));
  2220. rsp->port_multicast_xmit_pkts =
  2221. cpu_to_be64(read_dev_cntr(dd, C_DC_MC_XMIT_PKTS,
  2222. CNTR_INVALID_VL));
  2223. rsp->port_multicast_rcv_pkts =
  2224. cpu_to_be64(read_dev_cntr(dd, C_DC_MC_RCV_PKTS,
  2225. CNTR_INVALID_VL));
  2226. }
  2227. static int pma_get_opa_datacounters(struct opa_pma_mad *pmp,
  2228. struct ib_device *ibdev,
  2229. u8 port, u32 *resp_len)
  2230. {
  2231. struct opa_port_data_counters_msg *req =
  2232. (struct opa_port_data_counters_msg *)pmp->data;
  2233. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  2234. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  2235. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  2236. struct _port_dctrs *rsp;
  2237. struct _vls_dctrs *vlinfo;
  2238. size_t response_data_size;
  2239. u32 num_ports;
  2240. u8 num_pslm;
  2241. u8 lq, num_vls;
  2242. u8 res_lli, res_ler;
  2243. u64 port_mask;
  2244. u8 port_num;
  2245. unsigned long vl;
  2246. u32 vl_select_mask;
  2247. int vfi;
  2248. num_ports = be32_to_cpu(pmp->mad_hdr.attr_mod) >> 24;
  2249. num_pslm = hweight64(be64_to_cpu(req->port_select_mask[3]));
  2250. num_vls = hweight32(be32_to_cpu(req->vl_select_mask));
  2251. vl_select_mask = be32_to_cpu(req->vl_select_mask);
  2252. res_lli = (u8)(be32_to_cpu(req->resolution) & MSK_LLI) >> MSK_LLI_SFT;
  2253. res_lli = res_lli ? res_lli + ADD_LLI : 0;
  2254. res_ler = (u8)(be32_to_cpu(req->resolution) & MSK_LER) >> MSK_LER_SFT;
  2255. res_ler = res_ler ? res_ler + ADD_LER : 0;
  2256. if (num_ports != 1 || (vl_select_mask & ~VL_MASK_ALL)) {
  2257. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  2258. return reply((struct ib_mad_hdr *)pmp);
  2259. }
  2260. /* Sanity check */
  2261. response_data_size = sizeof(struct opa_port_data_counters_msg) +
  2262. num_vls * sizeof(struct _vls_dctrs);
  2263. if (response_data_size > sizeof(pmp->data)) {
  2264. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  2265. return reply((struct ib_mad_hdr *)pmp);
  2266. }
  2267. /*
  2268. * The bit set in the mask needs to be consistent with the
  2269. * port the request came in on.
  2270. */
  2271. port_mask = be64_to_cpu(req->port_select_mask[3]);
  2272. port_num = find_first_bit((unsigned long *)&port_mask,
  2273. sizeof(port_mask) * 8);
  2274. if (port_num != port) {
  2275. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  2276. return reply((struct ib_mad_hdr *)pmp);
  2277. }
  2278. rsp = &req->port[0];
  2279. memset(rsp, 0, sizeof(*rsp));
  2280. rsp->port_number = port;
  2281. /*
  2282. * Note that link_quality_indicator is a 32 bit quantity in
  2283. * 'datacounters' queries (as opposed to 'portinfo' queries,
  2284. * where it's a byte).
  2285. */
  2286. hfi1_read_link_quality(dd, &lq);
  2287. rsp->link_quality_indicator = cpu_to_be32((u32)lq);
  2288. pma_get_opa_port_dctrs(ibdev, rsp);
  2289. rsp->port_xmit_wait =
  2290. cpu_to_be64(read_port_cntr(ppd, C_TX_WAIT, CNTR_INVALID_VL));
  2291. rsp->port_rcv_fecn =
  2292. cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FCN, CNTR_INVALID_VL));
  2293. rsp->port_rcv_becn =
  2294. cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_BCN, CNTR_INVALID_VL));
  2295. rsp->port_error_counter_summary =
  2296. cpu_to_be64(get_error_counter_summary(ibdev, port,
  2297. res_lli, res_ler));
  2298. vlinfo = &rsp->vls[0];
  2299. vfi = 0;
  2300. /* The vl_select_mask has been checked above, and we know
  2301. * that it contains only entries which represent valid VLs.
  2302. * So in the for_each_set_bit() loop below, we don't need
  2303. * any additional checks for vl.
  2304. */
  2305. for_each_set_bit(vl, (unsigned long *)&(vl_select_mask),
  2306. 8 * sizeof(req->vl_select_mask)) {
  2307. memset(vlinfo, 0, sizeof(*vlinfo));
  2308. rsp->vls[vfi].port_vl_xmit_data =
  2309. cpu_to_be64(read_port_cntr(ppd, C_TX_FLIT_VL,
  2310. idx_from_vl(vl)));
  2311. rsp->vls[vfi].port_vl_rcv_data =
  2312. cpu_to_be64(read_dev_cntr(dd, C_DC_RX_FLIT_VL,
  2313. idx_from_vl(vl)));
  2314. rsp->vls[vfi].port_vl_xmit_pkts =
  2315. cpu_to_be64(read_port_cntr(ppd, C_TX_PKT_VL,
  2316. idx_from_vl(vl)));
  2317. rsp->vls[vfi].port_vl_rcv_pkts =
  2318. cpu_to_be64(read_dev_cntr(dd, C_DC_RX_PKT_VL,
  2319. idx_from_vl(vl)));
  2320. rsp->vls[vfi].port_vl_xmit_wait =
  2321. cpu_to_be64(read_port_cntr(ppd, C_TX_WAIT_VL,
  2322. idx_from_vl(vl)));
  2323. rsp->vls[vfi].port_vl_rcv_fecn =
  2324. cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FCN_VL,
  2325. idx_from_vl(vl)));
  2326. rsp->vls[vfi].port_vl_rcv_becn =
  2327. cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_BCN_VL,
  2328. idx_from_vl(vl)));
  2329. /* rsp->port_vl_xmit_time_cong is 0 for HFIs */
  2330. /* rsp->port_vl_xmit_wasted_bw ??? */
  2331. /* port_vl_xmit_wait_data - TXE (table 13-9 HFI spec) ???
  2332. * does this differ from rsp->vls[vfi].port_vl_xmit_wait
  2333. */
  2334. /*rsp->vls[vfi].port_vl_mark_fecn =
  2335. * cpu_to_be64(read_csr(dd, DCC_PRF_PORT_VL_MARK_FECN_CNT
  2336. * + offset));
  2337. */
  2338. vlinfo++;
  2339. vfi++;
  2340. }
  2341. a0_datacounters(ppd, rsp, vl_select_mask);
  2342. if (resp_len)
  2343. *resp_len += response_data_size;
  2344. return reply((struct ib_mad_hdr *)pmp);
  2345. }
  2346. static int pma_get_ib_portcounters_ext(struct ib_pma_mad *pmp,
  2347. struct ib_device *ibdev, u8 port)
  2348. {
  2349. struct ib_pma_portcounters_ext *p = (struct ib_pma_portcounters_ext *)
  2350. pmp->data;
  2351. struct _port_dctrs rsp;
  2352. if (pmp->mad_hdr.attr_mod != 0 || p->port_select != port) {
  2353. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  2354. goto bail;
  2355. }
  2356. memset(&rsp, 0, sizeof(rsp));
  2357. pma_get_opa_port_dctrs(ibdev, &rsp);
  2358. p->port_xmit_data = rsp.port_xmit_data;
  2359. p->port_rcv_data = rsp.port_rcv_data;
  2360. p->port_xmit_packets = rsp.port_xmit_pkts;
  2361. p->port_rcv_packets = rsp.port_rcv_pkts;
  2362. p->port_unicast_xmit_packets = 0;
  2363. p->port_unicast_rcv_packets = 0;
  2364. p->port_multicast_xmit_packets = rsp.port_multicast_xmit_pkts;
  2365. p->port_multicast_rcv_packets = rsp.port_multicast_rcv_pkts;
  2366. bail:
  2367. return reply((struct ib_mad_hdr *)pmp);
  2368. }
  2369. static void pma_get_opa_port_ectrs(struct ib_device *ibdev,
  2370. struct _port_ectrs *rsp, u8 port)
  2371. {
  2372. u64 tmp, tmp2;
  2373. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  2374. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  2375. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  2376. tmp = read_dev_cntr(dd, C_DC_SEQ_CRC_CNT, CNTR_INVALID_VL);
  2377. tmp2 = tmp + read_dev_cntr(dd, C_DC_REINIT_FROM_PEER_CNT,
  2378. CNTR_INVALID_VL);
  2379. if (tmp2 > (u32)UINT_MAX || tmp2 < tmp) {
  2380. /* overflow/wrapped */
  2381. rsp->link_error_recovery = cpu_to_be32(~0);
  2382. } else {
  2383. rsp->link_error_recovery = cpu_to_be32(tmp2);
  2384. }
  2385. rsp->link_downed = cpu_to_be32(read_port_cntr(ppd, C_SW_LINK_DOWN,
  2386. CNTR_INVALID_VL));
  2387. rsp->port_rcv_errors =
  2388. cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_ERR, CNTR_INVALID_VL));
  2389. rsp->port_rcv_remote_physical_errors =
  2390. cpu_to_be64(read_dev_cntr(dd, C_DC_RMT_PHY_ERR,
  2391. CNTR_INVALID_VL));
  2392. rsp->port_rcv_switch_relay_errors = 0;
  2393. rsp->port_xmit_discards =
  2394. cpu_to_be64(read_port_cntr(ppd, C_SW_XMIT_DSCD,
  2395. CNTR_INVALID_VL));
  2396. rsp->port_xmit_constraint_errors =
  2397. cpu_to_be64(read_port_cntr(ppd, C_SW_XMIT_CSTR_ERR,
  2398. CNTR_INVALID_VL));
  2399. rsp->port_rcv_constraint_errors =
  2400. cpu_to_be64(read_port_cntr(ppd, C_SW_RCV_CSTR_ERR,
  2401. CNTR_INVALID_VL));
  2402. rsp->local_link_integrity_errors =
  2403. cpu_to_be64(read_dev_cntr(dd, C_DC_RX_REPLAY,
  2404. CNTR_INVALID_VL));
  2405. rsp->excessive_buffer_overruns =
  2406. cpu_to_be64(read_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL));
  2407. }
  2408. static int pma_get_opa_porterrors(struct opa_pma_mad *pmp,
  2409. struct ib_device *ibdev,
  2410. u8 port, u32 *resp_len)
  2411. {
  2412. size_t response_data_size;
  2413. struct _port_ectrs *rsp;
  2414. u8 port_num;
  2415. struct opa_port_error_counters64_msg *req;
  2416. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  2417. u32 num_ports;
  2418. u8 num_pslm;
  2419. u8 num_vls;
  2420. struct hfi1_ibport *ibp;
  2421. struct hfi1_pportdata *ppd;
  2422. struct _vls_ectrs *vlinfo;
  2423. unsigned long vl;
  2424. u64 port_mask, tmp;
  2425. u32 vl_select_mask;
  2426. int vfi;
  2427. req = (struct opa_port_error_counters64_msg *)pmp->data;
  2428. num_ports = be32_to_cpu(pmp->mad_hdr.attr_mod) >> 24;
  2429. num_pslm = hweight64(be64_to_cpu(req->port_select_mask[3]));
  2430. num_vls = hweight32(be32_to_cpu(req->vl_select_mask));
  2431. if (num_ports != 1 || num_ports != num_pslm) {
  2432. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  2433. return reply((struct ib_mad_hdr *)pmp);
  2434. }
  2435. response_data_size = sizeof(struct opa_port_error_counters64_msg) +
  2436. num_vls * sizeof(struct _vls_ectrs);
  2437. if (response_data_size > sizeof(pmp->data)) {
  2438. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  2439. return reply((struct ib_mad_hdr *)pmp);
  2440. }
  2441. /*
  2442. * The bit set in the mask needs to be consistent with the
  2443. * port the request came in on.
  2444. */
  2445. port_mask = be64_to_cpu(req->port_select_mask[3]);
  2446. port_num = find_first_bit((unsigned long *)&port_mask,
  2447. sizeof(port_mask) * 8);
  2448. if (port_num != port) {
  2449. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  2450. return reply((struct ib_mad_hdr *)pmp);
  2451. }
  2452. rsp = &req->port[0];
  2453. ibp = to_iport(ibdev, port_num);
  2454. ppd = ppd_from_ibp(ibp);
  2455. memset(rsp, 0, sizeof(*rsp));
  2456. rsp->port_number = port_num;
  2457. pma_get_opa_port_ectrs(ibdev, rsp, port_num);
  2458. rsp->port_rcv_remote_physical_errors =
  2459. cpu_to_be64(read_dev_cntr(dd, C_DC_RMT_PHY_ERR,
  2460. CNTR_INVALID_VL));
  2461. rsp->fm_config_errors =
  2462. cpu_to_be64(read_dev_cntr(dd, C_DC_FM_CFG_ERR,
  2463. CNTR_INVALID_VL));
  2464. tmp = read_dev_cntr(dd, C_DC_UNC_ERR, CNTR_INVALID_VL);
  2465. rsp->uncorrectable_errors = tmp < 0x100 ? (tmp & 0xff) : 0xff;
  2466. rsp->port_rcv_errors =
  2467. cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_ERR, CNTR_INVALID_VL));
  2468. vlinfo = &rsp->vls[0];
  2469. vfi = 0;
  2470. vl_select_mask = be32_to_cpu(req->vl_select_mask);
  2471. for_each_set_bit(vl, (unsigned long *)&(vl_select_mask),
  2472. 8 * sizeof(req->vl_select_mask)) {
  2473. memset(vlinfo, 0, sizeof(*vlinfo));
  2474. rsp->vls[vfi].port_vl_xmit_discards =
  2475. cpu_to_be64(read_port_cntr(ppd, C_SW_XMIT_DSCD_VL,
  2476. idx_from_vl(vl)));
  2477. vlinfo += 1;
  2478. vfi++;
  2479. }
  2480. if (resp_len)
  2481. *resp_len += response_data_size;
  2482. return reply((struct ib_mad_hdr *)pmp);
  2483. }
  2484. static int pma_get_ib_portcounters(struct ib_pma_mad *pmp,
  2485. struct ib_device *ibdev, u8 port)
  2486. {
  2487. struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
  2488. pmp->data;
  2489. struct _port_ectrs rsp;
  2490. u64 temp_link_overrun_errors;
  2491. u64 temp_64;
  2492. u32 temp_32;
  2493. memset(&rsp, 0, sizeof(rsp));
  2494. pma_get_opa_port_ectrs(ibdev, &rsp, port);
  2495. if (pmp->mad_hdr.attr_mod != 0 || p->port_select != port) {
  2496. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  2497. goto bail;
  2498. }
  2499. p->symbol_error_counter = 0; /* N/A for OPA */
  2500. temp_32 = be32_to_cpu(rsp.link_error_recovery);
  2501. if (temp_32 > 0xFFUL)
  2502. p->link_error_recovery_counter = 0xFF;
  2503. else
  2504. p->link_error_recovery_counter = (u8)temp_32;
  2505. temp_32 = be32_to_cpu(rsp.link_downed);
  2506. if (temp_32 > 0xFFUL)
  2507. p->link_downed_counter = 0xFF;
  2508. else
  2509. p->link_downed_counter = (u8)temp_32;
  2510. temp_64 = be64_to_cpu(rsp.port_rcv_errors);
  2511. if (temp_64 > 0xFFFFUL)
  2512. p->port_rcv_errors = cpu_to_be16(0xFFFF);
  2513. else
  2514. p->port_rcv_errors = cpu_to_be16((u16)temp_64);
  2515. temp_64 = be64_to_cpu(rsp.port_rcv_remote_physical_errors);
  2516. if (temp_64 > 0xFFFFUL)
  2517. p->port_rcv_remphys_errors = cpu_to_be16(0xFFFF);
  2518. else
  2519. p->port_rcv_remphys_errors = cpu_to_be16((u16)temp_64);
  2520. temp_64 = be64_to_cpu(rsp.port_rcv_switch_relay_errors);
  2521. p->port_rcv_switch_relay_errors = cpu_to_be16((u16)temp_64);
  2522. temp_64 = be64_to_cpu(rsp.port_xmit_discards);
  2523. if (temp_64 > 0xFFFFUL)
  2524. p->port_xmit_discards = cpu_to_be16(0xFFFF);
  2525. else
  2526. p->port_xmit_discards = cpu_to_be16((u16)temp_64);
  2527. temp_64 = be64_to_cpu(rsp.port_xmit_constraint_errors);
  2528. if (temp_64 > 0xFFUL)
  2529. p->port_xmit_constraint_errors = 0xFF;
  2530. else
  2531. p->port_xmit_constraint_errors = (u8)temp_64;
  2532. temp_64 = be64_to_cpu(rsp.port_rcv_constraint_errors);
  2533. if (temp_64 > 0xFFUL)
  2534. p->port_rcv_constraint_errors = 0xFFUL;
  2535. else
  2536. p->port_rcv_constraint_errors = (u8)temp_64;
  2537. /* LocalLink: 7:4, BufferOverrun: 3:0 */
  2538. temp_64 = be64_to_cpu(rsp.local_link_integrity_errors);
  2539. if (temp_64 > 0xFUL)
  2540. temp_64 = 0xFUL;
  2541. temp_link_overrun_errors = temp_64 << 4;
  2542. temp_64 = be64_to_cpu(rsp.excessive_buffer_overruns);
  2543. if (temp_64 > 0xFUL)
  2544. temp_64 = 0xFUL;
  2545. temp_link_overrun_errors |= temp_64;
  2546. p->link_overrun_errors = (u8)temp_link_overrun_errors;
  2547. p->vl15_dropped = 0; /* N/A for OPA */
  2548. bail:
  2549. return reply((struct ib_mad_hdr *)pmp);
  2550. }
  2551. static int pma_get_opa_errorinfo(struct opa_pma_mad *pmp,
  2552. struct ib_device *ibdev,
  2553. u8 port, u32 *resp_len)
  2554. {
  2555. size_t response_data_size;
  2556. struct _port_ei *rsp;
  2557. struct opa_port_error_info_msg *req;
  2558. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  2559. u64 port_mask;
  2560. u32 num_ports;
  2561. u8 port_num;
  2562. u8 num_pslm;
  2563. u64 reg;
  2564. req = (struct opa_port_error_info_msg *)pmp->data;
  2565. rsp = &req->port[0];
  2566. num_ports = OPA_AM_NPORT(be32_to_cpu(pmp->mad_hdr.attr_mod));
  2567. num_pslm = hweight64(be64_to_cpu(req->port_select_mask[3]));
  2568. memset(rsp, 0, sizeof(*rsp));
  2569. if (num_ports != 1 || num_ports != num_pslm) {
  2570. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  2571. return reply((struct ib_mad_hdr *)pmp);
  2572. }
  2573. /* Sanity check */
  2574. response_data_size = sizeof(struct opa_port_error_info_msg);
  2575. if (response_data_size > sizeof(pmp->data)) {
  2576. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  2577. return reply((struct ib_mad_hdr *)pmp);
  2578. }
  2579. /*
  2580. * The bit set in the mask needs to be consistent with the port
  2581. * the request came in on.
  2582. */
  2583. port_mask = be64_to_cpu(req->port_select_mask[3]);
  2584. port_num = find_first_bit((unsigned long *)&port_mask,
  2585. sizeof(port_mask) * 8);
  2586. if (port_num != port) {
  2587. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  2588. return reply((struct ib_mad_hdr *)pmp);
  2589. }
  2590. /* PortRcvErrorInfo */
  2591. rsp->port_rcv_ei.status_and_code =
  2592. dd->err_info_rcvport.status_and_code;
  2593. memcpy(&rsp->port_rcv_ei.ei.ei1to12.packet_flit1,
  2594. &dd->err_info_rcvport.packet_flit1, sizeof(u64));
  2595. memcpy(&rsp->port_rcv_ei.ei.ei1to12.packet_flit2,
  2596. &dd->err_info_rcvport.packet_flit2, sizeof(u64));
  2597. /* ExcessiverBufferOverrunInfo */
  2598. reg = read_csr(dd, RCV_ERR_INFO);
  2599. if (reg & RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SMASK) {
  2600. /*
  2601. * if the RcvExcessBufferOverrun bit is set, save SC of
  2602. * first pkt that encountered an excess buffer overrun
  2603. */
  2604. u8 tmp = (u8)reg;
  2605. tmp &= RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SC_SMASK;
  2606. tmp <<= 2;
  2607. rsp->excessive_buffer_overrun_ei.status_and_sc = tmp;
  2608. /* set the status bit */
  2609. rsp->excessive_buffer_overrun_ei.status_and_sc |= 0x80;
  2610. }
  2611. rsp->port_xmit_constraint_ei.status =
  2612. dd->err_info_xmit_constraint.status;
  2613. rsp->port_xmit_constraint_ei.pkey =
  2614. cpu_to_be16(dd->err_info_xmit_constraint.pkey);
  2615. rsp->port_xmit_constraint_ei.slid =
  2616. cpu_to_be32(dd->err_info_xmit_constraint.slid);
  2617. rsp->port_rcv_constraint_ei.status =
  2618. dd->err_info_rcv_constraint.status;
  2619. rsp->port_rcv_constraint_ei.pkey =
  2620. cpu_to_be16(dd->err_info_rcv_constraint.pkey);
  2621. rsp->port_rcv_constraint_ei.slid =
  2622. cpu_to_be32(dd->err_info_rcv_constraint.slid);
  2623. /* UncorrectableErrorInfo */
  2624. rsp->uncorrectable_ei.status_and_code = dd->err_info_uncorrectable;
  2625. /* FMConfigErrorInfo */
  2626. rsp->fm_config_ei.status_and_code = dd->err_info_fmconfig;
  2627. if (resp_len)
  2628. *resp_len += response_data_size;
  2629. return reply((struct ib_mad_hdr *)pmp);
  2630. }
  2631. static int pma_set_opa_portstatus(struct opa_pma_mad *pmp,
  2632. struct ib_device *ibdev,
  2633. u8 port, u32 *resp_len)
  2634. {
  2635. struct opa_clear_port_status *req =
  2636. (struct opa_clear_port_status *)pmp->data;
  2637. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  2638. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  2639. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  2640. u32 nports = be32_to_cpu(pmp->mad_hdr.attr_mod) >> 24;
  2641. u64 portn = be64_to_cpu(req->port_select_mask[3]);
  2642. u32 counter_select = be32_to_cpu(req->counter_select_mask);
  2643. u32 vl_select_mask = VL_MASK_ALL; /* clear all per-vl cnts */
  2644. unsigned long vl;
  2645. if ((nports != 1) || (portn != 1 << port)) {
  2646. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  2647. return reply((struct ib_mad_hdr *)pmp);
  2648. }
  2649. /*
  2650. * only counters returned by pma_get_opa_portstatus() are
  2651. * handled, so when pma_get_opa_portstatus() gets a fix,
  2652. * the corresponding change should be made here as well.
  2653. */
  2654. if (counter_select & CS_PORT_XMIT_DATA)
  2655. write_dev_cntr(dd, C_DC_XMIT_FLITS, CNTR_INVALID_VL, 0);
  2656. if (counter_select & CS_PORT_RCV_DATA)
  2657. write_dev_cntr(dd, C_DC_RCV_FLITS, CNTR_INVALID_VL, 0);
  2658. if (counter_select & CS_PORT_XMIT_PKTS)
  2659. write_dev_cntr(dd, C_DC_XMIT_PKTS, CNTR_INVALID_VL, 0);
  2660. if (counter_select & CS_PORT_RCV_PKTS)
  2661. write_dev_cntr(dd, C_DC_RCV_PKTS, CNTR_INVALID_VL, 0);
  2662. if (counter_select & CS_PORT_MCAST_XMIT_PKTS)
  2663. write_dev_cntr(dd, C_DC_MC_XMIT_PKTS, CNTR_INVALID_VL, 0);
  2664. if (counter_select & CS_PORT_MCAST_RCV_PKTS)
  2665. write_dev_cntr(dd, C_DC_MC_RCV_PKTS, CNTR_INVALID_VL, 0);
  2666. if (counter_select & CS_PORT_XMIT_WAIT)
  2667. write_port_cntr(ppd, C_TX_WAIT, CNTR_INVALID_VL, 0);
  2668. /* ignore cs_sw_portCongestion for HFIs */
  2669. if (counter_select & CS_PORT_RCV_FECN)
  2670. write_dev_cntr(dd, C_DC_RCV_FCN, CNTR_INVALID_VL, 0);
  2671. if (counter_select & CS_PORT_RCV_BECN)
  2672. write_dev_cntr(dd, C_DC_RCV_BCN, CNTR_INVALID_VL, 0);
  2673. /* ignore cs_port_xmit_time_cong for HFIs */
  2674. /* ignore cs_port_xmit_wasted_bw for now */
  2675. /* ignore cs_port_xmit_wait_data for now */
  2676. if (counter_select & CS_PORT_RCV_BUBBLE)
  2677. write_dev_cntr(dd, C_DC_RCV_BBL, CNTR_INVALID_VL, 0);
  2678. /* Only applicable for switch */
  2679. /* if (counter_select & CS_PORT_MARK_FECN)
  2680. * write_csr(dd, DCC_PRF_PORT_MARK_FECN_CNT, 0);
  2681. */
  2682. if (counter_select & CS_PORT_RCV_CONSTRAINT_ERRORS)
  2683. write_port_cntr(ppd, C_SW_RCV_CSTR_ERR, CNTR_INVALID_VL, 0);
  2684. /* ignore cs_port_rcv_switch_relay_errors for HFIs */
  2685. if (counter_select & CS_PORT_XMIT_DISCARDS)
  2686. write_port_cntr(ppd, C_SW_XMIT_DSCD, CNTR_INVALID_VL, 0);
  2687. if (counter_select & CS_PORT_XMIT_CONSTRAINT_ERRORS)
  2688. write_port_cntr(ppd, C_SW_XMIT_CSTR_ERR, CNTR_INVALID_VL, 0);
  2689. if (counter_select & CS_PORT_RCV_REMOTE_PHYSICAL_ERRORS)
  2690. write_dev_cntr(dd, C_DC_RMT_PHY_ERR, CNTR_INVALID_VL, 0);
  2691. if (counter_select & CS_LOCAL_LINK_INTEGRITY_ERRORS)
  2692. write_dev_cntr(dd, C_DC_RX_REPLAY, CNTR_INVALID_VL, 0);
  2693. if (counter_select & CS_LINK_ERROR_RECOVERY) {
  2694. write_dev_cntr(dd, C_DC_SEQ_CRC_CNT, CNTR_INVALID_VL, 0);
  2695. write_dev_cntr(dd, C_DC_REINIT_FROM_PEER_CNT,
  2696. CNTR_INVALID_VL, 0);
  2697. }
  2698. if (counter_select & CS_PORT_RCV_ERRORS)
  2699. write_dev_cntr(dd, C_DC_RCV_ERR, CNTR_INVALID_VL, 0);
  2700. if (counter_select & CS_EXCESSIVE_BUFFER_OVERRUNS) {
  2701. write_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL, 0);
  2702. dd->rcv_ovfl_cnt = 0;
  2703. }
  2704. if (counter_select & CS_FM_CONFIG_ERRORS)
  2705. write_dev_cntr(dd, C_DC_FM_CFG_ERR, CNTR_INVALID_VL, 0);
  2706. if (counter_select & CS_LINK_DOWNED)
  2707. write_port_cntr(ppd, C_SW_LINK_DOWN, CNTR_INVALID_VL, 0);
  2708. if (counter_select & CS_UNCORRECTABLE_ERRORS)
  2709. write_dev_cntr(dd, C_DC_UNC_ERR, CNTR_INVALID_VL, 0);
  2710. for_each_set_bit(vl, (unsigned long *)&(vl_select_mask),
  2711. 8 * sizeof(vl_select_mask)) {
  2712. if (counter_select & CS_PORT_XMIT_DATA)
  2713. write_port_cntr(ppd, C_TX_FLIT_VL, idx_from_vl(vl), 0);
  2714. if (counter_select & CS_PORT_RCV_DATA)
  2715. write_dev_cntr(dd, C_DC_RX_FLIT_VL, idx_from_vl(vl), 0);
  2716. if (counter_select & CS_PORT_XMIT_PKTS)
  2717. write_port_cntr(ppd, C_TX_PKT_VL, idx_from_vl(vl), 0);
  2718. if (counter_select & CS_PORT_RCV_PKTS)
  2719. write_dev_cntr(dd, C_DC_RX_PKT_VL, idx_from_vl(vl), 0);
  2720. if (counter_select & CS_PORT_XMIT_WAIT)
  2721. write_port_cntr(ppd, C_TX_WAIT_VL, idx_from_vl(vl), 0);
  2722. /* sw_port_vl_congestion is 0 for HFIs */
  2723. if (counter_select & CS_PORT_RCV_FECN)
  2724. write_dev_cntr(dd, C_DC_RCV_FCN_VL, idx_from_vl(vl), 0);
  2725. if (counter_select & CS_PORT_RCV_BECN)
  2726. write_dev_cntr(dd, C_DC_RCV_BCN_VL, idx_from_vl(vl), 0);
  2727. /* port_vl_xmit_time_cong is 0 for HFIs */
  2728. /* port_vl_xmit_wasted_bw ??? */
  2729. /* port_vl_xmit_wait_data - TXE (table 13-9 HFI spec) ??? */
  2730. if (counter_select & CS_PORT_RCV_BUBBLE)
  2731. write_dev_cntr(dd, C_DC_RCV_BBL_VL, idx_from_vl(vl), 0);
  2732. /* if (counter_select & CS_PORT_MARK_FECN)
  2733. * write_csr(dd, DCC_PRF_PORT_VL_MARK_FECN_CNT + offset, 0);
  2734. */
  2735. if (counter_select & C_SW_XMIT_DSCD_VL)
  2736. write_port_cntr(ppd, C_SW_XMIT_DSCD_VL,
  2737. idx_from_vl(vl), 0);
  2738. }
  2739. if (resp_len)
  2740. *resp_len += sizeof(*req);
  2741. return reply((struct ib_mad_hdr *)pmp);
  2742. }
  2743. static int pma_set_opa_errorinfo(struct opa_pma_mad *pmp,
  2744. struct ib_device *ibdev,
  2745. u8 port, u32 *resp_len)
  2746. {
  2747. struct _port_ei *rsp;
  2748. struct opa_port_error_info_msg *req;
  2749. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  2750. u64 port_mask;
  2751. u32 num_ports;
  2752. u8 port_num;
  2753. u8 num_pslm;
  2754. u32 error_info_select;
  2755. req = (struct opa_port_error_info_msg *)pmp->data;
  2756. rsp = &req->port[0];
  2757. num_ports = OPA_AM_NPORT(be32_to_cpu(pmp->mad_hdr.attr_mod));
  2758. num_pslm = hweight64(be64_to_cpu(req->port_select_mask[3]));
  2759. memset(rsp, 0, sizeof(*rsp));
  2760. if (num_ports != 1 || num_ports != num_pslm) {
  2761. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  2762. return reply((struct ib_mad_hdr *)pmp);
  2763. }
  2764. /*
  2765. * The bit set in the mask needs to be consistent with the port
  2766. * the request came in on.
  2767. */
  2768. port_mask = be64_to_cpu(req->port_select_mask[3]);
  2769. port_num = find_first_bit((unsigned long *)&port_mask,
  2770. sizeof(port_mask) * 8);
  2771. if (port_num != port) {
  2772. pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
  2773. return reply((struct ib_mad_hdr *)pmp);
  2774. }
  2775. error_info_select = be32_to_cpu(req->error_info_select_mask);
  2776. /* PortRcvErrorInfo */
  2777. if (error_info_select & ES_PORT_RCV_ERROR_INFO)
  2778. /* turn off status bit */
  2779. dd->err_info_rcvport.status_and_code &= ~OPA_EI_STATUS_SMASK;
  2780. /* ExcessiverBufferOverrunInfo */
  2781. if (error_info_select & ES_EXCESSIVE_BUFFER_OVERRUN_INFO)
  2782. /*
  2783. * status bit is essentially kept in the h/w - bit 5 of
  2784. * RCV_ERR_INFO
  2785. */
  2786. write_csr(dd, RCV_ERR_INFO,
  2787. RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SMASK);
  2788. if (error_info_select & ES_PORT_XMIT_CONSTRAINT_ERROR_INFO)
  2789. dd->err_info_xmit_constraint.status &= ~OPA_EI_STATUS_SMASK;
  2790. if (error_info_select & ES_PORT_RCV_CONSTRAINT_ERROR_INFO)
  2791. dd->err_info_rcv_constraint.status &= ~OPA_EI_STATUS_SMASK;
  2792. /* UncorrectableErrorInfo */
  2793. if (error_info_select & ES_UNCORRECTABLE_ERROR_INFO)
  2794. /* turn off status bit */
  2795. dd->err_info_uncorrectable &= ~OPA_EI_STATUS_SMASK;
  2796. /* FMConfigErrorInfo */
  2797. if (error_info_select & ES_FM_CONFIG_ERROR_INFO)
  2798. /* turn off status bit */
  2799. dd->err_info_fmconfig &= ~OPA_EI_STATUS_SMASK;
  2800. if (resp_len)
  2801. *resp_len += sizeof(*req);
  2802. return reply((struct ib_mad_hdr *)pmp);
  2803. }
  2804. struct opa_congestion_info_attr {
  2805. __be16 congestion_info;
  2806. u8 control_table_cap; /* Multiple of 64 entry unit CCTs */
  2807. u8 congestion_log_length;
  2808. } __packed;
  2809. static int __subn_get_opa_cong_info(struct opa_smp *smp, u32 am, u8 *data,
  2810. struct ib_device *ibdev, u8 port,
  2811. u32 *resp_len)
  2812. {
  2813. struct opa_congestion_info_attr *p =
  2814. (struct opa_congestion_info_attr *)data;
  2815. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  2816. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  2817. p->congestion_info = 0;
  2818. p->control_table_cap = ppd->cc_max_table_entries;
  2819. p->congestion_log_length = OPA_CONG_LOG_ELEMS;
  2820. if (resp_len)
  2821. *resp_len += sizeof(*p);
  2822. return reply((struct ib_mad_hdr *)smp);
  2823. }
  2824. static int __subn_get_opa_cong_setting(struct opa_smp *smp, u32 am,
  2825. u8 *data, struct ib_device *ibdev,
  2826. u8 port, u32 *resp_len)
  2827. {
  2828. int i;
  2829. struct opa_congestion_setting_attr *p =
  2830. (struct opa_congestion_setting_attr *)data;
  2831. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  2832. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  2833. struct opa_congestion_setting_entry_shadow *entries;
  2834. struct cc_state *cc_state;
  2835. rcu_read_lock();
  2836. cc_state = get_cc_state(ppd);
  2837. if (!cc_state) {
  2838. rcu_read_unlock();
  2839. return reply((struct ib_mad_hdr *)smp);
  2840. }
  2841. entries = cc_state->cong_setting.entries;
  2842. p->port_control = cpu_to_be16(cc_state->cong_setting.port_control);
  2843. p->control_map = cpu_to_be32(cc_state->cong_setting.control_map);
  2844. for (i = 0; i < OPA_MAX_SLS; i++) {
  2845. p->entries[i].ccti_increase = entries[i].ccti_increase;
  2846. p->entries[i].ccti_timer = cpu_to_be16(entries[i].ccti_timer);
  2847. p->entries[i].trigger_threshold =
  2848. entries[i].trigger_threshold;
  2849. p->entries[i].ccti_min = entries[i].ccti_min;
  2850. }
  2851. rcu_read_unlock();
  2852. if (resp_len)
  2853. *resp_len += sizeof(*p);
  2854. return reply((struct ib_mad_hdr *)smp);
  2855. }
  2856. /*
  2857. * Apply congestion control information stored in the ppd to the
  2858. * active structure.
  2859. */
  2860. static void apply_cc_state(struct hfi1_pportdata *ppd)
  2861. {
  2862. struct cc_state *old_cc_state, *new_cc_state;
  2863. new_cc_state = kzalloc(sizeof(*new_cc_state), GFP_KERNEL);
  2864. if (!new_cc_state)
  2865. return;
  2866. /*
  2867. * Hold the lock for updating *and* to prevent ppd information
  2868. * from changing during the update.
  2869. */
  2870. spin_lock(&ppd->cc_state_lock);
  2871. old_cc_state = get_cc_state_protected(ppd);
  2872. if (!old_cc_state) {
  2873. /* never active, or shutting down */
  2874. spin_unlock(&ppd->cc_state_lock);
  2875. kfree(new_cc_state);
  2876. return;
  2877. }
  2878. *new_cc_state = *old_cc_state;
  2879. new_cc_state->cct.ccti_limit = ppd->total_cct_entry - 1;
  2880. memcpy(new_cc_state->cct.entries, ppd->ccti_entries,
  2881. ppd->total_cct_entry * sizeof(struct ib_cc_table_entry));
  2882. new_cc_state->cong_setting.port_control = IB_CC_CCS_PC_SL_BASED;
  2883. new_cc_state->cong_setting.control_map = ppd->cc_sl_control_map;
  2884. memcpy(new_cc_state->cong_setting.entries, ppd->congestion_entries,
  2885. OPA_MAX_SLS * sizeof(struct opa_congestion_setting_entry));
  2886. rcu_assign_pointer(ppd->cc_state, new_cc_state);
  2887. spin_unlock(&ppd->cc_state_lock);
  2888. kfree_rcu(old_cc_state, rcu);
  2889. }
  2890. static int __subn_set_opa_cong_setting(struct opa_smp *smp, u32 am, u8 *data,
  2891. struct ib_device *ibdev, u8 port,
  2892. u32 *resp_len)
  2893. {
  2894. struct opa_congestion_setting_attr *p =
  2895. (struct opa_congestion_setting_attr *)data;
  2896. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  2897. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  2898. struct opa_congestion_setting_entry_shadow *entries;
  2899. int i;
  2900. /*
  2901. * Save details from packet into the ppd. Hold the cc_state_lock so
  2902. * our information is consistent with anyone trying to apply the state.
  2903. */
  2904. spin_lock(&ppd->cc_state_lock);
  2905. ppd->cc_sl_control_map = be32_to_cpu(p->control_map);
  2906. entries = ppd->congestion_entries;
  2907. for (i = 0; i < OPA_MAX_SLS; i++) {
  2908. entries[i].ccti_increase = p->entries[i].ccti_increase;
  2909. entries[i].ccti_timer = be16_to_cpu(p->entries[i].ccti_timer);
  2910. entries[i].trigger_threshold =
  2911. p->entries[i].trigger_threshold;
  2912. entries[i].ccti_min = p->entries[i].ccti_min;
  2913. }
  2914. spin_unlock(&ppd->cc_state_lock);
  2915. /* now apply the information */
  2916. apply_cc_state(ppd);
  2917. return __subn_get_opa_cong_setting(smp, am, data, ibdev, port,
  2918. resp_len);
  2919. }
  2920. static int __subn_get_opa_hfi1_cong_log(struct opa_smp *smp, u32 am,
  2921. u8 *data, struct ib_device *ibdev,
  2922. u8 port, u32 *resp_len)
  2923. {
  2924. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  2925. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  2926. struct opa_hfi1_cong_log *cong_log = (struct opa_hfi1_cong_log *)data;
  2927. s64 ts;
  2928. int i;
  2929. if (am != 0) {
  2930. smp->status |= IB_SMP_INVALID_FIELD;
  2931. return reply((struct ib_mad_hdr *)smp);
  2932. }
  2933. spin_lock_irq(&ppd->cc_log_lock);
  2934. cong_log->log_type = OPA_CC_LOG_TYPE_HFI;
  2935. cong_log->congestion_flags = 0;
  2936. cong_log->threshold_event_counter =
  2937. cpu_to_be16(ppd->threshold_event_counter);
  2938. memcpy(cong_log->threshold_cong_event_map,
  2939. ppd->threshold_cong_event_map,
  2940. sizeof(cong_log->threshold_cong_event_map));
  2941. /* keep timestamp in units of 1.024 usec */
  2942. ts = ktime_to_ns(ktime_get()) / 1024;
  2943. cong_log->current_time_stamp = cpu_to_be32(ts);
  2944. for (i = 0; i < OPA_CONG_LOG_ELEMS; i++) {
  2945. struct opa_hfi1_cong_log_event_internal *cce =
  2946. &ppd->cc_events[ppd->cc_mad_idx++];
  2947. if (ppd->cc_mad_idx == OPA_CONG_LOG_ELEMS)
  2948. ppd->cc_mad_idx = 0;
  2949. /*
  2950. * Entries which are older than twice the time
  2951. * required to wrap the counter are supposed to
  2952. * be zeroed (CA10-49 IBTA, release 1.2.1, V1).
  2953. */
  2954. if ((u64)(ts - cce->timestamp) > (2 * UINT_MAX))
  2955. continue;
  2956. memcpy(cong_log->events[i].local_qp_cn_entry, &cce->lqpn, 3);
  2957. memcpy(cong_log->events[i].remote_qp_number_cn_entry,
  2958. &cce->rqpn, 3);
  2959. cong_log->events[i].sl_svc_type_cn_entry =
  2960. ((cce->sl & 0x1f) << 3) | (cce->svc_type & 0x7);
  2961. cong_log->events[i].remote_lid_cn_entry =
  2962. cpu_to_be32(cce->rlid);
  2963. cong_log->events[i].timestamp_cn_entry =
  2964. cpu_to_be32(cce->timestamp);
  2965. }
  2966. /*
  2967. * Reset threshold_cong_event_map, and threshold_event_counter
  2968. * to 0 when log is read.
  2969. */
  2970. memset(ppd->threshold_cong_event_map, 0x0,
  2971. sizeof(ppd->threshold_cong_event_map));
  2972. ppd->threshold_event_counter = 0;
  2973. spin_unlock_irq(&ppd->cc_log_lock);
  2974. if (resp_len)
  2975. *resp_len += sizeof(struct opa_hfi1_cong_log);
  2976. return reply((struct ib_mad_hdr *)smp);
  2977. }
  2978. static int __subn_get_opa_cc_table(struct opa_smp *smp, u32 am, u8 *data,
  2979. struct ib_device *ibdev, u8 port,
  2980. u32 *resp_len)
  2981. {
  2982. struct ib_cc_table_attr *cc_table_attr =
  2983. (struct ib_cc_table_attr *)data;
  2984. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  2985. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  2986. u32 start_block = OPA_AM_START_BLK(am);
  2987. u32 n_blocks = OPA_AM_NBLK(am);
  2988. struct ib_cc_table_entry_shadow *entries;
  2989. int i, j;
  2990. u32 sentry, eentry;
  2991. struct cc_state *cc_state;
  2992. /* sanity check n_blocks, start_block */
  2993. if (n_blocks == 0 ||
  2994. start_block + n_blocks > ppd->cc_max_table_entries) {
  2995. smp->status |= IB_SMP_INVALID_FIELD;
  2996. return reply((struct ib_mad_hdr *)smp);
  2997. }
  2998. rcu_read_lock();
  2999. cc_state = get_cc_state(ppd);
  3000. if (!cc_state) {
  3001. rcu_read_unlock();
  3002. return reply((struct ib_mad_hdr *)smp);
  3003. }
  3004. sentry = start_block * IB_CCT_ENTRIES;
  3005. eentry = sentry + (IB_CCT_ENTRIES * n_blocks);
  3006. cc_table_attr->ccti_limit = cpu_to_be16(cc_state->cct.ccti_limit);
  3007. entries = cc_state->cct.entries;
  3008. /* return n_blocks, though the last block may not be full */
  3009. for (j = 0, i = sentry; i < eentry; j++, i++)
  3010. cc_table_attr->ccti_entries[j].entry =
  3011. cpu_to_be16(entries[i].entry);
  3012. rcu_read_unlock();
  3013. if (resp_len)
  3014. *resp_len += sizeof(u16) * (IB_CCT_ENTRIES * n_blocks + 1);
  3015. return reply((struct ib_mad_hdr *)smp);
  3016. }
  3017. static int __subn_set_opa_cc_table(struct opa_smp *smp, u32 am, u8 *data,
  3018. struct ib_device *ibdev, u8 port,
  3019. u32 *resp_len)
  3020. {
  3021. struct ib_cc_table_attr *p = (struct ib_cc_table_attr *)data;
  3022. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  3023. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  3024. u32 start_block = OPA_AM_START_BLK(am);
  3025. u32 n_blocks = OPA_AM_NBLK(am);
  3026. struct ib_cc_table_entry_shadow *entries;
  3027. int i, j;
  3028. u32 sentry, eentry;
  3029. u16 ccti_limit;
  3030. /* sanity check n_blocks, start_block */
  3031. if (n_blocks == 0 ||
  3032. start_block + n_blocks > ppd->cc_max_table_entries) {
  3033. smp->status |= IB_SMP_INVALID_FIELD;
  3034. return reply((struct ib_mad_hdr *)smp);
  3035. }
  3036. sentry = start_block * IB_CCT_ENTRIES;
  3037. eentry = sentry + ((n_blocks - 1) * IB_CCT_ENTRIES) +
  3038. (be16_to_cpu(p->ccti_limit)) % IB_CCT_ENTRIES + 1;
  3039. /* sanity check ccti_limit */
  3040. ccti_limit = be16_to_cpu(p->ccti_limit);
  3041. if (ccti_limit + 1 > eentry) {
  3042. smp->status |= IB_SMP_INVALID_FIELD;
  3043. return reply((struct ib_mad_hdr *)smp);
  3044. }
  3045. /*
  3046. * Save details from packet into the ppd. Hold the cc_state_lock so
  3047. * our information is consistent with anyone trying to apply the state.
  3048. */
  3049. spin_lock(&ppd->cc_state_lock);
  3050. ppd->total_cct_entry = ccti_limit + 1;
  3051. entries = ppd->ccti_entries;
  3052. for (j = 0, i = sentry; i < eentry; j++, i++)
  3053. entries[i].entry = be16_to_cpu(p->ccti_entries[j].entry);
  3054. spin_unlock(&ppd->cc_state_lock);
  3055. /* now apply the information */
  3056. apply_cc_state(ppd);
  3057. return __subn_get_opa_cc_table(smp, am, data, ibdev, port, resp_len);
  3058. }
  3059. struct opa_led_info {
  3060. __be32 rsvd_led_mask;
  3061. __be32 rsvd;
  3062. };
  3063. #define OPA_LED_SHIFT 31
  3064. #define OPA_LED_MASK BIT(OPA_LED_SHIFT)
  3065. static int __subn_get_opa_led_info(struct opa_smp *smp, u32 am, u8 *data,
  3066. struct ib_device *ibdev, u8 port,
  3067. u32 *resp_len)
  3068. {
  3069. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  3070. struct hfi1_pportdata *ppd = dd->pport;
  3071. struct opa_led_info *p = (struct opa_led_info *)data;
  3072. u32 nport = OPA_AM_NPORT(am);
  3073. u32 is_beaconing_active;
  3074. if (nport != 1) {
  3075. smp->status |= IB_SMP_INVALID_FIELD;
  3076. return reply((struct ib_mad_hdr *)smp);
  3077. }
  3078. /*
  3079. * This pairs with the memory barrier in hfi1_start_led_override to
  3080. * ensure that we read the correct state of LED beaconing represented
  3081. * by led_override_timer_active
  3082. */
  3083. smp_rmb();
  3084. is_beaconing_active = !!atomic_read(&ppd->led_override_timer_active);
  3085. p->rsvd_led_mask = cpu_to_be32(is_beaconing_active << OPA_LED_SHIFT);
  3086. if (resp_len)
  3087. *resp_len += sizeof(struct opa_led_info);
  3088. return reply((struct ib_mad_hdr *)smp);
  3089. }
  3090. static int __subn_set_opa_led_info(struct opa_smp *smp, u32 am, u8 *data,
  3091. struct ib_device *ibdev, u8 port,
  3092. u32 *resp_len)
  3093. {
  3094. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  3095. struct opa_led_info *p = (struct opa_led_info *)data;
  3096. u32 nport = OPA_AM_NPORT(am);
  3097. int on = !!(be32_to_cpu(p->rsvd_led_mask) & OPA_LED_MASK);
  3098. if (nport != 1) {
  3099. smp->status |= IB_SMP_INVALID_FIELD;
  3100. return reply((struct ib_mad_hdr *)smp);
  3101. }
  3102. if (on)
  3103. hfi1_start_led_override(dd->pport, 2000, 1500);
  3104. else
  3105. shutdown_led_override(dd->pport);
  3106. return __subn_get_opa_led_info(smp, am, data, ibdev, port, resp_len);
  3107. }
  3108. static int subn_get_opa_sma(__be16 attr_id, struct opa_smp *smp, u32 am,
  3109. u8 *data, struct ib_device *ibdev, u8 port,
  3110. u32 *resp_len)
  3111. {
  3112. int ret;
  3113. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  3114. switch (attr_id) {
  3115. case IB_SMP_ATTR_NODE_DESC:
  3116. ret = __subn_get_opa_nodedesc(smp, am, data, ibdev, port,
  3117. resp_len);
  3118. break;
  3119. case IB_SMP_ATTR_NODE_INFO:
  3120. ret = __subn_get_opa_nodeinfo(smp, am, data, ibdev, port,
  3121. resp_len);
  3122. break;
  3123. case IB_SMP_ATTR_PORT_INFO:
  3124. ret = __subn_get_opa_portinfo(smp, am, data, ibdev, port,
  3125. resp_len);
  3126. break;
  3127. case IB_SMP_ATTR_PKEY_TABLE:
  3128. ret = __subn_get_opa_pkeytable(smp, am, data, ibdev, port,
  3129. resp_len);
  3130. break;
  3131. case OPA_ATTRIB_ID_SL_TO_SC_MAP:
  3132. ret = __subn_get_opa_sl_to_sc(smp, am, data, ibdev, port,
  3133. resp_len);
  3134. break;
  3135. case OPA_ATTRIB_ID_SC_TO_SL_MAP:
  3136. ret = __subn_get_opa_sc_to_sl(smp, am, data, ibdev, port,
  3137. resp_len);
  3138. break;
  3139. case OPA_ATTRIB_ID_SC_TO_VLT_MAP:
  3140. ret = __subn_get_opa_sc_to_vlt(smp, am, data, ibdev, port,
  3141. resp_len);
  3142. break;
  3143. case OPA_ATTRIB_ID_SC_TO_VLNT_MAP:
  3144. ret = __subn_get_opa_sc_to_vlnt(smp, am, data, ibdev, port,
  3145. resp_len);
  3146. break;
  3147. case OPA_ATTRIB_ID_PORT_STATE_INFO:
  3148. ret = __subn_get_opa_psi(smp, am, data, ibdev, port,
  3149. resp_len);
  3150. break;
  3151. case OPA_ATTRIB_ID_BUFFER_CONTROL_TABLE:
  3152. ret = __subn_get_opa_bct(smp, am, data, ibdev, port,
  3153. resp_len);
  3154. break;
  3155. case OPA_ATTRIB_ID_CABLE_INFO:
  3156. ret = __subn_get_opa_cable_info(smp, am, data, ibdev, port,
  3157. resp_len);
  3158. break;
  3159. case IB_SMP_ATTR_VL_ARB_TABLE:
  3160. ret = __subn_get_opa_vl_arb(smp, am, data, ibdev, port,
  3161. resp_len);
  3162. break;
  3163. case OPA_ATTRIB_ID_CONGESTION_INFO:
  3164. ret = __subn_get_opa_cong_info(smp, am, data, ibdev, port,
  3165. resp_len);
  3166. break;
  3167. case OPA_ATTRIB_ID_HFI_CONGESTION_SETTING:
  3168. ret = __subn_get_opa_cong_setting(smp, am, data, ibdev,
  3169. port, resp_len);
  3170. break;
  3171. case OPA_ATTRIB_ID_HFI_CONGESTION_LOG:
  3172. ret = __subn_get_opa_hfi1_cong_log(smp, am, data, ibdev,
  3173. port, resp_len);
  3174. break;
  3175. case OPA_ATTRIB_ID_CONGESTION_CONTROL_TABLE:
  3176. ret = __subn_get_opa_cc_table(smp, am, data, ibdev, port,
  3177. resp_len);
  3178. break;
  3179. case IB_SMP_ATTR_LED_INFO:
  3180. ret = __subn_get_opa_led_info(smp, am, data, ibdev, port,
  3181. resp_len);
  3182. break;
  3183. case IB_SMP_ATTR_SM_INFO:
  3184. if (ibp->rvp.port_cap_flags & IB_PORT_SM_DISABLED)
  3185. return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
  3186. if (ibp->rvp.port_cap_flags & IB_PORT_SM)
  3187. return IB_MAD_RESULT_SUCCESS;
  3188. /* FALLTHROUGH */
  3189. default:
  3190. smp->status |= IB_SMP_UNSUP_METH_ATTR;
  3191. ret = reply((struct ib_mad_hdr *)smp);
  3192. break;
  3193. }
  3194. return ret;
  3195. }
  3196. static int subn_set_opa_sma(__be16 attr_id, struct opa_smp *smp, u32 am,
  3197. u8 *data, struct ib_device *ibdev, u8 port,
  3198. u32 *resp_len)
  3199. {
  3200. int ret;
  3201. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  3202. switch (attr_id) {
  3203. case IB_SMP_ATTR_PORT_INFO:
  3204. ret = __subn_set_opa_portinfo(smp, am, data, ibdev, port,
  3205. resp_len);
  3206. break;
  3207. case IB_SMP_ATTR_PKEY_TABLE:
  3208. ret = __subn_set_opa_pkeytable(smp, am, data, ibdev, port,
  3209. resp_len);
  3210. break;
  3211. case OPA_ATTRIB_ID_SL_TO_SC_MAP:
  3212. ret = __subn_set_opa_sl_to_sc(smp, am, data, ibdev, port,
  3213. resp_len);
  3214. break;
  3215. case OPA_ATTRIB_ID_SC_TO_SL_MAP:
  3216. ret = __subn_set_opa_sc_to_sl(smp, am, data, ibdev, port,
  3217. resp_len);
  3218. break;
  3219. case OPA_ATTRIB_ID_SC_TO_VLT_MAP:
  3220. ret = __subn_set_opa_sc_to_vlt(smp, am, data, ibdev, port,
  3221. resp_len);
  3222. break;
  3223. case OPA_ATTRIB_ID_SC_TO_VLNT_MAP:
  3224. ret = __subn_set_opa_sc_to_vlnt(smp, am, data, ibdev, port,
  3225. resp_len);
  3226. break;
  3227. case OPA_ATTRIB_ID_PORT_STATE_INFO:
  3228. ret = __subn_set_opa_psi(smp, am, data, ibdev, port,
  3229. resp_len);
  3230. break;
  3231. case OPA_ATTRIB_ID_BUFFER_CONTROL_TABLE:
  3232. ret = __subn_set_opa_bct(smp, am, data, ibdev, port,
  3233. resp_len);
  3234. break;
  3235. case IB_SMP_ATTR_VL_ARB_TABLE:
  3236. ret = __subn_set_opa_vl_arb(smp, am, data, ibdev, port,
  3237. resp_len);
  3238. break;
  3239. case OPA_ATTRIB_ID_HFI_CONGESTION_SETTING:
  3240. ret = __subn_set_opa_cong_setting(smp, am, data, ibdev,
  3241. port, resp_len);
  3242. break;
  3243. case OPA_ATTRIB_ID_CONGESTION_CONTROL_TABLE:
  3244. ret = __subn_set_opa_cc_table(smp, am, data, ibdev, port,
  3245. resp_len);
  3246. break;
  3247. case IB_SMP_ATTR_LED_INFO:
  3248. ret = __subn_set_opa_led_info(smp, am, data, ibdev, port,
  3249. resp_len);
  3250. break;
  3251. case IB_SMP_ATTR_SM_INFO:
  3252. if (ibp->rvp.port_cap_flags & IB_PORT_SM_DISABLED)
  3253. return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
  3254. if (ibp->rvp.port_cap_flags & IB_PORT_SM)
  3255. return IB_MAD_RESULT_SUCCESS;
  3256. /* FALLTHROUGH */
  3257. default:
  3258. smp->status |= IB_SMP_UNSUP_METH_ATTR;
  3259. ret = reply((struct ib_mad_hdr *)smp);
  3260. break;
  3261. }
  3262. return ret;
  3263. }
  3264. static inline void set_aggr_error(struct opa_aggregate *ag)
  3265. {
  3266. ag->err_reqlength |= cpu_to_be16(0x8000);
  3267. }
  3268. static int subn_get_opa_aggregate(struct opa_smp *smp,
  3269. struct ib_device *ibdev, u8 port,
  3270. u32 *resp_len)
  3271. {
  3272. int i;
  3273. u32 num_attr = be32_to_cpu(smp->attr_mod) & 0x000000ff;
  3274. u8 *next_smp = opa_get_smp_data(smp);
  3275. if (num_attr < 1 || num_attr > 117) {
  3276. smp->status |= IB_SMP_INVALID_FIELD;
  3277. return reply((struct ib_mad_hdr *)smp);
  3278. }
  3279. for (i = 0; i < num_attr; i++) {
  3280. struct opa_aggregate *agg;
  3281. size_t agg_data_len;
  3282. size_t agg_size;
  3283. u32 am;
  3284. agg = (struct opa_aggregate *)next_smp;
  3285. agg_data_len = (be16_to_cpu(agg->err_reqlength) & 0x007f) * 8;
  3286. agg_size = sizeof(*agg) + agg_data_len;
  3287. am = be32_to_cpu(agg->attr_mod);
  3288. *resp_len += agg_size;
  3289. if (next_smp + agg_size > ((u8 *)smp) + sizeof(*smp)) {
  3290. smp->status |= IB_SMP_INVALID_FIELD;
  3291. return reply((struct ib_mad_hdr *)smp);
  3292. }
  3293. /* zero the payload for this segment */
  3294. memset(next_smp + sizeof(*agg), 0, agg_data_len);
  3295. (void)subn_get_opa_sma(agg->attr_id, smp, am, agg->data,
  3296. ibdev, port, NULL);
  3297. if (smp->status & ~IB_SMP_DIRECTION) {
  3298. set_aggr_error(agg);
  3299. return reply((struct ib_mad_hdr *)smp);
  3300. }
  3301. next_smp += agg_size;
  3302. }
  3303. return reply((struct ib_mad_hdr *)smp);
  3304. }
  3305. static int subn_set_opa_aggregate(struct opa_smp *smp,
  3306. struct ib_device *ibdev, u8 port,
  3307. u32 *resp_len)
  3308. {
  3309. int i;
  3310. u32 num_attr = be32_to_cpu(smp->attr_mod) & 0x000000ff;
  3311. u8 *next_smp = opa_get_smp_data(smp);
  3312. if (num_attr < 1 || num_attr > 117) {
  3313. smp->status |= IB_SMP_INVALID_FIELD;
  3314. return reply((struct ib_mad_hdr *)smp);
  3315. }
  3316. for (i = 0; i < num_attr; i++) {
  3317. struct opa_aggregate *agg;
  3318. size_t agg_data_len;
  3319. size_t agg_size;
  3320. u32 am;
  3321. agg = (struct opa_aggregate *)next_smp;
  3322. agg_data_len = (be16_to_cpu(agg->err_reqlength) & 0x007f) * 8;
  3323. agg_size = sizeof(*agg) + agg_data_len;
  3324. am = be32_to_cpu(agg->attr_mod);
  3325. *resp_len += agg_size;
  3326. if (next_smp + agg_size > ((u8 *)smp) + sizeof(*smp)) {
  3327. smp->status |= IB_SMP_INVALID_FIELD;
  3328. return reply((struct ib_mad_hdr *)smp);
  3329. }
  3330. (void)subn_set_opa_sma(agg->attr_id, smp, am, agg->data,
  3331. ibdev, port, NULL);
  3332. if (smp->status & ~IB_SMP_DIRECTION) {
  3333. set_aggr_error(agg);
  3334. return reply((struct ib_mad_hdr *)smp);
  3335. }
  3336. next_smp += agg_size;
  3337. }
  3338. return reply((struct ib_mad_hdr *)smp);
  3339. }
  3340. /*
  3341. * OPAv1 specifies that, on the transition to link up, these counters
  3342. * are cleared:
  3343. * PortRcvErrors [*]
  3344. * LinkErrorRecovery
  3345. * LocalLinkIntegrityErrors
  3346. * ExcessiveBufferOverruns [*]
  3347. *
  3348. * [*] Error info associated with these counters is retained, but the
  3349. * error info status is reset to 0.
  3350. */
  3351. void clear_linkup_counters(struct hfi1_devdata *dd)
  3352. {
  3353. /* PortRcvErrors */
  3354. write_dev_cntr(dd, C_DC_RCV_ERR, CNTR_INVALID_VL, 0);
  3355. dd->err_info_rcvport.status_and_code &= ~OPA_EI_STATUS_SMASK;
  3356. /* LinkErrorRecovery */
  3357. write_dev_cntr(dd, C_DC_SEQ_CRC_CNT, CNTR_INVALID_VL, 0);
  3358. write_dev_cntr(dd, C_DC_REINIT_FROM_PEER_CNT, CNTR_INVALID_VL, 0);
  3359. /* LocalLinkIntegrityErrors */
  3360. write_dev_cntr(dd, C_DC_RX_REPLAY, CNTR_INVALID_VL, 0);
  3361. /* ExcessiveBufferOverruns */
  3362. write_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL, 0);
  3363. dd->rcv_ovfl_cnt = 0;
  3364. dd->err_info_xmit_constraint.status &= ~OPA_EI_STATUS_SMASK;
  3365. }
  3366. /*
  3367. * is_local_mad() returns 1 if 'mad' is sent from, and destined to the
  3368. * local node, 0 otherwise.
  3369. */
  3370. static int is_local_mad(struct hfi1_ibport *ibp, const struct opa_mad *mad,
  3371. const struct ib_wc *in_wc)
  3372. {
  3373. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  3374. const struct opa_smp *smp = (const struct opa_smp *)mad;
  3375. if (smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) {
  3376. return (smp->hop_cnt == 0 &&
  3377. smp->route.dr.dr_slid == OPA_LID_PERMISSIVE &&
  3378. smp->route.dr.dr_dlid == OPA_LID_PERMISSIVE);
  3379. }
  3380. return (in_wc->slid == ppd->lid);
  3381. }
  3382. /*
  3383. * opa_local_smp_check() should only be called on MADs for which
  3384. * is_local_mad() returns true. It applies the SMP checks that are
  3385. * specific to SMPs which are sent from, and destined to this node.
  3386. * opa_local_smp_check() returns 0 if the SMP passes its checks, 1
  3387. * otherwise.
  3388. *
  3389. * SMPs which arrive from other nodes are instead checked by
  3390. * opa_smp_check().
  3391. */
  3392. static int opa_local_smp_check(struct hfi1_ibport *ibp,
  3393. const struct ib_wc *in_wc)
  3394. {
  3395. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  3396. u16 slid = in_wc->slid;
  3397. u16 pkey;
  3398. if (in_wc->pkey_index >= ARRAY_SIZE(ppd->pkeys))
  3399. return 1;
  3400. pkey = ppd->pkeys[in_wc->pkey_index];
  3401. /*
  3402. * We need to do the "node-local" checks specified in OPAv1,
  3403. * rev 0.90, section 9.10.26, which are:
  3404. * - pkey is 0x7fff, or 0xffff
  3405. * - Source QPN == 0 || Destination QPN == 0
  3406. * - the MAD header's management class is either
  3407. * IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE or
  3408. * IB_MGMT_CLASS_SUBN_LID_ROUTED
  3409. * - SLID != 0
  3410. *
  3411. * However, we know (and so don't need to check again) that,
  3412. * for local SMPs, the MAD stack passes MADs with:
  3413. * - Source QPN of 0
  3414. * - MAD mgmt_class is IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
  3415. * - SLID is either: OPA_LID_PERMISSIVE (0xFFFFFFFF), or
  3416. * our own port's lid
  3417. *
  3418. */
  3419. if (pkey == LIM_MGMT_P_KEY || pkey == FULL_MGMT_P_KEY)
  3420. return 0;
  3421. ingress_pkey_table_fail(ppd, pkey, slid);
  3422. return 1;
  3423. }
  3424. static int process_subn_opa(struct ib_device *ibdev, int mad_flags,
  3425. u8 port, const struct opa_mad *in_mad,
  3426. struct opa_mad *out_mad,
  3427. u32 *resp_len)
  3428. {
  3429. struct opa_smp *smp = (struct opa_smp *)out_mad;
  3430. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  3431. u8 *data;
  3432. u32 am;
  3433. __be16 attr_id;
  3434. int ret;
  3435. *out_mad = *in_mad;
  3436. data = opa_get_smp_data(smp);
  3437. am = be32_to_cpu(smp->attr_mod);
  3438. attr_id = smp->attr_id;
  3439. if (smp->class_version != OPA_SMI_CLASS_VERSION) {
  3440. smp->status |= IB_SMP_UNSUP_VERSION;
  3441. ret = reply((struct ib_mad_hdr *)smp);
  3442. return ret;
  3443. }
  3444. ret = check_mkey(ibp, (struct ib_mad_hdr *)smp, mad_flags, smp->mkey,
  3445. smp->route.dr.dr_slid, smp->route.dr.return_path,
  3446. smp->hop_cnt);
  3447. if (ret) {
  3448. u32 port_num = be32_to_cpu(smp->attr_mod);
  3449. /*
  3450. * If this is a get/set portinfo, we already check the
  3451. * M_Key if the MAD is for another port and the M_Key
  3452. * is OK on the receiving port. This check is needed
  3453. * to increment the error counters when the M_Key
  3454. * fails to match on *both* ports.
  3455. */
  3456. if (attr_id == IB_SMP_ATTR_PORT_INFO &&
  3457. (smp->method == IB_MGMT_METHOD_GET ||
  3458. smp->method == IB_MGMT_METHOD_SET) &&
  3459. port_num && port_num <= ibdev->phys_port_cnt &&
  3460. port != port_num)
  3461. (void)check_mkey(to_iport(ibdev, port_num),
  3462. (struct ib_mad_hdr *)smp, 0,
  3463. smp->mkey, smp->route.dr.dr_slid,
  3464. smp->route.dr.return_path,
  3465. smp->hop_cnt);
  3466. ret = IB_MAD_RESULT_FAILURE;
  3467. return ret;
  3468. }
  3469. *resp_len = opa_get_smp_header_size(smp);
  3470. switch (smp->method) {
  3471. case IB_MGMT_METHOD_GET:
  3472. switch (attr_id) {
  3473. default:
  3474. clear_opa_smp_data(smp);
  3475. ret = subn_get_opa_sma(attr_id, smp, am, data,
  3476. ibdev, port, resp_len);
  3477. break;
  3478. case OPA_ATTRIB_ID_AGGREGATE:
  3479. ret = subn_get_opa_aggregate(smp, ibdev, port,
  3480. resp_len);
  3481. break;
  3482. }
  3483. break;
  3484. case IB_MGMT_METHOD_SET:
  3485. switch (attr_id) {
  3486. default:
  3487. ret = subn_set_opa_sma(attr_id, smp, am, data,
  3488. ibdev, port, resp_len);
  3489. break;
  3490. case OPA_ATTRIB_ID_AGGREGATE:
  3491. ret = subn_set_opa_aggregate(smp, ibdev, port,
  3492. resp_len);
  3493. break;
  3494. }
  3495. break;
  3496. case IB_MGMT_METHOD_TRAP:
  3497. case IB_MGMT_METHOD_REPORT:
  3498. case IB_MGMT_METHOD_REPORT_RESP:
  3499. case IB_MGMT_METHOD_GET_RESP:
  3500. /*
  3501. * The ib_mad module will call us to process responses
  3502. * before checking for other consumers.
  3503. * Just tell the caller to process it normally.
  3504. */
  3505. ret = IB_MAD_RESULT_SUCCESS;
  3506. break;
  3507. default:
  3508. smp->status |= IB_SMP_UNSUP_METHOD;
  3509. ret = reply((struct ib_mad_hdr *)smp);
  3510. break;
  3511. }
  3512. return ret;
  3513. }
  3514. static int process_subn(struct ib_device *ibdev, int mad_flags,
  3515. u8 port, const struct ib_mad *in_mad,
  3516. struct ib_mad *out_mad)
  3517. {
  3518. struct ib_smp *smp = (struct ib_smp *)out_mad;
  3519. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  3520. int ret;
  3521. *out_mad = *in_mad;
  3522. if (smp->class_version != 1) {
  3523. smp->status |= IB_SMP_UNSUP_VERSION;
  3524. ret = reply((struct ib_mad_hdr *)smp);
  3525. return ret;
  3526. }
  3527. ret = check_mkey(ibp, (struct ib_mad_hdr *)smp, mad_flags,
  3528. smp->mkey, (__force __be32)smp->dr_slid,
  3529. smp->return_path, smp->hop_cnt);
  3530. if (ret) {
  3531. u32 port_num = be32_to_cpu(smp->attr_mod);
  3532. /*
  3533. * If this is a get/set portinfo, we already check the
  3534. * M_Key if the MAD is for another port and the M_Key
  3535. * is OK on the receiving port. This check is needed
  3536. * to increment the error counters when the M_Key
  3537. * fails to match on *both* ports.
  3538. */
  3539. if (in_mad->mad_hdr.attr_id == IB_SMP_ATTR_PORT_INFO &&
  3540. (smp->method == IB_MGMT_METHOD_GET ||
  3541. smp->method == IB_MGMT_METHOD_SET) &&
  3542. port_num && port_num <= ibdev->phys_port_cnt &&
  3543. port != port_num)
  3544. (void)check_mkey(to_iport(ibdev, port_num),
  3545. (struct ib_mad_hdr *)smp, 0,
  3546. smp->mkey,
  3547. (__force __be32)smp->dr_slid,
  3548. smp->return_path, smp->hop_cnt);
  3549. ret = IB_MAD_RESULT_FAILURE;
  3550. return ret;
  3551. }
  3552. switch (smp->method) {
  3553. case IB_MGMT_METHOD_GET:
  3554. switch (smp->attr_id) {
  3555. case IB_SMP_ATTR_NODE_INFO:
  3556. ret = subn_get_nodeinfo(smp, ibdev, port);
  3557. break;
  3558. default:
  3559. smp->status |= IB_SMP_UNSUP_METH_ATTR;
  3560. ret = reply((struct ib_mad_hdr *)smp);
  3561. break;
  3562. }
  3563. break;
  3564. }
  3565. return ret;
  3566. }
  3567. static int process_perf(struct ib_device *ibdev, u8 port,
  3568. const struct ib_mad *in_mad,
  3569. struct ib_mad *out_mad)
  3570. {
  3571. struct ib_pma_mad *pmp = (struct ib_pma_mad *)out_mad;
  3572. struct ib_class_port_info *cpi = (struct ib_class_port_info *)
  3573. &pmp->data;
  3574. int ret = IB_MAD_RESULT_FAILURE;
  3575. *out_mad = *in_mad;
  3576. if (pmp->mad_hdr.class_version != 1) {
  3577. pmp->mad_hdr.status |= IB_SMP_UNSUP_VERSION;
  3578. ret = reply((struct ib_mad_hdr *)pmp);
  3579. return ret;
  3580. }
  3581. switch (pmp->mad_hdr.method) {
  3582. case IB_MGMT_METHOD_GET:
  3583. switch (pmp->mad_hdr.attr_id) {
  3584. case IB_PMA_PORT_COUNTERS:
  3585. ret = pma_get_ib_portcounters(pmp, ibdev, port);
  3586. break;
  3587. case IB_PMA_PORT_COUNTERS_EXT:
  3588. ret = pma_get_ib_portcounters_ext(pmp, ibdev, port);
  3589. break;
  3590. case IB_PMA_CLASS_PORT_INFO:
  3591. cpi->capability_mask = IB_PMA_CLASS_CAP_EXT_WIDTH;
  3592. ret = reply((struct ib_mad_hdr *)pmp);
  3593. break;
  3594. default:
  3595. pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR;
  3596. ret = reply((struct ib_mad_hdr *)pmp);
  3597. break;
  3598. }
  3599. break;
  3600. case IB_MGMT_METHOD_SET:
  3601. if (pmp->mad_hdr.attr_id) {
  3602. pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR;
  3603. ret = reply((struct ib_mad_hdr *)pmp);
  3604. }
  3605. break;
  3606. case IB_MGMT_METHOD_TRAP:
  3607. case IB_MGMT_METHOD_GET_RESP:
  3608. /*
  3609. * The ib_mad module will call us to process responses
  3610. * before checking for other consumers.
  3611. * Just tell the caller to process it normally.
  3612. */
  3613. ret = IB_MAD_RESULT_SUCCESS;
  3614. break;
  3615. default:
  3616. pmp->mad_hdr.status |= IB_SMP_UNSUP_METHOD;
  3617. ret = reply((struct ib_mad_hdr *)pmp);
  3618. break;
  3619. }
  3620. return ret;
  3621. }
  3622. static int process_perf_opa(struct ib_device *ibdev, u8 port,
  3623. const struct opa_mad *in_mad,
  3624. struct opa_mad *out_mad, u32 *resp_len)
  3625. {
  3626. struct opa_pma_mad *pmp = (struct opa_pma_mad *)out_mad;
  3627. int ret;
  3628. *out_mad = *in_mad;
  3629. if (pmp->mad_hdr.class_version != OPA_SMI_CLASS_VERSION) {
  3630. pmp->mad_hdr.status |= IB_SMP_UNSUP_VERSION;
  3631. return reply((struct ib_mad_hdr *)pmp);
  3632. }
  3633. *resp_len = sizeof(pmp->mad_hdr);
  3634. switch (pmp->mad_hdr.method) {
  3635. case IB_MGMT_METHOD_GET:
  3636. switch (pmp->mad_hdr.attr_id) {
  3637. case IB_PMA_CLASS_PORT_INFO:
  3638. ret = pma_get_opa_classportinfo(pmp, ibdev, resp_len);
  3639. break;
  3640. case OPA_PM_ATTRIB_ID_PORT_STATUS:
  3641. ret = pma_get_opa_portstatus(pmp, ibdev, port,
  3642. resp_len);
  3643. break;
  3644. case OPA_PM_ATTRIB_ID_DATA_PORT_COUNTERS:
  3645. ret = pma_get_opa_datacounters(pmp, ibdev, port,
  3646. resp_len);
  3647. break;
  3648. case OPA_PM_ATTRIB_ID_ERROR_PORT_COUNTERS:
  3649. ret = pma_get_opa_porterrors(pmp, ibdev, port,
  3650. resp_len);
  3651. break;
  3652. case OPA_PM_ATTRIB_ID_ERROR_INFO:
  3653. ret = pma_get_opa_errorinfo(pmp, ibdev, port,
  3654. resp_len);
  3655. break;
  3656. default:
  3657. pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR;
  3658. ret = reply((struct ib_mad_hdr *)pmp);
  3659. break;
  3660. }
  3661. break;
  3662. case IB_MGMT_METHOD_SET:
  3663. switch (pmp->mad_hdr.attr_id) {
  3664. case OPA_PM_ATTRIB_ID_CLEAR_PORT_STATUS:
  3665. ret = pma_set_opa_portstatus(pmp, ibdev, port,
  3666. resp_len);
  3667. break;
  3668. case OPA_PM_ATTRIB_ID_ERROR_INFO:
  3669. ret = pma_set_opa_errorinfo(pmp, ibdev, port,
  3670. resp_len);
  3671. break;
  3672. default:
  3673. pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR;
  3674. ret = reply((struct ib_mad_hdr *)pmp);
  3675. break;
  3676. }
  3677. break;
  3678. case IB_MGMT_METHOD_TRAP:
  3679. case IB_MGMT_METHOD_GET_RESP:
  3680. /*
  3681. * The ib_mad module will call us to process responses
  3682. * before checking for other consumers.
  3683. * Just tell the caller to process it normally.
  3684. */
  3685. ret = IB_MAD_RESULT_SUCCESS;
  3686. break;
  3687. default:
  3688. pmp->mad_hdr.status |= IB_SMP_UNSUP_METHOD;
  3689. ret = reply((struct ib_mad_hdr *)pmp);
  3690. break;
  3691. }
  3692. return ret;
  3693. }
  3694. static int hfi1_process_opa_mad(struct ib_device *ibdev, int mad_flags,
  3695. u8 port, const struct ib_wc *in_wc,
  3696. const struct ib_grh *in_grh,
  3697. const struct opa_mad *in_mad,
  3698. struct opa_mad *out_mad, size_t *out_mad_size,
  3699. u16 *out_mad_pkey_index)
  3700. {
  3701. int ret;
  3702. int pkey_idx;
  3703. u32 resp_len = 0;
  3704. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  3705. pkey_idx = hfi1_lookup_pkey_idx(ibp, LIM_MGMT_P_KEY);
  3706. if (pkey_idx < 0) {
  3707. pr_warn("failed to find limited mgmt pkey, defaulting 0x%x\n",
  3708. hfi1_get_pkey(ibp, 1));
  3709. pkey_idx = 1;
  3710. }
  3711. *out_mad_pkey_index = (u16)pkey_idx;
  3712. switch (in_mad->mad_hdr.mgmt_class) {
  3713. case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE:
  3714. case IB_MGMT_CLASS_SUBN_LID_ROUTED:
  3715. if (is_local_mad(ibp, in_mad, in_wc)) {
  3716. ret = opa_local_smp_check(ibp, in_wc);
  3717. if (ret)
  3718. return IB_MAD_RESULT_FAILURE;
  3719. }
  3720. ret = process_subn_opa(ibdev, mad_flags, port, in_mad,
  3721. out_mad, &resp_len);
  3722. goto bail;
  3723. case IB_MGMT_CLASS_PERF_MGMT:
  3724. ret = process_perf_opa(ibdev, port, in_mad, out_mad,
  3725. &resp_len);
  3726. goto bail;
  3727. default:
  3728. ret = IB_MAD_RESULT_SUCCESS;
  3729. }
  3730. bail:
  3731. if (ret & IB_MAD_RESULT_REPLY)
  3732. *out_mad_size = round_up(resp_len, 8);
  3733. else if (ret & IB_MAD_RESULT_SUCCESS)
  3734. *out_mad_size = in_wc->byte_len - sizeof(struct ib_grh);
  3735. return ret;
  3736. }
  3737. static int hfi1_process_ib_mad(struct ib_device *ibdev, int mad_flags, u8 port,
  3738. const struct ib_wc *in_wc,
  3739. const struct ib_grh *in_grh,
  3740. const struct ib_mad *in_mad,
  3741. struct ib_mad *out_mad)
  3742. {
  3743. int ret;
  3744. switch (in_mad->mad_hdr.mgmt_class) {
  3745. case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE:
  3746. case IB_MGMT_CLASS_SUBN_LID_ROUTED:
  3747. ret = process_subn(ibdev, mad_flags, port, in_mad, out_mad);
  3748. break;
  3749. case IB_MGMT_CLASS_PERF_MGMT:
  3750. ret = process_perf(ibdev, port, in_mad, out_mad);
  3751. break;
  3752. default:
  3753. ret = IB_MAD_RESULT_SUCCESS;
  3754. break;
  3755. }
  3756. return ret;
  3757. }
  3758. /**
  3759. * hfi1_process_mad - process an incoming MAD packet
  3760. * @ibdev: the infiniband device this packet came in on
  3761. * @mad_flags: MAD flags
  3762. * @port: the port number this packet came in on
  3763. * @in_wc: the work completion entry for this packet
  3764. * @in_grh: the global route header for this packet
  3765. * @in_mad: the incoming MAD
  3766. * @out_mad: any outgoing MAD reply
  3767. *
  3768. * Returns IB_MAD_RESULT_SUCCESS if this is a MAD that we are not
  3769. * interested in processing.
  3770. *
  3771. * Note that the verbs framework has already done the MAD sanity checks,
  3772. * and hop count/pointer updating for IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
  3773. * MADs.
  3774. *
  3775. * This is called by the ib_mad module.
  3776. */
  3777. int hfi1_process_mad(struct ib_device *ibdev, int mad_flags, u8 port,
  3778. const struct ib_wc *in_wc, const struct ib_grh *in_grh,
  3779. const struct ib_mad_hdr *in_mad, size_t in_mad_size,
  3780. struct ib_mad_hdr *out_mad, size_t *out_mad_size,
  3781. u16 *out_mad_pkey_index)
  3782. {
  3783. switch (in_mad->base_version) {
  3784. case OPA_MGMT_BASE_VERSION:
  3785. if (unlikely(in_mad_size != sizeof(struct opa_mad))) {
  3786. dev_err(ibdev->dma_device, "invalid in_mad_size\n");
  3787. return IB_MAD_RESULT_FAILURE;
  3788. }
  3789. return hfi1_process_opa_mad(ibdev, mad_flags, port,
  3790. in_wc, in_grh,
  3791. (struct opa_mad *)in_mad,
  3792. (struct opa_mad *)out_mad,
  3793. out_mad_size,
  3794. out_mad_pkey_index);
  3795. case IB_MGMT_BASE_VERSION:
  3796. return hfi1_process_ib_mad(ibdev, mad_flags, port,
  3797. in_wc, in_grh,
  3798. (const struct ib_mad *)in_mad,
  3799. (struct ib_mad *)out_mad);
  3800. default:
  3801. break;
  3802. }
  3803. return IB_MAD_RESULT_FAILURE;
  3804. }