qib_iba7220.c 143 KB

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