mad.c 125 KB

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