qib_iba6120.c 109 KB

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