qib_iba6120.c 109 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578
  1. /*
  2. * Copyright (c) 2006, 2007, 2008, 2009, 2010 QLogic Corporation.
  3. * All rights reserved.
  4. * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. /*
  35. * This file contains all of the code that is specific to the
  36. * QLogic_IB 6120 PCIe chip.
  37. */
  38. #include <linux/interrupt.h>
  39. #include <linux/pci.h>
  40. #include <linux/delay.h>
  41. #include <rdma/ib_verbs.h>
  42. #include "qib.h"
  43. #include "qib_6120_regs.h"
  44. static void qib_6120_setup_setextled(struct qib_pportdata *, u32);
  45. static void sendctrl_6120_mod(struct qib_pportdata *ppd, u32 op);
  46. static u8 qib_6120_phys_portstate(u64);
  47. static u32 qib_6120_iblink_state(u64);
  48. /*
  49. * This file contains all the chip-specific register information and
  50. * access functions for the QLogic QLogic_IB PCI-Express chip.
  51. *
  52. */
  53. /* KREG_IDX uses machine-generated #defines */
  54. #define KREG_IDX(regname) (QIB_6120_##regname##_OFFS / sizeof(u64))
  55. /* Use defines to tie machine-generated names to lower-case names */
  56. #define kr_extctrl KREG_IDX(EXTCtrl)
  57. #define kr_extstatus KREG_IDX(EXTStatus)
  58. #define kr_gpio_clear KREG_IDX(GPIOClear)
  59. #define kr_gpio_mask KREG_IDX(GPIOMask)
  60. #define kr_gpio_out KREG_IDX(GPIOOut)
  61. #define kr_gpio_status KREG_IDX(GPIOStatus)
  62. #define kr_rcvctrl KREG_IDX(RcvCtrl)
  63. #define kr_sendctrl KREG_IDX(SendCtrl)
  64. #define kr_partitionkey KREG_IDX(RcvPartitionKey)
  65. #define kr_hwdiagctrl KREG_IDX(HwDiagCtrl)
  66. #define kr_ibcstatus KREG_IDX(IBCStatus)
  67. #define kr_ibcctrl KREG_IDX(IBCCtrl)
  68. #define kr_sendbuffererror KREG_IDX(SendBufErr0)
  69. #define kr_rcvbthqp KREG_IDX(RcvBTHQP)
  70. #define kr_counterregbase KREG_IDX(CntrRegBase)
  71. #define kr_palign KREG_IDX(PageAlign)
  72. #define kr_rcvegrbase KREG_IDX(RcvEgrBase)
  73. #define kr_rcvegrcnt KREG_IDX(RcvEgrCnt)
  74. #define kr_rcvhdrcnt KREG_IDX(RcvHdrCnt)
  75. #define kr_rcvhdrentsize KREG_IDX(RcvHdrEntSize)
  76. #define kr_rcvhdrsize KREG_IDX(RcvHdrSize)
  77. #define kr_rcvtidbase KREG_IDX(RcvTIDBase)
  78. #define kr_rcvtidcnt KREG_IDX(RcvTIDCnt)
  79. #define kr_scratch KREG_IDX(Scratch)
  80. #define kr_sendctrl KREG_IDX(SendCtrl)
  81. #define kr_sendpioavailaddr KREG_IDX(SendPIOAvailAddr)
  82. #define kr_sendpiobufbase KREG_IDX(SendPIOBufBase)
  83. #define kr_sendpiobufcnt KREG_IDX(SendPIOBufCnt)
  84. #define kr_sendpiosize KREG_IDX(SendPIOSize)
  85. #define kr_sendregbase KREG_IDX(SendRegBase)
  86. #define kr_userregbase KREG_IDX(UserRegBase)
  87. #define kr_control KREG_IDX(Control)
  88. #define kr_intclear KREG_IDX(IntClear)
  89. #define kr_intmask KREG_IDX(IntMask)
  90. #define kr_intstatus KREG_IDX(IntStatus)
  91. #define kr_errclear KREG_IDX(ErrClear)
  92. #define kr_errmask KREG_IDX(ErrMask)
  93. #define kr_errstatus KREG_IDX(ErrStatus)
  94. #define kr_hwerrclear KREG_IDX(HwErrClear)
  95. #define kr_hwerrmask KREG_IDX(HwErrMask)
  96. #define kr_hwerrstatus KREG_IDX(HwErrStatus)
  97. #define kr_revision KREG_IDX(Revision)
  98. #define kr_portcnt KREG_IDX(PortCnt)
  99. #define kr_serdes_cfg0 KREG_IDX(SerdesCfg0)
  100. #define kr_serdes_cfg1 (kr_serdes_cfg0 + 1)
  101. #define kr_serdes_stat KREG_IDX(SerdesStat)
  102. #define kr_xgxs_cfg KREG_IDX(XGXSCfg)
  103. /* These must only be written via qib_write_kreg_ctxt() */
  104. #define kr_rcvhdraddr KREG_IDX(RcvHdrAddr0)
  105. #define kr_rcvhdrtailaddr KREG_IDX(RcvHdrTailAddr0)
  106. #define CREG_IDX(regname) ((QIB_6120_##regname##_OFFS - \
  107. QIB_6120_LBIntCnt_OFFS) / sizeof(u64))
  108. #define cr_badformat CREG_IDX(RxBadFormatCnt)
  109. #define cr_erricrc CREG_IDX(RxICRCErrCnt)
  110. #define cr_errlink CREG_IDX(RxLinkProblemCnt)
  111. #define cr_errlpcrc CREG_IDX(RxLPCRCErrCnt)
  112. #define cr_errpkey CREG_IDX(RxPKeyMismatchCnt)
  113. #define cr_rcvflowctrl_err CREG_IDX(RxFlowCtrlErrCnt)
  114. #define cr_err_rlen CREG_IDX(RxLenErrCnt)
  115. #define cr_errslen CREG_IDX(TxLenErrCnt)
  116. #define cr_errtidfull CREG_IDX(RxTIDFullErrCnt)
  117. #define cr_errtidvalid CREG_IDX(RxTIDValidErrCnt)
  118. #define cr_errvcrc CREG_IDX(RxVCRCErrCnt)
  119. #define cr_ibstatuschange CREG_IDX(IBStatusChangeCnt)
  120. #define cr_lbint CREG_IDX(LBIntCnt)
  121. #define cr_invalidrlen CREG_IDX(RxMaxMinLenErrCnt)
  122. #define cr_invalidslen CREG_IDX(TxMaxMinLenErrCnt)
  123. #define cr_lbflowstall CREG_IDX(LBFlowStallCnt)
  124. #define cr_pktrcv CREG_IDX(RxDataPktCnt)
  125. #define cr_pktrcvflowctrl CREG_IDX(RxFlowPktCnt)
  126. #define cr_pktsend CREG_IDX(TxDataPktCnt)
  127. #define cr_pktsendflow CREG_IDX(TxFlowPktCnt)
  128. #define cr_portovfl CREG_IDX(RxP0HdrEgrOvflCnt)
  129. #define cr_rcvebp CREG_IDX(RxEBPCnt)
  130. #define cr_rcvovfl CREG_IDX(RxBufOvflCnt)
  131. #define cr_senddropped CREG_IDX(TxDroppedPktCnt)
  132. #define cr_sendstall CREG_IDX(TxFlowStallCnt)
  133. #define cr_sendunderrun CREG_IDX(TxUnderrunCnt)
  134. #define cr_wordrcv CREG_IDX(RxDwordCnt)
  135. #define cr_wordsend CREG_IDX(TxDwordCnt)
  136. #define cr_txunsupvl CREG_IDX(TxUnsupVLErrCnt)
  137. #define cr_rxdroppkt CREG_IDX(RxDroppedPktCnt)
  138. #define cr_iblinkerrrecov CREG_IDX(IBLinkErrRecoveryCnt)
  139. #define cr_iblinkdown CREG_IDX(IBLinkDownedCnt)
  140. #define cr_ibsymbolerr CREG_IDX(IBSymbolErrCnt)
  141. #define SYM_RMASK(regname, fldname) ((u64) \
  142. QIB_6120_##regname##_##fldname##_RMASK)
  143. #define SYM_MASK(regname, fldname) ((u64) \
  144. QIB_6120_##regname##_##fldname##_RMASK << \
  145. QIB_6120_##regname##_##fldname##_LSB)
  146. #define SYM_LSB(regname, fldname) (QIB_6120_##regname##_##fldname##_LSB)
  147. #define SYM_FIELD(value, regname, fldname) ((u64) \
  148. (((value) >> SYM_LSB(regname, fldname)) & \
  149. SYM_RMASK(regname, fldname)))
  150. #define ERR_MASK(fldname) SYM_MASK(ErrMask, fldname##Mask)
  151. #define HWE_MASK(fldname) SYM_MASK(HwErrMask, fldname##Mask)
  152. /* link training states, from IBC */
  153. #define IB_6120_LT_STATE_DISABLED 0x00
  154. #define IB_6120_LT_STATE_LINKUP 0x01
  155. #define IB_6120_LT_STATE_POLLACTIVE 0x02
  156. #define IB_6120_LT_STATE_POLLQUIET 0x03
  157. #define IB_6120_LT_STATE_SLEEPDELAY 0x04
  158. #define IB_6120_LT_STATE_SLEEPQUIET 0x05
  159. #define IB_6120_LT_STATE_CFGDEBOUNCE 0x08
  160. #define IB_6120_LT_STATE_CFGRCVFCFG 0x09
  161. #define IB_6120_LT_STATE_CFGWAITRMT 0x0a
  162. #define IB_6120_LT_STATE_CFGIDLE 0x0b
  163. #define IB_6120_LT_STATE_RECOVERRETRAIN 0x0c
  164. #define IB_6120_LT_STATE_RECOVERWAITRMT 0x0e
  165. #define IB_6120_LT_STATE_RECOVERIDLE 0x0f
  166. /* link state machine states from IBC */
  167. #define IB_6120_L_STATE_DOWN 0x0
  168. #define IB_6120_L_STATE_INIT 0x1
  169. #define IB_6120_L_STATE_ARM 0x2
  170. #define IB_6120_L_STATE_ACTIVE 0x3
  171. #define IB_6120_L_STATE_ACT_DEFER 0x4
  172. static const u8 qib_6120_physportstate[0x20] = {
  173. [IB_6120_LT_STATE_DISABLED] = IB_PHYSPORTSTATE_DISABLED,
  174. [IB_6120_LT_STATE_LINKUP] = IB_PHYSPORTSTATE_LINKUP,
  175. [IB_6120_LT_STATE_POLLACTIVE] = IB_PHYSPORTSTATE_POLL,
  176. [IB_6120_LT_STATE_POLLQUIET] = IB_PHYSPORTSTATE_POLL,
  177. [IB_6120_LT_STATE_SLEEPDELAY] = IB_PHYSPORTSTATE_SLEEP,
  178. [IB_6120_LT_STATE_SLEEPQUIET] = IB_PHYSPORTSTATE_SLEEP,
  179. [IB_6120_LT_STATE_CFGDEBOUNCE] =
  180. IB_PHYSPORTSTATE_CFG_TRAIN,
  181. [IB_6120_LT_STATE_CFGRCVFCFG] =
  182. IB_PHYSPORTSTATE_CFG_TRAIN,
  183. [IB_6120_LT_STATE_CFGWAITRMT] =
  184. IB_PHYSPORTSTATE_CFG_TRAIN,
  185. [IB_6120_LT_STATE_CFGIDLE] = IB_PHYSPORTSTATE_CFG_TRAIN,
  186. [IB_6120_LT_STATE_RECOVERRETRAIN] =
  187. IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
  188. [IB_6120_LT_STATE_RECOVERWAITRMT] =
  189. IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
  190. [IB_6120_LT_STATE_RECOVERIDLE] =
  191. IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
  192. [0x10] = IB_PHYSPORTSTATE_CFG_TRAIN,
  193. [0x11] = IB_PHYSPORTSTATE_CFG_TRAIN,
  194. [0x12] = IB_PHYSPORTSTATE_CFG_TRAIN,
  195. [0x13] = IB_PHYSPORTSTATE_CFG_TRAIN,
  196. [0x14] = IB_PHYSPORTSTATE_CFG_TRAIN,
  197. [0x15] = IB_PHYSPORTSTATE_CFG_TRAIN,
  198. [0x16] = IB_PHYSPORTSTATE_CFG_TRAIN,
  199. [0x17] = IB_PHYSPORTSTATE_CFG_TRAIN
  200. };
  201. struct qib_chip_specific {
  202. u64 __iomem *cregbase;
  203. u64 *cntrs;
  204. u64 *portcntrs;
  205. void *dummy_hdrq; /* used after ctxt close */
  206. dma_addr_t dummy_hdrq_phys;
  207. spinlock_t kernel_tid_lock; /* no back to back kernel TID writes */
  208. spinlock_t user_tid_lock; /* no back to back user TID writes */
  209. spinlock_t rcvmod_lock; /* protect rcvctrl shadow changes */
  210. spinlock_t gpio_lock; /* RMW of shadows/regs for ExtCtrl and GPIO */
  211. u64 hwerrmask;
  212. u64 errormask;
  213. u64 gpio_out; /* shadow of kr_gpio_out, for rmw ops */
  214. u64 gpio_mask; /* shadow the gpio mask register */
  215. u64 extctrl; /* shadow the gpio output enable, etc... */
  216. /*
  217. * these 5 fields are used to establish deltas for IB symbol
  218. * errors and linkrecovery errors. They can be reported on
  219. * some chips during link negotiation prior to INIT, and with
  220. * DDR when faking DDR negotiations with non-IBTA switches.
  221. * The chip counters are adjusted at driver unload if there is
  222. * a non-zero delta.
  223. */
  224. u64 ibdeltainprog;
  225. u64 ibsymdelta;
  226. u64 ibsymsnap;
  227. u64 iblnkerrdelta;
  228. u64 iblnkerrsnap;
  229. u64 ibcctrl; /* shadow for kr_ibcctrl */
  230. u32 lastlinkrecov; /* link recovery issue */
  231. int irq;
  232. u32 cntrnamelen;
  233. u32 portcntrnamelen;
  234. u32 ncntrs;
  235. u32 nportcntrs;
  236. /* used with gpio interrupts to implement IB counters */
  237. u32 rxfc_unsupvl_errs;
  238. u32 overrun_thresh_errs;
  239. /*
  240. * these count only cases where _successive_ LocalLinkIntegrity
  241. * errors were seen in the receive headers of IB standard packets
  242. */
  243. u32 lli_errs;
  244. u32 lli_counter;
  245. u64 lli_thresh;
  246. u64 sword; /* total dwords sent (sample result) */
  247. u64 rword; /* total dwords received (sample result) */
  248. u64 spkts; /* total packets sent (sample result) */
  249. u64 rpkts; /* total packets received (sample result) */
  250. u64 xmit_wait; /* # of ticks no data sent (sample result) */
  251. struct timer_list pma_timer;
  252. char emsgbuf[128];
  253. char bitsmsgbuf[64];
  254. u8 pma_sample_status;
  255. };
  256. /* ibcctrl bits */
  257. #define QLOGIC_IB_IBCC_LINKINITCMD_DISABLE 1
  258. /* cycle through TS1/TS2 till OK */
  259. #define QLOGIC_IB_IBCC_LINKINITCMD_POLL 2
  260. /* wait for TS1, then go on */
  261. #define QLOGIC_IB_IBCC_LINKINITCMD_SLEEP 3
  262. #define QLOGIC_IB_IBCC_LINKINITCMD_SHIFT 16
  263. #define QLOGIC_IB_IBCC_LINKCMD_DOWN 1 /* move to 0x11 */
  264. #define QLOGIC_IB_IBCC_LINKCMD_ARMED 2 /* move to 0x21 */
  265. #define QLOGIC_IB_IBCC_LINKCMD_ACTIVE 3 /* move to 0x31 */
  266. #define QLOGIC_IB_IBCC_LINKCMD_SHIFT 18
  267. /*
  268. * We could have a single register get/put routine, that takes a group type,
  269. * but this is somewhat clearer and cleaner. It also gives us some error
  270. * checking. 64 bit register reads should always work, but are inefficient
  271. * on opteron (the northbridge always generates 2 separate HT 32 bit reads),
  272. * so we use kreg32 wherever possible. User register and counter register
  273. * reads are always 32 bit reads, so only one form of those routines.
  274. */
  275. /**
  276. * qib_read_ureg32 - read 32-bit virtualized per-context register
  277. * @dd: device
  278. * @regno: register number
  279. * @ctxt: context number
  280. *
  281. * Return the contents of a register that is virtualized to be per context.
  282. * Returns -1 on errors (not distinguishable from valid contents at
  283. * runtime; we may add a separate error variable at some point).
  284. */
  285. static inline u32 qib_read_ureg32(const struct qib_devdata *dd,
  286. enum qib_ureg regno, int ctxt)
  287. {
  288. if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
  289. return 0;
  290. if (dd->userbase)
  291. return readl(regno + (u64 __iomem *)
  292. ((char __iomem *)dd->userbase +
  293. dd->ureg_align * ctxt));
  294. else
  295. return readl(regno + (u64 __iomem *)
  296. (dd->uregbase +
  297. (char __iomem *)dd->kregbase +
  298. dd->ureg_align * ctxt));
  299. }
  300. /**
  301. * qib_write_ureg - write 32-bit virtualized per-context register
  302. * @dd: device
  303. * @regno: register number
  304. * @value: value
  305. * @ctxt: context
  306. *
  307. * Write the contents of a register that is virtualized to be per context.
  308. */
  309. static inline void qib_write_ureg(const struct qib_devdata *dd,
  310. enum qib_ureg regno, u64 value, int ctxt)
  311. {
  312. u64 __iomem *ubase;
  313. if (dd->userbase)
  314. ubase = (u64 __iomem *)
  315. ((char __iomem *) dd->userbase +
  316. dd->ureg_align * ctxt);
  317. else
  318. ubase = (u64 __iomem *)
  319. (dd->uregbase +
  320. (char __iomem *) dd->kregbase +
  321. dd->ureg_align * ctxt);
  322. if (dd->kregbase && (dd->flags & QIB_PRESENT))
  323. writeq(value, &ubase[regno]);
  324. }
  325. static inline u32 qib_read_kreg32(const struct qib_devdata *dd,
  326. const u16 regno)
  327. {
  328. if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
  329. return -1;
  330. return readl((u32 __iomem *)&dd->kregbase[regno]);
  331. }
  332. static inline u64 qib_read_kreg64(const struct qib_devdata *dd,
  333. const u16 regno)
  334. {
  335. if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
  336. return -1;
  337. return readq(&dd->kregbase[regno]);
  338. }
  339. static inline void qib_write_kreg(const struct qib_devdata *dd,
  340. const u16 regno, u64 value)
  341. {
  342. if (dd->kregbase && (dd->flags & QIB_PRESENT))
  343. writeq(value, &dd->kregbase[regno]);
  344. }
  345. /**
  346. * qib_write_kreg_ctxt - write a device's per-ctxt 64-bit kernel register
  347. * @dd: the qlogic_ib device
  348. * @regno: the register number to write
  349. * @ctxt: the context containing the register
  350. * @value: the value to write
  351. */
  352. static inline void qib_write_kreg_ctxt(const struct qib_devdata *dd,
  353. const u16 regno, unsigned ctxt,
  354. u64 value)
  355. {
  356. qib_write_kreg(dd, regno + ctxt, value);
  357. }
  358. static inline void write_6120_creg(const struct qib_devdata *dd,
  359. u16 regno, u64 value)
  360. {
  361. if (dd->cspec->cregbase && (dd->flags & QIB_PRESENT))
  362. writeq(value, &dd->cspec->cregbase[regno]);
  363. }
  364. static inline u64 read_6120_creg(const struct qib_devdata *dd, u16 regno)
  365. {
  366. if (!dd->cspec->cregbase || !(dd->flags & QIB_PRESENT))
  367. return 0;
  368. return readq(&dd->cspec->cregbase[regno]);
  369. }
  370. static inline u32 read_6120_creg32(const struct qib_devdata *dd, u16 regno)
  371. {
  372. if (!dd->cspec->cregbase || !(dd->flags & QIB_PRESENT))
  373. return 0;
  374. return readl(&dd->cspec->cregbase[regno]);
  375. }
  376. /* kr_control bits */
  377. #define QLOGIC_IB_C_RESET 1U
  378. /* kr_intstatus, kr_intclear, kr_intmask bits */
  379. #define QLOGIC_IB_I_RCVURG_MASK ((1U << 5) - 1)
  380. #define QLOGIC_IB_I_RCVURG_SHIFT 0
  381. #define QLOGIC_IB_I_RCVAVAIL_MASK ((1U << 5) - 1)
  382. #define QLOGIC_IB_I_RCVAVAIL_SHIFT 12
  383. #define QLOGIC_IB_C_FREEZEMODE 0x00000002
  384. #define QLOGIC_IB_C_LINKENABLE 0x00000004
  385. #define QLOGIC_IB_I_ERROR 0x0000000080000000ULL
  386. #define QLOGIC_IB_I_SPIOSENT 0x0000000040000000ULL
  387. #define QLOGIC_IB_I_SPIOBUFAVAIL 0x0000000020000000ULL
  388. #define QLOGIC_IB_I_GPIO 0x0000000010000000ULL
  389. #define QLOGIC_IB_I_BITSEXTANT \
  390. ((QLOGIC_IB_I_RCVURG_MASK << QLOGIC_IB_I_RCVURG_SHIFT) | \
  391. (QLOGIC_IB_I_RCVAVAIL_MASK << \
  392. QLOGIC_IB_I_RCVAVAIL_SHIFT) | \
  393. QLOGIC_IB_I_ERROR | QLOGIC_IB_I_SPIOSENT | \
  394. QLOGIC_IB_I_SPIOBUFAVAIL | QLOGIC_IB_I_GPIO)
  395. /* kr_hwerrclear, kr_hwerrmask, kr_hwerrstatus, bits */
  396. #define QLOGIC_IB_HWE_PCIEMEMPARITYERR_MASK 0x000000000000003fULL
  397. #define QLOGIC_IB_HWE_PCIEMEMPARITYERR_SHIFT 0
  398. #define QLOGIC_IB_HWE_PCIEPOISONEDTLP 0x0000000010000000ULL
  399. #define QLOGIC_IB_HWE_PCIECPLTIMEOUT 0x0000000020000000ULL
  400. #define QLOGIC_IB_HWE_PCIEBUSPARITYXTLH 0x0000000040000000ULL
  401. #define QLOGIC_IB_HWE_PCIEBUSPARITYXADM 0x0000000080000000ULL
  402. #define QLOGIC_IB_HWE_PCIEBUSPARITYRADM 0x0000000100000000ULL
  403. #define QLOGIC_IB_HWE_COREPLL_FBSLIP 0x0080000000000000ULL
  404. #define QLOGIC_IB_HWE_COREPLL_RFSLIP 0x0100000000000000ULL
  405. #define QLOGIC_IB_HWE_PCIE1PLLFAILED 0x0400000000000000ULL
  406. #define QLOGIC_IB_HWE_PCIE0PLLFAILED 0x0800000000000000ULL
  407. #define QLOGIC_IB_HWE_SERDESPLLFAILED 0x1000000000000000ULL
  408. /* kr_extstatus bits */
  409. #define QLOGIC_IB_EXTS_FREQSEL 0x2
  410. #define QLOGIC_IB_EXTS_SERDESSEL 0x4
  411. #define QLOGIC_IB_EXTS_MEMBIST_ENDTEST 0x0000000000004000
  412. #define QLOGIC_IB_EXTS_MEMBIST_FOUND 0x0000000000008000
  413. /* kr_xgxsconfig bits */
  414. #define QLOGIC_IB_XGXS_RESET 0x5ULL
  415. #define _QIB_GPIO_SDA_NUM 1
  416. #define _QIB_GPIO_SCL_NUM 0
  417. /* Bits in GPIO for the added IB link interrupts */
  418. #define GPIO_RXUVL_BIT 3
  419. #define GPIO_OVRUN_BIT 4
  420. #define GPIO_LLI_BIT 5
  421. #define GPIO_ERRINTR_MASK 0x38
  422. #define QLOGIC_IB_RT_BUFSIZE_MASK 0xe0000000ULL
  423. #define QLOGIC_IB_RT_BUFSIZE_SHIFTVAL(tid) \
  424. ((((tid) & QLOGIC_IB_RT_BUFSIZE_MASK) >> 29) + 11 - 1)
  425. #define QLOGIC_IB_RT_BUFSIZE(tid) (1 << QLOGIC_IB_RT_BUFSIZE_SHIFTVAL(tid))
  426. #define QLOGIC_IB_RT_IS_VALID(tid) \
  427. (((tid) & QLOGIC_IB_RT_BUFSIZE_MASK) && \
  428. ((((tid) & QLOGIC_IB_RT_BUFSIZE_MASK) != QLOGIC_IB_RT_BUFSIZE_MASK)))
  429. #define QLOGIC_IB_RT_ADDR_MASK 0x1FFFFFFFULL /* 29 bits valid */
  430. #define QLOGIC_IB_RT_ADDR_SHIFT 10
  431. #define QLOGIC_IB_R_INTRAVAIL_SHIFT 16
  432. #define QLOGIC_IB_R_TAILUPD_SHIFT 31
  433. #define IBA6120_R_PKEY_DIS_SHIFT 30
  434. #define PBC_6120_VL15_SEND_CTRL (1ULL << 31) /* pbc; VL15; link_buf only */
  435. #define IBCBUSFRSPCPARITYERR HWE_MASK(IBCBusFromSPCParityErr)
  436. #define IBCBUSTOSPCPARITYERR HWE_MASK(IBCBusToSPCParityErr)
  437. #define SYM_MASK_BIT(regname, fldname, bit) ((u64) \
  438. ((1ULL << (SYM_LSB(regname, fldname) + (bit)))))
  439. #define TXEMEMPARITYERR_PIOBUF \
  440. SYM_MASK_BIT(HwErrMask, TXEMemParityErrMask, 0)
  441. #define TXEMEMPARITYERR_PIOPBC \
  442. SYM_MASK_BIT(HwErrMask, TXEMemParityErrMask, 1)
  443. #define TXEMEMPARITYERR_PIOLAUNCHFIFO \
  444. SYM_MASK_BIT(HwErrMask, TXEMemParityErrMask, 2)
  445. #define RXEMEMPARITYERR_RCVBUF \
  446. SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 0)
  447. #define RXEMEMPARITYERR_LOOKUPQ \
  448. SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 1)
  449. #define RXEMEMPARITYERR_EXPTID \
  450. SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 2)
  451. #define RXEMEMPARITYERR_EAGERTID \
  452. SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 3)
  453. #define RXEMEMPARITYERR_FLAGBUF \
  454. SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 4)
  455. #define RXEMEMPARITYERR_DATAINFO \
  456. SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 5)
  457. #define RXEMEMPARITYERR_HDRINFO \
  458. SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 6)
  459. /* 6120 specific hardware errors... */
  460. static const struct qib_hwerror_msgs qib_6120_hwerror_msgs[] = {
  461. /* generic hardware errors */
  462. QLOGIC_IB_HWE_MSG(IBCBUSFRSPCPARITYERR, "QIB2IB Parity"),
  463. QLOGIC_IB_HWE_MSG(IBCBUSTOSPCPARITYERR, "IB2QIB Parity"),
  464. QLOGIC_IB_HWE_MSG(TXEMEMPARITYERR_PIOBUF,
  465. "TXE PIOBUF Memory Parity"),
  466. QLOGIC_IB_HWE_MSG(TXEMEMPARITYERR_PIOPBC,
  467. "TXE PIOPBC Memory Parity"),
  468. QLOGIC_IB_HWE_MSG(TXEMEMPARITYERR_PIOLAUNCHFIFO,
  469. "TXE PIOLAUNCHFIFO Memory Parity"),
  470. QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_RCVBUF,
  471. "RXE RCVBUF Memory Parity"),
  472. QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_LOOKUPQ,
  473. "RXE LOOKUPQ Memory Parity"),
  474. QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_EAGERTID,
  475. "RXE EAGERTID Memory Parity"),
  476. QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_EXPTID,
  477. "RXE EXPTID Memory Parity"),
  478. QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_FLAGBUF,
  479. "RXE FLAGBUF Memory Parity"),
  480. QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_DATAINFO,
  481. "RXE DATAINFO Memory Parity"),
  482. QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_HDRINFO,
  483. "RXE HDRINFO Memory Parity"),
  484. /* chip-specific hardware errors */
  485. QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIEPOISONEDTLP,
  486. "PCIe Poisoned TLP"),
  487. QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIECPLTIMEOUT,
  488. "PCIe completion timeout"),
  489. /*
  490. * In practice, it's unlikely wthat we'll see PCIe PLL, or bus
  491. * parity or memory parity error failures, because most likely we
  492. * won't be able to talk to the core of the chip. Nonetheless, we
  493. * might see them, if they are in parts of the PCIe core that aren't
  494. * essential.
  495. */
  496. QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIE1PLLFAILED,
  497. "PCIePLL1"),
  498. QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIE0PLLFAILED,
  499. "PCIePLL0"),
  500. QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIEBUSPARITYXTLH,
  501. "PCIe XTLH core parity"),
  502. QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIEBUSPARITYXADM,
  503. "PCIe ADM TX core parity"),
  504. QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIEBUSPARITYRADM,
  505. "PCIe ADM RX core parity"),
  506. QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_SERDESPLLFAILED,
  507. "SerDes PLL"),
  508. };
  509. #define TXE_PIO_PARITY (TXEMEMPARITYERR_PIOBUF | TXEMEMPARITYERR_PIOPBC)
  510. #define _QIB_PLL_FAIL (QLOGIC_IB_HWE_COREPLL_FBSLIP | \
  511. QLOGIC_IB_HWE_COREPLL_RFSLIP)
  512. /* variables for sanity checking interrupt and errors */
  513. #define IB_HWE_BITSEXTANT \
  514. (HWE_MASK(RXEMemParityErr) | \
  515. HWE_MASK(TXEMemParityErr) | \
  516. (QLOGIC_IB_HWE_PCIEMEMPARITYERR_MASK << \
  517. QLOGIC_IB_HWE_PCIEMEMPARITYERR_SHIFT) | \
  518. QLOGIC_IB_HWE_PCIE1PLLFAILED | \
  519. QLOGIC_IB_HWE_PCIE0PLLFAILED | \
  520. QLOGIC_IB_HWE_PCIEPOISONEDTLP | \
  521. QLOGIC_IB_HWE_PCIECPLTIMEOUT | \
  522. QLOGIC_IB_HWE_PCIEBUSPARITYXTLH | \
  523. QLOGIC_IB_HWE_PCIEBUSPARITYXADM | \
  524. QLOGIC_IB_HWE_PCIEBUSPARITYRADM | \
  525. HWE_MASK(PowerOnBISTFailed) | \
  526. QLOGIC_IB_HWE_COREPLL_FBSLIP | \
  527. QLOGIC_IB_HWE_COREPLL_RFSLIP | \
  528. QLOGIC_IB_HWE_SERDESPLLFAILED | \
  529. HWE_MASK(IBCBusToSPCParityErr) | \
  530. HWE_MASK(IBCBusFromSPCParityErr))
  531. #define IB_E_BITSEXTANT \
  532. (ERR_MASK(RcvFormatErr) | ERR_MASK(RcvVCRCErr) | \
  533. ERR_MASK(RcvICRCErr) | ERR_MASK(RcvMinPktLenErr) | \
  534. ERR_MASK(RcvMaxPktLenErr) | ERR_MASK(RcvLongPktLenErr) | \
  535. ERR_MASK(RcvShortPktLenErr) | ERR_MASK(RcvUnexpectedCharErr) | \
  536. ERR_MASK(RcvUnsupportedVLErr) | ERR_MASK(RcvEBPErr) | \
  537. ERR_MASK(RcvIBFlowErr) | ERR_MASK(RcvBadVersionErr) | \
  538. ERR_MASK(RcvEgrFullErr) | ERR_MASK(RcvHdrFullErr) | \
  539. ERR_MASK(RcvBadTidErr) | ERR_MASK(RcvHdrLenErr) | \
  540. ERR_MASK(RcvHdrErr) | ERR_MASK(RcvIBLostLinkErr) | \
  541. ERR_MASK(SendMinPktLenErr) | ERR_MASK(SendMaxPktLenErr) | \
  542. ERR_MASK(SendUnderRunErr) | ERR_MASK(SendPktLenErr) | \
  543. ERR_MASK(SendDroppedSmpPktErr) | \
  544. ERR_MASK(SendDroppedDataPktErr) | \
  545. ERR_MASK(SendPioArmLaunchErr) | \
  546. ERR_MASK(SendUnexpectedPktNumErr) | \
  547. ERR_MASK(SendUnsupportedVLErr) | ERR_MASK(IBStatusChanged) | \
  548. ERR_MASK(InvalidAddrErr) | ERR_MASK(ResetNegated) | \
  549. ERR_MASK(HardwareErr))
  550. #define QLOGIC_IB_E_PKTERRS ( \
  551. ERR_MASK(SendPktLenErr) | \
  552. ERR_MASK(SendDroppedDataPktErr) | \
  553. ERR_MASK(RcvVCRCErr) | \
  554. ERR_MASK(RcvICRCErr) | \
  555. ERR_MASK(RcvShortPktLenErr) | \
  556. ERR_MASK(RcvEBPErr))
  557. /* These are all rcv-related errors which we want to count for stats */
  558. #define E_SUM_PKTERRS \
  559. (ERR_MASK(RcvHdrLenErr) | ERR_MASK(RcvBadTidErr) | \
  560. ERR_MASK(RcvBadVersionErr) | ERR_MASK(RcvHdrErr) | \
  561. ERR_MASK(RcvLongPktLenErr) | ERR_MASK(RcvShortPktLenErr) | \
  562. ERR_MASK(RcvMaxPktLenErr) | ERR_MASK(RcvMinPktLenErr) | \
  563. ERR_MASK(RcvFormatErr) | ERR_MASK(RcvUnsupportedVLErr) | \
  564. ERR_MASK(RcvUnexpectedCharErr) | ERR_MASK(RcvEBPErr))
  565. /* These are all send-related errors which we want to count for stats */
  566. #define E_SUM_ERRS \
  567. (ERR_MASK(SendPioArmLaunchErr) | \
  568. ERR_MASK(SendUnexpectedPktNumErr) | \
  569. ERR_MASK(SendDroppedDataPktErr) | \
  570. ERR_MASK(SendDroppedSmpPktErr) | \
  571. ERR_MASK(SendMaxPktLenErr) | ERR_MASK(SendUnsupportedVLErr) | \
  572. ERR_MASK(SendMinPktLenErr) | ERR_MASK(SendPktLenErr) | \
  573. ERR_MASK(InvalidAddrErr))
  574. /*
  575. * this is similar to E_SUM_ERRS, but can't ignore armlaunch, don't ignore
  576. * errors not related to freeze and cancelling buffers. Can't ignore
  577. * armlaunch because could get more while still cleaning up, and need
  578. * to cancel those as they happen.
  579. */
  580. #define E_SPKT_ERRS_IGNORE \
  581. (ERR_MASK(SendDroppedDataPktErr) | \
  582. ERR_MASK(SendDroppedSmpPktErr) | \
  583. ERR_MASK(SendMaxPktLenErr) | ERR_MASK(SendMinPktLenErr) | \
  584. ERR_MASK(SendPktLenErr))
  585. /*
  586. * these are errors that can occur when the link changes state while
  587. * a packet is being sent or received. This doesn't cover things
  588. * like EBP or VCRC that can be the result of a sending having the
  589. * link change state, so we receive a "known bad" packet.
  590. */
  591. #define E_SUM_LINK_PKTERRS \
  592. (ERR_MASK(SendDroppedDataPktErr) | \
  593. ERR_MASK(SendDroppedSmpPktErr) | \
  594. ERR_MASK(SendMinPktLenErr) | ERR_MASK(SendPktLenErr) | \
  595. ERR_MASK(RcvShortPktLenErr) | ERR_MASK(RcvMinPktLenErr) | \
  596. ERR_MASK(RcvUnexpectedCharErr))
  597. static void qib_6120_put_tid_2(struct qib_devdata *, u64 __iomem *,
  598. u32, unsigned long);
  599. /*
  600. * On platforms using this chip, and not having ordered WC stores, we
  601. * can get TXE parity errors due to speculative reads to the PIO buffers,
  602. * and this, due to a chip issue can result in (many) false parity error
  603. * reports. So it's a debug print on those, and an info print on systems
  604. * where the speculative reads don't occur.
  605. */
  606. static void qib_6120_txe_recover(struct qib_devdata *dd)
  607. {
  608. if (!qib_unordered_wc())
  609. qib_devinfo(dd->pcidev,
  610. "Recovering from TXE PIO parity error\n");
  611. }
  612. /* enable/disable chip from delivering interrupts */
  613. static void qib_6120_set_intr_state(struct qib_devdata *dd, u32 enable)
  614. {
  615. if (enable) {
  616. if (dd->flags & QIB_BADINTR)
  617. return;
  618. qib_write_kreg(dd, kr_intmask, ~0ULL);
  619. /* force re-interrupt of any pending interrupts. */
  620. qib_write_kreg(dd, kr_intclear, 0ULL);
  621. } else
  622. qib_write_kreg(dd, kr_intmask, 0ULL);
  623. }
  624. /*
  625. * Try to cleanup as much as possible for anything that might have gone
  626. * wrong while in freeze mode, such as pio buffers being written by user
  627. * processes (causing armlaunch), send errors due to going into freeze mode,
  628. * etc., and try to avoid causing extra interrupts while doing so.
  629. * Forcibly update the in-memory pioavail register copies after cleanup
  630. * because the chip won't do it while in freeze mode (the register values
  631. * themselves are kept correct).
  632. * Make sure that we don't lose any important interrupts by using the chip
  633. * feature that says that writing 0 to a bit in *clear that is set in
  634. * *status will cause an interrupt to be generated again (if allowed by
  635. * the *mask value).
  636. * This is in chip-specific code because of all of the register accesses,
  637. * even though the details are similar on most chips
  638. */
  639. static void qib_6120_clear_freeze(struct qib_devdata *dd)
  640. {
  641. /* disable error interrupts, to avoid confusion */
  642. qib_write_kreg(dd, kr_errmask, 0ULL);
  643. /* also disable interrupts; errormask is sometimes overwriten */
  644. qib_6120_set_intr_state(dd, 0);
  645. qib_cancel_sends(dd->pport);
  646. /* clear the freeze, and be sure chip saw it */
  647. qib_write_kreg(dd, kr_control, dd->control);
  648. qib_read_kreg32(dd, kr_scratch);
  649. /* force in-memory update now we are out of freeze */
  650. qib_force_pio_avail_update(dd);
  651. /*
  652. * force new interrupt if any hwerr, error or interrupt bits are
  653. * still set, and clear "safe" send packet errors related to freeze
  654. * and cancelling sends. Re-enable error interrupts before possible
  655. * force of re-interrupt on pending interrupts.
  656. */
  657. qib_write_kreg(dd, kr_hwerrclear, 0ULL);
  658. qib_write_kreg(dd, kr_errclear, E_SPKT_ERRS_IGNORE);
  659. qib_write_kreg(dd, kr_errmask, dd->cspec->errormask);
  660. qib_6120_set_intr_state(dd, 1);
  661. }
  662. /**
  663. * qib_handle_6120_hwerrors - display hardware errors.
  664. * @dd: the qlogic_ib device
  665. * @msg: the output buffer
  666. * @msgl: the size of the output buffer
  667. *
  668. * Use same msg buffer as regular errors to avoid excessive stack
  669. * use. Most hardware errors are catastrophic, but for right now,
  670. * we'll print them and continue. Reuse the same message buffer as
  671. * handle_6120_errors() to avoid excessive stack usage.
  672. */
  673. static void qib_handle_6120_hwerrors(struct qib_devdata *dd, char *msg,
  674. size_t msgl)
  675. {
  676. u64 hwerrs;
  677. u32 bits, ctrl;
  678. int isfatal = 0;
  679. char *bitsmsg;
  680. int log_idx;
  681. hwerrs = qib_read_kreg64(dd, kr_hwerrstatus);
  682. if (!hwerrs)
  683. return;
  684. if (hwerrs == ~0ULL) {
  685. qib_dev_err(dd, "Read of hardware error status failed "
  686. "(all bits set); ignoring\n");
  687. return;
  688. }
  689. qib_stats.sps_hwerrs++;
  690. /* Always clear the error status register, except MEMBISTFAIL,
  691. * regardless of whether we continue or stop using the chip.
  692. * We want that set so we know it failed, even across driver reload.
  693. * We'll still ignore it in the hwerrmask. We do this partly for
  694. * diagnostics, but also for support */
  695. qib_write_kreg(dd, kr_hwerrclear,
  696. hwerrs & ~HWE_MASK(PowerOnBISTFailed));
  697. hwerrs &= dd->cspec->hwerrmask;
  698. /* We log some errors to EEPROM, check if we have any of those. */
  699. for (log_idx = 0; log_idx < QIB_EEP_LOG_CNT; ++log_idx)
  700. if (hwerrs & dd->eep_st_masks[log_idx].hwerrs_to_log)
  701. qib_inc_eeprom_err(dd, log_idx, 1);
  702. /*
  703. * Make sure we get this much out, unless told to be quiet,
  704. * or it's occurred within the last 5 seconds.
  705. */
  706. if (hwerrs & ~(TXE_PIO_PARITY | RXEMEMPARITYERR_EAGERTID))
  707. qib_devinfo(dd->pcidev, "Hardware error: hwerr=0x%llx "
  708. "(cleared)\n", (unsigned long long) hwerrs);
  709. if (hwerrs & ~IB_HWE_BITSEXTANT)
  710. qib_dev_err(dd, "hwerror interrupt with unknown errors "
  711. "%llx set\n", (unsigned long long)
  712. (hwerrs & ~IB_HWE_BITSEXTANT));
  713. ctrl = qib_read_kreg32(dd, kr_control);
  714. if ((ctrl & QLOGIC_IB_C_FREEZEMODE) && !dd->diag_client) {
  715. /*
  716. * Parity errors in send memory are recoverable,
  717. * just cancel the send (if indicated in * sendbuffererror),
  718. * count the occurrence, unfreeze (if no other handled
  719. * hardware error bits are set), and continue. They can
  720. * occur if a processor speculative read is done to the PIO
  721. * buffer while we are sending a packet, for example.
  722. */
  723. if (hwerrs & TXE_PIO_PARITY) {
  724. qib_6120_txe_recover(dd);
  725. hwerrs &= ~TXE_PIO_PARITY;
  726. }
  727. if (!hwerrs) {
  728. static u32 freeze_cnt;
  729. freeze_cnt++;
  730. qib_6120_clear_freeze(dd);
  731. } else
  732. isfatal = 1;
  733. }
  734. *msg = '\0';
  735. if (hwerrs & HWE_MASK(PowerOnBISTFailed)) {
  736. isfatal = 1;
  737. strlcat(msg, "[Memory BIST test failed, InfiniPath hardware"
  738. " unusable]", msgl);
  739. /* ignore from now on, so disable until driver reloaded */
  740. dd->cspec->hwerrmask &= ~HWE_MASK(PowerOnBISTFailed);
  741. qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
  742. }
  743. qib_format_hwerrors(hwerrs, qib_6120_hwerror_msgs,
  744. ARRAY_SIZE(qib_6120_hwerror_msgs), msg, msgl);
  745. bitsmsg = dd->cspec->bitsmsgbuf;
  746. if (hwerrs & (QLOGIC_IB_HWE_PCIEMEMPARITYERR_MASK <<
  747. QLOGIC_IB_HWE_PCIEMEMPARITYERR_SHIFT)) {
  748. bits = (u32) ((hwerrs >>
  749. QLOGIC_IB_HWE_PCIEMEMPARITYERR_SHIFT) &
  750. QLOGIC_IB_HWE_PCIEMEMPARITYERR_MASK);
  751. snprintf(bitsmsg, sizeof dd->cspec->bitsmsgbuf,
  752. "[PCIe Mem Parity Errs %x] ", bits);
  753. strlcat(msg, bitsmsg, msgl);
  754. }
  755. if (hwerrs & _QIB_PLL_FAIL) {
  756. isfatal = 1;
  757. snprintf(bitsmsg, sizeof dd->cspec->bitsmsgbuf,
  758. "[PLL failed (%llx), InfiniPath hardware unusable]",
  759. (unsigned long long) hwerrs & _QIB_PLL_FAIL);
  760. strlcat(msg, bitsmsg, msgl);
  761. /* ignore from now on, so disable until driver reloaded */
  762. dd->cspec->hwerrmask &= ~(hwerrs & _QIB_PLL_FAIL);
  763. qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
  764. }
  765. if (hwerrs & QLOGIC_IB_HWE_SERDESPLLFAILED) {
  766. /*
  767. * If it occurs, it is left masked since the external
  768. * interface is unused
  769. */
  770. dd->cspec->hwerrmask &= ~QLOGIC_IB_HWE_SERDESPLLFAILED;
  771. qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
  772. }
  773. if (hwerrs)
  774. /*
  775. * if any set that we aren't ignoring; only
  776. * make the complaint once, in case it's stuck
  777. * or recurring, and we get here multiple
  778. * times.
  779. */
  780. qib_dev_err(dd, "%s hardware error\n", msg);
  781. else
  782. *msg = 0; /* recovered from all of them */
  783. if (isfatal && !dd->diag_client) {
  784. qib_dev_err(dd, "Fatal Hardware Error, no longer"
  785. " usable, SN %.16s\n", dd->serial);
  786. /*
  787. * for /sys status file and user programs to print; if no
  788. * trailing brace is copied, we'll know it was truncated.
  789. */
  790. if (dd->freezemsg)
  791. snprintf(dd->freezemsg, dd->freezelen,
  792. "{%s}", msg);
  793. qib_disable_after_error(dd);
  794. }
  795. }
  796. /*
  797. * Decode the error status into strings, deciding whether to always
  798. * print * it or not depending on "normal packet errors" vs everything
  799. * else. Return 1 if "real" errors, otherwise 0 if only packet
  800. * errors, so caller can decide what to print with the string.
  801. */
  802. static int qib_decode_6120_err(struct qib_devdata *dd, char *buf, size_t blen,
  803. u64 err)
  804. {
  805. int iserr = 1;
  806. *buf = '\0';
  807. if (err & QLOGIC_IB_E_PKTERRS) {
  808. if (!(err & ~QLOGIC_IB_E_PKTERRS))
  809. iserr = 0;
  810. if ((err & ERR_MASK(RcvICRCErr)) &&
  811. !(err&(ERR_MASK(RcvVCRCErr)|ERR_MASK(RcvEBPErr))))
  812. strlcat(buf, "CRC ", blen);
  813. if (!iserr)
  814. goto done;
  815. }
  816. if (err & ERR_MASK(RcvHdrLenErr))
  817. strlcat(buf, "rhdrlen ", blen);
  818. if (err & ERR_MASK(RcvBadTidErr))
  819. strlcat(buf, "rbadtid ", blen);
  820. if (err & ERR_MASK(RcvBadVersionErr))
  821. strlcat(buf, "rbadversion ", blen);
  822. if (err & ERR_MASK(RcvHdrErr))
  823. strlcat(buf, "rhdr ", blen);
  824. if (err & ERR_MASK(RcvLongPktLenErr))
  825. strlcat(buf, "rlongpktlen ", blen);
  826. if (err & ERR_MASK(RcvMaxPktLenErr))
  827. strlcat(buf, "rmaxpktlen ", blen);
  828. if (err & ERR_MASK(RcvMinPktLenErr))
  829. strlcat(buf, "rminpktlen ", blen);
  830. if (err & ERR_MASK(SendMinPktLenErr))
  831. strlcat(buf, "sminpktlen ", blen);
  832. if (err & ERR_MASK(RcvFormatErr))
  833. strlcat(buf, "rformaterr ", blen);
  834. if (err & ERR_MASK(RcvUnsupportedVLErr))
  835. strlcat(buf, "runsupvl ", blen);
  836. if (err & ERR_MASK(RcvUnexpectedCharErr))
  837. strlcat(buf, "runexpchar ", blen);
  838. if (err & ERR_MASK(RcvIBFlowErr))
  839. strlcat(buf, "ribflow ", blen);
  840. if (err & ERR_MASK(SendUnderRunErr))
  841. strlcat(buf, "sunderrun ", blen);
  842. if (err & ERR_MASK(SendPioArmLaunchErr))
  843. strlcat(buf, "spioarmlaunch ", blen);
  844. if (err & ERR_MASK(SendUnexpectedPktNumErr))
  845. strlcat(buf, "sunexperrpktnum ", blen);
  846. if (err & ERR_MASK(SendDroppedSmpPktErr))
  847. strlcat(buf, "sdroppedsmppkt ", blen);
  848. if (err & ERR_MASK(SendMaxPktLenErr))
  849. strlcat(buf, "smaxpktlen ", blen);
  850. if (err & ERR_MASK(SendUnsupportedVLErr))
  851. strlcat(buf, "sunsupVL ", blen);
  852. if (err & ERR_MASK(InvalidAddrErr))
  853. strlcat(buf, "invalidaddr ", blen);
  854. if (err & ERR_MASK(RcvEgrFullErr))
  855. strlcat(buf, "rcvegrfull ", blen);
  856. if (err & ERR_MASK(RcvHdrFullErr))
  857. strlcat(buf, "rcvhdrfull ", blen);
  858. if (err & ERR_MASK(IBStatusChanged))
  859. strlcat(buf, "ibcstatuschg ", blen);
  860. if (err & ERR_MASK(RcvIBLostLinkErr))
  861. strlcat(buf, "riblostlink ", blen);
  862. if (err & ERR_MASK(HardwareErr))
  863. strlcat(buf, "hardware ", blen);
  864. if (err & ERR_MASK(ResetNegated))
  865. strlcat(buf, "reset ", blen);
  866. done:
  867. return iserr;
  868. }
  869. /*
  870. * Called when we might have an error that is specific to a particular
  871. * PIO buffer, and may need to cancel that buffer, so it can be re-used.
  872. */
  873. static void qib_disarm_6120_senderrbufs(struct qib_pportdata *ppd)
  874. {
  875. unsigned long sbuf[2];
  876. struct qib_devdata *dd = ppd->dd;
  877. /*
  878. * It's possible that sendbuffererror could have bits set; might
  879. * have already done this as a result of hardware error handling.
  880. */
  881. sbuf[0] = qib_read_kreg64(dd, kr_sendbuffererror);
  882. sbuf[1] = qib_read_kreg64(dd, kr_sendbuffererror + 1);
  883. if (sbuf[0] || sbuf[1])
  884. qib_disarm_piobufs_set(dd, sbuf,
  885. dd->piobcnt2k + dd->piobcnt4k);
  886. }
  887. static int chk_6120_linkrecovery(struct qib_devdata *dd, u64 ibcs)
  888. {
  889. int ret = 1;
  890. u32 ibstate = qib_6120_iblink_state(ibcs);
  891. u32 linkrecov = read_6120_creg32(dd, cr_iblinkerrrecov);
  892. if (linkrecov != dd->cspec->lastlinkrecov) {
  893. /* and no more until active again */
  894. dd->cspec->lastlinkrecov = 0;
  895. qib_set_linkstate(dd->pport, QIB_IB_LINKDOWN);
  896. ret = 0;
  897. }
  898. if (ibstate == IB_PORT_ACTIVE)
  899. dd->cspec->lastlinkrecov =
  900. read_6120_creg32(dd, cr_iblinkerrrecov);
  901. return ret;
  902. }
  903. static void handle_6120_errors(struct qib_devdata *dd, u64 errs)
  904. {
  905. char *msg;
  906. u64 ignore_this_time = 0;
  907. u64 iserr = 0;
  908. int log_idx;
  909. struct qib_pportdata *ppd = dd->pport;
  910. u64 mask;
  911. /* don't report errors that are masked */
  912. errs &= dd->cspec->errormask;
  913. msg = dd->cspec->emsgbuf;
  914. /* do these first, they are most important */
  915. if (errs & ERR_MASK(HardwareErr))
  916. qib_handle_6120_hwerrors(dd, msg, sizeof dd->cspec->emsgbuf);
  917. else
  918. for (log_idx = 0; log_idx < QIB_EEP_LOG_CNT; ++log_idx)
  919. if (errs & dd->eep_st_masks[log_idx].errs_to_log)
  920. qib_inc_eeprom_err(dd, log_idx, 1);
  921. if (errs & ~IB_E_BITSEXTANT)
  922. qib_dev_err(dd, "error interrupt with unknown errors "
  923. "%llx set\n",
  924. (unsigned long long) (errs & ~IB_E_BITSEXTANT));
  925. if (errs & E_SUM_ERRS) {
  926. qib_disarm_6120_senderrbufs(ppd);
  927. if ((errs & E_SUM_LINK_PKTERRS) &&
  928. !(ppd->lflags & QIBL_LINKACTIVE)) {
  929. /*
  930. * This can happen when trying to bring the link
  931. * up, but the IB link changes state at the "wrong"
  932. * time. The IB logic then complains that the packet
  933. * isn't valid. We don't want to confuse people, so
  934. * we just don't print them, except at debug
  935. */
  936. ignore_this_time = errs & E_SUM_LINK_PKTERRS;
  937. }
  938. } else if ((errs & E_SUM_LINK_PKTERRS) &&
  939. !(ppd->lflags & QIBL_LINKACTIVE)) {
  940. /*
  941. * This can happen when SMA is trying to bring the link
  942. * up, but the IB link changes state at the "wrong" time.
  943. * The IB logic then complains that the packet isn't
  944. * valid. We don't want to confuse people, so we just
  945. * don't print them, except at debug
  946. */
  947. ignore_this_time = errs & E_SUM_LINK_PKTERRS;
  948. }
  949. qib_write_kreg(dd, kr_errclear, errs);
  950. errs &= ~ignore_this_time;
  951. if (!errs)
  952. goto done;
  953. /*
  954. * The ones we mask off are handled specially below
  955. * or above.
  956. */
  957. mask = ERR_MASK(IBStatusChanged) | ERR_MASK(RcvEgrFullErr) |
  958. ERR_MASK(RcvHdrFullErr) | ERR_MASK(HardwareErr);
  959. qib_decode_6120_err(dd, msg, sizeof dd->cspec->emsgbuf, errs & ~mask);
  960. if (errs & E_SUM_PKTERRS)
  961. qib_stats.sps_rcverrs++;
  962. if (errs & E_SUM_ERRS)
  963. qib_stats.sps_txerrs++;
  964. iserr = errs & ~(E_SUM_PKTERRS | QLOGIC_IB_E_PKTERRS);
  965. if (errs & ERR_MASK(IBStatusChanged)) {
  966. u64 ibcs = qib_read_kreg64(dd, kr_ibcstatus);
  967. u32 ibstate = qib_6120_iblink_state(ibcs);
  968. int handle = 1;
  969. if (ibstate != IB_PORT_INIT && dd->cspec->lastlinkrecov)
  970. handle = chk_6120_linkrecovery(dd, ibcs);
  971. /*
  972. * Since going into a recovery state causes the link state
  973. * to go down and since recovery is transitory, it is better
  974. * if we "miss" ever seeing the link training state go into
  975. * recovery (i.e., ignore this transition for link state
  976. * special handling purposes) without updating lastibcstat.
  977. */
  978. if (handle && qib_6120_phys_portstate(ibcs) ==
  979. IB_PHYSPORTSTATE_LINK_ERR_RECOVER)
  980. handle = 0;
  981. if (handle)
  982. qib_handle_e_ibstatuschanged(ppd, ibcs);
  983. }
  984. if (errs & ERR_MASK(ResetNegated)) {
  985. qib_dev_err(dd, "Got reset, requires re-init "
  986. "(unload and reload driver)\n");
  987. dd->flags &= ~QIB_INITTED; /* needs re-init */
  988. /* mark as having had error */
  989. *dd->devstatusp |= QIB_STATUS_HWERROR;
  990. *dd->pport->statusp &= ~QIB_STATUS_IB_CONF;
  991. }
  992. if (*msg && iserr)
  993. qib_dev_porterr(dd, ppd->port, "%s error\n", msg);
  994. if (ppd->state_wanted & ppd->lflags)
  995. wake_up_interruptible(&ppd->state_wait);
  996. /*
  997. * If there were hdrq or egrfull errors, wake up any processes
  998. * waiting in poll. We used to try to check which contexts had
  999. * the overflow, but given the cost of that and the chip reads
  1000. * to support it, it's better to just wake everybody up if we
  1001. * get an overflow; waiters can poll again if it's not them.
  1002. */
  1003. if (errs & (ERR_MASK(RcvEgrFullErr) | ERR_MASK(RcvHdrFullErr))) {
  1004. qib_handle_urcv(dd, ~0U);
  1005. if (errs & ERR_MASK(RcvEgrFullErr))
  1006. qib_stats.sps_buffull++;
  1007. else
  1008. qib_stats.sps_hdrfull++;
  1009. }
  1010. done:
  1011. return;
  1012. }
  1013. /**
  1014. * qib_6120_init_hwerrors - enable hardware errors
  1015. * @dd: the qlogic_ib device
  1016. *
  1017. * now that we have finished initializing everything that might reasonably
  1018. * cause a hardware error, and cleared those errors bits as they occur,
  1019. * we can enable hardware errors in the mask (potentially enabling
  1020. * freeze mode), and enable hardware errors as errors (along with
  1021. * everything else) in errormask
  1022. */
  1023. static void qib_6120_init_hwerrors(struct qib_devdata *dd)
  1024. {
  1025. u64 val;
  1026. u64 extsval;
  1027. extsval = qib_read_kreg64(dd, kr_extstatus);
  1028. if (!(extsval & QLOGIC_IB_EXTS_MEMBIST_ENDTEST))
  1029. qib_dev_err(dd, "MemBIST did not complete!\n");
  1030. /* init so all hwerrors interrupt, and enter freeze, ajdust below */
  1031. val = ~0ULL;
  1032. if (dd->minrev < 2) {
  1033. /*
  1034. * Avoid problem with internal interface bus parity
  1035. * checking. Fixed in Rev2.
  1036. */
  1037. val &= ~QLOGIC_IB_HWE_PCIEBUSPARITYRADM;
  1038. }
  1039. /* avoid some intel cpu's speculative read freeze mode issue */
  1040. val &= ~TXEMEMPARITYERR_PIOBUF;
  1041. dd->cspec->hwerrmask = val;
  1042. qib_write_kreg(dd, kr_hwerrclear, ~HWE_MASK(PowerOnBISTFailed));
  1043. qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
  1044. /* clear all */
  1045. qib_write_kreg(dd, kr_errclear, ~0ULL);
  1046. /* enable errors that are masked, at least this first time. */
  1047. qib_write_kreg(dd, kr_errmask, ~0ULL);
  1048. dd->cspec->errormask = qib_read_kreg64(dd, kr_errmask);
  1049. /* clear any interrupts up to this point (ints still not enabled) */
  1050. qib_write_kreg(dd, kr_intclear, ~0ULL);
  1051. qib_write_kreg(dd, kr_rcvbthqp,
  1052. dd->qpn_mask << (QIB_6120_RcvBTHQP_BTHQP_Mask_LSB - 1) |
  1053. QIB_KD_QP);
  1054. }
  1055. /*
  1056. * Disable and enable the armlaunch error. Used for PIO bandwidth testing
  1057. * on chips that are count-based, rather than trigger-based. There is no
  1058. * reference counting, but that's also fine, given the intended use.
  1059. * Only chip-specific because it's all register accesses
  1060. */
  1061. static void qib_set_6120_armlaunch(struct qib_devdata *dd, u32 enable)
  1062. {
  1063. if (enable) {
  1064. qib_write_kreg(dd, kr_errclear,
  1065. ERR_MASK(SendPioArmLaunchErr));
  1066. dd->cspec->errormask |= ERR_MASK(SendPioArmLaunchErr);
  1067. } else
  1068. dd->cspec->errormask &= ~ERR_MASK(SendPioArmLaunchErr);
  1069. qib_write_kreg(dd, kr_errmask, dd->cspec->errormask);
  1070. }
  1071. /*
  1072. * Formerly took parameter <which> in pre-shifted,
  1073. * pre-merged form with LinkCmd and LinkInitCmd
  1074. * together, and assuming the zero was NOP.
  1075. */
  1076. static void qib_set_ib_6120_lstate(struct qib_pportdata *ppd, u16 linkcmd,
  1077. u16 linitcmd)
  1078. {
  1079. u64 mod_wd;
  1080. struct qib_devdata *dd = ppd->dd;
  1081. unsigned long flags;
  1082. if (linitcmd == QLOGIC_IB_IBCC_LINKINITCMD_DISABLE) {
  1083. /*
  1084. * If we are told to disable, note that so link-recovery
  1085. * code does not attempt to bring us back up.
  1086. */
  1087. spin_lock_irqsave(&ppd->lflags_lock, flags);
  1088. ppd->lflags |= QIBL_IB_LINK_DISABLED;
  1089. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  1090. } else if (linitcmd || linkcmd == QLOGIC_IB_IBCC_LINKCMD_DOWN) {
  1091. /*
  1092. * Any other linkinitcmd will lead to LINKDOWN and then
  1093. * to INIT (if all is well), so clear flag to let
  1094. * link-recovery code attempt to bring us back up.
  1095. */
  1096. spin_lock_irqsave(&ppd->lflags_lock, flags);
  1097. ppd->lflags &= ~QIBL_IB_LINK_DISABLED;
  1098. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  1099. }
  1100. mod_wd = (linkcmd << QLOGIC_IB_IBCC_LINKCMD_SHIFT) |
  1101. (linitcmd << QLOGIC_IB_IBCC_LINKINITCMD_SHIFT);
  1102. qib_write_kreg(dd, kr_ibcctrl, dd->cspec->ibcctrl | mod_wd);
  1103. /* write to chip to prevent back-to-back writes of control reg */
  1104. qib_write_kreg(dd, kr_scratch, 0);
  1105. }
  1106. /**
  1107. * qib_6120_bringup_serdes - bring up the serdes
  1108. * @dd: the qlogic_ib device
  1109. */
  1110. static int qib_6120_bringup_serdes(struct qib_pportdata *ppd)
  1111. {
  1112. struct qib_devdata *dd = ppd->dd;
  1113. u64 val, config1, prev_val, hwstat, ibc;
  1114. /* Put IBC in reset, sends disabled */
  1115. dd->control &= ~QLOGIC_IB_C_LINKENABLE;
  1116. qib_write_kreg(dd, kr_control, 0ULL);
  1117. dd->cspec->ibdeltainprog = 1;
  1118. dd->cspec->ibsymsnap = read_6120_creg32(dd, cr_ibsymbolerr);
  1119. dd->cspec->iblnkerrsnap = read_6120_creg32(dd, cr_iblinkerrrecov);
  1120. /* flowcontrolwatermark is in units of KBytes */
  1121. ibc = 0x5ULL << SYM_LSB(IBCCtrl, FlowCtrlWaterMark);
  1122. /*
  1123. * How often flowctrl sent. More or less in usecs; balance against
  1124. * watermark value, so that in theory senders always get a flow
  1125. * control update in time to not let the IB link go idle.
  1126. */
  1127. ibc |= 0x3ULL << SYM_LSB(IBCCtrl, FlowCtrlPeriod);
  1128. /* max error tolerance */
  1129. dd->cspec->lli_thresh = 0xf;
  1130. ibc |= (u64) dd->cspec->lli_thresh << SYM_LSB(IBCCtrl, PhyerrThreshold);
  1131. /* use "real" buffer space for */
  1132. ibc |= 4ULL << SYM_LSB(IBCCtrl, CreditScale);
  1133. /* IB credit flow control. */
  1134. ibc |= 0xfULL << SYM_LSB(IBCCtrl, OverrunThreshold);
  1135. /*
  1136. * set initial max size pkt IBC will send, including ICRC; it's the
  1137. * PIO buffer size in dwords, less 1; also see qib_set_mtu()
  1138. */
  1139. ibc |= ((u64)(ppd->ibmaxlen >> 2) + 1) << SYM_LSB(IBCCtrl, MaxPktLen);
  1140. dd->cspec->ibcctrl = ibc; /* without linkcmd or linkinitcmd! */
  1141. /* initially come up waiting for TS1, without sending anything. */
  1142. val = dd->cspec->ibcctrl | (QLOGIC_IB_IBCC_LINKINITCMD_DISABLE <<
  1143. QLOGIC_IB_IBCC_LINKINITCMD_SHIFT);
  1144. qib_write_kreg(dd, kr_ibcctrl, val);
  1145. val = qib_read_kreg64(dd, kr_serdes_cfg0);
  1146. config1 = qib_read_kreg64(dd, kr_serdes_cfg1);
  1147. /*
  1148. * Force reset on, also set rxdetect enable. Must do before reading
  1149. * serdesstatus at least for simulation, or some of the bits in
  1150. * serdes status will come back as undefined and cause simulation
  1151. * failures
  1152. */
  1153. val |= SYM_MASK(SerdesCfg0, ResetPLL) |
  1154. SYM_MASK(SerdesCfg0, RxDetEnX) |
  1155. (SYM_MASK(SerdesCfg0, L1PwrDnA) |
  1156. SYM_MASK(SerdesCfg0, L1PwrDnB) |
  1157. SYM_MASK(SerdesCfg0, L1PwrDnC) |
  1158. SYM_MASK(SerdesCfg0, L1PwrDnD));
  1159. qib_write_kreg(dd, kr_serdes_cfg0, val);
  1160. /* be sure chip saw it */
  1161. qib_read_kreg64(dd, kr_scratch);
  1162. udelay(5); /* need pll reset set at least for a bit */
  1163. /*
  1164. * after PLL is reset, set the per-lane Resets and TxIdle and
  1165. * clear the PLL reset and rxdetect (to get falling edge).
  1166. * Leave L1PWR bits set (permanently)
  1167. */
  1168. val &= ~(SYM_MASK(SerdesCfg0, RxDetEnX) |
  1169. SYM_MASK(SerdesCfg0, ResetPLL) |
  1170. (SYM_MASK(SerdesCfg0, L1PwrDnA) |
  1171. SYM_MASK(SerdesCfg0, L1PwrDnB) |
  1172. SYM_MASK(SerdesCfg0, L1PwrDnC) |
  1173. SYM_MASK(SerdesCfg0, L1PwrDnD)));
  1174. val |= (SYM_MASK(SerdesCfg0, ResetA) |
  1175. SYM_MASK(SerdesCfg0, ResetB) |
  1176. SYM_MASK(SerdesCfg0, ResetC) |
  1177. SYM_MASK(SerdesCfg0, ResetD)) |
  1178. SYM_MASK(SerdesCfg0, TxIdeEnX);
  1179. qib_write_kreg(dd, kr_serdes_cfg0, val);
  1180. /* be sure chip saw it */
  1181. (void) qib_read_kreg64(dd, kr_scratch);
  1182. /* need PLL reset clear for at least 11 usec before lane
  1183. * resets cleared; give it a few more to be sure */
  1184. udelay(15);
  1185. val &= ~((SYM_MASK(SerdesCfg0, ResetA) |
  1186. SYM_MASK(SerdesCfg0, ResetB) |
  1187. SYM_MASK(SerdesCfg0, ResetC) |
  1188. SYM_MASK(SerdesCfg0, ResetD)) |
  1189. SYM_MASK(SerdesCfg0, TxIdeEnX));
  1190. qib_write_kreg(dd, kr_serdes_cfg0, val);
  1191. /* be sure chip saw it */
  1192. (void) qib_read_kreg64(dd, kr_scratch);
  1193. val = qib_read_kreg64(dd, kr_xgxs_cfg);
  1194. prev_val = val;
  1195. if (val & QLOGIC_IB_XGXS_RESET)
  1196. val &= ~QLOGIC_IB_XGXS_RESET;
  1197. if (SYM_FIELD(val, XGXSCfg, polarity_inv) != ppd->rx_pol_inv) {
  1198. /* need to compensate for Tx inversion in partner */
  1199. val &= ~SYM_MASK(XGXSCfg, polarity_inv);
  1200. val |= (u64)ppd->rx_pol_inv << SYM_LSB(XGXSCfg, polarity_inv);
  1201. }
  1202. if (val != prev_val)
  1203. qib_write_kreg(dd, kr_xgxs_cfg, val);
  1204. val = qib_read_kreg64(dd, kr_serdes_cfg0);
  1205. /* clear current and de-emphasis bits */
  1206. config1 &= ~0x0ffffffff00ULL;
  1207. /* set current to 20ma */
  1208. config1 |= 0x00000000000ULL;
  1209. /* set de-emphasis to -5.68dB */
  1210. config1 |= 0x0cccc000000ULL;
  1211. qib_write_kreg(dd, kr_serdes_cfg1, config1);
  1212. /* base and port guid same for single port */
  1213. ppd->guid = dd->base_guid;
  1214. /*
  1215. * the process of setting and un-resetting the serdes normally
  1216. * causes a serdes PLL error, so check for that and clear it
  1217. * here. Also clearr hwerr bit in errstatus, but not others.
  1218. */
  1219. hwstat = qib_read_kreg64(dd, kr_hwerrstatus);
  1220. if (hwstat) {
  1221. /* should just have PLL, clear all set, in an case */
  1222. qib_write_kreg(dd, kr_hwerrclear, hwstat);
  1223. qib_write_kreg(dd, kr_errclear, ERR_MASK(HardwareErr));
  1224. }
  1225. dd->control |= QLOGIC_IB_C_LINKENABLE;
  1226. dd->control &= ~QLOGIC_IB_C_FREEZEMODE;
  1227. qib_write_kreg(dd, kr_control, dd->control);
  1228. return 0;
  1229. }
  1230. /**
  1231. * qib_6120_quiet_serdes - set serdes to txidle
  1232. * @ppd: physical port of the qlogic_ib device
  1233. * Called when driver is being unloaded
  1234. */
  1235. static void qib_6120_quiet_serdes(struct qib_pportdata *ppd)
  1236. {
  1237. struct qib_devdata *dd = ppd->dd;
  1238. u64 val;
  1239. qib_set_ib_6120_lstate(ppd, 0, QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
  1240. /* disable IBC */
  1241. dd->control &= ~QLOGIC_IB_C_LINKENABLE;
  1242. qib_write_kreg(dd, kr_control,
  1243. dd->control | QLOGIC_IB_C_FREEZEMODE);
  1244. if (dd->cspec->ibsymdelta || dd->cspec->iblnkerrdelta ||
  1245. dd->cspec->ibdeltainprog) {
  1246. u64 diagc;
  1247. /* enable counter writes */
  1248. diagc = qib_read_kreg64(dd, kr_hwdiagctrl);
  1249. qib_write_kreg(dd, kr_hwdiagctrl,
  1250. diagc | SYM_MASK(HwDiagCtrl, CounterWrEnable));
  1251. if (dd->cspec->ibsymdelta || dd->cspec->ibdeltainprog) {
  1252. val = read_6120_creg32(dd, cr_ibsymbolerr);
  1253. if (dd->cspec->ibdeltainprog)
  1254. val -= val - dd->cspec->ibsymsnap;
  1255. val -= dd->cspec->ibsymdelta;
  1256. write_6120_creg(dd, cr_ibsymbolerr, val);
  1257. }
  1258. if (dd->cspec->iblnkerrdelta || dd->cspec->ibdeltainprog) {
  1259. val = read_6120_creg32(dd, cr_iblinkerrrecov);
  1260. if (dd->cspec->ibdeltainprog)
  1261. val -= val - dd->cspec->iblnkerrsnap;
  1262. val -= dd->cspec->iblnkerrdelta;
  1263. write_6120_creg(dd, cr_iblinkerrrecov, val);
  1264. }
  1265. /* and disable counter writes */
  1266. qib_write_kreg(dd, kr_hwdiagctrl, diagc);
  1267. }
  1268. val = qib_read_kreg64(dd, kr_serdes_cfg0);
  1269. val |= SYM_MASK(SerdesCfg0, TxIdeEnX);
  1270. qib_write_kreg(dd, kr_serdes_cfg0, val);
  1271. }
  1272. /**
  1273. * qib_6120_setup_setextled - set the state of the two external LEDs
  1274. * @dd: the qlogic_ib device
  1275. * @on: whether the link is up or not
  1276. *
  1277. * The exact combo of LEDs if on is true is determined by looking
  1278. * at the ibcstatus.
  1279. * These LEDs indicate the physical and logical state of IB link.
  1280. * For this chip (at least with recommended board pinouts), LED1
  1281. * is Yellow (logical state) and LED2 is Green (physical state),
  1282. *
  1283. * Note: We try to match the Mellanox HCA LED behavior as best
  1284. * we can. Green indicates physical link state is OK (something is
  1285. * plugged in, and we can train).
  1286. * Amber indicates the link is logically up (ACTIVE).
  1287. * Mellanox further blinks the amber LED to indicate data packet
  1288. * activity, but we have no hardware support for that, so it would
  1289. * require waking up every 10-20 msecs and checking the counters
  1290. * on the chip, and then turning the LED off if appropriate. That's
  1291. * visible overhead, so not something we will do.
  1292. *
  1293. */
  1294. static void qib_6120_setup_setextled(struct qib_pportdata *ppd, u32 on)
  1295. {
  1296. u64 extctl, val, lst, ltst;
  1297. unsigned long flags;
  1298. struct qib_devdata *dd = ppd->dd;
  1299. /*
  1300. * The diags use the LED to indicate diag info, so we leave
  1301. * the external LED alone when the diags are running.
  1302. */
  1303. if (dd->diag_client)
  1304. return;
  1305. /* Allow override of LED display for, e.g. Locating system in rack */
  1306. if (ppd->led_override) {
  1307. ltst = (ppd->led_override & QIB_LED_PHYS) ?
  1308. IB_PHYSPORTSTATE_LINKUP : IB_PHYSPORTSTATE_DISABLED,
  1309. lst = (ppd->led_override & QIB_LED_LOG) ?
  1310. IB_PORT_ACTIVE : IB_PORT_DOWN;
  1311. } else if (on) {
  1312. val = qib_read_kreg64(dd, kr_ibcstatus);
  1313. ltst = qib_6120_phys_portstate(val);
  1314. lst = qib_6120_iblink_state(val);
  1315. } else {
  1316. ltst = 0;
  1317. lst = 0;
  1318. }
  1319. spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
  1320. extctl = dd->cspec->extctrl & ~(SYM_MASK(EXTCtrl, LEDPriPortGreenOn) |
  1321. SYM_MASK(EXTCtrl, LEDPriPortYellowOn));
  1322. if (ltst == IB_PHYSPORTSTATE_LINKUP)
  1323. extctl |= SYM_MASK(EXTCtrl, LEDPriPortYellowOn);
  1324. if (lst == IB_PORT_ACTIVE)
  1325. extctl |= SYM_MASK(EXTCtrl, LEDPriPortGreenOn);
  1326. dd->cspec->extctrl = extctl;
  1327. qib_write_kreg(dd, kr_extctrl, extctl);
  1328. spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
  1329. }
  1330. static void qib_6120_free_irq(struct qib_devdata *dd)
  1331. {
  1332. if (dd->cspec->irq) {
  1333. free_irq(dd->cspec->irq, dd);
  1334. dd->cspec->irq = 0;
  1335. }
  1336. qib_nomsi(dd);
  1337. }
  1338. /**
  1339. * qib_6120_setup_cleanup - clean up any per-chip chip-specific stuff
  1340. * @dd: the qlogic_ib device
  1341. *
  1342. * This is called during driver unload.
  1343. */
  1344. static void qib_6120_setup_cleanup(struct qib_devdata *dd)
  1345. {
  1346. qib_6120_free_irq(dd);
  1347. kfree(dd->cspec->cntrs);
  1348. kfree(dd->cspec->portcntrs);
  1349. if (dd->cspec->dummy_hdrq) {
  1350. dma_free_coherent(&dd->pcidev->dev,
  1351. ALIGN(dd->rcvhdrcnt *
  1352. dd->rcvhdrentsize *
  1353. sizeof(u32), PAGE_SIZE),
  1354. dd->cspec->dummy_hdrq,
  1355. dd->cspec->dummy_hdrq_phys);
  1356. dd->cspec->dummy_hdrq = NULL;
  1357. }
  1358. }
  1359. static void qib_wantpiobuf_6120_intr(struct qib_devdata *dd, u32 needint)
  1360. {
  1361. unsigned long flags;
  1362. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  1363. if (needint)
  1364. dd->sendctrl |= SYM_MASK(SendCtrl, PIOIntBufAvail);
  1365. else
  1366. dd->sendctrl &= ~SYM_MASK(SendCtrl, PIOIntBufAvail);
  1367. qib_write_kreg(dd, kr_sendctrl, dd->sendctrl);
  1368. qib_write_kreg(dd, kr_scratch, 0ULL);
  1369. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  1370. }
  1371. /*
  1372. * handle errors and unusual events first, separate function
  1373. * to improve cache hits for fast path interrupt handling
  1374. */
  1375. static noinline void unlikely_6120_intr(struct qib_devdata *dd, u64 istat)
  1376. {
  1377. if (unlikely(istat & ~QLOGIC_IB_I_BITSEXTANT))
  1378. qib_dev_err(dd, "interrupt with unknown interrupts %Lx set\n",
  1379. istat & ~QLOGIC_IB_I_BITSEXTANT);
  1380. if (istat & QLOGIC_IB_I_ERROR) {
  1381. u64 estat = 0;
  1382. qib_stats.sps_errints++;
  1383. estat = qib_read_kreg64(dd, kr_errstatus);
  1384. if (!estat)
  1385. qib_devinfo(dd->pcidev, "error interrupt (%Lx), "
  1386. "but no error bits set!\n", istat);
  1387. handle_6120_errors(dd, estat);
  1388. }
  1389. if (istat & QLOGIC_IB_I_GPIO) {
  1390. u32 gpiostatus;
  1391. u32 to_clear = 0;
  1392. /*
  1393. * GPIO_3..5 on IBA6120 Rev2 chips indicate
  1394. * errors that we need to count.
  1395. */
  1396. gpiostatus = qib_read_kreg32(dd, kr_gpio_status);
  1397. /* First the error-counter case. */
  1398. if (gpiostatus & GPIO_ERRINTR_MASK) {
  1399. /* want to clear the bits we see asserted. */
  1400. to_clear |= (gpiostatus & GPIO_ERRINTR_MASK);
  1401. /*
  1402. * Count appropriately, clear bits out of our copy,
  1403. * as they have been "handled".
  1404. */
  1405. if (gpiostatus & (1 << GPIO_RXUVL_BIT))
  1406. dd->cspec->rxfc_unsupvl_errs++;
  1407. if (gpiostatus & (1 << GPIO_OVRUN_BIT))
  1408. dd->cspec->overrun_thresh_errs++;
  1409. if (gpiostatus & (1 << GPIO_LLI_BIT))
  1410. dd->cspec->lli_errs++;
  1411. gpiostatus &= ~GPIO_ERRINTR_MASK;
  1412. }
  1413. if (gpiostatus) {
  1414. /*
  1415. * Some unexpected bits remain. If they could have
  1416. * caused the interrupt, complain and clear.
  1417. * To avoid repetition of this condition, also clear
  1418. * the mask. It is almost certainly due to error.
  1419. */
  1420. const u32 mask = qib_read_kreg32(dd, kr_gpio_mask);
  1421. /*
  1422. * Also check that the chip reflects our shadow,
  1423. * and report issues, If they caused the interrupt.
  1424. * we will suppress by refreshing from the shadow.
  1425. */
  1426. if (mask & gpiostatus) {
  1427. to_clear |= (gpiostatus & mask);
  1428. dd->cspec->gpio_mask &= ~(gpiostatus & mask);
  1429. qib_write_kreg(dd, kr_gpio_mask,
  1430. dd->cspec->gpio_mask);
  1431. }
  1432. }
  1433. if (to_clear)
  1434. qib_write_kreg(dd, kr_gpio_clear, (u64) to_clear);
  1435. }
  1436. }
  1437. static irqreturn_t qib_6120intr(int irq, void *data)
  1438. {
  1439. struct qib_devdata *dd = data;
  1440. irqreturn_t ret;
  1441. u32 istat, ctxtrbits, rmask, crcs = 0;
  1442. unsigned i;
  1443. if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT) {
  1444. /*
  1445. * This return value is not great, but we do not want the
  1446. * interrupt core code to remove our interrupt handler
  1447. * because we don't appear to be handling an interrupt
  1448. * during a chip reset.
  1449. */
  1450. ret = IRQ_HANDLED;
  1451. goto bail;
  1452. }
  1453. istat = qib_read_kreg32(dd, kr_intstatus);
  1454. if (unlikely(!istat)) {
  1455. ret = IRQ_NONE; /* not our interrupt, or already handled */
  1456. goto bail;
  1457. }
  1458. if (unlikely(istat == -1)) {
  1459. qib_bad_intrstatus(dd);
  1460. /* don't know if it was our interrupt or not */
  1461. ret = IRQ_NONE;
  1462. goto bail;
  1463. }
  1464. qib_stats.sps_ints++;
  1465. if (dd->int_counter != (u32) -1)
  1466. dd->int_counter++;
  1467. if (unlikely(istat & (~QLOGIC_IB_I_BITSEXTANT |
  1468. QLOGIC_IB_I_GPIO | QLOGIC_IB_I_ERROR)))
  1469. unlikely_6120_intr(dd, istat);
  1470. /*
  1471. * Clear the interrupt bits we found set, relatively early, so we
  1472. * "know" know the chip will have seen this by the time we process
  1473. * the queue, and will re-interrupt if necessary. The processor
  1474. * itself won't take the interrupt again until we return.
  1475. */
  1476. qib_write_kreg(dd, kr_intclear, istat);
  1477. /*
  1478. * Handle kernel receive queues before checking for pio buffers
  1479. * available since receives can overflow; piobuf waiters can afford
  1480. * a few extra cycles, since they were waiting anyway.
  1481. */
  1482. ctxtrbits = istat &
  1483. ((QLOGIC_IB_I_RCVAVAIL_MASK << QLOGIC_IB_I_RCVAVAIL_SHIFT) |
  1484. (QLOGIC_IB_I_RCVURG_MASK << QLOGIC_IB_I_RCVURG_SHIFT));
  1485. if (ctxtrbits) {
  1486. rmask = (1U << QLOGIC_IB_I_RCVAVAIL_SHIFT) |
  1487. (1U << QLOGIC_IB_I_RCVURG_SHIFT);
  1488. for (i = 0; i < dd->first_user_ctxt; i++) {
  1489. if (ctxtrbits & rmask) {
  1490. ctxtrbits &= ~rmask;
  1491. crcs += qib_kreceive(dd->rcd[i],
  1492. &dd->cspec->lli_counter,
  1493. NULL);
  1494. }
  1495. rmask <<= 1;
  1496. }
  1497. if (crcs) {
  1498. u32 cntr = dd->cspec->lli_counter;
  1499. cntr += crcs;
  1500. if (cntr) {
  1501. if (cntr > dd->cspec->lli_thresh) {
  1502. dd->cspec->lli_counter = 0;
  1503. dd->cspec->lli_errs++;
  1504. } else
  1505. dd->cspec->lli_counter += cntr;
  1506. }
  1507. }
  1508. if (ctxtrbits) {
  1509. ctxtrbits =
  1510. (ctxtrbits >> QLOGIC_IB_I_RCVAVAIL_SHIFT) |
  1511. (ctxtrbits >> QLOGIC_IB_I_RCVURG_SHIFT);
  1512. qib_handle_urcv(dd, ctxtrbits);
  1513. }
  1514. }
  1515. if ((istat & QLOGIC_IB_I_SPIOBUFAVAIL) && (dd->flags & QIB_INITTED))
  1516. qib_ib_piobufavail(dd);
  1517. ret = IRQ_HANDLED;
  1518. bail:
  1519. return ret;
  1520. }
  1521. /*
  1522. * Set up our chip-specific interrupt handler
  1523. * The interrupt type has already been setup, so
  1524. * we just need to do the registration and error checking.
  1525. */
  1526. static void qib_setup_6120_interrupt(struct qib_devdata *dd)
  1527. {
  1528. /*
  1529. * If the chip supports added error indication via GPIO pins,
  1530. * enable interrupts on those bits so the interrupt routine
  1531. * can count the events. Also set flag so interrupt routine
  1532. * can know they are expected.
  1533. */
  1534. if (SYM_FIELD(dd->revision, Revision_R,
  1535. ChipRevMinor) > 1) {
  1536. /* Rev2+ reports extra errors via internal GPIO pins */
  1537. dd->cspec->gpio_mask |= GPIO_ERRINTR_MASK;
  1538. qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
  1539. }
  1540. if (!dd->cspec->irq)
  1541. qib_dev_err(dd, "irq is 0, BIOS error? Interrupts won't "
  1542. "work\n");
  1543. else {
  1544. int ret;
  1545. ret = request_irq(dd->cspec->irq, qib_6120intr, 0,
  1546. QIB_DRV_NAME, dd);
  1547. if (ret)
  1548. qib_dev_err(dd, "Couldn't setup interrupt "
  1549. "(irq=%d): %d\n", dd->cspec->irq,
  1550. ret);
  1551. }
  1552. }
  1553. /**
  1554. * pe_boardname - fill in the board name
  1555. * @dd: the qlogic_ib device
  1556. *
  1557. * info is based on the board revision register
  1558. */
  1559. static void pe_boardname(struct qib_devdata *dd)
  1560. {
  1561. char *n;
  1562. u32 boardid, namelen;
  1563. boardid = SYM_FIELD(dd->revision, Revision,
  1564. BoardID);
  1565. switch (boardid) {
  1566. case 2:
  1567. n = "InfiniPath_QLE7140";
  1568. break;
  1569. default:
  1570. qib_dev_err(dd, "Unknown 6120 board with ID %u\n", boardid);
  1571. n = "Unknown_InfiniPath_6120";
  1572. break;
  1573. }
  1574. namelen = strlen(n) + 1;
  1575. dd->boardname = kmalloc(namelen, GFP_KERNEL);
  1576. if (!dd->boardname)
  1577. qib_dev_err(dd, "Failed allocation for board name: %s\n", n);
  1578. else
  1579. snprintf(dd->boardname, namelen, "%s", n);
  1580. if (dd->majrev != 4 || !dd->minrev || dd->minrev > 2)
  1581. qib_dev_err(dd, "Unsupported InfiniPath hardware revision "
  1582. "%u.%u!\n", dd->majrev, dd->minrev);
  1583. snprintf(dd->boardversion, sizeof(dd->boardversion),
  1584. "ChipABI %u.%u, %s, InfiniPath%u %u.%u, SW Compat %u\n",
  1585. QIB_CHIP_VERS_MAJ, QIB_CHIP_VERS_MIN, dd->boardname,
  1586. (unsigned)SYM_FIELD(dd->revision, Revision_R, Arch),
  1587. dd->majrev, dd->minrev,
  1588. (unsigned)SYM_FIELD(dd->revision, Revision_R, SW));
  1589. }
  1590. /*
  1591. * This routine sleeps, so it can only be called from user context, not
  1592. * from interrupt context. If we need interrupt context, we can split
  1593. * it into two routines.
  1594. */
  1595. static int qib_6120_setup_reset(struct qib_devdata *dd)
  1596. {
  1597. u64 val;
  1598. int i;
  1599. int ret;
  1600. u16 cmdval;
  1601. u8 int_line, clinesz;
  1602. qib_pcie_getcmd(dd, &cmdval, &int_line, &clinesz);
  1603. /* Use ERROR so it shows up in logs, etc. */
  1604. qib_dev_err(dd, "Resetting InfiniPath unit %u\n", dd->unit);
  1605. /* no interrupts till re-initted */
  1606. qib_6120_set_intr_state(dd, 0);
  1607. dd->cspec->ibdeltainprog = 0;
  1608. dd->cspec->ibsymdelta = 0;
  1609. dd->cspec->iblnkerrdelta = 0;
  1610. /*
  1611. * Keep chip from being accessed until we are ready. Use
  1612. * writeq() directly, to allow the write even though QIB_PRESENT
  1613. * isn't set.
  1614. */
  1615. dd->flags &= ~(QIB_INITTED | QIB_PRESENT);
  1616. dd->int_counter = 0; /* so we check interrupts work again */
  1617. val = dd->control | QLOGIC_IB_C_RESET;
  1618. writeq(val, &dd->kregbase[kr_control]);
  1619. mb(); /* prevent compiler re-ordering around actual reset */
  1620. for (i = 1; i <= 5; i++) {
  1621. /*
  1622. * Allow MBIST, etc. to complete; longer on each retry.
  1623. * We sometimes get machine checks from bus timeout if no
  1624. * response, so for now, make it *really* long.
  1625. */
  1626. msleep(1000 + (1 + i) * 2000);
  1627. qib_pcie_reenable(dd, cmdval, int_line, clinesz);
  1628. /*
  1629. * Use readq directly, so we don't need to mark it as PRESENT
  1630. * until we get a successful indication that all is well.
  1631. */
  1632. val = readq(&dd->kregbase[kr_revision]);
  1633. if (val == dd->revision) {
  1634. dd->flags |= QIB_PRESENT; /* it's back */
  1635. ret = qib_reinit_intr(dd);
  1636. goto bail;
  1637. }
  1638. }
  1639. ret = 0; /* failed */
  1640. bail:
  1641. if (ret) {
  1642. if (qib_pcie_params(dd, dd->lbus_width, NULL, NULL))
  1643. qib_dev_err(dd, "Reset failed to setup PCIe or "
  1644. "interrupts; continuing anyway\n");
  1645. /* clear the reset error, init error/hwerror mask */
  1646. qib_6120_init_hwerrors(dd);
  1647. /* for Rev2 error interrupts; nop for rev 1 */
  1648. qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
  1649. /* clear the reset error, init error/hwerror mask */
  1650. qib_6120_init_hwerrors(dd);
  1651. }
  1652. return ret;
  1653. }
  1654. /**
  1655. * qib_6120_put_tid - write a TID in chip
  1656. * @dd: the qlogic_ib device
  1657. * @tidptr: pointer to the expected TID (in chip) to update
  1658. * @tidtype: RCVHQ_RCV_TYPE_EAGER (1) for eager, RCVHQ_RCV_TYPE_EXPECTED (0)
  1659. * for expected
  1660. * @pa: physical address of in memory buffer; tidinvalid if freeing
  1661. *
  1662. * This exists as a separate routine to allow for special locking etc.
  1663. * It's used for both the full cleanup on exit, as well as the normal
  1664. * setup and teardown.
  1665. */
  1666. static void qib_6120_put_tid(struct qib_devdata *dd, u64 __iomem *tidptr,
  1667. u32 type, unsigned long pa)
  1668. {
  1669. u32 __iomem *tidp32 = (u32 __iomem *)tidptr;
  1670. unsigned long flags;
  1671. int tidx;
  1672. spinlock_t *tidlockp; /* select appropriate spinlock */
  1673. if (!dd->kregbase)
  1674. return;
  1675. if (pa != dd->tidinvalid) {
  1676. if (pa & ((1U << 11) - 1)) {
  1677. qib_dev_err(dd, "Physaddr %lx not 2KB aligned!\n",
  1678. pa);
  1679. return;
  1680. }
  1681. pa >>= 11;
  1682. if (pa & ~QLOGIC_IB_RT_ADDR_MASK) {
  1683. qib_dev_err(dd, "Physical page address 0x%lx "
  1684. "larger than supported\n", pa);
  1685. return;
  1686. }
  1687. if (type == RCVHQ_RCV_TYPE_EAGER)
  1688. pa |= dd->tidtemplate;
  1689. else /* for now, always full 4KB page */
  1690. pa |= 2 << 29;
  1691. }
  1692. /*
  1693. * Avoid chip issue by writing the scratch register
  1694. * before and after the TID, and with an io write barrier.
  1695. * We use a spinlock around the writes, so they can't intermix
  1696. * with other TID (eager or expected) writes (the chip problem
  1697. * is triggered by back to back TID writes). Unfortunately, this
  1698. * call can be done from interrupt level for the ctxt 0 eager TIDs,
  1699. * so we have to use irqsave locks.
  1700. */
  1701. /*
  1702. * Assumes tidptr always > egrtidbase
  1703. * if type == RCVHQ_RCV_TYPE_EAGER.
  1704. */
  1705. tidx = tidptr - dd->egrtidbase;
  1706. tidlockp = (type == RCVHQ_RCV_TYPE_EAGER && tidx < dd->rcvhdrcnt)
  1707. ? &dd->cspec->kernel_tid_lock : &dd->cspec->user_tid_lock;
  1708. spin_lock_irqsave(tidlockp, flags);
  1709. qib_write_kreg(dd, kr_scratch, 0xfeeddeaf);
  1710. writel(pa, tidp32);
  1711. qib_write_kreg(dd, kr_scratch, 0xdeadbeef);
  1712. mmiowb();
  1713. spin_unlock_irqrestore(tidlockp, flags);
  1714. }
  1715. /**
  1716. * qib_6120_put_tid_2 - write a TID in chip, Revision 2 or higher
  1717. * @dd: the qlogic_ib device
  1718. * @tidptr: pointer to the expected TID (in chip) to update
  1719. * @tidtype: RCVHQ_RCV_TYPE_EAGER (1) for eager, RCVHQ_RCV_TYPE_EXPECTED (0)
  1720. * for expected
  1721. * @pa: physical address of in memory buffer; tidinvalid if freeing
  1722. *
  1723. * This exists as a separate routine to allow for selection of the
  1724. * appropriate "flavor". The static calls in cleanup just use the
  1725. * revision-agnostic form, as they are not performance critical.
  1726. */
  1727. static void qib_6120_put_tid_2(struct qib_devdata *dd, u64 __iomem *tidptr,
  1728. u32 type, unsigned long pa)
  1729. {
  1730. u32 __iomem *tidp32 = (u32 __iomem *)tidptr;
  1731. u32 tidx;
  1732. if (!dd->kregbase)
  1733. return;
  1734. if (pa != dd->tidinvalid) {
  1735. if (pa & ((1U << 11) - 1)) {
  1736. qib_dev_err(dd, "Physaddr %lx not 2KB aligned!\n",
  1737. pa);
  1738. return;
  1739. }
  1740. pa >>= 11;
  1741. if (pa & ~QLOGIC_IB_RT_ADDR_MASK) {
  1742. qib_dev_err(dd, "Physical page address 0x%lx "
  1743. "larger than supported\n", pa);
  1744. return;
  1745. }
  1746. if (type == RCVHQ_RCV_TYPE_EAGER)
  1747. pa |= dd->tidtemplate;
  1748. else /* for now, always full 4KB page */
  1749. pa |= 2 << 29;
  1750. }
  1751. tidx = tidptr - dd->egrtidbase;
  1752. writel(pa, tidp32);
  1753. mmiowb();
  1754. }
  1755. /**
  1756. * qib_6120_clear_tids - clear all TID entries for a context, expected and eager
  1757. * @dd: the qlogic_ib device
  1758. * @ctxt: the context
  1759. *
  1760. * clear all TID entries for a context, expected and eager.
  1761. * Used from qib_close(). On this chip, TIDs are only 32 bits,
  1762. * not 64, but they are still on 64 bit boundaries, so tidbase
  1763. * is declared as u64 * for the pointer math, even though we write 32 bits
  1764. */
  1765. static void qib_6120_clear_tids(struct qib_devdata *dd,
  1766. struct qib_ctxtdata *rcd)
  1767. {
  1768. u64 __iomem *tidbase;
  1769. unsigned long tidinv;
  1770. u32 ctxt;
  1771. int i;
  1772. if (!dd->kregbase || !rcd)
  1773. return;
  1774. ctxt = rcd->ctxt;
  1775. tidinv = dd->tidinvalid;
  1776. tidbase = (u64 __iomem *)
  1777. ((char __iomem *)(dd->kregbase) +
  1778. dd->rcvtidbase +
  1779. ctxt * dd->rcvtidcnt * sizeof(*tidbase));
  1780. for (i = 0; i < dd->rcvtidcnt; i++)
  1781. /* use func pointer because could be one of two funcs */
  1782. dd->f_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EXPECTED,
  1783. tidinv);
  1784. tidbase = (u64 __iomem *)
  1785. ((char __iomem *)(dd->kregbase) +
  1786. dd->rcvegrbase +
  1787. rcd->rcvegr_tid_base * sizeof(*tidbase));
  1788. for (i = 0; i < rcd->rcvegrcnt; i++)
  1789. /* use func pointer because could be one of two funcs */
  1790. dd->f_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EAGER,
  1791. tidinv);
  1792. }
  1793. /**
  1794. * qib_6120_tidtemplate - setup constants for TID updates
  1795. * @dd: the qlogic_ib device
  1796. *
  1797. * We setup stuff that we use a lot, to avoid calculating each time
  1798. */
  1799. static void qib_6120_tidtemplate(struct qib_devdata *dd)
  1800. {
  1801. u32 egrsize = dd->rcvegrbufsize;
  1802. /*
  1803. * For now, we always allocate 4KB buffers (at init) so we can
  1804. * receive max size packets. We may want a module parameter to
  1805. * specify 2KB or 4KB and/or make be per ctxt instead of per device
  1806. * for those who want to reduce memory footprint. Note that the
  1807. * rcvhdrentsize size must be large enough to hold the largest
  1808. * IB header (currently 96 bytes) that we expect to handle (plus of
  1809. * course the 2 dwords of RHF).
  1810. */
  1811. if (egrsize == 2048)
  1812. dd->tidtemplate = 1U << 29;
  1813. else if (egrsize == 4096)
  1814. dd->tidtemplate = 2U << 29;
  1815. dd->tidinvalid = 0;
  1816. }
  1817. int __attribute__((weak)) qib_unordered_wc(void)
  1818. {
  1819. return 0;
  1820. }
  1821. /**
  1822. * qib_6120_get_base_info - set chip-specific flags for user code
  1823. * @rcd: the qlogic_ib ctxt
  1824. * @kbase: qib_base_info pointer
  1825. *
  1826. * We set the PCIE flag because the lower bandwidth on PCIe vs
  1827. * HyperTransport can affect some user packet algorithms.
  1828. */
  1829. static int qib_6120_get_base_info(struct qib_ctxtdata *rcd,
  1830. struct qib_base_info *kinfo)
  1831. {
  1832. if (qib_unordered_wc())
  1833. kinfo->spi_runtime_flags |= QIB_RUNTIME_FORCE_WC_ORDER;
  1834. kinfo->spi_runtime_flags |= QIB_RUNTIME_PCIE |
  1835. QIB_RUNTIME_FORCE_PIOAVAIL | QIB_RUNTIME_PIO_REGSWAPPED;
  1836. return 0;
  1837. }
  1838. static struct qib_message_header *
  1839. qib_6120_get_msgheader(struct qib_devdata *dd, __le32 *rhf_addr)
  1840. {
  1841. return (struct qib_message_header *)
  1842. &rhf_addr[sizeof(u64) / sizeof(u32)];
  1843. }
  1844. static void qib_6120_config_ctxts(struct qib_devdata *dd)
  1845. {
  1846. dd->ctxtcnt = qib_read_kreg32(dd, kr_portcnt);
  1847. if (qib_n_krcv_queues > 1) {
  1848. dd->first_user_ctxt = qib_n_krcv_queues * dd->num_pports;
  1849. if (dd->first_user_ctxt > dd->ctxtcnt)
  1850. dd->first_user_ctxt = dd->ctxtcnt;
  1851. dd->qpn_mask = dd->first_user_ctxt <= 2 ? 2 : 6;
  1852. } else
  1853. dd->first_user_ctxt = dd->num_pports;
  1854. dd->n_krcv_queues = dd->first_user_ctxt;
  1855. }
  1856. static void qib_update_6120_usrhead(struct qib_ctxtdata *rcd, u64 hd,
  1857. u32 updegr, u32 egrhd, u32 npkts)
  1858. {
  1859. if (updegr)
  1860. qib_write_ureg(rcd->dd, ur_rcvegrindexhead, egrhd, rcd->ctxt);
  1861. mmiowb();
  1862. qib_write_ureg(rcd->dd, ur_rcvhdrhead, hd, rcd->ctxt);
  1863. mmiowb();
  1864. }
  1865. static u32 qib_6120_hdrqempty(struct qib_ctxtdata *rcd)
  1866. {
  1867. u32 head, tail;
  1868. head = qib_read_ureg32(rcd->dd, ur_rcvhdrhead, rcd->ctxt);
  1869. if (rcd->rcvhdrtail_kvaddr)
  1870. tail = qib_get_rcvhdrtail(rcd);
  1871. else
  1872. tail = qib_read_ureg32(rcd->dd, ur_rcvhdrtail, rcd->ctxt);
  1873. return head == tail;
  1874. }
  1875. /*
  1876. * Used when we close any ctxt, for DMA already in flight
  1877. * at close. Can't be done until we know hdrq size, so not
  1878. * early in chip init.
  1879. */
  1880. static void alloc_dummy_hdrq(struct qib_devdata *dd)
  1881. {
  1882. dd->cspec->dummy_hdrq = dma_alloc_coherent(&dd->pcidev->dev,
  1883. dd->rcd[0]->rcvhdrq_size,
  1884. &dd->cspec->dummy_hdrq_phys,
  1885. GFP_ATOMIC | __GFP_COMP);
  1886. if (!dd->cspec->dummy_hdrq) {
  1887. qib_devinfo(dd->pcidev, "Couldn't allocate dummy hdrq\n");
  1888. /* fallback to just 0'ing */
  1889. dd->cspec->dummy_hdrq_phys = 0UL;
  1890. }
  1891. }
  1892. /*
  1893. * Modify the RCVCTRL register in chip-specific way. This
  1894. * is a function because bit positions and (future) register
  1895. * location is chip-specific, but the needed operations are
  1896. * generic. <op> is a bit-mask because we often want to
  1897. * do multiple modifications.
  1898. */
  1899. static void rcvctrl_6120_mod(struct qib_pportdata *ppd, unsigned int op,
  1900. int ctxt)
  1901. {
  1902. struct qib_devdata *dd = ppd->dd;
  1903. u64 mask, val;
  1904. unsigned long flags;
  1905. spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
  1906. if (op & QIB_RCVCTRL_TAILUPD_ENB)
  1907. dd->rcvctrl |= (1ULL << QLOGIC_IB_R_TAILUPD_SHIFT);
  1908. if (op & QIB_RCVCTRL_TAILUPD_DIS)
  1909. dd->rcvctrl &= ~(1ULL << QLOGIC_IB_R_TAILUPD_SHIFT);
  1910. if (op & QIB_RCVCTRL_PKEY_ENB)
  1911. dd->rcvctrl &= ~(1ULL << IBA6120_R_PKEY_DIS_SHIFT);
  1912. if (op & QIB_RCVCTRL_PKEY_DIS)
  1913. dd->rcvctrl |= (1ULL << IBA6120_R_PKEY_DIS_SHIFT);
  1914. if (ctxt < 0)
  1915. mask = (1ULL << dd->ctxtcnt) - 1;
  1916. else
  1917. mask = (1ULL << ctxt);
  1918. if (op & QIB_RCVCTRL_CTXT_ENB) {
  1919. /* always done for specific ctxt */
  1920. dd->rcvctrl |= (mask << SYM_LSB(RcvCtrl, PortEnable));
  1921. if (!(dd->flags & QIB_NODMA_RTAIL))
  1922. dd->rcvctrl |= 1ULL << QLOGIC_IB_R_TAILUPD_SHIFT;
  1923. /* Write these registers before the context is enabled. */
  1924. qib_write_kreg_ctxt(dd, kr_rcvhdrtailaddr, ctxt,
  1925. dd->rcd[ctxt]->rcvhdrqtailaddr_phys);
  1926. qib_write_kreg_ctxt(dd, kr_rcvhdraddr, ctxt,
  1927. dd->rcd[ctxt]->rcvhdrq_phys);
  1928. if (ctxt == 0 && !dd->cspec->dummy_hdrq)
  1929. alloc_dummy_hdrq(dd);
  1930. }
  1931. if (op & QIB_RCVCTRL_CTXT_DIS)
  1932. dd->rcvctrl &= ~(mask << SYM_LSB(RcvCtrl, PortEnable));
  1933. if (op & QIB_RCVCTRL_INTRAVAIL_ENB)
  1934. dd->rcvctrl |= (mask << QLOGIC_IB_R_INTRAVAIL_SHIFT);
  1935. if (op & QIB_RCVCTRL_INTRAVAIL_DIS)
  1936. dd->rcvctrl &= ~(mask << QLOGIC_IB_R_INTRAVAIL_SHIFT);
  1937. qib_write_kreg(dd, kr_rcvctrl, dd->rcvctrl);
  1938. if ((op & QIB_RCVCTRL_INTRAVAIL_ENB) && dd->rhdrhead_intr_off) {
  1939. /* arm rcv interrupt */
  1940. val = qib_read_ureg32(dd, ur_rcvhdrhead, ctxt) |
  1941. dd->rhdrhead_intr_off;
  1942. qib_write_ureg(dd, ur_rcvhdrhead, val, ctxt);
  1943. }
  1944. if (op & QIB_RCVCTRL_CTXT_ENB) {
  1945. /*
  1946. * Init the context registers also; if we were
  1947. * disabled, tail and head should both be zero
  1948. * already from the enable, but since we don't
  1949. * know, we have to do it explicitly.
  1950. */
  1951. val = qib_read_ureg32(dd, ur_rcvegrindextail, ctxt);
  1952. qib_write_ureg(dd, ur_rcvegrindexhead, val, ctxt);
  1953. val = qib_read_ureg32(dd, ur_rcvhdrtail, ctxt);
  1954. dd->rcd[ctxt]->head = val;
  1955. /* If kctxt, interrupt on next receive. */
  1956. if (ctxt < dd->first_user_ctxt)
  1957. val |= dd->rhdrhead_intr_off;
  1958. qib_write_ureg(dd, ur_rcvhdrhead, val, ctxt);
  1959. }
  1960. if (op & QIB_RCVCTRL_CTXT_DIS) {
  1961. /*
  1962. * Be paranoid, and never write 0's to these, just use an
  1963. * unused page. Of course,
  1964. * rcvhdraddr points to a large chunk of memory, so this
  1965. * could still trash things, but at least it won't trash
  1966. * page 0, and by disabling the ctxt, it should stop "soon",
  1967. * even if a packet or two is in already in flight after we
  1968. * disabled the ctxt. Only 6120 has this issue.
  1969. */
  1970. if (ctxt >= 0) {
  1971. qib_write_kreg_ctxt(dd, kr_rcvhdrtailaddr, ctxt,
  1972. dd->cspec->dummy_hdrq_phys);
  1973. qib_write_kreg_ctxt(dd, kr_rcvhdraddr, ctxt,
  1974. dd->cspec->dummy_hdrq_phys);
  1975. } else {
  1976. unsigned i;
  1977. for (i = 0; i < dd->cfgctxts; i++) {
  1978. qib_write_kreg_ctxt(dd, kr_rcvhdrtailaddr,
  1979. i, dd->cspec->dummy_hdrq_phys);
  1980. qib_write_kreg_ctxt(dd, kr_rcvhdraddr,
  1981. i, dd->cspec->dummy_hdrq_phys);
  1982. }
  1983. }
  1984. }
  1985. spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
  1986. }
  1987. /*
  1988. * Modify the SENDCTRL register in chip-specific way. This
  1989. * is a function there may be multiple such registers with
  1990. * slightly different layouts. Only operations actually used
  1991. * are implemented yet.
  1992. * Chip requires no back-back sendctrl writes, so write
  1993. * scratch register after writing sendctrl
  1994. */
  1995. static void sendctrl_6120_mod(struct qib_pportdata *ppd, u32 op)
  1996. {
  1997. struct qib_devdata *dd = ppd->dd;
  1998. u64 tmp_dd_sendctrl;
  1999. unsigned long flags;
  2000. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  2001. /* First the ones that are "sticky", saved in shadow */
  2002. if (op & QIB_SENDCTRL_CLEAR)
  2003. dd->sendctrl = 0;
  2004. if (op & QIB_SENDCTRL_SEND_DIS)
  2005. dd->sendctrl &= ~SYM_MASK(SendCtrl, PIOEnable);
  2006. else if (op & QIB_SENDCTRL_SEND_ENB)
  2007. dd->sendctrl |= SYM_MASK(SendCtrl, PIOEnable);
  2008. if (op & QIB_SENDCTRL_AVAIL_DIS)
  2009. dd->sendctrl &= ~SYM_MASK(SendCtrl, PIOBufAvailUpd);
  2010. else if (op & QIB_SENDCTRL_AVAIL_ENB)
  2011. dd->sendctrl |= SYM_MASK(SendCtrl, PIOBufAvailUpd);
  2012. if (op & QIB_SENDCTRL_DISARM_ALL) {
  2013. u32 i, last;
  2014. tmp_dd_sendctrl = dd->sendctrl;
  2015. /*
  2016. * disarm any that are not yet launched, disabling sends
  2017. * and updates until done.
  2018. */
  2019. last = dd->piobcnt2k + dd->piobcnt4k;
  2020. tmp_dd_sendctrl &=
  2021. ~(SYM_MASK(SendCtrl, PIOEnable) |
  2022. SYM_MASK(SendCtrl, PIOBufAvailUpd));
  2023. for (i = 0; i < last; i++) {
  2024. qib_write_kreg(dd, kr_sendctrl, tmp_dd_sendctrl |
  2025. SYM_MASK(SendCtrl, Disarm) | i);
  2026. qib_write_kreg(dd, kr_scratch, 0);
  2027. }
  2028. }
  2029. tmp_dd_sendctrl = dd->sendctrl;
  2030. if (op & QIB_SENDCTRL_FLUSH)
  2031. tmp_dd_sendctrl |= SYM_MASK(SendCtrl, Abort);
  2032. if (op & QIB_SENDCTRL_DISARM)
  2033. tmp_dd_sendctrl |= SYM_MASK(SendCtrl, Disarm) |
  2034. ((op & QIB_6120_SendCtrl_DisarmPIOBuf_RMASK) <<
  2035. SYM_LSB(SendCtrl, DisarmPIOBuf));
  2036. if (op & QIB_SENDCTRL_AVAIL_BLIP)
  2037. tmp_dd_sendctrl &= ~SYM_MASK(SendCtrl, PIOBufAvailUpd);
  2038. qib_write_kreg(dd, kr_sendctrl, tmp_dd_sendctrl);
  2039. qib_write_kreg(dd, kr_scratch, 0);
  2040. if (op & QIB_SENDCTRL_AVAIL_BLIP) {
  2041. qib_write_kreg(dd, kr_sendctrl, dd->sendctrl);
  2042. qib_write_kreg(dd, kr_scratch, 0);
  2043. }
  2044. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  2045. if (op & QIB_SENDCTRL_FLUSH) {
  2046. u32 v;
  2047. /*
  2048. * ensure writes have hit chip, then do a few
  2049. * more reads, to allow DMA of pioavail registers
  2050. * to occur, so in-memory copy is in sync with
  2051. * the chip. Not always safe to sleep.
  2052. */
  2053. v = qib_read_kreg32(dd, kr_scratch);
  2054. qib_write_kreg(dd, kr_scratch, v);
  2055. v = qib_read_kreg32(dd, kr_scratch);
  2056. qib_write_kreg(dd, kr_scratch, v);
  2057. qib_read_kreg32(dd, kr_scratch);
  2058. }
  2059. }
  2060. /**
  2061. * qib_portcntr_6120 - read a per-port counter
  2062. * @dd: the qlogic_ib device
  2063. * @creg: the counter to snapshot
  2064. */
  2065. static u64 qib_portcntr_6120(struct qib_pportdata *ppd, u32 reg)
  2066. {
  2067. u64 ret = 0ULL;
  2068. struct qib_devdata *dd = ppd->dd;
  2069. u16 creg;
  2070. /* 0xffff for unimplemented or synthesized counters */
  2071. static const u16 xlator[] = {
  2072. [QIBPORTCNTR_PKTSEND] = cr_pktsend,
  2073. [QIBPORTCNTR_WORDSEND] = cr_wordsend,
  2074. [QIBPORTCNTR_PSXMITDATA] = 0xffff,
  2075. [QIBPORTCNTR_PSXMITPKTS] = 0xffff,
  2076. [QIBPORTCNTR_PSXMITWAIT] = 0xffff,
  2077. [QIBPORTCNTR_SENDSTALL] = cr_sendstall,
  2078. [QIBPORTCNTR_PKTRCV] = cr_pktrcv,
  2079. [QIBPORTCNTR_PSRCVDATA] = 0xffff,
  2080. [QIBPORTCNTR_PSRCVPKTS] = 0xffff,
  2081. [QIBPORTCNTR_RCVEBP] = cr_rcvebp,
  2082. [QIBPORTCNTR_RCVOVFL] = cr_rcvovfl,
  2083. [QIBPORTCNTR_WORDRCV] = cr_wordrcv,
  2084. [QIBPORTCNTR_RXDROPPKT] = cr_rxdroppkt,
  2085. [QIBPORTCNTR_RXLOCALPHYERR] = 0xffff,
  2086. [QIBPORTCNTR_RXVLERR] = 0xffff,
  2087. [QIBPORTCNTR_ERRICRC] = cr_erricrc,
  2088. [QIBPORTCNTR_ERRVCRC] = cr_errvcrc,
  2089. [QIBPORTCNTR_ERRLPCRC] = cr_errlpcrc,
  2090. [QIBPORTCNTR_BADFORMAT] = cr_badformat,
  2091. [QIBPORTCNTR_ERR_RLEN] = cr_err_rlen,
  2092. [QIBPORTCNTR_IBSYMBOLERR] = cr_ibsymbolerr,
  2093. [QIBPORTCNTR_INVALIDRLEN] = cr_invalidrlen,
  2094. [QIBPORTCNTR_UNSUPVL] = cr_txunsupvl,
  2095. [QIBPORTCNTR_EXCESSBUFOVFL] = 0xffff,
  2096. [QIBPORTCNTR_ERRLINK] = cr_errlink,
  2097. [QIBPORTCNTR_IBLINKDOWN] = cr_iblinkdown,
  2098. [QIBPORTCNTR_IBLINKERRRECOV] = cr_iblinkerrrecov,
  2099. [QIBPORTCNTR_LLI] = 0xffff,
  2100. [QIBPORTCNTR_PSINTERVAL] = 0xffff,
  2101. [QIBPORTCNTR_PSSTART] = 0xffff,
  2102. [QIBPORTCNTR_PSSTAT] = 0xffff,
  2103. [QIBPORTCNTR_VL15PKTDROP] = 0xffff,
  2104. [QIBPORTCNTR_ERRPKEY] = cr_errpkey,
  2105. [QIBPORTCNTR_KHDROVFL] = 0xffff,
  2106. };
  2107. if (reg >= ARRAY_SIZE(xlator)) {
  2108. qib_devinfo(ppd->dd->pcidev,
  2109. "Unimplemented portcounter %u\n", reg);
  2110. goto done;
  2111. }
  2112. creg = xlator[reg];
  2113. /* handle counters requests not implemented as chip counters */
  2114. if (reg == QIBPORTCNTR_LLI)
  2115. ret = dd->cspec->lli_errs;
  2116. else if (reg == QIBPORTCNTR_EXCESSBUFOVFL)
  2117. ret = dd->cspec->overrun_thresh_errs;
  2118. else if (reg == QIBPORTCNTR_KHDROVFL) {
  2119. int i;
  2120. /* sum over all kernel contexts */
  2121. for (i = 0; i < dd->first_user_ctxt; i++)
  2122. ret += read_6120_creg32(dd, cr_portovfl + i);
  2123. } else if (reg == QIBPORTCNTR_PSSTAT)
  2124. ret = dd->cspec->pma_sample_status;
  2125. if (creg == 0xffff)
  2126. goto done;
  2127. /*
  2128. * only fast incrementing counters are 64bit; use 32 bit reads to
  2129. * avoid two independent reads when on opteron
  2130. */
  2131. if (creg == cr_wordsend || creg == cr_wordrcv ||
  2132. creg == cr_pktsend || creg == cr_pktrcv)
  2133. ret = read_6120_creg(dd, creg);
  2134. else
  2135. ret = read_6120_creg32(dd, creg);
  2136. if (creg == cr_ibsymbolerr) {
  2137. if (dd->cspec->ibdeltainprog)
  2138. ret -= ret - dd->cspec->ibsymsnap;
  2139. ret -= dd->cspec->ibsymdelta;
  2140. } else if (creg == cr_iblinkerrrecov) {
  2141. if (dd->cspec->ibdeltainprog)
  2142. ret -= ret - dd->cspec->iblnkerrsnap;
  2143. ret -= dd->cspec->iblnkerrdelta;
  2144. }
  2145. if (reg == QIBPORTCNTR_RXDROPPKT) /* add special cased count */
  2146. ret += dd->cspec->rxfc_unsupvl_errs;
  2147. done:
  2148. return ret;
  2149. }
  2150. /*
  2151. * Device counter names (not port-specific), one line per stat,
  2152. * single string. Used by utilities like ipathstats to print the stats
  2153. * in a way which works for different versions of drivers, without changing
  2154. * the utility. Names need to be 12 chars or less (w/o newline), for proper
  2155. * display by utility.
  2156. * Non-error counters are first.
  2157. * Start of "error" conters is indicated by a leading "E " on the first
  2158. * "error" counter, and doesn't count in label length.
  2159. * The EgrOvfl list needs to be last so we truncate them at the configured
  2160. * context count for the device.
  2161. * cntr6120indices contains the corresponding register indices.
  2162. */
  2163. static const char cntr6120names[] =
  2164. "Interrupts\n"
  2165. "HostBusStall\n"
  2166. "E RxTIDFull\n"
  2167. "RxTIDInvalid\n"
  2168. "Ctxt0EgrOvfl\n"
  2169. "Ctxt1EgrOvfl\n"
  2170. "Ctxt2EgrOvfl\n"
  2171. "Ctxt3EgrOvfl\n"
  2172. "Ctxt4EgrOvfl\n";
  2173. static const size_t cntr6120indices[] = {
  2174. cr_lbint,
  2175. cr_lbflowstall,
  2176. cr_errtidfull,
  2177. cr_errtidvalid,
  2178. cr_portovfl + 0,
  2179. cr_portovfl + 1,
  2180. cr_portovfl + 2,
  2181. cr_portovfl + 3,
  2182. cr_portovfl + 4,
  2183. };
  2184. /*
  2185. * same as cntr6120names and cntr6120indices, but for port-specific counters.
  2186. * portcntr6120indices is somewhat complicated by some registers needing
  2187. * adjustments of various kinds, and those are ORed with _PORT_VIRT_FLAG
  2188. */
  2189. static const char portcntr6120names[] =
  2190. "TxPkt\n"
  2191. "TxFlowPkt\n"
  2192. "TxWords\n"
  2193. "RxPkt\n"
  2194. "RxFlowPkt\n"
  2195. "RxWords\n"
  2196. "TxFlowStall\n"
  2197. "E IBStatusChng\n"
  2198. "IBLinkDown\n"
  2199. "IBLnkRecov\n"
  2200. "IBRxLinkErr\n"
  2201. "IBSymbolErr\n"
  2202. "RxLLIErr\n"
  2203. "RxBadFormat\n"
  2204. "RxBadLen\n"
  2205. "RxBufOvrfl\n"
  2206. "RxEBP\n"
  2207. "RxFlowCtlErr\n"
  2208. "RxICRCerr\n"
  2209. "RxLPCRCerr\n"
  2210. "RxVCRCerr\n"
  2211. "RxInvalLen\n"
  2212. "RxInvalPKey\n"
  2213. "RxPktDropped\n"
  2214. "TxBadLength\n"
  2215. "TxDropped\n"
  2216. "TxInvalLen\n"
  2217. "TxUnderrun\n"
  2218. "TxUnsupVL\n"
  2219. ;
  2220. #define _PORT_VIRT_FLAG 0x8000 /* "virtual", need adjustments */
  2221. static const size_t portcntr6120indices[] = {
  2222. QIBPORTCNTR_PKTSEND | _PORT_VIRT_FLAG,
  2223. cr_pktsendflow,
  2224. QIBPORTCNTR_WORDSEND | _PORT_VIRT_FLAG,
  2225. QIBPORTCNTR_PKTRCV | _PORT_VIRT_FLAG,
  2226. cr_pktrcvflowctrl,
  2227. QIBPORTCNTR_WORDRCV | _PORT_VIRT_FLAG,
  2228. QIBPORTCNTR_SENDSTALL | _PORT_VIRT_FLAG,
  2229. cr_ibstatuschange,
  2230. QIBPORTCNTR_IBLINKDOWN | _PORT_VIRT_FLAG,
  2231. QIBPORTCNTR_IBLINKERRRECOV | _PORT_VIRT_FLAG,
  2232. QIBPORTCNTR_ERRLINK | _PORT_VIRT_FLAG,
  2233. QIBPORTCNTR_IBSYMBOLERR | _PORT_VIRT_FLAG,
  2234. QIBPORTCNTR_LLI | _PORT_VIRT_FLAG,
  2235. QIBPORTCNTR_BADFORMAT | _PORT_VIRT_FLAG,
  2236. QIBPORTCNTR_ERR_RLEN | _PORT_VIRT_FLAG,
  2237. QIBPORTCNTR_RCVOVFL | _PORT_VIRT_FLAG,
  2238. QIBPORTCNTR_RCVEBP | _PORT_VIRT_FLAG,
  2239. cr_rcvflowctrl_err,
  2240. QIBPORTCNTR_ERRICRC | _PORT_VIRT_FLAG,
  2241. QIBPORTCNTR_ERRLPCRC | _PORT_VIRT_FLAG,
  2242. QIBPORTCNTR_ERRVCRC | _PORT_VIRT_FLAG,
  2243. QIBPORTCNTR_INVALIDRLEN | _PORT_VIRT_FLAG,
  2244. QIBPORTCNTR_ERRPKEY | _PORT_VIRT_FLAG,
  2245. QIBPORTCNTR_RXDROPPKT | _PORT_VIRT_FLAG,
  2246. cr_invalidslen,
  2247. cr_senddropped,
  2248. cr_errslen,
  2249. cr_sendunderrun,
  2250. cr_txunsupvl,
  2251. };
  2252. /* do all the setup to make the counter reads efficient later */
  2253. static void init_6120_cntrnames(struct qib_devdata *dd)
  2254. {
  2255. int i, j = 0;
  2256. char *s;
  2257. for (i = 0, s = (char *)cntr6120names; s && j <= dd->cfgctxts;
  2258. i++) {
  2259. /* we always have at least one counter before the egrovfl */
  2260. if (!j && !strncmp("Ctxt0EgrOvfl", s + 1, 12))
  2261. j = 1;
  2262. s = strchr(s + 1, '\n');
  2263. if (s && j)
  2264. j++;
  2265. }
  2266. dd->cspec->ncntrs = i;
  2267. if (!s)
  2268. /* full list; size is without terminating null */
  2269. dd->cspec->cntrnamelen = sizeof(cntr6120names) - 1;
  2270. else
  2271. dd->cspec->cntrnamelen = 1 + s - cntr6120names;
  2272. dd->cspec->cntrs = kmalloc(dd->cspec->ncntrs
  2273. * sizeof(u64), GFP_KERNEL);
  2274. if (!dd->cspec->cntrs)
  2275. qib_dev_err(dd, "Failed allocation for counters\n");
  2276. for (i = 0, s = (char *)portcntr6120names; s; i++)
  2277. s = strchr(s + 1, '\n');
  2278. dd->cspec->nportcntrs = i - 1;
  2279. dd->cspec->portcntrnamelen = sizeof(portcntr6120names) - 1;
  2280. dd->cspec->portcntrs = kmalloc(dd->cspec->nportcntrs
  2281. * sizeof(u64), GFP_KERNEL);
  2282. if (!dd->cspec->portcntrs)
  2283. qib_dev_err(dd, "Failed allocation for portcounters\n");
  2284. }
  2285. static u32 qib_read_6120cntrs(struct qib_devdata *dd, loff_t pos, char **namep,
  2286. u64 **cntrp)
  2287. {
  2288. u32 ret;
  2289. if (namep) {
  2290. ret = dd->cspec->cntrnamelen;
  2291. if (pos >= ret)
  2292. ret = 0; /* final read after getting everything */
  2293. else
  2294. *namep = (char *)cntr6120names;
  2295. } else {
  2296. u64 *cntr = dd->cspec->cntrs;
  2297. int i;
  2298. ret = dd->cspec->ncntrs * sizeof(u64);
  2299. if (!cntr || pos >= ret) {
  2300. /* everything read, or couldn't get memory */
  2301. ret = 0;
  2302. goto done;
  2303. }
  2304. if (pos >= ret) {
  2305. ret = 0; /* final read after getting everything */
  2306. goto done;
  2307. }
  2308. *cntrp = cntr;
  2309. for (i = 0; i < dd->cspec->ncntrs; i++)
  2310. *cntr++ = read_6120_creg32(dd, cntr6120indices[i]);
  2311. }
  2312. done:
  2313. return ret;
  2314. }
  2315. static u32 qib_read_6120portcntrs(struct qib_devdata *dd, loff_t pos, u32 port,
  2316. char **namep, u64 **cntrp)
  2317. {
  2318. u32 ret;
  2319. if (namep) {
  2320. ret = dd->cspec->portcntrnamelen;
  2321. if (pos >= ret)
  2322. ret = 0; /* final read after getting everything */
  2323. else
  2324. *namep = (char *)portcntr6120names;
  2325. } else {
  2326. u64 *cntr = dd->cspec->portcntrs;
  2327. struct qib_pportdata *ppd = &dd->pport[port];
  2328. int i;
  2329. ret = dd->cspec->nportcntrs * sizeof(u64);
  2330. if (!cntr || pos >= ret) {
  2331. /* everything read, or couldn't get memory */
  2332. ret = 0;
  2333. goto done;
  2334. }
  2335. *cntrp = cntr;
  2336. for (i = 0; i < dd->cspec->nportcntrs; i++) {
  2337. if (portcntr6120indices[i] & _PORT_VIRT_FLAG)
  2338. *cntr++ = qib_portcntr_6120(ppd,
  2339. portcntr6120indices[i] &
  2340. ~_PORT_VIRT_FLAG);
  2341. else
  2342. *cntr++ = read_6120_creg32(dd,
  2343. portcntr6120indices[i]);
  2344. }
  2345. }
  2346. done:
  2347. return ret;
  2348. }
  2349. static void qib_chk_6120_errormask(struct qib_devdata *dd)
  2350. {
  2351. static u32 fixed;
  2352. u32 ctrl;
  2353. unsigned long errormask;
  2354. unsigned long hwerrs;
  2355. if (!dd->cspec->errormask || !(dd->flags & QIB_INITTED))
  2356. return;
  2357. errormask = qib_read_kreg64(dd, kr_errmask);
  2358. if (errormask == dd->cspec->errormask)
  2359. return;
  2360. fixed++;
  2361. hwerrs = qib_read_kreg64(dd, kr_hwerrstatus);
  2362. ctrl = qib_read_kreg32(dd, kr_control);
  2363. qib_write_kreg(dd, kr_errmask,
  2364. dd->cspec->errormask);
  2365. if ((hwerrs & dd->cspec->hwerrmask) ||
  2366. (ctrl & QLOGIC_IB_C_FREEZEMODE)) {
  2367. qib_write_kreg(dd, kr_hwerrclear, 0ULL);
  2368. qib_write_kreg(dd, kr_errclear, 0ULL);
  2369. /* force re-interrupt of pending events, just in case */
  2370. qib_write_kreg(dd, kr_intclear, 0ULL);
  2371. qib_devinfo(dd->pcidev,
  2372. "errormask fixed(%u) %lx->%lx, ctrl %x hwerr %lx\n",
  2373. fixed, errormask, (unsigned long)dd->cspec->errormask,
  2374. ctrl, hwerrs);
  2375. }
  2376. }
  2377. /**
  2378. * qib_get_faststats - get word counters from chip before they overflow
  2379. * @opaque - contains a pointer to the qlogic_ib device qib_devdata
  2380. *
  2381. * This needs more work; in particular, decision on whether we really
  2382. * need traffic_wds done the way it is
  2383. * called from add_timer
  2384. */
  2385. static void qib_get_6120_faststats(unsigned long opaque)
  2386. {
  2387. struct qib_devdata *dd = (struct qib_devdata *) opaque;
  2388. struct qib_pportdata *ppd = dd->pport;
  2389. unsigned long flags;
  2390. u64 traffic_wds;
  2391. /*
  2392. * don't access the chip while running diags, or memory diags can
  2393. * fail
  2394. */
  2395. if (!(dd->flags & QIB_INITTED) || dd->diag_client)
  2396. /* but re-arm the timer, for diags case; won't hurt other */
  2397. goto done;
  2398. /*
  2399. * We now try to maintain an activity timer, based on traffic
  2400. * exceeding a threshold, so we need to check the word-counts
  2401. * even if they are 64-bit.
  2402. */
  2403. traffic_wds = qib_portcntr_6120(ppd, cr_wordsend) +
  2404. qib_portcntr_6120(ppd, cr_wordrcv);
  2405. spin_lock_irqsave(&dd->eep_st_lock, flags);
  2406. traffic_wds -= dd->traffic_wds;
  2407. dd->traffic_wds += traffic_wds;
  2408. spin_unlock_irqrestore(&dd->eep_st_lock, flags);
  2409. qib_chk_6120_errormask(dd);
  2410. done:
  2411. mod_timer(&dd->stats_timer, jiffies + HZ * ACTIVITY_TIMER);
  2412. }
  2413. /* no interrupt fallback for these chips */
  2414. static int qib_6120_nointr_fallback(struct qib_devdata *dd)
  2415. {
  2416. return 0;
  2417. }
  2418. /*
  2419. * reset the XGXS (between serdes and IBC). Slightly less intrusive
  2420. * than resetting the IBC or external link state, and useful in some
  2421. * cases to cause some retraining. To do this right, we reset IBC
  2422. * as well.
  2423. */
  2424. static void qib_6120_xgxs_reset(struct qib_pportdata *ppd)
  2425. {
  2426. u64 val, prev_val;
  2427. struct qib_devdata *dd = ppd->dd;
  2428. prev_val = qib_read_kreg64(dd, kr_xgxs_cfg);
  2429. val = prev_val | QLOGIC_IB_XGXS_RESET;
  2430. prev_val &= ~QLOGIC_IB_XGXS_RESET; /* be sure */
  2431. qib_write_kreg(dd, kr_control,
  2432. dd->control & ~QLOGIC_IB_C_LINKENABLE);
  2433. qib_write_kreg(dd, kr_xgxs_cfg, val);
  2434. qib_read_kreg32(dd, kr_scratch);
  2435. qib_write_kreg(dd, kr_xgxs_cfg, prev_val);
  2436. qib_write_kreg(dd, kr_control, dd->control);
  2437. }
  2438. static int qib_6120_get_ib_cfg(struct qib_pportdata *ppd, int which)
  2439. {
  2440. int ret;
  2441. switch (which) {
  2442. case QIB_IB_CFG_LWID:
  2443. ret = ppd->link_width_active;
  2444. break;
  2445. case QIB_IB_CFG_SPD:
  2446. ret = ppd->link_speed_active;
  2447. break;
  2448. case QIB_IB_CFG_LWID_ENB:
  2449. ret = ppd->link_width_enabled;
  2450. break;
  2451. case QIB_IB_CFG_SPD_ENB:
  2452. ret = ppd->link_speed_enabled;
  2453. break;
  2454. case QIB_IB_CFG_OP_VLS:
  2455. ret = ppd->vls_operational;
  2456. break;
  2457. case QIB_IB_CFG_VL_HIGH_CAP:
  2458. ret = 0;
  2459. break;
  2460. case QIB_IB_CFG_VL_LOW_CAP:
  2461. ret = 0;
  2462. break;
  2463. case QIB_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
  2464. ret = SYM_FIELD(ppd->dd->cspec->ibcctrl, IBCCtrl,
  2465. OverrunThreshold);
  2466. break;
  2467. case QIB_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
  2468. ret = SYM_FIELD(ppd->dd->cspec->ibcctrl, IBCCtrl,
  2469. PhyerrThreshold);
  2470. break;
  2471. case QIB_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
  2472. /* will only take effect when the link state changes */
  2473. ret = (ppd->dd->cspec->ibcctrl &
  2474. SYM_MASK(IBCCtrl, LinkDownDefaultState)) ?
  2475. IB_LINKINITCMD_SLEEP : IB_LINKINITCMD_POLL;
  2476. break;
  2477. case QIB_IB_CFG_HRTBT: /* Get Heartbeat off/enable/auto */
  2478. ret = 0; /* no heartbeat on this chip */
  2479. break;
  2480. case QIB_IB_CFG_PMA_TICKS:
  2481. ret = 250; /* 1 usec. */
  2482. break;
  2483. default:
  2484. ret = -EINVAL;
  2485. break;
  2486. }
  2487. return ret;
  2488. }
  2489. /*
  2490. * We assume range checking is already done, if needed.
  2491. */
  2492. static int qib_6120_set_ib_cfg(struct qib_pportdata *ppd, int which, u32 val)
  2493. {
  2494. struct qib_devdata *dd = ppd->dd;
  2495. int ret = 0;
  2496. u64 val64;
  2497. u16 lcmd, licmd;
  2498. switch (which) {
  2499. case QIB_IB_CFG_LWID_ENB:
  2500. ppd->link_width_enabled = val;
  2501. break;
  2502. case QIB_IB_CFG_SPD_ENB:
  2503. ppd->link_speed_enabled = val;
  2504. break;
  2505. case QIB_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
  2506. val64 = SYM_FIELD(dd->cspec->ibcctrl, IBCCtrl,
  2507. OverrunThreshold);
  2508. if (val64 != val) {
  2509. dd->cspec->ibcctrl &=
  2510. ~SYM_MASK(IBCCtrl, OverrunThreshold);
  2511. dd->cspec->ibcctrl |= (u64) val <<
  2512. SYM_LSB(IBCCtrl, OverrunThreshold);
  2513. qib_write_kreg(dd, kr_ibcctrl, dd->cspec->ibcctrl);
  2514. qib_write_kreg(dd, kr_scratch, 0);
  2515. }
  2516. break;
  2517. case QIB_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
  2518. val64 = SYM_FIELD(dd->cspec->ibcctrl, IBCCtrl,
  2519. PhyerrThreshold);
  2520. if (val64 != val) {
  2521. dd->cspec->ibcctrl &=
  2522. ~SYM_MASK(IBCCtrl, PhyerrThreshold);
  2523. dd->cspec->ibcctrl |= (u64) val <<
  2524. SYM_LSB(IBCCtrl, PhyerrThreshold);
  2525. qib_write_kreg(dd, kr_ibcctrl, dd->cspec->ibcctrl);
  2526. qib_write_kreg(dd, kr_scratch, 0);
  2527. }
  2528. break;
  2529. case QIB_IB_CFG_PKEYS: /* update pkeys */
  2530. val64 = (u64) ppd->pkeys[0] | ((u64) ppd->pkeys[1] << 16) |
  2531. ((u64) ppd->pkeys[2] << 32) |
  2532. ((u64) ppd->pkeys[3] << 48);
  2533. qib_write_kreg(dd, kr_partitionkey, val64);
  2534. break;
  2535. case QIB_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
  2536. /* will only take effect when the link state changes */
  2537. if (val == IB_LINKINITCMD_POLL)
  2538. dd->cspec->ibcctrl &=
  2539. ~SYM_MASK(IBCCtrl, LinkDownDefaultState);
  2540. else /* SLEEP */
  2541. dd->cspec->ibcctrl |=
  2542. SYM_MASK(IBCCtrl, LinkDownDefaultState);
  2543. qib_write_kreg(dd, kr_ibcctrl, dd->cspec->ibcctrl);
  2544. qib_write_kreg(dd, kr_scratch, 0);
  2545. break;
  2546. case QIB_IB_CFG_MTU: /* update the MTU in IBC */
  2547. /*
  2548. * Update our housekeeping variables, and set IBC max
  2549. * size, same as init code; max IBC is max we allow in
  2550. * buffer, less the qword pbc, plus 1 for ICRC, in dwords
  2551. * Set even if it's unchanged, print debug message only
  2552. * on changes.
  2553. */
  2554. val = (ppd->ibmaxlen >> 2) + 1;
  2555. dd->cspec->ibcctrl &= ~SYM_MASK(IBCCtrl, MaxPktLen);
  2556. dd->cspec->ibcctrl |= (u64)val <<
  2557. SYM_LSB(IBCCtrl, MaxPktLen);
  2558. qib_write_kreg(dd, kr_ibcctrl, dd->cspec->ibcctrl);
  2559. qib_write_kreg(dd, kr_scratch, 0);
  2560. break;
  2561. case QIB_IB_CFG_LSTATE: /* set the IB link state */
  2562. switch (val & 0xffff0000) {
  2563. case IB_LINKCMD_DOWN:
  2564. lcmd = QLOGIC_IB_IBCC_LINKCMD_DOWN;
  2565. if (!dd->cspec->ibdeltainprog) {
  2566. dd->cspec->ibdeltainprog = 1;
  2567. dd->cspec->ibsymsnap =
  2568. read_6120_creg32(dd, cr_ibsymbolerr);
  2569. dd->cspec->iblnkerrsnap =
  2570. read_6120_creg32(dd, cr_iblinkerrrecov);
  2571. }
  2572. break;
  2573. case IB_LINKCMD_ARMED:
  2574. lcmd = QLOGIC_IB_IBCC_LINKCMD_ARMED;
  2575. break;
  2576. case IB_LINKCMD_ACTIVE:
  2577. lcmd = QLOGIC_IB_IBCC_LINKCMD_ACTIVE;
  2578. break;
  2579. default:
  2580. ret = -EINVAL;
  2581. qib_dev_err(dd, "bad linkcmd req 0x%x\n", val >> 16);
  2582. goto bail;
  2583. }
  2584. switch (val & 0xffff) {
  2585. case IB_LINKINITCMD_NOP:
  2586. licmd = 0;
  2587. break;
  2588. case IB_LINKINITCMD_POLL:
  2589. licmd = QLOGIC_IB_IBCC_LINKINITCMD_POLL;
  2590. break;
  2591. case IB_LINKINITCMD_SLEEP:
  2592. licmd = QLOGIC_IB_IBCC_LINKINITCMD_SLEEP;
  2593. break;
  2594. case IB_LINKINITCMD_DISABLE:
  2595. licmd = QLOGIC_IB_IBCC_LINKINITCMD_DISABLE;
  2596. break;
  2597. default:
  2598. ret = -EINVAL;
  2599. qib_dev_err(dd, "bad linkinitcmd req 0x%x\n",
  2600. val & 0xffff);
  2601. goto bail;
  2602. }
  2603. qib_set_ib_6120_lstate(ppd, lcmd, licmd);
  2604. goto bail;
  2605. case QIB_IB_CFG_HRTBT:
  2606. ret = -EINVAL;
  2607. break;
  2608. default:
  2609. ret = -EINVAL;
  2610. }
  2611. bail:
  2612. return ret;
  2613. }
  2614. static int qib_6120_set_loopback(struct qib_pportdata *ppd, const char *what)
  2615. {
  2616. int ret = 0;
  2617. if (!strncmp(what, "ibc", 3)) {
  2618. ppd->dd->cspec->ibcctrl |= SYM_MASK(IBCCtrl, Loopback);
  2619. qib_devinfo(ppd->dd->pcidev, "Enabling IB%u:%u IBC loopback\n",
  2620. ppd->dd->unit, ppd->port);
  2621. } else if (!strncmp(what, "off", 3)) {
  2622. ppd->dd->cspec->ibcctrl &= ~SYM_MASK(IBCCtrl, Loopback);
  2623. qib_devinfo(ppd->dd->pcidev, "Disabling IB%u:%u IBC loopback "
  2624. "(normal)\n", ppd->dd->unit, ppd->port);
  2625. } else
  2626. ret = -EINVAL;
  2627. if (!ret) {
  2628. qib_write_kreg(ppd->dd, kr_ibcctrl, ppd->dd->cspec->ibcctrl);
  2629. qib_write_kreg(ppd->dd, kr_scratch, 0);
  2630. }
  2631. return ret;
  2632. }
  2633. static void pma_6120_timer(unsigned long data)
  2634. {
  2635. struct qib_pportdata *ppd = (struct qib_pportdata *)data;
  2636. struct qib_chip_specific *cs = ppd->dd->cspec;
  2637. struct qib_ibport *ibp = &ppd->ibport_data;
  2638. unsigned long flags;
  2639. spin_lock_irqsave(&ibp->lock, flags);
  2640. if (cs->pma_sample_status == IB_PMA_SAMPLE_STATUS_STARTED) {
  2641. cs->pma_sample_status = IB_PMA_SAMPLE_STATUS_RUNNING;
  2642. qib_snapshot_counters(ppd, &cs->sword, &cs->rword,
  2643. &cs->spkts, &cs->rpkts, &cs->xmit_wait);
  2644. mod_timer(&cs->pma_timer,
  2645. jiffies + usecs_to_jiffies(ibp->pma_sample_interval));
  2646. } else if (cs->pma_sample_status == IB_PMA_SAMPLE_STATUS_RUNNING) {
  2647. u64 ta, tb, tc, td, te;
  2648. cs->pma_sample_status = IB_PMA_SAMPLE_STATUS_DONE;
  2649. qib_snapshot_counters(ppd, &ta, &tb, &tc, &td, &te);
  2650. cs->sword = ta - cs->sword;
  2651. cs->rword = tb - cs->rword;
  2652. cs->spkts = tc - cs->spkts;
  2653. cs->rpkts = td - cs->rpkts;
  2654. cs->xmit_wait = te - cs->xmit_wait;
  2655. }
  2656. spin_unlock_irqrestore(&ibp->lock, flags);
  2657. }
  2658. /*
  2659. * Note that the caller has the ibp->lock held.
  2660. */
  2661. static void qib_set_cntr_6120_sample(struct qib_pportdata *ppd, u32 intv,
  2662. u32 start)
  2663. {
  2664. struct qib_chip_specific *cs = ppd->dd->cspec;
  2665. if (start && intv) {
  2666. cs->pma_sample_status = IB_PMA_SAMPLE_STATUS_STARTED;
  2667. mod_timer(&cs->pma_timer, jiffies + usecs_to_jiffies(start));
  2668. } else if (intv) {
  2669. cs->pma_sample_status = IB_PMA_SAMPLE_STATUS_RUNNING;
  2670. qib_snapshot_counters(ppd, &cs->sword, &cs->rword,
  2671. &cs->spkts, &cs->rpkts, &cs->xmit_wait);
  2672. mod_timer(&cs->pma_timer, jiffies + usecs_to_jiffies(intv));
  2673. } else {
  2674. cs->pma_sample_status = IB_PMA_SAMPLE_STATUS_DONE;
  2675. cs->sword = 0;
  2676. cs->rword = 0;
  2677. cs->spkts = 0;
  2678. cs->rpkts = 0;
  2679. cs->xmit_wait = 0;
  2680. }
  2681. }
  2682. static u32 qib_6120_iblink_state(u64 ibcs)
  2683. {
  2684. u32 state = (u32)SYM_FIELD(ibcs, IBCStatus, LinkState);
  2685. switch (state) {
  2686. case IB_6120_L_STATE_INIT:
  2687. state = IB_PORT_INIT;
  2688. break;
  2689. case IB_6120_L_STATE_ARM:
  2690. state = IB_PORT_ARMED;
  2691. break;
  2692. case IB_6120_L_STATE_ACTIVE:
  2693. /* fall through */
  2694. case IB_6120_L_STATE_ACT_DEFER:
  2695. state = IB_PORT_ACTIVE;
  2696. break;
  2697. default: /* fall through */
  2698. case IB_6120_L_STATE_DOWN:
  2699. state = IB_PORT_DOWN;
  2700. break;
  2701. }
  2702. return state;
  2703. }
  2704. /* returns the IBTA port state, rather than the IBC link training state */
  2705. static u8 qib_6120_phys_portstate(u64 ibcs)
  2706. {
  2707. u8 state = (u8)SYM_FIELD(ibcs, IBCStatus, LinkTrainingState);
  2708. return qib_6120_physportstate[state];
  2709. }
  2710. static int qib_6120_ib_updown(struct qib_pportdata *ppd, int ibup, u64 ibcs)
  2711. {
  2712. unsigned long flags;
  2713. spin_lock_irqsave(&ppd->lflags_lock, flags);
  2714. ppd->lflags &= ~QIBL_IB_FORCE_NOTIFY;
  2715. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  2716. if (ibup) {
  2717. if (ppd->dd->cspec->ibdeltainprog) {
  2718. ppd->dd->cspec->ibdeltainprog = 0;
  2719. ppd->dd->cspec->ibsymdelta +=
  2720. read_6120_creg32(ppd->dd, cr_ibsymbolerr) -
  2721. ppd->dd->cspec->ibsymsnap;
  2722. ppd->dd->cspec->iblnkerrdelta +=
  2723. read_6120_creg32(ppd->dd, cr_iblinkerrrecov) -
  2724. ppd->dd->cspec->iblnkerrsnap;
  2725. }
  2726. qib_hol_init(ppd);
  2727. } else {
  2728. ppd->dd->cspec->lli_counter = 0;
  2729. if (!ppd->dd->cspec->ibdeltainprog) {
  2730. ppd->dd->cspec->ibdeltainprog = 1;
  2731. ppd->dd->cspec->ibsymsnap =
  2732. read_6120_creg32(ppd->dd, cr_ibsymbolerr);
  2733. ppd->dd->cspec->iblnkerrsnap =
  2734. read_6120_creg32(ppd->dd, cr_iblinkerrrecov);
  2735. }
  2736. qib_hol_down(ppd);
  2737. }
  2738. qib_6120_setup_setextled(ppd, ibup);
  2739. return 0;
  2740. }
  2741. /* Does read/modify/write to appropriate registers to
  2742. * set output and direction bits selected by mask.
  2743. * these are in their canonical postions (e.g. lsb of
  2744. * dir will end up in D48 of extctrl on existing chips).
  2745. * returns contents of GP Inputs.
  2746. */
  2747. static int gpio_6120_mod(struct qib_devdata *dd, u32 out, u32 dir, u32 mask)
  2748. {
  2749. u64 read_val, new_out;
  2750. unsigned long flags;
  2751. if (mask) {
  2752. /* some bits being written, lock access to GPIO */
  2753. dir &= mask;
  2754. out &= mask;
  2755. spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
  2756. dd->cspec->extctrl &= ~((u64)mask << SYM_LSB(EXTCtrl, GPIOOe));
  2757. dd->cspec->extctrl |= ((u64) dir << SYM_LSB(EXTCtrl, GPIOOe));
  2758. new_out = (dd->cspec->gpio_out & ~mask) | out;
  2759. qib_write_kreg(dd, kr_extctrl, dd->cspec->extctrl);
  2760. qib_write_kreg(dd, kr_gpio_out, new_out);
  2761. dd->cspec->gpio_out = new_out;
  2762. spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
  2763. }
  2764. /*
  2765. * It is unlikely that a read at this time would get valid
  2766. * data on a pin whose direction line was set in the same
  2767. * call to this function. We include the read here because
  2768. * that allows us to potentially combine a change on one pin with
  2769. * a read on another, and because the old code did something like
  2770. * this.
  2771. */
  2772. read_val = qib_read_kreg64(dd, kr_extstatus);
  2773. return SYM_FIELD(read_val, EXTStatus, GPIOIn);
  2774. }
  2775. /*
  2776. * Read fundamental info we need to use the chip. These are
  2777. * the registers that describe chip capabilities, and are
  2778. * saved in shadow registers.
  2779. */
  2780. static void get_6120_chip_params(struct qib_devdata *dd)
  2781. {
  2782. u64 val;
  2783. u32 piobufs;
  2784. int mtu;
  2785. dd->uregbase = qib_read_kreg32(dd, kr_userregbase);
  2786. dd->rcvtidcnt = qib_read_kreg32(dd, kr_rcvtidcnt);
  2787. dd->rcvtidbase = qib_read_kreg32(dd, kr_rcvtidbase);
  2788. dd->rcvegrbase = qib_read_kreg32(dd, kr_rcvegrbase);
  2789. dd->palign = qib_read_kreg32(dd, kr_palign);
  2790. dd->piobufbase = qib_read_kreg64(dd, kr_sendpiobufbase);
  2791. dd->pio2k_bufbase = dd->piobufbase & 0xffffffff;
  2792. dd->rcvhdrcnt = qib_read_kreg32(dd, kr_rcvegrcnt);
  2793. val = qib_read_kreg64(dd, kr_sendpiosize);
  2794. dd->piosize2k = val & ~0U;
  2795. dd->piosize4k = val >> 32;
  2796. mtu = ib_mtu_enum_to_int(qib_ibmtu);
  2797. if (mtu == -1)
  2798. mtu = QIB_DEFAULT_MTU;
  2799. dd->pport->ibmtu = (u32)mtu;
  2800. val = qib_read_kreg64(dd, kr_sendpiobufcnt);
  2801. dd->piobcnt2k = val & ~0U;
  2802. dd->piobcnt4k = val >> 32;
  2803. /* these may be adjusted in init_chip_wc_pat() */
  2804. dd->pio2kbase = (u32 __iomem *)
  2805. (((char __iomem *)dd->kregbase) + dd->pio2k_bufbase);
  2806. if (dd->piobcnt4k) {
  2807. dd->pio4kbase = (u32 __iomem *)
  2808. (((char __iomem *) dd->kregbase) +
  2809. (dd->piobufbase >> 32));
  2810. /*
  2811. * 4K buffers take 2 pages; we use roundup just to be
  2812. * paranoid; we calculate it once here, rather than on
  2813. * ever buf allocate
  2814. */
  2815. dd->align4k = ALIGN(dd->piosize4k, dd->palign);
  2816. }
  2817. piobufs = dd->piobcnt4k + dd->piobcnt2k;
  2818. dd->pioavregs = ALIGN(piobufs, sizeof(u64) * BITS_PER_BYTE / 2) /
  2819. (sizeof(u64) * BITS_PER_BYTE / 2);
  2820. }
  2821. /*
  2822. * The chip base addresses in cspec and cpspec have to be set
  2823. * after possible init_chip_wc_pat(), rather than in
  2824. * get_6120_chip_params(), so split out as separate function
  2825. */
  2826. static void set_6120_baseaddrs(struct qib_devdata *dd)
  2827. {
  2828. u32 cregbase;
  2829. cregbase = qib_read_kreg32(dd, kr_counterregbase);
  2830. dd->cspec->cregbase = (u64 __iomem *)
  2831. ((char __iomem *) dd->kregbase + cregbase);
  2832. dd->egrtidbase = (u64 __iomem *)
  2833. ((char __iomem *) dd->kregbase + dd->rcvegrbase);
  2834. }
  2835. /*
  2836. * Write the final few registers that depend on some of the
  2837. * init setup. Done late in init, just before bringing up
  2838. * the serdes.
  2839. */
  2840. static int qib_late_6120_initreg(struct qib_devdata *dd)
  2841. {
  2842. int ret = 0;
  2843. u64 val;
  2844. qib_write_kreg(dd, kr_rcvhdrentsize, dd->rcvhdrentsize);
  2845. qib_write_kreg(dd, kr_rcvhdrsize, dd->rcvhdrsize);
  2846. qib_write_kreg(dd, kr_rcvhdrcnt, dd->rcvhdrcnt);
  2847. qib_write_kreg(dd, kr_sendpioavailaddr, dd->pioavailregs_phys);
  2848. val = qib_read_kreg64(dd, kr_sendpioavailaddr);
  2849. if (val != dd->pioavailregs_phys) {
  2850. qib_dev_err(dd, "Catastrophic software error, "
  2851. "SendPIOAvailAddr written as %lx, "
  2852. "read back as %llx\n",
  2853. (unsigned long) dd->pioavailregs_phys,
  2854. (unsigned long long) val);
  2855. ret = -EINVAL;
  2856. }
  2857. return ret;
  2858. }
  2859. static int init_6120_variables(struct qib_devdata *dd)
  2860. {
  2861. int ret = 0;
  2862. struct qib_pportdata *ppd;
  2863. u32 sbufs;
  2864. ppd = (struct qib_pportdata *)(dd + 1);
  2865. dd->pport = ppd;
  2866. dd->num_pports = 1;
  2867. dd->cspec = (struct qib_chip_specific *)(ppd + dd->num_pports);
  2868. ppd->cpspec = NULL; /* not used in this chip */
  2869. spin_lock_init(&dd->cspec->kernel_tid_lock);
  2870. spin_lock_init(&dd->cspec->user_tid_lock);
  2871. spin_lock_init(&dd->cspec->rcvmod_lock);
  2872. spin_lock_init(&dd->cspec->gpio_lock);
  2873. /* we haven't yet set QIB_PRESENT, so use read directly */
  2874. dd->revision = readq(&dd->kregbase[kr_revision]);
  2875. if ((dd->revision & 0xffffffffU) == 0xffffffffU) {
  2876. qib_dev_err(dd, "Revision register read failure, "
  2877. "giving up initialization\n");
  2878. ret = -ENODEV;
  2879. goto bail;
  2880. }
  2881. dd->flags |= QIB_PRESENT; /* now register routines work */
  2882. dd->majrev = (u8) SYM_FIELD(dd->revision, Revision_R,
  2883. ChipRevMajor);
  2884. dd->minrev = (u8) SYM_FIELD(dd->revision, Revision_R,
  2885. ChipRevMinor);
  2886. get_6120_chip_params(dd);
  2887. pe_boardname(dd); /* fill in boardname */
  2888. /*
  2889. * GPIO bits for TWSI data and clock,
  2890. * used for serial EEPROM.
  2891. */
  2892. dd->gpio_sda_num = _QIB_GPIO_SDA_NUM;
  2893. dd->gpio_scl_num = _QIB_GPIO_SCL_NUM;
  2894. dd->twsi_eeprom_dev = QIB_TWSI_NO_DEV;
  2895. if (qib_unordered_wc())
  2896. dd->flags |= QIB_PIO_FLUSH_WC;
  2897. /*
  2898. * EEPROM error log 0 is TXE Parity errors. 1 is RXE Parity.
  2899. * 2 is Some Misc, 3 is reserved for future.
  2900. */
  2901. dd->eep_st_masks[0].hwerrs_to_log = HWE_MASK(TXEMemParityErr);
  2902. /* Ignore errors in PIO/PBC on systems with unordered write-combining */
  2903. if (qib_unordered_wc())
  2904. dd->eep_st_masks[0].hwerrs_to_log &= ~TXE_PIO_PARITY;
  2905. dd->eep_st_masks[1].hwerrs_to_log = HWE_MASK(RXEMemParityErr);
  2906. dd->eep_st_masks[2].errs_to_log = ERR_MASK(ResetNegated);
  2907. qib_init_pportdata(ppd, dd, 0, 1);
  2908. ppd->link_width_supported = IB_WIDTH_1X | IB_WIDTH_4X;
  2909. ppd->link_speed_supported = QIB_IB_SDR;
  2910. ppd->link_width_enabled = IB_WIDTH_4X;
  2911. ppd->link_speed_enabled = ppd->link_speed_supported;
  2912. /* these can't change for this chip, so set once */
  2913. ppd->link_width_active = ppd->link_width_enabled;
  2914. ppd->link_speed_active = ppd->link_speed_enabled;
  2915. ppd->vls_supported = IB_VL_VL0;
  2916. ppd->vls_operational = ppd->vls_supported;
  2917. dd->rcvhdrentsize = QIB_RCVHDR_ENTSIZE;
  2918. dd->rcvhdrsize = QIB_DFLT_RCVHDRSIZE;
  2919. dd->rhf_offset = 0;
  2920. /* we always allocate at least 2048 bytes for eager buffers */
  2921. ret = ib_mtu_enum_to_int(qib_ibmtu);
  2922. dd->rcvegrbufsize = ret != -1 ? max(ret, 2048) : QIB_DEFAULT_MTU;
  2923. BUG_ON(!is_power_of_2(dd->rcvegrbufsize));
  2924. dd->rcvegrbufsize_shift = ilog2(dd->rcvegrbufsize);
  2925. qib_6120_tidtemplate(dd);
  2926. /*
  2927. * We can request a receive interrupt for 1 or
  2928. * more packets from current offset. For now, we set this
  2929. * up for a single packet.
  2930. */
  2931. dd->rhdrhead_intr_off = 1ULL << 32;
  2932. /* setup the stats timer; the add_timer is done at end of init */
  2933. init_timer(&dd->stats_timer);
  2934. dd->stats_timer.function = qib_get_6120_faststats;
  2935. dd->stats_timer.data = (unsigned long) dd;
  2936. init_timer(&dd->cspec->pma_timer);
  2937. dd->cspec->pma_timer.function = pma_6120_timer;
  2938. dd->cspec->pma_timer.data = (unsigned long) ppd;
  2939. dd->ureg_align = qib_read_kreg32(dd, kr_palign);
  2940. dd->piosize2kmax_dwords = dd->piosize2k >> 2;
  2941. qib_6120_config_ctxts(dd);
  2942. qib_set_ctxtcnt(dd);
  2943. if (qib_wc_pat) {
  2944. ret = init_chip_wc_pat(dd, 0);
  2945. if (ret)
  2946. goto bail;
  2947. }
  2948. set_6120_baseaddrs(dd); /* set chip access pointers now */
  2949. ret = 0;
  2950. if (qib_mini_init)
  2951. goto bail;
  2952. qib_num_cfg_vls = 1; /* if any 6120's, only one VL */
  2953. ret = qib_create_ctxts(dd);
  2954. init_6120_cntrnames(dd);
  2955. /* use all of 4KB buffers for the kernel, otherwise 16 */
  2956. sbufs = dd->piobcnt4k ? dd->piobcnt4k : 16;
  2957. dd->lastctxt_piobuf = dd->piobcnt2k + dd->piobcnt4k - sbufs;
  2958. dd->pbufsctxt = dd->lastctxt_piobuf /
  2959. (dd->cfgctxts - dd->first_user_ctxt);
  2960. if (ret)
  2961. goto bail;
  2962. bail:
  2963. return ret;
  2964. }
  2965. /*
  2966. * For this chip, we want to use the same buffer every time
  2967. * when we are trying to bring the link up (they are always VL15
  2968. * packets). At that link state the packet should always go out immediately
  2969. * (or at least be discarded at the tx interface if the link is down).
  2970. * If it doesn't, and the buffer isn't available, that means some other
  2971. * sender has gotten ahead of us, and is preventing our packet from going
  2972. * out. In that case, we flush all packets, and try again. If that still
  2973. * fails, we fail the request, and hope things work the next time around.
  2974. *
  2975. * We don't need very complicated heuristics on whether the packet had
  2976. * time to go out or not, since even at SDR 1X, it goes out in very short
  2977. * time periods, covered by the chip reads done here and as part of the
  2978. * flush.
  2979. */
  2980. static u32 __iomem *get_6120_link_buf(struct qib_pportdata *ppd, u32 *bnum)
  2981. {
  2982. u32 __iomem *buf;
  2983. u32 lbuf = ppd->dd->piobcnt2k + ppd->dd->piobcnt4k - 1;
  2984. /*
  2985. * always blip to get avail list updated, since it's almost
  2986. * always needed, and is fairly cheap.
  2987. */
  2988. sendctrl_6120_mod(ppd->dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
  2989. qib_read_kreg64(ppd->dd, kr_scratch); /* extra chip flush */
  2990. buf = qib_getsendbuf_range(ppd->dd, bnum, lbuf, lbuf);
  2991. if (buf)
  2992. goto done;
  2993. sendctrl_6120_mod(ppd, QIB_SENDCTRL_DISARM_ALL | QIB_SENDCTRL_FLUSH |
  2994. QIB_SENDCTRL_AVAIL_BLIP);
  2995. ppd->dd->upd_pio_shadow = 1; /* update our idea of what's busy */
  2996. qib_read_kreg64(ppd->dd, kr_scratch); /* extra chip flush */
  2997. buf = qib_getsendbuf_range(ppd->dd, bnum, lbuf, lbuf);
  2998. done:
  2999. return buf;
  3000. }
  3001. static u32 __iomem *qib_6120_getsendbuf(struct qib_pportdata *ppd, u64 pbc,
  3002. u32 *pbufnum)
  3003. {
  3004. u32 first, last, plen = pbc & QIB_PBC_LENGTH_MASK;
  3005. struct qib_devdata *dd = ppd->dd;
  3006. u32 __iomem *buf;
  3007. if (((pbc >> 32) & PBC_6120_VL15_SEND_CTRL) &&
  3008. !(ppd->lflags & (QIBL_IB_AUTONEG_INPROG | QIBL_LINKACTIVE)))
  3009. buf = get_6120_link_buf(ppd, pbufnum);
  3010. else {
  3011. if ((plen + 1) > dd->piosize2kmax_dwords)
  3012. first = dd->piobcnt2k;
  3013. else
  3014. first = 0;
  3015. /* try 4k if all 2k busy, so same last for both sizes */
  3016. last = dd->piobcnt2k + dd->piobcnt4k - 1;
  3017. buf = qib_getsendbuf_range(dd, pbufnum, first, last);
  3018. }
  3019. return buf;
  3020. }
  3021. static int init_sdma_6120_regs(struct qib_pportdata *ppd)
  3022. {
  3023. return -ENODEV;
  3024. }
  3025. static u16 qib_sdma_6120_gethead(struct qib_pportdata *ppd)
  3026. {
  3027. return 0;
  3028. }
  3029. static int qib_sdma_6120_busy(struct qib_pportdata *ppd)
  3030. {
  3031. return 0;
  3032. }
  3033. static void qib_sdma_update_6120_tail(struct qib_pportdata *ppd, u16 tail)
  3034. {
  3035. }
  3036. static void qib_6120_sdma_sendctrl(struct qib_pportdata *ppd, unsigned op)
  3037. {
  3038. }
  3039. static void qib_sdma_set_6120_desc_cnt(struct qib_pportdata *ppd, unsigned cnt)
  3040. {
  3041. }
  3042. /*
  3043. * the pbc doesn't need a VL15 indicator, but we need it for link_buf.
  3044. * The chip ignores the bit if set.
  3045. */
  3046. static u32 qib_6120_setpbc_control(struct qib_pportdata *ppd, u32 plen,
  3047. u8 srate, u8 vl)
  3048. {
  3049. return vl == 15 ? PBC_6120_VL15_SEND_CTRL : 0;
  3050. }
  3051. static void qib_6120_initvl15_bufs(struct qib_devdata *dd)
  3052. {
  3053. }
  3054. static void qib_6120_init_ctxt(struct qib_ctxtdata *rcd)
  3055. {
  3056. rcd->rcvegrcnt = rcd->dd->rcvhdrcnt;
  3057. rcd->rcvegr_tid_base = rcd->ctxt * rcd->rcvegrcnt;
  3058. }
  3059. static void qib_6120_txchk_change(struct qib_devdata *dd, u32 start,
  3060. u32 len, u32 avail, struct qib_ctxtdata *rcd)
  3061. {
  3062. }
  3063. static void writescratch(struct qib_devdata *dd, u32 val)
  3064. {
  3065. (void) qib_write_kreg(dd, kr_scratch, val);
  3066. }
  3067. static int qib_6120_tempsense_rd(struct qib_devdata *dd, int regnum)
  3068. {
  3069. return -ENXIO;
  3070. }
  3071. /* Dummy function, as 6120 boards never disable EEPROM Write */
  3072. static int qib_6120_eeprom_wen(struct qib_devdata *dd, int wen)
  3073. {
  3074. return 1;
  3075. }
  3076. /**
  3077. * qib_init_iba6120_funcs - set up the chip-specific function pointers
  3078. * @pdev: pci_dev of the qlogic_ib device
  3079. * @ent: pci_device_id matching this chip
  3080. *
  3081. * This is global, and is called directly at init to set up the
  3082. * chip-specific function pointers for later use.
  3083. *
  3084. * It also allocates/partially-inits the qib_devdata struct for
  3085. * this device.
  3086. */
  3087. struct qib_devdata *qib_init_iba6120_funcs(struct pci_dev *pdev,
  3088. const struct pci_device_id *ent)
  3089. {
  3090. struct qib_devdata *dd;
  3091. int ret;
  3092. dd = qib_alloc_devdata(pdev, sizeof(struct qib_pportdata) +
  3093. sizeof(struct qib_chip_specific));
  3094. if (IS_ERR(dd))
  3095. goto bail;
  3096. dd->f_bringup_serdes = qib_6120_bringup_serdes;
  3097. dd->f_cleanup = qib_6120_setup_cleanup;
  3098. dd->f_clear_tids = qib_6120_clear_tids;
  3099. dd->f_free_irq = qib_6120_free_irq;
  3100. dd->f_get_base_info = qib_6120_get_base_info;
  3101. dd->f_get_msgheader = qib_6120_get_msgheader;
  3102. dd->f_getsendbuf = qib_6120_getsendbuf;
  3103. dd->f_gpio_mod = gpio_6120_mod;
  3104. dd->f_eeprom_wen = qib_6120_eeprom_wen;
  3105. dd->f_hdrqempty = qib_6120_hdrqempty;
  3106. dd->f_ib_updown = qib_6120_ib_updown;
  3107. dd->f_init_ctxt = qib_6120_init_ctxt;
  3108. dd->f_initvl15_bufs = qib_6120_initvl15_bufs;
  3109. dd->f_intr_fallback = qib_6120_nointr_fallback;
  3110. dd->f_late_initreg = qib_late_6120_initreg;
  3111. dd->f_setpbc_control = qib_6120_setpbc_control;
  3112. dd->f_portcntr = qib_portcntr_6120;
  3113. dd->f_put_tid = (dd->minrev >= 2) ?
  3114. qib_6120_put_tid_2 :
  3115. qib_6120_put_tid;
  3116. dd->f_quiet_serdes = qib_6120_quiet_serdes;
  3117. dd->f_rcvctrl = rcvctrl_6120_mod;
  3118. dd->f_read_cntrs = qib_read_6120cntrs;
  3119. dd->f_read_portcntrs = qib_read_6120portcntrs;
  3120. dd->f_reset = qib_6120_setup_reset;
  3121. dd->f_init_sdma_regs = init_sdma_6120_regs;
  3122. dd->f_sdma_busy = qib_sdma_6120_busy;
  3123. dd->f_sdma_gethead = qib_sdma_6120_gethead;
  3124. dd->f_sdma_sendctrl = qib_6120_sdma_sendctrl;
  3125. dd->f_sdma_set_desc_cnt = qib_sdma_set_6120_desc_cnt;
  3126. dd->f_sdma_update_tail = qib_sdma_update_6120_tail;
  3127. dd->f_sendctrl = sendctrl_6120_mod;
  3128. dd->f_set_armlaunch = qib_set_6120_armlaunch;
  3129. dd->f_set_cntr_sample = qib_set_cntr_6120_sample;
  3130. dd->f_iblink_state = qib_6120_iblink_state;
  3131. dd->f_ibphys_portstate = qib_6120_phys_portstate;
  3132. dd->f_get_ib_cfg = qib_6120_get_ib_cfg;
  3133. dd->f_set_ib_cfg = qib_6120_set_ib_cfg;
  3134. dd->f_set_ib_loopback = qib_6120_set_loopback;
  3135. dd->f_set_intr_state = qib_6120_set_intr_state;
  3136. dd->f_setextled = qib_6120_setup_setextled;
  3137. dd->f_txchk_change = qib_6120_txchk_change;
  3138. dd->f_update_usrhead = qib_update_6120_usrhead;
  3139. dd->f_wantpiobuf_intr = qib_wantpiobuf_6120_intr;
  3140. dd->f_xgxs_reset = qib_6120_xgxs_reset;
  3141. dd->f_writescratch = writescratch;
  3142. dd->f_tempsense_rd = qib_6120_tempsense_rd;
  3143. /*
  3144. * Do remaining pcie setup and save pcie values in dd.
  3145. * Any error printing is already done by the init code.
  3146. * On return, we have the chip mapped and accessible,
  3147. * but chip registers are not set up until start of
  3148. * init_6120_variables.
  3149. */
  3150. ret = qib_pcie_ddinit(dd, pdev, ent);
  3151. if (ret < 0)
  3152. goto bail_free;
  3153. /* initialize chip-specific variables */
  3154. ret = init_6120_variables(dd);
  3155. if (ret)
  3156. goto bail_cleanup;
  3157. if (qib_mini_init)
  3158. goto bail;
  3159. if (qib_pcie_params(dd, 8, NULL, NULL))
  3160. qib_dev_err(dd, "Failed to setup PCIe or interrupts; "
  3161. "continuing anyway\n");
  3162. dd->cspec->irq = pdev->irq; /* save IRQ */
  3163. /* clear diagctrl register, in case diags were running and crashed */
  3164. qib_write_kreg(dd, kr_hwdiagctrl, 0);
  3165. if (qib_read_kreg64(dd, kr_hwerrstatus) &
  3166. QLOGIC_IB_HWE_SERDESPLLFAILED)
  3167. qib_write_kreg(dd, kr_hwerrclear,
  3168. QLOGIC_IB_HWE_SERDESPLLFAILED);
  3169. /* setup interrupt handler (interrupt type handled above) */
  3170. qib_setup_6120_interrupt(dd);
  3171. /* Note that qpn_mask is set by qib_6120_config_ctxts() first */
  3172. qib_6120_init_hwerrors(dd);
  3173. goto bail;
  3174. bail_cleanup:
  3175. qib_pcie_ddcleanup(dd);
  3176. bail_free:
  3177. qib_free_devdata(dd);
  3178. dd = ERR_PTR(ret);
  3179. bail:
  3180. return dd;
  3181. }