qib_iba6120.c 108 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543
  1. /*
  2. * Copyright (c) 2013 - 2017 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. u32 cntrnamelen;
  233. u32 portcntrnamelen;
  234. u32 ncntrs;
  235. u32 nportcntrs;
  236. /* used with gpio interrupts to implement IB counters */
  237. u32 rxfc_unsupvl_errs;
  238. u32 overrun_thresh_errs;
  239. /*
  240. * these count only cases where _successive_ LocalLinkIntegrity
  241. * errors were seen in the receive headers of IB standard packets
  242. */
  243. u32 lli_errs;
  244. u32 lli_counter;
  245. u64 lli_thresh;
  246. u64 sword; /* total dwords sent (sample result) */
  247. u64 rword; /* total dwords received (sample result) */
  248. u64 spkts; /* total packets sent (sample result) */
  249. u64 rpkts; /* total packets received (sample result) */
  250. u64 xmit_wait; /* # of ticks no data sent (sample result) */
  251. struct timer_list pma_timer;
  252. struct qib_pportdata *ppd;
  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 overwritten */
  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. hwerrs = qib_read_kreg64(dd, kr_hwerrstatus);
  682. if (!hwerrs)
  683. return;
  684. if (hwerrs == ~0ULL) {
  685. qib_dev_err(dd,
  686. "Read of hardware error status failed (all bits set); ignoring\n");
  687. return;
  688. }
  689. qib_stats.sps_hwerrs++;
  690. /* Always clear the error status register, except MEMBISTFAIL,
  691. * regardless of whether we continue or stop using the chip.
  692. * We want that set so we know it failed, even across driver reload.
  693. * We'll still ignore it in the hwerrmask. We do this partly for
  694. * diagnostics, but also for support */
  695. qib_write_kreg(dd, kr_hwerrclear,
  696. hwerrs & ~HWE_MASK(PowerOnBISTFailed));
  697. hwerrs &= dd->cspec->hwerrmask;
  698. /*
  699. * Make sure we get this much out, unless told to be quiet,
  700. * or it's occurred within the last 5 seconds.
  701. */
  702. if (hwerrs & ~(TXE_PIO_PARITY | RXEMEMPARITYERR_EAGERTID))
  703. qib_devinfo(dd->pcidev,
  704. "Hardware error: hwerr=0x%llx (cleared)\n",
  705. (unsigned long long) hwerrs);
  706. if (hwerrs & ~IB_HWE_BITSEXTANT)
  707. qib_dev_err(dd,
  708. "hwerror interrupt with unknown errors %llx set\n",
  709. (unsigned long long)(hwerrs & ~IB_HWE_BITSEXTANT));
  710. ctrl = qib_read_kreg32(dd, kr_control);
  711. if ((ctrl & QLOGIC_IB_C_FREEZEMODE) && !dd->diag_client) {
  712. /*
  713. * Parity errors in send memory are recoverable,
  714. * just cancel the send (if indicated in * sendbuffererror),
  715. * count the occurrence, unfreeze (if no other handled
  716. * hardware error bits are set), and continue. They can
  717. * occur if a processor speculative read is done to the PIO
  718. * buffer while we are sending a packet, for example.
  719. */
  720. if (hwerrs & TXE_PIO_PARITY) {
  721. qib_6120_txe_recover(dd);
  722. hwerrs &= ~TXE_PIO_PARITY;
  723. }
  724. if (!hwerrs) {
  725. static u32 freeze_cnt;
  726. freeze_cnt++;
  727. qib_6120_clear_freeze(dd);
  728. } else
  729. isfatal = 1;
  730. }
  731. *msg = '\0';
  732. if (hwerrs & HWE_MASK(PowerOnBISTFailed)) {
  733. isfatal = 1;
  734. strlcat(msg,
  735. "[Memory BIST test failed, InfiniPath hardware unusable]",
  736. msgl);
  737. /* ignore from now on, so disable until driver reloaded */
  738. dd->cspec->hwerrmask &= ~HWE_MASK(PowerOnBISTFailed);
  739. qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
  740. }
  741. qib_format_hwerrors(hwerrs, qib_6120_hwerror_msgs,
  742. ARRAY_SIZE(qib_6120_hwerror_msgs), msg, msgl);
  743. bitsmsg = dd->cspec->bitsmsgbuf;
  744. if (hwerrs & (QLOGIC_IB_HWE_PCIEMEMPARITYERR_MASK <<
  745. QLOGIC_IB_HWE_PCIEMEMPARITYERR_SHIFT)) {
  746. bits = (u32) ((hwerrs >>
  747. QLOGIC_IB_HWE_PCIEMEMPARITYERR_SHIFT) &
  748. QLOGIC_IB_HWE_PCIEMEMPARITYERR_MASK);
  749. snprintf(bitsmsg, sizeof(dd->cspec->bitsmsgbuf),
  750. "[PCIe Mem Parity Errs %x] ", bits);
  751. strlcat(msg, bitsmsg, msgl);
  752. }
  753. if (hwerrs & _QIB_PLL_FAIL) {
  754. isfatal = 1;
  755. snprintf(bitsmsg, sizeof(dd->cspec->bitsmsgbuf),
  756. "[PLL failed (%llx), InfiniPath hardware unusable]",
  757. (unsigned long long) hwerrs & _QIB_PLL_FAIL);
  758. strlcat(msg, bitsmsg, msgl);
  759. /* ignore from now on, so disable until driver reloaded */
  760. dd->cspec->hwerrmask &= ~(hwerrs & _QIB_PLL_FAIL);
  761. qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
  762. }
  763. if (hwerrs & QLOGIC_IB_HWE_SERDESPLLFAILED) {
  764. /*
  765. * If it occurs, it is left masked since the external
  766. * interface is unused
  767. */
  768. dd->cspec->hwerrmask &= ~QLOGIC_IB_HWE_SERDESPLLFAILED;
  769. qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
  770. }
  771. if (hwerrs)
  772. /*
  773. * if any set that we aren't ignoring; only
  774. * make the complaint once, in case it's stuck
  775. * or recurring, and we get here multiple
  776. * times.
  777. */
  778. qib_dev_err(dd, "%s hardware error\n", msg);
  779. else
  780. *msg = 0; /* recovered from all of them */
  781. if (isfatal && !dd->diag_client) {
  782. qib_dev_err(dd,
  783. "Fatal Hardware Error, no longer usable, SN %.16s\n",
  784. dd->serial);
  785. /*
  786. * for /sys status file and user programs to print; if no
  787. * trailing brace is copied, we'll know it was truncated.
  788. */
  789. if (dd->freezemsg)
  790. snprintf(dd->freezemsg, dd->freezelen,
  791. "{%s}", msg);
  792. qib_disable_after_error(dd);
  793. }
  794. }
  795. /*
  796. * Decode the error status into strings, deciding whether to always
  797. * print * it or not depending on "normal packet errors" vs everything
  798. * else. Return 1 if "real" errors, otherwise 0 if only packet
  799. * errors, so caller can decide what to print with the string.
  800. */
  801. static int qib_decode_6120_err(struct qib_devdata *dd, char *buf, size_t blen,
  802. u64 err)
  803. {
  804. int iserr = 1;
  805. *buf = '\0';
  806. if (err & QLOGIC_IB_E_PKTERRS) {
  807. if (!(err & ~QLOGIC_IB_E_PKTERRS))
  808. iserr = 0;
  809. if ((err & ERR_MASK(RcvICRCErr)) &&
  810. !(err&(ERR_MASK(RcvVCRCErr)|ERR_MASK(RcvEBPErr))))
  811. strlcat(buf, "CRC ", blen);
  812. if (!iserr)
  813. goto done;
  814. }
  815. if (err & ERR_MASK(RcvHdrLenErr))
  816. strlcat(buf, "rhdrlen ", blen);
  817. if (err & ERR_MASK(RcvBadTidErr))
  818. strlcat(buf, "rbadtid ", blen);
  819. if (err & ERR_MASK(RcvBadVersionErr))
  820. strlcat(buf, "rbadversion ", blen);
  821. if (err & ERR_MASK(RcvHdrErr))
  822. strlcat(buf, "rhdr ", blen);
  823. if (err & ERR_MASK(RcvLongPktLenErr))
  824. strlcat(buf, "rlongpktlen ", blen);
  825. if (err & ERR_MASK(RcvMaxPktLenErr))
  826. strlcat(buf, "rmaxpktlen ", blen);
  827. if (err & ERR_MASK(RcvMinPktLenErr))
  828. strlcat(buf, "rminpktlen ", blen);
  829. if (err & ERR_MASK(SendMinPktLenErr))
  830. strlcat(buf, "sminpktlen ", blen);
  831. if (err & ERR_MASK(RcvFormatErr))
  832. strlcat(buf, "rformaterr ", blen);
  833. if (err & ERR_MASK(RcvUnsupportedVLErr))
  834. strlcat(buf, "runsupvl ", blen);
  835. if (err & ERR_MASK(RcvUnexpectedCharErr))
  836. strlcat(buf, "runexpchar ", blen);
  837. if (err & ERR_MASK(RcvIBFlowErr))
  838. strlcat(buf, "ribflow ", blen);
  839. if (err & ERR_MASK(SendUnderRunErr))
  840. strlcat(buf, "sunderrun ", blen);
  841. if (err & ERR_MASK(SendPioArmLaunchErr))
  842. strlcat(buf, "spioarmlaunch ", blen);
  843. if (err & ERR_MASK(SendUnexpectedPktNumErr))
  844. strlcat(buf, "sunexperrpktnum ", blen);
  845. if (err & ERR_MASK(SendDroppedSmpPktErr))
  846. strlcat(buf, "sdroppedsmppkt ", blen);
  847. if (err & ERR_MASK(SendMaxPktLenErr))
  848. strlcat(buf, "smaxpktlen ", blen);
  849. if (err & ERR_MASK(SendUnsupportedVLErr))
  850. strlcat(buf, "sunsupVL ", blen);
  851. if (err & ERR_MASK(InvalidAddrErr))
  852. strlcat(buf, "invalidaddr ", blen);
  853. if (err & ERR_MASK(RcvEgrFullErr))
  854. strlcat(buf, "rcvegrfull ", blen);
  855. if (err & ERR_MASK(RcvHdrFullErr))
  856. strlcat(buf, "rcvhdrfull ", blen);
  857. if (err & ERR_MASK(IBStatusChanged))
  858. strlcat(buf, "ibcstatuschg ", blen);
  859. if (err & ERR_MASK(RcvIBLostLinkErr))
  860. strlcat(buf, "riblostlink ", blen);
  861. if (err & ERR_MASK(HardwareErr))
  862. strlcat(buf, "hardware ", blen);
  863. if (err & ERR_MASK(ResetNegated))
  864. strlcat(buf, "reset ", blen);
  865. done:
  866. return iserr;
  867. }
  868. /*
  869. * Called when we might have an error that is specific to a particular
  870. * PIO buffer, and may need to cancel that buffer, so it can be re-used.
  871. */
  872. static void qib_disarm_6120_senderrbufs(struct qib_pportdata *ppd)
  873. {
  874. unsigned long sbuf[2];
  875. struct qib_devdata *dd = ppd->dd;
  876. /*
  877. * It's possible that sendbuffererror could have bits set; might
  878. * have already done this as a result of hardware error handling.
  879. */
  880. sbuf[0] = qib_read_kreg64(dd, kr_sendbuffererror);
  881. sbuf[1] = qib_read_kreg64(dd, kr_sendbuffererror + 1);
  882. if (sbuf[0] || sbuf[1])
  883. qib_disarm_piobufs_set(dd, sbuf,
  884. dd->piobcnt2k + dd->piobcnt4k);
  885. }
  886. static int chk_6120_linkrecovery(struct qib_devdata *dd, u64 ibcs)
  887. {
  888. int ret = 1;
  889. u32 ibstate = qib_6120_iblink_state(ibcs);
  890. u32 linkrecov = read_6120_creg32(dd, cr_iblinkerrrecov);
  891. if (linkrecov != dd->cspec->lastlinkrecov) {
  892. /* and no more until active again */
  893. dd->cspec->lastlinkrecov = 0;
  894. qib_set_linkstate(dd->pport, QIB_IB_LINKDOWN);
  895. ret = 0;
  896. }
  897. if (ibstate == IB_PORT_ACTIVE)
  898. dd->cspec->lastlinkrecov =
  899. read_6120_creg32(dd, cr_iblinkerrrecov);
  900. return ret;
  901. }
  902. static void handle_6120_errors(struct qib_devdata *dd, u64 errs)
  903. {
  904. char *msg;
  905. u64 ignore_this_time = 0;
  906. u64 iserr = 0;
  907. struct qib_pportdata *ppd = dd->pport;
  908. u64 mask;
  909. /* don't report errors that are masked */
  910. errs &= dd->cspec->errormask;
  911. msg = dd->cspec->emsgbuf;
  912. /* do these first, they are most important */
  913. if (errs & ERR_MASK(HardwareErr))
  914. qib_handle_6120_hwerrors(dd, msg, sizeof(dd->cspec->emsgbuf));
  915. if (errs & ~IB_E_BITSEXTANT)
  916. qib_dev_err(dd,
  917. "error interrupt with unknown errors %llx set\n",
  918. (unsigned long long) (errs & ~IB_E_BITSEXTANT));
  919. if (errs & E_SUM_ERRS) {
  920. qib_disarm_6120_senderrbufs(ppd);
  921. if ((errs & E_SUM_LINK_PKTERRS) &&
  922. !(ppd->lflags & QIBL_LINKACTIVE)) {
  923. /*
  924. * This can happen when trying to bring the link
  925. * up, but the IB link changes state at the "wrong"
  926. * time. The IB logic then complains that the packet
  927. * isn't valid. We don't want to confuse people, so
  928. * we just don't print them, except at debug
  929. */
  930. ignore_this_time = errs & E_SUM_LINK_PKTERRS;
  931. }
  932. } else if ((errs & E_SUM_LINK_PKTERRS) &&
  933. !(ppd->lflags & QIBL_LINKACTIVE)) {
  934. /*
  935. * This can happen when SMA is trying to bring the link
  936. * up, but the IB link changes state at the "wrong" time.
  937. * The IB logic then complains that the packet isn't
  938. * valid. We don't want to confuse people, so we just
  939. * don't print them, except at debug
  940. */
  941. ignore_this_time = errs & E_SUM_LINK_PKTERRS;
  942. }
  943. qib_write_kreg(dd, kr_errclear, errs);
  944. errs &= ~ignore_this_time;
  945. if (!errs)
  946. goto done;
  947. /*
  948. * The ones we mask off are handled specially below
  949. * or above.
  950. */
  951. mask = ERR_MASK(IBStatusChanged) | ERR_MASK(RcvEgrFullErr) |
  952. ERR_MASK(RcvHdrFullErr) | ERR_MASK(HardwareErr);
  953. qib_decode_6120_err(dd, msg, sizeof(dd->cspec->emsgbuf), errs & ~mask);
  954. if (errs & E_SUM_PKTERRS)
  955. qib_stats.sps_rcverrs++;
  956. if (errs & E_SUM_ERRS)
  957. qib_stats.sps_txerrs++;
  958. iserr = errs & ~(E_SUM_PKTERRS | QLOGIC_IB_E_PKTERRS);
  959. if (errs & ERR_MASK(IBStatusChanged)) {
  960. u64 ibcs = qib_read_kreg64(dd, kr_ibcstatus);
  961. u32 ibstate = qib_6120_iblink_state(ibcs);
  962. int handle = 1;
  963. if (ibstate != IB_PORT_INIT && dd->cspec->lastlinkrecov)
  964. handle = chk_6120_linkrecovery(dd, ibcs);
  965. /*
  966. * Since going into a recovery state causes the link state
  967. * to go down and since recovery is transitory, it is better
  968. * if we "miss" ever seeing the link training state go into
  969. * recovery (i.e., ignore this transition for link state
  970. * special handling purposes) without updating lastibcstat.
  971. */
  972. if (handle && qib_6120_phys_portstate(ibcs) ==
  973. IB_PHYSPORTSTATE_LINK_ERR_RECOVER)
  974. handle = 0;
  975. if (handle)
  976. qib_handle_e_ibstatuschanged(ppd, ibcs);
  977. }
  978. if (errs & ERR_MASK(ResetNegated)) {
  979. qib_dev_err(dd,
  980. "Got reset, requires re-init (unload and reload driver)\n");
  981. dd->flags &= ~QIB_INITTED; /* needs re-init */
  982. /* mark as having had error */
  983. *dd->devstatusp |= QIB_STATUS_HWERROR;
  984. *dd->pport->statusp &= ~QIB_STATUS_IB_CONF;
  985. }
  986. if (*msg && iserr)
  987. qib_dev_porterr(dd, ppd->port, "%s error\n", msg);
  988. if (ppd->state_wanted & ppd->lflags)
  989. wake_up_interruptible(&ppd->state_wait);
  990. /*
  991. * If there were hdrq or egrfull errors, wake up any processes
  992. * waiting in poll. We used to try to check which contexts had
  993. * the overflow, but given the cost of that and the chip reads
  994. * to support it, it's better to just wake everybody up if we
  995. * get an overflow; waiters can poll again if it's not them.
  996. */
  997. if (errs & (ERR_MASK(RcvEgrFullErr) | ERR_MASK(RcvHdrFullErr))) {
  998. qib_handle_urcv(dd, ~0U);
  999. if (errs & ERR_MASK(RcvEgrFullErr))
  1000. qib_stats.sps_buffull++;
  1001. else
  1002. qib_stats.sps_hdrfull++;
  1003. }
  1004. done:
  1005. return;
  1006. }
  1007. /**
  1008. * qib_6120_init_hwerrors - enable hardware errors
  1009. * @dd: the qlogic_ib device
  1010. *
  1011. * now that we have finished initializing everything that might reasonably
  1012. * cause a hardware error, and cleared those errors bits as they occur,
  1013. * we can enable hardware errors in the mask (potentially enabling
  1014. * freeze mode), and enable hardware errors as errors (along with
  1015. * everything else) in errormask
  1016. */
  1017. static void qib_6120_init_hwerrors(struct qib_devdata *dd)
  1018. {
  1019. u64 val;
  1020. u64 extsval;
  1021. extsval = qib_read_kreg64(dd, kr_extstatus);
  1022. if (!(extsval & QLOGIC_IB_EXTS_MEMBIST_ENDTEST))
  1023. qib_dev_err(dd, "MemBIST did not complete!\n");
  1024. /* init so all hwerrors interrupt, and enter freeze, ajdust below */
  1025. val = ~0ULL;
  1026. if (dd->minrev < 2) {
  1027. /*
  1028. * Avoid problem with internal interface bus parity
  1029. * checking. Fixed in Rev2.
  1030. */
  1031. val &= ~QLOGIC_IB_HWE_PCIEBUSPARITYRADM;
  1032. }
  1033. /* avoid some intel cpu's speculative read freeze mode issue */
  1034. val &= ~TXEMEMPARITYERR_PIOBUF;
  1035. dd->cspec->hwerrmask = val;
  1036. qib_write_kreg(dd, kr_hwerrclear, ~HWE_MASK(PowerOnBISTFailed));
  1037. qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
  1038. /* clear all */
  1039. qib_write_kreg(dd, kr_errclear, ~0ULL);
  1040. /* enable errors that are masked, at least this first time. */
  1041. qib_write_kreg(dd, kr_errmask, ~0ULL);
  1042. dd->cspec->errormask = qib_read_kreg64(dd, kr_errmask);
  1043. /* clear any interrupts up to this point (ints still not enabled) */
  1044. qib_write_kreg(dd, kr_intclear, ~0ULL);
  1045. qib_write_kreg(dd, kr_rcvbthqp,
  1046. dd->qpn_mask << (QIB_6120_RcvBTHQP_BTHQP_Mask_LSB - 1) |
  1047. QIB_KD_QP);
  1048. }
  1049. /*
  1050. * Disable and enable the armlaunch error. Used for PIO bandwidth testing
  1051. * on chips that are count-based, rather than trigger-based. There is no
  1052. * reference counting, but that's also fine, given the intended use.
  1053. * Only chip-specific because it's all register accesses
  1054. */
  1055. static void qib_set_6120_armlaunch(struct qib_devdata *dd, u32 enable)
  1056. {
  1057. if (enable) {
  1058. qib_write_kreg(dd, kr_errclear,
  1059. ERR_MASK(SendPioArmLaunchErr));
  1060. dd->cspec->errormask |= ERR_MASK(SendPioArmLaunchErr);
  1061. } else
  1062. dd->cspec->errormask &= ~ERR_MASK(SendPioArmLaunchErr);
  1063. qib_write_kreg(dd, kr_errmask, dd->cspec->errormask);
  1064. }
  1065. /*
  1066. * Formerly took parameter <which> in pre-shifted,
  1067. * pre-merged form with LinkCmd and LinkInitCmd
  1068. * together, and assuming the zero was NOP.
  1069. */
  1070. static void qib_set_ib_6120_lstate(struct qib_pportdata *ppd, u16 linkcmd,
  1071. u16 linitcmd)
  1072. {
  1073. u64 mod_wd;
  1074. struct qib_devdata *dd = ppd->dd;
  1075. unsigned long flags;
  1076. if (linitcmd == QLOGIC_IB_IBCC_LINKINITCMD_DISABLE) {
  1077. /*
  1078. * If we are told to disable, note that so link-recovery
  1079. * code does not attempt to bring us back up.
  1080. */
  1081. spin_lock_irqsave(&ppd->lflags_lock, flags);
  1082. ppd->lflags |= QIBL_IB_LINK_DISABLED;
  1083. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  1084. } else if (linitcmd || linkcmd == QLOGIC_IB_IBCC_LINKCMD_DOWN) {
  1085. /*
  1086. * Any other linkinitcmd will lead to LINKDOWN and then
  1087. * to INIT (if all is well), so clear flag to let
  1088. * link-recovery code attempt to bring us back up.
  1089. */
  1090. spin_lock_irqsave(&ppd->lflags_lock, flags);
  1091. ppd->lflags &= ~QIBL_IB_LINK_DISABLED;
  1092. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  1093. }
  1094. mod_wd = (linkcmd << QLOGIC_IB_IBCC_LINKCMD_SHIFT) |
  1095. (linitcmd << QLOGIC_IB_IBCC_LINKINITCMD_SHIFT);
  1096. qib_write_kreg(dd, kr_ibcctrl, dd->cspec->ibcctrl | mod_wd);
  1097. /* write to chip to prevent back-to-back writes of control reg */
  1098. qib_write_kreg(dd, kr_scratch, 0);
  1099. }
  1100. /**
  1101. * qib_6120_bringup_serdes - bring up the serdes
  1102. * @dd: the qlogic_ib device
  1103. */
  1104. static int qib_6120_bringup_serdes(struct qib_pportdata *ppd)
  1105. {
  1106. struct qib_devdata *dd = ppd->dd;
  1107. u64 val, config1, prev_val, hwstat, ibc;
  1108. /* Put IBC in reset, sends disabled */
  1109. dd->control &= ~QLOGIC_IB_C_LINKENABLE;
  1110. qib_write_kreg(dd, kr_control, 0ULL);
  1111. dd->cspec->ibdeltainprog = 1;
  1112. dd->cspec->ibsymsnap = read_6120_creg32(dd, cr_ibsymbolerr);
  1113. dd->cspec->iblnkerrsnap = read_6120_creg32(dd, cr_iblinkerrrecov);
  1114. /* flowcontrolwatermark is in units of KBytes */
  1115. ibc = 0x5ULL << SYM_LSB(IBCCtrl, FlowCtrlWaterMark);
  1116. /*
  1117. * How often flowctrl sent. More or less in usecs; balance against
  1118. * watermark value, so that in theory senders always get a flow
  1119. * control update in time to not let the IB link go idle.
  1120. */
  1121. ibc |= 0x3ULL << SYM_LSB(IBCCtrl, FlowCtrlPeriod);
  1122. /* max error tolerance */
  1123. dd->cspec->lli_thresh = 0xf;
  1124. ibc |= (u64) dd->cspec->lli_thresh << SYM_LSB(IBCCtrl, PhyerrThreshold);
  1125. /* use "real" buffer space for */
  1126. ibc |= 4ULL << SYM_LSB(IBCCtrl, CreditScale);
  1127. /* IB credit flow control. */
  1128. ibc |= 0xfULL << SYM_LSB(IBCCtrl, OverrunThreshold);
  1129. /*
  1130. * set initial max size pkt IBC will send, including ICRC; it's the
  1131. * PIO buffer size in dwords, less 1; also see qib_set_mtu()
  1132. */
  1133. ibc |= ((u64)(ppd->ibmaxlen >> 2) + 1) << SYM_LSB(IBCCtrl, MaxPktLen);
  1134. dd->cspec->ibcctrl = ibc; /* without linkcmd or linkinitcmd! */
  1135. /* initially come up waiting for TS1, without sending anything. */
  1136. val = dd->cspec->ibcctrl | (QLOGIC_IB_IBCC_LINKINITCMD_DISABLE <<
  1137. QLOGIC_IB_IBCC_LINKINITCMD_SHIFT);
  1138. qib_write_kreg(dd, kr_ibcctrl, val);
  1139. val = qib_read_kreg64(dd, kr_serdes_cfg0);
  1140. config1 = qib_read_kreg64(dd, kr_serdes_cfg1);
  1141. /*
  1142. * Force reset on, also set rxdetect enable. Must do before reading
  1143. * serdesstatus at least for simulation, or some of the bits in
  1144. * serdes status will come back as undefined and cause simulation
  1145. * failures
  1146. */
  1147. val |= SYM_MASK(SerdesCfg0, ResetPLL) |
  1148. SYM_MASK(SerdesCfg0, RxDetEnX) |
  1149. (SYM_MASK(SerdesCfg0, L1PwrDnA) |
  1150. SYM_MASK(SerdesCfg0, L1PwrDnB) |
  1151. SYM_MASK(SerdesCfg0, L1PwrDnC) |
  1152. SYM_MASK(SerdesCfg0, L1PwrDnD));
  1153. qib_write_kreg(dd, kr_serdes_cfg0, val);
  1154. /* be sure chip saw it */
  1155. qib_read_kreg64(dd, kr_scratch);
  1156. udelay(5); /* need pll reset set at least for a bit */
  1157. /*
  1158. * after PLL is reset, set the per-lane Resets and TxIdle and
  1159. * clear the PLL reset and rxdetect (to get falling edge).
  1160. * Leave L1PWR bits set (permanently)
  1161. */
  1162. val &= ~(SYM_MASK(SerdesCfg0, RxDetEnX) |
  1163. SYM_MASK(SerdesCfg0, ResetPLL) |
  1164. (SYM_MASK(SerdesCfg0, L1PwrDnA) |
  1165. SYM_MASK(SerdesCfg0, L1PwrDnB) |
  1166. SYM_MASK(SerdesCfg0, L1PwrDnC) |
  1167. SYM_MASK(SerdesCfg0, L1PwrDnD)));
  1168. val |= (SYM_MASK(SerdesCfg0, ResetA) |
  1169. SYM_MASK(SerdesCfg0, ResetB) |
  1170. SYM_MASK(SerdesCfg0, ResetC) |
  1171. SYM_MASK(SerdesCfg0, ResetD)) |
  1172. SYM_MASK(SerdesCfg0, TxIdeEnX);
  1173. qib_write_kreg(dd, kr_serdes_cfg0, val);
  1174. /* be sure chip saw it */
  1175. (void) qib_read_kreg64(dd, kr_scratch);
  1176. /* need PLL reset clear for at least 11 usec before lane
  1177. * resets cleared; give it a few more to be sure */
  1178. udelay(15);
  1179. val &= ~((SYM_MASK(SerdesCfg0, ResetA) |
  1180. SYM_MASK(SerdesCfg0, ResetB) |
  1181. SYM_MASK(SerdesCfg0, ResetC) |
  1182. SYM_MASK(SerdesCfg0, ResetD)) |
  1183. SYM_MASK(SerdesCfg0, TxIdeEnX));
  1184. qib_write_kreg(dd, kr_serdes_cfg0, val);
  1185. /* be sure chip saw it */
  1186. (void) qib_read_kreg64(dd, kr_scratch);
  1187. val = qib_read_kreg64(dd, kr_xgxs_cfg);
  1188. prev_val = val;
  1189. if (val & QLOGIC_IB_XGXS_RESET)
  1190. val &= ~QLOGIC_IB_XGXS_RESET;
  1191. if (SYM_FIELD(val, XGXSCfg, polarity_inv) != ppd->rx_pol_inv) {
  1192. /* need to compensate for Tx inversion in partner */
  1193. val &= ~SYM_MASK(XGXSCfg, polarity_inv);
  1194. val |= (u64)ppd->rx_pol_inv << SYM_LSB(XGXSCfg, polarity_inv);
  1195. }
  1196. if (val != prev_val)
  1197. qib_write_kreg(dd, kr_xgxs_cfg, val);
  1198. val = qib_read_kreg64(dd, kr_serdes_cfg0);
  1199. /* clear current and de-emphasis bits */
  1200. config1 &= ~0x0ffffffff00ULL;
  1201. /* set current to 20ma */
  1202. config1 |= 0x00000000000ULL;
  1203. /* set de-emphasis to -5.68dB */
  1204. config1 |= 0x0cccc000000ULL;
  1205. qib_write_kreg(dd, kr_serdes_cfg1, config1);
  1206. /* base and port guid same for single port */
  1207. ppd->guid = dd->base_guid;
  1208. /*
  1209. * the process of setting and un-resetting the serdes normally
  1210. * causes a serdes PLL error, so check for that and clear it
  1211. * here. Also clearr hwerr bit in errstatus, but not others.
  1212. */
  1213. hwstat = qib_read_kreg64(dd, kr_hwerrstatus);
  1214. if (hwstat) {
  1215. /* should just have PLL, clear all set, in an case */
  1216. qib_write_kreg(dd, kr_hwerrclear, hwstat);
  1217. qib_write_kreg(dd, kr_errclear, ERR_MASK(HardwareErr));
  1218. }
  1219. dd->control |= QLOGIC_IB_C_LINKENABLE;
  1220. dd->control &= ~QLOGIC_IB_C_FREEZEMODE;
  1221. qib_write_kreg(dd, kr_control, dd->control);
  1222. return 0;
  1223. }
  1224. /**
  1225. * qib_6120_quiet_serdes - set serdes to txidle
  1226. * @ppd: physical port of the qlogic_ib device
  1227. * Called when driver is being unloaded
  1228. */
  1229. static void qib_6120_quiet_serdes(struct qib_pportdata *ppd)
  1230. {
  1231. struct qib_devdata *dd = ppd->dd;
  1232. u64 val;
  1233. qib_set_ib_6120_lstate(ppd, 0, QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
  1234. /* disable IBC */
  1235. dd->control &= ~QLOGIC_IB_C_LINKENABLE;
  1236. qib_write_kreg(dd, kr_control,
  1237. dd->control | QLOGIC_IB_C_FREEZEMODE);
  1238. if (dd->cspec->ibsymdelta || dd->cspec->iblnkerrdelta ||
  1239. dd->cspec->ibdeltainprog) {
  1240. u64 diagc;
  1241. /* enable counter writes */
  1242. diagc = qib_read_kreg64(dd, kr_hwdiagctrl);
  1243. qib_write_kreg(dd, kr_hwdiagctrl,
  1244. diagc | SYM_MASK(HwDiagCtrl, CounterWrEnable));
  1245. if (dd->cspec->ibsymdelta || dd->cspec->ibdeltainprog) {
  1246. val = read_6120_creg32(dd, cr_ibsymbolerr);
  1247. if (dd->cspec->ibdeltainprog)
  1248. val -= val - dd->cspec->ibsymsnap;
  1249. val -= dd->cspec->ibsymdelta;
  1250. write_6120_creg(dd, cr_ibsymbolerr, val);
  1251. }
  1252. if (dd->cspec->iblnkerrdelta || dd->cspec->ibdeltainprog) {
  1253. val = read_6120_creg32(dd, cr_iblinkerrrecov);
  1254. if (dd->cspec->ibdeltainprog)
  1255. val -= val - dd->cspec->iblnkerrsnap;
  1256. val -= dd->cspec->iblnkerrdelta;
  1257. write_6120_creg(dd, cr_iblinkerrrecov, val);
  1258. }
  1259. /* and disable counter writes */
  1260. qib_write_kreg(dd, kr_hwdiagctrl, diagc);
  1261. }
  1262. val = qib_read_kreg64(dd, kr_serdes_cfg0);
  1263. val |= SYM_MASK(SerdesCfg0, TxIdeEnX);
  1264. qib_write_kreg(dd, kr_serdes_cfg0, val);
  1265. }
  1266. /**
  1267. * qib_6120_setup_setextled - set the state of the two external LEDs
  1268. * @dd: the qlogic_ib device
  1269. * @on: whether the link is up or not
  1270. *
  1271. * The exact combo of LEDs if on is true is determined by looking
  1272. * at the ibcstatus.
  1273. * These LEDs indicate the physical and logical state of IB link.
  1274. * For this chip (at least with recommended board pinouts), LED1
  1275. * is Yellow (logical state) and LED2 is Green (physical state),
  1276. *
  1277. * Note: We try to match the Mellanox HCA LED behavior as best
  1278. * we can. Green indicates physical link state is OK (something is
  1279. * plugged in, and we can train).
  1280. * Amber indicates the link is logically up (ACTIVE).
  1281. * Mellanox further blinks the amber LED to indicate data packet
  1282. * activity, but we have no hardware support for that, so it would
  1283. * require waking up every 10-20 msecs and checking the counters
  1284. * on the chip, and then turning the LED off if appropriate. That's
  1285. * visible overhead, so not something we will do.
  1286. *
  1287. */
  1288. static void qib_6120_setup_setextled(struct qib_pportdata *ppd, u32 on)
  1289. {
  1290. u64 extctl, val, lst, ltst;
  1291. unsigned long flags;
  1292. struct qib_devdata *dd = ppd->dd;
  1293. /*
  1294. * The diags use the LED to indicate diag info, so we leave
  1295. * the external LED alone when the diags are running.
  1296. */
  1297. if (dd->diag_client)
  1298. return;
  1299. /* Allow override of LED display for, e.g. Locating system in rack */
  1300. if (ppd->led_override) {
  1301. ltst = (ppd->led_override & QIB_LED_PHYS) ?
  1302. IB_PHYSPORTSTATE_LINKUP : IB_PHYSPORTSTATE_DISABLED,
  1303. lst = (ppd->led_override & QIB_LED_LOG) ?
  1304. IB_PORT_ACTIVE : IB_PORT_DOWN;
  1305. } else if (on) {
  1306. val = qib_read_kreg64(dd, kr_ibcstatus);
  1307. ltst = qib_6120_phys_portstate(val);
  1308. lst = qib_6120_iblink_state(val);
  1309. } else {
  1310. ltst = 0;
  1311. lst = 0;
  1312. }
  1313. spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
  1314. extctl = dd->cspec->extctrl & ~(SYM_MASK(EXTCtrl, LEDPriPortGreenOn) |
  1315. SYM_MASK(EXTCtrl, LEDPriPortYellowOn));
  1316. if (ltst == IB_PHYSPORTSTATE_LINKUP)
  1317. extctl |= SYM_MASK(EXTCtrl, LEDPriPortYellowOn);
  1318. if (lst == IB_PORT_ACTIVE)
  1319. extctl |= SYM_MASK(EXTCtrl, LEDPriPortGreenOn);
  1320. dd->cspec->extctrl = extctl;
  1321. qib_write_kreg(dd, kr_extctrl, extctl);
  1322. spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
  1323. }
  1324. /**
  1325. * qib_6120_setup_cleanup - clean up any per-chip chip-specific stuff
  1326. * @dd: the qlogic_ib device
  1327. *
  1328. * This is called during driver unload.
  1329. */
  1330. static void qib_6120_setup_cleanup(struct qib_devdata *dd)
  1331. {
  1332. qib_free_irq(dd);
  1333. kfree(dd->cspec->cntrs);
  1334. kfree(dd->cspec->portcntrs);
  1335. if (dd->cspec->dummy_hdrq) {
  1336. dma_free_coherent(&dd->pcidev->dev,
  1337. ALIGN(dd->rcvhdrcnt *
  1338. dd->rcvhdrentsize *
  1339. sizeof(u32), PAGE_SIZE),
  1340. dd->cspec->dummy_hdrq,
  1341. dd->cspec->dummy_hdrq_phys);
  1342. dd->cspec->dummy_hdrq = NULL;
  1343. }
  1344. }
  1345. static void qib_wantpiobuf_6120_intr(struct qib_devdata *dd, u32 needint)
  1346. {
  1347. unsigned long flags;
  1348. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  1349. if (needint)
  1350. dd->sendctrl |= SYM_MASK(SendCtrl, PIOIntBufAvail);
  1351. else
  1352. dd->sendctrl &= ~SYM_MASK(SendCtrl, PIOIntBufAvail);
  1353. qib_write_kreg(dd, kr_sendctrl, dd->sendctrl);
  1354. qib_write_kreg(dd, kr_scratch, 0ULL);
  1355. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  1356. }
  1357. /*
  1358. * handle errors and unusual events first, separate function
  1359. * to improve cache hits for fast path interrupt handling
  1360. */
  1361. static noinline void unlikely_6120_intr(struct qib_devdata *dd, u64 istat)
  1362. {
  1363. if (unlikely(istat & ~QLOGIC_IB_I_BITSEXTANT))
  1364. qib_dev_err(dd, "interrupt with unknown interrupts %Lx set\n",
  1365. istat & ~QLOGIC_IB_I_BITSEXTANT);
  1366. if (istat & QLOGIC_IB_I_ERROR) {
  1367. u64 estat = 0;
  1368. qib_stats.sps_errints++;
  1369. estat = qib_read_kreg64(dd, kr_errstatus);
  1370. if (!estat)
  1371. qib_devinfo(dd->pcidev,
  1372. "error interrupt (%Lx), but no error bits set!\n",
  1373. istat);
  1374. handle_6120_errors(dd, estat);
  1375. }
  1376. if (istat & QLOGIC_IB_I_GPIO) {
  1377. u32 gpiostatus;
  1378. u32 to_clear = 0;
  1379. /*
  1380. * GPIO_3..5 on IBA6120 Rev2 chips indicate
  1381. * errors that we need to count.
  1382. */
  1383. gpiostatus = qib_read_kreg32(dd, kr_gpio_status);
  1384. /* First the error-counter case. */
  1385. if (gpiostatus & GPIO_ERRINTR_MASK) {
  1386. /* want to clear the bits we see asserted. */
  1387. to_clear |= (gpiostatus & GPIO_ERRINTR_MASK);
  1388. /*
  1389. * Count appropriately, clear bits out of our copy,
  1390. * as they have been "handled".
  1391. */
  1392. if (gpiostatus & (1 << GPIO_RXUVL_BIT))
  1393. dd->cspec->rxfc_unsupvl_errs++;
  1394. if (gpiostatus & (1 << GPIO_OVRUN_BIT))
  1395. dd->cspec->overrun_thresh_errs++;
  1396. if (gpiostatus & (1 << GPIO_LLI_BIT))
  1397. dd->cspec->lli_errs++;
  1398. gpiostatus &= ~GPIO_ERRINTR_MASK;
  1399. }
  1400. if (gpiostatus) {
  1401. /*
  1402. * Some unexpected bits remain. If they could have
  1403. * caused the interrupt, complain and clear.
  1404. * To avoid repetition of this condition, also clear
  1405. * the mask. It is almost certainly due to error.
  1406. */
  1407. const u32 mask = qib_read_kreg32(dd, kr_gpio_mask);
  1408. /*
  1409. * Also check that the chip reflects our shadow,
  1410. * and report issues, If they caused the interrupt.
  1411. * we will suppress by refreshing from the shadow.
  1412. */
  1413. if (mask & gpiostatus) {
  1414. to_clear |= (gpiostatus & mask);
  1415. dd->cspec->gpio_mask &= ~(gpiostatus & mask);
  1416. qib_write_kreg(dd, kr_gpio_mask,
  1417. dd->cspec->gpio_mask);
  1418. }
  1419. }
  1420. if (to_clear)
  1421. qib_write_kreg(dd, kr_gpio_clear, (u64) to_clear);
  1422. }
  1423. }
  1424. static irqreturn_t qib_6120intr(int irq, void *data)
  1425. {
  1426. struct qib_devdata *dd = data;
  1427. irqreturn_t ret;
  1428. u32 istat, ctxtrbits, rmask, crcs = 0;
  1429. unsigned i;
  1430. if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT) {
  1431. /*
  1432. * This return value is not great, but we do not want the
  1433. * interrupt core code to remove our interrupt handler
  1434. * because we don't appear to be handling an interrupt
  1435. * during a chip reset.
  1436. */
  1437. ret = IRQ_HANDLED;
  1438. goto bail;
  1439. }
  1440. istat = qib_read_kreg32(dd, kr_intstatus);
  1441. if (unlikely(!istat)) {
  1442. ret = IRQ_NONE; /* not our interrupt, or already handled */
  1443. goto bail;
  1444. }
  1445. if (unlikely(istat == -1)) {
  1446. qib_bad_intrstatus(dd);
  1447. /* don't know if it was our interrupt or not */
  1448. ret = IRQ_NONE;
  1449. goto bail;
  1450. }
  1451. this_cpu_inc(*dd->int_counter);
  1452. if (unlikely(istat & (~QLOGIC_IB_I_BITSEXTANT |
  1453. QLOGIC_IB_I_GPIO | QLOGIC_IB_I_ERROR)))
  1454. unlikely_6120_intr(dd, istat);
  1455. /*
  1456. * Clear the interrupt bits we found set, relatively early, so we
  1457. * "know" know the chip will have seen this by the time we process
  1458. * the queue, and will re-interrupt if necessary. The processor
  1459. * itself won't take the interrupt again until we return.
  1460. */
  1461. qib_write_kreg(dd, kr_intclear, istat);
  1462. /*
  1463. * Handle kernel receive queues before checking for pio buffers
  1464. * available since receives can overflow; piobuf waiters can afford
  1465. * a few extra cycles, since they were waiting anyway.
  1466. */
  1467. ctxtrbits = istat &
  1468. ((QLOGIC_IB_I_RCVAVAIL_MASK << QLOGIC_IB_I_RCVAVAIL_SHIFT) |
  1469. (QLOGIC_IB_I_RCVURG_MASK << QLOGIC_IB_I_RCVURG_SHIFT));
  1470. if (ctxtrbits) {
  1471. rmask = (1U << QLOGIC_IB_I_RCVAVAIL_SHIFT) |
  1472. (1U << QLOGIC_IB_I_RCVURG_SHIFT);
  1473. for (i = 0; i < dd->first_user_ctxt; i++) {
  1474. if (ctxtrbits & rmask) {
  1475. ctxtrbits &= ~rmask;
  1476. crcs += qib_kreceive(dd->rcd[i],
  1477. &dd->cspec->lli_counter,
  1478. NULL);
  1479. }
  1480. rmask <<= 1;
  1481. }
  1482. if (crcs) {
  1483. u32 cntr = dd->cspec->lli_counter;
  1484. cntr += crcs;
  1485. if (cntr) {
  1486. if (cntr > dd->cspec->lli_thresh) {
  1487. dd->cspec->lli_counter = 0;
  1488. dd->cspec->lli_errs++;
  1489. } else
  1490. dd->cspec->lli_counter += cntr;
  1491. }
  1492. }
  1493. if (ctxtrbits) {
  1494. ctxtrbits =
  1495. (ctxtrbits >> QLOGIC_IB_I_RCVAVAIL_SHIFT) |
  1496. (ctxtrbits >> QLOGIC_IB_I_RCVURG_SHIFT);
  1497. qib_handle_urcv(dd, ctxtrbits);
  1498. }
  1499. }
  1500. if ((istat & QLOGIC_IB_I_SPIOBUFAVAIL) && (dd->flags & QIB_INITTED))
  1501. qib_ib_piobufavail(dd);
  1502. ret = IRQ_HANDLED;
  1503. bail:
  1504. return ret;
  1505. }
  1506. /*
  1507. * Set up our chip-specific interrupt handler
  1508. * The interrupt type has already been setup, so
  1509. * we just need to do the registration and error checking.
  1510. */
  1511. static void qib_setup_6120_interrupt(struct qib_devdata *dd)
  1512. {
  1513. int ret;
  1514. /*
  1515. * If the chip supports added error indication via GPIO pins,
  1516. * enable interrupts on those bits so the interrupt routine
  1517. * can count the events. Also set flag so interrupt routine
  1518. * can know they are expected.
  1519. */
  1520. if (SYM_FIELD(dd->revision, Revision_R,
  1521. ChipRevMinor) > 1) {
  1522. /* Rev2+ reports extra errors via internal GPIO pins */
  1523. dd->cspec->gpio_mask |= GPIO_ERRINTR_MASK;
  1524. qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
  1525. }
  1526. ret = pci_request_irq(dd->pcidev, 0, qib_6120intr, NULL, dd,
  1527. QIB_DRV_NAME);
  1528. if (ret)
  1529. qib_dev_err(dd,
  1530. "Couldn't setup interrupt (irq=%d): %d\n",
  1531. pci_irq_vector(dd->pcidev, 0), ret);
  1532. }
  1533. /**
  1534. * pe_boardname - fill in the board name
  1535. * @dd: the qlogic_ib device
  1536. *
  1537. * info is based on the board revision register
  1538. */
  1539. static void pe_boardname(struct qib_devdata *dd)
  1540. {
  1541. u32 boardid;
  1542. boardid = SYM_FIELD(dd->revision, Revision,
  1543. BoardID);
  1544. switch (boardid) {
  1545. case 2:
  1546. dd->boardname = "InfiniPath_QLE7140";
  1547. break;
  1548. default:
  1549. qib_dev_err(dd, "Unknown 6120 board with ID %u\n", boardid);
  1550. dd->boardname = "Unknown_InfiniPath_6120";
  1551. break;
  1552. }
  1553. if (dd->majrev != 4 || !dd->minrev || dd->minrev > 2)
  1554. qib_dev_err(dd,
  1555. "Unsupported InfiniPath hardware revision %u.%u!\n",
  1556. dd->majrev, dd->minrev);
  1557. snprintf(dd->boardversion, sizeof(dd->boardversion),
  1558. "ChipABI %u.%u, %s, InfiniPath%u %u.%u, SW Compat %u\n",
  1559. QIB_CHIP_VERS_MAJ, QIB_CHIP_VERS_MIN, dd->boardname,
  1560. (unsigned int)SYM_FIELD(dd->revision, Revision_R, Arch),
  1561. dd->majrev, dd->minrev,
  1562. (unsigned int)SYM_FIELD(dd->revision, Revision_R, SW));
  1563. }
  1564. /*
  1565. * This routine sleeps, so it can only be called from user context, not
  1566. * from interrupt context. If we need interrupt context, we can split
  1567. * it into two routines.
  1568. */
  1569. static int qib_6120_setup_reset(struct qib_devdata *dd)
  1570. {
  1571. u64 val;
  1572. int i;
  1573. int ret;
  1574. u16 cmdval;
  1575. u8 int_line, clinesz;
  1576. qib_pcie_getcmd(dd, &cmdval, &int_line, &clinesz);
  1577. /* Use ERROR so it shows up in logs, etc. */
  1578. qib_dev_err(dd, "Resetting InfiniPath unit %u\n", dd->unit);
  1579. /* no interrupts till re-initted */
  1580. qib_6120_set_intr_state(dd, 0);
  1581. dd->cspec->ibdeltainprog = 0;
  1582. dd->cspec->ibsymdelta = 0;
  1583. dd->cspec->iblnkerrdelta = 0;
  1584. /*
  1585. * Keep chip from being accessed until we are ready. Use
  1586. * writeq() directly, to allow the write even though QIB_PRESENT
  1587. * isn't set.
  1588. */
  1589. dd->flags &= ~(QIB_INITTED | QIB_PRESENT);
  1590. /* so we check interrupts work again */
  1591. dd->z_int_counter = qib_int_counter(dd);
  1592. val = dd->control | QLOGIC_IB_C_RESET;
  1593. writeq(val, &dd->kregbase[kr_control]);
  1594. mb(); /* prevent compiler re-ordering around actual reset */
  1595. for (i = 1; i <= 5; i++) {
  1596. /*
  1597. * Allow MBIST, etc. to complete; longer on each retry.
  1598. * We sometimes get machine checks from bus timeout if no
  1599. * response, so for now, make it *really* long.
  1600. */
  1601. msleep(1000 + (1 + i) * 2000);
  1602. qib_pcie_reenable(dd, cmdval, int_line, clinesz);
  1603. /*
  1604. * Use readq directly, so we don't need to mark it as PRESENT
  1605. * until we get a successful indication that all is well.
  1606. */
  1607. val = readq(&dd->kregbase[kr_revision]);
  1608. if (val == dd->revision) {
  1609. dd->flags |= QIB_PRESENT; /* it's back */
  1610. ret = qib_reinit_intr(dd);
  1611. goto bail;
  1612. }
  1613. }
  1614. ret = 0; /* failed */
  1615. bail:
  1616. if (ret) {
  1617. if (qib_pcie_params(dd, dd->lbus_width, NULL))
  1618. qib_dev_err(dd,
  1619. "Reset failed to setup PCIe or interrupts; continuing anyway\n");
  1620. /* clear the reset error, init error/hwerror mask */
  1621. qib_6120_init_hwerrors(dd);
  1622. /* for Rev2 error interrupts; nop for rev 1 */
  1623. qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
  1624. /* clear the reset error, init error/hwerror mask */
  1625. qib_6120_init_hwerrors(dd);
  1626. }
  1627. return ret;
  1628. }
  1629. /**
  1630. * qib_6120_put_tid - write a TID in chip
  1631. * @dd: the qlogic_ib device
  1632. * @tidptr: pointer to the expected TID (in chip) to update
  1633. * @tidtype: RCVHQ_RCV_TYPE_EAGER (1) for eager, RCVHQ_RCV_TYPE_EXPECTED (0)
  1634. * for expected
  1635. * @pa: physical address of in memory buffer; tidinvalid if freeing
  1636. *
  1637. * This exists as a separate routine to allow for special locking etc.
  1638. * It's used for both the full cleanup on exit, as well as the normal
  1639. * setup and teardown.
  1640. */
  1641. static void qib_6120_put_tid(struct qib_devdata *dd, u64 __iomem *tidptr,
  1642. u32 type, unsigned long pa)
  1643. {
  1644. u32 __iomem *tidp32 = (u32 __iomem *)tidptr;
  1645. unsigned long flags;
  1646. int tidx;
  1647. spinlock_t *tidlockp; /* select appropriate spinlock */
  1648. if (!dd->kregbase)
  1649. return;
  1650. if (pa != dd->tidinvalid) {
  1651. if (pa & ((1U << 11) - 1)) {
  1652. qib_dev_err(dd, "Physaddr %lx not 2KB aligned!\n",
  1653. pa);
  1654. return;
  1655. }
  1656. pa >>= 11;
  1657. if (pa & ~QLOGIC_IB_RT_ADDR_MASK) {
  1658. qib_dev_err(dd,
  1659. "Physical page address 0x%lx larger than supported\n",
  1660. pa);
  1661. return;
  1662. }
  1663. if (type == RCVHQ_RCV_TYPE_EAGER)
  1664. pa |= dd->tidtemplate;
  1665. else /* for now, always full 4KB page */
  1666. pa |= 2 << 29;
  1667. }
  1668. /*
  1669. * Avoid chip issue by writing the scratch register
  1670. * before and after the TID, and with an io write barrier.
  1671. * We use a spinlock around the writes, so they can't intermix
  1672. * with other TID (eager or expected) writes (the chip problem
  1673. * is triggered by back to back TID writes). Unfortunately, this
  1674. * call can be done from interrupt level for the ctxt 0 eager TIDs,
  1675. * so we have to use irqsave locks.
  1676. */
  1677. /*
  1678. * Assumes tidptr always > egrtidbase
  1679. * if type == RCVHQ_RCV_TYPE_EAGER.
  1680. */
  1681. tidx = tidptr - dd->egrtidbase;
  1682. tidlockp = (type == RCVHQ_RCV_TYPE_EAGER && tidx < dd->rcvhdrcnt)
  1683. ? &dd->cspec->kernel_tid_lock : &dd->cspec->user_tid_lock;
  1684. spin_lock_irqsave(tidlockp, flags);
  1685. qib_write_kreg(dd, kr_scratch, 0xfeeddeaf);
  1686. writel(pa, tidp32);
  1687. qib_write_kreg(dd, kr_scratch, 0xdeadbeef);
  1688. mmiowb();
  1689. spin_unlock_irqrestore(tidlockp, flags);
  1690. }
  1691. /**
  1692. * qib_6120_put_tid_2 - write a TID in chip, Revision 2 or higher
  1693. * @dd: the qlogic_ib device
  1694. * @tidptr: pointer to the expected TID (in chip) to update
  1695. * @tidtype: RCVHQ_RCV_TYPE_EAGER (1) for eager, RCVHQ_RCV_TYPE_EXPECTED (0)
  1696. * for expected
  1697. * @pa: physical address of in memory buffer; tidinvalid if freeing
  1698. *
  1699. * This exists as a separate routine to allow for selection of the
  1700. * appropriate "flavor". The static calls in cleanup just use the
  1701. * revision-agnostic form, as they are not performance critical.
  1702. */
  1703. static void qib_6120_put_tid_2(struct qib_devdata *dd, u64 __iomem *tidptr,
  1704. u32 type, unsigned long pa)
  1705. {
  1706. u32 __iomem *tidp32 = (u32 __iomem *)tidptr;
  1707. if (!dd->kregbase)
  1708. return;
  1709. if (pa != dd->tidinvalid) {
  1710. if (pa & ((1U << 11) - 1)) {
  1711. qib_dev_err(dd, "Physaddr %lx not 2KB aligned!\n",
  1712. pa);
  1713. return;
  1714. }
  1715. pa >>= 11;
  1716. if (pa & ~QLOGIC_IB_RT_ADDR_MASK) {
  1717. qib_dev_err(dd,
  1718. "Physical page address 0x%lx larger than supported\n",
  1719. pa);
  1720. return;
  1721. }
  1722. if (type == RCVHQ_RCV_TYPE_EAGER)
  1723. pa |= dd->tidtemplate;
  1724. else /* for now, always full 4KB page */
  1725. pa |= 2 << 29;
  1726. }
  1727. writel(pa, tidp32);
  1728. mmiowb();
  1729. }
  1730. /**
  1731. * qib_6120_clear_tids - clear all TID entries for a context, expected and eager
  1732. * @dd: the qlogic_ib device
  1733. * @ctxt: the context
  1734. *
  1735. * clear all TID entries for a context, expected and eager.
  1736. * Used from qib_close(). On this chip, TIDs are only 32 bits,
  1737. * not 64, but they are still on 64 bit boundaries, so tidbase
  1738. * is declared as u64 * for the pointer math, even though we write 32 bits
  1739. */
  1740. static void qib_6120_clear_tids(struct qib_devdata *dd,
  1741. struct qib_ctxtdata *rcd)
  1742. {
  1743. u64 __iomem *tidbase;
  1744. unsigned long tidinv;
  1745. u32 ctxt;
  1746. int i;
  1747. if (!dd->kregbase || !rcd)
  1748. return;
  1749. ctxt = rcd->ctxt;
  1750. tidinv = dd->tidinvalid;
  1751. tidbase = (u64 __iomem *)
  1752. ((char __iomem *)(dd->kregbase) +
  1753. dd->rcvtidbase +
  1754. ctxt * dd->rcvtidcnt * sizeof(*tidbase));
  1755. for (i = 0; i < dd->rcvtidcnt; i++)
  1756. /* use func pointer because could be one of two funcs */
  1757. dd->f_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EXPECTED,
  1758. tidinv);
  1759. tidbase = (u64 __iomem *)
  1760. ((char __iomem *)(dd->kregbase) +
  1761. dd->rcvegrbase +
  1762. rcd->rcvegr_tid_base * sizeof(*tidbase));
  1763. for (i = 0; i < rcd->rcvegrcnt; i++)
  1764. /* use func pointer because could be one of two funcs */
  1765. dd->f_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EAGER,
  1766. tidinv);
  1767. }
  1768. /**
  1769. * qib_6120_tidtemplate - setup constants for TID updates
  1770. * @dd: the qlogic_ib device
  1771. *
  1772. * We setup stuff that we use a lot, to avoid calculating each time
  1773. */
  1774. static void qib_6120_tidtemplate(struct qib_devdata *dd)
  1775. {
  1776. u32 egrsize = dd->rcvegrbufsize;
  1777. /*
  1778. * For now, we always allocate 4KB buffers (at init) so we can
  1779. * receive max size packets. We may want a module parameter to
  1780. * specify 2KB or 4KB and/or make be per ctxt instead of per device
  1781. * for those who want to reduce memory footprint. Note that the
  1782. * rcvhdrentsize size must be large enough to hold the largest
  1783. * IB header (currently 96 bytes) that we expect to handle (plus of
  1784. * course the 2 dwords of RHF).
  1785. */
  1786. if (egrsize == 2048)
  1787. dd->tidtemplate = 1U << 29;
  1788. else if (egrsize == 4096)
  1789. dd->tidtemplate = 2U << 29;
  1790. dd->tidinvalid = 0;
  1791. }
  1792. int __attribute__((weak)) qib_unordered_wc(void)
  1793. {
  1794. return 0;
  1795. }
  1796. /**
  1797. * qib_6120_get_base_info - set chip-specific flags for user code
  1798. * @rcd: the qlogic_ib ctxt
  1799. * @kbase: qib_base_info pointer
  1800. *
  1801. * We set the PCIE flag because the lower bandwidth on PCIe vs
  1802. * HyperTransport can affect some user packet algorithms.
  1803. */
  1804. static int qib_6120_get_base_info(struct qib_ctxtdata *rcd,
  1805. struct qib_base_info *kinfo)
  1806. {
  1807. if (qib_unordered_wc())
  1808. kinfo->spi_runtime_flags |= QIB_RUNTIME_FORCE_WC_ORDER;
  1809. kinfo->spi_runtime_flags |= QIB_RUNTIME_PCIE |
  1810. QIB_RUNTIME_FORCE_PIOAVAIL | QIB_RUNTIME_PIO_REGSWAPPED;
  1811. return 0;
  1812. }
  1813. static struct qib_message_header *
  1814. qib_6120_get_msgheader(struct qib_devdata *dd, __le32 *rhf_addr)
  1815. {
  1816. return (struct qib_message_header *)
  1817. &rhf_addr[sizeof(u64) / sizeof(u32)];
  1818. }
  1819. static void qib_6120_config_ctxts(struct qib_devdata *dd)
  1820. {
  1821. dd->ctxtcnt = qib_read_kreg32(dd, kr_portcnt);
  1822. if (qib_n_krcv_queues > 1) {
  1823. dd->first_user_ctxt = qib_n_krcv_queues * dd->num_pports;
  1824. if (dd->first_user_ctxt > dd->ctxtcnt)
  1825. dd->first_user_ctxt = dd->ctxtcnt;
  1826. dd->qpn_mask = dd->first_user_ctxt <= 2 ? 2 : 6;
  1827. } else
  1828. dd->first_user_ctxt = dd->num_pports;
  1829. dd->n_krcv_queues = dd->first_user_ctxt;
  1830. }
  1831. static void qib_update_6120_usrhead(struct qib_ctxtdata *rcd, u64 hd,
  1832. u32 updegr, u32 egrhd, u32 npkts)
  1833. {
  1834. if (updegr)
  1835. qib_write_ureg(rcd->dd, ur_rcvegrindexhead, egrhd, rcd->ctxt);
  1836. mmiowb();
  1837. qib_write_ureg(rcd->dd, ur_rcvhdrhead, hd, rcd->ctxt);
  1838. mmiowb();
  1839. }
  1840. static u32 qib_6120_hdrqempty(struct qib_ctxtdata *rcd)
  1841. {
  1842. u32 head, tail;
  1843. head = qib_read_ureg32(rcd->dd, ur_rcvhdrhead, rcd->ctxt);
  1844. if (rcd->rcvhdrtail_kvaddr)
  1845. tail = qib_get_rcvhdrtail(rcd);
  1846. else
  1847. tail = qib_read_ureg32(rcd->dd, ur_rcvhdrtail, rcd->ctxt);
  1848. return head == tail;
  1849. }
  1850. /*
  1851. * Used when we close any ctxt, for DMA already in flight
  1852. * at close. Can't be done until we know hdrq size, so not
  1853. * early in chip init.
  1854. */
  1855. static void alloc_dummy_hdrq(struct qib_devdata *dd)
  1856. {
  1857. dd->cspec->dummy_hdrq = dma_alloc_coherent(&dd->pcidev->dev,
  1858. dd->rcd[0]->rcvhdrq_size,
  1859. &dd->cspec->dummy_hdrq_phys,
  1860. GFP_ATOMIC | __GFP_COMP);
  1861. if (!dd->cspec->dummy_hdrq) {
  1862. qib_devinfo(dd->pcidev, "Couldn't allocate dummy hdrq\n");
  1863. /* fallback to just 0'ing */
  1864. dd->cspec->dummy_hdrq_phys = 0UL;
  1865. }
  1866. }
  1867. /*
  1868. * Modify the RCVCTRL register in chip-specific way. This
  1869. * is a function because bit positions and (future) register
  1870. * location is chip-specific, but the needed operations are
  1871. * generic. <op> is a bit-mask because we often want to
  1872. * do multiple modifications.
  1873. */
  1874. static void rcvctrl_6120_mod(struct qib_pportdata *ppd, unsigned int op,
  1875. int ctxt)
  1876. {
  1877. struct qib_devdata *dd = ppd->dd;
  1878. u64 mask, val;
  1879. unsigned long flags;
  1880. spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
  1881. if (op & QIB_RCVCTRL_TAILUPD_ENB)
  1882. dd->rcvctrl |= (1ULL << QLOGIC_IB_R_TAILUPD_SHIFT);
  1883. if (op & QIB_RCVCTRL_TAILUPD_DIS)
  1884. dd->rcvctrl &= ~(1ULL << QLOGIC_IB_R_TAILUPD_SHIFT);
  1885. if (op & QIB_RCVCTRL_PKEY_ENB)
  1886. dd->rcvctrl &= ~(1ULL << IBA6120_R_PKEY_DIS_SHIFT);
  1887. if (op & QIB_RCVCTRL_PKEY_DIS)
  1888. dd->rcvctrl |= (1ULL << IBA6120_R_PKEY_DIS_SHIFT);
  1889. if (ctxt < 0)
  1890. mask = (1ULL << dd->ctxtcnt) - 1;
  1891. else
  1892. mask = (1ULL << ctxt);
  1893. if (op & QIB_RCVCTRL_CTXT_ENB) {
  1894. /* always done for specific ctxt */
  1895. dd->rcvctrl |= (mask << SYM_LSB(RcvCtrl, PortEnable));
  1896. if (!(dd->flags & QIB_NODMA_RTAIL))
  1897. dd->rcvctrl |= 1ULL << QLOGIC_IB_R_TAILUPD_SHIFT;
  1898. /* Write these registers before the context is enabled. */
  1899. qib_write_kreg_ctxt(dd, kr_rcvhdrtailaddr, ctxt,
  1900. dd->rcd[ctxt]->rcvhdrqtailaddr_phys);
  1901. qib_write_kreg_ctxt(dd, kr_rcvhdraddr, ctxt,
  1902. dd->rcd[ctxt]->rcvhdrq_phys);
  1903. if (ctxt == 0 && !dd->cspec->dummy_hdrq)
  1904. alloc_dummy_hdrq(dd);
  1905. }
  1906. if (op & QIB_RCVCTRL_CTXT_DIS)
  1907. dd->rcvctrl &= ~(mask << SYM_LSB(RcvCtrl, PortEnable));
  1908. if (op & QIB_RCVCTRL_INTRAVAIL_ENB)
  1909. dd->rcvctrl |= (mask << QLOGIC_IB_R_INTRAVAIL_SHIFT);
  1910. if (op & QIB_RCVCTRL_INTRAVAIL_DIS)
  1911. dd->rcvctrl &= ~(mask << QLOGIC_IB_R_INTRAVAIL_SHIFT);
  1912. qib_write_kreg(dd, kr_rcvctrl, dd->rcvctrl);
  1913. if ((op & QIB_RCVCTRL_INTRAVAIL_ENB) && dd->rhdrhead_intr_off) {
  1914. /* arm rcv interrupt */
  1915. val = qib_read_ureg32(dd, ur_rcvhdrhead, ctxt) |
  1916. dd->rhdrhead_intr_off;
  1917. qib_write_ureg(dd, ur_rcvhdrhead, val, ctxt);
  1918. }
  1919. if (op & QIB_RCVCTRL_CTXT_ENB) {
  1920. /*
  1921. * Init the context registers also; if we were
  1922. * disabled, tail and head should both be zero
  1923. * already from the enable, but since we don't
  1924. * know, we have to do it explicitly.
  1925. */
  1926. val = qib_read_ureg32(dd, ur_rcvegrindextail, ctxt);
  1927. qib_write_ureg(dd, ur_rcvegrindexhead, val, ctxt);
  1928. val = qib_read_ureg32(dd, ur_rcvhdrtail, ctxt);
  1929. dd->rcd[ctxt]->head = val;
  1930. /* If kctxt, interrupt on next receive. */
  1931. if (ctxt < dd->first_user_ctxt)
  1932. val |= dd->rhdrhead_intr_off;
  1933. qib_write_ureg(dd, ur_rcvhdrhead, val, ctxt);
  1934. }
  1935. if (op & QIB_RCVCTRL_CTXT_DIS) {
  1936. /*
  1937. * Be paranoid, and never write 0's to these, just use an
  1938. * unused page. Of course,
  1939. * rcvhdraddr points to a large chunk of memory, so this
  1940. * could still trash things, but at least it won't trash
  1941. * page 0, and by disabling the ctxt, it should stop "soon",
  1942. * even if a packet or two is in already in flight after we
  1943. * disabled the ctxt. Only 6120 has this issue.
  1944. */
  1945. if (ctxt >= 0) {
  1946. qib_write_kreg_ctxt(dd, kr_rcvhdrtailaddr, ctxt,
  1947. dd->cspec->dummy_hdrq_phys);
  1948. qib_write_kreg_ctxt(dd, kr_rcvhdraddr, ctxt,
  1949. dd->cspec->dummy_hdrq_phys);
  1950. } else {
  1951. unsigned i;
  1952. for (i = 0; i < dd->cfgctxts; i++) {
  1953. qib_write_kreg_ctxt(dd, kr_rcvhdrtailaddr,
  1954. i, dd->cspec->dummy_hdrq_phys);
  1955. qib_write_kreg_ctxt(dd, kr_rcvhdraddr,
  1956. i, dd->cspec->dummy_hdrq_phys);
  1957. }
  1958. }
  1959. }
  1960. spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
  1961. }
  1962. /*
  1963. * Modify the SENDCTRL register in chip-specific way. This
  1964. * is a function there may be multiple such registers with
  1965. * slightly different layouts. Only operations actually used
  1966. * are implemented yet.
  1967. * Chip requires no back-back sendctrl writes, so write
  1968. * scratch register after writing sendctrl
  1969. */
  1970. static void sendctrl_6120_mod(struct qib_pportdata *ppd, u32 op)
  1971. {
  1972. struct qib_devdata *dd = ppd->dd;
  1973. u64 tmp_dd_sendctrl;
  1974. unsigned long flags;
  1975. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  1976. /* First the ones that are "sticky", saved in shadow */
  1977. if (op & QIB_SENDCTRL_CLEAR)
  1978. dd->sendctrl = 0;
  1979. if (op & QIB_SENDCTRL_SEND_DIS)
  1980. dd->sendctrl &= ~SYM_MASK(SendCtrl, PIOEnable);
  1981. else if (op & QIB_SENDCTRL_SEND_ENB)
  1982. dd->sendctrl |= SYM_MASK(SendCtrl, PIOEnable);
  1983. if (op & QIB_SENDCTRL_AVAIL_DIS)
  1984. dd->sendctrl &= ~SYM_MASK(SendCtrl, PIOBufAvailUpd);
  1985. else if (op & QIB_SENDCTRL_AVAIL_ENB)
  1986. dd->sendctrl |= SYM_MASK(SendCtrl, PIOBufAvailUpd);
  1987. if (op & QIB_SENDCTRL_DISARM_ALL) {
  1988. u32 i, last;
  1989. tmp_dd_sendctrl = dd->sendctrl;
  1990. /*
  1991. * disarm any that are not yet launched, disabling sends
  1992. * and updates until done.
  1993. */
  1994. last = dd->piobcnt2k + dd->piobcnt4k;
  1995. tmp_dd_sendctrl &=
  1996. ~(SYM_MASK(SendCtrl, PIOEnable) |
  1997. SYM_MASK(SendCtrl, PIOBufAvailUpd));
  1998. for (i = 0; i < last; i++) {
  1999. qib_write_kreg(dd, kr_sendctrl, tmp_dd_sendctrl |
  2000. SYM_MASK(SendCtrl, Disarm) | i);
  2001. qib_write_kreg(dd, kr_scratch, 0);
  2002. }
  2003. }
  2004. tmp_dd_sendctrl = dd->sendctrl;
  2005. if (op & QIB_SENDCTRL_FLUSH)
  2006. tmp_dd_sendctrl |= SYM_MASK(SendCtrl, Abort);
  2007. if (op & QIB_SENDCTRL_DISARM)
  2008. tmp_dd_sendctrl |= SYM_MASK(SendCtrl, Disarm) |
  2009. ((op & QIB_6120_SendCtrl_DisarmPIOBuf_RMASK) <<
  2010. SYM_LSB(SendCtrl, DisarmPIOBuf));
  2011. if (op & QIB_SENDCTRL_AVAIL_BLIP)
  2012. tmp_dd_sendctrl &= ~SYM_MASK(SendCtrl, PIOBufAvailUpd);
  2013. qib_write_kreg(dd, kr_sendctrl, tmp_dd_sendctrl);
  2014. qib_write_kreg(dd, kr_scratch, 0);
  2015. if (op & QIB_SENDCTRL_AVAIL_BLIP) {
  2016. qib_write_kreg(dd, kr_sendctrl, dd->sendctrl);
  2017. qib_write_kreg(dd, kr_scratch, 0);
  2018. }
  2019. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  2020. if (op & QIB_SENDCTRL_FLUSH) {
  2021. u32 v;
  2022. /*
  2023. * ensure writes have hit chip, then do a few
  2024. * more reads, to allow DMA of pioavail registers
  2025. * to occur, so in-memory copy is in sync with
  2026. * the chip. Not always safe to sleep.
  2027. */
  2028. v = qib_read_kreg32(dd, kr_scratch);
  2029. qib_write_kreg(dd, kr_scratch, v);
  2030. v = qib_read_kreg32(dd, kr_scratch);
  2031. qib_write_kreg(dd, kr_scratch, v);
  2032. qib_read_kreg32(dd, kr_scratch);
  2033. }
  2034. }
  2035. /**
  2036. * qib_portcntr_6120 - read a per-port counter
  2037. * @dd: the qlogic_ib device
  2038. * @creg: the counter to snapshot
  2039. */
  2040. static u64 qib_portcntr_6120(struct qib_pportdata *ppd, u32 reg)
  2041. {
  2042. u64 ret = 0ULL;
  2043. struct qib_devdata *dd = ppd->dd;
  2044. u16 creg;
  2045. /* 0xffff for unimplemented or synthesized counters */
  2046. static const u16 xlator[] = {
  2047. [QIBPORTCNTR_PKTSEND] = cr_pktsend,
  2048. [QIBPORTCNTR_WORDSEND] = cr_wordsend,
  2049. [QIBPORTCNTR_PSXMITDATA] = 0xffff,
  2050. [QIBPORTCNTR_PSXMITPKTS] = 0xffff,
  2051. [QIBPORTCNTR_PSXMITWAIT] = 0xffff,
  2052. [QIBPORTCNTR_SENDSTALL] = cr_sendstall,
  2053. [QIBPORTCNTR_PKTRCV] = cr_pktrcv,
  2054. [QIBPORTCNTR_PSRCVDATA] = 0xffff,
  2055. [QIBPORTCNTR_PSRCVPKTS] = 0xffff,
  2056. [QIBPORTCNTR_RCVEBP] = cr_rcvebp,
  2057. [QIBPORTCNTR_RCVOVFL] = cr_rcvovfl,
  2058. [QIBPORTCNTR_WORDRCV] = cr_wordrcv,
  2059. [QIBPORTCNTR_RXDROPPKT] = cr_rxdroppkt,
  2060. [QIBPORTCNTR_RXLOCALPHYERR] = 0xffff,
  2061. [QIBPORTCNTR_RXVLERR] = 0xffff,
  2062. [QIBPORTCNTR_ERRICRC] = cr_erricrc,
  2063. [QIBPORTCNTR_ERRVCRC] = cr_errvcrc,
  2064. [QIBPORTCNTR_ERRLPCRC] = cr_errlpcrc,
  2065. [QIBPORTCNTR_BADFORMAT] = cr_badformat,
  2066. [QIBPORTCNTR_ERR_RLEN] = cr_err_rlen,
  2067. [QIBPORTCNTR_IBSYMBOLERR] = cr_ibsymbolerr,
  2068. [QIBPORTCNTR_INVALIDRLEN] = cr_invalidrlen,
  2069. [QIBPORTCNTR_UNSUPVL] = cr_txunsupvl,
  2070. [QIBPORTCNTR_EXCESSBUFOVFL] = 0xffff,
  2071. [QIBPORTCNTR_ERRLINK] = cr_errlink,
  2072. [QIBPORTCNTR_IBLINKDOWN] = cr_iblinkdown,
  2073. [QIBPORTCNTR_IBLINKERRRECOV] = cr_iblinkerrrecov,
  2074. [QIBPORTCNTR_LLI] = 0xffff,
  2075. [QIBPORTCNTR_PSINTERVAL] = 0xffff,
  2076. [QIBPORTCNTR_PSSTART] = 0xffff,
  2077. [QIBPORTCNTR_PSSTAT] = 0xffff,
  2078. [QIBPORTCNTR_VL15PKTDROP] = 0xffff,
  2079. [QIBPORTCNTR_ERRPKEY] = cr_errpkey,
  2080. [QIBPORTCNTR_KHDROVFL] = 0xffff,
  2081. };
  2082. if (reg >= ARRAY_SIZE(xlator)) {
  2083. qib_devinfo(ppd->dd->pcidev,
  2084. "Unimplemented portcounter %u\n", reg);
  2085. goto done;
  2086. }
  2087. creg = xlator[reg];
  2088. /* handle counters requests not implemented as chip counters */
  2089. if (reg == QIBPORTCNTR_LLI)
  2090. ret = dd->cspec->lli_errs;
  2091. else if (reg == QIBPORTCNTR_EXCESSBUFOVFL)
  2092. ret = dd->cspec->overrun_thresh_errs;
  2093. else if (reg == QIBPORTCNTR_KHDROVFL) {
  2094. int i;
  2095. /* sum over all kernel contexts */
  2096. for (i = 0; i < dd->first_user_ctxt; i++)
  2097. ret += read_6120_creg32(dd, cr_portovfl + i);
  2098. } else if (reg == QIBPORTCNTR_PSSTAT)
  2099. ret = dd->cspec->pma_sample_status;
  2100. if (creg == 0xffff)
  2101. goto done;
  2102. /*
  2103. * only fast incrementing counters are 64bit; use 32 bit reads to
  2104. * avoid two independent reads when on opteron
  2105. */
  2106. if (creg == cr_wordsend || creg == cr_wordrcv ||
  2107. creg == cr_pktsend || creg == cr_pktrcv)
  2108. ret = read_6120_creg(dd, creg);
  2109. else
  2110. ret = read_6120_creg32(dd, creg);
  2111. if (creg == cr_ibsymbolerr) {
  2112. if (dd->cspec->ibdeltainprog)
  2113. ret -= ret - dd->cspec->ibsymsnap;
  2114. ret -= dd->cspec->ibsymdelta;
  2115. } else if (creg == cr_iblinkerrrecov) {
  2116. if (dd->cspec->ibdeltainprog)
  2117. ret -= ret - dd->cspec->iblnkerrsnap;
  2118. ret -= dd->cspec->iblnkerrdelta;
  2119. }
  2120. if (reg == QIBPORTCNTR_RXDROPPKT) /* add special cased count */
  2121. ret += dd->cspec->rxfc_unsupvl_errs;
  2122. done:
  2123. return ret;
  2124. }
  2125. /*
  2126. * Device counter names (not port-specific), one line per stat,
  2127. * single string. Used by utilities like ipathstats to print the stats
  2128. * in a way which works for different versions of drivers, without changing
  2129. * the utility. Names need to be 12 chars or less (w/o newline), for proper
  2130. * display by utility.
  2131. * Non-error counters are first.
  2132. * Start of "error" conters is indicated by a leading "E " on the first
  2133. * "error" counter, and doesn't count in label length.
  2134. * The EgrOvfl list needs to be last so we truncate them at the configured
  2135. * context count for the device.
  2136. * cntr6120indices contains the corresponding register indices.
  2137. */
  2138. static const char cntr6120names[] =
  2139. "Interrupts\n"
  2140. "HostBusStall\n"
  2141. "E RxTIDFull\n"
  2142. "RxTIDInvalid\n"
  2143. "Ctxt0EgrOvfl\n"
  2144. "Ctxt1EgrOvfl\n"
  2145. "Ctxt2EgrOvfl\n"
  2146. "Ctxt3EgrOvfl\n"
  2147. "Ctxt4EgrOvfl\n";
  2148. static const size_t cntr6120indices[] = {
  2149. cr_lbint,
  2150. cr_lbflowstall,
  2151. cr_errtidfull,
  2152. cr_errtidvalid,
  2153. cr_portovfl + 0,
  2154. cr_portovfl + 1,
  2155. cr_portovfl + 2,
  2156. cr_portovfl + 3,
  2157. cr_portovfl + 4,
  2158. };
  2159. /*
  2160. * same as cntr6120names and cntr6120indices, but for port-specific counters.
  2161. * portcntr6120indices is somewhat complicated by some registers needing
  2162. * adjustments of various kinds, and those are ORed with _PORT_VIRT_FLAG
  2163. */
  2164. static const char portcntr6120names[] =
  2165. "TxPkt\n"
  2166. "TxFlowPkt\n"
  2167. "TxWords\n"
  2168. "RxPkt\n"
  2169. "RxFlowPkt\n"
  2170. "RxWords\n"
  2171. "TxFlowStall\n"
  2172. "E IBStatusChng\n"
  2173. "IBLinkDown\n"
  2174. "IBLnkRecov\n"
  2175. "IBRxLinkErr\n"
  2176. "IBSymbolErr\n"
  2177. "RxLLIErr\n"
  2178. "RxBadFormat\n"
  2179. "RxBadLen\n"
  2180. "RxBufOvrfl\n"
  2181. "RxEBP\n"
  2182. "RxFlowCtlErr\n"
  2183. "RxICRCerr\n"
  2184. "RxLPCRCerr\n"
  2185. "RxVCRCerr\n"
  2186. "RxInvalLen\n"
  2187. "RxInvalPKey\n"
  2188. "RxPktDropped\n"
  2189. "TxBadLength\n"
  2190. "TxDropped\n"
  2191. "TxInvalLen\n"
  2192. "TxUnderrun\n"
  2193. "TxUnsupVL\n"
  2194. ;
  2195. #define _PORT_VIRT_FLAG 0x8000 /* "virtual", need adjustments */
  2196. static const size_t portcntr6120indices[] = {
  2197. QIBPORTCNTR_PKTSEND | _PORT_VIRT_FLAG,
  2198. cr_pktsendflow,
  2199. QIBPORTCNTR_WORDSEND | _PORT_VIRT_FLAG,
  2200. QIBPORTCNTR_PKTRCV | _PORT_VIRT_FLAG,
  2201. cr_pktrcvflowctrl,
  2202. QIBPORTCNTR_WORDRCV | _PORT_VIRT_FLAG,
  2203. QIBPORTCNTR_SENDSTALL | _PORT_VIRT_FLAG,
  2204. cr_ibstatuschange,
  2205. QIBPORTCNTR_IBLINKDOWN | _PORT_VIRT_FLAG,
  2206. QIBPORTCNTR_IBLINKERRRECOV | _PORT_VIRT_FLAG,
  2207. QIBPORTCNTR_ERRLINK | _PORT_VIRT_FLAG,
  2208. QIBPORTCNTR_IBSYMBOLERR | _PORT_VIRT_FLAG,
  2209. QIBPORTCNTR_LLI | _PORT_VIRT_FLAG,
  2210. QIBPORTCNTR_BADFORMAT | _PORT_VIRT_FLAG,
  2211. QIBPORTCNTR_ERR_RLEN | _PORT_VIRT_FLAG,
  2212. QIBPORTCNTR_RCVOVFL | _PORT_VIRT_FLAG,
  2213. QIBPORTCNTR_RCVEBP | _PORT_VIRT_FLAG,
  2214. cr_rcvflowctrl_err,
  2215. QIBPORTCNTR_ERRICRC | _PORT_VIRT_FLAG,
  2216. QIBPORTCNTR_ERRLPCRC | _PORT_VIRT_FLAG,
  2217. QIBPORTCNTR_ERRVCRC | _PORT_VIRT_FLAG,
  2218. QIBPORTCNTR_INVALIDRLEN | _PORT_VIRT_FLAG,
  2219. QIBPORTCNTR_ERRPKEY | _PORT_VIRT_FLAG,
  2220. QIBPORTCNTR_RXDROPPKT | _PORT_VIRT_FLAG,
  2221. cr_invalidslen,
  2222. cr_senddropped,
  2223. cr_errslen,
  2224. cr_sendunderrun,
  2225. cr_txunsupvl,
  2226. };
  2227. /* do all the setup to make the counter reads efficient later */
  2228. static void init_6120_cntrnames(struct qib_devdata *dd)
  2229. {
  2230. int i, j = 0;
  2231. char *s;
  2232. for (i = 0, s = (char *)cntr6120names; s && j <= dd->cfgctxts;
  2233. i++) {
  2234. /* we always have at least one counter before the egrovfl */
  2235. if (!j && !strncmp("Ctxt0EgrOvfl", s + 1, 12))
  2236. j = 1;
  2237. s = strchr(s + 1, '\n');
  2238. if (s && j)
  2239. j++;
  2240. }
  2241. dd->cspec->ncntrs = i;
  2242. if (!s)
  2243. /* full list; size is without terminating null */
  2244. dd->cspec->cntrnamelen = sizeof(cntr6120names) - 1;
  2245. else
  2246. dd->cspec->cntrnamelen = 1 + s - cntr6120names;
  2247. dd->cspec->cntrs = kmalloc_array(dd->cspec->ncntrs, sizeof(u64),
  2248. GFP_KERNEL);
  2249. for (i = 0, s = (char *)portcntr6120names; s; i++)
  2250. s = strchr(s + 1, '\n');
  2251. dd->cspec->nportcntrs = i - 1;
  2252. dd->cspec->portcntrnamelen = sizeof(portcntr6120names) - 1;
  2253. dd->cspec->portcntrs = kmalloc_array(dd->cspec->nportcntrs,
  2254. sizeof(u64),
  2255. GFP_KERNEL);
  2256. }
  2257. static u32 qib_read_6120cntrs(struct qib_devdata *dd, loff_t pos, char **namep,
  2258. u64 **cntrp)
  2259. {
  2260. u32 ret;
  2261. if (namep) {
  2262. ret = dd->cspec->cntrnamelen;
  2263. if (pos >= ret)
  2264. ret = 0; /* final read after getting everything */
  2265. else
  2266. *namep = (char *)cntr6120names;
  2267. } else {
  2268. u64 *cntr = dd->cspec->cntrs;
  2269. int i;
  2270. ret = dd->cspec->ncntrs * sizeof(u64);
  2271. if (!cntr || pos >= ret) {
  2272. /* everything read, or couldn't get memory */
  2273. ret = 0;
  2274. goto done;
  2275. }
  2276. if (pos >= ret) {
  2277. ret = 0; /* final read after getting everything */
  2278. goto done;
  2279. }
  2280. *cntrp = cntr;
  2281. for (i = 0; i < dd->cspec->ncntrs; i++)
  2282. *cntr++ = read_6120_creg32(dd, cntr6120indices[i]);
  2283. }
  2284. done:
  2285. return ret;
  2286. }
  2287. static u32 qib_read_6120portcntrs(struct qib_devdata *dd, loff_t pos, u32 port,
  2288. char **namep, u64 **cntrp)
  2289. {
  2290. u32 ret;
  2291. if (namep) {
  2292. ret = dd->cspec->portcntrnamelen;
  2293. if (pos >= ret)
  2294. ret = 0; /* final read after getting everything */
  2295. else
  2296. *namep = (char *)portcntr6120names;
  2297. } else {
  2298. u64 *cntr = dd->cspec->portcntrs;
  2299. struct qib_pportdata *ppd = &dd->pport[port];
  2300. int i;
  2301. ret = dd->cspec->nportcntrs * sizeof(u64);
  2302. if (!cntr || pos >= ret) {
  2303. /* everything read, or couldn't get memory */
  2304. ret = 0;
  2305. goto done;
  2306. }
  2307. *cntrp = cntr;
  2308. for (i = 0; i < dd->cspec->nportcntrs; i++) {
  2309. if (portcntr6120indices[i] & _PORT_VIRT_FLAG)
  2310. *cntr++ = qib_portcntr_6120(ppd,
  2311. portcntr6120indices[i] &
  2312. ~_PORT_VIRT_FLAG);
  2313. else
  2314. *cntr++ = read_6120_creg32(dd,
  2315. portcntr6120indices[i]);
  2316. }
  2317. }
  2318. done:
  2319. return ret;
  2320. }
  2321. static void qib_chk_6120_errormask(struct qib_devdata *dd)
  2322. {
  2323. static u32 fixed;
  2324. u32 ctrl;
  2325. unsigned long errormask;
  2326. unsigned long hwerrs;
  2327. if (!dd->cspec->errormask || !(dd->flags & QIB_INITTED))
  2328. return;
  2329. errormask = qib_read_kreg64(dd, kr_errmask);
  2330. if (errormask == dd->cspec->errormask)
  2331. return;
  2332. fixed++;
  2333. hwerrs = qib_read_kreg64(dd, kr_hwerrstatus);
  2334. ctrl = qib_read_kreg32(dd, kr_control);
  2335. qib_write_kreg(dd, kr_errmask,
  2336. dd->cspec->errormask);
  2337. if ((hwerrs & dd->cspec->hwerrmask) ||
  2338. (ctrl & QLOGIC_IB_C_FREEZEMODE)) {
  2339. qib_write_kreg(dd, kr_hwerrclear, 0ULL);
  2340. qib_write_kreg(dd, kr_errclear, 0ULL);
  2341. /* force re-interrupt of pending events, just in case */
  2342. qib_write_kreg(dd, kr_intclear, 0ULL);
  2343. qib_devinfo(dd->pcidev,
  2344. "errormask fixed(%u) %lx->%lx, ctrl %x hwerr %lx\n",
  2345. fixed, errormask, (unsigned long)dd->cspec->errormask,
  2346. ctrl, hwerrs);
  2347. }
  2348. }
  2349. /**
  2350. * qib_get_faststats - get word counters from chip before they overflow
  2351. * @opaque - contains a pointer to the qlogic_ib device qib_devdata
  2352. *
  2353. * This needs more work; in particular, decision on whether we really
  2354. * need traffic_wds done the way it is
  2355. * called from add_timer
  2356. */
  2357. static void qib_get_6120_faststats(struct timer_list *t)
  2358. {
  2359. struct qib_devdata *dd = from_timer(dd, t, stats_timer);
  2360. struct qib_pportdata *ppd = dd->pport;
  2361. unsigned long flags;
  2362. u64 traffic_wds;
  2363. /*
  2364. * don't access the chip while running diags, or memory diags can
  2365. * fail
  2366. */
  2367. if (!(dd->flags & QIB_INITTED) || dd->diag_client)
  2368. /* but re-arm the timer, for diags case; won't hurt other */
  2369. goto done;
  2370. /*
  2371. * We now try to maintain an activity timer, based on traffic
  2372. * exceeding a threshold, so we need to check the word-counts
  2373. * even if they are 64-bit.
  2374. */
  2375. traffic_wds = qib_portcntr_6120(ppd, cr_wordsend) +
  2376. qib_portcntr_6120(ppd, cr_wordrcv);
  2377. spin_lock_irqsave(&dd->eep_st_lock, flags);
  2378. traffic_wds -= dd->traffic_wds;
  2379. dd->traffic_wds += traffic_wds;
  2380. spin_unlock_irqrestore(&dd->eep_st_lock, flags);
  2381. qib_chk_6120_errormask(dd);
  2382. done:
  2383. mod_timer(&dd->stats_timer, jiffies + HZ * ACTIVITY_TIMER);
  2384. }
  2385. /* no interrupt fallback for these chips */
  2386. static int qib_6120_nointr_fallback(struct qib_devdata *dd)
  2387. {
  2388. return 0;
  2389. }
  2390. /*
  2391. * reset the XGXS (between serdes and IBC). Slightly less intrusive
  2392. * than resetting the IBC or external link state, and useful in some
  2393. * cases to cause some retraining. To do this right, we reset IBC
  2394. * as well.
  2395. */
  2396. static void qib_6120_xgxs_reset(struct qib_pportdata *ppd)
  2397. {
  2398. u64 val, prev_val;
  2399. struct qib_devdata *dd = ppd->dd;
  2400. prev_val = qib_read_kreg64(dd, kr_xgxs_cfg);
  2401. val = prev_val | QLOGIC_IB_XGXS_RESET;
  2402. prev_val &= ~QLOGIC_IB_XGXS_RESET; /* be sure */
  2403. qib_write_kreg(dd, kr_control,
  2404. dd->control & ~QLOGIC_IB_C_LINKENABLE);
  2405. qib_write_kreg(dd, kr_xgxs_cfg, val);
  2406. qib_read_kreg32(dd, kr_scratch);
  2407. qib_write_kreg(dd, kr_xgxs_cfg, prev_val);
  2408. qib_write_kreg(dd, kr_control, dd->control);
  2409. }
  2410. static int qib_6120_get_ib_cfg(struct qib_pportdata *ppd, int which)
  2411. {
  2412. int ret;
  2413. switch (which) {
  2414. case QIB_IB_CFG_LWID:
  2415. ret = ppd->link_width_active;
  2416. break;
  2417. case QIB_IB_CFG_SPD:
  2418. ret = ppd->link_speed_active;
  2419. break;
  2420. case QIB_IB_CFG_LWID_ENB:
  2421. ret = ppd->link_width_enabled;
  2422. break;
  2423. case QIB_IB_CFG_SPD_ENB:
  2424. ret = ppd->link_speed_enabled;
  2425. break;
  2426. case QIB_IB_CFG_OP_VLS:
  2427. ret = ppd->vls_operational;
  2428. break;
  2429. case QIB_IB_CFG_VL_HIGH_CAP:
  2430. ret = 0;
  2431. break;
  2432. case QIB_IB_CFG_VL_LOW_CAP:
  2433. ret = 0;
  2434. break;
  2435. case QIB_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
  2436. ret = SYM_FIELD(ppd->dd->cspec->ibcctrl, IBCCtrl,
  2437. OverrunThreshold);
  2438. break;
  2439. case QIB_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
  2440. ret = SYM_FIELD(ppd->dd->cspec->ibcctrl, IBCCtrl,
  2441. PhyerrThreshold);
  2442. break;
  2443. case QIB_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
  2444. /* will only take effect when the link state changes */
  2445. ret = (ppd->dd->cspec->ibcctrl &
  2446. SYM_MASK(IBCCtrl, LinkDownDefaultState)) ?
  2447. IB_LINKINITCMD_SLEEP : IB_LINKINITCMD_POLL;
  2448. break;
  2449. case QIB_IB_CFG_HRTBT: /* Get Heartbeat off/enable/auto */
  2450. ret = 0; /* no heartbeat on this chip */
  2451. break;
  2452. case QIB_IB_CFG_PMA_TICKS:
  2453. ret = 250; /* 1 usec. */
  2454. break;
  2455. default:
  2456. ret = -EINVAL;
  2457. break;
  2458. }
  2459. return ret;
  2460. }
  2461. /*
  2462. * We assume range checking is already done, if needed.
  2463. */
  2464. static int qib_6120_set_ib_cfg(struct qib_pportdata *ppd, int which, u32 val)
  2465. {
  2466. struct qib_devdata *dd = ppd->dd;
  2467. int ret = 0;
  2468. u64 val64;
  2469. u16 lcmd, licmd;
  2470. switch (which) {
  2471. case QIB_IB_CFG_LWID_ENB:
  2472. ppd->link_width_enabled = val;
  2473. break;
  2474. case QIB_IB_CFG_SPD_ENB:
  2475. ppd->link_speed_enabled = val;
  2476. break;
  2477. case QIB_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
  2478. val64 = SYM_FIELD(dd->cspec->ibcctrl, IBCCtrl,
  2479. OverrunThreshold);
  2480. if (val64 != val) {
  2481. dd->cspec->ibcctrl &=
  2482. ~SYM_MASK(IBCCtrl, OverrunThreshold);
  2483. dd->cspec->ibcctrl |= (u64) val <<
  2484. SYM_LSB(IBCCtrl, OverrunThreshold);
  2485. qib_write_kreg(dd, kr_ibcctrl, dd->cspec->ibcctrl);
  2486. qib_write_kreg(dd, kr_scratch, 0);
  2487. }
  2488. break;
  2489. case QIB_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
  2490. val64 = SYM_FIELD(dd->cspec->ibcctrl, IBCCtrl,
  2491. PhyerrThreshold);
  2492. if (val64 != val) {
  2493. dd->cspec->ibcctrl &=
  2494. ~SYM_MASK(IBCCtrl, PhyerrThreshold);
  2495. dd->cspec->ibcctrl |= (u64) val <<
  2496. SYM_LSB(IBCCtrl, PhyerrThreshold);
  2497. qib_write_kreg(dd, kr_ibcctrl, dd->cspec->ibcctrl);
  2498. qib_write_kreg(dd, kr_scratch, 0);
  2499. }
  2500. break;
  2501. case QIB_IB_CFG_PKEYS: /* update pkeys */
  2502. val64 = (u64) ppd->pkeys[0] | ((u64) ppd->pkeys[1] << 16) |
  2503. ((u64) ppd->pkeys[2] << 32) |
  2504. ((u64) ppd->pkeys[3] << 48);
  2505. qib_write_kreg(dd, kr_partitionkey, val64);
  2506. break;
  2507. case QIB_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
  2508. /* will only take effect when the link state changes */
  2509. if (val == IB_LINKINITCMD_POLL)
  2510. dd->cspec->ibcctrl &=
  2511. ~SYM_MASK(IBCCtrl, LinkDownDefaultState);
  2512. else /* SLEEP */
  2513. dd->cspec->ibcctrl |=
  2514. SYM_MASK(IBCCtrl, LinkDownDefaultState);
  2515. qib_write_kreg(dd, kr_ibcctrl, dd->cspec->ibcctrl);
  2516. qib_write_kreg(dd, kr_scratch, 0);
  2517. break;
  2518. case QIB_IB_CFG_MTU: /* update the MTU in IBC */
  2519. /*
  2520. * Update our housekeeping variables, and set IBC max
  2521. * size, same as init code; max IBC is max we allow in
  2522. * buffer, less the qword pbc, plus 1 for ICRC, in dwords
  2523. * Set even if it's unchanged, print debug message only
  2524. * on changes.
  2525. */
  2526. val = (ppd->ibmaxlen >> 2) + 1;
  2527. dd->cspec->ibcctrl &= ~SYM_MASK(IBCCtrl, MaxPktLen);
  2528. dd->cspec->ibcctrl |= (u64)val <<
  2529. SYM_LSB(IBCCtrl, MaxPktLen);
  2530. qib_write_kreg(dd, kr_ibcctrl, dd->cspec->ibcctrl);
  2531. qib_write_kreg(dd, kr_scratch, 0);
  2532. break;
  2533. case QIB_IB_CFG_LSTATE: /* set the IB link state */
  2534. switch (val & 0xffff0000) {
  2535. case IB_LINKCMD_DOWN:
  2536. lcmd = QLOGIC_IB_IBCC_LINKCMD_DOWN;
  2537. if (!dd->cspec->ibdeltainprog) {
  2538. dd->cspec->ibdeltainprog = 1;
  2539. dd->cspec->ibsymsnap =
  2540. read_6120_creg32(dd, cr_ibsymbolerr);
  2541. dd->cspec->iblnkerrsnap =
  2542. read_6120_creg32(dd, cr_iblinkerrrecov);
  2543. }
  2544. break;
  2545. case IB_LINKCMD_ARMED:
  2546. lcmd = QLOGIC_IB_IBCC_LINKCMD_ARMED;
  2547. break;
  2548. case IB_LINKCMD_ACTIVE:
  2549. lcmd = QLOGIC_IB_IBCC_LINKCMD_ACTIVE;
  2550. break;
  2551. default:
  2552. ret = -EINVAL;
  2553. qib_dev_err(dd, "bad linkcmd req 0x%x\n", val >> 16);
  2554. goto bail;
  2555. }
  2556. switch (val & 0xffff) {
  2557. case IB_LINKINITCMD_NOP:
  2558. licmd = 0;
  2559. break;
  2560. case IB_LINKINITCMD_POLL:
  2561. licmd = QLOGIC_IB_IBCC_LINKINITCMD_POLL;
  2562. break;
  2563. case IB_LINKINITCMD_SLEEP:
  2564. licmd = QLOGIC_IB_IBCC_LINKINITCMD_SLEEP;
  2565. break;
  2566. case IB_LINKINITCMD_DISABLE:
  2567. licmd = QLOGIC_IB_IBCC_LINKINITCMD_DISABLE;
  2568. break;
  2569. default:
  2570. ret = -EINVAL;
  2571. qib_dev_err(dd, "bad linkinitcmd req 0x%x\n",
  2572. val & 0xffff);
  2573. goto bail;
  2574. }
  2575. qib_set_ib_6120_lstate(ppd, lcmd, licmd);
  2576. goto bail;
  2577. case QIB_IB_CFG_HRTBT:
  2578. ret = -EINVAL;
  2579. break;
  2580. default:
  2581. ret = -EINVAL;
  2582. }
  2583. bail:
  2584. return ret;
  2585. }
  2586. static int qib_6120_set_loopback(struct qib_pportdata *ppd, const char *what)
  2587. {
  2588. int ret = 0;
  2589. if (!strncmp(what, "ibc", 3)) {
  2590. ppd->dd->cspec->ibcctrl |= SYM_MASK(IBCCtrl, Loopback);
  2591. qib_devinfo(ppd->dd->pcidev, "Enabling IB%u:%u IBC loopback\n",
  2592. ppd->dd->unit, ppd->port);
  2593. } else if (!strncmp(what, "off", 3)) {
  2594. ppd->dd->cspec->ibcctrl &= ~SYM_MASK(IBCCtrl, Loopback);
  2595. qib_devinfo(ppd->dd->pcidev,
  2596. "Disabling IB%u:%u IBC loopback (normal)\n",
  2597. ppd->dd->unit, ppd->port);
  2598. } else
  2599. ret = -EINVAL;
  2600. if (!ret) {
  2601. qib_write_kreg(ppd->dd, kr_ibcctrl, ppd->dd->cspec->ibcctrl);
  2602. qib_write_kreg(ppd->dd, kr_scratch, 0);
  2603. }
  2604. return ret;
  2605. }
  2606. static void pma_6120_timer(struct timer_list *t)
  2607. {
  2608. struct qib_chip_specific *cs = from_timer(cs, t, pma_timer);
  2609. struct qib_pportdata *ppd = cs->ppd;
  2610. struct qib_ibport *ibp = &ppd->ibport_data;
  2611. unsigned long flags;
  2612. spin_lock_irqsave(&ibp->rvp.lock, flags);
  2613. if (cs->pma_sample_status == IB_PMA_SAMPLE_STATUS_STARTED) {
  2614. cs->pma_sample_status = IB_PMA_SAMPLE_STATUS_RUNNING;
  2615. qib_snapshot_counters(ppd, &cs->sword, &cs->rword,
  2616. &cs->spkts, &cs->rpkts, &cs->xmit_wait);
  2617. mod_timer(&cs->pma_timer,
  2618. jiffies + usecs_to_jiffies(ibp->rvp.pma_sample_interval));
  2619. } else if (cs->pma_sample_status == IB_PMA_SAMPLE_STATUS_RUNNING) {
  2620. u64 ta, tb, tc, td, te;
  2621. cs->pma_sample_status = IB_PMA_SAMPLE_STATUS_DONE;
  2622. qib_snapshot_counters(ppd, &ta, &tb, &tc, &td, &te);
  2623. cs->sword = ta - cs->sword;
  2624. cs->rword = tb - cs->rword;
  2625. cs->spkts = tc - cs->spkts;
  2626. cs->rpkts = td - cs->rpkts;
  2627. cs->xmit_wait = te - cs->xmit_wait;
  2628. }
  2629. spin_unlock_irqrestore(&ibp->rvp.lock, flags);
  2630. }
  2631. /*
  2632. * Note that the caller has the ibp->rvp.lock held.
  2633. */
  2634. static void qib_set_cntr_6120_sample(struct qib_pportdata *ppd, u32 intv,
  2635. u32 start)
  2636. {
  2637. struct qib_chip_specific *cs = ppd->dd->cspec;
  2638. if (start && intv) {
  2639. cs->pma_sample_status = IB_PMA_SAMPLE_STATUS_STARTED;
  2640. mod_timer(&cs->pma_timer, jiffies + usecs_to_jiffies(start));
  2641. } else if (intv) {
  2642. cs->pma_sample_status = IB_PMA_SAMPLE_STATUS_RUNNING;
  2643. qib_snapshot_counters(ppd, &cs->sword, &cs->rword,
  2644. &cs->spkts, &cs->rpkts, &cs->xmit_wait);
  2645. mod_timer(&cs->pma_timer, jiffies + usecs_to_jiffies(intv));
  2646. } else {
  2647. cs->pma_sample_status = IB_PMA_SAMPLE_STATUS_DONE;
  2648. cs->sword = 0;
  2649. cs->rword = 0;
  2650. cs->spkts = 0;
  2651. cs->rpkts = 0;
  2652. cs->xmit_wait = 0;
  2653. }
  2654. }
  2655. static u32 qib_6120_iblink_state(u64 ibcs)
  2656. {
  2657. u32 state = (u32)SYM_FIELD(ibcs, IBCStatus, LinkState);
  2658. switch (state) {
  2659. case IB_6120_L_STATE_INIT:
  2660. state = IB_PORT_INIT;
  2661. break;
  2662. case IB_6120_L_STATE_ARM:
  2663. state = IB_PORT_ARMED;
  2664. break;
  2665. case IB_6120_L_STATE_ACTIVE:
  2666. /* fall through */
  2667. case IB_6120_L_STATE_ACT_DEFER:
  2668. state = IB_PORT_ACTIVE;
  2669. break;
  2670. default: /* fall through */
  2671. case IB_6120_L_STATE_DOWN:
  2672. state = IB_PORT_DOWN;
  2673. break;
  2674. }
  2675. return state;
  2676. }
  2677. /* returns the IBTA port state, rather than the IBC link training state */
  2678. static u8 qib_6120_phys_portstate(u64 ibcs)
  2679. {
  2680. u8 state = (u8)SYM_FIELD(ibcs, IBCStatus, LinkTrainingState);
  2681. return qib_6120_physportstate[state];
  2682. }
  2683. static int qib_6120_ib_updown(struct qib_pportdata *ppd, int ibup, u64 ibcs)
  2684. {
  2685. unsigned long flags;
  2686. spin_lock_irqsave(&ppd->lflags_lock, flags);
  2687. ppd->lflags &= ~QIBL_IB_FORCE_NOTIFY;
  2688. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  2689. if (ibup) {
  2690. if (ppd->dd->cspec->ibdeltainprog) {
  2691. ppd->dd->cspec->ibdeltainprog = 0;
  2692. ppd->dd->cspec->ibsymdelta +=
  2693. read_6120_creg32(ppd->dd, cr_ibsymbolerr) -
  2694. ppd->dd->cspec->ibsymsnap;
  2695. ppd->dd->cspec->iblnkerrdelta +=
  2696. read_6120_creg32(ppd->dd, cr_iblinkerrrecov) -
  2697. ppd->dd->cspec->iblnkerrsnap;
  2698. }
  2699. qib_hol_init(ppd);
  2700. } else {
  2701. ppd->dd->cspec->lli_counter = 0;
  2702. if (!ppd->dd->cspec->ibdeltainprog) {
  2703. ppd->dd->cspec->ibdeltainprog = 1;
  2704. ppd->dd->cspec->ibsymsnap =
  2705. read_6120_creg32(ppd->dd, cr_ibsymbolerr);
  2706. ppd->dd->cspec->iblnkerrsnap =
  2707. read_6120_creg32(ppd->dd, cr_iblinkerrrecov);
  2708. }
  2709. qib_hol_down(ppd);
  2710. }
  2711. qib_6120_setup_setextled(ppd, ibup);
  2712. return 0;
  2713. }
  2714. /* Does read/modify/write to appropriate registers to
  2715. * set output and direction bits selected by mask.
  2716. * these are in their canonical postions (e.g. lsb of
  2717. * dir will end up in D48 of extctrl on existing chips).
  2718. * returns contents of GP Inputs.
  2719. */
  2720. static int gpio_6120_mod(struct qib_devdata *dd, u32 out, u32 dir, u32 mask)
  2721. {
  2722. u64 read_val, new_out;
  2723. unsigned long flags;
  2724. if (mask) {
  2725. /* some bits being written, lock access to GPIO */
  2726. dir &= mask;
  2727. out &= mask;
  2728. spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
  2729. dd->cspec->extctrl &= ~((u64)mask << SYM_LSB(EXTCtrl, GPIOOe));
  2730. dd->cspec->extctrl |= ((u64) dir << SYM_LSB(EXTCtrl, GPIOOe));
  2731. new_out = (dd->cspec->gpio_out & ~mask) | out;
  2732. qib_write_kreg(dd, kr_extctrl, dd->cspec->extctrl);
  2733. qib_write_kreg(dd, kr_gpio_out, new_out);
  2734. dd->cspec->gpio_out = new_out;
  2735. spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
  2736. }
  2737. /*
  2738. * It is unlikely that a read at this time would get valid
  2739. * data on a pin whose direction line was set in the same
  2740. * call to this function. We include the read here because
  2741. * that allows us to potentially combine a change on one pin with
  2742. * a read on another, and because the old code did something like
  2743. * this.
  2744. */
  2745. read_val = qib_read_kreg64(dd, kr_extstatus);
  2746. return SYM_FIELD(read_val, EXTStatus, GPIOIn);
  2747. }
  2748. /*
  2749. * Read fundamental info we need to use the chip. These are
  2750. * the registers that describe chip capabilities, and are
  2751. * saved in shadow registers.
  2752. */
  2753. static void get_6120_chip_params(struct qib_devdata *dd)
  2754. {
  2755. u64 val;
  2756. u32 piobufs;
  2757. int mtu;
  2758. dd->uregbase = qib_read_kreg32(dd, kr_userregbase);
  2759. dd->rcvtidcnt = qib_read_kreg32(dd, kr_rcvtidcnt);
  2760. dd->rcvtidbase = qib_read_kreg32(dd, kr_rcvtidbase);
  2761. dd->rcvegrbase = qib_read_kreg32(dd, kr_rcvegrbase);
  2762. dd->palign = qib_read_kreg32(dd, kr_palign);
  2763. dd->piobufbase = qib_read_kreg64(dd, kr_sendpiobufbase);
  2764. dd->pio2k_bufbase = dd->piobufbase & 0xffffffff;
  2765. dd->rcvhdrcnt = qib_read_kreg32(dd, kr_rcvegrcnt);
  2766. val = qib_read_kreg64(dd, kr_sendpiosize);
  2767. dd->piosize2k = val & ~0U;
  2768. dd->piosize4k = val >> 32;
  2769. mtu = ib_mtu_enum_to_int(qib_ibmtu);
  2770. if (mtu == -1)
  2771. mtu = QIB_DEFAULT_MTU;
  2772. dd->pport->ibmtu = (u32)mtu;
  2773. val = qib_read_kreg64(dd, kr_sendpiobufcnt);
  2774. dd->piobcnt2k = val & ~0U;
  2775. dd->piobcnt4k = val >> 32;
  2776. dd->last_pio = dd->piobcnt4k + dd->piobcnt2k - 1;
  2777. /* these may be adjusted in init_chip_wc_pat() */
  2778. dd->pio2kbase = (u32 __iomem *)
  2779. (((char __iomem *)dd->kregbase) + dd->pio2k_bufbase);
  2780. if (dd->piobcnt4k) {
  2781. dd->pio4kbase = (u32 __iomem *)
  2782. (((char __iomem *) dd->kregbase) +
  2783. (dd->piobufbase >> 32));
  2784. /*
  2785. * 4K buffers take 2 pages; we use roundup just to be
  2786. * paranoid; we calculate it once here, rather than on
  2787. * ever buf allocate
  2788. */
  2789. dd->align4k = ALIGN(dd->piosize4k, dd->palign);
  2790. }
  2791. piobufs = dd->piobcnt4k + dd->piobcnt2k;
  2792. dd->pioavregs = ALIGN(piobufs, sizeof(u64) * BITS_PER_BYTE / 2) /
  2793. (sizeof(u64) * BITS_PER_BYTE / 2);
  2794. }
  2795. /*
  2796. * The chip base addresses in cspec and cpspec have to be set
  2797. * after possible init_chip_wc_pat(), rather than in
  2798. * get_6120_chip_params(), so split out as separate function
  2799. */
  2800. static void set_6120_baseaddrs(struct qib_devdata *dd)
  2801. {
  2802. u32 cregbase;
  2803. cregbase = qib_read_kreg32(dd, kr_counterregbase);
  2804. dd->cspec->cregbase = (u64 __iomem *)
  2805. ((char __iomem *) dd->kregbase + cregbase);
  2806. dd->egrtidbase = (u64 __iomem *)
  2807. ((char __iomem *) dd->kregbase + dd->rcvegrbase);
  2808. }
  2809. /*
  2810. * Write the final few registers that depend on some of the
  2811. * init setup. Done late in init, just before bringing up
  2812. * the serdes.
  2813. */
  2814. static int qib_late_6120_initreg(struct qib_devdata *dd)
  2815. {
  2816. int ret = 0;
  2817. u64 val;
  2818. qib_write_kreg(dd, kr_rcvhdrentsize, dd->rcvhdrentsize);
  2819. qib_write_kreg(dd, kr_rcvhdrsize, dd->rcvhdrsize);
  2820. qib_write_kreg(dd, kr_rcvhdrcnt, dd->rcvhdrcnt);
  2821. qib_write_kreg(dd, kr_sendpioavailaddr, dd->pioavailregs_phys);
  2822. val = qib_read_kreg64(dd, kr_sendpioavailaddr);
  2823. if (val != dd->pioavailregs_phys) {
  2824. qib_dev_err(dd,
  2825. "Catastrophic software error, SendPIOAvailAddr written as %lx, read back as %llx\n",
  2826. (unsigned long) dd->pioavailregs_phys,
  2827. (unsigned long long) val);
  2828. ret = -EINVAL;
  2829. }
  2830. return ret;
  2831. }
  2832. static int init_6120_variables(struct qib_devdata *dd)
  2833. {
  2834. int ret = 0;
  2835. struct qib_pportdata *ppd;
  2836. u32 sbufs;
  2837. ppd = (struct qib_pportdata *)(dd + 1);
  2838. dd->pport = ppd;
  2839. dd->num_pports = 1;
  2840. dd->cspec = (struct qib_chip_specific *)(ppd + dd->num_pports);
  2841. dd->cspec->ppd = ppd;
  2842. ppd->cpspec = NULL; /* not used in this chip */
  2843. spin_lock_init(&dd->cspec->kernel_tid_lock);
  2844. spin_lock_init(&dd->cspec->user_tid_lock);
  2845. spin_lock_init(&dd->cspec->rcvmod_lock);
  2846. spin_lock_init(&dd->cspec->gpio_lock);
  2847. /* we haven't yet set QIB_PRESENT, so use read directly */
  2848. dd->revision = readq(&dd->kregbase[kr_revision]);
  2849. if ((dd->revision & 0xffffffffU) == 0xffffffffU) {
  2850. qib_dev_err(dd,
  2851. "Revision register read failure, giving up initialization\n");
  2852. ret = -ENODEV;
  2853. goto bail;
  2854. }
  2855. dd->flags |= QIB_PRESENT; /* now register routines work */
  2856. dd->majrev = (u8) SYM_FIELD(dd->revision, Revision_R,
  2857. ChipRevMajor);
  2858. dd->minrev = (u8) SYM_FIELD(dd->revision, Revision_R,
  2859. ChipRevMinor);
  2860. get_6120_chip_params(dd);
  2861. pe_boardname(dd); /* fill in boardname */
  2862. /*
  2863. * GPIO bits for TWSI data and clock,
  2864. * used for serial EEPROM.
  2865. */
  2866. dd->gpio_sda_num = _QIB_GPIO_SDA_NUM;
  2867. dd->gpio_scl_num = _QIB_GPIO_SCL_NUM;
  2868. dd->twsi_eeprom_dev = QIB_TWSI_NO_DEV;
  2869. if (qib_unordered_wc())
  2870. dd->flags |= QIB_PIO_FLUSH_WC;
  2871. ret = qib_init_pportdata(ppd, dd, 0, 1);
  2872. if (ret)
  2873. goto bail;
  2874. ppd->link_width_supported = IB_WIDTH_1X | IB_WIDTH_4X;
  2875. ppd->link_speed_supported = QIB_IB_SDR;
  2876. ppd->link_width_enabled = IB_WIDTH_4X;
  2877. ppd->link_speed_enabled = ppd->link_speed_supported;
  2878. /* these can't change for this chip, so set once */
  2879. ppd->link_width_active = ppd->link_width_enabled;
  2880. ppd->link_speed_active = ppd->link_speed_enabled;
  2881. ppd->vls_supported = IB_VL_VL0;
  2882. ppd->vls_operational = ppd->vls_supported;
  2883. dd->rcvhdrentsize = QIB_RCVHDR_ENTSIZE;
  2884. dd->rcvhdrsize = QIB_DFLT_RCVHDRSIZE;
  2885. dd->rhf_offset = 0;
  2886. /* we always allocate at least 2048 bytes for eager buffers */
  2887. ret = ib_mtu_enum_to_int(qib_ibmtu);
  2888. dd->rcvegrbufsize = ret != -1 ? max(ret, 2048) : QIB_DEFAULT_MTU;
  2889. BUG_ON(!is_power_of_2(dd->rcvegrbufsize));
  2890. dd->rcvegrbufsize_shift = ilog2(dd->rcvegrbufsize);
  2891. qib_6120_tidtemplate(dd);
  2892. /*
  2893. * We can request a receive interrupt for 1 or
  2894. * more packets from current offset. For now, we set this
  2895. * up for a single packet.
  2896. */
  2897. dd->rhdrhead_intr_off = 1ULL << 32;
  2898. /* setup the stats timer; the add_timer is done at end of init */
  2899. timer_setup(&dd->stats_timer, qib_get_6120_faststats, 0);
  2900. timer_setup(&dd->cspec->pma_timer, pma_6120_timer, 0);
  2901. dd->ureg_align = qib_read_kreg32(dd, kr_palign);
  2902. dd->piosize2kmax_dwords = dd->piosize2k >> 2;
  2903. qib_6120_config_ctxts(dd);
  2904. qib_set_ctxtcnt(dd);
  2905. ret = init_chip_wc_pat(dd, 0);
  2906. if (ret)
  2907. goto bail;
  2908. set_6120_baseaddrs(dd); /* set chip access pointers now */
  2909. ret = 0;
  2910. if (qib_mini_init)
  2911. goto bail;
  2912. qib_num_cfg_vls = 1; /* if any 6120's, only one VL */
  2913. ret = qib_create_ctxts(dd);
  2914. init_6120_cntrnames(dd);
  2915. /* use all of 4KB buffers for the kernel, otherwise 16 */
  2916. sbufs = dd->piobcnt4k ? dd->piobcnt4k : 16;
  2917. dd->lastctxt_piobuf = dd->piobcnt2k + dd->piobcnt4k - sbufs;
  2918. dd->pbufsctxt = dd->lastctxt_piobuf /
  2919. (dd->cfgctxts - dd->first_user_ctxt);
  2920. if (ret)
  2921. goto bail;
  2922. bail:
  2923. return ret;
  2924. }
  2925. /*
  2926. * For this chip, we want to use the same buffer every time
  2927. * when we are trying to bring the link up (they are always VL15
  2928. * packets). At that link state the packet should always go out immediately
  2929. * (or at least be discarded at the tx interface if the link is down).
  2930. * If it doesn't, and the buffer isn't available, that means some other
  2931. * sender has gotten ahead of us, and is preventing our packet from going
  2932. * out. In that case, we flush all packets, and try again. If that still
  2933. * fails, we fail the request, and hope things work the next time around.
  2934. *
  2935. * We don't need very complicated heuristics on whether the packet had
  2936. * time to go out or not, since even at SDR 1X, it goes out in very short
  2937. * time periods, covered by the chip reads done here and as part of the
  2938. * flush.
  2939. */
  2940. static u32 __iomem *get_6120_link_buf(struct qib_pportdata *ppd, u32 *bnum)
  2941. {
  2942. u32 __iomem *buf;
  2943. u32 lbuf = ppd->dd->piobcnt2k + ppd->dd->piobcnt4k - 1;
  2944. /*
  2945. * always blip to get avail list updated, since it's almost
  2946. * always needed, and is fairly cheap.
  2947. */
  2948. sendctrl_6120_mod(ppd->dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
  2949. qib_read_kreg64(ppd->dd, kr_scratch); /* extra chip flush */
  2950. buf = qib_getsendbuf_range(ppd->dd, bnum, lbuf, lbuf);
  2951. if (buf)
  2952. goto done;
  2953. sendctrl_6120_mod(ppd, QIB_SENDCTRL_DISARM_ALL | QIB_SENDCTRL_FLUSH |
  2954. QIB_SENDCTRL_AVAIL_BLIP);
  2955. ppd->dd->upd_pio_shadow = 1; /* update our idea of what's busy */
  2956. qib_read_kreg64(ppd->dd, kr_scratch); /* extra chip flush */
  2957. buf = qib_getsendbuf_range(ppd->dd, bnum, lbuf, lbuf);
  2958. done:
  2959. return buf;
  2960. }
  2961. static u32 __iomem *qib_6120_getsendbuf(struct qib_pportdata *ppd, u64 pbc,
  2962. u32 *pbufnum)
  2963. {
  2964. u32 first, last, plen = pbc & QIB_PBC_LENGTH_MASK;
  2965. struct qib_devdata *dd = ppd->dd;
  2966. u32 __iomem *buf;
  2967. if (((pbc >> 32) & PBC_6120_VL15_SEND_CTRL) &&
  2968. !(ppd->lflags & (QIBL_IB_AUTONEG_INPROG | QIBL_LINKACTIVE)))
  2969. buf = get_6120_link_buf(ppd, pbufnum);
  2970. else {
  2971. if ((plen + 1) > dd->piosize2kmax_dwords)
  2972. first = dd->piobcnt2k;
  2973. else
  2974. first = 0;
  2975. /* try 4k if all 2k busy, so same last for both sizes */
  2976. last = dd->piobcnt2k + dd->piobcnt4k - 1;
  2977. buf = qib_getsendbuf_range(dd, pbufnum, first, last);
  2978. }
  2979. return buf;
  2980. }
  2981. static int init_sdma_6120_regs(struct qib_pportdata *ppd)
  2982. {
  2983. return -ENODEV;
  2984. }
  2985. static u16 qib_sdma_6120_gethead(struct qib_pportdata *ppd)
  2986. {
  2987. return 0;
  2988. }
  2989. static int qib_sdma_6120_busy(struct qib_pportdata *ppd)
  2990. {
  2991. return 0;
  2992. }
  2993. static void qib_sdma_update_6120_tail(struct qib_pportdata *ppd, u16 tail)
  2994. {
  2995. }
  2996. static void qib_6120_sdma_sendctrl(struct qib_pportdata *ppd, unsigned op)
  2997. {
  2998. }
  2999. static void qib_sdma_set_6120_desc_cnt(struct qib_pportdata *ppd, unsigned cnt)
  3000. {
  3001. }
  3002. /*
  3003. * the pbc doesn't need a VL15 indicator, but we need it for link_buf.
  3004. * The chip ignores the bit if set.
  3005. */
  3006. static u32 qib_6120_setpbc_control(struct qib_pportdata *ppd, u32 plen,
  3007. u8 srate, u8 vl)
  3008. {
  3009. return vl == 15 ? PBC_6120_VL15_SEND_CTRL : 0;
  3010. }
  3011. static void qib_6120_initvl15_bufs(struct qib_devdata *dd)
  3012. {
  3013. }
  3014. static void qib_6120_init_ctxt(struct qib_ctxtdata *rcd)
  3015. {
  3016. rcd->rcvegrcnt = rcd->dd->rcvhdrcnt;
  3017. rcd->rcvegr_tid_base = rcd->ctxt * rcd->rcvegrcnt;
  3018. }
  3019. static void qib_6120_txchk_change(struct qib_devdata *dd, u32 start,
  3020. u32 len, u32 avail, struct qib_ctxtdata *rcd)
  3021. {
  3022. }
  3023. static void writescratch(struct qib_devdata *dd, u32 val)
  3024. {
  3025. (void) qib_write_kreg(dd, kr_scratch, val);
  3026. }
  3027. static int qib_6120_tempsense_rd(struct qib_devdata *dd, int regnum)
  3028. {
  3029. return -ENXIO;
  3030. }
  3031. #ifdef CONFIG_INFINIBAND_QIB_DCA
  3032. static int qib_6120_notify_dca(struct qib_devdata *dd, unsigned long event)
  3033. {
  3034. return 0;
  3035. }
  3036. #endif
  3037. /* Dummy function, as 6120 boards never disable EEPROM Write */
  3038. static int qib_6120_eeprom_wen(struct qib_devdata *dd, int wen)
  3039. {
  3040. return 1;
  3041. }
  3042. /**
  3043. * qib_init_iba6120_funcs - set up the chip-specific function pointers
  3044. * @pdev: pci_dev of the qlogic_ib device
  3045. * @ent: pci_device_id matching this chip
  3046. *
  3047. * This is global, and is called directly at init to set up the
  3048. * chip-specific function pointers for later use.
  3049. *
  3050. * It also allocates/partially-inits the qib_devdata struct for
  3051. * this device.
  3052. */
  3053. struct qib_devdata *qib_init_iba6120_funcs(struct pci_dev *pdev,
  3054. const struct pci_device_id *ent)
  3055. {
  3056. struct qib_devdata *dd;
  3057. int ret;
  3058. dd = qib_alloc_devdata(pdev, sizeof(struct qib_pportdata) +
  3059. sizeof(struct qib_chip_specific));
  3060. if (IS_ERR(dd))
  3061. goto bail;
  3062. dd->f_bringup_serdes = qib_6120_bringup_serdes;
  3063. dd->f_cleanup = qib_6120_setup_cleanup;
  3064. dd->f_clear_tids = qib_6120_clear_tids;
  3065. dd->f_free_irq = qib_free_irq;
  3066. dd->f_get_base_info = qib_6120_get_base_info;
  3067. dd->f_get_msgheader = qib_6120_get_msgheader;
  3068. dd->f_getsendbuf = qib_6120_getsendbuf;
  3069. dd->f_gpio_mod = gpio_6120_mod;
  3070. dd->f_eeprom_wen = qib_6120_eeprom_wen;
  3071. dd->f_hdrqempty = qib_6120_hdrqempty;
  3072. dd->f_ib_updown = qib_6120_ib_updown;
  3073. dd->f_init_ctxt = qib_6120_init_ctxt;
  3074. dd->f_initvl15_bufs = qib_6120_initvl15_bufs;
  3075. dd->f_intr_fallback = qib_6120_nointr_fallback;
  3076. dd->f_late_initreg = qib_late_6120_initreg;
  3077. dd->f_setpbc_control = qib_6120_setpbc_control;
  3078. dd->f_portcntr = qib_portcntr_6120;
  3079. dd->f_put_tid = (dd->minrev >= 2) ?
  3080. qib_6120_put_tid_2 :
  3081. qib_6120_put_tid;
  3082. dd->f_quiet_serdes = qib_6120_quiet_serdes;
  3083. dd->f_rcvctrl = rcvctrl_6120_mod;
  3084. dd->f_read_cntrs = qib_read_6120cntrs;
  3085. dd->f_read_portcntrs = qib_read_6120portcntrs;
  3086. dd->f_reset = qib_6120_setup_reset;
  3087. dd->f_init_sdma_regs = init_sdma_6120_regs;
  3088. dd->f_sdma_busy = qib_sdma_6120_busy;
  3089. dd->f_sdma_gethead = qib_sdma_6120_gethead;
  3090. dd->f_sdma_sendctrl = qib_6120_sdma_sendctrl;
  3091. dd->f_sdma_set_desc_cnt = qib_sdma_set_6120_desc_cnt;
  3092. dd->f_sdma_update_tail = qib_sdma_update_6120_tail;
  3093. dd->f_sendctrl = sendctrl_6120_mod;
  3094. dd->f_set_armlaunch = qib_set_6120_armlaunch;
  3095. dd->f_set_cntr_sample = qib_set_cntr_6120_sample;
  3096. dd->f_iblink_state = qib_6120_iblink_state;
  3097. dd->f_ibphys_portstate = qib_6120_phys_portstate;
  3098. dd->f_get_ib_cfg = qib_6120_get_ib_cfg;
  3099. dd->f_set_ib_cfg = qib_6120_set_ib_cfg;
  3100. dd->f_set_ib_loopback = qib_6120_set_loopback;
  3101. dd->f_set_intr_state = qib_6120_set_intr_state;
  3102. dd->f_setextled = qib_6120_setup_setextled;
  3103. dd->f_txchk_change = qib_6120_txchk_change;
  3104. dd->f_update_usrhead = qib_update_6120_usrhead;
  3105. dd->f_wantpiobuf_intr = qib_wantpiobuf_6120_intr;
  3106. dd->f_xgxs_reset = qib_6120_xgxs_reset;
  3107. dd->f_writescratch = writescratch;
  3108. dd->f_tempsense_rd = qib_6120_tempsense_rd;
  3109. #ifdef CONFIG_INFINIBAND_QIB_DCA
  3110. dd->f_notify_dca = qib_6120_notify_dca;
  3111. #endif
  3112. /*
  3113. * Do remaining pcie setup and save pcie values in dd.
  3114. * Any error printing is already done by the init code.
  3115. * On return, we have the chip mapped and accessible,
  3116. * but chip registers are not set up until start of
  3117. * init_6120_variables.
  3118. */
  3119. ret = qib_pcie_ddinit(dd, pdev, ent);
  3120. if (ret < 0)
  3121. goto bail_free;
  3122. /* initialize chip-specific variables */
  3123. ret = init_6120_variables(dd);
  3124. if (ret)
  3125. goto bail_cleanup;
  3126. if (qib_mini_init)
  3127. goto bail;
  3128. if (qib_pcie_params(dd, 8, NULL))
  3129. qib_dev_err(dd,
  3130. "Failed to setup PCIe or interrupts; continuing anyway\n");
  3131. /* clear diagctrl register, in case diags were running and crashed */
  3132. qib_write_kreg(dd, kr_hwdiagctrl, 0);
  3133. if (qib_read_kreg64(dd, kr_hwerrstatus) &
  3134. QLOGIC_IB_HWE_SERDESPLLFAILED)
  3135. qib_write_kreg(dd, kr_hwerrclear,
  3136. QLOGIC_IB_HWE_SERDESPLLFAILED);
  3137. /* setup interrupt handler (interrupt type handled above) */
  3138. qib_setup_6120_interrupt(dd);
  3139. /* Note that qpn_mask is set by qib_6120_config_ctxts() first */
  3140. qib_6120_init_hwerrors(dd);
  3141. goto bail;
  3142. bail_cleanup:
  3143. qib_pcie_ddcleanup(dd);
  3144. bail_free:
  3145. qib_free_devdata(dd);
  3146. dd = ERR_PTR(ret);
  3147. bail:
  3148. return dd;
  3149. }