qib_iba7220.c 142 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602
  1. /*
  2. * Copyright (c) 2011 - 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 7220 chip (except that specific to the SerDes)
  38. */
  39. #include <linux/interrupt.h>
  40. #include <linux/pci.h>
  41. #include <linux/delay.h>
  42. #include <linux/module.h>
  43. #include <linux/io.h>
  44. #include <rdma/ib_verbs.h>
  45. #include "qib.h"
  46. #include "qib_7220.h"
  47. static void qib_setup_7220_setextled(struct qib_pportdata *, u32);
  48. static void qib_7220_handle_hwerrors(struct qib_devdata *, char *, size_t);
  49. static void sendctrl_7220_mod(struct qib_pportdata *ppd, u32 op);
  50. static u32 qib_7220_iblink_state(u64);
  51. static u8 qib_7220_phys_portstate(u64);
  52. static void qib_sdma_update_7220_tail(struct qib_pportdata *, u16);
  53. static void qib_set_ib_7220_lstate(struct qib_pportdata *, u16, u16);
  54. /*
  55. * This file contains almost all the chip-specific register information and
  56. * access functions for the QLogic QLogic_IB 7220 PCI-Express chip, with the
  57. * exception of SerDes support, which in in qib_sd7220.c.
  58. */
  59. /* Below uses machine-generated qib_chipnum_regs.h file */
  60. #define KREG_IDX(regname) (QIB_7220_##regname##_OFFS / sizeof(u64))
  61. /* Use defines to tie machine-generated names to lower-case names */
  62. #define kr_control KREG_IDX(Control)
  63. #define kr_counterregbase KREG_IDX(CntrRegBase)
  64. #define kr_errclear KREG_IDX(ErrClear)
  65. #define kr_errmask KREG_IDX(ErrMask)
  66. #define kr_errstatus KREG_IDX(ErrStatus)
  67. #define kr_extctrl KREG_IDX(EXTCtrl)
  68. #define kr_extstatus KREG_IDX(EXTStatus)
  69. #define kr_gpio_clear KREG_IDX(GPIOClear)
  70. #define kr_gpio_mask KREG_IDX(GPIOMask)
  71. #define kr_gpio_out KREG_IDX(GPIOOut)
  72. #define kr_gpio_status KREG_IDX(GPIOStatus)
  73. #define kr_hrtbt_guid KREG_IDX(HRTBT_GUID)
  74. #define kr_hwdiagctrl KREG_IDX(HwDiagCtrl)
  75. #define kr_hwerrclear KREG_IDX(HwErrClear)
  76. #define kr_hwerrmask KREG_IDX(HwErrMask)
  77. #define kr_hwerrstatus KREG_IDX(HwErrStatus)
  78. #define kr_ibcctrl KREG_IDX(IBCCtrl)
  79. #define kr_ibcddrctrl KREG_IDX(IBCDDRCtrl)
  80. #define kr_ibcddrstatus KREG_IDX(IBCDDRStatus)
  81. #define kr_ibcstatus KREG_IDX(IBCStatus)
  82. #define kr_ibserdesctrl KREG_IDX(IBSerDesCtrl)
  83. #define kr_intclear KREG_IDX(IntClear)
  84. #define kr_intmask KREG_IDX(IntMask)
  85. #define kr_intstatus KREG_IDX(IntStatus)
  86. #define kr_ncmodectrl KREG_IDX(IBNCModeCtrl)
  87. #define kr_palign KREG_IDX(PageAlign)
  88. #define kr_partitionkey KREG_IDX(RcvPartitionKey)
  89. #define kr_portcnt KREG_IDX(PortCnt)
  90. #define kr_rcvbthqp KREG_IDX(RcvBTHQP)
  91. #define kr_rcvctrl KREG_IDX(RcvCtrl)
  92. #define kr_rcvegrbase KREG_IDX(RcvEgrBase)
  93. #define kr_rcvegrcnt KREG_IDX(RcvEgrCnt)
  94. #define kr_rcvhdrcnt KREG_IDX(RcvHdrCnt)
  95. #define kr_rcvhdrentsize KREG_IDX(RcvHdrEntSize)
  96. #define kr_rcvhdrsize KREG_IDX(RcvHdrSize)
  97. #define kr_rcvpktledcnt KREG_IDX(RcvPktLEDCnt)
  98. #define kr_rcvtidbase KREG_IDX(RcvTIDBase)
  99. #define kr_rcvtidcnt KREG_IDX(RcvTIDCnt)
  100. #define kr_revision KREG_IDX(Revision)
  101. #define kr_scratch KREG_IDX(Scratch)
  102. #define kr_sendbuffererror KREG_IDX(SendBufErr0)
  103. #define kr_sendctrl KREG_IDX(SendCtrl)
  104. #define kr_senddmabase KREG_IDX(SendDmaBase)
  105. #define kr_senddmabufmask0 KREG_IDX(SendDmaBufMask0)
  106. #define kr_senddmabufmask1 (KREG_IDX(SendDmaBufMask0) + 1)
  107. #define kr_senddmabufmask2 (KREG_IDX(SendDmaBufMask0) + 2)
  108. #define kr_senddmahead KREG_IDX(SendDmaHead)
  109. #define kr_senddmaheadaddr KREG_IDX(SendDmaHeadAddr)
  110. #define kr_senddmalengen KREG_IDX(SendDmaLenGen)
  111. #define kr_senddmastatus KREG_IDX(SendDmaStatus)
  112. #define kr_senddmatail KREG_IDX(SendDmaTail)
  113. #define kr_sendpioavailaddr KREG_IDX(SendBufAvailAddr)
  114. #define kr_sendpiobufbase KREG_IDX(SendBufBase)
  115. #define kr_sendpiobufcnt KREG_IDX(SendBufCnt)
  116. #define kr_sendpiosize KREG_IDX(SendBufSize)
  117. #define kr_sendregbase KREG_IDX(SendRegBase)
  118. #define kr_userregbase KREG_IDX(UserRegBase)
  119. #define kr_xgxs_cfg KREG_IDX(XGXSCfg)
  120. /* These must only be written via qib_write_kreg_ctxt() */
  121. #define kr_rcvhdraddr KREG_IDX(RcvHdrAddr0)
  122. #define kr_rcvhdrtailaddr KREG_IDX(RcvHdrTailAddr0)
  123. #define CREG_IDX(regname) ((QIB_7220_##regname##_OFFS - \
  124. QIB_7220_LBIntCnt_OFFS) / sizeof(u64))
  125. #define cr_badformat CREG_IDX(RxVersionErrCnt)
  126. #define cr_erricrc CREG_IDX(RxICRCErrCnt)
  127. #define cr_errlink CREG_IDX(RxLinkMalformCnt)
  128. #define cr_errlpcrc CREG_IDX(RxLPCRCErrCnt)
  129. #define cr_errpkey CREG_IDX(RxPKeyMismatchCnt)
  130. #define cr_rcvflowctrl_err CREG_IDX(RxFlowCtrlViolCnt)
  131. #define cr_err_rlen CREG_IDX(RxLenErrCnt)
  132. #define cr_errslen CREG_IDX(TxLenErrCnt)
  133. #define cr_errtidfull CREG_IDX(RxTIDFullErrCnt)
  134. #define cr_errtidvalid CREG_IDX(RxTIDValidErrCnt)
  135. #define cr_errvcrc CREG_IDX(RxVCRCErrCnt)
  136. #define cr_ibstatuschange CREG_IDX(IBStatusChangeCnt)
  137. #define cr_lbint CREG_IDX(LBIntCnt)
  138. #define cr_invalidrlen CREG_IDX(RxMaxMinLenErrCnt)
  139. #define cr_invalidslen CREG_IDX(TxMaxMinLenErrCnt)
  140. #define cr_lbflowstall CREG_IDX(LBFlowStallCnt)
  141. #define cr_pktrcv CREG_IDX(RxDataPktCnt)
  142. #define cr_pktrcvflowctrl CREG_IDX(RxFlowPktCnt)
  143. #define cr_pktsend CREG_IDX(TxDataPktCnt)
  144. #define cr_pktsendflow CREG_IDX(TxFlowPktCnt)
  145. #define cr_portovfl CREG_IDX(RxP0HdrEgrOvflCnt)
  146. #define cr_rcvebp CREG_IDX(RxEBPCnt)
  147. #define cr_rcvovfl CREG_IDX(RxBufOvflCnt)
  148. #define cr_senddropped CREG_IDX(TxDroppedPktCnt)
  149. #define cr_sendstall CREG_IDX(TxFlowStallCnt)
  150. #define cr_sendunderrun CREG_IDX(TxUnderrunCnt)
  151. #define cr_wordrcv CREG_IDX(RxDwordCnt)
  152. #define cr_wordsend CREG_IDX(TxDwordCnt)
  153. #define cr_txunsupvl CREG_IDX(TxUnsupVLErrCnt)
  154. #define cr_rxdroppkt CREG_IDX(RxDroppedPktCnt)
  155. #define cr_iblinkerrrecov CREG_IDX(IBLinkErrRecoveryCnt)
  156. #define cr_iblinkdown CREG_IDX(IBLinkDownedCnt)
  157. #define cr_ibsymbolerr CREG_IDX(IBSymbolErrCnt)
  158. #define cr_vl15droppedpkt CREG_IDX(RxVL15DroppedPktCnt)
  159. #define cr_rxotherlocalphyerr CREG_IDX(RxOtherLocalPhyErrCnt)
  160. #define cr_excessbufferovfl CREG_IDX(ExcessBufferOvflCnt)
  161. #define cr_locallinkintegrityerr CREG_IDX(LocalLinkIntegrityErrCnt)
  162. #define cr_rxvlerr CREG_IDX(RxVlErrCnt)
  163. #define cr_rxdlidfltr CREG_IDX(RxDlidFltrCnt)
  164. #define cr_psstat CREG_IDX(PSStat)
  165. #define cr_psstart CREG_IDX(PSStart)
  166. #define cr_psinterval CREG_IDX(PSInterval)
  167. #define cr_psrcvdatacount CREG_IDX(PSRcvDataCount)
  168. #define cr_psrcvpktscount CREG_IDX(PSRcvPktsCount)
  169. #define cr_psxmitdatacount CREG_IDX(PSXmitDataCount)
  170. #define cr_psxmitpktscount CREG_IDX(PSXmitPktsCount)
  171. #define cr_psxmitwaitcount CREG_IDX(PSXmitWaitCount)
  172. #define cr_txsdmadesc CREG_IDX(TxSDmaDescCnt)
  173. #define cr_pcieretrydiag CREG_IDX(PcieRetryBufDiagQwordCnt)
  174. #define SYM_RMASK(regname, fldname) ((u64) \
  175. QIB_7220_##regname##_##fldname##_RMASK)
  176. #define SYM_MASK(regname, fldname) ((u64) \
  177. QIB_7220_##regname##_##fldname##_RMASK << \
  178. QIB_7220_##regname##_##fldname##_LSB)
  179. #define SYM_LSB(regname, fldname) (QIB_7220_##regname##_##fldname##_LSB)
  180. #define SYM_FIELD(value, regname, fldname) ((u64) \
  181. (((value) >> SYM_LSB(regname, fldname)) & \
  182. SYM_RMASK(regname, fldname)))
  183. #define ERR_MASK(fldname) SYM_MASK(ErrMask, fldname##Mask)
  184. #define HWE_MASK(fldname) SYM_MASK(HwErrMask, fldname##Mask)
  185. /* ibcctrl bits */
  186. #define QLOGIC_IB_IBCC_LINKINITCMD_DISABLE 1
  187. /* cycle through TS1/TS2 till OK */
  188. #define QLOGIC_IB_IBCC_LINKINITCMD_POLL 2
  189. /* wait for TS1, then go on */
  190. #define QLOGIC_IB_IBCC_LINKINITCMD_SLEEP 3
  191. #define QLOGIC_IB_IBCC_LINKINITCMD_SHIFT 16
  192. #define QLOGIC_IB_IBCC_LINKCMD_DOWN 1 /* move to 0x11 */
  193. #define QLOGIC_IB_IBCC_LINKCMD_ARMED 2 /* move to 0x21 */
  194. #define QLOGIC_IB_IBCC_LINKCMD_ACTIVE 3 /* move to 0x31 */
  195. #define BLOB_7220_IBCHG 0x81
  196. /*
  197. * We could have a single register get/put routine, that takes a group type,
  198. * but this is somewhat clearer and cleaner. It also gives us some error
  199. * checking. 64 bit register reads should always work, but are inefficient
  200. * on opteron (the northbridge always generates 2 separate HT 32 bit reads),
  201. * so we use kreg32 wherever possible. User register and counter register
  202. * reads are always 32 bit reads, so only one form of those routines.
  203. */
  204. /**
  205. * qib_read_ureg32 - read 32-bit virtualized per-context register
  206. * @dd: device
  207. * @regno: register number
  208. * @ctxt: context number
  209. *
  210. * Return the contents of a register that is virtualized to be per context.
  211. * Returns -1 on errors (not distinguishable from valid contents at
  212. * runtime; we may add a separate error variable at some point).
  213. */
  214. static inline u32 qib_read_ureg32(const struct qib_devdata *dd,
  215. enum qib_ureg regno, int ctxt)
  216. {
  217. if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
  218. return 0;
  219. if (dd->userbase)
  220. return readl(regno + (u64 __iomem *)
  221. ((char __iomem *)dd->userbase +
  222. dd->ureg_align * ctxt));
  223. else
  224. return readl(regno + (u64 __iomem *)
  225. (dd->uregbase +
  226. (char __iomem *)dd->kregbase +
  227. dd->ureg_align * ctxt));
  228. }
  229. /**
  230. * qib_write_ureg - write 32-bit virtualized per-context register
  231. * @dd: device
  232. * @regno: register number
  233. * @value: value
  234. * @ctxt: context
  235. *
  236. * Write the contents of a register that is virtualized to be per context.
  237. */
  238. static inline void qib_write_ureg(const struct qib_devdata *dd,
  239. enum qib_ureg regno, u64 value, int ctxt)
  240. {
  241. u64 __iomem *ubase;
  242. if (dd->userbase)
  243. ubase = (u64 __iomem *)
  244. ((char __iomem *) dd->userbase +
  245. dd->ureg_align * ctxt);
  246. else
  247. ubase = (u64 __iomem *)
  248. (dd->uregbase +
  249. (char __iomem *) dd->kregbase +
  250. dd->ureg_align * ctxt);
  251. if (dd->kregbase && (dd->flags & QIB_PRESENT))
  252. writeq(value, &ubase[regno]);
  253. }
  254. /**
  255. * qib_write_kreg_ctxt - write a device's per-ctxt 64-bit kernel register
  256. * @dd: the qlogic_ib device
  257. * @regno: the register number to write
  258. * @ctxt: the context containing the register
  259. * @value: the value to write
  260. */
  261. static inline void qib_write_kreg_ctxt(const struct qib_devdata *dd,
  262. const u16 regno, unsigned ctxt,
  263. u64 value)
  264. {
  265. qib_write_kreg(dd, regno + ctxt, value);
  266. }
  267. static inline void write_7220_creg(const struct qib_devdata *dd,
  268. u16 regno, u64 value)
  269. {
  270. if (dd->cspec->cregbase && (dd->flags & QIB_PRESENT))
  271. writeq(value, &dd->cspec->cregbase[regno]);
  272. }
  273. static inline u64 read_7220_creg(const struct qib_devdata *dd, u16 regno)
  274. {
  275. if (!dd->cspec->cregbase || !(dd->flags & QIB_PRESENT))
  276. return 0;
  277. return readq(&dd->cspec->cregbase[regno]);
  278. }
  279. static inline u32 read_7220_creg32(const struct qib_devdata *dd, u16 regno)
  280. {
  281. if (!dd->cspec->cregbase || !(dd->flags & QIB_PRESENT))
  282. return 0;
  283. return readl(&dd->cspec->cregbase[regno]);
  284. }
  285. /* kr_revision bits */
  286. #define QLOGIC_IB_R_EMULATORREV_MASK ((1ULL << 22) - 1)
  287. #define QLOGIC_IB_R_EMULATORREV_SHIFT 40
  288. /* kr_control bits */
  289. #define QLOGIC_IB_C_RESET (1U << 7)
  290. /* kr_intstatus, kr_intclear, kr_intmask bits */
  291. #define QLOGIC_IB_I_RCVURG_MASK ((1ULL << 17) - 1)
  292. #define QLOGIC_IB_I_RCVURG_SHIFT 32
  293. #define QLOGIC_IB_I_RCVAVAIL_MASK ((1ULL << 17) - 1)
  294. #define QLOGIC_IB_I_RCVAVAIL_SHIFT 0
  295. #define QLOGIC_IB_I_SERDESTRIMDONE (1ULL << 27)
  296. #define QLOGIC_IB_C_FREEZEMODE 0x00000002
  297. #define QLOGIC_IB_C_LINKENABLE 0x00000004
  298. #define QLOGIC_IB_I_SDMAINT 0x8000000000000000ULL
  299. #define QLOGIC_IB_I_SDMADISABLED 0x4000000000000000ULL
  300. #define QLOGIC_IB_I_ERROR 0x0000000080000000ULL
  301. #define QLOGIC_IB_I_SPIOSENT 0x0000000040000000ULL
  302. #define QLOGIC_IB_I_SPIOBUFAVAIL 0x0000000020000000ULL
  303. #define QLOGIC_IB_I_GPIO 0x0000000010000000ULL
  304. /* variables for sanity checking interrupt and errors */
  305. #define QLOGIC_IB_I_BITSEXTANT \
  306. (QLOGIC_IB_I_SDMAINT | QLOGIC_IB_I_SDMADISABLED | \
  307. (QLOGIC_IB_I_RCVURG_MASK << QLOGIC_IB_I_RCVURG_SHIFT) | \
  308. (QLOGIC_IB_I_RCVAVAIL_MASK << \
  309. QLOGIC_IB_I_RCVAVAIL_SHIFT) | \
  310. QLOGIC_IB_I_ERROR | QLOGIC_IB_I_SPIOSENT | \
  311. QLOGIC_IB_I_SPIOBUFAVAIL | QLOGIC_IB_I_GPIO | \
  312. QLOGIC_IB_I_SERDESTRIMDONE)
  313. #define IB_HWE_BITSEXTANT \
  314. (HWE_MASK(RXEMemParityErr) | \
  315. HWE_MASK(TXEMemParityErr) | \
  316. (QLOGIC_IB_HWE_PCIEMEMPARITYERR_MASK << \
  317. QLOGIC_IB_HWE_PCIEMEMPARITYERR_SHIFT) | \
  318. QLOGIC_IB_HWE_PCIE1PLLFAILED | \
  319. QLOGIC_IB_HWE_PCIE0PLLFAILED | \
  320. QLOGIC_IB_HWE_PCIEPOISONEDTLP | \
  321. QLOGIC_IB_HWE_PCIECPLTIMEOUT | \
  322. QLOGIC_IB_HWE_PCIEBUSPARITYXTLH | \
  323. QLOGIC_IB_HWE_PCIEBUSPARITYXADM | \
  324. QLOGIC_IB_HWE_PCIEBUSPARITYRADM | \
  325. HWE_MASK(PowerOnBISTFailed) | \
  326. QLOGIC_IB_HWE_COREPLL_FBSLIP | \
  327. QLOGIC_IB_HWE_COREPLL_RFSLIP | \
  328. QLOGIC_IB_HWE_SERDESPLLFAILED | \
  329. HWE_MASK(IBCBusToSPCParityErr) | \
  330. HWE_MASK(IBCBusFromSPCParityErr) | \
  331. QLOGIC_IB_HWE_PCIECPLDATAQUEUEERR | \
  332. QLOGIC_IB_HWE_PCIECPLHDRQUEUEERR | \
  333. QLOGIC_IB_HWE_SDMAMEMREADERR | \
  334. QLOGIC_IB_HWE_CLK_UC_PLLNOTLOCKED | \
  335. QLOGIC_IB_HWE_PCIESERDESQ0PCLKNOTDETECT | \
  336. QLOGIC_IB_HWE_PCIESERDESQ1PCLKNOTDETECT | \
  337. QLOGIC_IB_HWE_PCIESERDESQ2PCLKNOTDETECT | \
  338. QLOGIC_IB_HWE_PCIESERDESQ3PCLKNOTDETECT | \
  339. QLOGIC_IB_HWE_DDSRXEQMEMORYPARITYERR | \
  340. QLOGIC_IB_HWE_IB_UC_MEMORYPARITYERR | \
  341. QLOGIC_IB_HWE_PCIE_UC_OCT0MEMORYPARITYERR | \
  342. QLOGIC_IB_HWE_PCIE_UC_OCT1MEMORYPARITYERR)
  343. #define IB_E_BITSEXTANT \
  344. (ERR_MASK(RcvFormatErr) | ERR_MASK(RcvVCRCErr) | \
  345. ERR_MASK(RcvICRCErr) | ERR_MASK(RcvMinPktLenErr) | \
  346. ERR_MASK(RcvMaxPktLenErr) | ERR_MASK(RcvLongPktLenErr) | \
  347. ERR_MASK(RcvShortPktLenErr) | ERR_MASK(RcvUnexpectedCharErr) | \
  348. ERR_MASK(RcvUnsupportedVLErr) | ERR_MASK(RcvEBPErr) | \
  349. ERR_MASK(RcvIBFlowErr) | ERR_MASK(RcvBadVersionErr) | \
  350. ERR_MASK(RcvEgrFullErr) | ERR_MASK(RcvHdrFullErr) | \
  351. ERR_MASK(RcvBadTidErr) | ERR_MASK(RcvHdrLenErr) | \
  352. ERR_MASK(RcvHdrErr) | ERR_MASK(RcvIBLostLinkErr) | \
  353. ERR_MASK(SendSpecialTriggerErr) | \
  354. ERR_MASK(SDmaDisabledErr) | ERR_MASK(SendMinPktLenErr) | \
  355. ERR_MASK(SendMaxPktLenErr) | ERR_MASK(SendUnderRunErr) | \
  356. ERR_MASK(SendPktLenErr) | ERR_MASK(SendDroppedSmpPktErr) | \
  357. ERR_MASK(SendDroppedDataPktErr) | \
  358. ERR_MASK(SendPioArmLaunchErr) | \
  359. ERR_MASK(SendUnexpectedPktNumErr) | \
  360. ERR_MASK(SendUnsupportedVLErr) | ERR_MASK(SendBufMisuseErr) | \
  361. ERR_MASK(SDmaGenMismatchErr) | ERR_MASK(SDmaOutOfBoundErr) | \
  362. ERR_MASK(SDmaTailOutOfBoundErr) | ERR_MASK(SDmaBaseErr) | \
  363. ERR_MASK(SDma1stDescErr) | ERR_MASK(SDmaRpyTagErr) | \
  364. ERR_MASK(SDmaDwEnErr) | ERR_MASK(SDmaMissingDwErr) | \
  365. ERR_MASK(SDmaUnexpDataErr) | \
  366. ERR_MASK(IBStatusChanged) | ERR_MASK(InvalidAddrErr) | \
  367. ERR_MASK(ResetNegated) | ERR_MASK(HardwareErr) | \
  368. ERR_MASK(SDmaDescAddrMisalignErr) | \
  369. ERR_MASK(InvalidEEPCmd))
  370. /* kr_hwerrclear, kr_hwerrmask, kr_hwerrstatus, bits */
  371. #define QLOGIC_IB_HWE_PCIEMEMPARITYERR_MASK 0x00000000000000ffULL
  372. #define QLOGIC_IB_HWE_PCIEMEMPARITYERR_SHIFT 0
  373. #define QLOGIC_IB_HWE_PCIEPOISONEDTLP 0x0000000010000000ULL
  374. #define QLOGIC_IB_HWE_PCIECPLTIMEOUT 0x0000000020000000ULL
  375. #define QLOGIC_IB_HWE_PCIEBUSPARITYXTLH 0x0000000040000000ULL
  376. #define QLOGIC_IB_HWE_PCIEBUSPARITYXADM 0x0000000080000000ULL
  377. #define QLOGIC_IB_HWE_PCIEBUSPARITYRADM 0x0000000100000000ULL
  378. #define QLOGIC_IB_HWE_COREPLL_FBSLIP 0x0080000000000000ULL
  379. #define QLOGIC_IB_HWE_COREPLL_RFSLIP 0x0100000000000000ULL
  380. #define QLOGIC_IB_HWE_PCIE1PLLFAILED 0x0400000000000000ULL
  381. #define QLOGIC_IB_HWE_PCIE0PLLFAILED 0x0800000000000000ULL
  382. #define QLOGIC_IB_HWE_SERDESPLLFAILED 0x1000000000000000ULL
  383. /* specific to this chip */
  384. #define QLOGIC_IB_HWE_PCIECPLDATAQUEUEERR 0x0000000000000040ULL
  385. #define QLOGIC_IB_HWE_PCIECPLHDRQUEUEERR 0x0000000000000080ULL
  386. #define QLOGIC_IB_HWE_SDMAMEMREADERR 0x0000000010000000ULL
  387. #define QLOGIC_IB_HWE_CLK_UC_PLLNOTLOCKED 0x2000000000000000ULL
  388. #define QLOGIC_IB_HWE_PCIESERDESQ0PCLKNOTDETECT 0x0100000000000000ULL
  389. #define QLOGIC_IB_HWE_PCIESERDESQ1PCLKNOTDETECT 0x0200000000000000ULL
  390. #define QLOGIC_IB_HWE_PCIESERDESQ2PCLKNOTDETECT 0x0400000000000000ULL
  391. #define QLOGIC_IB_HWE_PCIESERDESQ3PCLKNOTDETECT 0x0800000000000000ULL
  392. #define QLOGIC_IB_HWE_DDSRXEQMEMORYPARITYERR 0x0000008000000000ULL
  393. #define QLOGIC_IB_HWE_IB_UC_MEMORYPARITYERR 0x0000004000000000ULL
  394. #define QLOGIC_IB_HWE_PCIE_UC_OCT0MEMORYPARITYERR 0x0000001000000000ULL
  395. #define QLOGIC_IB_HWE_PCIE_UC_OCT1MEMORYPARITYERR 0x0000002000000000ULL
  396. #define IBA7220_IBCC_LINKCMD_SHIFT 19
  397. /* kr_ibcddrctrl bits */
  398. #define IBA7220_IBC_DLIDLMC_MASK 0xFFFFFFFFUL
  399. #define IBA7220_IBC_DLIDLMC_SHIFT 32
  400. #define IBA7220_IBC_HRTBT_MASK (SYM_RMASK(IBCDDRCtrl, HRTBT_AUTO) | \
  401. SYM_RMASK(IBCDDRCtrl, HRTBT_ENB))
  402. #define IBA7220_IBC_HRTBT_SHIFT SYM_LSB(IBCDDRCtrl, HRTBT_ENB)
  403. #define IBA7220_IBC_LANE_REV_SUPPORTED (1<<8)
  404. #define IBA7220_IBC_LREV_MASK 1
  405. #define IBA7220_IBC_LREV_SHIFT 8
  406. #define IBA7220_IBC_RXPOL_MASK 1
  407. #define IBA7220_IBC_RXPOL_SHIFT 7
  408. #define IBA7220_IBC_WIDTH_SHIFT 5
  409. #define IBA7220_IBC_WIDTH_MASK 0x3
  410. #define IBA7220_IBC_WIDTH_1X_ONLY (0 << IBA7220_IBC_WIDTH_SHIFT)
  411. #define IBA7220_IBC_WIDTH_4X_ONLY (1 << IBA7220_IBC_WIDTH_SHIFT)
  412. #define IBA7220_IBC_WIDTH_AUTONEG (2 << IBA7220_IBC_WIDTH_SHIFT)
  413. #define IBA7220_IBC_SPEED_AUTONEG (1 << 1)
  414. #define IBA7220_IBC_SPEED_SDR (1 << 2)
  415. #define IBA7220_IBC_SPEED_DDR (1 << 3)
  416. #define IBA7220_IBC_SPEED_AUTONEG_MASK (0x7 << 1)
  417. #define IBA7220_IBC_IBTA_1_2_MASK (1)
  418. /* kr_ibcddrstatus */
  419. /* link latency shift is 0, don't bother defining */
  420. #define IBA7220_DDRSTAT_LINKLAT_MASK 0x3ffffff
  421. /* kr_extstatus bits */
  422. #define QLOGIC_IB_EXTS_FREQSEL 0x2
  423. #define QLOGIC_IB_EXTS_SERDESSEL 0x4
  424. #define QLOGIC_IB_EXTS_MEMBIST_ENDTEST 0x0000000000004000
  425. #define QLOGIC_IB_EXTS_MEMBIST_DISABLED 0x0000000000008000
  426. /* kr_xgxsconfig bits */
  427. #define QLOGIC_IB_XGXS_RESET 0x5ULL
  428. #define QLOGIC_IB_XGXS_FC_SAFE (1ULL << 63)
  429. /* kr_rcvpktledcnt */
  430. #define IBA7220_LEDBLINK_ON_SHIFT 32 /* 4ns period on after packet */
  431. #define IBA7220_LEDBLINK_OFF_SHIFT 0 /* 4ns period off before next on */
  432. #define _QIB_GPIO_SDA_NUM 1
  433. #define _QIB_GPIO_SCL_NUM 0
  434. #define QIB_TWSI_EEPROM_DEV 0xA2 /* All Production 7220 cards. */
  435. #define QIB_TWSI_TEMP_DEV 0x98
  436. /* HW counter clock is at 4nsec */
  437. #define QIB_7220_PSXMITWAIT_CHECK_RATE 4000
  438. #define IBA7220_R_INTRAVAIL_SHIFT 17
  439. #define IBA7220_R_PKEY_DIS_SHIFT 34
  440. #define IBA7220_R_TAILUPD_SHIFT 35
  441. #define IBA7220_R_CTXTCFG_SHIFT 36
  442. #define IBA7220_HDRHEAD_PKTINT_SHIFT 32 /* interrupt cnt in upper 32 bits */
  443. /*
  444. * the size bits give us 2^N, in KB units. 0 marks as invalid,
  445. * and 7 is reserved. We currently use only 2KB and 4KB
  446. */
  447. #define IBA7220_TID_SZ_SHIFT 37 /* shift to 3bit size selector */
  448. #define IBA7220_TID_SZ_2K (1UL << IBA7220_TID_SZ_SHIFT) /* 2KB */
  449. #define IBA7220_TID_SZ_4K (2UL << IBA7220_TID_SZ_SHIFT) /* 4KB */
  450. #define IBA7220_TID_PA_SHIFT 11U /* TID addr in chip stored w/o low bits */
  451. #define PBC_7220_VL15_SEND (1ULL << 63) /* pbc; VL15, no credit check */
  452. #define PBC_7220_VL15_SEND_CTRL (1ULL << 31) /* control version of same */
  453. #define AUTONEG_TRIES 5 /* sequential retries to negotiate DDR */
  454. /* packet rate matching delay multiplier */
  455. static u8 rate_to_delay[2][2] = {
  456. /* 1x, 4x */
  457. { 8, 2 }, /* SDR */
  458. { 4, 1 } /* DDR */
  459. };
  460. static u8 ib_rate_to_delay[IB_RATE_120_GBPS + 1] = {
  461. [IB_RATE_2_5_GBPS] = 8,
  462. [IB_RATE_5_GBPS] = 4,
  463. [IB_RATE_10_GBPS] = 2,
  464. [IB_RATE_20_GBPS] = 1
  465. };
  466. #define IBA7220_LINKSPEED_SHIFT SYM_LSB(IBCStatus, LinkSpeedActive)
  467. #define IBA7220_LINKWIDTH_SHIFT SYM_LSB(IBCStatus, LinkWidthActive)
  468. /* link training states, from IBC */
  469. #define IB_7220_LT_STATE_DISABLED 0x00
  470. #define IB_7220_LT_STATE_LINKUP 0x01
  471. #define IB_7220_LT_STATE_POLLACTIVE 0x02
  472. #define IB_7220_LT_STATE_POLLQUIET 0x03
  473. #define IB_7220_LT_STATE_SLEEPDELAY 0x04
  474. #define IB_7220_LT_STATE_SLEEPQUIET 0x05
  475. #define IB_7220_LT_STATE_CFGDEBOUNCE 0x08
  476. #define IB_7220_LT_STATE_CFGRCVFCFG 0x09
  477. #define IB_7220_LT_STATE_CFGWAITRMT 0x0a
  478. #define IB_7220_LT_STATE_CFGIDLE 0x0b
  479. #define IB_7220_LT_STATE_RECOVERRETRAIN 0x0c
  480. #define IB_7220_LT_STATE_RECOVERWAITRMT 0x0e
  481. #define IB_7220_LT_STATE_RECOVERIDLE 0x0f
  482. /* link state machine states from IBC */
  483. #define IB_7220_L_STATE_DOWN 0x0
  484. #define IB_7220_L_STATE_INIT 0x1
  485. #define IB_7220_L_STATE_ARM 0x2
  486. #define IB_7220_L_STATE_ACTIVE 0x3
  487. #define IB_7220_L_STATE_ACT_DEFER 0x4
  488. static const u8 qib_7220_physportstate[0x20] = {
  489. [IB_7220_LT_STATE_DISABLED] = IB_PHYSPORTSTATE_DISABLED,
  490. [IB_7220_LT_STATE_LINKUP] = IB_PHYSPORTSTATE_LINKUP,
  491. [IB_7220_LT_STATE_POLLACTIVE] = IB_PHYSPORTSTATE_POLL,
  492. [IB_7220_LT_STATE_POLLQUIET] = IB_PHYSPORTSTATE_POLL,
  493. [IB_7220_LT_STATE_SLEEPDELAY] = IB_PHYSPORTSTATE_SLEEP,
  494. [IB_7220_LT_STATE_SLEEPQUIET] = IB_PHYSPORTSTATE_SLEEP,
  495. [IB_7220_LT_STATE_CFGDEBOUNCE] =
  496. IB_PHYSPORTSTATE_CFG_TRAIN,
  497. [IB_7220_LT_STATE_CFGRCVFCFG] =
  498. IB_PHYSPORTSTATE_CFG_TRAIN,
  499. [IB_7220_LT_STATE_CFGWAITRMT] =
  500. IB_PHYSPORTSTATE_CFG_TRAIN,
  501. [IB_7220_LT_STATE_CFGIDLE] = IB_PHYSPORTSTATE_CFG_TRAIN,
  502. [IB_7220_LT_STATE_RECOVERRETRAIN] =
  503. IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
  504. [IB_7220_LT_STATE_RECOVERWAITRMT] =
  505. IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
  506. [IB_7220_LT_STATE_RECOVERIDLE] =
  507. IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
  508. [0x10] = IB_PHYSPORTSTATE_CFG_TRAIN,
  509. [0x11] = IB_PHYSPORTSTATE_CFG_TRAIN,
  510. [0x12] = IB_PHYSPORTSTATE_CFG_TRAIN,
  511. [0x13] = IB_PHYSPORTSTATE_CFG_TRAIN,
  512. [0x14] = IB_PHYSPORTSTATE_CFG_TRAIN,
  513. [0x15] = IB_PHYSPORTSTATE_CFG_TRAIN,
  514. [0x16] = IB_PHYSPORTSTATE_CFG_TRAIN,
  515. [0x17] = IB_PHYSPORTSTATE_CFG_TRAIN
  516. };
  517. int qib_special_trigger;
  518. module_param_named(special_trigger, qib_special_trigger, int, S_IRUGO);
  519. MODULE_PARM_DESC(special_trigger, "Enable SpecialTrigger arm/launch");
  520. #define IBCBUSFRSPCPARITYERR HWE_MASK(IBCBusFromSPCParityErr)
  521. #define IBCBUSTOSPCPARITYERR HWE_MASK(IBCBusToSPCParityErr)
  522. #define SYM_MASK_BIT(regname, fldname, bit) ((u64) \
  523. (1ULL << (SYM_LSB(regname, fldname) + (bit))))
  524. #define TXEMEMPARITYERR_PIOBUF \
  525. SYM_MASK_BIT(HwErrMask, TXEMemParityErrMask, 0)
  526. #define TXEMEMPARITYERR_PIOPBC \
  527. SYM_MASK_BIT(HwErrMask, TXEMemParityErrMask, 1)
  528. #define TXEMEMPARITYERR_PIOLAUNCHFIFO \
  529. SYM_MASK_BIT(HwErrMask, TXEMemParityErrMask, 2)
  530. #define RXEMEMPARITYERR_RCVBUF \
  531. SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 0)
  532. #define RXEMEMPARITYERR_LOOKUPQ \
  533. SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 1)
  534. #define RXEMEMPARITYERR_EXPTID \
  535. SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 2)
  536. #define RXEMEMPARITYERR_EAGERTID \
  537. SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 3)
  538. #define RXEMEMPARITYERR_FLAGBUF \
  539. SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 4)
  540. #define RXEMEMPARITYERR_DATAINFO \
  541. SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 5)
  542. #define RXEMEMPARITYERR_HDRINFO \
  543. SYM_MASK_BIT(HwErrMask, RXEMemParityErrMask, 6)
  544. /* 7220 specific hardware errors... */
  545. static const struct qib_hwerror_msgs qib_7220_hwerror_msgs[] = {
  546. /* generic hardware errors */
  547. QLOGIC_IB_HWE_MSG(IBCBUSFRSPCPARITYERR, "QIB2IB Parity"),
  548. QLOGIC_IB_HWE_MSG(IBCBUSTOSPCPARITYERR, "IB2QIB Parity"),
  549. QLOGIC_IB_HWE_MSG(TXEMEMPARITYERR_PIOBUF,
  550. "TXE PIOBUF Memory Parity"),
  551. QLOGIC_IB_HWE_MSG(TXEMEMPARITYERR_PIOPBC,
  552. "TXE PIOPBC Memory Parity"),
  553. QLOGIC_IB_HWE_MSG(TXEMEMPARITYERR_PIOLAUNCHFIFO,
  554. "TXE PIOLAUNCHFIFO Memory Parity"),
  555. QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_RCVBUF,
  556. "RXE RCVBUF Memory Parity"),
  557. QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_LOOKUPQ,
  558. "RXE LOOKUPQ Memory Parity"),
  559. QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_EAGERTID,
  560. "RXE EAGERTID Memory Parity"),
  561. QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_EXPTID,
  562. "RXE EXPTID Memory Parity"),
  563. QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_FLAGBUF,
  564. "RXE FLAGBUF Memory Parity"),
  565. QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_DATAINFO,
  566. "RXE DATAINFO Memory Parity"),
  567. QLOGIC_IB_HWE_MSG(RXEMEMPARITYERR_HDRINFO,
  568. "RXE HDRINFO Memory Parity"),
  569. /* chip-specific hardware errors */
  570. QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIEPOISONEDTLP,
  571. "PCIe Poisoned TLP"),
  572. QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIECPLTIMEOUT,
  573. "PCIe completion timeout"),
  574. /*
  575. * In practice, it's unlikely wthat we'll see PCIe PLL, or bus
  576. * parity or memory parity error failures, because most likely we
  577. * won't be able to talk to the core of the chip. Nonetheless, we
  578. * might see them, if they are in parts of the PCIe core that aren't
  579. * essential.
  580. */
  581. QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIE1PLLFAILED,
  582. "PCIePLL1"),
  583. QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIE0PLLFAILED,
  584. "PCIePLL0"),
  585. QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIEBUSPARITYXTLH,
  586. "PCIe XTLH core parity"),
  587. QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIEBUSPARITYXADM,
  588. "PCIe ADM TX core parity"),
  589. QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIEBUSPARITYRADM,
  590. "PCIe ADM RX core parity"),
  591. QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_SERDESPLLFAILED,
  592. "SerDes PLL"),
  593. QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIECPLDATAQUEUEERR,
  594. "PCIe cpl header queue"),
  595. QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIECPLHDRQUEUEERR,
  596. "PCIe cpl data queue"),
  597. QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_SDMAMEMREADERR,
  598. "Send DMA memory read"),
  599. QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_CLK_UC_PLLNOTLOCKED,
  600. "uC PLL clock not locked"),
  601. QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIESERDESQ0PCLKNOTDETECT,
  602. "PCIe serdes Q0 no clock"),
  603. QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIESERDESQ1PCLKNOTDETECT,
  604. "PCIe serdes Q1 no clock"),
  605. QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIESERDESQ2PCLKNOTDETECT,
  606. "PCIe serdes Q2 no clock"),
  607. QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIESERDESQ3PCLKNOTDETECT,
  608. "PCIe serdes Q3 no clock"),
  609. QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_DDSRXEQMEMORYPARITYERR,
  610. "DDS RXEQ memory parity"),
  611. QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_IB_UC_MEMORYPARITYERR,
  612. "IB uC memory parity"),
  613. QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIE_UC_OCT0MEMORYPARITYERR,
  614. "PCIe uC oct0 memory parity"),
  615. QLOGIC_IB_HWE_MSG(QLOGIC_IB_HWE_PCIE_UC_OCT1MEMORYPARITYERR,
  616. "PCIe uC oct1 memory parity"),
  617. };
  618. #define RXE_PARITY (RXEMEMPARITYERR_EAGERTID|RXEMEMPARITYERR_EXPTID)
  619. #define QLOGIC_IB_E_PKTERRS (\
  620. ERR_MASK(SendPktLenErr) | \
  621. ERR_MASK(SendDroppedDataPktErr) | \
  622. ERR_MASK(RcvVCRCErr) | \
  623. ERR_MASK(RcvICRCErr) | \
  624. ERR_MASK(RcvShortPktLenErr) | \
  625. ERR_MASK(RcvEBPErr))
  626. /* Convenience for decoding Send DMA errors */
  627. #define QLOGIC_IB_E_SDMAERRS ( \
  628. ERR_MASK(SDmaGenMismatchErr) | \
  629. ERR_MASK(SDmaOutOfBoundErr) | \
  630. ERR_MASK(SDmaTailOutOfBoundErr) | ERR_MASK(SDmaBaseErr) | \
  631. ERR_MASK(SDma1stDescErr) | ERR_MASK(SDmaRpyTagErr) | \
  632. ERR_MASK(SDmaDwEnErr) | ERR_MASK(SDmaMissingDwErr) | \
  633. ERR_MASK(SDmaUnexpDataErr) | \
  634. ERR_MASK(SDmaDescAddrMisalignErr) | \
  635. ERR_MASK(SDmaDisabledErr) | \
  636. ERR_MASK(SendBufMisuseErr))
  637. /* These are all rcv-related errors which we want to count for stats */
  638. #define E_SUM_PKTERRS \
  639. (ERR_MASK(RcvHdrLenErr) | ERR_MASK(RcvBadTidErr) | \
  640. ERR_MASK(RcvBadVersionErr) | ERR_MASK(RcvHdrErr) | \
  641. ERR_MASK(RcvLongPktLenErr) | ERR_MASK(RcvShortPktLenErr) | \
  642. ERR_MASK(RcvMaxPktLenErr) | ERR_MASK(RcvMinPktLenErr) | \
  643. ERR_MASK(RcvFormatErr) | ERR_MASK(RcvUnsupportedVLErr) | \
  644. ERR_MASK(RcvUnexpectedCharErr) | ERR_MASK(RcvEBPErr))
  645. /* These are all send-related errors which we want to count for stats */
  646. #define E_SUM_ERRS \
  647. (ERR_MASK(SendPioArmLaunchErr) | ERR_MASK(SendUnexpectedPktNumErr) | \
  648. ERR_MASK(SendDroppedDataPktErr) | ERR_MASK(SendDroppedSmpPktErr) | \
  649. ERR_MASK(SendMaxPktLenErr) | ERR_MASK(SendUnsupportedVLErr) | \
  650. ERR_MASK(SendMinPktLenErr) | ERR_MASK(SendPktLenErr) | \
  651. ERR_MASK(InvalidAddrErr))
  652. /*
  653. * this is similar to E_SUM_ERRS, but can't ignore armlaunch, don't ignore
  654. * errors not related to freeze and cancelling buffers. Can't ignore
  655. * armlaunch because could get more while still cleaning up, and need
  656. * to cancel those as they happen.
  657. */
  658. #define E_SPKT_ERRS_IGNORE \
  659. (ERR_MASK(SendDroppedDataPktErr) | ERR_MASK(SendDroppedSmpPktErr) | \
  660. ERR_MASK(SendMaxPktLenErr) | ERR_MASK(SendMinPktLenErr) | \
  661. ERR_MASK(SendPktLenErr))
  662. /*
  663. * these are errors that can occur when the link changes state while
  664. * a packet is being sent or received. This doesn't cover things
  665. * like EBP or VCRC that can be the result of a sending having the
  666. * link change state, so we receive a "known bad" packet.
  667. */
  668. #define E_SUM_LINK_PKTERRS \
  669. (ERR_MASK(SendDroppedDataPktErr) | ERR_MASK(SendDroppedSmpPktErr) | \
  670. ERR_MASK(SendMinPktLenErr) | ERR_MASK(SendPktLenErr) | \
  671. ERR_MASK(RcvShortPktLenErr) | ERR_MASK(RcvMinPktLenErr) | \
  672. ERR_MASK(RcvUnexpectedCharErr))
  673. static void autoneg_7220_work(struct work_struct *);
  674. static u32 __iomem *qib_7220_getsendbuf(struct qib_pportdata *, u64, u32 *);
  675. /*
  676. * Called when we might have an error that is specific to a particular
  677. * PIO buffer, and may need to cancel that buffer, so it can be re-used.
  678. * because we don't need to force the update of pioavail.
  679. */
  680. static void qib_disarm_7220_senderrbufs(struct qib_pportdata *ppd)
  681. {
  682. unsigned long sbuf[3];
  683. struct qib_devdata *dd = ppd->dd;
  684. /*
  685. * It's possible that sendbuffererror could have bits set; might
  686. * have already done this as a result of hardware error handling.
  687. */
  688. /* read these before writing errorclear */
  689. sbuf[0] = qib_read_kreg64(dd, kr_sendbuffererror);
  690. sbuf[1] = qib_read_kreg64(dd, kr_sendbuffererror + 1);
  691. sbuf[2] = qib_read_kreg64(dd, kr_sendbuffererror + 2);
  692. if (sbuf[0] || sbuf[1] || sbuf[2])
  693. qib_disarm_piobufs_set(dd, sbuf,
  694. dd->piobcnt2k + dd->piobcnt4k);
  695. }
  696. static void qib_7220_txe_recover(struct qib_devdata *dd)
  697. {
  698. qib_devinfo(dd->pcidev, "Recovering from TXE PIO parity error\n");
  699. qib_disarm_7220_senderrbufs(dd->pport);
  700. }
  701. /*
  702. * This is called with interrupts disabled and sdma_lock held.
  703. */
  704. static void qib_7220_sdma_sendctrl(struct qib_pportdata *ppd, unsigned op)
  705. {
  706. struct qib_devdata *dd = ppd->dd;
  707. u64 set_sendctrl = 0;
  708. u64 clr_sendctrl = 0;
  709. if (op & QIB_SDMA_SENDCTRL_OP_ENABLE)
  710. set_sendctrl |= SYM_MASK(SendCtrl, SDmaEnable);
  711. else
  712. clr_sendctrl |= SYM_MASK(SendCtrl, SDmaEnable);
  713. if (op & QIB_SDMA_SENDCTRL_OP_INTENABLE)
  714. set_sendctrl |= SYM_MASK(SendCtrl, SDmaIntEnable);
  715. else
  716. clr_sendctrl |= SYM_MASK(SendCtrl, SDmaIntEnable);
  717. if (op & QIB_SDMA_SENDCTRL_OP_HALT)
  718. set_sendctrl |= SYM_MASK(SendCtrl, SDmaHalt);
  719. else
  720. clr_sendctrl |= SYM_MASK(SendCtrl, SDmaHalt);
  721. spin_lock(&dd->sendctrl_lock);
  722. dd->sendctrl |= set_sendctrl;
  723. dd->sendctrl &= ~clr_sendctrl;
  724. qib_write_kreg(dd, kr_sendctrl, dd->sendctrl);
  725. qib_write_kreg(dd, kr_scratch, 0);
  726. spin_unlock(&dd->sendctrl_lock);
  727. }
  728. static void qib_decode_7220_sdma_errs(struct qib_pportdata *ppd,
  729. u64 err, char *buf, size_t blen)
  730. {
  731. static const struct {
  732. u64 err;
  733. const char *msg;
  734. } errs[] = {
  735. { ERR_MASK(SDmaGenMismatchErr),
  736. "SDmaGenMismatch" },
  737. { ERR_MASK(SDmaOutOfBoundErr),
  738. "SDmaOutOfBound" },
  739. { ERR_MASK(SDmaTailOutOfBoundErr),
  740. "SDmaTailOutOfBound" },
  741. { ERR_MASK(SDmaBaseErr),
  742. "SDmaBase" },
  743. { ERR_MASK(SDma1stDescErr),
  744. "SDma1stDesc" },
  745. { ERR_MASK(SDmaRpyTagErr),
  746. "SDmaRpyTag" },
  747. { ERR_MASK(SDmaDwEnErr),
  748. "SDmaDwEn" },
  749. { ERR_MASK(SDmaMissingDwErr),
  750. "SDmaMissingDw" },
  751. { ERR_MASK(SDmaUnexpDataErr),
  752. "SDmaUnexpData" },
  753. { ERR_MASK(SDmaDescAddrMisalignErr),
  754. "SDmaDescAddrMisalign" },
  755. { ERR_MASK(SendBufMisuseErr),
  756. "SendBufMisuse" },
  757. { ERR_MASK(SDmaDisabledErr),
  758. "SDmaDisabled" },
  759. };
  760. int i;
  761. size_t bidx = 0;
  762. for (i = 0; i < ARRAY_SIZE(errs); i++) {
  763. if (err & errs[i].err)
  764. bidx += scnprintf(buf + bidx, blen - bidx,
  765. "%s ", errs[i].msg);
  766. }
  767. }
  768. /*
  769. * This is called as part of link down clean up so disarm and flush
  770. * all send buffers so that SMP packets can be sent.
  771. */
  772. static void qib_7220_sdma_hw_clean_up(struct qib_pportdata *ppd)
  773. {
  774. /* This will trigger the Abort interrupt */
  775. sendctrl_7220_mod(ppd, QIB_SENDCTRL_DISARM_ALL | QIB_SENDCTRL_FLUSH |
  776. QIB_SENDCTRL_AVAIL_BLIP);
  777. ppd->dd->upd_pio_shadow = 1; /* update our idea of what's busy */
  778. }
  779. static void qib_sdma_7220_setlengen(struct qib_pportdata *ppd)
  780. {
  781. /*
  782. * Set SendDmaLenGen and clear and set
  783. * the MSB of the generation count to enable generation checking
  784. * and load the internal generation counter.
  785. */
  786. qib_write_kreg(ppd->dd, kr_senddmalengen, ppd->sdma_descq_cnt);
  787. qib_write_kreg(ppd->dd, kr_senddmalengen,
  788. ppd->sdma_descq_cnt |
  789. (1ULL << QIB_7220_SendDmaLenGen_Generation_MSB));
  790. }
  791. static void qib_7220_sdma_hw_start_up(struct qib_pportdata *ppd)
  792. {
  793. qib_sdma_7220_setlengen(ppd);
  794. qib_sdma_update_7220_tail(ppd, 0); /* Set SendDmaTail */
  795. ppd->sdma_head_dma[0] = 0;
  796. }
  797. #define DISABLES_SDMA ( \
  798. ERR_MASK(SDmaDisabledErr) | \
  799. ERR_MASK(SDmaBaseErr) | \
  800. ERR_MASK(SDmaTailOutOfBoundErr) | \
  801. ERR_MASK(SDmaOutOfBoundErr) | \
  802. ERR_MASK(SDma1stDescErr) | \
  803. ERR_MASK(SDmaRpyTagErr) | \
  804. ERR_MASK(SDmaGenMismatchErr) | \
  805. ERR_MASK(SDmaDescAddrMisalignErr) | \
  806. ERR_MASK(SDmaMissingDwErr) | \
  807. ERR_MASK(SDmaDwEnErr))
  808. static void sdma_7220_errors(struct qib_pportdata *ppd, u64 errs)
  809. {
  810. unsigned long flags;
  811. struct qib_devdata *dd = ppd->dd;
  812. char *msg;
  813. errs &= QLOGIC_IB_E_SDMAERRS;
  814. msg = dd->cspec->sdmamsgbuf;
  815. qib_decode_7220_sdma_errs(ppd, errs, msg,
  816. sizeof(dd->cspec->sdmamsgbuf));
  817. spin_lock_irqsave(&ppd->sdma_lock, flags);
  818. if (errs & ERR_MASK(SendBufMisuseErr)) {
  819. unsigned long sbuf[3];
  820. sbuf[0] = qib_read_kreg64(dd, kr_sendbuffererror);
  821. sbuf[1] = qib_read_kreg64(dd, kr_sendbuffererror + 1);
  822. sbuf[2] = qib_read_kreg64(dd, kr_sendbuffererror + 2);
  823. qib_dev_err(ppd->dd,
  824. "IB%u:%u SendBufMisuse: %04lx %016lx %016lx\n",
  825. ppd->dd->unit, ppd->port, sbuf[2], sbuf[1],
  826. sbuf[0]);
  827. }
  828. if (errs & ERR_MASK(SDmaUnexpDataErr))
  829. qib_dev_err(dd, "IB%u:%u SDmaUnexpData\n", ppd->dd->unit,
  830. ppd->port);
  831. switch (ppd->sdma_state.current_state) {
  832. case qib_sdma_state_s00_hw_down:
  833. /* not expecting any interrupts */
  834. break;
  835. case qib_sdma_state_s10_hw_start_up_wait:
  836. /* handled in intr path */
  837. break;
  838. case qib_sdma_state_s20_idle:
  839. /* not expecting any interrupts */
  840. break;
  841. case qib_sdma_state_s30_sw_clean_up_wait:
  842. /* not expecting any interrupts */
  843. break;
  844. case qib_sdma_state_s40_hw_clean_up_wait:
  845. if (errs & ERR_MASK(SDmaDisabledErr))
  846. __qib_sdma_process_event(ppd,
  847. qib_sdma_event_e50_hw_cleaned);
  848. break;
  849. case qib_sdma_state_s50_hw_halt_wait:
  850. /* handled in intr path */
  851. break;
  852. case qib_sdma_state_s99_running:
  853. if (errs & DISABLES_SDMA)
  854. __qib_sdma_process_event(ppd,
  855. qib_sdma_event_e7220_err_halted);
  856. break;
  857. }
  858. spin_unlock_irqrestore(&ppd->sdma_lock, flags);
  859. }
  860. /*
  861. * Decode the error status into strings, deciding whether to always
  862. * print * it or not depending on "normal packet errors" vs everything
  863. * else. Return 1 if "real" errors, otherwise 0 if only packet
  864. * errors, so caller can decide what to print with the string.
  865. */
  866. static int qib_decode_7220_err(struct qib_devdata *dd, char *buf, size_t blen,
  867. u64 err)
  868. {
  869. int iserr = 1;
  870. *buf = '\0';
  871. if (err & QLOGIC_IB_E_PKTERRS) {
  872. if (!(err & ~QLOGIC_IB_E_PKTERRS))
  873. iserr = 0;
  874. if ((err & ERR_MASK(RcvICRCErr)) &&
  875. !(err & (ERR_MASK(RcvVCRCErr) | ERR_MASK(RcvEBPErr))))
  876. strlcat(buf, "CRC ", blen);
  877. if (!iserr)
  878. goto done;
  879. }
  880. if (err & ERR_MASK(RcvHdrLenErr))
  881. strlcat(buf, "rhdrlen ", blen);
  882. if (err & ERR_MASK(RcvBadTidErr))
  883. strlcat(buf, "rbadtid ", blen);
  884. if (err & ERR_MASK(RcvBadVersionErr))
  885. strlcat(buf, "rbadversion ", blen);
  886. if (err & ERR_MASK(RcvHdrErr))
  887. strlcat(buf, "rhdr ", blen);
  888. if (err & ERR_MASK(SendSpecialTriggerErr))
  889. strlcat(buf, "sendspecialtrigger ", blen);
  890. if (err & ERR_MASK(RcvLongPktLenErr))
  891. strlcat(buf, "rlongpktlen ", blen);
  892. if (err & ERR_MASK(RcvMaxPktLenErr))
  893. strlcat(buf, "rmaxpktlen ", blen);
  894. if (err & ERR_MASK(RcvMinPktLenErr))
  895. strlcat(buf, "rminpktlen ", blen);
  896. if (err & ERR_MASK(SendMinPktLenErr))
  897. strlcat(buf, "sminpktlen ", blen);
  898. if (err & ERR_MASK(RcvFormatErr))
  899. strlcat(buf, "rformaterr ", blen);
  900. if (err & ERR_MASK(RcvUnsupportedVLErr))
  901. strlcat(buf, "runsupvl ", blen);
  902. if (err & ERR_MASK(RcvUnexpectedCharErr))
  903. strlcat(buf, "runexpchar ", blen);
  904. if (err & ERR_MASK(RcvIBFlowErr))
  905. strlcat(buf, "ribflow ", blen);
  906. if (err & ERR_MASK(SendUnderRunErr))
  907. strlcat(buf, "sunderrun ", blen);
  908. if (err & ERR_MASK(SendPioArmLaunchErr))
  909. strlcat(buf, "spioarmlaunch ", blen);
  910. if (err & ERR_MASK(SendUnexpectedPktNumErr))
  911. strlcat(buf, "sunexperrpktnum ", blen);
  912. if (err & ERR_MASK(SendDroppedSmpPktErr))
  913. strlcat(buf, "sdroppedsmppkt ", blen);
  914. if (err & ERR_MASK(SendMaxPktLenErr))
  915. strlcat(buf, "smaxpktlen ", blen);
  916. if (err & ERR_MASK(SendUnsupportedVLErr))
  917. strlcat(buf, "sunsupVL ", blen);
  918. if (err & ERR_MASK(InvalidAddrErr))
  919. strlcat(buf, "invalidaddr ", blen);
  920. if (err & ERR_MASK(RcvEgrFullErr))
  921. strlcat(buf, "rcvegrfull ", blen);
  922. if (err & ERR_MASK(RcvHdrFullErr))
  923. strlcat(buf, "rcvhdrfull ", blen);
  924. if (err & ERR_MASK(IBStatusChanged))
  925. strlcat(buf, "ibcstatuschg ", blen);
  926. if (err & ERR_MASK(RcvIBLostLinkErr))
  927. strlcat(buf, "riblostlink ", blen);
  928. if (err & ERR_MASK(HardwareErr))
  929. strlcat(buf, "hardware ", blen);
  930. if (err & ERR_MASK(ResetNegated))
  931. strlcat(buf, "reset ", blen);
  932. if (err & QLOGIC_IB_E_SDMAERRS)
  933. qib_decode_7220_sdma_errs(dd->pport, err, buf, blen);
  934. if (err & ERR_MASK(InvalidEEPCmd))
  935. strlcat(buf, "invalideepromcmd ", blen);
  936. done:
  937. return iserr;
  938. }
  939. static void reenable_7220_chase(struct timer_list *t)
  940. {
  941. struct qib_chippport_specific *cpspec = from_timer(cpspec, t,
  942. chase_timer);
  943. struct qib_pportdata *ppd = &cpspec->pportdata;
  944. ppd->cpspec->chase_timer.expires = 0;
  945. qib_set_ib_7220_lstate(ppd, QLOGIC_IB_IBCC_LINKCMD_DOWN,
  946. QLOGIC_IB_IBCC_LINKINITCMD_POLL);
  947. }
  948. static void handle_7220_chase(struct qib_pportdata *ppd, u64 ibcst)
  949. {
  950. u8 ibclt;
  951. unsigned long tnow;
  952. ibclt = (u8)SYM_FIELD(ibcst, IBCStatus, LinkTrainingState);
  953. /*
  954. * Detect and handle the state chase issue, where we can
  955. * get stuck if we are unlucky on timing on both sides of
  956. * the link. If we are, we disable, set a timer, and
  957. * then re-enable.
  958. */
  959. switch (ibclt) {
  960. case IB_7220_LT_STATE_CFGRCVFCFG:
  961. case IB_7220_LT_STATE_CFGWAITRMT:
  962. case IB_7220_LT_STATE_TXREVLANES:
  963. case IB_7220_LT_STATE_CFGENH:
  964. tnow = jiffies;
  965. if (ppd->cpspec->chase_end &&
  966. time_after(tnow, ppd->cpspec->chase_end)) {
  967. ppd->cpspec->chase_end = 0;
  968. qib_set_ib_7220_lstate(ppd,
  969. QLOGIC_IB_IBCC_LINKCMD_DOWN,
  970. QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
  971. ppd->cpspec->chase_timer.expires = jiffies +
  972. QIB_CHASE_DIS_TIME;
  973. add_timer(&ppd->cpspec->chase_timer);
  974. } else if (!ppd->cpspec->chase_end)
  975. ppd->cpspec->chase_end = tnow + QIB_CHASE_TIME;
  976. break;
  977. default:
  978. ppd->cpspec->chase_end = 0;
  979. break;
  980. }
  981. }
  982. static void handle_7220_errors(struct qib_devdata *dd, u64 errs)
  983. {
  984. char *msg;
  985. u64 ignore_this_time = 0;
  986. u64 iserr = 0;
  987. struct qib_pportdata *ppd = dd->pport;
  988. u64 mask;
  989. /* don't report errors that are masked */
  990. errs &= dd->cspec->errormask;
  991. msg = dd->cspec->emsgbuf;
  992. /* do these first, they are most important */
  993. if (errs & ERR_MASK(HardwareErr))
  994. qib_7220_handle_hwerrors(dd, msg, sizeof(dd->cspec->emsgbuf));
  995. if (errs & QLOGIC_IB_E_SDMAERRS)
  996. sdma_7220_errors(ppd, errs);
  997. if (errs & ~IB_E_BITSEXTANT)
  998. qib_dev_err(dd,
  999. "error interrupt with unknown errors %llx set\n",
  1000. (unsigned long long) (errs & ~IB_E_BITSEXTANT));
  1001. if (errs & E_SUM_ERRS) {
  1002. qib_disarm_7220_senderrbufs(ppd);
  1003. if ((errs & E_SUM_LINK_PKTERRS) &&
  1004. !(ppd->lflags & QIBL_LINKACTIVE)) {
  1005. /*
  1006. * This can happen when trying to bring the link
  1007. * up, but the IB link changes state at the "wrong"
  1008. * time. The IB logic then complains that the packet
  1009. * isn't valid. We don't want to confuse people, so
  1010. * we just don't print them, except at debug
  1011. */
  1012. ignore_this_time = errs & E_SUM_LINK_PKTERRS;
  1013. }
  1014. } else if ((errs & E_SUM_LINK_PKTERRS) &&
  1015. !(ppd->lflags & QIBL_LINKACTIVE)) {
  1016. /*
  1017. * This can happen when SMA is trying to bring the link
  1018. * up, but the IB link changes state at the "wrong" time.
  1019. * The IB logic then complains that the packet isn't
  1020. * valid. We don't want to confuse people, so we just
  1021. * don't print them, except at debug
  1022. */
  1023. ignore_this_time = errs & E_SUM_LINK_PKTERRS;
  1024. }
  1025. qib_write_kreg(dd, kr_errclear, errs);
  1026. errs &= ~ignore_this_time;
  1027. if (!errs)
  1028. goto done;
  1029. /*
  1030. * The ones we mask off are handled specially below
  1031. * or above. Also mask SDMADISABLED by default as it
  1032. * is too chatty.
  1033. */
  1034. mask = ERR_MASK(IBStatusChanged) |
  1035. ERR_MASK(RcvEgrFullErr) | ERR_MASK(RcvHdrFullErr) |
  1036. ERR_MASK(HardwareErr) | ERR_MASK(SDmaDisabledErr);
  1037. qib_decode_7220_err(dd, msg, sizeof(dd->cspec->emsgbuf), errs & ~mask);
  1038. if (errs & E_SUM_PKTERRS)
  1039. qib_stats.sps_rcverrs++;
  1040. if (errs & E_SUM_ERRS)
  1041. qib_stats.sps_txerrs++;
  1042. iserr = errs & ~(E_SUM_PKTERRS | QLOGIC_IB_E_PKTERRS |
  1043. ERR_MASK(SDmaDisabledErr));
  1044. if (errs & ERR_MASK(IBStatusChanged)) {
  1045. u64 ibcs;
  1046. ibcs = qib_read_kreg64(dd, kr_ibcstatus);
  1047. if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG))
  1048. handle_7220_chase(ppd, ibcs);
  1049. /* Update our picture of width and speed from chip */
  1050. ppd->link_width_active =
  1051. ((ibcs >> IBA7220_LINKWIDTH_SHIFT) & 1) ?
  1052. IB_WIDTH_4X : IB_WIDTH_1X;
  1053. ppd->link_speed_active =
  1054. ((ibcs >> IBA7220_LINKSPEED_SHIFT) & 1) ?
  1055. QIB_IB_DDR : QIB_IB_SDR;
  1056. /*
  1057. * Since going into a recovery state causes the link state
  1058. * to go down and since recovery is transitory, it is better
  1059. * if we "miss" ever seeing the link training state go into
  1060. * recovery (i.e., ignore this transition for link state
  1061. * special handling purposes) without updating lastibcstat.
  1062. */
  1063. if (qib_7220_phys_portstate(ibcs) !=
  1064. IB_PHYSPORTSTATE_LINK_ERR_RECOVER)
  1065. qib_handle_e_ibstatuschanged(ppd, ibcs);
  1066. }
  1067. if (errs & ERR_MASK(ResetNegated)) {
  1068. qib_dev_err(dd,
  1069. "Got reset, requires re-init (unload and reload driver)\n");
  1070. dd->flags &= ~QIB_INITTED; /* needs re-init */
  1071. /* mark as having had error */
  1072. *dd->devstatusp |= QIB_STATUS_HWERROR;
  1073. *dd->pport->statusp &= ~QIB_STATUS_IB_CONF;
  1074. }
  1075. if (*msg && iserr)
  1076. qib_dev_porterr(dd, ppd->port, "%s error\n", msg);
  1077. if (ppd->state_wanted & ppd->lflags)
  1078. wake_up_interruptible(&ppd->state_wait);
  1079. /*
  1080. * If there were hdrq or egrfull errors, wake up any processes
  1081. * waiting in poll. We used to try to check which contexts had
  1082. * the overflow, but given the cost of that and the chip reads
  1083. * to support it, it's better to just wake everybody up if we
  1084. * get an overflow; waiters can poll again if it's not them.
  1085. */
  1086. if (errs & (ERR_MASK(RcvEgrFullErr) | ERR_MASK(RcvHdrFullErr))) {
  1087. qib_handle_urcv(dd, ~0U);
  1088. if (errs & ERR_MASK(RcvEgrFullErr))
  1089. qib_stats.sps_buffull++;
  1090. else
  1091. qib_stats.sps_hdrfull++;
  1092. }
  1093. done:
  1094. return;
  1095. }
  1096. /* enable/disable chip from delivering interrupts */
  1097. static void qib_7220_set_intr_state(struct qib_devdata *dd, u32 enable)
  1098. {
  1099. if (enable) {
  1100. if (dd->flags & QIB_BADINTR)
  1101. return;
  1102. qib_write_kreg(dd, kr_intmask, ~0ULL);
  1103. /* force re-interrupt of any pending interrupts. */
  1104. qib_write_kreg(dd, kr_intclear, 0ULL);
  1105. } else
  1106. qib_write_kreg(dd, kr_intmask, 0ULL);
  1107. }
  1108. /*
  1109. * Try to cleanup as much as possible for anything that might have gone
  1110. * wrong while in freeze mode, such as pio buffers being written by user
  1111. * processes (causing armlaunch), send errors due to going into freeze mode,
  1112. * etc., and try to avoid causing extra interrupts while doing so.
  1113. * Forcibly update the in-memory pioavail register copies after cleanup
  1114. * because the chip won't do it while in freeze mode (the register values
  1115. * themselves are kept correct).
  1116. * Make sure that we don't lose any important interrupts by using the chip
  1117. * feature that says that writing 0 to a bit in *clear that is set in
  1118. * *status will cause an interrupt to be generated again (if allowed by
  1119. * the *mask value).
  1120. * This is in chip-specific code because of all of the register accesses,
  1121. * even though the details are similar on most chips.
  1122. */
  1123. static void qib_7220_clear_freeze(struct qib_devdata *dd)
  1124. {
  1125. /* disable error interrupts, to avoid confusion */
  1126. qib_write_kreg(dd, kr_errmask, 0ULL);
  1127. /* also disable interrupts; errormask is sometimes overwritten */
  1128. qib_7220_set_intr_state(dd, 0);
  1129. qib_cancel_sends(dd->pport);
  1130. /* clear the freeze, and be sure chip saw it */
  1131. qib_write_kreg(dd, kr_control, dd->control);
  1132. qib_read_kreg32(dd, kr_scratch);
  1133. /* force in-memory update now we are out of freeze */
  1134. qib_force_pio_avail_update(dd);
  1135. /*
  1136. * force new interrupt if any hwerr, error or interrupt bits are
  1137. * still set, and clear "safe" send packet errors related to freeze
  1138. * and cancelling sends. Re-enable error interrupts before possible
  1139. * force of re-interrupt on pending interrupts.
  1140. */
  1141. qib_write_kreg(dd, kr_hwerrclear, 0ULL);
  1142. qib_write_kreg(dd, kr_errclear, E_SPKT_ERRS_IGNORE);
  1143. qib_write_kreg(dd, kr_errmask, dd->cspec->errormask);
  1144. qib_7220_set_intr_state(dd, 1);
  1145. }
  1146. /**
  1147. * qib_7220_handle_hwerrors - display hardware errors.
  1148. * @dd: the qlogic_ib device
  1149. * @msg: the output buffer
  1150. * @msgl: the size of the output buffer
  1151. *
  1152. * Use same msg buffer as regular errors to avoid excessive stack
  1153. * use. Most hardware errors are catastrophic, but for right now,
  1154. * we'll print them and continue. We reuse the same message buffer as
  1155. * handle_7220_errors() to avoid excessive stack usage.
  1156. */
  1157. static void qib_7220_handle_hwerrors(struct qib_devdata *dd, char *msg,
  1158. size_t msgl)
  1159. {
  1160. u64 hwerrs;
  1161. u32 bits, ctrl;
  1162. int isfatal = 0;
  1163. char *bitsmsg;
  1164. hwerrs = qib_read_kreg64(dd, kr_hwerrstatus);
  1165. if (!hwerrs)
  1166. goto bail;
  1167. if (hwerrs == ~0ULL) {
  1168. qib_dev_err(dd,
  1169. "Read of hardware error status failed (all bits set); ignoring\n");
  1170. goto bail;
  1171. }
  1172. qib_stats.sps_hwerrs++;
  1173. /*
  1174. * Always clear the error status register, except MEMBISTFAIL,
  1175. * regardless of whether we continue or stop using the chip.
  1176. * We want that set so we know it failed, even across driver reload.
  1177. * We'll still ignore it in the hwerrmask. We do this partly for
  1178. * diagnostics, but also for support.
  1179. */
  1180. qib_write_kreg(dd, kr_hwerrclear,
  1181. hwerrs & ~HWE_MASK(PowerOnBISTFailed));
  1182. hwerrs &= dd->cspec->hwerrmask;
  1183. if (hwerrs & ~(TXEMEMPARITYERR_PIOBUF | TXEMEMPARITYERR_PIOPBC |
  1184. RXE_PARITY))
  1185. qib_devinfo(dd->pcidev,
  1186. "Hardware error: hwerr=0x%llx (cleared)\n",
  1187. (unsigned long long) hwerrs);
  1188. if (hwerrs & ~IB_HWE_BITSEXTANT)
  1189. qib_dev_err(dd,
  1190. "hwerror interrupt with unknown errors %llx set\n",
  1191. (unsigned long long) (hwerrs & ~IB_HWE_BITSEXTANT));
  1192. if (hwerrs & QLOGIC_IB_HWE_IB_UC_MEMORYPARITYERR)
  1193. qib_sd7220_clr_ibpar(dd);
  1194. ctrl = qib_read_kreg32(dd, kr_control);
  1195. if ((ctrl & QLOGIC_IB_C_FREEZEMODE) && !dd->diag_client) {
  1196. /*
  1197. * Parity errors in send memory are recoverable by h/w
  1198. * just do housekeeping, exit freeze mode and continue.
  1199. */
  1200. if (hwerrs & (TXEMEMPARITYERR_PIOBUF |
  1201. TXEMEMPARITYERR_PIOPBC)) {
  1202. qib_7220_txe_recover(dd);
  1203. hwerrs &= ~(TXEMEMPARITYERR_PIOBUF |
  1204. TXEMEMPARITYERR_PIOPBC);
  1205. }
  1206. if (hwerrs)
  1207. isfatal = 1;
  1208. else
  1209. qib_7220_clear_freeze(dd);
  1210. }
  1211. *msg = '\0';
  1212. if (hwerrs & HWE_MASK(PowerOnBISTFailed)) {
  1213. isfatal = 1;
  1214. strlcat(msg,
  1215. "[Memory BIST test failed, InfiniPath hardware unusable]",
  1216. msgl);
  1217. /* ignore from now on, so disable until driver reloaded */
  1218. dd->cspec->hwerrmask &= ~HWE_MASK(PowerOnBISTFailed);
  1219. qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
  1220. }
  1221. qib_format_hwerrors(hwerrs, qib_7220_hwerror_msgs,
  1222. ARRAY_SIZE(qib_7220_hwerror_msgs), msg, msgl);
  1223. bitsmsg = dd->cspec->bitsmsgbuf;
  1224. if (hwerrs & (QLOGIC_IB_HWE_PCIEMEMPARITYERR_MASK <<
  1225. QLOGIC_IB_HWE_PCIEMEMPARITYERR_SHIFT)) {
  1226. bits = (u32) ((hwerrs >>
  1227. QLOGIC_IB_HWE_PCIEMEMPARITYERR_SHIFT) &
  1228. QLOGIC_IB_HWE_PCIEMEMPARITYERR_MASK);
  1229. snprintf(bitsmsg, sizeof(dd->cspec->bitsmsgbuf),
  1230. "[PCIe Mem Parity Errs %x] ", bits);
  1231. strlcat(msg, bitsmsg, msgl);
  1232. }
  1233. #define _QIB_PLL_FAIL (QLOGIC_IB_HWE_COREPLL_FBSLIP | \
  1234. QLOGIC_IB_HWE_COREPLL_RFSLIP)
  1235. if (hwerrs & _QIB_PLL_FAIL) {
  1236. isfatal = 1;
  1237. snprintf(bitsmsg, sizeof(dd->cspec->bitsmsgbuf),
  1238. "[PLL failed (%llx), InfiniPath hardware unusable]",
  1239. (unsigned long long) hwerrs & _QIB_PLL_FAIL);
  1240. strlcat(msg, bitsmsg, msgl);
  1241. /* ignore from now on, so disable until driver reloaded */
  1242. dd->cspec->hwerrmask &= ~(hwerrs & _QIB_PLL_FAIL);
  1243. qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
  1244. }
  1245. if (hwerrs & QLOGIC_IB_HWE_SERDESPLLFAILED) {
  1246. /*
  1247. * If it occurs, it is left masked since the eternal
  1248. * interface is unused.
  1249. */
  1250. dd->cspec->hwerrmask &= ~QLOGIC_IB_HWE_SERDESPLLFAILED;
  1251. qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
  1252. }
  1253. qib_dev_err(dd, "%s hardware error\n", msg);
  1254. if (isfatal && !dd->diag_client) {
  1255. qib_dev_err(dd,
  1256. "Fatal Hardware Error, no longer usable, SN %.16s\n",
  1257. dd->serial);
  1258. /*
  1259. * For /sys status file and user programs to print; if no
  1260. * trailing brace is copied, we'll know it was truncated.
  1261. */
  1262. if (dd->freezemsg)
  1263. snprintf(dd->freezemsg, dd->freezelen,
  1264. "{%s}", msg);
  1265. qib_disable_after_error(dd);
  1266. }
  1267. bail:;
  1268. }
  1269. /**
  1270. * qib_7220_init_hwerrors - enable hardware errors
  1271. * @dd: the qlogic_ib device
  1272. *
  1273. * now that we have finished initializing everything that might reasonably
  1274. * cause a hardware error, and cleared those errors bits as they occur,
  1275. * we can enable hardware errors in the mask (potentially enabling
  1276. * freeze mode), and enable hardware errors as errors (along with
  1277. * everything else) in errormask
  1278. */
  1279. static void qib_7220_init_hwerrors(struct qib_devdata *dd)
  1280. {
  1281. u64 val;
  1282. u64 extsval;
  1283. extsval = qib_read_kreg64(dd, kr_extstatus);
  1284. if (!(extsval & (QLOGIC_IB_EXTS_MEMBIST_ENDTEST |
  1285. QLOGIC_IB_EXTS_MEMBIST_DISABLED)))
  1286. qib_dev_err(dd, "MemBIST did not complete!\n");
  1287. if (extsval & QLOGIC_IB_EXTS_MEMBIST_DISABLED)
  1288. qib_devinfo(dd->pcidev, "MemBIST is disabled.\n");
  1289. val = ~0ULL; /* default to all hwerrors become interrupts, */
  1290. val &= ~QLOGIC_IB_HWE_IB_UC_MEMORYPARITYERR;
  1291. dd->cspec->hwerrmask = val;
  1292. qib_write_kreg(dd, kr_hwerrclear, ~HWE_MASK(PowerOnBISTFailed));
  1293. qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
  1294. /* clear all */
  1295. qib_write_kreg(dd, kr_errclear, ~0ULL);
  1296. /* enable errors that are masked, at least this first time. */
  1297. qib_write_kreg(dd, kr_errmask, ~0ULL);
  1298. dd->cspec->errormask = qib_read_kreg64(dd, kr_errmask);
  1299. /* clear any interrupts up to this point (ints still not enabled) */
  1300. qib_write_kreg(dd, kr_intclear, ~0ULL);
  1301. }
  1302. /*
  1303. * Disable and enable the armlaunch error. Used for PIO bandwidth testing
  1304. * on chips that are count-based, rather than trigger-based. There is no
  1305. * reference counting, but that's also fine, given the intended use.
  1306. * Only chip-specific because it's all register accesses
  1307. */
  1308. static void qib_set_7220_armlaunch(struct qib_devdata *dd, u32 enable)
  1309. {
  1310. if (enable) {
  1311. qib_write_kreg(dd, kr_errclear, ERR_MASK(SendPioArmLaunchErr));
  1312. dd->cspec->errormask |= ERR_MASK(SendPioArmLaunchErr);
  1313. } else
  1314. dd->cspec->errormask &= ~ERR_MASK(SendPioArmLaunchErr);
  1315. qib_write_kreg(dd, kr_errmask, dd->cspec->errormask);
  1316. }
  1317. /*
  1318. * Formerly took parameter <which> in pre-shifted,
  1319. * pre-merged form with LinkCmd and LinkInitCmd
  1320. * together, and assuming the zero was NOP.
  1321. */
  1322. static void qib_set_ib_7220_lstate(struct qib_pportdata *ppd, u16 linkcmd,
  1323. u16 linitcmd)
  1324. {
  1325. u64 mod_wd;
  1326. struct qib_devdata *dd = ppd->dd;
  1327. unsigned long flags;
  1328. if (linitcmd == QLOGIC_IB_IBCC_LINKINITCMD_DISABLE) {
  1329. /*
  1330. * If we are told to disable, note that so link-recovery
  1331. * code does not attempt to bring us back up.
  1332. */
  1333. spin_lock_irqsave(&ppd->lflags_lock, flags);
  1334. ppd->lflags |= QIBL_IB_LINK_DISABLED;
  1335. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  1336. } else if (linitcmd || linkcmd == QLOGIC_IB_IBCC_LINKCMD_DOWN) {
  1337. /*
  1338. * Any other linkinitcmd will lead to LINKDOWN and then
  1339. * to INIT (if all is well), so clear flag to let
  1340. * link-recovery code attempt to bring us back up.
  1341. */
  1342. spin_lock_irqsave(&ppd->lflags_lock, flags);
  1343. ppd->lflags &= ~QIBL_IB_LINK_DISABLED;
  1344. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  1345. }
  1346. mod_wd = (linkcmd << IBA7220_IBCC_LINKCMD_SHIFT) |
  1347. (linitcmd << QLOGIC_IB_IBCC_LINKINITCMD_SHIFT);
  1348. qib_write_kreg(dd, kr_ibcctrl, ppd->cpspec->ibcctrl | mod_wd);
  1349. /* write to chip to prevent back-to-back writes of ibc reg */
  1350. qib_write_kreg(dd, kr_scratch, 0);
  1351. }
  1352. /*
  1353. * All detailed interaction with the SerDes has been moved to qib_sd7220.c
  1354. *
  1355. * The portion of IBA7220-specific bringup_serdes() that actually deals with
  1356. * registers and memory within the SerDes itself is qib_sd7220_init().
  1357. */
  1358. /**
  1359. * qib_7220_bringup_serdes - bring up the serdes
  1360. * @ppd: physical port on the qlogic_ib device
  1361. */
  1362. static int qib_7220_bringup_serdes(struct qib_pportdata *ppd)
  1363. {
  1364. struct qib_devdata *dd = ppd->dd;
  1365. u64 val, prev_val, guid, ibc;
  1366. int ret = 0;
  1367. /* Put IBC in reset, sends disabled */
  1368. dd->control &= ~QLOGIC_IB_C_LINKENABLE;
  1369. qib_write_kreg(dd, kr_control, 0ULL);
  1370. if (qib_compat_ddr_negotiate) {
  1371. ppd->cpspec->ibdeltainprog = 1;
  1372. ppd->cpspec->ibsymsnap = read_7220_creg32(dd, cr_ibsymbolerr);
  1373. ppd->cpspec->iblnkerrsnap =
  1374. read_7220_creg32(dd, cr_iblinkerrrecov);
  1375. }
  1376. /* flowcontrolwatermark is in units of KBytes */
  1377. ibc = 0x5ULL << SYM_LSB(IBCCtrl, FlowCtrlWaterMark);
  1378. /*
  1379. * How often flowctrl sent. More or less in usecs; balance against
  1380. * watermark value, so that in theory senders always get a flow
  1381. * control update in time to not let the IB link go idle.
  1382. */
  1383. ibc |= 0x3ULL << SYM_LSB(IBCCtrl, FlowCtrlPeriod);
  1384. /* max error tolerance */
  1385. ibc |= 0xfULL << SYM_LSB(IBCCtrl, PhyerrThreshold);
  1386. /* use "real" buffer space for */
  1387. ibc |= 4ULL << SYM_LSB(IBCCtrl, CreditScale);
  1388. /* IB credit flow control. */
  1389. ibc |= 0xfULL << SYM_LSB(IBCCtrl, OverrunThreshold);
  1390. /*
  1391. * set initial max size pkt IBC will send, including ICRC; it's the
  1392. * PIO buffer size in dwords, less 1; also see qib_set_mtu()
  1393. */
  1394. ibc |= ((u64)(ppd->ibmaxlen >> 2) + 1) << SYM_LSB(IBCCtrl, MaxPktLen);
  1395. ppd->cpspec->ibcctrl = ibc; /* without linkcmd or linkinitcmd! */
  1396. /* initially come up waiting for TS1, without sending anything. */
  1397. val = ppd->cpspec->ibcctrl | (QLOGIC_IB_IBCC_LINKINITCMD_DISABLE <<
  1398. QLOGIC_IB_IBCC_LINKINITCMD_SHIFT);
  1399. qib_write_kreg(dd, kr_ibcctrl, val);
  1400. if (!ppd->cpspec->ibcddrctrl) {
  1401. /* not on re-init after reset */
  1402. ppd->cpspec->ibcddrctrl = qib_read_kreg64(dd, kr_ibcddrctrl);
  1403. if (ppd->link_speed_enabled == (QIB_IB_SDR | QIB_IB_DDR))
  1404. ppd->cpspec->ibcddrctrl |=
  1405. IBA7220_IBC_SPEED_AUTONEG_MASK |
  1406. IBA7220_IBC_IBTA_1_2_MASK;
  1407. else
  1408. ppd->cpspec->ibcddrctrl |=
  1409. ppd->link_speed_enabled == QIB_IB_DDR ?
  1410. IBA7220_IBC_SPEED_DDR : IBA7220_IBC_SPEED_SDR;
  1411. if ((ppd->link_width_enabled & (IB_WIDTH_1X | IB_WIDTH_4X)) ==
  1412. (IB_WIDTH_1X | IB_WIDTH_4X))
  1413. ppd->cpspec->ibcddrctrl |= IBA7220_IBC_WIDTH_AUTONEG;
  1414. else
  1415. ppd->cpspec->ibcddrctrl |=
  1416. ppd->link_width_enabled == IB_WIDTH_4X ?
  1417. IBA7220_IBC_WIDTH_4X_ONLY :
  1418. IBA7220_IBC_WIDTH_1X_ONLY;
  1419. /* always enable these on driver reload, not sticky */
  1420. ppd->cpspec->ibcddrctrl |=
  1421. IBA7220_IBC_RXPOL_MASK << IBA7220_IBC_RXPOL_SHIFT;
  1422. ppd->cpspec->ibcddrctrl |=
  1423. IBA7220_IBC_HRTBT_MASK << IBA7220_IBC_HRTBT_SHIFT;
  1424. /* enable automatic lane reversal detection for receive */
  1425. ppd->cpspec->ibcddrctrl |= IBA7220_IBC_LANE_REV_SUPPORTED;
  1426. } else
  1427. /* write to chip to prevent back-to-back writes of ibc reg */
  1428. qib_write_kreg(dd, kr_scratch, 0);
  1429. qib_write_kreg(dd, kr_ibcddrctrl, ppd->cpspec->ibcddrctrl);
  1430. qib_write_kreg(dd, kr_scratch, 0);
  1431. qib_write_kreg(dd, kr_ncmodectrl, 0Ull);
  1432. qib_write_kreg(dd, kr_scratch, 0);
  1433. ret = qib_sd7220_init(dd);
  1434. val = qib_read_kreg64(dd, kr_xgxs_cfg);
  1435. prev_val = val;
  1436. val |= QLOGIC_IB_XGXS_FC_SAFE;
  1437. if (val != prev_val) {
  1438. qib_write_kreg(dd, kr_xgxs_cfg, val);
  1439. qib_read_kreg32(dd, kr_scratch);
  1440. }
  1441. if (val & QLOGIC_IB_XGXS_RESET)
  1442. val &= ~QLOGIC_IB_XGXS_RESET;
  1443. if (val != prev_val)
  1444. qib_write_kreg(dd, kr_xgxs_cfg, val);
  1445. /* first time through, set port guid */
  1446. if (!ppd->guid)
  1447. ppd->guid = dd->base_guid;
  1448. guid = be64_to_cpu(ppd->guid);
  1449. qib_write_kreg(dd, kr_hrtbt_guid, guid);
  1450. if (!ret) {
  1451. dd->control |= QLOGIC_IB_C_LINKENABLE;
  1452. qib_write_kreg(dd, kr_control, dd->control);
  1453. } else
  1454. /* write to chip to prevent back-to-back writes of ibc reg */
  1455. qib_write_kreg(dd, kr_scratch, 0);
  1456. return ret;
  1457. }
  1458. /**
  1459. * qib_7220_quiet_serdes - set serdes to txidle
  1460. * @ppd: physical port of the qlogic_ib device
  1461. * Called when driver is being unloaded
  1462. */
  1463. static void qib_7220_quiet_serdes(struct qib_pportdata *ppd)
  1464. {
  1465. u64 val;
  1466. struct qib_devdata *dd = ppd->dd;
  1467. unsigned long flags;
  1468. /* disable IBC */
  1469. dd->control &= ~QLOGIC_IB_C_LINKENABLE;
  1470. qib_write_kreg(dd, kr_control,
  1471. dd->control | QLOGIC_IB_C_FREEZEMODE);
  1472. ppd->cpspec->chase_end = 0;
  1473. if (ppd->cpspec->chase_timer.function) /* if initted */
  1474. del_timer_sync(&ppd->cpspec->chase_timer);
  1475. if (ppd->cpspec->ibsymdelta || ppd->cpspec->iblnkerrdelta ||
  1476. ppd->cpspec->ibdeltainprog) {
  1477. u64 diagc;
  1478. /* enable counter writes */
  1479. diagc = qib_read_kreg64(dd, kr_hwdiagctrl);
  1480. qib_write_kreg(dd, kr_hwdiagctrl,
  1481. diagc | SYM_MASK(HwDiagCtrl, CounterWrEnable));
  1482. if (ppd->cpspec->ibsymdelta || ppd->cpspec->ibdeltainprog) {
  1483. val = read_7220_creg32(dd, cr_ibsymbolerr);
  1484. if (ppd->cpspec->ibdeltainprog)
  1485. val -= val - ppd->cpspec->ibsymsnap;
  1486. val -= ppd->cpspec->ibsymdelta;
  1487. write_7220_creg(dd, cr_ibsymbolerr, val);
  1488. }
  1489. if (ppd->cpspec->iblnkerrdelta || ppd->cpspec->ibdeltainprog) {
  1490. val = read_7220_creg32(dd, cr_iblinkerrrecov);
  1491. if (ppd->cpspec->ibdeltainprog)
  1492. val -= val - ppd->cpspec->iblnkerrsnap;
  1493. val -= ppd->cpspec->iblnkerrdelta;
  1494. write_7220_creg(dd, cr_iblinkerrrecov, val);
  1495. }
  1496. /* and disable counter writes */
  1497. qib_write_kreg(dd, kr_hwdiagctrl, diagc);
  1498. }
  1499. qib_set_ib_7220_lstate(ppd, 0, QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
  1500. spin_lock_irqsave(&ppd->lflags_lock, flags);
  1501. ppd->lflags &= ~QIBL_IB_AUTONEG_INPROG;
  1502. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  1503. wake_up(&ppd->cpspec->autoneg_wait);
  1504. cancel_delayed_work_sync(&ppd->cpspec->autoneg_work);
  1505. shutdown_7220_relock_poll(ppd->dd);
  1506. val = qib_read_kreg64(ppd->dd, kr_xgxs_cfg);
  1507. val |= QLOGIC_IB_XGXS_RESET;
  1508. qib_write_kreg(ppd->dd, kr_xgxs_cfg, val);
  1509. }
  1510. /**
  1511. * qib_setup_7220_setextled - set the state of the two external LEDs
  1512. * @dd: the qlogic_ib device
  1513. * @on: whether the link is up or not
  1514. *
  1515. * The exact combo of LEDs if on is true is determined by looking
  1516. * at the ibcstatus.
  1517. *
  1518. * These LEDs indicate the physical and logical state of IB link.
  1519. * For this chip (at least with recommended board pinouts), LED1
  1520. * is Yellow (logical state) and LED2 is Green (physical state),
  1521. *
  1522. * Note: We try to match the Mellanox HCA LED behavior as best
  1523. * we can. Green indicates physical link state is OK (something is
  1524. * plugged in, and we can train).
  1525. * Amber indicates the link is logically up (ACTIVE).
  1526. * Mellanox further blinks the amber LED to indicate data packet
  1527. * activity, but we have no hardware support for that, so it would
  1528. * require waking up every 10-20 msecs and checking the counters
  1529. * on the chip, and then turning the LED off if appropriate. That's
  1530. * visible overhead, so not something we will do.
  1531. *
  1532. */
  1533. static void qib_setup_7220_setextled(struct qib_pportdata *ppd, u32 on)
  1534. {
  1535. struct qib_devdata *dd = ppd->dd;
  1536. u64 extctl, ledblink = 0, val, lst, ltst;
  1537. unsigned long flags;
  1538. /*
  1539. * The diags use the LED to indicate diag info, so we leave
  1540. * the external LED alone when the diags are running.
  1541. */
  1542. if (dd->diag_client)
  1543. return;
  1544. if (ppd->led_override) {
  1545. ltst = (ppd->led_override & QIB_LED_PHYS) ?
  1546. IB_PHYSPORTSTATE_LINKUP : IB_PHYSPORTSTATE_DISABLED,
  1547. lst = (ppd->led_override & QIB_LED_LOG) ?
  1548. IB_PORT_ACTIVE : IB_PORT_DOWN;
  1549. } else if (on) {
  1550. val = qib_read_kreg64(dd, kr_ibcstatus);
  1551. ltst = qib_7220_phys_portstate(val);
  1552. lst = qib_7220_iblink_state(val);
  1553. } else {
  1554. ltst = 0;
  1555. lst = 0;
  1556. }
  1557. spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
  1558. extctl = dd->cspec->extctrl & ~(SYM_MASK(EXTCtrl, LEDPriPortGreenOn) |
  1559. SYM_MASK(EXTCtrl, LEDPriPortYellowOn));
  1560. if (ltst == IB_PHYSPORTSTATE_LINKUP) {
  1561. extctl |= SYM_MASK(EXTCtrl, LEDPriPortGreenOn);
  1562. /*
  1563. * counts are in chip clock (4ns) periods.
  1564. * This is 1/16 sec (66.6ms) on,
  1565. * 3/16 sec (187.5 ms) off, with packets rcvd
  1566. */
  1567. ledblink = ((66600 * 1000UL / 4) << IBA7220_LEDBLINK_ON_SHIFT)
  1568. | ((187500 * 1000UL / 4) << IBA7220_LEDBLINK_OFF_SHIFT);
  1569. }
  1570. if (lst == IB_PORT_ACTIVE)
  1571. extctl |= SYM_MASK(EXTCtrl, LEDPriPortYellowOn);
  1572. dd->cspec->extctrl = extctl;
  1573. qib_write_kreg(dd, kr_extctrl, extctl);
  1574. spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
  1575. if (ledblink) /* blink the LED on packet receive */
  1576. qib_write_kreg(dd, kr_rcvpktledcnt, ledblink);
  1577. }
  1578. /*
  1579. * qib_setup_7220_cleanup - clean up any per-chip chip-specific stuff
  1580. * @dd: the qlogic_ib device
  1581. *
  1582. * This is called during driver unload.
  1583. *
  1584. */
  1585. static void qib_setup_7220_cleanup(struct qib_devdata *dd)
  1586. {
  1587. qib_free_irq(dd);
  1588. kfree(dd->cspec->cntrs);
  1589. kfree(dd->cspec->portcntrs);
  1590. }
  1591. /*
  1592. * This is only called for SDmaInt.
  1593. * SDmaDisabled is handled on the error path.
  1594. */
  1595. static void sdma_7220_intr(struct qib_pportdata *ppd, u64 istat)
  1596. {
  1597. unsigned long flags;
  1598. spin_lock_irqsave(&ppd->sdma_lock, flags);
  1599. switch (ppd->sdma_state.current_state) {
  1600. case qib_sdma_state_s00_hw_down:
  1601. break;
  1602. case qib_sdma_state_s10_hw_start_up_wait:
  1603. __qib_sdma_process_event(ppd, qib_sdma_event_e20_hw_started);
  1604. break;
  1605. case qib_sdma_state_s20_idle:
  1606. break;
  1607. case qib_sdma_state_s30_sw_clean_up_wait:
  1608. break;
  1609. case qib_sdma_state_s40_hw_clean_up_wait:
  1610. break;
  1611. case qib_sdma_state_s50_hw_halt_wait:
  1612. __qib_sdma_process_event(ppd, qib_sdma_event_e60_hw_halted);
  1613. break;
  1614. case qib_sdma_state_s99_running:
  1615. /* too chatty to print here */
  1616. __qib_sdma_intr(ppd);
  1617. break;
  1618. }
  1619. spin_unlock_irqrestore(&ppd->sdma_lock, flags);
  1620. }
  1621. static void qib_wantpiobuf_7220_intr(struct qib_devdata *dd, u32 needint)
  1622. {
  1623. unsigned long flags;
  1624. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  1625. if (needint) {
  1626. if (!(dd->sendctrl & SYM_MASK(SendCtrl, SendBufAvailUpd)))
  1627. goto done;
  1628. /*
  1629. * blip the availupd off, next write will be on, so
  1630. * we ensure an avail update, regardless of threshold or
  1631. * buffers becoming free, whenever we want an interrupt
  1632. */
  1633. qib_write_kreg(dd, kr_sendctrl, dd->sendctrl &
  1634. ~SYM_MASK(SendCtrl, SendBufAvailUpd));
  1635. qib_write_kreg(dd, kr_scratch, 0ULL);
  1636. dd->sendctrl |= SYM_MASK(SendCtrl, SendIntBufAvail);
  1637. } else
  1638. dd->sendctrl &= ~SYM_MASK(SendCtrl, SendIntBufAvail);
  1639. qib_write_kreg(dd, kr_sendctrl, dd->sendctrl);
  1640. qib_write_kreg(dd, kr_scratch, 0ULL);
  1641. done:
  1642. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  1643. }
  1644. /*
  1645. * Handle errors and unusual events first, separate function
  1646. * to improve cache hits for fast path interrupt handling.
  1647. */
  1648. static noinline void unlikely_7220_intr(struct qib_devdata *dd, u64 istat)
  1649. {
  1650. if (unlikely(istat & ~QLOGIC_IB_I_BITSEXTANT))
  1651. qib_dev_err(dd,
  1652. "interrupt with unknown interrupts %Lx set\n",
  1653. istat & ~QLOGIC_IB_I_BITSEXTANT);
  1654. if (istat & QLOGIC_IB_I_GPIO) {
  1655. u32 gpiostatus;
  1656. /*
  1657. * Boards for this chip currently don't use GPIO interrupts,
  1658. * so clear by writing GPIOstatus to GPIOclear, and complain
  1659. * to alert developer. To avoid endless repeats, clear
  1660. * the bits in the mask, since there is some kind of
  1661. * programming error or chip problem.
  1662. */
  1663. gpiostatus = qib_read_kreg32(dd, kr_gpio_status);
  1664. /*
  1665. * In theory, writing GPIOstatus to GPIOclear could
  1666. * have a bad side-effect on some diagnostic that wanted
  1667. * to poll for a status-change, but the various shadows
  1668. * make that problematic at best. Diags will just suppress
  1669. * all GPIO interrupts during such tests.
  1670. */
  1671. qib_write_kreg(dd, kr_gpio_clear, gpiostatus);
  1672. if (gpiostatus) {
  1673. const u32 mask = qib_read_kreg32(dd, kr_gpio_mask);
  1674. u32 gpio_irq = mask & gpiostatus;
  1675. /*
  1676. * A bit set in status and (chip) Mask register
  1677. * would cause an interrupt. Since we are not
  1678. * expecting any, report it. Also check that the
  1679. * chip reflects our shadow, report issues,
  1680. * and refresh from the shadow.
  1681. */
  1682. /*
  1683. * Clear any troublemakers, and update chip
  1684. * from shadow
  1685. */
  1686. dd->cspec->gpio_mask &= ~gpio_irq;
  1687. qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
  1688. }
  1689. }
  1690. if (istat & QLOGIC_IB_I_ERROR) {
  1691. u64 estat;
  1692. qib_stats.sps_errints++;
  1693. estat = qib_read_kreg64(dd, kr_errstatus);
  1694. if (!estat)
  1695. qib_devinfo(dd->pcidev,
  1696. "error interrupt (%Lx), but no error bits set!\n",
  1697. istat);
  1698. else
  1699. handle_7220_errors(dd, estat);
  1700. }
  1701. }
  1702. static irqreturn_t qib_7220intr(int irq, void *data)
  1703. {
  1704. struct qib_devdata *dd = data;
  1705. irqreturn_t ret;
  1706. u64 istat;
  1707. u64 ctxtrbits;
  1708. u64 rmask;
  1709. unsigned i;
  1710. if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT) {
  1711. /*
  1712. * This return value is not great, but we do not want the
  1713. * interrupt core code to remove our interrupt handler
  1714. * because we don't appear to be handling an interrupt
  1715. * during a chip reset.
  1716. */
  1717. ret = IRQ_HANDLED;
  1718. goto bail;
  1719. }
  1720. istat = qib_read_kreg64(dd, kr_intstatus);
  1721. if (unlikely(!istat)) {
  1722. ret = IRQ_NONE; /* not our interrupt, or already handled */
  1723. goto bail;
  1724. }
  1725. if (unlikely(istat == -1)) {
  1726. qib_bad_intrstatus(dd);
  1727. /* don't know if it was our interrupt or not */
  1728. ret = IRQ_NONE;
  1729. goto bail;
  1730. }
  1731. this_cpu_inc(*dd->int_counter);
  1732. if (unlikely(istat & (~QLOGIC_IB_I_BITSEXTANT |
  1733. QLOGIC_IB_I_GPIO | QLOGIC_IB_I_ERROR)))
  1734. unlikely_7220_intr(dd, istat);
  1735. /*
  1736. * Clear the interrupt bits we found set, relatively early, so we
  1737. * "know" know the chip will have seen this by the time we process
  1738. * the queue, and will re-interrupt if necessary. The processor
  1739. * itself won't take the interrupt again until we return.
  1740. */
  1741. qib_write_kreg(dd, kr_intclear, istat);
  1742. /*
  1743. * Handle kernel receive queues before checking for pio buffers
  1744. * available since receives can overflow; piobuf waiters can afford
  1745. * a few extra cycles, since they were waiting anyway.
  1746. */
  1747. ctxtrbits = istat &
  1748. ((QLOGIC_IB_I_RCVAVAIL_MASK << QLOGIC_IB_I_RCVAVAIL_SHIFT) |
  1749. (QLOGIC_IB_I_RCVURG_MASK << QLOGIC_IB_I_RCVURG_SHIFT));
  1750. if (ctxtrbits) {
  1751. rmask = (1ULL << QLOGIC_IB_I_RCVAVAIL_SHIFT) |
  1752. (1ULL << QLOGIC_IB_I_RCVURG_SHIFT);
  1753. for (i = 0; i < dd->first_user_ctxt; i++) {
  1754. if (ctxtrbits & rmask) {
  1755. ctxtrbits &= ~rmask;
  1756. qib_kreceive(dd->rcd[i], NULL, NULL);
  1757. }
  1758. rmask <<= 1;
  1759. }
  1760. if (ctxtrbits) {
  1761. ctxtrbits =
  1762. (ctxtrbits >> QLOGIC_IB_I_RCVAVAIL_SHIFT) |
  1763. (ctxtrbits >> QLOGIC_IB_I_RCVURG_SHIFT);
  1764. qib_handle_urcv(dd, ctxtrbits);
  1765. }
  1766. }
  1767. /* only call for SDmaInt */
  1768. if (istat & QLOGIC_IB_I_SDMAINT)
  1769. sdma_7220_intr(dd->pport, istat);
  1770. if ((istat & QLOGIC_IB_I_SPIOBUFAVAIL) && (dd->flags & QIB_INITTED))
  1771. qib_ib_piobufavail(dd);
  1772. ret = IRQ_HANDLED;
  1773. bail:
  1774. return ret;
  1775. }
  1776. /*
  1777. * Set up our chip-specific interrupt handler.
  1778. * The interrupt type has already been setup, so
  1779. * we just need to do the registration and error checking.
  1780. * If we are using MSI interrupts, we may fall back to
  1781. * INTx later, if the interrupt handler doesn't get called
  1782. * within 1/2 second (see verify_interrupt()).
  1783. */
  1784. static void qib_setup_7220_interrupt(struct qib_devdata *dd)
  1785. {
  1786. int ret;
  1787. ret = pci_request_irq(dd->pcidev, 0, qib_7220intr, NULL, dd,
  1788. QIB_DRV_NAME);
  1789. if (ret)
  1790. qib_dev_err(dd, "Couldn't setup %s interrupt (irq=%d): %d\n",
  1791. dd->pcidev->msi_enabled ? "MSI" : "INTx",
  1792. pci_irq_vector(dd->pcidev, 0), ret);
  1793. }
  1794. /**
  1795. * qib_7220_boardname - fill in the board name
  1796. * @dd: the qlogic_ib device
  1797. *
  1798. * info is based on the board revision register
  1799. */
  1800. static void qib_7220_boardname(struct qib_devdata *dd)
  1801. {
  1802. u32 boardid;
  1803. boardid = SYM_FIELD(dd->revision, Revision,
  1804. BoardID);
  1805. switch (boardid) {
  1806. case 1:
  1807. dd->boardname = "InfiniPath_QLE7240";
  1808. break;
  1809. case 2:
  1810. dd->boardname = "InfiniPath_QLE7280";
  1811. break;
  1812. default:
  1813. qib_dev_err(dd, "Unknown 7220 board with ID %u\n", boardid);
  1814. dd->boardname = "Unknown_InfiniPath_7220";
  1815. break;
  1816. }
  1817. if (dd->majrev != 5 || !dd->minrev || dd->minrev > 2)
  1818. qib_dev_err(dd,
  1819. "Unsupported InfiniPath hardware revision %u.%u!\n",
  1820. dd->majrev, dd->minrev);
  1821. snprintf(dd->boardversion, sizeof(dd->boardversion),
  1822. "ChipABI %u.%u, %s, InfiniPath%u %u.%u, SW Compat %u\n",
  1823. QIB_CHIP_VERS_MAJ, QIB_CHIP_VERS_MIN, dd->boardname,
  1824. (unsigned int)SYM_FIELD(dd->revision, Revision_R, Arch),
  1825. dd->majrev, dd->minrev,
  1826. (unsigned int)SYM_FIELD(dd->revision, Revision_R, SW));
  1827. }
  1828. /*
  1829. * This routine sleeps, so it can only be called from user context, not
  1830. * from interrupt context.
  1831. */
  1832. static int qib_setup_7220_reset(struct qib_devdata *dd)
  1833. {
  1834. u64 val;
  1835. int i;
  1836. int ret;
  1837. u16 cmdval;
  1838. u8 int_line, clinesz;
  1839. unsigned long flags;
  1840. qib_pcie_getcmd(dd, &cmdval, &int_line, &clinesz);
  1841. /* Use dev_err so it shows up in logs, etc. */
  1842. qib_dev_err(dd, "Resetting InfiniPath unit %u\n", dd->unit);
  1843. /* no interrupts till re-initted */
  1844. qib_7220_set_intr_state(dd, 0);
  1845. dd->pport->cpspec->ibdeltainprog = 0;
  1846. dd->pport->cpspec->ibsymdelta = 0;
  1847. dd->pport->cpspec->iblnkerrdelta = 0;
  1848. /*
  1849. * Keep chip from being accessed until we are ready. Use
  1850. * writeq() directly, to allow the write even though QIB_PRESENT
  1851. * isn't set.
  1852. */
  1853. dd->flags &= ~(QIB_INITTED | QIB_PRESENT);
  1854. /* so we check interrupts work again */
  1855. dd->z_int_counter = qib_int_counter(dd);
  1856. val = dd->control | QLOGIC_IB_C_RESET;
  1857. writeq(val, &dd->kregbase[kr_control]);
  1858. mb(); /* prevent compiler reordering around actual reset */
  1859. for (i = 1; i <= 5; i++) {
  1860. /*
  1861. * Allow MBIST, etc. to complete; longer on each retry.
  1862. * We sometimes get machine checks from bus timeout if no
  1863. * response, so for now, make it *really* long.
  1864. */
  1865. msleep(1000 + (1 + i) * 2000);
  1866. qib_pcie_reenable(dd, cmdval, int_line, clinesz);
  1867. /*
  1868. * Use readq directly, so we don't need to mark it as PRESENT
  1869. * until we get a successful indication that all is well.
  1870. */
  1871. val = readq(&dd->kregbase[kr_revision]);
  1872. if (val == dd->revision) {
  1873. dd->flags |= QIB_PRESENT; /* it's back */
  1874. ret = qib_reinit_intr(dd);
  1875. goto bail;
  1876. }
  1877. }
  1878. ret = 0; /* failed */
  1879. bail:
  1880. if (ret) {
  1881. if (qib_pcie_params(dd, dd->lbus_width, NULL))
  1882. qib_dev_err(dd,
  1883. "Reset failed to setup PCIe or interrupts; continuing anyway\n");
  1884. /* hold IBC in reset, no sends, etc till later */
  1885. qib_write_kreg(dd, kr_control, 0ULL);
  1886. /* clear the reset error, init error/hwerror mask */
  1887. qib_7220_init_hwerrors(dd);
  1888. /* do setup similar to speed or link-width changes */
  1889. if (dd->pport->cpspec->ibcddrctrl & IBA7220_IBC_IBTA_1_2_MASK)
  1890. dd->cspec->presets_needed = 1;
  1891. spin_lock_irqsave(&dd->pport->lflags_lock, flags);
  1892. dd->pport->lflags |= QIBL_IB_FORCE_NOTIFY;
  1893. dd->pport->lflags &= ~QIBL_IB_AUTONEG_FAILED;
  1894. spin_unlock_irqrestore(&dd->pport->lflags_lock, flags);
  1895. }
  1896. return ret;
  1897. }
  1898. /**
  1899. * qib_7220_put_tid - write a TID to the chip
  1900. * @dd: the qlogic_ib device
  1901. * @tidptr: pointer to the expected TID (in chip) to update
  1902. * @tidtype: 0 for eager, 1 for expected
  1903. * @pa: physical address of in memory buffer; tidinvalid if freeing
  1904. */
  1905. static void qib_7220_put_tid(struct qib_devdata *dd, u64 __iomem *tidptr,
  1906. u32 type, unsigned long pa)
  1907. {
  1908. if (pa != dd->tidinvalid) {
  1909. u64 chippa = pa >> IBA7220_TID_PA_SHIFT;
  1910. /* paranoia checks */
  1911. if (pa != (chippa << IBA7220_TID_PA_SHIFT)) {
  1912. qib_dev_err(dd, "Physaddr %lx not 2KB aligned!\n",
  1913. pa);
  1914. return;
  1915. }
  1916. if (chippa >= (1UL << IBA7220_TID_SZ_SHIFT)) {
  1917. qib_dev_err(dd,
  1918. "Physical page address 0x%lx larger than supported\n",
  1919. pa);
  1920. return;
  1921. }
  1922. if (type == RCVHQ_RCV_TYPE_EAGER)
  1923. chippa |= dd->tidtemplate;
  1924. else /* for now, always full 4KB page */
  1925. chippa |= IBA7220_TID_SZ_4K;
  1926. pa = chippa;
  1927. }
  1928. writeq(pa, tidptr);
  1929. mmiowb();
  1930. }
  1931. /**
  1932. * qib_7220_clear_tids - clear all TID entries for a ctxt, expected and eager
  1933. * @dd: the qlogic_ib device
  1934. * @ctxt: the ctxt
  1935. *
  1936. * clear all TID entries for a ctxt, expected and eager.
  1937. * Used from qib_close(). On this chip, TIDs are only 32 bits,
  1938. * not 64, but they are still on 64 bit boundaries, so tidbase
  1939. * is declared as u64 * for the pointer math, even though we write 32 bits
  1940. */
  1941. static void qib_7220_clear_tids(struct qib_devdata *dd,
  1942. struct qib_ctxtdata *rcd)
  1943. {
  1944. u64 __iomem *tidbase;
  1945. unsigned long tidinv;
  1946. u32 ctxt;
  1947. int i;
  1948. if (!dd->kregbase || !rcd)
  1949. return;
  1950. ctxt = rcd->ctxt;
  1951. tidinv = dd->tidinvalid;
  1952. tidbase = (u64 __iomem *)
  1953. ((char __iomem *)(dd->kregbase) +
  1954. dd->rcvtidbase +
  1955. ctxt * dd->rcvtidcnt * sizeof(*tidbase));
  1956. for (i = 0; i < dd->rcvtidcnt; i++)
  1957. qib_7220_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EXPECTED,
  1958. tidinv);
  1959. tidbase = (u64 __iomem *)
  1960. ((char __iomem *)(dd->kregbase) +
  1961. dd->rcvegrbase +
  1962. rcd->rcvegr_tid_base * sizeof(*tidbase));
  1963. for (i = 0; i < rcd->rcvegrcnt; i++)
  1964. qib_7220_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EAGER,
  1965. tidinv);
  1966. }
  1967. /**
  1968. * qib_7220_tidtemplate - setup constants for TID updates
  1969. * @dd: the qlogic_ib device
  1970. *
  1971. * We setup stuff that we use a lot, to avoid calculating each time
  1972. */
  1973. static void qib_7220_tidtemplate(struct qib_devdata *dd)
  1974. {
  1975. if (dd->rcvegrbufsize == 2048)
  1976. dd->tidtemplate = IBA7220_TID_SZ_2K;
  1977. else if (dd->rcvegrbufsize == 4096)
  1978. dd->tidtemplate = IBA7220_TID_SZ_4K;
  1979. dd->tidinvalid = 0;
  1980. }
  1981. /**
  1982. * qib_init_7220_get_base_info - set chip-specific flags for user code
  1983. * @rcd: the qlogic_ib ctxt
  1984. * @kbase: qib_base_info pointer
  1985. *
  1986. * We set the PCIE flag because the lower bandwidth on PCIe vs
  1987. * HyperTransport can affect some user packet algorithims.
  1988. */
  1989. static int qib_7220_get_base_info(struct qib_ctxtdata *rcd,
  1990. struct qib_base_info *kinfo)
  1991. {
  1992. kinfo->spi_runtime_flags |= QIB_RUNTIME_PCIE |
  1993. QIB_RUNTIME_NODMA_RTAIL | QIB_RUNTIME_SDMA;
  1994. if (rcd->dd->flags & QIB_USE_SPCL_TRIG)
  1995. kinfo->spi_runtime_flags |= QIB_RUNTIME_SPECIAL_TRIGGER;
  1996. return 0;
  1997. }
  1998. static struct qib_message_header *
  1999. qib_7220_get_msgheader(struct qib_devdata *dd, __le32 *rhf_addr)
  2000. {
  2001. u32 offset = qib_hdrget_offset(rhf_addr);
  2002. return (struct qib_message_header *)
  2003. (rhf_addr - dd->rhf_offset + offset);
  2004. }
  2005. static void qib_7220_config_ctxts(struct qib_devdata *dd)
  2006. {
  2007. unsigned long flags;
  2008. u32 nchipctxts;
  2009. nchipctxts = qib_read_kreg32(dd, kr_portcnt);
  2010. dd->cspec->numctxts = nchipctxts;
  2011. if (qib_n_krcv_queues > 1) {
  2012. dd->qpn_mask = 0x3e;
  2013. dd->first_user_ctxt = qib_n_krcv_queues * dd->num_pports;
  2014. if (dd->first_user_ctxt > nchipctxts)
  2015. dd->first_user_ctxt = nchipctxts;
  2016. } else
  2017. dd->first_user_ctxt = dd->num_pports;
  2018. dd->n_krcv_queues = dd->first_user_ctxt;
  2019. if (!qib_cfgctxts) {
  2020. int nctxts = dd->first_user_ctxt + num_online_cpus();
  2021. if (nctxts <= 5)
  2022. dd->ctxtcnt = 5;
  2023. else if (nctxts <= 9)
  2024. dd->ctxtcnt = 9;
  2025. else if (nctxts <= nchipctxts)
  2026. dd->ctxtcnt = nchipctxts;
  2027. } else if (qib_cfgctxts <= nchipctxts)
  2028. dd->ctxtcnt = qib_cfgctxts;
  2029. if (!dd->ctxtcnt) /* none of the above, set to max */
  2030. dd->ctxtcnt = nchipctxts;
  2031. /*
  2032. * Chip can be configured for 5, 9, or 17 ctxts, and choice
  2033. * affects number of eager TIDs per ctxt (1K, 2K, 4K).
  2034. * Lock to be paranoid about later motion, etc.
  2035. */
  2036. spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
  2037. if (dd->ctxtcnt > 9)
  2038. dd->rcvctrl |= 2ULL << IBA7220_R_CTXTCFG_SHIFT;
  2039. else if (dd->ctxtcnt > 5)
  2040. dd->rcvctrl |= 1ULL << IBA7220_R_CTXTCFG_SHIFT;
  2041. /* else configure for default 5 receive ctxts */
  2042. if (dd->qpn_mask)
  2043. dd->rcvctrl |= 1ULL << QIB_7220_RcvCtrl_RcvQPMapEnable_LSB;
  2044. qib_write_kreg(dd, kr_rcvctrl, dd->rcvctrl);
  2045. spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
  2046. /* kr_rcvegrcnt changes based on the number of contexts enabled */
  2047. dd->cspec->rcvegrcnt = qib_read_kreg32(dd, kr_rcvegrcnt);
  2048. dd->rcvhdrcnt = max(dd->cspec->rcvegrcnt, IBA7220_KRCVEGRCNT);
  2049. }
  2050. static int qib_7220_get_ib_cfg(struct qib_pportdata *ppd, int which)
  2051. {
  2052. int lsb, ret = 0;
  2053. u64 maskr; /* right-justified mask */
  2054. switch (which) {
  2055. case QIB_IB_CFG_LWID_ENB: /* Get allowed Link-width */
  2056. ret = ppd->link_width_enabled;
  2057. goto done;
  2058. case QIB_IB_CFG_LWID: /* Get currently active Link-width */
  2059. ret = ppd->link_width_active;
  2060. goto done;
  2061. case QIB_IB_CFG_SPD_ENB: /* Get allowed Link speeds */
  2062. ret = ppd->link_speed_enabled;
  2063. goto done;
  2064. case QIB_IB_CFG_SPD: /* Get current Link spd */
  2065. ret = ppd->link_speed_active;
  2066. goto done;
  2067. case QIB_IB_CFG_RXPOL_ENB: /* Get Auto-RX-polarity enable */
  2068. lsb = IBA7220_IBC_RXPOL_SHIFT;
  2069. maskr = IBA7220_IBC_RXPOL_MASK;
  2070. break;
  2071. case QIB_IB_CFG_LREV_ENB: /* Get Auto-Lane-reversal enable */
  2072. lsb = IBA7220_IBC_LREV_SHIFT;
  2073. maskr = IBA7220_IBC_LREV_MASK;
  2074. break;
  2075. case QIB_IB_CFG_LINKLATENCY:
  2076. ret = qib_read_kreg64(ppd->dd, kr_ibcddrstatus)
  2077. & IBA7220_DDRSTAT_LINKLAT_MASK;
  2078. goto done;
  2079. case QIB_IB_CFG_OP_VLS:
  2080. ret = ppd->vls_operational;
  2081. goto done;
  2082. case QIB_IB_CFG_VL_HIGH_CAP:
  2083. ret = 0;
  2084. goto done;
  2085. case QIB_IB_CFG_VL_LOW_CAP:
  2086. ret = 0;
  2087. goto done;
  2088. case QIB_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
  2089. ret = SYM_FIELD(ppd->cpspec->ibcctrl, IBCCtrl,
  2090. OverrunThreshold);
  2091. goto done;
  2092. case QIB_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
  2093. ret = SYM_FIELD(ppd->cpspec->ibcctrl, IBCCtrl,
  2094. PhyerrThreshold);
  2095. goto done;
  2096. case QIB_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
  2097. /* will only take effect when the link state changes */
  2098. ret = (ppd->cpspec->ibcctrl &
  2099. SYM_MASK(IBCCtrl, LinkDownDefaultState)) ?
  2100. IB_LINKINITCMD_SLEEP : IB_LINKINITCMD_POLL;
  2101. goto done;
  2102. case QIB_IB_CFG_HRTBT: /* Get Heartbeat off/enable/auto */
  2103. lsb = IBA7220_IBC_HRTBT_SHIFT;
  2104. maskr = IBA7220_IBC_HRTBT_MASK;
  2105. break;
  2106. case QIB_IB_CFG_PMA_TICKS:
  2107. /*
  2108. * 0x00 = 10x link transfer rate or 4 nsec. for 2.5Gbs
  2109. * Since the clock is always 250MHz, the value is 1 or 0.
  2110. */
  2111. ret = (ppd->link_speed_active == QIB_IB_DDR);
  2112. goto done;
  2113. default:
  2114. ret = -EINVAL;
  2115. goto done;
  2116. }
  2117. ret = (int)((ppd->cpspec->ibcddrctrl >> lsb) & maskr);
  2118. done:
  2119. return ret;
  2120. }
  2121. static int qib_7220_set_ib_cfg(struct qib_pportdata *ppd, int which, u32 val)
  2122. {
  2123. struct qib_devdata *dd = ppd->dd;
  2124. u64 maskr; /* right-justified mask */
  2125. int lsb, ret = 0, setforce = 0;
  2126. u16 lcmd, licmd;
  2127. unsigned long flags;
  2128. u32 tmp = 0;
  2129. switch (which) {
  2130. case QIB_IB_CFG_LIDLMC:
  2131. /*
  2132. * Set LID and LMC. Combined to avoid possible hazard
  2133. * caller puts LMC in 16MSbits, DLID in 16LSbits of val
  2134. */
  2135. lsb = IBA7220_IBC_DLIDLMC_SHIFT;
  2136. maskr = IBA7220_IBC_DLIDLMC_MASK;
  2137. break;
  2138. case QIB_IB_CFG_LWID_ENB: /* set allowed Link-width */
  2139. /*
  2140. * As with speed, only write the actual register if
  2141. * the link is currently down, otherwise takes effect
  2142. * on next link change.
  2143. */
  2144. ppd->link_width_enabled = val;
  2145. if (!(ppd->lflags & QIBL_LINKDOWN))
  2146. goto bail;
  2147. /*
  2148. * We set the QIBL_IB_FORCE_NOTIFY bit so updown
  2149. * will get called because we want update
  2150. * link_width_active, and the change may not take
  2151. * effect for some time (if we are in POLL), so this
  2152. * flag will force the updown routine to be called
  2153. * on the next ibstatuschange down interrupt, even
  2154. * if it's not an down->up transition.
  2155. */
  2156. val--; /* convert from IB to chip */
  2157. maskr = IBA7220_IBC_WIDTH_MASK;
  2158. lsb = IBA7220_IBC_WIDTH_SHIFT;
  2159. setforce = 1;
  2160. break;
  2161. case QIB_IB_CFG_SPD_ENB: /* set allowed Link speeds */
  2162. /*
  2163. * If we turn off IB1.2, need to preset SerDes defaults,
  2164. * but not right now. Set a flag for the next time
  2165. * we command the link down. As with width, only write the
  2166. * actual register if the link is currently down, otherwise
  2167. * takes effect on next link change. Since setting is being
  2168. * explicitly requested (via MAD or sysfs), clear autoneg
  2169. * failure status if speed autoneg is enabled.
  2170. */
  2171. ppd->link_speed_enabled = val;
  2172. if ((ppd->cpspec->ibcddrctrl & IBA7220_IBC_IBTA_1_2_MASK) &&
  2173. !(val & (val - 1)))
  2174. dd->cspec->presets_needed = 1;
  2175. if (!(ppd->lflags & QIBL_LINKDOWN))
  2176. goto bail;
  2177. /*
  2178. * We set the QIBL_IB_FORCE_NOTIFY bit so updown
  2179. * will get called because we want update
  2180. * link_speed_active, and the change may not take
  2181. * effect for some time (if we are in POLL), so this
  2182. * flag will force the updown routine to be called
  2183. * on the next ibstatuschange down interrupt, even
  2184. * if it's not an down->up transition.
  2185. */
  2186. if (val == (QIB_IB_SDR | QIB_IB_DDR)) {
  2187. val = IBA7220_IBC_SPEED_AUTONEG_MASK |
  2188. IBA7220_IBC_IBTA_1_2_MASK;
  2189. spin_lock_irqsave(&ppd->lflags_lock, flags);
  2190. ppd->lflags &= ~QIBL_IB_AUTONEG_FAILED;
  2191. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  2192. } else
  2193. val = val == QIB_IB_DDR ?
  2194. IBA7220_IBC_SPEED_DDR : IBA7220_IBC_SPEED_SDR;
  2195. maskr = IBA7220_IBC_SPEED_AUTONEG_MASK |
  2196. IBA7220_IBC_IBTA_1_2_MASK;
  2197. /* IBTA 1.2 mode + speed bits are contiguous */
  2198. lsb = SYM_LSB(IBCDDRCtrl, IB_ENHANCED_MODE);
  2199. setforce = 1;
  2200. break;
  2201. case QIB_IB_CFG_RXPOL_ENB: /* set Auto-RX-polarity enable */
  2202. lsb = IBA7220_IBC_RXPOL_SHIFT;
  2203. maskr = IBA7220_IBC_RXPOL_MASK;
  2204. break;
  2205. case QIB_IB_CFG_LREV_ENB: /* set Auto-Lane-reversal enable */
  2206. lsb = IBA7220_IBC_LREV_SHIFT;
  2207. maskr = IBA7220_IBC_LREV_MASK;
  2208. break;
  2209. case QIB_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
  2210. maskr = SYM_FIELD(ppd->cpspec->ibcctrl, IBCCtrl,
  2211. OverrunThreshold);
  2212. if (maskr != val) {
  2213. ppd->cpspec->ibcctrl &=
  2214. ~SYM_MASK(IBCCtrl, OverrunThreshold);
  2215. ppd->cpspec->ibcctrl |= (u64) val <<
  2216. SYM_LSB(IBCCtrl, OverrunThreshold);
  2217. qib_write_kreg(dd, kr_ibcctrl, ppd->cpspec->ibcctrl);
  2218. qib_write_kreg(dd, kr_scratch, 0);
  2219. }
  2220. goto bail;
  2221. case QIB_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
  2222. maskr = SYM_FIELD(ppd->cpspec->ibcctrl, IBCCtrl,
  2223. PhyerrThreshold);
  2224. if (maskr != val) {
  2225. ppd->cpspec->ibcctrl &=
  2226. ~SYM_MASK(IBCCtrl, PhyerrThreshold);
  2227. ppd->cpspec->ibcctrl |= (u64) val <<
  2228. SYM_LSB(IBCCtrl, PhyerrThreshold);
  2229. qib_write_kreg(dd, kr_ibcctrl, ppd->cpspec->ibcctrl);
  2230. qib_write_kreg(dd, kr_scratch, 0);
  2231. }
  2232. goto bail;
  2233. case QIB_IB_CFG_PKEYS: /* update pkeys */
  2234. maskr = (u64) ppd->pkeys[0] | ((u64) ppd->pkeys[1] << 16) |
  2235. ((u64) ppd->pkeys[2] << 32) |
  2236. ((u64) ppd->pkeys[3] << 48);
  2237. qib_write_kreg(dd, kr_partitionkey, maskr);
  2238. goto bail;
  2239. case QIB_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
  2240. /* will only take effect when the link state changes */
  2241. if (val == IB_LINKINITCMD_POLL)
  2242. ppd->cpspec->ibcctrl &=
  2243. ~SYM_MASK(IBCCtrl, LinkDownDefaultState);
  2244. else /* SLEEP */
  2245. ppd->cpspec->ibcctrl |=
  2246. SYM_MASK(IBCCtrl, LinkDownDefaultState);
  2247. qib_write_kreg(dd, kr_ibcctrl, ppd->cpspec->ibcctrl);
  2248. qib_write_kreg(dd, kr_scratch, 0);
  2249. goto bail;
  2250. case QIB_IB_CFG_MTU: /* update the MTU in IBC */
  2251. /*
  2252. * Update our housekeeping variables, and set IBC max
  2253. * size, same as init code; max IBC is max we allow in
  2254. * buffer, less the qword pbc, plus 1 for ICRC, in dwords
  2255. * Set even if it's unchanged, print debug message only
  2256. * on changes.
  2257. */
  2258. val = (ppd->ibmaxlen >> 2) + 1;
  2259. ppd->cpspec->ibcctrl &= ~SYM_MASK(IBCCtrl, MaxPktLen);
  2260. ppd->cpspec->ibcctrl |= (u64)val << SYM_LSB(IBCCtrl, MaxPktLen);
  2261. qib_write_kreg(dd, kr_ibcctrl, ppd->cpspec->ibcctrl);
  2262. qib_write_kreg(dd, kr_scratch, 0);
  2263. goto bail;
  2264. case QIB_IB_CFG_LSTATE: /* set the IB link state */
  2265. switch (val & 0xffff0000) {
  2266. case IB_LINKCMD_DOWN:
  2267. lcmd = QLOGIC_IB_IBCC_LINKCMD_DOWN;
  2268. if (!ppd->cpspec->ibdeltainprog &&
  2269. qib_compat_ddr_negotiate) {
  2270. ppd->cpspec->ibdeltainprog = 1;
  2271. ppd->cpspec->ibsymsnap =
  2272. read_7220_creg32(dd, cr_ibsymbolerr);
  2273. ppd->cpspec->iblnkerrsnap =
  2274. read_7220_creg32(dd, cr_iblinkerrrecov);
  2275. }
  2276. break;
  2277. case IB_LINKCMD_ARMED:
  2278. lcmd = QLOGIC_IB_IBCC_LINKCMD_ARMED;
  2279. break;
  2280. case IB_LINKCMD_ACTIVE:
  2281. lcmd = QLOGIC_IB_IBCC_LINKCMD_ACTIVE;
  2282. break;
  2283. default:
  2284. ret = -EINVAL;
  2285. qib_dev_err(dd, "bad linkcmd req 0x%x\n", val >> 16);
  2286. goto bail;
  2287. }
  2288. switch (val & 0xffff) {
  2289. case IB_LINKINITCMD_NOP:
  2290. licmd = 0;
  2291. break;
  2292. case IB_LINKINITCMD_POLL:
  2293. licmd = QLOGIC_IB_IBCC_LINKINITCMD_POLL;
  2294. break;
  2295. case IB_LINKINITCMD_SLEEP:
  2296. licmd = QLOGIC_IB_IBCC_LINKINITCMD_SLEEP;
  2297. break;
  2298. case IB_LINKINITCMD_DISABLE:
  2299. licmd = QLOGIC_IB_IBCC_LINKINITCMD_DISABLE;
  2300. ppd->cpspec->chase_end = 0;
  2301. /*
  2302. * stop state chase counter and timer, if running.
  2303. * wait forpending timer, but don't clear .data (ppd)!
  2304. */
  2305. if (ppd->cpspec->chase_timer.expires) {
  2306. del_timer_sync(&ppd->cpspec->chase_timer);
  2307. ppd->cpspec->chase_timer.expires = 0;
  2308. }
  2309. break;
  2310. default:
  2311. ret = -EINVAL;
  2312. qib_dev_err(dd, "bad linkinitcmd req 0x%x\n",
  2313. val & 0xffff);
  2314. goto bail;
  2315. }
  2316. qib_set_ib_7220_lstate(ppd, lcmd, licmd);
  2317. maskr = IBA7220_IBC_WIDTH_MASK;
  2318. lsb = IBA7220_IBC_WIDTH_SHIFT;
  2319. tmp = (ppd->cpspec->ibcddrctrl >> lsb) & maskr;
  2320. /* If the width active on the chip does not match the
  2321. * width in the shadow register, write the new active
  2322. * width to the chip.
  2323. * We don't have to worry about speed as the speed is taken
  2324. * care of by set_7220_ibspeed_fast called by ib_updown.
  2325. */
  2326. if (ppd->link_width_enabled-1 != tmp) {
  2327. ppd->cpspec->ibcddrctrl &= ~(maskr << lsb);
  2328. ppd->cpspec->ibcddrctrl |=
  2329. (((u64)(ppd->link_width_enabled-1) & maskr) <<
  2330. lsb);
  2331. qib_write_kreg(dd, kr_ibcddrctrl,
  2332. ppd->cpspec->ibcddrctrl);
  2333. qib_write_kreg(dd, kr_scratch, 0);
  2334. spin_lock_irqsave(&ppd->lflags_lock, flags);
  2335. ppd->lflags |= QIBL_IB_FORCE_NOTIFY;
  2336. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  2337. }
  2338. goto bail;
  2339. case QIB_IB_CFG_HRTBT: /* set Heartbeat off/enable/auto */
  2340. if (val > IBA7220_IBC_HRTBT_MASK) {
  2341. ret = -EINVAL;
  2342. goto bail;
  2343. }
  2344. lsb = IBA7220_IBC_HRTBT_SHIFT;
  2345. maskr = IBA7220_IBC_HRTBT_MASK;
  2346. break;
  2347. default:
  2348. ret = -EINVAL;
  2349. goto bail;
  2350. }
  2351. ppd->cpspec->ibcddrctrl &= ~(maskr << lsb);
  2352. ppd->cpspec->ibcddrctrl |= (((u64) val & maskr) << lsb);
  2353. qib_write_kreg(dd, kr_ibcddrctrl, ppd->cpspec->ibcddrctrl);
  2354. qib_write_kreg(dd, kr_scratch, 0);
  2355. if (setforce) {
  2356. spin_lock_irqsave(&ppd->lflags_lock, flags);
  2357. ppd->lflags |= QIBL_IB_FORCE_NOTIFY;
  2358. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  2359. }
  2360. bail:
  2361. return ret;
  2362. }
  2363. static int qib_7220_set_loopback(struct qib_pportdata *ppd, const char *what)
  2364. {
  2365. int ret = 0;
  2366. u64 val, ddr;
  2367. if (!strncmp(what, "ibc", 3)) {
  2368. ppd->cpspec->ibcctrl |= SYM_MASK(IBCCtrl, Loopback);
  2369. val = 0; /* disable heart beat, so link will come up */
  2370. qib_devinfo(ppd->dd->pcidev, "Enabling IB%u:%u IBC loopback\n",
  2371. ppd->dd->unit, ppd->port);
  2372. } else if (!strncmp(what, "off", 3)) {
  2373. ppd->cpspec->ibcctrl &= ~SYM_MASK(IBCCtrl, Loopback);
  2374. /* enable heart beat again */
  2375. val = IBA7220_IBC_HRTBT_MASK << IBA7220_IBC_HRTBT_SHIFT;
  2376. qib_devinfo(ppd->dd->pcidev,
  2377. "Disabling IB%u:%u IBC loopback (normal)\n",
  2378. ppd->dd->unit, ppd->port);
  2379. } else
  2380. ret = -EINVAL;
  2381. if (!ret) {
  2382. qib_write_kreg(ppd->dd, kr_ibcctrl, ppd->cpspec->ibcctrl);
  2383. ddr = ppd->cpspec->ibcddrctrl & ~(IBA7220_IBC_HRTBT_MASK
  2384. << IBA7220_IBC_HRTBT_SHIFT);
  2385. ppd->cpspec->ibcddrctrl = ddr | val;
  2386. qib_write_kreg(ppd->dd, kr_ibcddrctrl,
  2387. ppd->cpspec->ibcddrctrl);
  2388. qib_write_kreg(ppd->dd, kr_scratch, 0);
  2389. }
  2390. return ret;
  2391. }
  2392. static void qib_update_7220_usrhead(struct qib_ctxtdata *rcd, u64 hd,
  2393. u32 updegr, u32 egrhd, u32 npkts)
  2394. {
  2395. if (updegr)
  2396. qib_write_ureg(rcd->dd, ur_rcvegrindexhead, egrhd, rcd->ctxt);
  2397. mmiowb();
  2398. qib_write_ureg(rcd->dd, ur_rcvhdrhead, hd, rcd->ctxt);
  2399. mmiowb();
  2400. }
  2401. static u32 qib_7220_hdrqempty(struct qib_ctxtdata *rcd)
  2402. {
  2403. u32 head, tail;
  2404. head = qib_read_ureg32(rcd->dd, ur_rcvhdrhead, rcd->ctxt);
  2405. if (rcd->rcvhdrtail_kvaddr)
  2406. tail = qib_get_rcvhdrtail(rcd);
  2407. else
  2408. tail = qib_read_ureg32(rcd->dd, ur_rcvhdrtail, rcd->ctxt);
  2409. return head == tail;
  2410. }
  2411. /*
  2412. * Modify the RCVCTRL register in chip-specific way. This
  2413. * is a function because bit positions and (future) register
  2414. * location is chip-specifc, but the needed operations are
  2415. * generic. <op> is a bit-mask because we often want to
  2416. * do multiple modifications.
  2417. */
  2418. static void rcvctrl_7220_mod(struct qib_pportdata *ppd, unsigned int op,
  2419. int ctxt)
  2420. {
  2421. struct qib_devdata *dd = ppd->dd;
  2422. u64 mask, val;
  2423. unsigned long flags;
  2424. spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
  2425. if (op & QIB_RCVCTRL_TAILUPD_ENB)
  2426. dd->rcvctrl |= (1ULL << IBA7220_R_TAILUPD_SHIFT);
  2427. if (op & QIB_RCVCTRL_TAILUPD_DIS)
  2428. dd->rcvctrl &= ~(1ULL << IBA7220_R_TAILUPD_SHIFT);
  2429. if (op & QIB_RCVCTRL_PKEY_ENB)
  2430. dd->rcvctrl &= ~(1ULL << IBA7220_R_PKEY_DIS_SHIFT);
  2431. if (op & QIB_RCVCTRL_PKEY_DIS)
  2432. dd->rcvctrl |= (1ULL << IBA7220_R_PKEY_DIS_SHIFT);
  2433. if (ctxt < 0)
  2434. mask = (1ULL << dd->ctxtcnt) - 1;
  2435. else
  2436. mask = (1ULL << ctxt);
  2437. if (op & QIB_RCVCTRL_CTXT_ENB) {
  2438. /* always done for specific ctxt */
  2439. dd->rcvctrl |= (mask << SYM_LSB(RcvCtrl, PortEnable));
  2440. if (!(dd->flags & QIB_NODMA_RTAIL))
  2441. dd->rcvctrl |= 1ULL << IBA7220_R_TAILUPD_SHIFT;
  2442. /* Write these registers before the context is enabled. */
  2443. qib_write_kreg_ctxt(dd, kr_rcvhdrtailaddr, ctxt,
  2444. dd->rcd[ctxt]->rcvhdrqtailaddr_phys);
  2445. qib_write_kreg_ctxt(dd, kr_rcvhdraddr, ctxt,
  2446. dd->rcd[ctxt]->rcvhdrq_phys);
  2447. dd->rcd[ctxt]->seq_cnt = 1;
  2448. }
  2449. if (op & QIB_RCVCTRL_CTXT_DIS)
  2450. dd->rcvctrl &= ~(mask << SYM_LSB(RcvCtrl, PortEnable));
  2451. if (op & QIB_RCVCTRL_INTRAVAIL_ENB)
  2452. dd->rcvctrl |= (mask << IBA7220_R_INTRAVAIL_SHIFT);
  2453. if (op & QIB_RCVCTRL_INTRAVAIL_DIS)
  2454. dd->rcvctrl &= ~(mask << IBA7220_R_INTRAVAIL_SHIFT);
  2455. qib_write_kreg(dd, kr_rcvctrl, dd->rcvctrl);
  2456. if ((op & QIB_RCVCTRL_INTRAVAIL_ENB) && dd->rhdrhead_intr_off) {
  2457. /* arm rcv interrupt */
  2458. val = qib_read_ureg32(dd, ur_rcvhdrhead, ctxt) |
  2459. dd->rhdrhead_intr_off;
  2460. qib_write_ureg(dd, ur_rcvhdrhead, val, ctxt);
  2461. }
  2462. if (op & QIB_RCVCTRL_CTXT_ENB) {
  2463. /*
  2464. * Init the context registers also; if we were
  2465. * disabled, tail and head should both be zero
  2466. * already from the enable, but since we don't
  2467. * know, we have to do it explicitly.
  2468. */
  2469. val = qib_read_ureg32(dd, ur_rcvegrindextail, ctxt);
  2470. qib_write_ureg(dd, ur_rcvegrindexhead, val, ctxt);
  2471. val = qib_read_ureg32(dd, ur_rcvhdrtail, ctxt);
  2472. dd->rcd[ctxt]->head = val;
  2473. /* If kctxt, interrupt on next receive. */
  2474. if (ctxt < dd->first_user_ctxt)
  2475. val |= dd->rhdrhead_intr_off;
  2476. qib_write_ureg(dd, ur_rcvhdrhead, val, ctxt);
  2477. }
  2478. if (op & QIB_RCVCTRL_CTXT_DIS) {
  2479. if (ctxt >= 0) {
  2480. qib_write_kreg_ctxt(dd, kr_rcvhdrtailaddr, ctxt, 0);
  2481. qib_write_kreg_ctxt(dd, kr_rcvhdraddr, ctxt, 0);
  2482. } else {
  2483. unsigned i;
  2484. for (i = 0; i < dd->cfgctxts; i++) {
  2485. qib_write_kreg_ctxt(dd, kr_rcvhdrtailaddr,
  2486. i, 0);
  2487. qib_write_kreg_ctxt(dd, kr_rcvhdraddr, i, 0);
  2488. }
  2489. }
  2490. }
  2491. spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
  2492. }
  2493. /*
  2494. * Modify the SENDCTRL register in chip-specific way. This
  2495. * is a function there may be multiple such registers with
  2496. * slightly different layouts. To start, we assume the
  2497. * "canonical" register layout of the first chips.
  2498. * Chip requires no back-back sendctrl writes, so write
  2499. * scratch register after writing sendctrl
  2500. */
  2501. static void sendctrl_7220_mod(struct qib_pportdata *ppd, u32 op)
  2502. {
  2503. struct qib_devdata *dd = ppd->dd;
  2504. u64 tmp_dd_sendctrl;
  2505. unsigned long flags;
  2506. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  2507. /* First the ones that are "sticky", saved in shadow */
  2508. if (op & QIB_SENDCTRL_CLEAR)
  2509. dd->sendctrl = 0;
  2510. if (op & QIB_SENDCTRL_SEND_DIS)
  2511. dd->sendctrl &= ~SYM_MASK(SendCtrl, SPioEnable);
  2512. else if (op & QIB_SENDCTRL_SEND_ENB) {
  2513. dd->sendctrl |= SYM_MASK(SendCtrl, SPioEnable);
  2514. if (dd->flags & QIB_USE_SPCL_TRIG)
  2515. dd->sendctrl |= SYM_MASK(SendCtrl,
  2516. SSpecialTriggerEn);
  2517. }
  2518. if (op & QIB_SENDCTRL_AVAIL_DIS)
  2519. dd->sendctrl &= ~SYM_MASK(SendCtrl, SendBufAvailUpd);
  2520. else if (op & QIB_SENDCTRL_AVAIL_ENB)
  2521. dd->sendctrl |= SYM_MASK(SendCtrl, SendBufAvailUpd);
  2522. if (op & QIB_SENDCTRL_DISARM_ALL) {
  2523. u32 i, last;
  2524. tmp_dd_sendctrl = dd->sendctrl;
  2525. /*
  2526. * disarm any that are not yet launched, disabling sends
  2527. * and updates until done.
  2528. */
  2529. last = dd->piobcnt2k + dd->piobcnt4k;
  2530. tmp_dd_sendctrl &=
  2531. ~(SYM_MASK(SendCtrl, SPioEnable) |
  2532. SYM_MASK(SendCtrl, SendBufAvailUpd));
  2533. for (i = 0; i < last; i++) {
  2534. qib_write_kreg(dd, kr_sendctrl,
  2535. tmp_dd_sendctrl |
  2536. SYM_MASK(SendCtrl, Disarm) | i);
  2537. qib_write_kreg(dd, kr_scratch, 0);
  2538. }
  2539. }
  2540. tmp_dd_sendctrl = dd->sendctrl;
  2541. if (op & QIB_SENDCTRL_FLUSH)
  2542. tmp_dd_sendctrl |= SYM_MASK(SendCtrl, Abort);
  2543. if (op & QIB_SENDCTRL_DISARM)
  2544. tmp_dd_sendctrl |= SYM_MASK(SendCtrl, Disarm) |
  2545. ((op & QIB_7220_SendCtrl_DisarmPIOBuf_RMASK) <<
  2546. SYM_LSB(SendCtrl, DisarmPIOBuf));
  2547. if ((op & QIB_SENDCTRL_AVAIL_BLIP) &&
  2548. (dd->sendctrl & SYM_MASK(SendCtrl, SendBufAvailUpd)))
  2549. tmp_dd_sendctrl &= ~SYM_MASK(SendCtrl, SendBufAvailUpd);
  2550. qib_write_kreg(dd, kr_sendctrl, tmp_dd_sendctrl);
  2551. qib_write_kreg(dd, kr_scratch, 0);
  2552. if (op & QIB_SENDCTRL_AVAIL_BLIP) {
  2553. qib_write_kreg(dd, kr_sendctrl, dd->sendctrl);
  2554. qib_write_kreg(dd, kr_scratch, 0);
  2555. }
  2556. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  2557. if (op & QIB_SENDCTRL_FLUSH) {
  2558. u32 v;
  2559. /*
  2560. * ensure writes have hit chip, then do a few
  2561. * more reads, to allow DMA of pioavail registers
  2562. * to occur, so in-memory copy is in sync with
  2563. * the chip. Not always safe to sleep.
  2564. */
  2565. v = qib_read_kreg32(dd, kr_scratch);
  2566. qib_write_kreg(dd, kr_scratch, v);
  2567. v = qib_read_kreg32(dd, kr_scratch);
  2568. qib_write_kreg(dd, kr_scratch, v);
  2569. qib_read_kreg32(dd, kr_scratch);
  2570. }
  2571. }
  2572. /**
  2573. * qib_portcntr_7220 - read a per-port counter
  2574. * @dd: the qlogic_ib device
  2575. * @creg: the counter to snapshot
  2576. */
  2577. static u64 qib_portcntr_7220(struct qib_pportdata *ppd, u32 reg)
  2578. {
  2579. u64 ret = 0ULL;
  2580. struct qib_devdata *dd = ppd->dd;
  2581. u16 creg;
  2582. /* 0xffff for unimplemented or synthesized counters */
  2583. static const u16 xlator[] = {
  2584. [QIBPORTCNTR_PKTSEND] = cr_pktsend,
  2585. [QIBPORTCNTR_WORDSEND] = cr_wordsend,
  2586. [QIBPORTCNTR_PSXMITDATA] = cr_psxmitdatacount,
  2587. [QIBPORTCNTR_PSXMITPKTS] = cr_psxmitpktscount,
  2588. [QIBPORTCNTR_PSXMITWAIT] = cr_psxmitwaitcount,
  2589. [QIBPORTCNTR_SENDSTALL] = cr_sendstall,
  2590. [QIBPORTCNTR_PKTRCV] = cr_pktrcv,
  2591. [QIBPORTCNTR_PSRCVDATA] = cr_psrcvdatacount,
  2592. [QIBPORTCNTR_PSRCVPKTS] = cr_psrcvpktscount,
  2593. [QIBPORTCNTR_RCVEBP] = cr_rcvebp,
  2594. [QIBPORTCNTR_RCVOVFL] = cr_rcvovfl,
  2595. [QIBPORTCNTR_WORDRCV] = cr_wordrcv,
  2596. [QIBPORTCNTR_RXDROPPKT] = cr_rxdroppkt,
  2597. [QIBPORTCNTR_RXLOCALPHYERR] = cr_rxotherlocalphyerr,
  2598. [QIBPORTCNTR_RXVLERR] = cr_rxvlerr,
  2599. [QIBPORTCNTR_ERRICRC] = cr_erricrc,
  2600. [QIBPORTCNTR_ERRVCRC] = cr_errvcrc,
  2601. [QIBPORTCNTR_ERRLPCRC] = cr_errlpcrc,
  2602. [QIBPORTCNTR_BADFORMAT] = cr_badformat,
  2603. [QIBPORTCNTR_ERR_RLEN] = cr_err_rlen,
  2604. [QIBPORTCNTR_IBSYMBOLERR] = cr_ibsymbolerr,
  2605. [QIBPORTCNTR_INVALIDRLEN] = cr_invalidrlen,
  2606. [QIBPORTCNTR_UNSUPVL] = cr_txunsupvl,
  2607. [QIBPORTCNTR_EXCESSBUFOVFL] = cr_excessbufferovfl,
  2608. [QIBPORTCNTR_ERRLINK] = cr_errlink,
  2609. [QIBPORTCNTR_IBLINKDOWN] = cr_iblinkdown,
  2610. [QIBPORTCNTR_IBLINKERRRECOV] = cr_iblinkerrrecov,
  2611. [QIBPORTCNTR_LLI] = cr_locallinkintegrityerr,
  2612. [QIBPORTCNTR_PSINTERVAL] = cr_psinterval,
  2613. [QIBPORTCNTR_PSSTART] = cr_psstart,
  2614. [QIBPORTCNTR_PSSTAT] = cr_psstat,
  2615. [QIBPORTCNTR_VL15PKTDROP] = cr_vl15droppedpkt,
  2616. [QIBPORTCNTR_ERRPKEY] = cr_errpkey,
  2617. [QIBPORTCNTR_KHDROVFL] = 0xffff,
  2618. };
  2619. if (reg >= ARRAY_SIZE(xlator)) {
  2620. qib_devinfo(ppd->dd->pcidev,
  2621. "Unimplemented portcounter %u\n", reg);
  2622. goto done;
  2623. }
  2624. creg = xlator[reg];
  2625. if (reg == QIBPORTCNTR_KHDROVFL) {
  2626. int i;
  2627. /* sum over all kernel contexts */
  2628. for (i = 0; i < dd->first_user_ctxt; i++)
  2629. ret += read_7220_creg32(dd, cr_portovfl + i);
  2630. }
  2631. if (creg == 0xffff)
  2632. goto done;
  2633. /*
  2634. * only fast incrementing counters are 64bit; use 32 bit reads to
  2635. * avoid two independent reads when on opteron
  2636. */
  2637. if ((creg == cr_wordsend || creg == cr_wordrcv ||
  2638. creg == cr_pktsend || creg == cr_pktrcv))
  2639. ret = read_7220_creg(dd, creg);
  2640. else
  2641. ret = read_7220_creg32(dd, creg);
  2642. if (creg == cr_ibsymbolerr) {
  2643. if (dd->pport->cpspec->ibdeltainprog)
  2644. ret -= ret - ppd->cpspec->ibsymsnap;
  2645. ret -= dd->pport->cpspec->ibsymdelta;
  2646. } else if (creg == cr_iblinkerrrecov) {
  2647. if (dd->pport->cpspec->ibdeltainprog)
  2648. ret -= ret - ppd->cpspec->iblnkerrsnap;
  2649. ret -= dd->pport->cpspec->iblnkerrdelta;
  2650. }
  2651. done:
  2652. return ret;
  2653. }
  2654. /*
  2655. * Device counter names (not port-specific), one line per stat,
  2656. * single string. Used by utilities like ipathstats to print the stats
  2657. * in a way which works for different versions of drivers, without changing
  2658. * the utility. Names need to be 12 chars or less (w/o newline), for proper
  2659. * display by utility.
  2660. * Non-error counters are first.
  2661. * Start of "error" conters is indicated by a leading "E " on the first
  2662. * "error" counter, and doesn't count in label length.
  2663. * The EgrOvfl list needs to be last so we truncate them at the configured
  2664. * context count for the device.
  2665. * cntr7220indices contains the corresponding register indices.
  2666. */
  2667. static const char cntr7220names[] =
  2668. "Interrupts\n"
  2669. "HostBusStall\n"
  2670. "E RxTIDFull\n"
  2671. "RxTIDInvalid\n"
  2672. "Ctxt0EgrOvfl\n"
  2673. "Ctxt1EgrOvfl\n"
  2674. "Ctxt2EgrOvfl\n"
  2675. "Ctxt3EgrOvfl\n"
  2676. "Ctxt4EgrOvfl\n"
  2677. "Ctxt5EgrOvfl\n"
  2678. "Ctxt6EgrOvfl\n"
  2679. "Ctxt7EgrOvfl\n"
  2680. "Ctxt8EgrOvfl\n"
  2681. "Ctxt9EgrOvfl\n"
  2682. "Ctx10EgrOvfl\n"
  2683. "Ctx11EgrOvfl\n"
  2684. "Ctx12EgrOvfl\n"
  2685. "Ctx13EgrOvfl\n"
  2686. "Ctx14EgrOvfl\n"
  2687. "Ctx15EgrOvfl\n"
  2688. "Ctx16EgrOvfl\n";
  2689. static const size_t cntr7220indices[] = {
  2690. cr_lbint,
  2691. cr_lbflowstall,
  2692. cr_errtidfull,
  2693. cr_errtidvalid,
  2694. cr_portovfl + 0,
  2695. cr_portovfl + 1,
  2696. cr_portovfl + 2,
  2697. cr_portovfl + 3,
  2698. cr_portovfl + 4,
  2699. cr_portovfl + 5,
  2700. cr_portovfl + 6,
  2701. cr_portovfl + 7,
  2702. cr_portovfl + 8,
  2703. cr_portovfl + 9,
  2704. cr_portovfl + 10,
  2705. cr_portovfl + 11,
  2706. cr_portovfl + 12,
  2707. cr_portovfl + 13,
  2708. cr_portovfl + 14,
  2709. cr_portovfl + 15,
  2710. cr_portovfl + 16,
  2711. };
  2712. /*
  2713. * same as cntr7220names and cntr7220indices, but for port-specific counters.
  2714. * portcntr7220indices is somewhat complicated by some registers needing
  2715. * adjustments of various kinds, and those are ORed with _PORT_VIRT_FLAG
  2716. */
  2717. static const char portcntr7220names[] =
  2718. "TxPkt\n"
  2719. "TxFlowPkt\n"
  2720. "TxWords\n"
  2721. "RxPkt\n"
  2722. "RxFlowPkt\n"
  2723. "RxWords\n"
  2724. "TxFlowStall\n"
  2725. "TxDmaDesc\n" /* 7220 and 7322-only */
  2726. "E RxDlidFltr\n" /* 7220 and 7322-only */
  2727. "IBStatusChng\n"
  2728. "IBLinkDown\n"
  2729. "IBLnkRecov\n"
  2730. "IBRxLinkErr\n"
  2731. "IBSymbolErr\n"
  2732. "RxLLIErr\n"
  2733. "RxBadFormat\n"
  2734. "RxBadLen\n"
  2735. "RxBufOvrfl\n"
  2736. "RxEBP\n"
  2737. "RxFlowCtlErr\n"
  2738. "RxICRCerr\n"
  2739. "RxLPCRCerr\n"
  2740. "RxVCRCerr\n"
  2741. "RxInvalLen\n"
  2742. "RxInvalPKey\n"
  2743. "RxPktDropped\n"
  2744. "TxBadLength\n"
  2745. "TxDropped\n"
  2746. "TxInvalLen\n"
  2747. "TxUnderrun\n"
  2748. "TxUnsupVL\n"
  2749. "RxLclPhyErr\n" /* 7220 and 7322-only */
  2750. "RxVL15Drop\n" /* 7220 and 7322-only */
  2751. "RxVlErr\n" /* 7220 and 7322-only */
  2752. "XcessBufOvfl\n" /* 7220 and 7322-only */
  2753. ;
  2754. #define _PORT_VIRT_FLAG 0x8000 /* "virtual", need adjustments */
  2755. static const size_t portcntr7220indices[] = {
  2756. QIBPORTCNTR_PKTSEND | _PORT_VIRT_FLAG,
  2757. cr_pktsendflow,
  2758. QIBPORTCNTR_WORDSEND | _PORT_VIRT_FLAG,
  2759. QIBPORTCNTR_PKTRCV | _PORT_VIRT_FLAG,
  2760. cr_pktrcvflowctrl,
  2761. QIBPORTCNTR_WORDRCV | _PORT_VIRT_FLAG,
  2762. QIBPORTCNTR_SENDSTALL | _PORT_VIRT_FLAG,
  2763. cr_txsdmadesc,
  2764. cr_rxdlidfltr,
  2765. cr_ibstatuschange,
  2766. QIBPORTCNTR_IBLINKDOWN | _PORT_VIRT_FLAG,
  2767. QIBPORTCNTR_IBLINKERRRECOV | _PORT_VIRT_FLAG,
  2768. QIBPORTCNTR_ERRLINK | _PORT_VIRT_FLAG,
  2769. QIBPORTCNTR_IBSYMBOLERR | _PORT_VIRT_FLAG,
  2770. QIBPORTCNTR_LLI | _PORT_VIRT_FLAG,
  2771. QIBPORTCNTR_BADFORMAT | _PORT_VIRT_FLAG,
  2772. QIBPORTCNTR_ERR_RLEN | _PORT_VIRT_FLAG,
  2773. QIBPORTCNTR_RCVOVFL | _PORT_VIRT_FLAG,
  2774. QIBPORTCNTR_RCVEBP | _PORT_VIRT_FLAG,
  2775. cr_rcvflowctrl_err,
  2776. QIBPORTCNTR_ERRICRC | _PORT_VIRT_FLAG,
  2777. QIBPORTCNTR_ERRLPCRC | _PORT_VIRT_FLAG,
  2778. QIBPORTCNTR_ERRVCRC | _PORT_VIRT_FLAG,
  2779. QIBPORTCNTR_INVALIDRLEN | _PORT_VIRT_FLAG,
  2780. QIBPORTCNTR_ERRPKEY | _PORT_VIRT_FLAG,
  2781. QIBPORTCNTR_RXDROPPKT | _PORT_VIRT_FLAG,
  2782. cr_invalidslen,
  2783. cr_senddropped,
  2784. cr_errslen,
  2785. cr_sendunderrun,
  2786. cr_txunsupvl,
  2787. QIBPORTCNTR_RXLOCALPHYERR | _PORT_VIRT_FLAG,
  2788. QIBPORTCNTR_VL15PKTDROP | _PORT_VIRT_FLAG,
  2789. QIBPORTCNTR_RXVLERR | _PORT_VIRT_FLAG,
  2790. QIBPORTCNTR_EXCESSBUFOVFL | _PORT_VIRT_FLAG,
  2791. };
  2792. /* do all the setup to make the counter reads efficient later */
  2793. static void init_7220_cntrnames(struct qib_devdata *dd)
  2794. {
  2795. int i, j = 0;
  2796. char *s;
  2797. for (i = 0, s = (char *)cntr7220names; s && j <= dd->cfgctxts;
  2798. i++) {
  2799. /* we always have at least one counter before the egrovfl */
  2800. if (!j && !strncmp("Ctxt0EgrOvfl", s + 1, 12))
  2801. j = 1;
  2802. s = strchr(s + 1, '\n');
  2803. if (s && j)
  2804. j++;
  2805. }
  2806. dd->cspec->ncntrs = i;
  2807. if (!s)
  2808. /* full list; size is without terminating null */
  2809. dd->cspec->cntrnamelen = sizeof(cntr7220names) - 1;
  2810. else
  2811. dd->cspec->cntrnamelen = 1 + s - cntr7220names;
  2812. dd->cspec->cntrs = kmalloc_array(dd->cspec->ncntrs, sizeof(u64),
  2813. GFP_KERNEL);
  2814. for (i = 0, s = (char *)portcntr7220names; s; i++)
  2815. s = strchr(s + 1, '\n');
  2816. dd->cspec->nportcntrs = i - 1;
  2817. dd->cspec->portcntrnamelen = sizeof(portcntr7220names) - 1;
  2818. dd->cspec->portcntrs = kmalloc_array(dd->cspec->nportcntrs,
  2819. sizeof(u64),
  2820. GFP_KERNEL);
  2821. }
  2822. static u32 qib_read_7220cntrs(struct qib_devdata *dd, loff_t pos, char **namep,
  2823. u64 **cntrp)
  2824. {
  2825. u32 ret;
  2826. if (!dd->cspec->cntrs) {
  2827. ret = 0;
  2828. goto done;
  2829. }
  2830. if (namep) {
  2831. *namep = (char *)cntr7220names;
  2832. ret = dd->cspec->cntrnamelen;
  2833. if (pos >= ret)
  2834. ret = 0; /* final read after getting everything */
  2835. } else {
  2836. u64 *cntr = dd->cspec->cntrs;
  2837. int i;
  2838. ret = dd->cspec->ncntrs * sizeof(u64);
  2839. if (!cntr || pos >= ret) {
  2840. /* everything read, or couldn't get memory */
  2841. ret = 0;
  2842. goto done;
  2843. }
  2844. *cntrp = cntr;
  2845. for (i = 0; i < dd->cspec->ncntrs; i++)
  2846. *cntr++ = read_7220_creg32(dd, cntr7220indices[i]);
  2847. }
  2848. done:
  2849. return ret;
  2850. }
  2851. static u32 qib_read_7220portcntrs(struct qib_devdata *dd, loff_t pos, u32 port,
  2852. char **namep, u64 **cntrp)
  2853. {
  2854. u32 ret;
  2855. if (!dd->cspec->portcntrs) {
  2856. ret = 0;
  2857. goto done;
  2858. }
  2859. if (namep) {
  2860. *namep = (char *)portcntr7220names;
  2861. ret = dd->cspec->portcntrnamelen;
  2862. if (pos >= ret)
  2863. ret = 0; /* final read after getting everything */
  2864. } else {
  2865. u64 *cntr = dd->cspec->portcntrs;
  2866. struct qib_pportdata *ppd = &dd->pport[port];
  2867. int i;
  2868. ret = dd->cspec->nportcntrs * sizeof(u64);
  2869. if (!cntr || pos >= ret) {
  2870. /* everything read, or couldn't get memory */
  2871. ret = 0;
  2872. goto done;
  2873. }
  2874. *cntrp = cntr;
  2875. for (i = 0; i < dd->cspec->nportcntrs; i++) {
  2876. if (portcntr7220indices[i] & _PORT_VIRT_FLAG)
  2877. *cntr++ = qib_portcntr_7220(ppd,
  2878. portcntr7220indices[i] &
  2879. ~_PORT_VIRT_FLAG);
  2880. else
  2881. *cntr++ = read_7220_creg32(dd,
  2882. portcntr7220indices[i]);
  2883. }
  2884. }
  2885. done:
  2886. return ret;
  2887. }
  2888. /**
  2889. * qib_get_7220_faststats - get word counters from chip before they overflow
  2890. * @opaque - contains a pointer to the qlogic_ib device qib_devdata
  2891. *
  2892. * This needs more work; in particular, decision on whether we really
  2893. * need traffic_wds done the way it is
  2894. * called from add_timer
  2895. */
  2896. static void qib_get_7220_faststats(struct timer_list *t)
  2897. {
  2898. struct qib_devdata *dd = from_timer(dd, t, stats_timer);
  2899. struct qib_pportdata *ppd = dd->pport;
  2900. unsigned long flags;
  2901. u64 traffic_wds;
  2902. /*
  2903. * don't access the chip while running diags, or memory diags can
  2904. * fail
  2905. */
  2906. if (!(dd->flags & QIB_INITTED) || dd->diag_client)
  2907. /* but re-arm the timer, for diags case; won't hurt other */
  2908. goto done;
  2909. /*
  2910. * We now try to maintain an activity timer, based on traffic
  2911. * exceeding a threshold, so we need to check the word-counts
  2912. * even if they are 64-bit.
  2913. */
  2914. traffic_wds = qib_portcntr_7220(ppd, cr_wordsend) +
  2915. qib_portcntr_7220(ppd, cr_wordrcv);
  2916. spin_lock_irqsave(&dd->eep_st_lock, flags);
  2917. traffic_wds -= dd->traffic_wds;
  2918. dd->traffic_wds += traffic_wds;
  2919. spin_unlock_irqrestore(&dd->eep_st_lock, flags);
  2920. done:
  2921. mod_timer(&dd->stats_timer, jiffies + HZ * ACTIVITY_TIMER);
  2922. }
  2923. /*
  2924. * If we are using MSI, try to fallback to INTx.
  2925. */
  2926. static int qib_7220_intr_fallback(struct qib_devdata *dd)
  2927. {
  2928. if (!dd->msi_lo)
  2929. return 0;
  2930. qib_devinfo(dd->pcidev,
  2931. "MSI interrupt not detected, trying INTx interrupts\n");
  2932. qib_free_irq(dd);
  2933. dd->msi_lo = 0;
  2934. if (pci_alloc_irq_vectors(dd->pcidev, 1, 1, PCI_IRQ_LEGACY) < 0)
  2935. qib_dev_err(dd, "Failed to enable INTx\n");
  2936. qib_setup_7220_interrupt(dd);
  2937. return 1;
  2938. }
  2939. /*
  2940. * Reset the XGXS (between serdes and IBC). Slightly less intrusive
  2941. * than resetting the IBC or external link state, and useful in some
  2942. * cases to cause some retraining. To do this right, we reset IBC
  2943. * as well.
  2944. */
  2945. static void qib_7220_xgxs_reset(struct qib_pportdata *ppd)
  2946. {
  2947. u64 val, prev_val;
  2948. struct qib_devdata *dd = ppd->dd;
  2949. prev_val = qib_read_kreg64(dd, kr_xgxs_cfg);
  2950. val = prev_val | QLOGIC_IB_XGXS_RESET;
  2951. prev_val &= ~QLOGIC_IB_XGXS_RESET; /* be sure */
  2952. qib_write_kreg(dd, kr_control,
  2953. dd->control & ~QLOGIC_IB_C_LINKENABLE);
  2954. qib_write_kreg(dd, kr_xgxs_cfg, val);
  2955. qib_read_kreg32(dd, kr_scratch);
  2956. qib_write_kreg(dd, kr_xgxs_cfg, prev_val);
  2957. qib_write_kreg(dd, kr_control, dd->control);
  2958. }
  2959. /*
  2960. * For this chip, we want to use the same buffer every time
  2961. * when we are trying to bring the link up (they are always VL15
  2962. * packets). At that link state the packet should always go out immediately
  2963. * (or at least be discarded at the tx interface if the link is down).
  2964. * If it doesn't, and the buffer isn't available, that means some other
  2965. * sender has gotten ahead of us, and is preventing our packet from going
  2966. * out. In that case, we flush all packets, and try again. If that still
  2967. * fails, we fail the request, and hope things work the next time around.
  2968. *
  2969. * We don't need very complicated heuristics on whether the packet had
  2970. * time to go out or not, since even at SDR 1X, it goes out in very short
  2971. * time periods, covered by the chip reads done here and as part of the
  2972. * flush.
  2973. */
  2974. static u32 __iomem *get_7220_link_buf(struct qib_pportdata *ppd, u32 *bnum)
  2975. {
  2976. u32 __iomem *buf;
  2977. u32 lbuf = ppd->dd->cspec->lastbuf_for_pio;
  2978. int do_cleanup;
  2979. unsigned long flags;
  2980. /*
  2981. * always blip to get avail list updated, since it's almost
  2982. * always needed, and is fairly cheap.
  2983. */
  2984. sendctrl_7220_mod(ppd->dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
  2985. qib_read_kreg64(ppd->dd, kr_scratch); /* extra chip flush */
  2986. buf = qib_getsendbuf_range(ppd->dd, bnum, lbuf, lbuf);
  2987. if (buf)
  2988. goto done;
  2989. spin_lock_irqsave(&ppd->sdma_lock, flags);
  2990. if (ppd->sdma_state.current_state == qib_sdma_state_s20_idle &&
  2991. ppd->sdma_state.current_state != qib_sdma_state_s00_hw_down) {
  2992. __qib_sdma_process_event(ppd, qib_sdma_event_e00_go_hw_down);
  2993. do_cleanup = 0;
  2994. } else {
  2995. do_cleanup = 1;
  2996. qib_7220_sdma_hw_clean_up(ppd);
  2997. }
  2998. spin_unlock_irqrestore(&ppd->sdma_lock, flags);
  2999. if (do_cleanup) {
  3000. qib_read_kreg64(ppd->dd, kr_scratch); /* extra chip flush */
  3001. buf = qib_getsendbuf_range(ppd->dd, bnum, lbuf, lbuf);
  3002. }
  3003. done:
  3004. return buf;
  3005. }
  3006. /*
  3007. * This code for non-IBTA-compliant IB speed negotiation is only known to
  3008. * work for the SDR to DDR transition, and only between an HCA and a switch
  3009. * with recent firmware. It is based on observed heuristics, rather than
  3010. * actual knowledge of the non-compliant speed negotiation.
  3011. * It has a number of hard-coded fields, since the hope is to rewrite this
  3012. * when a spec is available on how the negoation is intended to work.
  3013. */
  3014. static void autoneg_7220_sendpkt(struct qib_pportdata *ppd, u32 *hdr,
  3015. u32 dcnt, u32 *data)
  3016. {
  3017. int i;
  3018. u64 pbc;
  3019. u32 __iomem *piobuf;
  3020. u32 pnum;
  3021. struct qib_devdata *dd = ppd->dd;
  3022. i = 0;
  3023. pbc = 7 + dcnt + 1; /* 7 dword header, dword data, icrc */
  3024. pbc |= PBC_7220_VL15_SEND;
  3025. while (!(piobuf = get_7220_link_buf(ppd, &pnum))) {
  3026. if (i++ > 5)
  3027. return;
  3028. udelay(2);
  3029. }
  3030. sendctrl_7220_mod(dd->pport, QIB_SENDCTRL_DISARM_BUF(pnum));
  3031. writeq(pbc, piobuf);
  3032. qib_flush_wc();
  3033. qib_pio_copy(piobuf + 2, hdr, 7);
  3034. qib_pio_copy(piobuf + 9, data, dcnt);
  3035. if (dd->flags & QIB_USE_SPCL_TRIG) {
  3036. u32 spcl_off = (pnum >= dd->piobcnt2k) ? 2047 : 1023;
  3037. qib_flush_wc();
  3038. __raw_writel(0xaebecede, piobuf + spcl_off);
  3039. }
  3040. qib_flush_wc();
  3041. qib_sendbuf_done(dd, pnum);
  3042. }
  3043. /*
  3044. * _start packet gets sent twice at start, _done gets sent twice at end
  3045. */
  3046. static void autoneg_7220_send(struct qib_pportdata *ppd, int which)
  3047. {
  3048. struct qib_devdata *dd = ppd->dd;
  3049. static u32 swapped;
  3050. u32 dw, i, hcnt, dcnt, *data;
  3051. static u32 hdr[7] = { 0xf002ffff, 0x48ffff, 0x6400abba };
  3052. static u32 madpayload_start[0x40] = {
  3053. 0x1810103, 0x1, 0x0, 0x0, 0x2c90000, 0x2c9, 0x0, 0x0,
  3054. 0xffffffff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  3055. 0x1, 0x1388, 0x15e, 0x1, /* rest 0's */
  3056. };
  3057. static u32 madpayload_done[0x40] = {
  3058. 0x1810103, 0x1, 0x0, 0x0, 0x2c90000, 0x2c9, 0x0, 0x0,
  3059. 0xffffffff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  3060. 0x40000001, 0x1388, 0x15e, /* rest 0's */
  3061. };
  3062. dcnt = ARRAY_SIZE(madpayload_start);
  3063. hcnt = ARRAY_SIZE(hdr);
  3064. if (!swapped) {
  3065. /* for maintainability, do it at runtime */
  3066. for (i = 0; i < hcnt; i++) {
  3067. dw = (__force u32) cpu_to_be32(hdr[i]);
  3068. hdr[i] = dw;
  3069. }
  3070. for (i = 0; i < dcnt; i++) {
  3071. dw = (__force u32) cpu_to_be32(madpayload_start[i]);
  3072. madpayload_start[i] = dw;
  3073. dw = (__force u32) cpu_to_be32(madpayload_done[i]);
  3074. madpayload_done[i] = dw;
  3075. }
  3076. swapped = 1;
  3077. }
  3078. data = which ? madpayload_done : madpayload_start;
  3079. autoneg_7220_sendpkt(ppd, hdr, dcnt, data);
  3080. qib_read_kreg64(dd, kr_scratch);
  3081. udelay(2);
  3082. autoneg_7220_sendpkt(ppd, hdr, dcnt, data);
  3083. qib_read_kreg64(dd, kr_scratch);
  3084. udelay(2);
  3085. }
  3086. /*
  3087. * Do the absolute minimum to cause an IB speed change, and make it
  3088. * ready, but don't actually trigger the change. The caller will
  3089. * do that when ready (if link is in Polling training state, it will
  3090. * happen immediately, otherwise when link next goes down)
  3091. *
  3092. * This routine should only be used as part of the DDR autonegotation
  3093. * code for devices that are not compliant with IB 1.2 (or code that
  3094. * fixes things up for same).
  3095. *
  3096. * When link has gone down, and autoneg enabled, or autoneg has
  3097. * failed and we give up until next time we set both speeds, and
  3098. * then we want IBTA enabled as well as "use max enabled speed.
  3099. */
  3100. static void set_7220_ibspeed_fast(struct qib_pportdata *ppd, u32 speed)
  3101. {
  3102. ppd->cpspec->ibcddrctrl &= ~(IBA7220_IBC_SPEED_AUTONEG_MASK |
  3103. IBA7220_IBC_IBTA_1_2_MASK);
  3104. if (speed == (QIB_IB_SDR | QIB_IB_DDR))
  3105. ppd->cpspec->ibcddrctrl |= IBA7220_IBC_SPEED_AUTONEG_MASK |
  3106. IBA7220_IBC_IBTA_1_2_MASK;
  3107. else
  3108. ppd->cpspec->ibcddrctrl |= speed == QIB_IB_DDR ?
  3109. IBA7220_IBC_SPEED_DDR : IBA7220_IBC_SPEED_SDR;
  3110. qib_write_kreg(ppd->dd, kr_ibcddrctrl, ppd->cpspec->ibcddrctrl);
  3111. qib_write_kreg(ppd->dd, kr_scratch, 0);
  3112. }
  3113. /*
  3114. * This routine is only used when we are not talking to another
  3115. * IB 1.2-compliant device that we think can do DDR.
  3116. * (This includes all existing switch chips as of Oct 2007.)
  3117. * 1.2-compliant devices go directly to DDR prior to reaching INIT
  3118. */
  3119. static void try_7220_autoneg(struct qib_pportdata *ppd)
  3120. {
  3121. unsigned long flags;
  3122. /*
  3123. * Required for older non-IB1.2 DDR switches. Newer
  3124. * non-IB-compliant switches don't need it, but so far,
  3125. * aren't bothered by it either. "Magic constant"
  3126. */
  3127. qib_write_kreg(ppd->dd, kr_ncmodectrl, 0x3b9dc07);
  3128. spin_lock_irqsave(&ppd->lflags_lock, flags);
  3129. ppd->lflags |= QIBL_IB_AUTONEG_INPROG;
  3130. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  3131. autoneg_7220_send(ppd, 0);
  3132. set_7220_ibspeed_fast(ppd, QIB_IB_DDR);
  3133. toggle_7220_rclkrls(ppd->dd);
  3134. /* 2 msec is minimum length of a poll cycle */
  3135. queue_delayed_work(ib_wq, &ppd->cpspec->autoneg_work,
  3136. msecs_to_jiffies(2));
  3137. }
  3138. /*
  3139. * Handle the empirically determined mechanism for auto-negotiation
  3140. * of DDR speed with switches.
  3141. */
  3142. static void autoneg_7220_work(struct work_struct *work)
  3143. {
  3144. struct qib_pportdata *ppd;
  3145. struct qib_devdata *dd;
  3146. u32 i;
  3147. unsigned long flags;
  3148. ppd = &container_of(work, struct qib_chippport_specific,
  3149. autoneg_work.work)->pportdata;
  3150. dd = ppd->dd;
  3151. /*
  3152. * Busy wait for this first part, it should be at most a
  3153. * few hundred usec, since we scheduled ourselves for 2msec.
  3154. */
  3155. for (i = 0; i < 25; i++) {
  3156. if (SYM_FIELD(ppd->lastibcstat, IBCStatus, LinkTrainingState)
  3157. == IB_7220_LT_STATE_POLLQUIET) {
  3158. qib_set_linkstate(ppd, QIB_IB_LINKDOWN_DISABLE);
  3159. break;
  3160. }
  3161. udelay(100);
  3162. }
  3163. if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG))
  3164. goto done; /* we got there early or told to stop */
  3165. /* we expect this to timeout */
  3166. if (wait_event_timeout(ppd->cpspec->autoneg_wait,
  3167. !(ppd->lflags & QIBL_IB_AUTONEG_INPROG),
  3168. msecs_to_jiffies(90)))
  3169. goto done;
  3170. toggle_7220_rclkrls(dd);
  3171. /* we expect this to timeout */
  3172. if (wait_event_timeout(ppd->cpspec->autoneg_wait,
  3173. !(ppd->lflags & QIBL_IB_AUTONEG_INPROG),
  3174. msecs_to_jiffies(1700)))
  3175. goto done;
  3176. set_7220_ibspeed_fast(ppd, QIB_IB_SDR);
  3177. toggle_7220_rclkrls(dd);
  3178. /*
  3179. * Wait up to 250 msec for link to train and get to INIT at DDR;
  3180. * this should terminate early.
  3181. */
  3182. wait_event_timeout(ppd->cpspec->autoneg_wait,
  3183. !(ppd->lflags & QIBL_IB_AUTONEG_INPROG),
  3184. msecs_to_jiffies(250));
  3185. done:
  3186. if (ppd->lflags & QIBL_IB_AUTONEG_INPROG) {
  3187. spin_lock_irqsave(&ppd->lflags_lock, flags);
  3188. ppd->lflags &= ~QIBL_IB_AUTONEG_INPROG;
  3189. if (dd->cspec->autoneg_tries == AUTONEG_TRIES) {
  3190. ppd->lflags |= QIBL_IB_AUTONEG_FAILED;
  3191. dd->cspec->autoneg_tries = 0;
  3192. }
  3193. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  3194. set_7220_ibspeed_fast(ppd, ppd->link_speed_enabled);
  3195. }
  3196. }
  3197. static u32 qib_7220_iblink_state(u64 ibcs)
  3198. {
  3199. u32 state = (u32)SYM_FIELD(ibcs, IBCStatus, LinkState);
  3200. switch (state) {
  3201. case IB_7220_L_STATE_INIT:
  3202. state = IB_PORT_INIT;
  3203. break;
  3204. case IB_7220_L_STATE_ARM:
  3205. state = IB_PORT_ARMED;
  3206. break;
  3207. case IB_7220_L_STATE_ACTIVE:
  3208. /* fall through */
  3209. case IB_7220_L_STATE_ACT_DEFER:
  3210. state = IB_PORT_ACTIVE;
  3211. break;
  3212. default: /* fall through */
  3213. case IB_7220_L_STATE_DOWN:
  3214. state = IB_PORT_DOWN;
  3215. break;
  3216. }
  3217. return state;
  3218. }
  3219. /* returns the IBTA port state, rather than the IBC link training state */
  3220. static u8 qib_7220_phys_portstate(u64 ibcs)
  3221. {
  3222. u8 state = (u8)SYM_FIELD(ibcs, IBCStatus, LinkTrainingState);
  3223. return qib_7220_physportstate[state];
  3224. }
  3225. static int qib_7220_ib_updown(struct qib_pportdata *ppd, int ibup, u64 ibcs)
  3226. {
  3227. int ret = 0, symadj = 0;
  3228. struct qib_devdata *dd = ppd->dd;
  3229. unsigned long flags;
  3230. spin_lock_irqsave(&ppd->lflags_lock, flags);
  3231. ppd->lflags &= ~QIBL_IB_FORCE_NOTIFY;
  3232. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  3233. if (!ibup) {
  3234. /*
  3235. * When the link goes down we don't want AEQ running, so it
  3236. * won't interfere with IBC training, etc., and we need
  3237. * to go back to the static SerDes preset values.
  3238. */
  3239. if (!(ppd->lflags & (QIBL_IB_AUTONEG_FAILED |
  3240. QIBL_IB_AUTONEG_INPROG)))
  3241. set_7220_ibspeed_fast(ppd, ppd->link_speed_enabled);
  3242. if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG)) {
  3243. qib_sd7220_presets(dd);
  3244. qib_cancel_sends(ppd); /* initial disarm, etc. */
  3245. spin_lock_irqsave(&ppd->sdma_lock, flags);
  3246. if (__qib_sdma_running(ppd))
  3247. __qib_sdma_process_event(ppd,
  3248. qib_sdma_event_e70_go_idle);
  3249. spin_unlock_irqrestore(&ppd->sdma_lock, flags);
  3250. }
  3251. /* this might better in qib_sd7220_presets() */
  3252. set_7220_relock_poll(dd, ibup);
  3253. } else {
  3254. if (qib_compat_ddr_negotiate &&
  3255. !(ppd->lflags & (QIBL_IB_AUTONEG_FAILED |
  3256. QIBL_IB_AUTONEG_INPROG)) &&
  3257. ppd->link_speed_active == QIB_IB_SDR &&
  3258. (ppd->link_speed_enabled & (QIB_IB_DDR | QIB_IB_SDR)) ==
  3259. (QIB_IB_DDR | QIB_IB_SDR) &&
  3260. dd->cspec->autoneg_tries < AUTONEG_TRIES) {
  3261. /* we are SDR, and DDR auto-negotiation enabled */
  3262. ++dd->cspec->autoneg_tries;
  3263. if (!ppd->cpspec->ibdeltainprog) {
  3264. ppd->cpspec->ibdeltainprog = 1;
  3265. ppd->cpspec->ibsymsnap = read_7220_creg32(dd,
  3266. cr_ibsymbolerr);
  3267. ppd->cpspec->iblnkerrsnap = read_7220_creg32(dd,
  3268. cr_iblinkerrrecov);
  3269. }
  3270. try_7220_autoneg(ppd);
  3271. ret = 1; /* no other IB status change processing */
  3272. } else if ((ppd->lflags & QIBL_IB_AUTONEG_INPROG) &&
  3273. ppd->link_speed_active == QIB_IB_SDR) {
  3274. autoneg_7220_send(ppd, 1);
  3275. set_7220_ibspeed_fast(ppd, QIB_IB_DDR);
  3276. udelay(2);
  3277. toggle_7220_rclkrls(dd);
  3278. ret = 1; /* no other IB status change processing */
  3279. } else {
  3280. if ((ppd->lflags & QIBL_IB_AUTONEG_INPROG) &&
  3281. (ppd->link_speed_active & QIB_IB_DDR)) {
  3282. spin_lock_irqsave(&ppd->lflags_lock, flags);
  3283. ppd->lflags &= ~(QIBL_IB_AUTONEG_INPROG |
  3284. QIBL_IB_AUTONEG_FAILED);
  3285. spin_unlock_irqrestore(&ppd->lflags_lock,
  3286. flags);
  3287. dd->cspec->autoneg_tries = 0;
  3288. /* re-enable SDR, for next link down */
  3289. set_7220_ibspeed_fast(ppd,
  3290. ppd->link_speed_enabled);
  3291. wake_up(&ppd->cpspec->autoneg_wait);
  3292. symadj = 1;
  3293. } else if (ppd->lflags & QIBL_IB_AUTONEG_FAILED) {
  3294. /*
  3295. * Clear autoneg failure flag, and do setup
  3296. * so we'll try next time link goes down and
  3297. * back to INIT (possibly connected to a
  3298. * different device).
  3299. */
  3300. spin_lock_irqsave(&ppd->lflags_lock, flags);
  3301. ppd->lflags &= ~QIBL_IB_AUTONEG_FAILED;
  3302. spin_unlock_irqrestore(&ppd->lflags_lock,
  3303. flags);
  3304. ppd->cpspec->ibcddrctrl |=
  3305. IBA7220_IBC_IBTA_1_2_MASK;
  3306. qib_write_kreg(dd, kr_ncmodectrl, 0);
  3307. symadj = 1;
  3308. }
  3309. }
  3310. if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG))
  3311. symadj = 1;
  3312. if (!ret) {
  3313. ppd->delay_mult = rate_to_delay
  3314. [(ibcs >> IBA7220_LINKSPEED_SHIFT) & 1]
  3315. [(ibcs >> IBA7220_LINKWIDTH_SHIFT) & 1];
  3316. set_7220_relock_poll(dd, ibup);
  3317. spin_lock_irqsave(&ppd->sdma_lock, flags);
  3318. /*
  3319. * Unlike 7322, the 7220 needs this, due to lack of
  3320. * interrupt in some cases when we have sdma active
  3321. * when the link goes down.
  3322. */
  3323. if (ppd->sdma_state.current_state !=
  3324. qib_sdma_state_s20_idle)
  3325. __qib_sdma_process_event(ppd,
  3326. qib_sdma_event_e00_go_hw_down);
  3327. spin_unlock_irqrestore(&ppd->sdma_lock, flags);
  3328. }
  3329. }
  3330. if (symadj) {
  3331. if (ppd->cpspec->ibdeltainprog) {
  3332. ppd->cpspec->ibdeltainprog = 0;
  3333. ppd->cpspec->ibsymdelta += read_7220_creg32(ppd->dd,
  3334. cr_ibsymbolerr) - ppd->cpspec->ibsymsnap;
  3335. ppd->cpspec->iblnkerrdelta += read_7220_creg32(ppd->dd,
  3336. cr_iblinkerrrecov) - ppd->cpspec->iblnkerrsnap;
  3337. }
  3338. } else if (!ibup && qib_compat_ddr_negotiate &&
  3339. !ppd->cpspec->ibdeltainprog &&
  3340. !(ppd->lflags & QIBL_IB_AUTONEG_INPROG)) {
  3341. ppd->cpspec->ibdeltainprog = 1;
  3342. ppd->cpspec->ibsymsnap = read_7220_creg32(ppd->dd,
  3343. cr_ibsymbolerr);
  3344. ppd->cpspec->iblnkerrsnap = read_7220_creg32(ppd->dd,
  3345. cr_iblinkerrrecov);
  3346. }
  3347. if (!ret)
  3348. qib_setup_7220_setextled(ppd, ibup);
  3349. return ret;
  3350. }
  3351. /*
  3352. * Does read/modify/write to appropriate registers to
  3353. * set output and direction bits selected by mask.
  3354. * these are in their canonical postions (e.g. lsb of
  3355. * dir will end up in D48 of extctrl on existing chips).
  3356. * returns contents of GP Inputs.
  3357. */
  3358. static int gpio_7220_mod(struct qib_devdata *dd, u32 out, u32 dir, u32 mask)
  3359. {
  3360. u64 read_val, new_out;
  3361. unsigned long flags;
  3362. if (mask) {
  3363. /* some bits being written, lock access to GPIO */
  3364. dir &= mask;
  3365. out &= mask;
  3366. spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
  3367. dd->cspec->extctrl &= ~((u64)mask << SYM_LSB(EXTCtrl, GPIOOe));
  3368. dd->cspec->extctrl |= ((u64) dir << SYM_LSB(EXTCtrl, GPIOOe));
  3369. new_out = (dd->cspec->gpio_out & ~mask) | out;
  3370. qib_write_kreg(dd, kr_extctrl, dd->cspec->extctrl);
  3371. qib_write_kreg(dd, kr_gpio_out, new_out);
  3372. dd->cspec->gpio_out = new_out;
  3373. spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
  3374. }
  3375. /*
  3376. * It is unlikely that a read at this time would get valid
  3377. * data on a pin whose direction line was set in the same
  3378. * call to this function. We include the read here because
  3379. * that allows us to potentially combine a change on one pin with
  3380. * a read on another, and because the old code did something like
  3381. * this.
  3382. */
  3383. read_val = qib_read_kreg64(dd, kr_extstatus);
  3384. return SYM_FIELD(read_val, EXTStatus, GPIOIn);
  3385. }
  3386. /*
  3387. * Read fundamental info we need to use the chip. These are
  3388. * the registers that describe chip capabilities, and are
  3389. * saved in shadow registers.
  3390. */
  3391. static void get_7220_chip_params(struct qib_devdata *dd)
  3392. {
  3393. u64 val;
  3394. u32 piobufs;
  3395. int mtu;
  3396. dd->uregbase = qib_read_kreg32(dd, kr_userregbase);
  3397. dd->rcvtidcnt = qib_read_kreg32(dd, kr_rcvtidcnt);
  3398. dd->rcvtidbase = qib_read_kreg32(dd, kr_rcvtidbase);
  3399. dd->rcvegrbase = qib_read_kreg32(dd, kr_rcvegrbase);
  3400. dd->palign = qib_read_kreg32(dd, kr_palign);
  3401. dd->piobufbase = qib_read_kreg64(dd, kr_sendpiobufbase);
  3402. dd->pio2k_bufbase = dd->piobufbase & 0xffffffff;
  3403. val = qib_read_kreg64(dd, kr_sendpiosize);
  3404. dd->piosize2k = val & ~0U;
  3405. dd->piosize4k = val >> 32;
  3406. mtu = ib_mtu_enum_to_int(qib_ibmtu);
  3407. if (mtu == -1)
  3408. mtu = QIB_DEFAULT_MTU;
  3409. dd->pport->ibmtu = (u32)mtu;
  3410. val = qib_read_kreg64(dd, kr_sendpiobufcnt);
  3411. dd->piobcnt2k = val & ~0U;
  3412. dd->piobcnt4k = val >> 32;
  3413. /* these may be adjusted in init_chip_wc_pat() */
  3414. dd->pio2kbase = (u32 __iomem *)
  3415. ((char __iomem *) dd->kregbase + dd->pio2k_bufbase);
  3416. if (dd->piobcnt4k) {
  3417. dd->pio4kbase = (u32 __iomem *)
  3418. ((char __iomem *) dd->kregbase +
  3419. (dd->piobufbase >> 32));
  3420. /*
  3421. * 4K buffers take 2 pages; we use roundup just to be
  3422. * paranoid; we calculate it once here, rather than on
  3423. * ever buf allocate
  3424. */
  3425. dd->align4k = ALIGN(dd->piosize4k, dd->palign);
  3426. }
  3427. piobufs = dd->piobcnt4k + dd->piobcnt2k;
  3428. dd->pioavregs = ALIGN(piobufs, sizeof(u64) * BITS_PER_BYTE / 2) /
  3429. (sizeof(u64) * BITS_PER_BYTE / 2);
  3430. }
  3431. /*
  3432. * The chip base addresses in cspec and cpspec have to be set
  3433. * after possible init_chip_wc_pat(), rather than in
  3434. * qib_get_7220_chip_params(), so split out as separate function
  3435. */
  3436. static void set_7220_baseaddrs(struct qib_devdata *dd)
  3437. {
  3438. u32 cregbase;
  3439. /* init after possible re-map in init_chip_wc_pat() */
  3440. cregbase = qib_read_kreg32(dd, kr_counterregbase);
  3441. dd->cspec->cregbase = (u64 __iomem *)
  3442. ((char __iomem *) dd->kregbase + cregbase);
  3443. dd->egrtidbase = (u64 __iomem *)
  3444. ((char __iomem *) dd->kregbase + dd->rcvegrbase);
  3445. }
  3446. #define SENDCTRL_SHADOWED (SYM_MASK(SendCtrl, SendIntBufAvail) | \
  3447. SYM_MASK(SendCtrl, SPioEnable) | \
  3448. SYM_MASK(SendCtrl, SSpecialTriggerEn) | \
  3449. SYM_MASK(SendCtrl, SendBufAvailUpd) | \
  3450. SYM_MASK(SendCtrl, AvailUpdThld) | \
  3451. SYM_MASK(SendCtrl, SDmaEnable) | \
  3452. SYM_MASK(SendCtrl, SDmaIntEnable) | \
  3453. SYM_MASK(SendCtrl, SDmaHalt) | \
  3454. SYM_MASK(SendCtrl, SDmaSingleDescriptor))
  3455. static int sendctrl_hook(struct qib_devdata *dd,
  3456. const struct diag_observer *op,
  3457. u32 offs, u64 *data, u64 mask, int only_32)
  3458. {
  3459. unsigned long flags;
  3460. unsigned idx = offs / sizeof(u64);
  3461. u64 local_data, all_bits;
  3462. if (idx != kr_sendctrl) {
  3463. qib_dev_err(dd, "SendCtrl Hook called with offs %X, %s-bit\n",
  3464. offs, only_32 ? "32" : "64");
  3465. return 0;
  3466. }
  3467. all_bits = ~0ULL;
  3468. if (only_32)
  3469. all_bits >>= 32;
  3470. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  3471. if ((mask & all_bits) != all_bits) {
  3472. /*
  3473. * At least some mask bits are zero, so we need
  3474. * to read. The judgement call is whether from
  3475. * reg or shadow. First-cut: read reg, and complain
  3476. * if any bits which should be shadowed are different
  3477. * from their shadowed value.
  3478. */
  3479. if (only_32)
  3480. local_data = (u64)qib_read_kreg32(dd, idx);
  3481. else
  3482. local_data = qib_read_kreg64(dd, idx);
  3483. qib_dev_err(dd, "Sendctrl -> %X, Shad -> %X\n",
  3484. (u32)local_data, (u32)dd->sendctrl);
  3485. if ((local_data & SENDCTRL_SHADOWED) !=
  3486. (dd->sendctrl & SENDCTRL_SHADOWED))
  3487. qib_dev_err(dd, "Sendctrl read: %X shadow is %X\n",
  3488. (u32)local_data, (u32) dd->sendctrl);
  3489. *data = (local_data & ~mask) | (*data & mask);
  3490. }
  3491. if (mask) {
  3492. /*
  3493. * At least some mask bits are one, so we need
  3494. * to write, but only shadow some bits.
  3495. */
  3496. u64 sval, tval; /* Shadowed, transient */
  3497. /*
  3498. * New shadow val is bits we don't want to touch,
  3499. * ORed with bits we do, that are intended for shadow.
  3500. */
  3501. sval = (dd->sendctrl & ~mask);
  3502. sval |= *data & SENDCTRL_SHADOWED & mask;
  3503. dd->sendctrl = sval;
  3504. tval = sval | (*data & ~SENDCTRL_SHADOWED & mask);
  3505. qib_dev_err(dd, "Sendctrl <- %X, Shad <- %X\n",
  3506. (u32)tval, (u32)sval);
  3507. qib_write_kreg(dd, kr_sendctrl, tval);
  3508. qib_write_kreg(dd, kr_scratch, 0Ull);
  3509. }
  3510. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  3511. return only_32 ? 4 : 8;
  3512. }
  3513. static const struct diag_observer sendctrl_observer = {
  3514. sendctrl_hook, kr_sendctrl * sizeof(u64),
  3515. kr_sendctrl * sizeof(u64)
  3516. };
  3517. /*
  3518. * write the final few registers that depend on some of the
  3519. * init setup. Done late in init, just before bringing up
  3520. * the serdes.
  3521. */
  3522. static int qib_late_7220_initreg(struct qib_devdata *dd)
  3523. {
  3524. int ret = 0;
  3525. u64 val;
  3526. qib_write_kreg(dd, kr_rcvhdrentsize, dd->rcvhdrentsize);
  3527. qib_write_kreg(dd, kr_rcvhdrsize, dd->rcvhdrsize);
  3528. qib_write_kreg(dd, kr_rcvhdrcnt, dd->rcvhdrcnt);
  3529. qib_write_kreg(dd, kr_sendpioavailaddr, dd->pioavailregs_phys);
  3530. val = qib_read_kreg64(dd, kr_sendpioavailaddr);
  3531. if (val != dd->pioavailregs_phys) {
  3532. qib_dev_err(dd,
  3533. "Catastrophic software error, SendPIOAvailAddr written as %lx, read back as %llx\n",
  3534. (unsigned long) dd->pioavailregs_phys,
  3535. (unsigned long long) val);
  3536. ret = -EINVAL;
  3537. }
  3538. qib_register_observer(dd, &sendctrl_observer);
  3539. return ret;
  3540. }
  3541. static int qib_init_7220_variables(struct qib_devdata *dd)
  3542. {
  3543. struct qib_chippport_specific *cpspec;
  3544. struct qib_pportdata *ppd;
  3545. int ret = 0;
  3546. u32 sbufs, updthresh;
  3547. cpspec = (struct qib_chippport_specific *)(dd + 1);
  3548. ppd = &cpspec->pportdata;
  3549. dd->pport = ppd;
  3550. dd->num_pports = 1;
  3551. dd->cspec = (struct qib_chip_specific *)(cpspec + dd->num_pports);
  3552. dd->cspec->dd = dd;
  3553. ppd->cpspec = cpspec;
  3554. spin_lock_init(&dd->cspec->sdepb_lock);
  3555. spin_lock_init(&dd->cspec->rcvmod_lock);
  3556. spin_lock_init(&dd->cspec->gpio_lock);
  3557. /* we haven't yet set QIB_PRESENT, so use read directly */
  3558. dd->revision = readq(&dd->kregbase[kr_revision]);
  3559. if ((dd->revision & 0xffffffffU) == 0xffffffffU) {
  3560. qib_dev_err(dd,
  3561. "Revision register read failure, giving up initialization\n");
  3562. ret = -ENODEV;
  3563. goto bail;
  3564. }
  3565. dd->flags |= QIB_PRESENT; /* now register routines work */
  3566. dd->majrev = (u8) SYM_FIELD(dd->revision, Revision_R,
  3567. ChipRevMajor);
  3568. dd->minrev = (u8) SYM_FIELD(dd->revision, Revision_R,
  3569. ChipRevMinor);
  3570. get_7220_chip_params(dd);
  3571. qib_7220_boardname(dd);
  3572. /*
  3573. * GPIO bits for TWSI data and clock,
  3574. * used for serial EEPROM.
  3575. */
  3576. dd->gpio_sda_num = _QIB_GPIO_SDA_NUM;
  3577. dd->gpio_scl_num = _QIB_GPIO_SCL_NUM;
  3578. dd->twsi_eeprom_dev = QIB_TWSI_EEPROM_DEV;
  3579. dd->flags |= QIB_HAS_INTX | QIB_HAS_LINK_LATENCY |
  3580. QIB_NODMA_RTAIL | QIB_HAS_THRESH_UPDATE;
  3581. dd->flags |= qib_special_trigger ?
  3582. QIB_USE_SPCL_TRIG : QIB_HAS_SEND_DMA;
  3583. init_waitqueue_head(&cpspec->autoneg_wait);
  3584. INIT_DELAYED_WORK(&cpspec->autoneg_work, autoneg_7220_work);
  3585. ret = qib_init_pportdata(ppd, dd, 0, 1);
  3586. if (ret)
  3587. goto bail;
  3588. ppd->link_width_supported = IB_WIDTH_1X | IB_WIDTH_4X;
  3589. ppd->link_speed_supported = QIB_IB_SDR | QIB_IB_DDR;
  3590. ppd->link_width_enabled = ppd->link_width_supported;
  3591. ppd->link_speed_enabled = ppd->link_speed_supported;
  3592. /*
  3593. * Set the initial values to reasonable default, will be set
  3594. * for real when link is up.
  3595. */
  3596. ppd->link_width_active = IB_WIDTH_4X;
  3597. ppd->link_speed_active = QIB_IB_SDR;
  3598. ppd->delay_mult = rate_to_delay[0][1];
  3599. ppd->vls_supported = IB_VL_VL0;
  3600. ppd->vls_operational = ppd->vls_supported;
  3601. if (!qib_mini_init)
  3602. qib_write_kreg(dd, kr_rcvbthqp, QIB_KD_QP);
  3603. timer_setup(&ppd->cpspec->chase_timer, reenable_7220_chase, 0);
  3604. qib_num_cfg_vls = 1; /* if any 7220's, only one VL */
  3605. dd->rcvhdrentsize = QIB_RCVHDR_ENTSIZE;
  3606. dd->rcvhdrsize = QIB_DFLT_RCVHDRSIZE;
  3607. dd->rhf_offset =
  3608. dd->rcvhdrentsize - sizeof(u64) / sizeof(u32);
  3609. /* we always allocate at least 2048 bytes for eager buffers */
  3610. ret = ib_mtu_enum_to_int(qib_ibmtu);
  3611. dd->rcvegrbufsize = ret != -1 ? max(ret, 2048) : QIB_DEFAULT_MTU;
  3612. BUG_ON(!is_power_of_2(dd->rcvegrbufsize));
  3613. dd->rcvegrbufsize_shift = ilog2(dd->rcvegrbufsize);
  3614. qib_7220_tidtemplate(dd);
  3615. /*
  3616. * We can request a receive interrupt for 1 or
  3617. * more packets from current offset. For now, we set this
  3618. * up for a single packet.
  3619. */
  3620. dd->rhdrhead_intr_off = 1ULL << 32;
  3621. /* setup the stats timer; the add_timer is done at end of init */
  3622. timer_setup(&dd->stats_timer, qib_get_7220_faststats, 0);
  3623. dd->stats_timer.expires = jiffies + ACTIVITY_TIMER * HZ;
  3624. /*
  3625. * Control[4] has been added to change the arbitration within
  3626. * the SDMA engine between favoring data fetches over descriptor
  3627. * fetches. qib_sdma_fetch_arb==0 gives data fetches priority.
  3628. */
  3629. if (qib_sdma_fetch_arb)
  3630. dd->control |= 1 << 4;
  3631. dd->ureg_align = 0x10000; /* 64KB alignment */
  3632. dd->piosize2kmax_dwords = (dd->piosize2k >> 2)-1;
  3633. qib_7220_config_ctxts(dd);
  3634. qib_set_ctxtcnt(dd); /* needed for PAT setup */
  3635. ret = init_chip_wc_pat(dd, 0);
  3636. if (ret)
  3637. goto bail;
  3638. set_7220_baseaddrs(dd); /* set chip access pointers now */
  3639. ret = 0;
  3640. if (qib_mini_init)
  3641. goto bail;
  3642. ret = qib_create_ctxts(dd);
  3643. init_7220_cntrnames(dd);
  3644. /* use all of 4KB buffers for the kernel SDMA, zero if !SDMA.
  3645. * reserve the update threshold amount for other kernel use, such
  3646. * as sending SMI, MAD, and ACKs, or 3, whichever is greater,
  3647. * unless we aren't enabling SDMA, in which case we want to use
  3648. * all the 4k bufs for the kernel.
  3649. * if this was less than the update threshold, we could wait
  3650. * a long time for an update. Coded this way because we
  3651. * sometimes change the update threshold for various reasons,
  3652. * and we want this to remain robust.
  3653. */
  3654. updthresh = 8U; /* update threshold */
  3655. if (dd->flags & QIB_HAS_SEND_DMA) {
  3656. dd->cspec->sdmabufcnt = dd->piobcnt4k;
  3657. sbufs = updthresh > 3 ? updthresh : 3;
  3658. } else {
  3659. dd->cspec->sdmabufcnt = 0;
  3660. sbufs = dd->piobcnt4k;
  3661. }
  3662. dd->cspec->lastbuf_for_pio = dd->piobcnt2k + dd->piobcnt4k -
  3663. dd->cspec->sdmabufcnt;
  3664. dd->lastctxt_piobuf = dd->cspec->lastbuf_for_pio - sbufs;
  3665. dd->cspec->lastbuf_for_pio--; /* range is <= , not < */
  3666. dd->last_pio = dd->cspec->lastbuf_for_pio;
  3667. dd->pbufsctxt = dd->lastctxt_piobuf /
  3668. (dd->cfgctxts - dd->first_user_ctxt);
  3669. /*
  3670. * if we are at 16 user contexts, we will have one 7 sbufs
  3671. * per context, so drop the update threshold to match. We
  3672. * want to update before we actually run out, at low pbufs/ctxt
  3673. * so give ourselves some margin
  3674. */
  3675. if ((dd->pbufsctxt - 2) < updthresh)
  3676. updthresh = dd->pbufsctxt - 2;
  3677. dd->cspec->updthresh_dflt = updthresh;
  3678. dd->cspec->updthresh = updthresh;
  3679. /* before full enable, no interrupts, no locking needed */
  3680. dd->sendctrl |= (updthresh & SYM_RMASK(SendCtrl, AvailUpdThld))
  3681. << SYM_LSB(SendCtrl, AvailUpdThld);
  3682. dd->psxmitwait_supported = 1;
  3683. dd->psxmitwait_check_rate = QIB_7220_PSXMITWAIT_CHECK_RATE;
  3684. bail:
  3685. return ret;
  3686. }
  3687. static u32 __iomem *qib_7220_getsendbuf(struct qib_pportdata *ppd, u64 pbc,
  3688. u32 *pbufnum)
  3689. {
  3690. u32 first, last, plen = pbc & QIB_PBC_LENGTH_MASK;
  3691. struct qib_devdata *dd = ppd->dd;
  3692. u32 __iomem *buf;
  3693. if (((pbc >> 32) & PBC_7220_VL15_SEND_CTRL) &&
  3694. !(ppd->lflags & (QIBL_IB_AUTONEG_INPROG | QIBL_LINKACTIVE)))
  3695. buf = get_7220_link_buf(ppd, pbufnum);
  3696. else {
  3697. if ((plen + 1) > dd->piosize2kmax_dwords)
  3698. first = dd->piobcnt2k;
  3699. else
  3700. first = 0;
  3701. /* try 4k if all 2k busy, so same last for both sizes */
  3702. last = dd->cspec->lastbuf_for_pio;
  3703. buf = qib_getsendbuf_range(dd, pbufnum, first, last);
  3704. }
  3705. return buf;
  3706. }
  3707. /* these 2 "counters" are really control registers, and are always RW */
  3708. static void qib_set_cntr_7220_sample(struct qib_pportdata *ppd, u32 intv,
  3709. u32 start)
  3710. {
  3711. write_7220_creg(ppd->dd, cr_psinterval, intv);
  3712. write_7220_creg(ppd->dd, cr_psstart, start);
  3713. }
  3714. /*
  3715. * NOTE: no real attempt is made to generalize the SDMA stuff.
  3716. * At some point "soon" we will have a new more generalized
  3717. * set of sdma interface, and then we'll clean this up.
  3718. */
  3719. /* Must be called with sdma_lock held, or before init finished */
  3720. static void qib_sdma_update_7220_tail(struct qib_pportdata *ppd, u16 tail)
  3721. {
  3722. /* Commit writes to memory and advance the tail on the chip */
  3723. wmb();
  3724. ppd->sdma_descq_tail = tail;
  3725. qib_write_kreg(ppd->dd, kr_senddmatail, tail);
  3726. }
  3727. static void qib_sdma_set_7220_desc_cnt(struct qib_pportdata *ppd, unsigned cnt)
  3728. {
  3729. }
  3730. static struct sdma_set_state_action sdma_7220_action_table[] = {
  3731. [qib_sdma_state_s00_hw_down] = {
  3732. .op_enable = 0,
  3733. .op_intenable = 0,
  3734. .op_halt = 0,
  3735. .go_s99_running_tofalse = 1,
  3736. },
  3737. [qib_sdma_state_s10_hw_start_up_wait] = {
  3738. .op_enable = 1,
  3739. .op_intenable = 1,
  3740. .op_halt = 1,
  3741. },
  3742. [qib_sdma_state_s20_idle] = {
  3743. .op_enable = 1,
  3744. .op_intenable = 1,
  3745. .op_halt = 1,
  3746. },
  3747. [qib_sdma_state_s30_sw_clean_up_wait] = {
  3748. .op_enable = 0,
  3749. .op_intenable = 1,
  3750. .op_halt = 0,
  3751. },
  3752. [qib_sdma_state_s40_hw_clean_up_wait] = {
  3753. .op_enable = 1,
  3754. .op_intenable = 1,
  3755. .op_halt = 1,
  3756. },
  3757. [qib_sdma_state_s50_hw_halt_wait] = {
  3758. .op_enable = 1,
  3759. .op_intenable = 1,
  3760. .op_halt = 1,
  3761. },
  3762. [qib_sdma_state_s99_running] = {
  3763. .op_enable = 1,
  3764. .op_intenable = 1,
  3765. .op_halt = 0,
  3766. .go_s99_running_totrue = 1,
  3767. },
  3768. };
  3769. static void qib_7220_sdma_init_early(struct qib_pportdata *ppd)
  3770. {
  3771. ppd->sdma_state.set_state_action = sdma_7220_action_table;
  3772. }
  3773. static int init_sdma_7220_regs(struct qib_pportdata *ppd)
  3774. {
  3775. struct qib_devdata *dd = ppd->dd;
  3776. unsigned i, n;
  3777. u64 senddmabufmask[3] = { 0 };
  3778. /* Set SendDmaBase */
  3779. qib_write_kreg(dd, kr_senddmabase, ppd->sdma_descq_phys);
  3780. qib_sdma_7220_setlengen(ppd);
  3781. qib_sdma_update_7220_tail(ppd, 0); /* Set SendDmaTail */
  3782. /* Set SendDmaHeadAddr */
  3783. qib_write_kreg(dd, kr_senddmaheadaddr, ppd->sdma_head_phys);
  3784. /*
  3785. * Reserve all the former "kernel" piobufs, using high number range
  3786. * so we get as many 4K buffers as possible
  3787. */
  3788. n = dd->piobcnt2k + dd->piobcnt4k;
  3789. i = n - dd->cspec->sdmabufcnt;
  3790. for (; i < n; ++i) {
  3791. unsigned word = i / 64;
  3792. unsigned bit = i & 63;
  3793. BUG_ON(word >= 3);
  3794. senddmabufmask[word] |= 1ULL << bit;
  3795. }
  3796. qib_write_kreg(dd, kr_senddmabufmask0, senddmabufmask[0]);
  3797. qib_write_kreg(dd, kr_senddmabufmask1, senddmabufmask[1]);
  3798. qib_write_kreg(dd, kr_senddmabufmask2, senddmabufmask[2]);
  3799. ppd->sdma_state.first_sendbuf = i;
  3800. ppd->sdma_state.last_sendbuf = n;
  3801. return 0;
  3802. }
  3803. /* sdma_lock must be held */
  3804. static u16 qib_sdma_7220_gethead(struct qib_pportdata *ppd)
  3805. {
  3806. struct qib_devdata *dd = ppd->dd;
  3807. int sane;
  3808. int use_dmahead;
  3809. u16 swhead;
  3810. u16 swtail;
  3811. u16 cnt;
  3812. u16 hwhead;
  3813. use_dmahead = __qib_sdma_running(ppd) &&
  3814. (dd->flags & QIB_HAS_SDMA_TIMEOUT);
  3815. retry:
  3816. hwhead = use_dmahead ?
  3817. (u16)le64_to_cpu(*ppd->sdma_head_dma) :
  3818. (u16)qib_read_kreg32(dd, kr_senddmahead);
  3819. swhead = ppd->sdma_descq_head;
  3820. swtail = ppd->sdma_descq_tail;
  3821. cnt = ppd->sdma_descq_cnt;
  3822. if (swhead < swtail) {
  3823. /* not wrapped */
  3824. sane = (hwhead >= swhead) & (hwhead <= swtail);
  3825. } else if (swhead > swtail) {
  3826. /* wrapped around */
  3827. sane = ((hwhead >= swhead) && (hwhead < cnt)) ||
  3828. (hwhead <= swtail);
  3829. } else {
  3830. /* empty */
  3831. sane = (hwhead == swhead);
  3832. }
  3833. if (unlikely(!sane)) {
  3834. if (use_dmahead) {
  3835. /* try one more time, directly from the register */
  3836. use_dmahead = 0;
  3837. goto retry;
  3838. }
  3839. /* assume no progress */
  3840. hwhead = swhead;
  3841. }
  3842. return hwhead;
  3843. }
  3844. static int qib_sdma_7220_busy(struct qib_pportdata *ppd)
  3845. {
  3846. u64 hwstatus = qib_read_kreg64(ppd->dd, kr_senddmastatus);
  3847. return (hwstatus & SYM_MASK(SendDmaStatus, ScoreBoardDrainInProg)) ||
  3848. (hwstatus & SYM_MASK(SendDmaStatus, AbortInProg)) ||
  3849. (hwstatus & SYM_MASK(SendDmaStatus, InternalSDmaEnable)) ||
  3850. !(hwstatus & SYM_MASK(SendDmaStatus, ScbEmpty));
  3851. }
  3852. /*
  3853. * Compute the amount of delay before sending the next packet if the
  3854. * port's send rate differs from the static rate set for the QP.
  3855. * Since the delay affects this packet but the amount of the delay is
  3856. * based on the length of the previous packet, use the last delay computed
  3857. * and save the delay count for this packet to be used next time
  3858. * we get here.
  3859. */
  3860. static u32 qib_7220_setpbc_control(struct qib_pportdata *ppd, u32 plen,
  3861. u8 srate, u8 vl)
  3862. {
  3863. u8 snd_mult = ppd->delay_mult;
  3864. u8 rcv_mult = ib_rate_to_delay[srate];
  3865. u32 ret = ppd->cpspec->last_delay_mult;
  3866. ppd->cpspec->last_delay_mult = (rcv_mult > snd_mult) ?
  3867. (plen * (rcv_mult - snd_mult) + 1) >> 1 : 0;
  3868. /* Indicate VL15, if necessary */
  3869. if (vl == 15)
  3870. ret |= PBC_7220_VL15_SEND_CTRL;
  3871. return ret;
  3872. }
  3873. static void qib_7220_initvl15_bufs(struct qib_devdata *dd)
  3874. {
  3875. }
  3876. static void qib_7220_init_ctxt(struct qib_ctxtdata *rcd)
  3877. {
  3878. if (!rcd->ctxt) {
  3879. rcd->rcvegrcnt = IBA7220_KRCVEGRCNT;
  3880. rcd->rcvegr_tid_base = 0;
  3881. } else {
  3882. rcd->rcvegrcnt = rcd->dd->cspec->rcvegrcnt;
  3883. rcd->rcvegr_tid_base = IBA7220_KRCVEGRCNT +
  3884. (rcd->ctxt - 1) * rcd->rcvegrcnt;
  3885. }
  3886. }
  3887. static void qib_7220_txchk_change(struct qib_devdata *dd, u32 start,
  3888. u32 len, u32 which, struct qib_ctxtdata *rcd)
  3889. {
  3890. int i;
  3891. unsigned long flags;
  3892. switch (which) {
  3893. case TXCHK_CHG_TYPE_KERN:
  3894. /* see if we need to raise avail update threshold */
  3895. spin_lock_irqsave(&dd->uctxt_lock, flags);
  3896. for (i = dd->first_user_ctxt;
  3897. dd->cspec->updthresh != dd->cspec->updthresh_dflt
  3898. && i < dd->cfgctxts; i++)
  3899. if (dd->rcd[i] && dd->rcd[i]->subctxt_cnt &&
  3900. ((dd->rcd[i]->piocnt / dd->rcd[i]->subctxt_cnt) - 1)
  3901. < dd->cspec->updthresh_dflt)
  3902. break;
  3903. spin_unlock_irqrestore(&dd->uctxt_lock, flags);
  3904. if (i == dd->cfgctxts) {
  3905. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  3906. dd->cspec->updthresh = dd->cspec->updthresh_dflt;
  3907. dd->sendctrl &= ~SYM_MASK(SendCtrl, AvailUpdThld);
  3908. dd->sendctrl |= (dd->cspec->updthresh &
  3909. SYM_RMASK(SendCtrl, AvailUpdThld)) <<
  3910. SYM_LSB(SendCtrl, AvailUpdThld);
  3911. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  3912. sendctrl_7220_mod(dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
  3913. }
  3914. break;
  3915. case TXCHK_CHG_TYPE_USER:
  3916. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  3917. if (rcd && rcd->subctxt_cnt && ((rcd->piocnt
  3918. / rcd->subctxt_cnt) - 1) < dd->cspec->updthresh) {
  3919. dd->cspec->updthresh = (rcd->piocnt /
  3920. rcd->subctxt_cnt) - 1;
  3921. dd->sendctrl &= ~SYM_MASK(SendCtrl, AvailUpdThld);
  3922. dd->sendctrl |= (dd->cspec->updthresh &
  3923. SYM_RMASK(SendCtrl, AvailUpdThld))
  3924. << SYM_LSB(SendCtrl, AvailUpdThld);
  3925. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  3926. sendctrl_7220_mod(dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
  3927. } else
  3928. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  3929. break;
  3930. }
  3931. }
  3932. static void writescratch(struct qib_devdata *dd, u32 val)
  3933. {
  3934. qib_write_kreg(dd, kr_scratch, val);
  3935. }
  3936. #define VALID_TS_RD_REG_MASK 0xBF
  3937. /**
  3938. * qib_7220_tempsense_read - read register of temp sensor via TWSI
  3939. * @dd: the qlogic_ib device
  3940. * @regnum: register to read from
  3941. *
  3942. * returns reg contents (0..255) or < 0 for error
  3943. */
  3944. static int qib_7220_tempsense_rd(struct qib_devdata *dd, int regnum)
  3945. {
  3946. int ret;
  3947. u8 rdata;
  3948. if (regnum > 7) {
  3949. ret = -EINVAL;
  3950. goto bail;
  3951. }
  3952. /* return a bogus value for (the one) register we do not have */
  3953. if (!((1 << regnum) & VALID_TS_RD_REG_MASK)) {
  3954. ret = 0;
  3955. goto bail;
  3956. }
  3957. ret = mutex_lock_interruptible(&dd->eep_lock);
  3958. if (ret)
  3959. goto bail;
  3960. ret = qib_twsi_blk_rd(dd, QIB_TWSI_TEMP_DEV, regnum, &rdata, 1);
  3961. if (!ret)
  3962. ret = rdata;
  3963. mutex_unlock(&dd->eep_lock);
  3964. /*
  3965. * There are three possibilities here:
  3966. * ret is actual value (0..255)
  3967. * ret is -ENXIO or -EINVAL from twsi code or this file
  3968. * ret is -EINTR from mutex_lock_interruptible.
  3969. */
  3970. bail:
  3971. return ret;
  3972. }
  3973. #ifdef CONFIG_INFINIBAND_QIB_DCA
  3974. static int qib_7220_notify_dca(struct qib_devdata *dd, unsigned long event)
  3975. {
  3976. return 0;
  3977. }
  3978. #endif
  3979. /* Dummy function, as 7220 boards never disable EEPROM Write */
  3980. static int qib_7220_eeprom_wen(struct qib_devdata *dd, int wen)
  3981. {
  3982. return 1;
  3983. }
  3984. /**
  3985. * qib_init_iba7220_funcs - set up the chip-specific function pointers
  3986. * @dev: the pci_dev for qlogic_ib device
  3987. * @ent: pci_device_id struct for this dev
  3988. *
  3989. * This is global, and is called directly at init to set up the
  3990. * chip-specific function pointers for later use.
  3991. */
  3992. struct qib_devdata *qib_init_iba7220_funcs(struct pci_dev *pdev,
  3993. const struct pci_device_id *ent)
  3994. {
  3995. struct qib_devdata *dd;
  3996. int ret;
  3997. u32 boardid, minwidth;
  3998. dd = qib_alloc_devdata(pdev, sizeof(struct qib_chip_specific) +
  3999. sizeof(struct qib_chippport_specific));
  4000. if (IS_ERR(dd))
  4001. goto bail;
  4002. dd->f_bringup_serdes = qib_7220_bringup_serdes;
  4003. dd->f_cleanup = qib_setup_7220_cleanup;
  4004. dd->f_clear_tids = qib_7220_clear_tids;
  4005. dd->f_free_irq = qib_free_irq;
  4006. dd->f_get_base_info = qib_7220_get_base_info;
  4007. dd->f_get_msgheader = qib_7220_get_msgheader;
  4008. dd->f_getsendbuf = qib_7220_getsendbuf;
  4009. dd->f_gpio_mod = gpio_7220_mod;
  4010. dd->f_eeprom_wen = qib_7220_eeprom_wen;
  4011. dd->f_hdrqempty = qib_7220_hdrqempty;
  4012. dd->f_ib_updown = qib_7220_ib_updown;
  4013. dd->f_init_ctxt = qib_7220_init_ctxt;
  4014. dd->f_initvl15_bufs = qib_7220_initvl15_bufs;
  4015. dd->f_intr_fallback = qib_7220_intr_fallback;
  4016. dd->f_late_initreg = qib_late_7220_initreg;
  4017. dd->f_setpbc_control = qib_7220_setpbc_control;
  4018. dd->f_portcntr = qib_portcntr_7220;
  4019. dd->f_put_tid = qib_7220_put_tid;
  4020. dd->f_quiet_serdes = qib_7220_quiet_serdes;
  4021. dd->f_rcvctrl = rcvctrl_7220_mod;
  4022. dd->f_read_cntrs = qib_read_7220cntrs;
  4023. dd->f_read_portcntrs = qib_read_7220portcntrs;
  4024. dd->f_reset = qib_setup_7220_reset;
  4025. dd->f_init_sdma_regs = init_sdma_7220_regs;
  4026. dd->f_sdma_busy = qib_sdma_7220_busy;
  4027. dd->f_sdma_gethead = qib_sdma_7220_gethead;
  4028. dd->f_sdma_sendctrl = qib_7220_sdma_sendctrl;
  4029. dd->f_sdma_set_desc_cnt = qib_sdma_set_7220_desc_cnt;
  4030. dd->f_sdma_update_tail = qib_sdma_update_7220_tail;
  4031. dd->f_sdma_hw_clean_up = qib_7220_sdma_hw_clean_up;
  4032. dd->f_sdma_hw_start_up = qib_7220_sdma_hw_start_up;
  4033. dd->f_sdma_init_early = qib_7220_sdma_init_early;
  4034. dd->f_sendctrl = sendctrl_7220_mod;
  4035. dd->f_set_armlaunch = qib_set_7220_armlaunch;
  4036. dd->f_set_cntr_sample = qib_set_cntr_7220_sample;
  4037. dd->f_iblink_state = qib_7220_iblink_state;
  4038. dd->f_ibphys_portstate = qib_7220_phys_portstate;
  4039. dd->f_get_ib_cfg = qib_7220_get_ib_cfg;
  4040. dd->f_set_ib_cfg = qib_7220_set_ib_cfg;
  4041. dd->f_set_ib_loopback = qib_7220_set_loopback;
  4042. dd->f_set_intr_state = qib_7220_set_intr_state;
  4043. dd->f_setextled = qib_setup_7220_setextled;
  4044. dd->f_txchk_change = qib_7220_txchk_change;
  4045. dd->f_update_usrhead = qib_update_7220_usrhead;
  4046. dd->f_wantpiobuf_intr = qib_wantpiobuf_7220_intr;
  4047. dd->f_xgxs_reset = qib_7220_xgxs_reset;
  4048. dd->f_writescratch = writescratch;
  4049. dd->f_tempsense_rd = qib_7220_tempsense_rd;
  4050. #ifdef CONFIG_INFINIBAND_QIB_DCA
  4051. dd->f_notify_dca = qib_7220_notify_dca;
  4052. #endif
  4053. /*
  4054. * Do remaining pcie setup and save pcie values in dd.
  4055. * Any error printing is already done by the init code.
  4056. * On return, we have the chip mapped, but chip registers
  4057. * are not set up until start of qib_init_7220_variables.
  4058. */
  4059. ret = qib_pcie_ddinit(dd, pdev, ent);
  4060. if (ret < 0)
  4061. goto bail_free;
  4062. /* initialize chip-specific variables */
  4063. ret = qib_init_7220_variables(dd);
  4064. if (ret)
  4065. goto bail_cleanup;
  4066. if (qib_mini_init)
  4067. goto bail;
  4068. boardid = SYM_FIELD(dd->revision, Revision,
  4069. BoardID);
  4070. switch (boardid) {
  4071. case 0:
  4072. case 2:
  4073. case 10:
  4074. case 12:
  4075. minwidth = 16; /* x16 capable boards */
  4076. break;
  4077. default:
  4078. minwidth = 8; /* x8 capable boards */
  4079. break;
  4080. }
  4081. if (qib_pcie_params(dd, minwidth, NULL))
  4082. qib_dev_err(dd,
  4083. "Failed to setup PCIe or interrupts; continuing anyway\n");
  4084. if (qib_read_kreg64(dd, kr_hwerrstatus) &
  4085. QLOGIC_IB_HWE_SERDESPLLFAILED)
  4086. qib_write_kreg(dd, kr_hwerrclear,
  4087. QLOGIC_IB_HWE_SERDESPLLFAILED);
  4088. /* setup interrupt handler (interrupt type handled above) */
  4089. qib_setup_7220_interrupt(dd);
  4090. qib_7220_init_hwerrors(dd);
  4091. /* clear diagctrl register, in case diags were running and crashed */
  4092. qib_write_kreg(dd, kr_hwdiagctrl, 0);
  4093. goto bail;
  4094. bail_cleanup:
  4095. qib_pcie_ddcleanup(dd);
  4096. bail_free:
  4097. qib_free_devdata(dd);
  4098. dd = ERR_PTR(ret);
  4099. bail:
  4100. return dd;
  4101. }