mad.c 134 KB

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