qib_iba7322.c 247 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992
  1. /*
  2. * Copyright (c) 2008, 2009, 2010 QLogic Corporation. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. /*
  33. * This file contains all of the code that is specific to the
  34. * InfiniPath 7322 chip
  35. */
  36. #include <linux/interrupt.h>
  37. #include <linux/pci.h>
  38. #include <linux/delay.h>
  39. #include <linux/io.h>
  40. #include <linux/jiffies.h>
  41. #include <rdma/ib_verbs.h>
  42. #include <rdma/ib_smi.h>
  43. #include "qib.h"
  44. #include "qib_7322_regs.h"
  45. #include "qib_qsfp.h"
  46. #include "qib_mad.h"
  47. static void qib_setup_7322_setextled(struct qib_pportdata *, u32);
  48. static void qib_7322_handle_hwerrors(struct qib_devdata *, char *, size_t);
  49. static void sendctrl_7322_mod(struct qib_pportdata *ppd, u32 op);
  50. static irqreturn_t qib_7322intr(int irq, void *data);
  51. static irqreturn_t qib_7322bufavail(int irq, void *data);
  52. static irqreturn_t sdma_intr(int irq, void *data);
  53. static irqreturn_t sdma_idle_intr(int irq, void *data);
  54. static irqreturn_t sdma_progress_intr(int irq, void *data);
  55. static irqreturn_t sdma_cleanup_intr(int irq, void *data);
  56. static void qib_7322_txchk_change(struct qib_devdata *, u32, u32, u32,
  57. struct qib_ctxtdata *rcd);
  58. static u8 qib_7322_phys_portstate(u64);
  59. static u32 qib_7322_iblink_state(u64);
  60. static void qib_set_ib_7322_lstate(struct qib_pportdata *ppd, u16 linkcmd,
  61. u16 linitcmd);
  62. static void force_h1(struct qib_pportdata *);
  63. static void adj_tx_serdes(struct qib_pportdata *);
  64. static u32 qib_7322_setpbc_control(struct qib_pportdata *, u32, u8, u8);
  65. static void qib_7322_mini_pcs_reset(struct qib_pportdata *);
  66. static u32 ahb_mod(struct qib_devdata *, int, int, int, u32, u32);
  67. static void ibsd_wr_allchans(struct qib_pportdata *, int, unsigned, unsigned);
  68. static void serdes_7322_los_enable(struct qib_pportdata *, int);
  69. static int serdes_7322_init_old(struct qib_pportdata *);
  70. static int serdes_7322_init_new(struct qib_pportdata *);
  71. #define BMASK(msb, lsb) (((1 << ((msb) + 1 - (lsb))) - 1) << (lsb))
  72. /* LE2 serdes values for different cases */
  73. #define LE2_DEFAULT 5
  74. #define LE2_5m 4
  75. #define LE2_QME 0
  76. /* Below is special-purpose, so only really works for the IB SerDes blocks. */
  77. #define IBSD(hw_pidx) (hw_pidx + 2)
  78. /* these are variables for documentation and experimentation purposes */
  79. static const unsigned rcv_int_timeout = 375;
  80. static const unsigned rcv_int_count = 16;
  81. static const unsigned sdma_idle_cnt = 64;
  82. /* Time to stop altering Rx Equalization parameters, after link up. */
  83. #define RXEQ_DISABLE_MSECS 2500
  84. /*
  85. * Number of VLs we are configured to use (to allow for more
  86. * credits per vl, etc.)
  87. */
  88. ushort qib_num_cfg_vls = 2;
  89. module_param_named(num_vls, qib_num_cfg_vls, ushort, S_IRUGO);
  90. MODULE_PARM_DESC(num_vls, "Set number of Virtual Lanes to use (1-8)");
  91. static ushort qib_chase = 1;
  92. module_param_named(chase, qib_chase, ushort, S_IRUGO);
  93. MODULE_PARM_DESC(chase, "Enable state chase handling");
  94. static ushort qib_long_atten = 10; /* 10 dB ~= 5m length */
  95. module_param_named(long_attenuation, qib_long_atten, ushort, S_IRUGO);
  96. MODULE_PARM_DESC(long_attenuation, \
  97. "attenuation cutoff (dB) for long copper cable setup");
  98. static ushort qib_singleport;
  99. module_param_named(singleport, qib_singleport, ushort, S_IRUGO);
  100. MODULE_PARM_DESC(singleport, "Use only IB port 1; more per-port buffer space");
  101. /*
  102. * Receive header queue sizes
  103. */
  104. static unsigned qib_rcvhdrcnt;
  105. module_param_named(rcvhdrcnt, qib_rcvhdrcnt, uint, S_IRUGO);
  106. MODULE_PARM_DESC(rcvhdrcnt, "receive header count");
  107. static unsigned qib_rcvhdrsize;
  108. module_param_named(rcvhdrsize, qib_rcvhdrsize, uint, S_IRUGO);
  109. MODULE_PARM_DESC(rcvhdrsize, "receive header size in 32-bit words");
  110. static unsigned qib_rcvhdrentsize;
  111. module_param_named(rcvhdrentsize, qib_rcvhdrentsize, uint, S_IRUGO);
  112. MODULE_PARM_DESC(rcvhdrentsize, "receive header entry size in 32-bit words");
  113. #define MAX_ATTEN_LEN 64 /* plenty for any real system */
  114. /* for read back, default index is ~5m copper cable */
  115. static char txselect_list[MAX_ATTEN_LEN] = "10";
  116. static struct kparam_string kp_txselect = {
  117. .string = txselect_list,
  118. .maxlen = MAX_ATTEN_LEN
  119. };
  120. static int setup_txselect(const char *, struct kernel_param *);
  121. module_param_call(txselect, setup_txselect, param_get_string,
  122. &kp_txselect, S_IWUSR | S_IRUGO);
  123. MODULE_PARM_DESC(txselect, \
  124. "Tx serdes indices (for no QSFP or invalid QSFP data)");
  125. #define BOARD_QME7342 5
  126. #define BOARD_QMH7342 6
  127. #define IS_QMH(dd) (SYM_FIELD((dd)->revision, Revision, BoardID) == \
  128. BOARD_QMH7342)
  129. #define IS_QME(dd) (SYM_FIELD((dd)->revision, Revision, BoardID) == \
  130. BOARD_QME7342)
  131. #define KREG_IDX(regname) (QIB_7322_##regname##_OFFS / sizeof(u64))
  132. #define KREG_IBPORT_IDX(regname) ((QIB_7322_##regname##_0_OFFS / sizeof(u64)))
  133. #define MASK_ACROSS(lsb, msb) \
  134. (((1ULL << ((msb) + 1 - (lsb))) - 1) << (lsb))
  135. #define SYM_RMASK(regname, fldname) ((u64) \
  136. QIB_7322_##regname##_##fldname##_RMASK)
  137. #define SYM_MASK(regname, fldname) ((u64) \
  138. QIB_7322_##regname##_##fldname##_RMASK << \
  139. QIB_7322_##regname##_##fldname##_LSB)
  140. #define SYM_FIELD(value, regname, fldname) ((u64) \
  141. (((value) >> SYM_LSB(regname, fldname)) & \
  142. SYM_RMASK(regname, fldname)))
  143. /* useful for things like LaFifoEmpty_0...7, TxCreditOK_0...7, etc. */
  144. #define SYM_FIELD_ACROSS(value, regname, fldname, nbits) \
  145. (((value) >> SYM_LSB(regname, fldname)) & MASK_ACROSS(0, nbits))
  146. #define HWE_MASK(fldname) SYM_MASK(HwErrMask, fldname##Mask)
  147. #define ERR_MASK(fldname) SYM_MASK(ErrMask, fldname##Mask)
  148. #define ERR_MASK_N(fldname) SYM_MASK(ErrMask_0, fldname##Mask)
  149. #define INT_MASK(fldname) SYM_MASK(IntMask, fldname##IntMask)
  150. #define INT_MASK_P(fldname, port) SYM_MASK(IntMask, fldname##IntMask##_##port)
  151. /* Below because most, but not all, fields of IntMask have that full suffix */
  152. #define INT_MASK_PM(fldname, port) SYM_MASK(IntMask, fldname##Mask##_##port)
  153. #define SYM_LSB(regname, fldname) (QIB_7322_##regname##_##fldname##_LSB)
  154. /*
  155. * the size bits give us 2^N, in KB units. 0 marks as invalid,
  156. * and 7 is reserved. We currently use only 2KB and 4KB
  157. */
  158. #define IBA7322_TID_SZ_SHIFT QIB_7322_RcvTIDArray0_RT_BufSize_LSB
  159. #define IBA7322_TID_SZ_2K (1UL<<IBA7322_TID_SZ_SHIFT) /* 2KB */
  160. #define IBA7322_TID_SZ_4K (2UL<<IBA7322_TID_SZ_SHIFT) /* 4KB */
  161. #define IBA7322_TID_PA_SHIFT 11U /* TID addr in chip stored w/o low bits */
  162. #define SendIBSLIDAssignMask \
  163. QIB_7322_SendIBSLIDAssign_0_SendIBSLIDAssign_15_0_RMASK
  164. #define SendIBSLMCMask \
  165. QIB_7322_SendIBSLIDMask_0_SendIBSLIDMask_15_0_RMASK
  166. #define ExtLED_IB1_YEL SYM_MASK(EXTCtrl, LEDPort0YellowOn)
  167. #define ExtLED_IB1_GRN SYM_MASK(EXTCtrl, LEDPort0GreenOn)
  168. #define ExtLED_IB2_YEL SYM_MASK(EXTCtrl, LEDPort1YellowOn)
  169. #define ExtLED_IB2_GRN SYM_MASK(EXTCtrl, LEDPort1GreenOn)
  170. #define ExtLED_IB1_MASK (ExtLED_IB1_YEL | ExtLED_IB1_GRN)
  171. #define ExtLED_IB2_MASK (ExtLED_IB2_YEL | ExtLED_IB2_GRN)
  172. #define _QIB_GPIO_SDA_NUM 1
  173. #define _QIB_GPIO_SCL_NUM 0
  174. #define QIB_EEPROM_WEN_NUM 14
  175. #define QIB_TWSI_EEPROM_DEV 0xA2 /* All Production 7322 cards. */
  176. /* HW counter clock is at 4nsec */
  177. #define QIB_7322_PSXMITWAIT_CHECK_RATE 4000
  178. /* full speed IB port 1 only */
  179. #define PORT_SPD_CAP (QIB_IB_SDR | QIB_IB_DDR | QIB_IB_QDR)
  180. #define PORT_SPD_CAP_SHIFT 3
  181. /* full speed featuremask, both ports */
  182. #define DUAL_PORT_CAP (PORT_SPD_CAP | (PORT_SPD_CAP << PORT_SPD_CAP_SHIFT))
  183. /*
  184. * This file contains almost all the chip-specific register information and
  185. * access functions for the FAKED QLogic InfiniPath 7322 PCI-Express chip.
  186. */
  187. /* Use defines to tie machine-generated names to lower-case names */
  188. #define kr_contextcnt KREG_IDX(ContextCnt)
  189. #define kr_control KREG_IDX(Control)
  190. #define kr_counterregbase KREG_IDX(CntrRegBase)
  191. #define kr_errclear KREG_IDX(ErrClear)
  192. #define kr_errmask KREG_IDX(ErrMask)
  193. #define kr_errstatus KREG_IDX(ErrStatus)
  194. #define kr_extctrl KREG_IDX(EXTCtrl)
  195. #define kr_extstatus KREG_IDX(EXTStatus)
  196. #define kr_gpio_clear KREG_IDX(GPIOClear)
  197. #define kr_gpio_mask KREG_IDX(GPIOMask)
  198. #define kr_gpio_out KREG_IDX(GPIOOut)
  199. #define kr_gpio_status KREG_IDX(GPIOStatus)
  200. #define kr_hwdiagctrl KREG_IDX(HwDiagCtrl)
  201. #define kr_debugportval KREG_IDX(DebugPortValueReg)
  202. #define kr_fmask KREG_IDX(feature_mask)
  203. #define kr_act_fmask KREG_IDX(active_feature_mask)
  204. #define kr_hwerrclear KREG_IDX(HwErrClear)
  205. #define kr_hwerrmask KREG_IDX(HwErrMask)
  206. #define kr_hwerrstatus KREG_IDX(HwErrStatus)
  207. #define kr_intclear KREG_IDX(IntClear)
  208. #define kr_intmask KREG_IDX(IntMask)
  209. #define kr_intredirect KREG_IDX(IntRedirect0)
  210. #define kr_intstatus KREG_IDX(IntStatus)
  211. #define kr_pagealign KREG_IDX(PageAlign)
  212. #define kr_rcvavailtimeout KREG_IDX(RcvAvailTimeOut0)
  213. #define kr_rcvctrl KREG_IDX(RcvCtrl) /* Common, but chip also has per-port */
  214. #define kr_rcvegrbase KREG_IDX(RcvEgrBase)
  215. #define kr_rcvegrcnt KREG_IDX(RcvEgrCnt)
  216. #define kr_rcvhdrcnt KREG_IDX(RcvHdrCnt)
  217. #define kr_rcvhdrentsize KREG_IDX(RcvHdrEntSize)
  218. #define kr_rcvhdrsize KREG_IDX(RcvHdrSize)
  219. #define kr_rcvtidbase KREG_IDX(RcvTIDBase)
  220. #define kr_rcvtidcnt KREG_IDX(RcvTIDCnt)
  221. #define kr_revision KREG_IDX(Revision)
  222. #define kr_scratch KREG_IDX(Scratch)
  223. #define kr_sendbuffererror KREG_IDX(SendBufErr0) /* and base for 1 and 2 */
  224. #define kr_sendcheckmask KREG_IDX(SendCheckMask0) /* and 1, 2 */
  225. #define kr_sendctrl KREG_IDX(SendCtrl)
  226. #define kr_sendgrhcheckmask KREG_IDX(SendGRHCheckMask0) /* and 1, 2 */
  227. #define kr_sendibpktmask KREG_IDX(SendIBPacketMask0) /* and 1, 2 */
  228. #define kr_sendpioavailaddr KREG_IDX(SendBufAvailAddr)
  229. #define kr_sendpiobufbase KREG_IDX(SendBufBase)
  230. #define kr_sendpiobufcnt KREG_IDX(SendBufCnt)
  231. #define kr_sendpiosize KREG_IDX(SendBufSize)
  232. #define kr_sendregbase KREG_IDX(SendRegBase)
  233. #define kr_sendbufavail0 KREG_IDX(SendBufAvail0)
  234. #define kr_userregbase KREG_IDX(UserRegBase)
  235. #define kr_intgranted KREG_IDX(Int_Granted)
  236. #define kr_vecclr_wo_int KREG_IDX(vec_clr_without_int)
  237. #define kr_intblocked KREG_IDX(IntBlocked)
  238. #define kr_r_access KREG_IDX(SPC_JTAG_ACCESS_REG)
  239. /*
  240. * per-port kernel registers. Access only with qib_read_kreg_port()
  241. * or qib_write_kreg_port()
  242. */
  243. #define krp_errclear KREG_IBPORT_IDX(ErrClear)
  244. #define krp_errmask KREG_IBPORT_IDX(ErrMask)
  245. #define krp_errstatus KREG_IBPORT_IDX(ErrStatus)
  246. #define krp_highprio_0 KREG_IBPORT_IDX(HighPriority0)
  247. #define krp_highprio_limit KREG_IBPORT_IDX(HighPriorityLimit)
  248. #define krp_hrtbt_guid KREG_IBPORT_IDX(HRTBT_GUID)
  249. #define krp_ib_pcsconfig KREG_IBPORT_IDX(IBPCSConfig)
  250. #define krp_ibcctrl_a KREG_IBPORT_IDX(IBCCtrlA)
  251. #define krp_ibcctrl_b KREG_IBPORT_IDX(IBCCtrlB)
  252. #define krp_ibcctrl_c KREG_IBPORT_IDX(IBCCtrlC)
  253. #define krp_ibcstatus_a KREG_IBPORT_IDX(IBCStatusA)
  254. #define krp_ibcstatus_b KREG_IBPORT_IDX(IBCStatusB)
  255. #define krp_txestatus KREG_IBPORT_IDX(TXEStatus)
  256. #define krp_lowprio_0 KREG_IBPORT_IDX(LowPriority0)
  257. #define krp_ncmodectrl KREG_IBPORT_IDX(IBNCModeCtrl)
  258. #define krp_partitionkey KREG_IBPORT_IDX(RcvPartitionKey)
  259. #define krp_psinterval KREG_IBPORT_IDX(PSInterval)
  260. #define krp_psstart KREG_IBPORT_IDX(PSStart)
  261. #define krp_psstat KREG_IBPORT_IDX(PSStat)
  262. #define krp_rcvbthqp KREG_IBPORT_IDX(RcvBTHQP)
  263. #define krp_rcvctrl KREG_IBPORT_IDX(RcvCtrl)
  264. #define krp_rcvpktledcnt KREG_IBPORT_IDX(RcvPktLEDCnt)
  265. #define krp_rcvqpmaptable KREG_IBPORT_IDX(RcvQPMapTableA)
  266. #define krp_rxcreditvl0 KREG_IBPORT_IDX(RxCreditVL0)
  267. #define krp_rxcreditvl15 (KREG_IBPORT_IDX(RxCreditVL0)+15)
  268. #define krp_sendcheckcontrol KREG_IBPORT_IDX(SendCheckControl)
  269. #define krp_sendctrl KREG_IBPORT_IDX(SendCtrl)
  270. #define krp_senddmabase KREG_IBPORT_IDX(SendDmaBase)
  271. #define krp_senddmabufmask0 KREG_IBPORT_IDX(SendDmaBufMask0)
  272. #define krp_senddmabufmask1 (KREG_IBPORT_IDX(SendDmaBufMask0) + 1)
  273. #define krp_senddmabufmask2 (KREG_IBPORT_IDX(SendDmaBufMask0) + 2)
  274. #define krp_senddmabuf_use0 KREG_IBPORT_IDX(SendDmaBufUsed0)
  275. #define krp_senddmabuf_use1 (KREG_IBPORT_IDX(SendDmaBufUsed0) + 1)
  276. #define krp_senddmabuf_use2 (KREG_IBPORT_IDX(SendDmaBufUsed0) + 2)
  277. #define krp_senddmadesccnt KREG_IBPORT_IDX(SendDmaDescCnt)
  278. #define krp_senddmahead KREG_IBPORT_IDX(SendDmaHead)
  279. #define krp_senddmaheadaddr KREG_IBPORT_IDX(SendDmaHeadAddr)
  280. #define krp_senddmaidlecnt KREG_IBPORT_IDX(SendDmaIdleCnt)
  281. #define krp_senddmalengen KREG_IBPORT_IDX(SendDmaLenGen)
  282. #define krp_senddmaprioritythld KREG_IBPORT_IDX(SendDmaPriorityThld)
  283. #define krp_senddmareloadcnt KREG_IBPORT_IDX(SendDmaReloadCnt)
  284. #define krp_senddmastatus KREG_IBPORT_IDX(SendDmaStatus)
  285. #define krp_senddmatail KREG_IBPORT_IDX(SendDmaTail)
  286. #define krp_sendhdrsymptom KREG_IBPORT_IDX(SendHdrErrSymptom)
  287. #define krp_sendslid KREG_IBPORT_IDX(SendIBSLIDAssign)
  288. #define krp_sendslidmask KREG_IBPORT_IDX(SendIBSLIDMask)
  289. #define krp_ibsdtestiftx KREG_IBPORT_IDX(IB_SDTEST_IF_TX)
  290. #define krp_adapt_dis_timer KREG_IBPORT_IDX(ADAPT_DISABLE_TIMER_THRESHOLD)
  291. #define krp_tx_deemph_override KREG_IBPORT_IDX(IBSD_TX_DEEMPHASIS_OVERRIDE)
  292. #define krp_serdesctrl KREG_IBPORT_IDX(IBSerdesCtrl)
  293. /*
  294. * Per-context kernel registers. Access only with qib_read_kreg_ctxt()
  295. * or qib_write_kreg_ctxt()
  296. */
  297. #define krc_rcvhdraddr KREG_IDX(RcvHdrAddr0)
  298. #define krc_rcvhdrtailaddr KREG_IDX(RcvHdrTailAddr0)
  299. /*
  300. * TID Flow table, per context. Reduces
  301. * number of hdrq updates to one per flow (or on errors).
  302. * context 0 and 1 share same memory, but have distinct
  303. * addresses. Since for now, we never use expected sends
  304. * on kernel contexts, we don't worry about that (we initialize
  305. * those entries for ctxt 0/1 on driver load twice, for example).
  306. */
  307. #define NUM_TIDFLOWS_CTXT 0x20 /* 0x20 per context; have to hardcode */
  308. #define ur_rcvflowtable (KREG_IDX(RcvTIDFlowTable0) - KREG_IDX(RcvHdrTail0))
  309. /* these are the error bits in the tid flows, and are W1C */
  310. #define TIDFLOW_ERRBITS ( \
  311. (SYM_MASK(RcvTIDFlowTable0, GenMismatch) << \
  312. SYM_LSB(RcvTIDFlowTable0, GenMismatch)) | \
  313. (SYM_MASK(RcvTIDFlowTable0, SeqMismatch) << \
  314. SYM_LSB(RcvTIDFlowTable0, SeqMismatch)))
  315. /* Most (not all) Counters are per-IBport.
  316. * Requires LBIntCnt is at offset 0 in the group
  317. */
  318. #define CREG_IDX(regname) \
  319. ((QIB_7322_##regname##_0_OFFS - QIB_7322_LBIntCnt_OFFS) / sizeof(u64))
  320. #define crp_badformat CREG_IDX(RxVersionErrCnt)
  321. #define crp_err_rlen CREG_IDX(RxLenErrCnt)
  322. #define crp_erricrc CREG_IDX(RxICRCErrCnt)
  323. #define crp_errlink CREG_IDX(RxLinkMalformCnt)
  324. #define crp_errlpcrc CREG_IDX(RxLPCRCErrCnt)
  325. #define crp_errpkey CREG_IDX(RxPKeyMismatchCnt)
  326. #define crp_errvcrc CREG_IDX(RxVCRCErrCnt)
  327. #define crp_excessbufferovfl CREG_IDX(ExcessBufferOvflCnt)
  328. #define crp_iblinkdown CREG_IDX(IBLinkDownedCnt)
  329. #define crp_iblinkerrrecov CREG_IDX(IBLinkErrRecoveryCnt)
  330. #define crp_ibstatuschange CREG_IDX(IBStatusChangeCnt)
  331. #define crp_ibsymbolerr CREG_IDX(IBSymbolErrCnt)
  332. #define crp_invalidrlen CREG_IDX(RxMaxMinLenErrCnt)
  333. #define crp_locallinkintegrityerr CREG_IDX(LocalLinkIntegrityErrCnt)
  334. #define crp_pktrcv CREG_IDX(RxDataPktCnt)
  335. #define crp_pktrcvflowctrl CREG_IDX(RxFlowPktCnt)
  336. #define crp_pktsend CREG_IDX(TxDataPktCnt)
  337. #define crp_pktsendflow CREG_IDX(TxFlowPktCnt)
  338. #define crp_psrcvdatacount CREG_IDX(PSRcvDataCount)
  339. #define crp_psrcvpktscount CREG_IDX(PSRcvPktsCount)
  340. #define crp_psxmitdatacount CREG_IDX(PSXmitDataCount)
  341. #define crp_psxmitpktscount CREG_IDX(PSXmitPktsCount)
  342. #define crp_psxmitwaitcount CREG_IDX(PSXmitWaitCount)
  343. #define crp_rcvebp CREG_IDX(RxEBPCnt)
  344. #define crp_rcvflowctrlviol CREG_IDX(RxFlowCtrlViolCnt)
  345. #define crp_rcvovfl CREG_IDX(RxBufOvflCnt)
  346. #define crp_rxdlidfltr CREG_IDX(RxDlidFltrCnt)
  347. #define crp_rxdroppkt CREG_IDX(RxDroppedPktCnt)
  348. #define crp_rxotherlocalphyerr CREG_IDX(RxOtherLocalPhyErrCnt)
  349. #define crp_rxqpinvalidctxt CREG_IDX(RxQPInvalidContextCnt)
  350. #define crp_rxvlerr CREG_IDX(RxVlErrCnt)
  351. #define crp_sendstall CREG_IDX(TxFlowStallCnt)
  352. #define crp_txdroppedpkt CREG_IDX(TxDroppedPktCnt)
  353. #define crp_txhdrerr CREG_IDX(TxHeadersErrCnt)
  354. #define crp_txlenerr CREG_IDX(TxLenErrCnt)
  355. #define crp_txlenerr CREG_IDX(TxLenErrCnt)
  356. #define crp_txminmaxlenerr CREG_IDX(TxMaxMinLenErrCnt)
  357. #define crp_txsdmadesc CREG_IDX(TxSDmaDescCnt)
  358. #define crp_txunderrun CREG_IDX(TxUnderrunCnt)
  359. #define crp_txunsupvl CREG_IDX(TxUnsupVLErrCnt)
  360. #define crp_vl15droppedpkt CREG_IDX(RxVL15DroppedPktCnt)
  361. #define crp_wordrcv CREG_IDX(RxDwordCnt)
  362. #define crp_wordsend CREG_IDX(TxDwordCnt)
  363. #define crp_tx_creditstalls CREG_IDX(TxCreditUpToDateTimeOut)
  364. /* these are the (few) counters that are not port-specific */
  365. #define CREG_DEVIDX(regname) ((QIB_7322_##regname##_OFFS - \
  366. QIB_7322_LBIntCnt_OFFS) / sizeof(u64))
  367. #define cr_base_egrovfl CREG_DEVIDX(RxP0HdrEgrOvflCnt)
  368. #define cr_lbint CREG_DEVIDX(LBIntCnt)
  369. #define cr_lbstall CREG_DEVIDX(LBFlowStallCnt)
  370. #define cr_pcieretrydiag CREG_DEVIDX(PcieRetryBufDiagQwordCnt)
  371. #define cr_rxtidflowdrop CREG_DEVIDX(RxTidFlowDropCnt)
  372. #define cr_tidfull CREG_DEVIDX(RxTIDFullErrCnt)
  373. #define cr_tidinvalid CREG_DEVIDX(RxTIDValidErrCnt)
  374. /* no chip register for # of IB ports supported, so define */
  375. #define NUM_IB_PORTS 2
  376. /* 1 VL15 buffer per hardware IB port, no register for this, so define */
  377. #define NUM_VL15_BUFS NUM_IB_PORTS
  378. /*
  379. * context 0 and 1 are special, and there is no chip register that
  380. * defines this value, so we have to define it here.
  381. * These are all allocated to either 0 or 1 for single port
  382. * hardware configuration, otherwise each gets half
  383. */
  384. #define KCTXT0_EGRCNT 2048
  385. /* values for vl and port fields in PBC, 7322-specific */
  386. #define PBC_PORT_SEL_LSB 26
  387. #define PBC_PORT_SEL_RMASK 1
  388. #define PBC_VL_NUM_LSB 27
  389. #define PBC_VL_NUM_RMASK 7
  390. #define PBC_7322_VL15_SEND (1ULL << 63) /* pbc; VL15, no credit check */
  391. #define PBC_7322_VL15_SEND_CTRL (1ULL << 31) /* control version of same */
  392. static u8 ib_rate_to_delay[IB_RATE_120_GBPS + 1] = {
  393. [IB_RATE_2_5_GBPS] = 16,
  394. [IB_RATE_5_GBPS] = 8,
  395. [IB_RATE_10_GBPS] = 4,
  396. [IB_RATE_20_GBPS] = 2,
  397. [IB_RATE_30_GBPS] = 2,
  398. [IB_RATE_40_GBPS] = 1
  399. };
  400. #define IBA7322_LINKSPEED_SHIFT SYM_LSB(IBCStatusA_0, LinkSpeedActive)
  401. #define IBA7322_LINKWIDTH_SHIFT SYM_LSB(IBCStatusA_0, LinkWidthActive)
  402. /* link training states, from IBC */
  403. #define IB_7322_LT_STATE_DISABLED 0x00
  404. #define IB_7322_LT_STATE_LINKUP 0x01
  405. #define IB_7322_LT_STATE_POLLACTIVE 0x02
  406. #define IB_7322_LT_STATE_POLLQUIET 0x03
  407. #define IB_7322_LT_STATE_SLEEPDELAY 0x04
  408. #define IB_7322_LT_STATE_SLEEPQUIET 0x05
  409. #define IB_7322_LT_STATE_CFGDEBOUNCE 0x08
  410. #define IB_7322_LT_STATE_CFGRCVFCFG 0x09
  411. #define IB_7322_LT_STATE_CFGWAITRMT 0x0a
  412. #define IB_7322_LT_STATE_CFGIDLE 0x0b
  413. #define IB_7322_LT_STATE_RECOVERRETRAIN 0x0c
  414. #define IB_7322_LT_STATE_TXREVLANES 0x0d
  415. #define IB_7322_LT_STATE_RECOVERWAITRMT 0x0e
  416. #define IB_7322_LT_STATE_RECOVERIDLE 0x0f
  417. #define IB_7322_LT_STATE_CFGENH 0x10
  418. #define IB_7322_LT_STATE_CFGTEST 0x11
  419. #define IB_7322_LT_STATE_CFGWAITRMTTEST 0x12
  420. #define IB_7322_LT_STATE_CFGWAITENH 0x13
  421. /* link state machine states from IBC */
  422. #define IB_7322_L_STATE_DOWN 0x0
  423. #define IB_7322_L_STATE_INIT 0x1
  424. #define IB_7322_L_STATE_ARM 0x2
  425. #define IB_7322_L_STATE_ACTIVE 0x3
  426. #define IB_7322_L_STATE_ACT_DEFER 0x4
  427. static const u8 qib_7322_physportstate[0x20] = {
  428. [IB_7322_LT_STATE_DISABLED] = IB_PHYSPORTSTATE_DISABLED,
  429. [IB_7322_LT_STATE_LINKUP] = IB_PHYSPORTSTATE_LINKUP,
  430. [IB_7322_LT_STATE_POLLACTIVE] = IB_PHYSPORTSTATE_POLL,
  431. [IB_7322_LT_STATE_POLLQUIET] = IB_PHYSPORTSTATE_POLL,
  432. [IB_7322_LT_STATE_SLEEPDELAY] = IB_PHYSPORTSTATE_SLEEP,
  433. [IB_7322_LT_STATE_SLEEPQUIET] = IB_PHYSPORTSTATE_SLEEP,
  434. [IB_7322_LT_STATE_CFGDEBOUNCE] = IB_PHYSPORTSTATE_CFG_TRAIN,
  435. [IB_7322_LT_STATE_CFGRCVFCFG] =
  436. IB_PHYSPORTSTATE_CFG_TRAIN,
  437. [IB_7322_LT_STATE_CFGWAITRMT] =
  438. IB_PHYSPORTSTATE_CFG_TRAIN,
  439. [IB_7322_LT_STATE_CFGIDLE] = IB_PHYSPORTSTATE_CFG_IDLE,
  440. [IB_7322_LT_STATE_RECOVERRETRAIN] =
  441. IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
  442. [IB_7322_LT_STATE_RECOVERWAITRMT] =
  443. IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
  444. [IB_7322_LT_STATE_RECOVERIDLE] =
  445. IB_PHYSPORTSTATE_LINK_ERR_RECOVER,
  446. [IB_7322_LT_STATE_CFGENH] = IB_PHYSPORTSTATE_CFG_ENH,
  447. [IB_7322_LT_STATE_CFGTEST] = IB_PHYSPORTSTATE_CFG_TRAIN,
  448. [IB_7322_LT_STATE_CFGWAITRMTTEST] =
  449. IB_PHYSPORTSTATE_CFG_TRAIN,
  450. [IB_7322_LT_STATE_CFGWAITENH] =
  451. IB_PHYSPORTSTATE_CFG_WAIT_ENH,
  452. [0x14] = IB_PHYSPORTSTATE_CFG_TRAIN,
  453. [0x15] = IB_PHYSPORTSTATE_CFG_TRAIN,
  454. [0x16] = IB_PHYSPORTSTATE_CFG_TRAIN,
  455. [0x17] = IB_PHYSPORTSTATE_CFG_TRAIN
  456. };
  457. struct qib_chip_specific {
  458. u64 __iomem *cregbase;
  459. u64 *cntrs;
  460. spinlock_t rcvmod_lock; /* protect rcvctrl shadow changes */
  461. spinlock_t gpio_lock; /* RMW of shadows/regs for ExtCtrl and GPIO */
  462. u64 main_int_mask; /* clear bits which have dedicated handlers */
  463. u64 int_enable_mask; /* for per port interrupts in single port mode */
  464. u64 errormask;
  465. u64 hwerrmask;
  466. u64 gpio_out; /* shadow of kr_gpio_out, for rmw ops */
  467. u64 gpio_mask; /* shadow the gpio mask register */
  468. u64 extctrl; /* shadow the gpio output enable, etc... */
  469. u32 ncntrs;
  470. u32 nportcntrs;
  471. u32 cntrnamelen;
  472. u32 portcntrnamelen;
  473. u32 numctxts;
  474. u32 rcvegrcnt;
  475. u32 updthresh; /* current AvailUpdThld */
  476. u32 updthresh_dflt; /* default AvailUpdThld */
  477. u32 r1;
  478. int irq;
  479. u32 num_msix_entries;
  480. u32 sdmabufcnt;
  481. u32 lastbuf_for_pio;
  482. u32 stay_in_freeze;
  483. u32 recovery_ports_initted;
  484. struct msix_entry *msix_entries;
  485. void **msix_arg;
  486. unsigned long *sendchkenable;
  487. unsigned long *sendgrhchk;
  488. unsigned long *sendibchk;
  489. u32 rcvavail_timeout[18];
  490. char emsgbuf[128]; /* for device error interrupt msg buffer */
  491. };
  492. /* Table of entries in "human readable" form Tx Emphasis. */
  493. struct txdds_ent {
  494. u8 amp;
  495. u8 pre;
  496. u8 main;
  497. u8 post;
  498. };
  499. struct vendor_txdds_ent {
  500. u8 oui[QSFP_VOUI_LEN];
  501. u8 *partnum;
  502. struct txdds_ent sdr;
  503. struct txdds_ent ddr;
  504. struct txdds_ent qdr;
  505. };
  506. static void write_tx_serdes_param(struct qib_pportdata *, struct txdds_ent *);
  507. #define TXDDS_TABLE_SZ 16 /* number of entries per speed in onchip table */
  508. #define TXDDS_EXTRA_SZ 13 /* number of extra tx settings entries */
  509. #define TXDDS_MFG_SZ 2 /* number of mfg tx settings entries */
  510. #define SERDES_CHANS 4 /* yes, it's obvious, but one less magic number */
  511. #define H1_FORCE_VAL 8
  512. #define H1_FORCE_QME 1 /* may be overridden via setup_txselect() */
  513. #define H1_FORCE_QMH 7 /* may be overridden via setup_txselect() */
  514. /* The static and dynamic registers are paired, and the pairs indexed by spd */
  515. #define krp_static_adapt_dis(spd) (KREG_IBPORT_IDX(ADAPT_DISABLE_STATIC_SDR) \
  516. + ((spd) * 2))
  517. #define QDR_DFE_DISABLE_DELAY 4000 /* msec after LINKUP */
  518. #define QDR_STATIC_ADAPT_DOWN 0xf0f0f0f0ULL /* link down, H1-H4 QDR adapts */
  519. #define QDR_STATIC_ADAPT_DOWN_R1 0ULL /* r1 link down, H1-H4 QDR adapts */
  520. #define QDR_STATIC_ADAPT_INIT 0xffffffffffULL /* up, disable H0,H1-8, LE */
  521. #define QDR_STATIC_ADAPT_INIT_R1 0xf0ffffffffULL /* r1 up, disable H0,H1-8 */
  522. struct qib_chippport_specific {
  523. u64 __iomem *kpregbase;
  524. u64 __iomem *cpregbase;
  525. u64 *portcntrs;
  526. struct qib_pportdata *ppd;
  527. wait_queue_head_t autoneg_wait;
  528. struct delayed_work autoneg_work;
  529. struct delayed_work ipg_work;
  530. struct timer_list chase_timer;
  531. /*
  532. * these 5 fields are used to establish deltas for IB symbol
  533. * errors and linkrecovery errors. They can be reported on
  534. * some chips during link negotiation prior to INIT, and with
  535. * DDR when faking DDR negotiations with non-IBTA switches.
  536. * The chip counters are adjusted at driver unload if there is
  537. * a non-zero delta.
  538. */
  539. u64 ibdeltainprog;
  540. u64 ibsymdelta;
  541. u64 ibsymsnap;
  542. u64 iblnkerrdelta;
  543. u64 iblnkerrsnap;
  544. u64 iblnkdownsnap;
  545. u64 iblnkdowndelta;
  546. u64 ibmalfdelta;
  547. u64 ibmalfsnap;
  548. u64 ibcctrl_a; /* krp_ibcctrl_a shadow */
  549. u64 ibcctrl_b; /* krp_ibcctrl_b shadow */
  550. u64 qdr_dfe_time;
  551. u64 chase_end;
  552. u32 autoneg_tries;
  553. u32 recovery_init;
  554. u32 qdr_dfe_on;
  555. u32 qdr_reforce;
  556. /*
  557. * Per-bay per-channel rcv QMH H1 values and Tx values for QDR.
  558. * entry zero is unused, to simplify indexing
  559. */
  560. u8 h1_val;
  561. u8 no_eep; /* txselect table index to use if no qsfp info */
  562. u8 ipg_tries;
  563. u8 ibmalfusesnap;
  564. struct qib_qsfp_data qsfp_data;
  565. char epmsgbuf[192]; /* for port error interrupt msg buffer */
  566. };
  567. static struct {
  568. const char *name;
  569. irq_handler_t handler;
  570. int lsb;
  571. int port; /* 0 if not port-specific, else port # */
  572. } irq_table[] = {
  573. { QIB_DRV_NAME, qib_7322intr, -1, 0 },
  574. { QIB_DRV_NAME " (buf avail)", qib_7322bufavail,
  575. SYM_LSB(IntStatus, SendBufAvail), 0 },
  576. { QIB_DRV_NAME " (sdma 0)", sdma_intr,
  577. SYM_LSB(IntStatus, SDmaInt_0), 1 },
  578. { QIB_DRV_NAME " (sdma 1)", sdma_intr,
  579. SYM_LSB(IntStatus, SDmaInt_1), 2 },
  580. { QIB_DRV_NAME " (sdmaI 0)", sdma_idle_intr,
  581. SYM_LSB(IntStatus, SDmaIdleInt_0), 1 },
  582. { QIB_DRV_NAME " (sdmaI 1)", sdma_idle_intr,
  583. SYM_LSB(IntStatus, SDmaIdleInt_1), 2 },
  584. { QIB_DRV_NAME " (sdmaP 0)", sdma_progress_intr,
  585. SYM_LSB(IntStatus, SDmaProgressInt_0), 1 },
  586. { QIB_DRV_NAME " (sdmaP 1)", sdma_progress_intr,
  587. SYM_LSB(IntStatus, SDmaProgressInt_1), 2 },
  588. { QIB_DRV_NAME " (sdmaC 0)", sdma_cleanup_intr,
  589. SYM_LSB(IntStatus, SDmaCleanupDone_0), 1 },
  590. { QIB_DRV_NAME " (sdmaC 1)", sdma_cleanup_intr,
  591. SYM_LSB(IntStatus, SDmaCleanupDone_1), 2 },
  592. };
  593. /* ibcctrl bits */
  594. #define QLOGIC_IB_IBCC_LINKINITCMD_DISABLE 1
  595. /* cycle through TS1/TS2 till OK */
  596. #define QLOGIC_IB_IBCC_LINKINITCMD_POLL 2
  597. /* wait for TS1, then go on */
  598. #define QLOGIC_IB_IBCC_LINKINITCMD_SLEEP 3
  599. #define QLOGIC_IB_IBCC_LINKINITCMD_SHIFT 16
  600. #define QLOGIC_IB_IBCC_LINKCMD_DOWN 1 /* move to 0x11 */
  601. #define QLOGIC_IB_IBCC_LINKCMD_ARMED 2 /* move to 0x21 */
  602. #define QLOGIC_IB_IBCC_LINKCMD_ACTIVE 3 /* move to 0x31 */
  603. #define BLOB_7322_IBCHG 0x101
  604. static inline void qib_write_kreg(const struct qib_devdata *dd,
  605. const u32 regno, u64 value);
  606. static inline u32 qib_read_kreg32(const struct qib_devdata *, const u32);
  607. static void write_7322_initregs(struct qib_devdata *);
  608. static void write_7322_init_portregs(struct qib_pportdata *);
  609. static void setup_7322_link_recovery(struct qib_pportdata *, u32);
  610. static void check_7322_rxe_status(struct qib_pportdata *);
  611. static u32 __iomem *qib_7322_getsendbuf(struct qib_pportdata *, u64, u32 *);
  612. /**
  613. * qib_read_ureg32 - read 32-bit virtualized per-context register
  614. * @dd: device
  615. * @regno: register number
  616. * @ctxt: context number
  617. *
  618. * Return the contents of a register that is virtualized to be per context.
  619. * Returns -1 on errors (not distinguishable from valid contents at
  620. * runtime; we may add a separate error variable at some point).
  621. */
  622. static inline u32 qib_read_ureg32(const struct qib_devdata *dd,
  623. enum qib_ureg regno, int ctxt)
  624. {
  625. if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
  626. return 0;
  627. return readl(regno + (u64 __iomem *)(
  628. (dd->ureg_align * ctxt) + (dd->userbase ?
  629. (char __iomem *)dd->userbase :
  630. (char __iomem *)dd->kregbase + dd->uregbase)));
  631. }
  632. /**
  633. * qib_read_ureg - read virtualized per-context register
  634. * @dd: device
  635. * @regno: register number
  636. * @ctxt: context number
  637. *
  638. * Return the contents of a register that is virtualized to be per context.
  639. * Returns -1 on errors (not distinguishable from valid contents at
  640. * runtime; we may add a separate error variable at some point).
  641. */
  642. static inline u64 qib_read_ureg(const struct qib_devdata *dd,
  643. enum qib_ureg regno, int ctxt)
  644. {
  645. if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
  646. return 0;
  647. return readq(regno + (u64 __iomem *)(
  648. (dd->ureg_align * ctxt) + (dd->userbase ?
  649. (char __iomem *)dd->userbase :
  650. (char __iomem *)dd->kregbase + dd->uregbase)));
  651. }
  652. /**
  653. * qib_write_ureg - write virtualized per-context register
  654. * @dd: device
  655. * @regno: register number
  656. * @value: value
  657. * @ctxt: context
  658. *
  659. * Write the contents of a register that is virtualized to be per context.
  660. */
  661. static inline void qib_write_ureg(const struct qib_devdata *dd,
  662. enum qib_ureg regno, u64 value, int ctxt)
  663. {
  664. u64 __iomem *ubase;
  665. if (dd->userbase)
  666. ubase = (u64 __iomem *)
  667. ((char __iomem *) dd->userbase +
  668. dd->ureg_align * ctxt);
  669. else
  670. ubase = (u64 __iomem *)
  671. (dd->uregbase +
  672. (char __iomem *) dd->kregbase +
  673. dd->ureg_align * ctxt);
  674. if (dd->kregbase && (dd->flags & QIB_PRESENT))
  675. writeq(value, &ubase[regno]);
  676. }
  677. static inline u32 qib_read_kreg32(const struct qib_devdata *dd,
  678. const u32 regno)
  679. {
  680. if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
  681. return -1;
  682. return readl((u32 __iomem *) &dd->kregbase[regno]);
  683. }
  684. static inline u64 qib_read_kreg64(const struct qib_devdata *dd,
  685. const u32 regno)
  686. {
  687. if (!dd->kregbase || !(dd->flags & QIB_PRESENT))
  688. return -1;
  689. return readq(&dd->kregbase[regno]);
  690. }
  691. static inline void qib_write_kreg(const struct qib_devdata *dd,
  692. const u32 regno, u64 value)
  693. {
  694. if (dd->kregbase && (dd->flags & QIB_PRESENT))
  695. writeq(value, &dd->kregbase[regno]);
  696. }
  697. /*
  698. * not many sanity checks for the port-specific kernel register routines,
  699. * since they are only used when it's known to be safe.
  700. */
  701. static inline u64 qib_read_kreg_port(const struct qib_pportdata *ppd,
  702. const u16 regno)
  703. {
  704. if (!ppd->cpspec->kpregbase || !(ppd->dd->flags & QIB_PRESENT))
  705. return 0ULL;
  706. return readq(&ppd->cpspec->kpregbase[regno]);
  707. }
  708. static inline void qib_write_kreg_port(const struct qib_pportdata *ppd,
  709. const u16 regno, u64 value)
  710. {
  711. if (ppd->cpspec && ppd->dd && ppd->cpspec->kpregbase &&
  712. (ppd->dd->flags & QIB_PRESENT))
  713. writeq(value, &ppd->cpspec->kpregbase[regno]);
  714. }
  715. /**
  716. * qib_write_kreg_ctxt - write a device's per-ctxt 64-bit kernel register
  717. * @dd: the qlogic_ib device
  718. * @regno: the register number to write
  719. * @ctxt: the context containing the register
  720. * @value: the value to write
  721. */
  722. static inline void qib_write_kreg_ctxt(const struct qib_devdata *dd,
  723. const u16 regno, unsigned ctxt,
  724. u64 value)
  725. {
  726. qib_write_kreg(dd, regno + ctxt, value);
  727. }
  728. static inline u64 read_7322_creg(const struct qib_devdata *dd, u16 regno)
  729. {
  730. if (!dd->cspec->cregbase || !(dd->flags & QIB_PRESENT))
  731. return 0;
  732. return readq(&dd->cspec->cregbase[regno]);
  733. }
  734. static inline u32 read_7322_creg32(const struct qib_devdata *dd, u16 regno)
  735. {
  736. if (!dd->cspec->cregbase || !(dd->flags & QIB_PRESENT))
  737. return 0;
  738. return readl(&dd->cspec->cregbase[regno]);
  739. }
  740. static inline void write_7322_creg_port(const struct qib_pportdata *ppd,
  741. u16 regno, u64 value)
  742. {
  743. if (ppd->cpspec && ppd->cpspec->cpregbase &&
  744. (ppd->dd->flags & QIB_PRESENT))
  745. writeq(value, &ppd->cpspec->cpregbase[regno]);
  746. }
  747. static inline u64 read_7322_creg_port(const struct qib_pportdata *ppd,
  748. u16 regno)
  749. {
  750. if (!ppd->cpspec || !ppd->cpspec->cpregbase ||
  751. !(ppd->dd->flags & QIB_PRESENT))
  752. return 0;
  753. return readq(&ppd->cpspec->cpregbase[regno]);
  754. }
  755. static inline u32 read_7322_creg32_port(const struct qib_pportdata *ppd,
  756. u16 regno)
  757. {
  758. if (!ppd->cpspec || !ppd->cpspec->cpregbase ||
  759. !(ppd->dd->flags & QIB_PRESENT))
  760. return 0;
  761. return readl(&ppd->cpspec->cpregbase[regno]);
  762. }
  763. /* bits in Control register */
  764. #define QLOGIC_IB_C_RESET SYM_MASK(Control, SyncReset)
  765. #define QLOGIC_IB_C_SDMAFETCHPRIOEN SYM_MASK(Control, SDmaDescFetchPriorityEn)
  766. /* bits in general interrupt regs */
  767. #define QIB_I_RCVURG_LSB SYM_LSB(IntMask, RcvUrg0IntMask)
  768. #define QIB_I_RCVURG_RMASK MASK_ACROSS(0, 17)
  769. #define QIB_I_RCVURG_MASK (QIB_I_RCVURG_RMASK << QIB_I_RCVURG_LSB)
  770. #define QIB_I_RCVAVAIL_LSB SYM_LSB(IntMask, RcvAvail0IntMask)
  771. #define QIB_I_RCVAVAIL_RMASK MASK_ACROSS(0, 17)
  772. #define QIB_I_RCVAVAIL_MASK (QIB_I_RCVAVAIL_RMASK << QIB_I_RCVAVAIL_LSB)
  773. #define QIB_I_C_ERROR INT_MASK(Err)
  774. #define QIB_I_SPIOSENT (INT_MASK_P(SendDone, 0) | INT_MASK_P(SendDone, 1))
  775. #define QIB_I_SPIOBUFAVAIL INT_MASK(SendBufAvail)
  776. #define QIB_I_GPIO INT_MASK(AssertGPIO)
  777. #define QIB_I_P_SDMAINT(pidx) \
  778. (INT_MASK_P(SDma, pidx) | INT_MASK_P(SDmaIdle, pidx) | \
  779. INT_MASK_P(SDmaProgress, pidx) | \
  780. INT_MASK_PM(SDmaCleanupDone, pidx))
  781. /* Interrupt bits that are "per port" */
  782. #define QIB_I_P_BITSEXTANT(pidx) \
  783. (INT_MASK_P(Err, pidx) | INT_MASK_P(SendDone, pidx) | \
  784. INT_MASK_P(SDma, pidx) | INT_MASK_P(SDmaIdle, pidx) | \
  785. INT_MASK_P(SDmaProgress, pidx) | \
  786. INT_MASK_PM(SDmaCleanupDone, pidx))
  787. /* Interrupt bits that are common to a device */
  788. /* currently unused: QIB_I_SPIOSENT */
  789. #define QIB_I_C_BITSEXTANT \
  790. (QIB_I_RCVURG_MASK | QIB_I_RCVAVAIL_MASK | \
  791. QIB_I_SPIOSENT | \
  792. QIB_I_C_ERROR | QIB_I_SPIOBUFAVAIL | QIB_I_GPIO)
  793. #define QIB_I_BITSEXTANT (QIB_I_C_BITSEXTANT | \
  794. QIB_I_P_BITSEXTANT(0) | QIB_I_P_BITSEXTANT(1))
  795. /*
  796. * Error bits that are "per port".
  797. */
  798. #define QIB_E_P_IBSTATUSCHANGED ERR_MASK_N(IBStatusChanged)
  799. #define QIB_E_P_SHDR ERR_MASK_N(SHeadersErr)
  800. #define QIB_E_P_VL15_BUF_MISUSE ERR_MASK_N(VL15BufMisuseErr)
  801. #define QIB_E_P_SND_BUF_MISUSE ERR_MASK_N(SendBufMisuseErr)
  802. #define QIB_E_P_SUNSUPVL ERR_MASK_N(SendUnsupportedVLErr)
  803. #define QIB_E_P_SUNEXP_PKTNUM ERR_MASK_N(SendUnexpectedPktNumErr)
  804. #define QIB_E_P_SDROP_DATA ERR_MASK_N(SendDroppedDataPktErr)
  805. #define QIB_E_P_SDROP_SMP ERR_MASK_N(SendDroppedSmpPktErr)
  806. #define QIB_E_P_SPKTLEN ERR_MASK_N(SendPktLenErr)
  807. #define QIB_E_P_SUNDERRUN ERR_MASK_N(SendUnderRunErr)
  808. #define QIB_E_P_SMAXPKTLEN ERR_MASK_N(SendMaxPktLenErr)
  809. #define QIB_E_P_SMINPKTLEN ERR_MASK_N(SendMinPktLenErr)
  810. #define QIB_E_P_RIBLOSTLINK ERR_MASK_N(RcvIBLostLinkErr)
  811. #define QIB_E_P_RHDR ERR_MASK_N(RcvHdrErr)
  812. #define QIB_E_P_RHDRLEN ERR_MASK_N(RcvHdrLenErr)
  813. #define QIB_E_P_RBADTID ERR_MASK_N(RcvBadTidErr)
  814. #define QIB_E_P_RBADVERSION ERR_MASK_N(RcvBadVersionErr)
  815. #define QIB_E_P_RIBFLOW ERR_MASK_N(RcvIBFlowErr)
  816. #define QIB_E_P_REBP ERR_MASK_N(RcvEBPErr)
  817. #define QIB_E_P_RUNSUPVL ERR_MASK_N(RcvUnsupportedVLErr)
  818. #define QIB_E_P_RUNEXPCHAR ERR_MASK_N(RcvUnexpectedCharErr)
  819. #define QIB_E_P_RSHORTPKTLEN ERR_MASK_N(RcvShortPktLenErr)
  820. #define QIB_E_P_RLONGPKTLEN ERR_MASK_N(RcvLongPktLenErr)
  821. #define QIB_E_P_RMAXPKTLEN ERR_MASK_N(RcvMaxPktLenErr)
  822. #define QIB_E_P_RMINPKTLEN ERR_MASK_N(RcvMinPktLenErr)
  823. #define QIB_E_P_RICRC ERR_MASK_N(RcvICRCErr)
  824. #define QIB_E_P_RVCRC ERR_MASK_N(RcvVCRCErr)
  825. #define QIB_E_P_RFORMATERR ERR_MASK_N(RcvFormatErr)
  826. #define QIB_E_P_SDMA1STDESC ERR_MASK_N(SDma1stDescErr)
  827. #define QIB_E_P_SDMABASE ERR_MASK_N(SDmaBaseErr)
  828. #define QIB_E_P_SDMADESCADDRMISALIGN ERR_MASK_N(SDmaDescAddrMisalignErr)
  829. #define QIB_E_P_SDMADWEN ERR_MASK_N(SDmaDwEnErr)
  830. #define QIB_E_P_SDMAGENMISMATCH ERR_MASK_N(SDmaGenMismatchErr)
  831. #define QIB_E_P_SDMAHALT ERR_MASK_N(SDmaHaltErr)
  832. #define QIB_E_P_SDMAMISSINGDW ERR_MASK_N(SDmaMissingDwErr)
  833. #define QIB_E_P_SDMAOUTOFBOUND ERR_MASK_N(SDmaOutOfBoundErr)
  834. #define QIB_E_P_SDMARPYTAG ERR_MASK_N(SDmaRpyTagErr)
  835. #define QIB_E_P_SDMATAILOUTOFBOUND ERR_MASK_N(SDmaTailOutOfBoundErr)
  836. #define QIB_E_P_SDMAUNEXPDATA ERR_MASK_N(SDmaUnexpDataErr)
  837. /* Error bits that are common to a device */
  838. #define QIB_E_RESET ERR_MASK(ResetNegated)
  839. #define QIB_E_HARDWARE ERR_MASK(HardwareErr)
  840. #define QIB_E_INVALIDADDR ERR_MASK(InvalidAddrErr)
  841. /*
  842. * Per chip (rather than per-port) errors. Most either do
  843. * nothing but trigger a print (because they self-recover, or
  844. * always occur in tandem with other errors that handle the
  845. * issue), or because they indicate errors with no recovery,
  846. * but we want to know that they happened.
  847. */
  848. #define QIB_E_SBUF_VL15_MISUSE ERR_MASK(SBufVL15MisUseErr)
  849. #define QIB_E_BADEEP ERR_MASK(InvalidEEPCmd)
  850. #define QIB_E_VLMISMATCH ERR_MASK(SendVLMismatchErr)
  851. #define QIB_E_ARMLAUNCH ERR_MASK(SendArmLaunchErr)
  852. #define QIB_E_SPCLTRIG ERR_MASK(SendSpecialTriggerErr)
  853. #define QIB_E_RRCVHDRFULL ERR_MASK(RcvHdrFullErr)
  854. #define QIB_E_RRCVEGRFULL ERR_MASK(RcvEgrFullErr)
  855. #define QIB_E_RCVCTXTSHARE ERR_MASK(RcvContextShareErr)
  856. /* SDMA chip errors (not per port)
  857. * QIB_E_SDMA_BUF_DUP needs no special handling, because we will also get
  858. * the SDMAHALT error immediately, so we just print the dup error via the
  859. * E_AUTO mechanism. This is true of most of the per-port fatal errors
  860. * as well, but since this is port-independent, by definition, it's
  861. * handled a bit differently. SDMA_VL15 and SDMA_WRONG_PORT are per
  862. * packet send errors, and so are handled in the same manner as other
  863. * per-packet errors.
  864. */
  865. #define QIB_E_SDMA_VL15 ERR_MASK(SDmaVL15Err)
  866. #define QIB_E_SDMA_WRONG_PORT ERR_MASK(SDmaWrongPortErr)
  867. #define QIB_E_SDMA_BUF_DUP ERR_MASK(SDmaBufMaskDuplicateErr)
  868. /*
  869. * Below functionally equivalent to legacy QLOGIC_IB_E_PKTERRS
  870. * it is used to print "common" packet errors.
  871. */
  872. #define QIB_E_P_PKTERRS (QIB_E_P_SPKTLEN |\
  873. QIB_E_P_SDROP_DATA | QIB_E_P_RVCRC |\
  874. QIB_E_P_RICRC | QIB_E_P_RSHORTPKTLEN |\
  875. QIB_E_P_VL15_BUF_MISUSE | QIB_E_P_SHDR | \
  876. QIB_E_P_REBP)
  877. /* Error Bits that Packet-related (Receive, per-port) */
  878. #define QIB_E_P_RPKTERRS (\
  879. QIB_E_P_RHDRLEN | QIB_E_P_RBADTID | \
  880. QIB_E_P_RBADVERSION | QIB_E_P_RHDR | \
  881. QIB_E_P_RLONGPKTLEN | QIB_E_P_RSHORTPKTLEN |\
  882. QIB_E_P_RMAXPKTLEN | QIB_E_P_RMINPKTLEN | \
  883. QIB_E_P_RFORMATERR | QIB_E_P_RUNSUPVL | \
  884. QIB_E_P_RUNEXPCHAR | QIB_E_P_RIBFLOW | QIB_E_P_REBP)
  885. /*
  886. * Error bits that are Send-related (per port)
  887. * (ARMLAUNCH excluded from E_SPKTERRS because it gets special handling).
  888. * All of these potentially need to have a buffer disarmed
  889. */
  890. #define QIB_E_P_SPKTERRS (\
  891. QIB_E_P_SUNEXP_PKTNUM |\
  892. QIB_E_P_SDROP_DATA | QIB_E_P_SDROP_SMP |\
  893. QIB_E_P_SMAXPKTLEN |\
  894. QIB_E_P_VL15_BUF_MISUSE | QIB_E_P_SHDR | \
  895. QIB_E_P_SMINPKTLEN | QIB_E_P_SPKTLEN | \
  896. QIB_E_P_SND_BUF_MISUSE | QIB_E_P_SUNSUPVL)
  897. #define QIB_E_SPKTERRS ( \
  898. QIB_E_SBUF_VL15_MISUSE | QIB_E_VLMISMATCH | \
  899. ERR_MASK_N(SendUnsupportedVLErr) | \
  900. QIB_E_SPCLTRIG | QIB_E_SDMA_VL15 | QIB_E_SDMA_WRONG_PORT)
  901. #define QIB_E_P_SDMAERRS ( \
  902. QIB_E_P_SDMAHALT | \
  903. QIB_E_P_SDMADESCADDRMISALIGN | \
  904. QIB_E_P_SDMAUNEXPDATA | \
  905. QIB_E_P_SDMAMISSINGDW | \
  906. QIB_E_P_SDMADWEN | \
  907. QIB_E_P_SDMARPYTAG | \
  908. QIB_E_P_SDMA1STDESC | \
  909. QIB_E_P_SDMABASE | \
  910. QIB_E_P_SDMATAILOUTOFBOUND | \
  911. QIB_E_P_SDMAOUTOFBOUND | \
  912. QIB_E_P_SDMAGENMISMATCH)
  913. /*
  914. * This sets some bits more than once, but makes it more obvious which
  915. * bits are not handled under other categories, and the repeat definition
  916. * is not a problem.
  917. */
  918. #define QIB_E_P_BITSEXTANT ( \
  919. QIB_E_P_SPKTERRS | QIB_E_P_PKTERRS | QIB_E_P_RPKTERRS | \
  920. QIB_E_P_RIBLOSTLINK | QIB_E_P_IBSTATUSCHANGED | \
  921. QIB_E_P_SND_BUF_MISUSE | QIB_E_P_SUNDERRUN | \
  922. QIB_E_P_SHDR | QIB_E_P_VL15_BUF_MISUSE | QIB_E_P_SDMAERRS \
  923. )
  924. /*
  925. * These are errors that can occur when the link
  926. * changes state while a packet is being sent or received. This doesn't
  927. * cover things like EBP or VCRC that can be the result of a sending
  928. * having the link change state, so we receive a "known bad" packet.
  929. * All of these are "per port", so renamed:
  930. */
  931. #define QIB_E_P_LINK_PKTERRS (\
  932. QIB_E_P_SDROP_DATA | QIB_E_P_SDROP_SMP |\
  933. QIB_E_P_SMINPKTLEN | QIB_E_P_SPKTLEN |\
  934. QIB_E_P_RSHORTPKTLEN | QIB_E_P_RMINPKTLEN |\
  935. QIB_E_P_RUNEXPCHAR)
  936. /*
  937. * This sets some bits more than once, but makes it more obvious which
  938. * bits are not handled under other categories (such as QIB_E_SPKTERRS),
  939. * and the repeat definition is not a problem.
  940. */
  941. #define QIB_E_C_BITSEXTANT (\
  942. QIB_E_HARDWARE | QIB_E_INVALIDADDR | QIB_E_BADEEP |\
  943. QIB_E_ARMLAUNCH | QIB_E_VLMISMATCH | QIB_E_RRCVHDRFULL |\
  944. QIB_E_RRCVEGRFULL | QIB_E_RESET | QIB_E_SBUF_VL15_MISUSE)
  945. /* Likewise Neuter E_SPKT_ERRS_IGNORE */
  946. #define E_SPKT_ERRS_IGNORE 0
  947. #define QIB_EXTS_MEMBIST_DISABLED \
  948. SYM_MASK(EXTStatus, MemBISTDisabled)
  949. #define QIB_EXTS_MEMBIST_ENDTEST \
  950. SYM_MASK(EXTStatus, MemBISTEndTest)
  951. #define QIB_E_SPIOARMLAUNCH \
  952. ERR_MASK(SendArmLaunchErr)
  953. #define IBA7322_IBCC_LINKINITCMD_MASK SYM_RMASK(IBCCtrlA_0, LinkInitCmd)
  954. #define IBA7322_IBCC_LINKCMD_SHIFT SYM_LSB(IBCCtrlA_0, LinkCmd)
  955. /*
  956. * IBTA_1_2 is set when multiple speeds are enabled (normal),
  957. * and also if forced QDR (only QDR enabled). It's enabled for the
  958. * forced QDR case so that scrambling will be enabled by the TS3
  959. * exchange, when supported by both sides of the link.
  960. */
  961. #define IBA7322_IBC_IBTA_1_2_MASK SYM_MASK(IBCCtrlB_0, IB_ENHANCED_MODE)
  962. #define IBA7322_IBC_MAX_SPEED_MASK SYM_MASK(IBCCtrlB_0, SD_SPEED)
  963. #define IBA7322_IBC_SPEED_QDR SYM_MASK(IBCCtrlB_0, SD_SPEED_QDR)
  964. #define IBA7322_IBC_SPEED_DDR SYM_MASK(IBCCtrlB_0, SD_SPEED_DDR)
  965. #define IBA7322_IBC_SPEED_SDR SYM_MASK(IBCCtrlB_0, SD_SPEED_SDR)
  966. #define IBA7322_IBC_SPEED_MASK (SYM_MASK(IBCCtrlB_0, SD_SPEED_SDR) | \
  967. SYM_MASK(IBCCtrlB_0, SD_SPEED_DDR) | SYM_MASK(IBCCtrlB_0, SD_SPEED_QDR))
  968. #define IBA7322_IBC_SPEED_LSB SYM_LSB(IBCCtrlB_0, SD_SPEED_SDR)
  969. #define IBA7322_LEDBLINK_OFF_SHIFT SYM_LSB(RcvPktLEDCnt_0, OFFperiod)
  970. #define IBA7322_LEDBLINK_ON_SHIFT SYM_LSB(RcvPktLEDCnt_0, ONperiod)
  971. #define IBA7322_IBC_WIDTH_AUTONEG SYM_MASK(IBCCtrlB_0, IB_NUM_CHANNELS)
  972. #define IBA7322_IBC_WIDTH_4X_ONLY (1<<SYM_LSB(IBCCtrlB_0, IB_NUM_CHANNELS))
  973. #define IBA7322_IBC_WIDTH_1X_ONLY (0<<SYM_LSB(IBCCtrlB_0, IB_NUM_CHANNELS))
  974. #define IBA7322_IBC_RXPOL_MASK SYM_MASK(IBCCtrlB_0, IB_POLARITY_REV_SUPP)
  975. #define IBA7322_IBC_RXPOL_LSB SYM_LSB(IBCCtrlB_0, IB_POLARITY_REV_SUPP)
  976. #define IBA7322_IBC_HRTBT_MASK (SYM_MASK(IBCCtrlB_0, HRTBT_AUTO) | \
  977. SYM_MASK(IBCCtrlB_0, HRTBT_ENB))
  978. #define IBA7322_IBC_HRTBT_RMASK (IBA7322_IBC_HRTBT_MASK >> \
  979. SYM_LSB(IBCCtrlB_0, HRTBT_ENB))
  980. #define IBA7322_IBC_HRTBT_LSB SYM_LSB(IBCCtrlB_0, HRTBT_ENB)
  981. #define IBA7322_REDIRECT_VEC_PER_REG 12
  982. #define IBA7322_SENDCHK_PKEY SYM_MASK(SendCheckControl_0, PKey_En)
  983. #define IBA7322_SENDCHK_BTHQP SYM_MASK(SendCheckControl_0, BTHQP_En)
  984. #define IBA7322_SENDCHK_SLID SYM_MASK(SendCheckControl_0, SLID_En)
  985. #define IBA7322_SENDCHK_RAW_IPV6 SYM_MASK(SendCheckControl_0, RawIPV6_En)
  986. #define IBA7322_SENDCHK_MINSZ SYM_MASK(SendCheckControl_0, PacketTooSmall_En)
  987. #define AUTONEG_TRIES 3 /* sequential retries to negotiate DDR */
  988. #define HWE_AUTO(fldname) { .mask = SYM_MASK(HwErrMask, fldname##Mask), \
  989. .msg = #fldname }
  990. #define HWE_AUTO_P(fldname, port) { .mask = SYM_MASK(HwErrMask, \
  991. fldname##Mask##_##port), .msg = #fldname }
  992. static const struct qib_hwerror_msgs qib_7322_hwerror_msgs[] = {
  993. HWE_AUTO_P(IBSerdesPClkNotDetect, 1),
  994. HWE_AUTO_P(IBSerdesPClkNotDetect, 0),
  995. HWE_AUTO(PCIESerdesPClkNotDetect),
  996. HWE_AUTO(PowerOnBISTFailed),
  997. HWE_AUTO(TempsenseTholdReached),
  998. HWE_AUTO(MemoryErr),
  999. HWE_AUTO(PCIeBusParityErr),
  1000. HWE_AUTO(PcieCplTimeout),
  1001. HWE_AUTO(PciePoisonedTLP),
  1002. HWE_AUTO_P(SDmaMemReadErr, 1),
  1003. HWE_AUTO_P(SDmaMemReadErr, 0),
  1004. HWE_AUTO_P(IBCBusFromSPCParityErr, 1),
  1005. HWE_AUTO_P(IBCBusToSPCParityErr, 1),
  1006. HWE_AUTO_P(IBCBusFromSPCParityErr, 0),
  1007. HWE_AUTO(statusValidNoEop),
  1008. HWE_AUTO(LATriggered),
  1009. { .mask = 0 }
  1010. };
  1011. #define E_AUTO(fldname) { .mask = SYM_MASK(ErrMask, fldname##Mask), \
  1012. .msg = #fldname }
  1013. #define E_P_AUTO(fldname) { .mask = SYM_MASK(ErrMask_0, fldname##Mask), \
  1014. .msg = #fldname }
  1015. static const struct qib_hwerror_msgs qib_7322error_msgs[] = {
  1016. E_AUTO(ResetNegated),
  1017. E_AUTO(HardwareErr),
  1018. E_AUTO(InvalidAddrErr),
  1019. E_AUTO(SDmaVL15Err),
  1020. E_AUTO(SBufVL15MisUseErr),
  1021. E_AUTO(InvalidEEPCmd),
  1022. E_AUTO(RcvContextShareErr),
  1023. E_AUTO(SendVLMismatchErr),
  1024. E_AUTO(SendArmLaunchErr),
  1025. E_AUTO(SendSpecialTriggerErr),
  1026. E_AUTO(SDmaWrongPortErr),
  1027. E_AUTO(SDmaBufMaskDuplicateErr),
  1028. E_AUTO(RcvHdrFullErr),
  1029. E_AUTO(RcvEgrFullErr),
  1030. { .mask = 0 }
  1031. };
  1032. static const struct qib_hwerror_msgs qib_7322p_error_msgs[] = {
  1033. E_P_AUTO(IBStatusChanged),
  1034. E_P_AUTO(SHeadersErr),
  1035. E_P_AUTO(VL15BufMisuseErr),
  1036. /*
  1037. * SDmaHaltErr is not really an error, make it clearer;
  1038. */
  1039. {.mask = SYM_MASK(ErrMask_0, SDmaHaltErrMask), .msg = "SDmaHalted"},
  1040. E_P_AUTO(SDmaDescAddrMisalignErr),
  1041. E_P_AUTO(SDmaUnexpDataErr),
  1042. E_P_AUTO(SDmaMissingDwErr),
  1043. E_P_AUTO(SDmaDwEnErr),
  1044. E_P_AUTO(SDmaRpyTagErr),
  1045. E_P_AUTO(SDma1stDescErr),
  1046. E_P_AUTO(SDmaBaseErr),
  1047. E_P_AUTO(SDmaTailOutOfBoundErr),
  1048. E_P_AUTO(SDmaOutOfBoundErr),
  1049. E_P_AUTO(SDmaGenMismatchErr),
  1050. E_P_AUTO(SendBufMisuseErr),
  1051. E_P_AUTO(SendUnsupportedVLErr),
  1052. E_P_AUTO(SendUnexpectedPktNumErr),
  1053. E_P_AUTO(SendDroppedDataPktErr),
  1054. E_P_AUTO(SendDroppedSmpPktErr),
  1055. E_P_AUTO(SendPktLenErr),
  1056. E_P_AUTO(SendUnderRunErr),
  1057. E_P_AUTO(SendMaxPktLenErr),
  1058. E_P_AUTO(SendMinPktLenErr),
  1059. E_P_AUTO(RcvIBLostLinkErr),
  1060. E_P_AUTO(RcvHdrErr),
  1061. E_P_AUTO(RcvHdrLenErr),
  1062. E_P_AUTO(RcvBadTidErr),
  1063. E_P_AUTO(RcvBadVersionErr),
  1064. E_P_AUTO(RcvIBFlowErr),
  1065. E_P_AUTO(RcvEBPErr),
  1066. E_P_AUTO(RcvUnsupportedVLErr),
  1067. E_P_AUTO(RcvUnexpectedCharErr),
  1068. E_P_AUTO(RcvShortPktLenErr),
  1069. E_P_AUTO(RcvLongPktLenErr),
  1070. E_P_AUTO(RcvMaxPktLenErr),
  1071. E_P_AUTO(RcvMinPktLenErr),
  1072. E_P_AUTO(RcvICRCErr),
  1073. E_P_AUTO(RcvVCRCErr),
  1074. E_P_AUTO(RcvFormatErr),
  1075. { .mask = 0 }
  1076. };
  1077. /*
  1078. * Below generates "auto-message" for interrupts not specific to any port or
  1079. * context
  1080. */
  1081. #define INTR_AUTO(fldname) { .mask = SYM_MASK(IntMask, fldname##Mask), \
  1082. .msg = #fldname }
  1083. /* Below generates "auto-message" for interrupts specific to a port */
  1084. #define INTR_AUTO_P(fldname) { .mask = MASK_ACROSS(\
  1085. SYM_LSB(IntMask, fldname##Mask##_0), \
  1086. SYM_LSB(IntMask, fldname##Mask##_1)), \
  1087. .msg = #fldname "_P" }
  1088. /* For some reason, the SerDesTrimDone bits are reversed */
  1089. #define INTR_AUTO_PI(fldname) { .mask = MASK_ACROSS(\
  1090. SYM_LSB(IntMask, fldname##Mask##_1), \
  1091. SYM_LSB(IntMask, fldname##Mask##_0)), \
  1092. .msg = #fldname "_P" }
  1093. /*
  1094. * Below generates "auto-message" for interrupts specific to a context,
  1095. * with ctxt-number appended
  1096. */
  1097. #define INTR_AUTO_C(fldname) { .mask = MASK_ACROSS(\
  1098. SYM_LSB(IntMask, fldname##0IntMask), \
  1099. SYM_LSB(IntMask, fldname##17IntMask)), \
  1100. .msg = #fldname "_C"}
  1101. static const struct qib_hwerror_msgs qib_7322_intr_msgs[] = {
  1102. INTR_AUTO_P(SDmaInt),
  1103. INTR_AUTO_P(SDmaProgressInt),
  1104. INTR_AUTO_P(SDmaIdleInt),
  1105. INTR_AUTO_P(SDmaCleanupDone),
  1106. INTR_AUTO_C(RcvUrg),
  1107. INTR_AUTO_P(ErrInt),
  1108. INTR_AUTO(ErrInt), /* non-port-specific errs */
  1109. INTR_AUTO(AssertGPIOInt),
  1110. INTR_AUTO_P(SendDoneInt),
  1111. INTR_AUTO(SendBufAvailInt),
  1112. INTR_AUTO_C(RcvAvail),
  1113. { .mask = 0 }
  1114. };
  1115. #define TXSYMPTOM_AUTO_P(fldname) \
  1116. { .mask = SYM_MASK(SendHdrErrSymptom_0, fldname), .msg = #fldname }
  1117. static const struct qib_hwerror_msgs hdrchk_msgs[] = {
  1118. TXSYMPTOM_AUTO_P(NonKeyPacket),
  1119. TXSYMPTOM_AUTO_P(GRHFail),
  1120. TXSYMPTOM_AUTO_P(PkeyFail),
  1121. TXSYMPTOM_AUTO_P(QPFail),
  1122. TXSYMPTOM_AUTO_P(SLIDFail),
  1123. TXSYMPTOM_AUTO_P(RawIPV6),
  1124. TXSYMPTOM_AUTO_P(PacketTooSmall),
  1125. { .mask = 0 }
  1126. };
  1127. #define IBA7322_HDRHEAD_PKTINT_SHIFT 32 /* interrupt cnt in upper 32 bits */
  1128. /*
  1129. * Called when we might have an error that is specific to a particular
  1130. * PIO buffer, and may need to cancel that buffer, so it can be re-used,
  1131. * because we don't need to force the update of pioavail
  1132. */
  1133. static void qib_disarm_7322_senderrbufs(struct qib_pportdata *ppd)
  1134. {
  1135. struct qib_devdata *dd = ppd->dd;
  1136. u32 i;
  1137. int any;
  1138. u32 piobcnt = dd->piobcnt2k + dd->piobcnt4k + NUM_VL15_BUFS;
  1139. u32 regcnt = (piobcnt + BITS_PER_LONG - 1) / BITS_PER_LONG;
  1140. unsigned long sbuf[4];
  1141. /*
  1142. * It's possible that sendbuffererror could have bits set; might
  1143. * have already done this as a result of hardware error handling.
  1144. */
  1145. any = 0;
  1146. for (i = 0; i < regcnt; ++i) {
  1147. sbuf[i] = qib_read_kreg64(dd, kr_sendbuffererror + i);
  1148. if (sbuf[i]) {
  1149. any = 1;
  1150. qib_write_kreg(dd, kr_sendbuffererror + i, sbuf[i]);
  1151. }
  1152. }
  1153. if (any)
  1154. qib_disarm_piobufs_set(dd, sbuf, piobcnt);
  1155. }
  1156. /* No txe_recover yet, if ever */
  1157. /* No decode__errors yet */
  1158. static void err_decode(char *msg, size_t len, u64 errs,
  1159. const struct qib_hwerror_msgs *msp)
  1160. {
  1161. u64 these, lmask;
  1162. int took, multi, n = 0;
  1163. while (msp && msp->mask) {
  1164. multi = (msp->mask & (msp->mask - 1));
  1165. while (errs & msp->mask) {
  1166. these = (errs & msp->mask);
  1167. lmask = (these & (these - 1)) ^ these;
  1168. if (len) {
  1169. if (n++) {
  1170. /* separate the strings */
  1171. *msg++ = ',';
  1172. len--;
  1173. }
  1174. took = scnprintf(msg, len, "%s", msp->msg);
  1175. len -= took;
  1176. msg += took;
  1177. }
  1178. errs &= ~lmask;
  1179. if (len && multi) {
  1180. /* More than one bit this mask */
  1181. int idx = -1;
  1182. while (lmask & msp->mask) {
  1183. ++idx;
  1184. lmask >>= 1;
  1185. }
  1186. took = scnprintf(msg, len, "_%d", idx);
  1187. len -= took;
  1188. msg += took;
  1189. }
  1190. }
  1191. ++msp;
  1192. }
  1193. /* If some bits are left, show in hex. */
  1194. if (len && errs)
  1195. snprintf(msg, len, "%sMORE:%llX", n ? "," : "",
  1196. (unsigned long long) errs);
  1197. }
  1198. /* only called if r1 set */
  1199. static void flush_fifo(struct qib_pportdata *ppd)
  1200. {
  1201. struct qib_devdata *dd = ppd->dd;
  1202. u32 __iomem *piobuf;
  1203. u32 bufn;
  1204. u32 *hdr;
  1205. u64 pbc;
  1206. const unsigned hdrwords = 7;
  1207. static struct qib_ib_header ibhdr = {
  1208. .lrh[0] = cpu_to_be16(0xF000 | QIB_LRH_BTH),
  1209. .lrh[1] = IB_LID_PERMISSIVE,
  1210. .lrh[2] = cpu_to_be16(hdrwords + SIZE_OF_CRC),
  1211. .lrh[3] = IB_LID_PERMISSIVE,
  1212. .u.oth.bth[0] = cpu_to_be32(
  1213. (IB_OPCODE_UD_SEND_ONLY << 24) | QIB_DEFAULT_P_KEY),
  1214. .u.oth.bth[1] = cpu_to_be32(0),
  1215. .u.oth.bth[2] = cpu_to_be32(0),
  1216. .u.oth.u.ud.deth[0] = cpu_to_be32(0),
  1217. .u.oth.u.ud.deth[1] = cpu_to_be32(0),
  1218. };
  1219. /*
  1220. * Send a dummy VL15 packet to flush the launch FIFO.
  1221. * This will not actually be sent since the TxeBypassIbc bit is set.
  1222. */
  1223. pbc = PBC_7322_VL15_SEND |
  1224. (((u64)ppd->hw_pidx) << (PBC_PORT_SEL_LSB + 32)) |
  1225. (hdrwords + SIZE_OF_CRC);
  1226. piobuf = qib_7322_getsendbuf(ppd, pbc, &bufn);
  1227. if (!piobuf)
  1228. return;
  1229. writeq(pbc, piobuf);
  1230. hdr = (u32 *) &ibhdr;
  1231. if (dd->flags & QIB_PIO_FLUSH_WC) {
  1232. qib_flush_wc();
  1233. qib_pio_copy(piobuf + 2, hdr, hdrwords - 1);
  1234. qib_flush_wc();
  1235. __raw_writel(hdr[hdrwords - 1], piobuf + hdrwords + 1);
  1236. qib_flush_wc();
  1237. } else
  1238. qib_pio_copy(piobuf + 2, hdr, hdrwords);
  1239. qib_sendbuf_done(dd, bufn);
  1240. }
  1241. /*
  1242. * This is called with interrupts disabled and sdma_lock held.
  1243. */
  1244. static void qib_7322_sdma_sendctrl(struct qib_pportdata *ppd, unsigned op)
  1245. {
  1246. struct qib_devdata *dd = ppd->dd;
  1247. u64 set_sendctrl = 0;
  1248. u64 clr_sendctrl = 0;
  1249. if (op & QIB_SDMA_SENDCTRL_OP_ENABLE)
  1250. set_sendctrl |= SYM_MASK(SendCtrl_0, SDmaEnable);
  1251. else
  1252. clr_sendctrl |= SYM_MASK(SendCtrl_0, SDmaEnable);
  1253. if (op & QIB_SDMA_SENDCTRL_OP_INTENABLE)
  1254. set_sendctrl |= SYM_MASK(SendCtrl_0, SDmaIntEnable);
  1255. else
  1256. clr_sendctrl |= SYM_MASK(SendCtrl_0, SDmaIntEnable);
  1257. if (op & QIB_SDMA_SENDCTRL_OP_HALT)
  1258. set_sendctrl |= SYM_MASK(SendCtrl_0, SDmaHalt);
  1259. else
  1260. clr_sendctrl |= SYM_MASK(SendCtrl_0, SDmaHalt);
  1261. if (op & QIB_SDMA_SENDCTRL_OP_DRAIN)
  1262. set_sendctrl |= SYM_MASK(SendCtrl_0, TxeBypassIbc) |
  1263. SYM_MASK(SendCtrl_0, TxeAbortIbc) |
  1264. SYM_MASK(SendCtrl_0, TxeDrainRmFifo);
  1265. else
  1266. clr_sendctrl |= SYM_MASK(SendCtrl_0, TxeBypassIbc) |
  1267. SYM_MASK(SendCtrl_0, TxeAbortIbc) |
  1268. SYM_MASK(SendCtrl_0, TxeDrainRmFifo);
  1269. spin_lock(&dd->sendctrl_lock);
  1270. /* If we are draining everything, block sends first */
  1271. if (op & QIB_SDMA_SENDCTRL_OP_DRAIN) {
  1272. ppd->p_sendctrl &= ~SYM_MASK(SendCtrl_0, SendEnable);
  1273. qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
  1274. qib_write_kreg(dd, kr_scratch, 0);
  1275. }
  1276. ppd->p_sendctrl |= set_sendctrl;
  1277. ppd->p_sendctrl &= ~clr_sendctrl;
  1278. if (op & QIB_SDMA_SENDCTRL_OP_CLEANUP)
  1279. qib_write_kreg_port(ppd, krp_sendctrl,
  1280. ppd->p_sendctrl |
  1281. SYM_MASK(SendCtrl_0, SDmaCleanup));
  1282. else
  1283. qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
  1284. qib_write_kreg(dd, kr_scratch, 0);
  1285. if (op & QIB_SDMA_SENDCTRL_OP_DRAIN) {
  1286. ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, SendEnable);
  1287. qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
  1288. qib_write_kreg(dd, kr_scratch, 0);
  1289. }
  1290. spin_unlock(&dd->sendctrl_lock);
  1291. if ((op & QIB_SDMA_SENDCTRL_OP_DRAIN) && ppd->dd->cspec->r1)
  1292. flush_fifo(ppd);
  1293. }
  1294. static void qib_7322_sdma_hw_clean_up(struct qib_pportdata *ppd)
  1295. {
  1296. __qib_sdma_process_event(ppd, qib_sdma_event_e50_hw_cleaned);
  1297. }
  1298. static void qib_sdma_7322_setlengen(struct qib_pportdata *ppd)
  1299. {
  1300. /*
  1301. * Set SendDmaLenGen and clear and set
  1302. * the MSB of the generation count to enable generation checking
  1303. * and load the internal generation counter.
  1304. */
  1305. qib_write_kreg_port(ppd, krp_senddmalengen, ppd->sdma_descq_cnt);
  1306. qib_write_kreg_port(ppd, krp_senddmalengen,
  1307. ppd->sdma_descq_cnt |
  1308. (1ULL << QIB_7322_SendDmaLenGen_0_Generation_MSB));
  1309. }
  1310. /*
  1311. * Must be called with sdma_lock held, or before init finished.
  1312. */
  1313. static void qib_sdma_update_7322_tail(struct qib_pportdata *ppd, u16 tail)
  1314. {
  1315. /* Commit writes to memory and advance the tail on the chip */
  1316. wmb();
  1317. ppd->sdma_descq_tail = tail;
  1318. qib_write_kreg_port(ppd, krp_senddmatail, tail);
  1319. }
  1320. /*
  1321. * This is called with interrupts disabled and sdma_lock held.
  1322. */
  1323. static void qib_7322_sdma_hw_start_up(struct qib_pportdata *ppd)
  1324. {
  1325. /*
  1326. * Drain all FIFOs.
  1327. * The hardware doesn't require this but we do it so that verbs
  1328. * and user applications don't wait for link active to send stale
  1329. * data.
  1330. */
  1331. sendctrl_7322_mod(ppd, QIB_SENDCTRL_FLUSH);
  1332. qib_sdma_7322_setlengen(ppd);
  1333. qib_sdma_update_7322_tail(ppd, 0); /* Set SendDmaTail */
  1334. ppd->sdma_head_dma[0] = 0;
  1335. qib_7322_sdma_sendctrl(ppd,
  1336. ppd->sdma_state.current_op | QIB_SDMA_SENDCTRL_OP_CLEANUP);
  1337. }
  1338. #define DISABLES_SDMA ( \
  1339. QIB_E_P_SDMAHALT | \
  1340. QIB_E_P_SDMADESCADDRMISALIGN | \
  1341. QIB_E_P_SDMAMISSINGDW | \
  1342. QIB_E_P_SDMADWEN | \
  1343. QIB_E_P_SDMARPYTAG | \
  1344. QIB_E_P_SDMA1STDESC | \
  1345. QIB_E_P_SDMABASE | \
  1346. QIB_E_P_SDMATAILOUTOFBOUND | \
  1347. QIB_E_P_SDMAOUTOFBOUND | \
  1348. QIB_E_P_SDMAGENMISMATCH)
  1349. static void sdma_7322_p_errors(struct qib_pportdata *ppd, u64 errs)
  1350. {
  1351. unsigned long flags;
  1352. struct qib_devdata *dd = ppd->dd;
  1353. errs &= QIB_E_P_SDMAERRS;
  1354. if (errs & QIB_E_P_SDMAUNEXPDATA)
  1355. qib_dev_err(dd, "IB%u:%u SDmaUnexpData\n", dd->unit,
  1356. ppd->port);
  1357. spin_lock_irqsave(&ppd->sdma_lock, flags);
  1358. switch (ppd->sdma_state.current_state) {
  1359. case qib_sdma_state_s00_hw_down:
  1360. break;
  1361. case qib_sdma_state_s10_hw_start_up_wait:
  1362. if (errs & QIB_E_P_SDMAHALT)
  1363. __qib_sdma_process_event(ppd,
  1364. qib_sdma_event_e20_hw_started);
  1365. break;
  1366. case qib_sdma_state_s20_idle:
  1367. break;
  1368. case qib_sdma_state_s30_sw_clean_up_wait:
  1369. break;
  1370. case qib_sdma_state_s40_hw_clean_up_wait:
  1371. if (errs & QIB_E_P_SDMAHALT)
  1372. __qib_sdma_process_event(ppd,
  1373. qib_sdma_event_e50_hw_cleaned);
  1374. break;
  1375. case qib_sdma_state_s50_hw_halt_wait:
  1376. if (errs & QIB_E_P_SDMAHALT)
  1377. __qib_sdma_process_event(ppd,
  1378. qib_sdma_event_e60_hw_halted);
  1379. break;
  1380. case qib_sdma_state_s99_running:
  1381. __qib_sdma_process_event(ppd, qib_sdma_event_e7322_err_halted);
  1382. __qib_sdma_process_event(ppd, qib_sdma_event_e60_hw_halted);
  1383. break;
  1384. }
  1385. spin_unlock_irqrestore(&ppd->sdma_lock, flags);
  1386. }
  1387. /*
  1388. * handle per-device errors (not per-port errors)
  1389. */
  1390. static noinline void handle_7322_errors(struct qib_devdata *dd)
  1391. {
  1392. char *msg;
  1393. u64 iserr = 0;
  1394. u64 errs;
  1395. u64 mask;
  1396. int log_idx;
  1397. qib_stats.sps_errints++;
  1398. errs = qib_read_kreg64(dd, kr_errstatus);
  1399. if (!errs) {
  1400. qib_devinfo(dd->pcidev, "device error interrupt, "
  1401. "but no error bits set!\n");
  1402. goto done;
  1403. }
  1404. /* don't report errors that are masked */
  1405. errs &= dd->cspec->errormask;
  1406. msg = dd->cspec->emsgbuf;
  1407. /* do these first, they are most important */
  1408. if (errs & QIB_E_HARDWARE) {
  1409. *msg = '\0';
  1410. qib_7322_handle_hwerrors(dd, msg, sizeof dd->cspec->emsgbuf);
  1411. } else
  1412. for (log_idx = 0; log_idx < QIB_EEP_LOG_CNT; ++log_idx)
  1413. if (errs & dd->eep_st_masks[log_idx].errs_to_log)
  1414. qib_inc_eeprom_err(dd, log_idx, 1);
  1415. if (errs & QIB_E_SPKTERRS) {
  1416. qib_disarm_7322_senderrbufs(dd->pport);
  1417. qib_stats.sps_txerrs++;
  1418. } else if (errs & QIB_E_INVALIDADDR)
  1419. qib_stats.sps_txerrs++;
  1420. else if (errs & QIB_E_ARMLAUNCH) {
  1421. qib_stats.sps_txerrs++;
  1422. qib_disarm_7322_senderrbufs(dd->pport);
  1423. }
  1424. qib_write_kreg(dd, kr_errclear, errs);
  1425. /*
  1426. * The ones we mask off are handled specially below
  1427. * or above. Also mask SDMADISABLED by default as it
  1428. * is too chatty.
  1429. */
  1430. mask = QIB_E_HARDWARE;
  1431. *msg = '\0';
  1432. err_decode(msg, sizeof dd->cspec->emsgbuf, errs & ~mask,
  1433. qib_7322error_msgs);
  1434. /*
  1435. * Getting reset is a tragedy for all ports. Mark the device
  1436. * _and_ the ports as "offline" in way meaningful to each.
  1437. */
  1438. if (errs & QIB_E_RESET) {
  1439. int pidx;
  1440. qib_dev_err(dd, "Got reset, requires re-init "
  1441. "(unload and reload driver)\n");
  1442. dd->flags &= ~QIB_INITTED; /* needs re-init */
  1443. /* mark as having had error */
  1444. *dd->devstatusp |= QIB_STATUS_HWERROR;
  1445. for (pidx = 0; pidx < dd->num_pports; ++pidx)
  1446. if (dd->pport[pidx].link_speed_supported)
  1447. *dd->pport[pidx].statusp &= ~QIB_STATUS_IB_CONF;
  1448. }
  1449. if (*msg && iserr)
  1450. qib_dev_err(dd, "%s error\n", msg);
  1451. /*
  1452. * If there were hdrq or egrfull errors, wake up any processes
  1453. * waiting in poll. We used to try to check which contexts had
  1454. * the overflow, but given the cost of that and the chip reads
  1455. * to support it, it's better to just wake everybody up if we
  1456. * get an overflow; waiters can poll again if it's not them.
  1457. */
  1458. if (errs & (ERR_MASK(RcvEgrFullErr) | ERR_MASK(RcvHdrFullErr))) {
  1459. qib_handle_urcv(dd, ~0U);
  1460. if (errs & ERR_MASK(RcvEgrFullErr))
  1461. qib_stats.sps_buffull++;
  1462. else
  1463. qib_stats.sps_hdrfull++;
  1464. }
  1465. done:
  1466. return;
  1467. }
  1468. static void reenable_chase(unsigned long opaque)
  1469. {
  1470. struct qib_pportdata *ppd = (struct qib_pportdata *)opaque;
  1471. ppd->cpspec->chase_timer.expires = 0;
  1472. qib_set_ib_7322_lstate(ppd, QLOGIC_IB_IBCC_LINKCMD_DOWN,
  1473. QLOGIC_IB_IBCC_LINKINITCMD_POLL);
  1474. }
  1475. static void disable_chase(struct qib_pportdata *ppd, u64 tnow, u8 ibclt)
  1476. {
  1477. ppd->cpspec->chase_end = 0;
  1478. if (!qib_chase)
  1479. return;
  1480. qib_set_ib_7322_lstate(ppd, QLOGIC_IB_IBCC_LINKCMD_DOWN,
  1481. QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
  1482. ppd->cpspec->chase_timer.expires = jiffies + QIB_CHASE_DIS_TIME;
  1483. add_timer(&ppd->cpspec->chase_timer);
  1484. }
  1485. static void handle_serdes_issues(struct qib_pportdata *ppd, u64 ibcst)
  1486. {
  1487. u8 ibclt;
  1488. u64 tnow;
  1489. ibclt = (u8)SYM_FIELD(ibcst, IBCStatusA_0, LinkTrainingState);
  1490. /*
  1491. * Detect and handle the state chase issue, where we can
  1492. * get stuck if we are unlucky on timing on both sides of
  1493. * the link. If we are, we disable, set a timer, and
  1494. * then re-enable.
  1495. */
  1496. switch (ibclt) {
  1497. case IB_7322_LT_STATE_CFGRCVFCFG:
  1498. case IB_7322_LT_STATE_CFGWAITRMT:
  1499. case IB_7322_LT_STATE_TXREVLANES:
  1500. case IB_7322_LT_STATE_CFGENH:
  1501. tnow = get_jiffies_64();
  1502. if (ppd->cpspec->chase_end &&
  1503. time_after64(tnow, ppd->cpspec->chase_end))
  1504. disable_chase(ppd, tnow, ibclt);
  1505. else if (!ppd->cpspec->chase_end)
  1506. ppd->cpspec->chase_end = tnow + QIB_CHASE_TIME;
  1507. break;
  1508. default:
  1509. ppd->cpspec->chase_end = 0;
  1510. break;
  1511. }
  1512. if (((ibclt >= IB_7322_LT_STATE_CFGTEST &&
  1513. ibclt <= IB_7322_LT_STATE_CFGWAITENH) ||
  1514. ibclt == IB_7322_LT_STATE_LINKUP) &&
  1515. (ibcst & SYM_MASK(IBCStatusA_0, LinkSpeedQDR))) {
  1516. force_h1(ppd);
  1517. ppd->cpspec->qdr_reforce = 1;
  1518. if (!ppd->dd->cspec->r1)
  1519. serdes_7322_los_enable(ppd, 0);
  1520. } else if (ppd->cpspec->qdr_reforce &&
  1521. (ibcst & SYM_MASK(IBCStatusA_0, LinkSpeedQDR)) &&
  1522. (ibclt == IB_7322_LT_STATE_CFGENH ||
  1523. ibclt == IB_7322_LT_STATE_CFGIDLE ||
  1524. ibclt == IB_7322_LT_STATE_LINKUP))
  1525. force_h1(ppd);
  1526. if ((IS_QMH(ppd->dd) || IS_QME(ppd->dd)) &&
  1527. ppd->link_speed_enabled == QIB_IB_QDR &&
  1528. (ibclt == IB_7322_LT_STATE_CFGTEST ||
  1529. ibclt == IB_7322_LT_STATE_CFGENH ||
  1530. (ibclt >= IB_7322_LT_STATE_POLLACTIVE &&
  1531. ibclt <= IB_7322_LT_STATE_SLEEPQUIET)))
  1532. adj_tx_serdes(ppd);
  1533. if (ibclt != IB_7322_LT_STATE_LINKUP) {
  1534. u8 ltstate = qib_7322_phys_portstate(ibcst);
  1535. u8 pibclt = (u8)SYM_FIELD(ppd->lastibcstat, IBCStatusA_0,
  1536. LinkTrainingState);
  1537. if (!ppd->dd->cspec->r1 &&
  1538. pibclt == IB_7322_LT_STATE_LINKUP &&
  1539. ltstate != IB_PHYSPORTSTATE_LINK_ERR_RECOVER &&
  1540. ltstate != IB_PHYSPORTSTATE_RECOVERY_RETRAIN &&
  1541. ltstate != IB_PHYSPORTSTATE_RECOVERY_WAITRMT &&
  1542. ltstate != IB_PHYSPORTSTATE_RECOVERY_IDLE)
  1543. /* If the link went down (but no into recovery,
  1544. * turn LOS back on */
  1545. serdes_7322_los_enable(ppd, 1);
  1546. if (!ppd->cpspec->qdr_dfe_on &&
  1547. ibclt <= IB_7322_LT_STATE_SLEEPQUIET) {
  1548. ppd->cpspec->qdr_dfe_on = 1;
  1549. ppd->cpspec->qdr_dfe_time = 0;
  1550. /* On link down, reenable QDR adaptation */
  1551. qib_write_kreg_port(ppd, krp_static_adapt_dis(2),
  1552. ppd->dd->cspec->r1 ?
  1553. QDR_STATIC_ADAPT_DOWN_R1 :
  1554. QDR_STATIC_ADAPT_DOWN);
  1555. printk(KERN_INFO QIB_DRV_NAME
  1556. " IB%u:%u re-enabled QDR adaptation "
  1557. "ibclt %x\n", ppd->dd->unit, ppd->port, ibclt);
  1558. }
  1559. }
  1560. }
  1561. static int qib_7322_set_ib_cfg(struct qib_pportdata *, int, u32);
  1562. /*
  1563. * This is per-pport error handling.
  1564. * will likely get it's own MSIx interrupt (one for each port,
  1565. * although just a single handler).
  1566. */
  1567. static noinline void handle_7322_p_errors(struct qib_pportdata *ppd)
  1568. {
  1569. char *msg;
  1570. u64 ignore_this_time = 0, iserr = 0, errs, fmask;
  1571. struct qib_devdata *dd = ppd->dd;
  1572. /* do this as soon as possible */
  1573. fmask = qib_read_kreg64(dd, kr_act_fmask);
  1574. if (!fmask)
  1575. check_7322_rxe_status(ppd);
  1576. errs = qib_read_kreg_port(ppd, krp_errstatus);
  1577. if (!errs)
  1578. qib_devinfo(dd->pcidev,
  1579. "Port%d error interrupt, but no error bits set!\n",
  1580. ppd->port);
  1581. if (!fmask)
  1582. errs &= ~QIB_E_P_IBSTATUSCHANGED;
  1583. if (!errs)
  1584. goto done;
  1585. msg = ppd->cpspec->epmsgbuf;
  1586. *msg = '\0';
  1587. if (errs & ~QIB_E_P_BITSEXTANT) {
  1588. err_decode(msg, sizeof ppd->cpspec->epmsgbuf,
  1589. errs & ~QIB_E_P_BITSEXTANT, qib_7322p_error_msgs);
  1590. if (!*msg)
  1591. snprintf(msg, sizeof ppd->cpspec->epmsgbuf,
  1592. "no others");
  1593. qib_dev_porterr(dd, ppd->port, "error interrupt with unknown"
  1594. " errors 0x%016Lx set (and %s)\n",
  1595. (errs & ~QIB_E_P_BITSEXTANT), msg);
  1596. *msg = '\0';
  1597. }
  1598. if (errs & QIB_E_P_SHDR) {
  1599. u64 symptom;
  1600. /* determine cause, then write to clear */
  1601. symptom = qib_read_kreg_port(ppd, krp_sendhdrsymptom);
  1602. qib_write_kreg_port(ppd, krp_sendhdrsymptom, 0);
  1603. err_decode(msg, sizeof ppd->cpspec->epmsgbuf, symptom,
  1604. hdrchk_msgs);
  1605. *msg = '\0';
  1606. /* senderrbuf cleared in SPKTERRS below */
  1607. }
  1608. if (errs & QIB_E_P_SPKTERRS) {
  1609. if ((errs & QIB_E_P_LINK_PKTERRS) &&
  1610. !(ppd->lflags & QIBL_LINKACTIVE)) {
  1611. /*
  1612. * This can happen when trying to bring the link
  1613. * up, but the IB link changes state at the "wrong"
  1614. * time. The IB logic then complains that the packet
  1615. * isn't valid. We don't want to confuse people, so
  1616. * we just don't print them, except at debug
  1617. */
  1618. err_decode(msg, sizeof ppd->cpspec->epmsgbuf,
  1619. (errs & QIB_E_P_LINK_PKTERRS),
  1620. qib_7322p_error_msgs);
  1621. *msg = '\0';
  1622. ignore_this_time = errs & QIB_E_P_LINK_PKTERRS;
  1623. }
  1624. qib_disarm_7322_senderrbufs(ppd);
  1625. } else if ((errs & QIB_E_P_LINK_PKTERRS) &&
  1626. !(ppd->lflags & QIBL_LINKACTIVE)) {
  1627. /*
  1628. * This can happen when SMA is trying to bring the link
  1629. * up, but the IB link changes state at the "wrong" time.
  1630. * The IB logic then complains that the packet isn't
  1631. * valid. We don't want to confuse people, so we just
  1632. * don't print them, except at debug
  1633. */
  1634. err_decode(msg, sizeof ppd->cpspec->epmsgbuf, errs,
  1635. qib_7322p_error_msgs);
  1636. ignore_this_time = errs & QIB_E_P_LINK_PKTERRS;
  1637. *msg = '\0';
  1638. }
  1639. qib_write_kreg_port(ppd, krp_errclear, errs);
  1640. errs &= ~ignore_this_time;
  1641. if (!errs)
  1642. goto done;
  1643. if (errs & QIB_E_P_RPKTERRS)
  1644. qib_stats.sps_rcverrs++;
  1645. if (errs & QIB_E_P_SPKTERRS)
  1646. qib_stats.sps_txerrs++;
  1647. iserr = errs & ~(QIB_E_P_RPKTERRS | QIB_E_P_PKTERRS);
  1648. if (errs & QIB_E_P_SDMAERRS)
  1649. sdma_7322_p_errors(ppd, errs);
  1650. if (errs & QIB_E_P_IBSTATUSCHANGED) {
  1651. u64 ibcs;
  1652. u8 ltstate;
  1653. ibcs = qib_read_kreg_port(ppd, krp_ibcstatus_a);
  1654. ltstate = qib_7322_phys_portstate(ibcs);
  1655. if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG))
  1656. handle_serdes_issues(ppd, ibcs);
  1657. if (!(ppd->cpspec->ibcctrl_a &
  1658. SYM_MASK(IBCCtrlA_0, IBStatIntReductionEn))) {
  1659. /*
  1660. * We got our interrupt, so init code should be
  1661. * happy and not try alternatives. Now squelch
  1662. * other "chatter" from link-negotiation (pre Init)
  1663. */
  1664. ppd->cpspec->ibcctrl_a |=
  1665. SYM_MASK(IBCCtrlA_0, IBStatIntReductionEn);
  1666. qib_write_kreg_port(ppd, krp_ibcctrl_a,
  1667. ppd->cpspec->ibcctrl_a);
  1668. }
  1669. /* Update our picture of width and speed from chip */
  1670. ppd->link_width_active =
  1671. (ibcs & SYM_MASK(IBCStatusA_0, LinkWidthActive)) ?
  1672. IB_WIDTH_4X : IB_WIDTH_1X;
  1673. ppd->link_speed_active = (ibcs & SYM_MASK(IBCStatusA_0,
  1674. LinkSpeedQDR)) ? QIB_IB_QDR : (ibcs &
  1675. SYM_MASK(IBCStatusA_0, LinkSpeedActive)) ?
  1676. QIB_IB_DDR : QIB_IB_SDR;
  1677. if ((ppd->lflags & QIBL_IB_LINK_DISABLED) && ltstate !=
  1678. IB_PHYSPORTSTATE_DISABLED)
  1679. qib_set_ib_7322_lstate(ppd, 0,
  1680. QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
  1681. else
  1682. /*
  1683. * Since going into a recovery state causes the link
  1684. * state to go down and since recovery is transitory,
  1685. * it is better if we "miss" ever seeing the link
  1686. * training state go into recovery (i.e., ignore this
  1687. * transition for link state special handling purposes)
  1688. * without updating lastibcstat.
  1689. */
  1690. if (ltstate != IB_PHYSPORTSTATE_LINK_ERR_RECOVER &&
  1691. ltstate != IB_PHYSPORTSTATE_RECOVERY_RETRAIN &&
  1692. ltstate != IB_PHYSPORTSTATE_RECOVERY_WAITRMT &&
  1693. ltstate != IB_PHYSPORTSTATE_RECOVERY_IDLE)
  1694. qib_handle_e_ibstatuschanged(ppd, ibcs);
  1695. }
  1696. if (*msg && iserr)
  1697. qib_dev_porterr(dd, ppd->port, "%s error\n", msg);
  1698. if (ppd->state_wanted & ppd->lflags)
  1699. wake_up_interruptible(&ppd->state_wait);
  1700. done:
  1701. return;
  1702. }
  1703. /* enable/disable chip from delivering interrupts */
  1704. static void qib_7322_set_intr_state(struct qib_devdata *dd, u32 enable)
  1705. {
  1706. if (enable) {
  1707. if (dd->flags & QIB_BADINTR)
  1708. return;
  1709. qib_write_kreg(dd, kr_intmask, dd->cspec->int_enable_mask);
  1710. /* cause any pending enabled interrupts to be re-delivered */
  1711. qib_write_kreg(dd, kr_intclear, 0ULL);
  1712. if (dd->cspec->num_msix_entries) {
  1713. /* and same for MSIx */
  1714. u64 val = qib_read_kreg64(dd, kr_intgranted);
  1715. if (val)
  1716. qib_write_kreg(dd, kr_intgranted, val);
  1717. }
  1718. } else
  1719. qib_write_kreg(dd, kr_intmask, 0ULL);
  1720. }
  1721. /*
  1722. * Try to cleanup as much as possible for anything that might have gone
  1723. * wrong while in freeze mode, such as pio buffers being written by user
  1724. * processes (causing armlaunch), send errors due to going into freeze mode,
  1725. * etc., and try to avoid causing extra interrupts while doing so.
  1726. * Forcibly update the in-memory pioavail register copies after cleanup
  1727. * because the chip won't do it while in freeze mode (the register values
  1728. * themselves are kept correct).
  1729. * Make sure that we don't lose any important interrupts by using the chip
  1730. * feature that says that writing 0 to a bit in *clear that is set in
  1731. * *status will cause an interrupt to be generated again (if allowed by
  1732. * the *mask value).
  1733. * This is in chip-specific code because of all of the register accesses,
  1734. * even though the details are similar on most chips.
  1735. */
  1736. static void qib_7322_clear_freeze(struct qib_devdata *dd)
  1737. {
  1738. int pidx;
  1739. /* disable error interrupts, to avoid confusion */
  1740. qib_write_kreg(dd, kr_errmask, 0ULL);
  1741. for (pidx = 0; pidx < dd->num_pports; ++pidx)
  1742. if (dd->pport[pidx].link_speed_supported)
  1743. qib_write_kreg_port(dd->pport + pidx, krp_errmask,
  1744. 0ULL);
  1745. /* also disable interrupts; errormask is sometimes overwriten */
  1746. qib_7322_set_intr_state(dd, 0);
  1747. /* clear the freeze, and be sure chip saw it */
  1748. qib_write_kreg(dd, kr_control, dd->control);
  1749. qib_read_kreg32(dd, kr_scratch);
  1750. /*
  1751. * Force new interrupt if any hwerr, error or interrupt bits are
  1752. * still set, and clear "safe" send packet errors related to freeze
  1753. * and cancelling sends. Re-enable error interrupts before possible
  1754. * force of re-interrupt on pending interrupts.
  1755. */
  1756. qib_write_kreg(dd, kr_hwerrclear, 0ULL);
  1757. qib_write_kreg(dd, kr_errclear, E_SPKT_ERRS_IGNORE);
  1758. qib_write_kreg(dd, kr_errmask, dd->cspec->errormask);
  1759. /* We need to purge per-port errs and reset mask, too */
  1760. for (pidx = 0; pidx < dd->num_pports; ++pidx) {
  1761. if (!dd->pport[pidx].link_speed_supported)
  1762. continue;
  1763. qib_write_kreg_port(dd->pport + pidx, krp_errclear, ~0Ull);
  1764. qib_write_kreg_port(dd->pport + pidx, krp_errmask, ~0Ull);
  1765. }
  1766. qib_7322_set_intr_state(dd, 1);
  1767. }
  1768. /* no error handling to speak of */
  1769. /**
  1770. * qib_7322_handle_hwerrors - display hardware errors.
  1771. * @dd: the qlogic_ib device
  1772. * @msg: the output buffer
  1773. * @msgl: the size of the output buffer
  1774. *
  1775. * Use same msg buffer as regular errors to avoid excessive stack
  1776. * use. Most hardware errors are catastrophic, but for right now,
  1777. * we'll print them and continue. We reuse the same message buffer as
  1778. * qib_handle_errors() to avoid excessive stack usage.
  1779. */
  1780. static void qib_7322_handle_hwerrors(struct qib_devdata *dd, char *msg,
  1781. size_t msgl)
  1782. {
  1783. u64 hwerrs;
  1784. u32 ctrl;
  1785. int isfatal = 0;
  1786. hwerrs = qib_read_kreg64(dd, kr_hwerrstatus);
  1787. if (!hwerrs)
  1788. goto bail;
  1789. if (hwerrs == ~0ULL) {
  1790. qib_dev_err(dd, "Read of hardware error status failed "
  1791. "(all bits set); ignoring\n");
  1792. goto bail;
  1793. }
  1794. qib_stats.sps_hwerrs++;
  1795. /* Always clear the error status register, except BIST fail */
  1796. qib_write_kreg(dd, kr_hwerrclear, hwerrs &
  1797. ~HWE_MASK(PowerOnBISTFailed));
  1798. hwerrs &= dd->cspec->hwerrmask;
  1799. /* no EEPROM logging, yet */
  1800. if (hwerrs)
  1801. qib_devinfo(dd->pcidev, "Hardware error: hwerr=0x%llx "
  1802. "(cleared)\n", (unsigned long long) hwerrs);
  1803. ctrl = qib_read_kreg32(dd, kr_control);
  1804. if ((ctrl & SYM_MASK(Control, FreezeMode)) && !dd->diag_client) {
  1805. /*
  1806. * No recovery yet...
  1807. */
  1808. if ((hwerrs & ~HWE_MASK(LATriggered)) ||
  1809. dd->cspec->stay_in_freeze) {
  1810. /*
  1811. * If any set that we aren't ignoring only make the
  1812. * complaint once, in case it's stuck or recurring,
  1813. * and we get here multiple times
  1814. * Force link down, so switch knows, and
  1815. * LEDs are turned off.
  1816. */
  1817. if (dd->flags & QIB_INITTED)
  1818. isfatal = 1;
  1819. } else
  1820. qib_7322_clear_freeze(dd);
  1821. }
  1822. if (hwerrs & HWE_MASK(PowerOnBISTFailed)) {
  1823. isfatal = 1;
  1824. strlcpy(msg, "[Memory BIST test failed, "
  1825. "InfiniPath hardware unusable]", msgl);
  1826. /* ignore from now on, so disable until driver reloaded */
  1827. dd->cspec->hwerrmask &= ~HWE_MASK(PowerOnBISTFailed);
  1828. qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
  1829. }
  1830. err_decode(msg, msgl, hwerrs, qib_7322_hwerror_msgs);
  1831. /* Ignore esoteric PLL failures et al. */
  1832. qib_dev_err(dd, "%s hardware error\n", msg);
  1833. if (isfatal && !dd->diag_client) {
  1834. qib_dev_err(dd, "Fatal Hardware Error, no longer"
  1835. " usable, SN %.16s\n", dd->serial);
  1836. /*
  1837. * for /sys status file and user programs to print; if no
  1838. * trailing brace is copied, we'll know it was truncated.
  1839. */
  1840. if (dd->freezemsg)
  1841. snprintf(dd->freezemsg, dd->freezelen,
  1842. "{%s}", msg);
  1843. qib_disable_after_error(dd);
  1844. }
  1845. bail:;
  1846. }
  1847. /**
  1848. * qib_7322_init_hwerrors - enable hardware errors
  1849. * @dd: the qlogic_ib device
  1850. *
  1851. * now that we have finished initializing everything that might reasonably
  1852. * cause a hardware error, and cleared those errors bits as they occur,
  1853. * we can enable hardware errors in the mask (potentially enabling
  1854. * freeze mode), and enable hardware errors as errors (along with
  1855. * everything else) in errormask
  1856. */
  1857. static void qib_7322_init_hwerrors(struct qib_devdata *dd)
  1858. {
  1859. int pidx;
  1860. u64 extsval;
  1861. extsval = qib_read_kreg64(dd, kr_extstatus);
  1862. if (!(extsval & (QIB_EXTS_MEMBIST_DISABLED |
  1863. QIB_EXTS_MEMBIST_ENDTEST)))
  1864. qib_dev_err(dd, "MemBIST did not complete!\n");
  1865. /* never clear BIST failure, so reported on each driver load */
  1866. qib_write_kreg(dd, kr_hwerrclear, ~HWE_MASK(PowerOnBISTFailed));
  1867. qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
  1868. /* clear all */
  1869. qib_write_kreg(dd, kr_errclear, ~0ULL);
  1870. /* enable errors that are masked, at least this first time. */
  1871. qib_write_kreg(dd, kr_errmask, ~0ULL);
  1872. dd->cspec->errormask = qib_read_kreg64(dd, kr_errmask);
  1873. for (pidx = 0; pidx < dd->num_pports; ++pidx)
  1874. if (dd->pport[pidx].link_speed_supported)
  1875. qib_write_kreg_port(dd->pport + pidx, krp_errmask,
  1876. ~0ULL);
  1877. }
  1878. /*
  1879. * Disable and enable the armlaunch error. Used for PIO bandwidth testing
  1880. * on chips that are count-based, rather than trigger-based. There is no
  1881. * reference counting, but that's also fine, given the intended use.
  1882. * Only chip-specific because it's all register accesses
  1883. */
  1884. static void qib_set_7322_armlaunch(struct qib_devdata *dd, u32 enable)
  1885. {
  1886. if (enable) {
  1887. qib_write_kreg(dd, kr_errclear, QIB_E_SPIOARMLAUNCH);
  1888. dd->cspec->errormask |= QIB_E_SPIOARMLAUNCH;
  1889. } else
  1890. dd->cspec->errormask &= ~QIB_E_SPIOARMLAUNCH;
  1891. qib_write_kreg(dd, kr_errmask, dd->cspec->errormask);
  1892. }
  1893. /*
  1894. * Formerly took parameter <which> in pre-shifted,
  1895. * pre-merged form with LinkCmd and LinkInitCmd
  1896. * together, and assuming the zero was NOP.
  1897. */
  1898. static void qib_set_ib_7322_lstate(struct qib_pportdata *ppd, u16 linkcmd,
  1899. u16 linitcmd)
  1900. {
  1901. u64 mod_wd;
  1902. struct qib_devdata *dd = ppd->dd;
  1903. unsigned long flags;
  1904. if (linitcmd == QLOGIC_IB_IBCC_LINKINITCMD_DISABLE) {
  1905. /*
  1906. * If we are told to disable, note that so link-recovery
  1907. * code does not attempt to bring us back up.
  1908. * Also reset everything that we can, so we start
  1909. * completely clean when re-enabled (before we
  1910. * actually issue the disable to the IBC)
  1911. */
  1912. qib_7322_mini_pcs_reset(ppd);
  1913. spin_lock_irqsave(&ppd->lflags_lock, flags);
  1914. ppd->lflags |= QIBL_IB_LINK_DISABLED;
  1915. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  1916. } else if (linitcmd || linkcmd == QLOGIC_IB_IBCC_LINKCMD_DOWN) {
  1917. /*
  1918. * Any other linkinitcmd will lead to LINKDOWN and then
  1919. * to INIT (if all is well), so clear flag to let
  1920. * link-recovery code attempt to bring us back up.
  1921. */
  1922. spin_lock_irqsave(&ppd->lflags_lock, flags);
  1923. ppd->lflags &= ~QIBL_IB_LINK_DISABLED;
  1924. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  1925. /*
  1926. * Clear status change interrupt reduction so the
  1927. * new state is seen.
  1928. */
  1929. ppd->cpspec->ibcctrl_a &=
  1930. ~SYM_MASK(IBCCtrlA_0, IBStatIntReductionEn);
  1931. }
  1932. mod_wd = (linkcmd << IBA7322_IBCC_LINKCMD_SHIFT) |
  1933. (linitcmd << QLOGIC_IB_IBCC_LINKINITCMD_SHIFT);
  1934. qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a |
  1935. mod_wd);
  1936. /* write to chip to prevent back-to-back writes of ibc reg */
  1937. qib_write_kreg(dd, kr_scratch, 0);
  1938. }
  1939. /*
  1940. * The total RCV buffer memory is 64KB, used for both ports, and is
  1941. * in units of 64 bytes (same as IB flow control credit unit).
  1942. * The consumedVL unit in the same registers are in 32 byte units!
  1943. * So, a VL15 packet needs 4.50 IB credits, and 9 rx buffer chunks,
  1944. * and we can therefore allocate just 9 IB credits for 2 VL15 packets
  1945. * in krp_rxcreditvl15, rather than 10.
  1946. */
  1947. #define RCV_BUF_UNITSZ 64
  1948. #define NUM_RCV_BUF_UNITS(dd) ((64 * 1024) / (RCV_BUF_UNITSZ * dd->num_pports))
  1949. static void set_vls(struct qib_pportdata *ppd)
  1950. {
  1951. int i, numvls, totcred, cred_vl, vl0extra;
  1952. struct qib_devdata *dd = ppd->dd;
  1953. u64 val;
  1954. numvls = qib_num_vls(ppd->vls_operational);
  1955. /*
  1956. * Set up per-VL credits. Below is kluge based on these assumptions:
  1957. * 1) port is disabled at the time early_init is called.
  1958. * 2) give VL15 17 credits, for two max-plausible packets.
  1959. * 3) Give VL0-N the rest, with any rounding excess used for VL0
  1960. */
  1961. /* 2 VL15 packets @ 288 bytes each (including IB headers) */
  1962. totcred = NUM_RCV_BUF_UNITS(dd);
  1963. cred_vl = (2 * 288 + RCV_BUF_UNITSZ - 1) / RCV_BUF_UNITSZ;
  1964. totcred -= cred_vl;
  1965. qib_write_kreg_port(ppd, krp_rxcreditvl15, (u64) cred_vl);
  1966. cred_vl = totcred / numvls;
  1967. vl0extra = totcred - cred_vl * numvls;
  1968. qib_write_kreg_port(ppd, krp_rxcreditvl0, cred_vl + vl0extra);
  1969. for (i = 1; i < numvls; i++)
  1970. qib_write_kreg_port(ppd, krp_rxcreditvl0 + i, cred_vl);
  1971. for (; i < 8; i++) /* no buffer space for other VLs */
  1972. qib_write_kreg_port(ppd, krp_rxcreditvl0 + i, 0);
  1973. /* Notify IBC that credits need to be recalculated */
  1974. val = qib_read_kreg_port(ppd, krp_ibsdtestiftx);
  1975. val |= SYM_MASK(IB_SDTEST_IF_TX_0, CREDIT_CHANGE);
  1976. qib_write_kreg_port(ppd, krp_ibsdtestiftx, val);
  1977. qib_write_kreg(dd, kr_scratch, 0ULL);
  1978. val &= ~SYM_MASK(IB_SDTEST_IF_TX_0, CREDIT_CHANGE);
  1979. qib_write_kreg_port(ppd, krp_ibsdtestiftx, val);
  1980. for (i = 0; i < numvls; i++)
  1981. val = qib_read_kreg_port(ppd, krp_rxcreditvl0 + i);
  1982. val = qib_read_kreg_port(ppd, krp_rxcreditvl15);
  1983. /* Change the number of operational VLs */
  1984. ppd->cpspec->ibcctrl_a = (ppd->cpspec->ibcctrl_a &
  1985. ~SYM_MASK(IBCCtrlA_0, NumVLane)) |
  1986. ((u64)(numvls - 1) << SYM_LSB(IBCCtrlA_0, NumVLane));
  1987. qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
  1988. qib_write_kreg(dd, kr_scratch, 0ULL);
  1989. }
  1990. /*
  1991. * The code that deals with actual SerDes is in serdes_7322_init().
  1992. * Compared to the code for iba7220, it is minimal.
  1993. */
  1994. static int serdes_7322_init(struct qib_pportdata *ppd);
  1995. /**
  1996. * qib_7322_bringup_serdes - bring up the serdes
  1997. * @ppd: physical port on the qlogic_ib device
  1998. */
  1999. static int qib_7322_bringup_serdes(struct qib_pportdata *ppd)
  2000. {
  2001. struct qib_devdata *dd = ppd->dd;
  2002. u64 val, guid, ibc;
  2003. unsigned long flags;
  2004. int ret = 0;
  2005. /*
  2006. * SerDes model not in Pd, but still need to
  2007. * set up much of IBCCtrl and IBCDDRCtrl; move elsewhere
  2008. * eventually.
  2009. */
  2010. /* Put IBC in reset, sends disabled (should be in reset already) */
  2011. ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0, IBLinkEn);
  2012. qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
  2013. qib_write_kreg(dd, kr_scratch, 0ULL);
  2014. if (qib_compat_ddr_negotiate) {
  2015. ppd->cpspec->ibdeltainprog = 1;
  2016. ppd->cpspec->ibsymsnap = read_7322_creg32_port(ppd,
  2017. crp_ibsymbolerr);
  2018. ppd->cpspec->iblnkerrsnap = read_7322_creg32_port(ppd,
  2019. crp_iblinkerrrecov);
  2020. }
  2021. /* flowcontrolwatermark is in units of KBytes */
  2022. ibc = 0x5ULL << SYM_LSB(IBCCtrlA_0, FlowCtrlWaterMark);
  2023. /*
  2024. * Flow control is sent this often, even if no changes in
  2025. * buffer space occur. Units are 128ns for this chip.
  2026. * Set to 3usec.
  2027. */
  2028. ibc |= 24ULL << SYM_LSB(IBCCtrlA_0, FlowCtrlPeriod);
  2029. /* max error tolerance */
  2030. ibc |= 0xfULL << SYM_LSB(IBCCtrlA_0, PhyerrThreshold);
  2031. /* IB credit flow control. */
  2032. ibc |= 0xfULL << SYM_LSB(IBCCtrlA_0, OverrunThreshold);
  2033. /*
  2034. * set initial max size pkt IBC will send, including ICRC; it's the
  2035. * PIO buffer size in dwords, less 1; also see qib_set_mtu()
  2036. */
  2037. ibc |= ((u64)(ppd->ibmaxlen >> 2) + 1) <<
  2038. SYM_LSB(IBCCtrlA_0, MaxPktLen);
  2039. ppd->cpspec->ibcctrl_a = ibc; /* without linkcmd or linkinitcmd! */
  2040. /* initially come up waiting for TS1, without sending anything. */
  2041. val = ppd->cpspec->ibcctrl_a | (QLOGIC_IB_IBCC_LINKINITCMD_DISABLE <<
  2042. QLOGIC_IB_IBCC_LINKINITCMD_SHIFT);
  2043. /*
  2044. * Reset the PCS interface to the serdes (and also ibc, which is still
  2045. * in reset from above). Writes new value of ibcctrl_a as last step.
  2046. */
  2047. qib_7322_mini_pcs_reset(ppd);
  2048. qib_write_kreg(dd, kr_scratch, 0ULL);
  2049. if (!ppd->cpspec->ibcctrl_b) {
  2050. unsigned lse = ppd->link_speed_enabled;
  2051. /*
  2052. * Not on re-init after reset, establish shadow
  2053. * and force initial config.
  2054. */
  2055. ppd->cpspec->ibcctrl_b = qib_read_kreg_port(ppd,
  2056. krp_ibcctrl_b);
  2057. ppd->cpspec->ibcctrl_b &= ~(IBA7322_IBC_SPEED_QDR |
  2058. IBA7322_IBC_SPEED_DDR |
  2059. IBA7322_IBC_SPEED_SDR |
  2060. IBA7322_IBC_WIDTH_AUTONEG |
  2061. SYM_MASK(IBCCtrlB_0, IB_LANE_REV_SUPPORTED));
  2062. if (lse & (lse - 1)) /* Muliple speeds enabled */
  2063. ppd->cpspec->ibcctrl_b |=
  2064. (lse << IBA7322_IBC_SPEED_LSB) |
  2065. IBA7322_IBC_IBTA_1_2_MASK |
  2066. IBA7322_IBC_MAX_SPEED_MASK;
  2067. else
  2068. ppd->cpspec->ibcctrl_b |= (lse == QIB_IB_QDR) ?
  2069. IBA7322_IBC_SPEED_QDR |
  2070. IBA7322_IBC_IBTA_1_2_MASK :
  2071. (lse == QIB_IB_DDR) ?
  2072. IBA7322_IBC_SPEED_DDR :
  2073. IBA7322_IBC_SPEED_SDR;
  2074. if ((ppd->link_width_enabled & (IB_WIDTH_1X | IB_WIDTH_4X)) ==
  2075. (IB_WIDTH_1X | IB_WIDTH_4X))
  2076. ppd->cpspec->ibcctrl_b |= IBA7322_IBC_WIDTH_AUTONEG;
  2077. else
  2078. ppd->cpspec->ibcctrl_b |=
  2079. ppd->link_width_enabled == IB_WIDTH_4X ?
  2080. IBA7322_IBC_WIDTH_4X_ONLY :
  2081. IBA7322_IBC_WIDTH_1X_ONLY;
  2082. /* always enable these on driver reload, not sticky */
  2083. ppd->cpspec->ibcctrl_b |= (IBA7322_IBC_RXPOL_MASK |
  2084. IBA7322_IBC_HRTBT_MASK);
  2085. }
  2086. qib_write_kreg_port(ppd, krp_ibcctrl_b, ppd->cpspec->ibcctrl_b);
  2087. /* setup so we have more time at CFGTEST to change H1 */
  2088. val = qib_read_kreg_port(ppd, krp_ibcctrl_c);
  2089. val &= ~SYM_MASK(IBCCtrlC_0, IB_FRONT_PORCH);
  2090. val |= 0xfULL << SYM_LSB(IBCCtrlC_0, IB_FRONT_PORCH);
  2091. qib_write_kreg_port(ppd, krp_ibcctrl_c, val);
  2092. serdes_7322_init(ppd);
  2093. guid = be64_to_cpu(ppd->guid);
  2094. if (!guid) {
  2095. if (dd->base_guid)
  2096. guid = be64_to_cpu(dd->base_guid) + ppd->port - 1;
  2097. ppd->guid = cpu_to_be64(guid);
  2098. }
  2099. qib_write_kreg_port(ppd, krp_hrtbt_guid, guid);
  2100. /* write to chip to prevent back-to-back writes of ibc reg */
  2101. qib_write_kreg(dd, kr_scratch, 0);
  2102. /* Enable port */
  2103. ppd->cpspec->ibcctrl_a |= SYM_MASK(IBCCtrlA_0, IBLinkEn);
  2104. set_vls(ppd);
  2105. /* be paranoid against later code motion, etc. */
  2106. spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
  2107. ppd->p_rcvctrl |= SYM_MASK(RcvCtrl_0, RcvIBPortEnable);
  2108. qib_write_kreg_port(ppd, krp_rcvctrl, ppd->p_rcvctrl);
  2109. spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
  2110. /* Hold the link state machine for mezz boards */
  2111. if (IS_QMH(dd) || IS_QME(dd))
  2112. qib_set_ib_7322_lstate(ppd, 0,
  2113. QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
  2114. /* Also enable IBSTATUSCHG interrupt. */
  2115. val = qib_read_kreg_port(ppd, krp_errmask);
  2116. qib_write_kreg_port(ppd, krp_errmask,
  2117. val | ERR_MASK_N(IBStatusChanged));
  2118. /* Always zero until we start messing with SerDes for real */
  2119. return ret;
  2120. }
  2121. /**
  2122. * qib_7322_quiet_serdes - set serdes to txidle
  2123. * @dd: the qlogic_ib device
  2124. * Called when driver is being unloaded
  2125. */
  2126. static void qib_7322_mini_quiet_serdes(struct qib_pportdata *ppd)
  2127. {
  2128. u64 val;
  2129. unsigned long flags;
  2130. qib_set_ib_7322_lstate(ppd, 0, QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
  2131. spin_lock_irqsave(&ppd->lflags_lock, flags);
  2132. ppd->lflags &= ~QIBL_IB_AUTONEG_INPROG;
  2133. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  2134. wake_up(&ppd->cpspec->autoneg_wait);
  2135. cancel_delayed_work_sync(&ppd->cpspec->autoneg_work);
  2136. if (ppd->dd->cspec->r1)
  2137. cancel_delayed_work_sync(&ppd->cpspec->ipg_work);
  2138. ppd->cpspec->chase_end = 0;
  2139. if (ppd->cpspec->chase_timer.data) /* if initted */
  2140. del_timer_sync(&ppd->cpspec->chase_timer);
  2141. /*
  2142. * Despite the name, actually disables IBC as well. Do it when
  2143. * we are as sure as possible that no more packets can be
  2144. * received, following the down and the PCS reset.
  2145. * The actual disabling happens in qib_7322_mini_pci_reset(),
  2146. * along with the PCS being reset.
  2147. */
  2148. ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0, IBLinkEn);
  2149. qib_7322_mini_pcs_reset(ppd);
  2150. /*
  2151. * Update the adjusted counters so the adjustment persists
  2152. * across driver reload.
  2153. */
  2154. if (ppd->cpspec->ibsymdelta || ppd->cpspec->iblnkerrdelta ||
  2155. ppd->cpspec->ibdeltainprog || ppd->cpspec->iblnkdowndelta) {
  2156. struct qib_devdata *dd = ppd->dd;
  2157. u64 diagc;
  2158. /* enable counter writes */
  2159. diagc = qib_read_kreg64(dd, kr_hwdiagctrl);
  2160. qib_write_kreg(dd, kr_hwdiagctrl,
  2161. diagc | SYM_MASK(HwDiagCtrl, CounterWrEnable));
  2162. if (ppd->cpspec->ibsymdelta || ppd->cpspec->ibdeltainprog) {
  2163. val = read_7322_creg32_port(ppd, crp_ibsymbolerr);
  2164. if (ppd->cpspec->ibdeltainprog)
  2165. val -= val - ppd->cpspec->ibsymsnap;
  2166. val -= ppd->cpspec->ibsymdelta;
  2167. write_7322_creg_port(ppd, crp_ibsymbolerr, val);
  2168. }
  2169. if (ppd->cpspec->iblnkerrdelta || ppd->cpspec->ibdeltainprog) {
  2170. val = read_7322_creg32_port(ppd, crp_iblinkerrrecov);
  2171. if (ppd->cpspec->ibdeltainprog)
  2172. val -= val - ppd->cpspec->iblnkerrsnap;
  2173. val -= ppd->cpspec->iblnkerrdelta;
  2174. write_7322_creg_port(ppd, crp_iblinkerrrecov, val);
  2175. }
  2176. if (ppd->cpspec->iblnkdowndelta) {
  2177. val = read_7322_creg32_port(ppd, crp_iblinkdown);
  2178. val += ppd->cpspec->iblnkdowndelta;
  2179. write_7322_creg_port(ppd, crp_iblinkdown, val);
  2180. }
  2181. /*
  2182. * No need to save ibmalfdelta since IB perfcounters
  2183. * are cleared on driver reload.
  2184. */
  2185. /* and disable counter writes */
  2186. qib_write_kreg(dd, kr_hwdiagctrl, diagc);
  2187. }
  2188. }
  2189. /**
  2190. * qib_setup_7322_setextled - set the state of the two external LEDs
  2191. * @ppd: physical port on the qlogic_ib device
  2192. * @on: whether the link is up or not
  2193. *
  2194. * The exact combo of LEDs if on is true is determined by looking
  2195. * at the ibcstatus.
  2196. *
  2197. * These LEDs indicate the physical and logical state of IB link.
  2198. * For this chip (at least with recommended board pinouts), LED1
  2199. * is Yellow (logical state) and LED2 is Green (physical state),
  2200. *
  2201. * Note: We try to match the Mellanox HCA LED behavior as best
  2202. * we can. Green indicates physical link state is OK (something is
  2203. * plugged in, and we can train).
  2204. * Amber indicates the link is logically up (ACTIVE).
  2205. * Mellanox further blinks the amber LED to indicate data packet
  2206. * activity, but we have no hardware support for that, so it would
  2207. * require waking up every 10-20 msecs and checking the counters
  2208. * on the chip, and then turning the LED off if appropriate. That's
  2209. * visible overhead, so not something we will do.
  2210. */
  2211. static void qib_setup_7322_setextled(struct qib_pportdata *ppd, u32 on)
  2212. {
  2213. struct qib_devdata *dd = ppd->dd;
  2214. u64 extctl, ledblink = 0, val;
  2215. unsigned long flags;
  2216. int yel, grn;
  2217. /*
  2218. * The diags use the LED to indicate diag info, so we leave
  2219. * the external LED alone when the diags are running.
  2220. */
  2221. if (dd->diag_client)
  2222. return;
  2223. /* Allow override of LED display for, e.g. Locating system in rack */
  2224. if (ppd->led_override) {
  2225. grn = (ppd->led_override & QIB_LED_PHYS);
  2226. yel = (ppd->led_override & QIB_LED_LOG);
  2227. } else if (on) {
  2228. val = qib_read_kreg_port(ppd, krp_ibcstatus_a);
  2229. grn = qib_7322_phys_portstate(val) ==
  2230. IB_PHYSPORTSTATE_LINKUP;
  2231. yel = qib_7322_iblink_state(val) == IB_PORT_ACTIVE;
  2232. } else {
  2233. grn = 0;
  2234. yel = 0;
  2235. }
  2236. spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
  2237. extctl = dd->cspec->extctrl & (ppd->port == 1 ?
  2238. ~ExtLED_IB1_MASK : ~ExtLED_IB2_MASK);
  2239. if (grn) {
  2240. extctl |= ppd->port == 1 ? ExtLED_IB1_GRN : ExtLED_IB2_GRN;
  2241. /*
  2242. * Counts are in chip clock (4ns) periods.
  2243. * This is 1/16 sec (66.6ms) on,
  2244. * 3/16 sec (187.5 ms) off, with packets rcvd.
  2245. */
  2246. ledblink = ((66600 * 1000UL / 4) << IBA7322_LEDBLINK_ON_SHIFT) |
  2247. ((187500 * 1000UL / 4) << IBA7322_LEDBLINK_OFF_SHIFT);
  2248. }
  2249. if (yel)
  2250. extctl |= ppd->port == 1 ? ExtLED_IB1_YEL : ExtLED_IB2_YEL;
  2251. dd->cspec->extctrl = extctl;
  2252. qib_write_kreg(dd, kr_extctrl, dd->cspec->extctrl);
  2253. spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
  2254. if (ledblink) /* blink the LED on packet receive */
  2255. qib_write_kreg_port(ppd, krp_rcvpktledcnt, ledblink);
  2256. }
  2257. /*
  2258. * Disable MSIx interrupt if enabled, call generic MSIx code
  2259. * to cleanup, and clear pending MSIx interrupts.
  2260. * Used for fallback to INTx, after reset, and when MSIx setup fails.
  2261. */
  2262. static void qib_7322_nomsix(struct qib_devdata *dd)
  2263. {
  2264. u64 intgranted;
  2265. int n;
  2266. dd->cspec->main_int_mask = ~0ULL;
  2267. n = dd->cspec->num_msix_entries;
  2268. if (n) {
  2269. int i;
  2270. dd->cspec->num_msix_entries = 0;
  2271. for (i = 0; i < n; i++)
  2272. free_irq(dd->cspec->msix_entries[i].vector,
  2273. dd->cspec->msix_arg[i]);
  2274. qib_nomsix(dd);
  2275. }
  2276. /* make sure no MSIx interrupts are left pending */
  2277. intgranted = qib_read_kreg64(dd, kr_intgranted);
  2278. if (intgranted)
  2279. qib_write_kreg(dd, kr_intgranted, intgranted);
  2280. }
  2281. static void qib_7322_free_irq(struct qib_devdata *dd)
  2282. {
  2283. if (dd->cspec->irq) {
  2284. free_irq(dd->cspec->irq, dd);
  2285. dd->cspec->irq = 0;
  2286. }
  2287. qib_7322_nomsix(dd);
  2288. }
  2289. static void qib_setup_7322_cleanup(struct qib_devdata *dd)
  2290. {
  2291. int i;
  2292. qib_7322_free_irq(dd);
  2293. kfree(dd->cspec->cntrs);
  2294. kfree(dd->cspec->sendchkenable);
  2295. kfree(dd->cspec->sendgrhchk);
  2296. kfree(dd->cspec->sendibchk);
  2297. kfree(dd->cspec->msix_entries);
  2298. kfree(dd->cspec->msix_arg);
  2299. for (i = 0; i < dd->num_pports; i++) {
  2300. unsigned long flags;
  2301. u32 mask = QSFP_GPIO_MOD_PRS_N |
  2302. (QSFP_GPIO_MOD_PRS_N << QSFP_GPIO_PORT2_SHIFT);
  2303. kfree(dd->pport[i].cpspec->portcntrs);
  2304. if (dd->flags & QIB_HAS_QSFP) {
  2305. spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
  2306. dd->cspec->gpio_mask &= ~mask;
  2307. qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
  2308. spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
  2309. qib_qsfp_deinit(&dd->pport[i].cpspec->qsfp_data);
  2310. }
  2311. if (dd->pport[i].ibport_data.smi_ah)
  2312. ib_destroy_ah(&dd->pport[i].ibport_data.smi_ah->ibah);
  2313. }
  2314. }
  2315. /* handle SDMA interrupts */
  2316. static void sdma_7322_intr(struct qib_devdata *dd, u64 istat)
  2317. {
  2318. struct qib_pportdata *ppd0 = &dd->pport[0];
  2319. struct qib_pportdata *ppd1 = &dd->pport[1];
  2320. u64 intr0 = istat & (INT_MASK_P(SDma, 0) |
  2321. INT_MASK_P(SDmaIdle, 0) | INT_MASK_P(SDmaProgress, 0));
  2322. u64 intr1 = istat & (INT_MASK_P(SDma, 1) |
  2323. INT_MASK_P(SDmaIdle, 1) | INT_MASK_P(SDmaProgress, 1));
  2324. if (intr0)
  2325. qib_sdma_intr(ppd0);
  2326. if (intr1)
  2327. qib_sdma_intr(ppd1);
  2328. if (istat & INT_MASK_PM(SDmaCleanupDone, 0))
  2329. qib_sdma_process_event(ppd0, qib_sdma_event_e20_hw_started);
  2330. if (istat & INT_MASK_PM(SDmaCleanupDone, 1))
  2331. qib_sdma_process_event(ppd1, qib_sdma_event_e20_hw_started);
  2332. }
  2333. /*
  2334. * Set or clear the Send buffer available interrupt enable bit.
  2335. */
  2336. static void qib_wantpiobuf_7322_intr(struct qib_devdata *dd, u32 needint)
  2337. {
  2338. unsigned long flags;
  2339. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  2340. if (needint)
  2341. dd->sendctrl |= SYM_MASK(SendCtrl, SendIntBufAvail);
  2342. else
  2343. dd->sendctrl &= ~SYM_MASK(SendCtrl, SendIntBufAvail);
  2344. qib_write_kreg(dd, kr_sendctrl, dd->sendctrl);
  2345. qib_write_kreg(dd, kr_scratch, 0ULL);
  2346. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  2347. }
  2348. /*
  2349. * Somehow got an interrupt with reserved bits set in interrupt status.
  2350. * Print a message so we know it happened, then clear them.
  2351. * keep mainline interrupt handler cache-friendly
  2352. */
  2353. static noinline void unknown_7322_ibits(struct qib_devdata *dd, u64 istat)
  2354. {
  2355. u64 kills;
  2356. char msg[128];
  2357. kills = istat & ~QIB_I_BITSEXTANT;
  2358. qib_dev_err(dd, "Clearing reserved interrupt(s) 0x%016llx:"
  2359. " %s\n", (unsigned long long) kills, msg);
  2360. qib_write_kreg(dd, kr_intmask, (dd->cspec->int_enable_mask & ~kills));
  2361. }
  2362. /* keep mainline interrupt handler cache-friendly */
  2363. static noinline void unknown_7322_gpio_intr(struct qib_devdata *dd)
  2364. {
  2365. u32 gpiostatus;
  2366. int handled = 0;
  2367. int pidx;
  2368. /*
  2369. * Boards for this chip currently don't use GPIO interrupts,
  2370. * so clear by writing GPIOstatus to GPIOclear, and complain
  2371. * to developer. To avoid endless repeats, clear
  2372. * the bits in the mask, since there is some kind of
  2373. * programming error or chip problem.
  2374. */
  2375. gpiostatus = qib_read_kreg32(dd, kr_gpio_status);
  2376. /*
  2377. * In theory, writing GPIOstatus to GPIOclear could
  2378. * have a bad side-effect on some diagnostic that wanted
  2379. * to poll for a status-change, but the various shadows
  2380. * make that problematic at best. Diags will just suppress
  2381. * all GPIO interrupts during such tests.
  2382. */
  2383. qib_write_kreg(dd, kr_gpio_clear, gpiostatus);
  2384. /*
  2385. * Check for QSFP MOD_PRS changes
  2386. * only works for single port if IB1 != pidx1
  2387. */
  2388. for (pidx = 0; pidx < dd->num_pports && (dd->flags & QIB_HAS_QSFP);
  2389. ++pidx) {
  2390. struct qib_pportdata *ppd;
  2391. struct qib_qsfp_data *qd;
  2392. u32 mask;
  2393. if (!dd->pport[pidx].link_speed_supported)
  2394. continue;
  2395. mask = QSFP_GPIO_MOD_PRS_N;
  2396. ppd = dd->pport + pidx;
  2397. mask <<= (QSFP_GPIO_PORT2_SHIFT * ppd->hw_pidx);
  2398. if (gpiostatus & dd->cspec->gpio_mask & mask) {
  2399. u64 pins;
  2400. qd = &ppd->cpspec->qsfp_data;
  2401. gpiostatus &= ~mask;
  2402. pins = qib_read_kreg64(dd, kr_extstatus);
  2403. pins >>= SYM_LSB(EXTStatus, GPIOIn);
  2404. if (!(pins & mask)) {
  2405. ++handled;
  2406. qd->t_insert = get_jiffies_64();
  2407. queue_work(ib_wq, &qd->work);
  2408. }
  2409. }
  2410. }
  2411. if (gpiostatus && !handled) {
  2412. const u32 mask = qib_read_kreg32(dd, kr_gpio_mask);
  2413. u32 gpio_irq = mask & gpiostatus;
  2414. /*
  2415. * Clear any troublemakers, and update chip from shadow
  2416. */
  2417. dd->cspec->gpio_mask &= ~gpio_irq;
  2418. qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
  2419. }
  2420. }
  2421. /*
  2422. * Handle errors and unusual events first, separate function
  2423. * to improve cache hits for fast path interrupt handling.
  2424. */
  2425. static noinline void unlikely_7322_intr(struct qib_devdata *dd, u64 istat)
  2426. {
  2427. if (istat & ~QIB_I_BITSEXTANT)
  2428. unknown_7322_ibits(dd, istat);
  2429. if (istat & QIB_I_GPIO)
  2430. unknown_7322_gpio_intr(dd);
  2431. if (istat & QIB_I_C_ERROR)
  2432. handle_7322_errors(dd);
  2433. if (istat & INT_MASK_P(Err, 0) && dd->rcd[0])
  2434. handle_7322_p_errors(dd->rcd[0]->ppd);
  2435. if (istat & INT_MASK_P(Err, 1) && dd->rcd[1])
  2436. handle_7322_p_errors(dd->rcd[1]->ppd);
  2437. }
  2438. /*
  2439. * Dynamically adjust the rcv int timeout for a context based on incoming
  2440. * packet rate.
  2441. */
  2442. static void adjust_rcv_timeout(struct qib_ctxtdata *rcd, int npkts)
  2443. {
  2444. struct qib_devdata *dd = rcd->dd;
  2445. u32 timeout = dd->cspec->rcvavail_timeout[rcd->ctxt];
  2446. /*
  2447. * Dynamically adjust idle timeout on chip
  2448. * based on number of packets processed.
  2449. */
  2450. if (npkts < rcv_int_count && timeout > 2)
  2451. timeout >>= 1;
  2452. else if (npkts >= rcv_int_count && timeout < rcv_int_timeout)
  2453. timeout = min(timeout << 1, rcv_int_timeout);
  2454. else
  2455. return;
  2456. dd->cspec->rcvavail_timeout[rcd->ctxt] = timeout;
  2457. qib_write_kreg(dd, kr_rcvavailtimeout + rcd->ctxt, timeout);
  2458. }
  2459. /*
  2460. * This is the main interrupt handler.
  2461. * It will normally only be used for low frequency interrupts but may
  2462. * have to handle all interrupts if INTx is enabled or fewer than normal
  2463. * MSIx interrupts were allocated.
  2464. * This routine should ignore the interrupt bits for any of the
  2465. * dedicated MSIx handlers.
  2466. */
  2467. static irqreturn_t qib_7322intr(int irq, void *data)
  2468. {
  2469. struct qib_devdata *dd = data;
  2470. irqreturn_t ret;
  2471. u64 istat;
  2472. u64 ctxtrbits;
  2473. u64 rmask;
  2474. unsigned i;
  2475. u32 npkts;
  2476. if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT) {
  2477. /*
  2478. * This return value is not great, but we do not want the
  2479. * interrupt core code to remove our interrupt handler
  2480. * because we don't appear to be handling an interrupt
  2481. * during a chip reset.
  2482. */
  2483. ret = IRQ_HANDLED;
  2484. goto bail;
  2485. }
  2486. istat = qib_read_kreg64(dd, kr_intstatus);
  2487. if (unlikely(istat == ~0ULL)) {
  2488. qib_bad_intrstatus(dd);
  2489. qib_dev_err(dd, "Interrupt status all f's, skipping\n");
  2490. /* don't know if it was our interrupt or not */
  2491. ret = IRQ_NONE;
  2492. goto bail;
  2493. }
  2494. istat &= dd->cspec->main_int_mask;
  2495. if (unlikely(!istat)) {
  2496. /* already handled, or shared and not us */
  2497. ret = IRQ_NONE;
  2498. goto bail;
  2499. }
  2500. qib_stats.sps_ints++;
  2501. if (dd->int_counter != (u32) -1)
  2502. dd->int_counter++;
  2503. /* handle "errors" of various kinds first, device ahead of port */
  2504. if (unlikely(istat & (~QIB_I_BITSEXTANT | QIB_I_GPIO |
  2505. QIB_I_C_ERROR | INT_MASK_P(Err, 0) |
  2506. INT_MASK_P(Err, 1))))
  2507. unlikely_7322_intr(dd, istat);
  2508. /*
  2509. * Clear the interrupt bits we found set, relatively early, so we
  2510. * "know" know the chip will have seen this by the time we process
  2511. * the queue, and will re-interrupt if necessary. The processor
  2512. * itself won't take the interrupt again until we return.
  2513. */
  2514. qib_write_kreg(dd, kr_intclear, istat);
  2515. /*
  2516. * Handle kernel receive queues before checking for pio buffers
  2517. * available since receives can overflow; piobuf waiters can afford
  2518. * a few extra cycles, since they were waiting anyway.
  2519. */
  2520. ctxtrbits = istat & (QIB_I_RCVAVAIL_MASK | QIB_I_RCVURG_MASK);
  2521. if (ctxtrbits) {
  2522. rmask = (1ULL << QIB_I_RCVAVAIL_LSB) |
  2523. (1ULL << QIB_I_RCVURG_LSB);
  2524. for (i = 0; i < dd->first_user_ctxt; i++) {
  2525. if (ctxtrbits & rmask) {
  2526. ctxtrbits &= ~rmask;
  2527. if (dd->rcd[i]) {
  2528. qib_kreceive(dd->rcd[i], NULL, &npkts);
  2529. }
  2530. }
  2531. rmask <<= 1;
  2532. }
  2533. if (ctxtrbits) {
  2534. ctxtrbits = (ctxtrbits >> QIB_I_RCVAVAIL_LSB) |
  2535. (ctxtrbits >> QIB_I_RCVURG_LSB);
  2536. qib_handle_urcv(dd, ctxtrbits);
  2537. }
  2538. }
  2539. if (istat & (QIB_I_P_SDMAINT(0) | QIB_I_P_SDMAINT(1)))
  2540. sdma_7322_intr(dd, istat);
  2541. if ((istat & QIB_I_SPIOBUFAVAIL) && (dd->flags & QIB_INITTED))
  2542. qib_ib_piobufavail(dd);
  2543. ret = IRQ_HANDLED;
  2544. bail:
  2545. return ret;
  2546. }
  2547. /*
  2548. * Dedicated receive packet available interrupt handler.
  2549. */
  2550. static irqreturn_t qib_7322pintr(int irq, void *data)
  2551. {
  2552. struct qib_ctxtdata *rcd = data;
  2553. struct qib_devdata *dd = rcd->dd;
  2554. u32 npkts;
  2555. if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
  2556. /*
  2557. * This return value is not great, but we do not want the
  2558. * interrupt core code to remove our interrupt handler
  2559. * because we don't appear to be handling an interrupt
  2560. * during a chip reset.
  2561. */
  2562. return IRQ_HANDLED;
  2563. qib_stats.sps_ints++;
  2564. if (dd->int_counter != (u32) -1)
  2565. dd->int_counter++;
  2566. /* Clear the interrupt bit we expect to be set. */
  2567. qib_write_kreg(dd, kr_intclear, ((1ULL << QIB_I_RCVAVAIL_LSB) |
  2568. (1ULL << QIB_I_RCVURG_LSB)) << rcd->ctxt);
  2569. qib_kreceive(rcd, NULL, &npkts);
  2570. return IRQ_HANDLED;
  2571. }
  2572. /*
  2573. * Dedicated Send buffer available interrupt handler.
  2574. */
  2575. static irqreturn_t qib_7322bufavail(int irq, void *data)
  2576. {
  2577. struct qib_devdata *dd = data;
  2578. if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
  2579. /*
  2580. * This return value is not great, but we do not want the
  2581. * interrupt core code to remove our interrupt handler
  2582. * because we don't appear to be handling an interrupt
  2583. * during a chip reset.
  2584. */
  2585. return IRQ_HANDLED;
  2586. qib_stats.sps_ints++;
  2587. if (dd->int_counter != (u32) -1)
  2588. dd->int_counter++;
  2589. /* Clear the interrupt bit we expect to be set. */
  2590. qib_write_kreg(dd, kr_intclear, QIB_I_SPIOBUFAVAIL);
  2591. /* qib_ib_piobufavail() will clear the want PIO interrupt if needed */
  2592. if (dd->flags & QIB_INITTED)
  2593. qib_ib_piobufavail(dd);
  2594. else
  2595. qib_wantpiobuf_7322_intr(dd, 0);
  2596. return IRQ_HANDLED;
  2597. }
  2598. /*
  2599. * Dedicated Send DMA interrupt handler.
  2600. */
  2601. static irqreturn_t sdma_intr(int irq, void *data)
  2602. {
  2603. struct qib_pportdata *ppd = data;
  2604. struct qib_devdata *dd = ppd->dd;
  2605. if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
  2606. /*
  2607. * This return value is not great, but we do not want the
  2608. * interrupt core code to remove our interrupt handler
  2609. * because we don't appear to be handling an interrupt
  2610. * during a chip reset.
  2611. */
  2612. return IRQ_HANDLED;
  2613. qib_stats.sps_ints++;
  2614. if (dd->int_counter != (u32) -1)
  2615. dd->int_counter++;
  2616. /* Clear the interrupt bit we expect to be set. */
  2617. qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
  2618. INT_MASK_P(SDma, 1) : INT_MASK_P(SDma, 0));
  2619. qib_sdma_intr(ppd);
  2620. return IRQ_HANDLED;
  2621. }
  2622. /*
  2623. * Dedicated Send DMA idle interrupt handler.
  2624. */
  2625. static irqreturn_t sdma_idle_intr(int irq, void *data)
  2626. {
  2627. struct qib_pportdata *ppd = data;
  2628. struct qib_devdata *dd = ppd->dd;
  2629. if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
  2630. /*
  2631. * This return value is not great, but we do not want the
  2632. * interrupt core code to remove our interrupt handler
  2633. * because we don't appear to be handling an interrupt
  2634. * during a chip reset.
  2635. */
  2636. return IRQ_HANDLED;
  2637. qib_stats.sps_ints++;
  2638. if (dd->int_counter != (u32) -1)
  2639. dd->int_counter++;
  2640. /* Clear the interrupt bit we expect to be set. */
  2641. qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
  2642. INT_MASK_P(SDmaIdle, 1) : INT_MASK_P(SDmaIdle, 0));
  2643. qib_sdma_intr(ppd);
  2644. return IRQ_HANDLED;
  2645. }
  2646. /*
  2647. * Dedicated Send DMA progress interrupt handler.
  2648. */
  2649. static irqreturn_t sdma_progress_intr(int irq, void *data)
  2650. {
  2651. struct qib_pportdata *ppd = data;
  2652. struct qib_devdata *dd = ppd->dd;
  2653. if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
  2654. /*
  2655. * This return value is not great, but we do not want the
  2656. * interrupt core code to remove our interrupt handler
  2657. * because we don't appear to be handling an interrupt
  2658. * during a chip reset.
  2659. */
  2660. return IRQ_HANDLED;
  2661. qib_stats.sps_ints++;
  2662. if (dd->int_counter != (u32) -1)
  2663. dd->int_counter++;
  2664. /* Clear the interrupt bit we expect to be set. */
  2665. qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
  2666. INT_MASK_P(SDmaProgress, 1) :
  2667. INT_MASK_P(SDmaProgress, 0));
  2668. qib_sdma_intr(ppd);
  2669. return IRQ_HANDLED;
  2670. }
  2671. /*
  2672. * Dedicated Send DMA cleanup interrupt handler.
  2673. */
  2674. static irqreturn_t sdma_cleanup_intr(int irq, void *data)
  2675. {
  2676. struct qib_pportdata *ppd = data;
  2677. struct qib_devdata *dd = ppd->dd;
  2678. if ((dd->flags & (QIB_PRESENT | QIB_BADINTR)) != QIB_PRESENT)
  2679. /*
  2680. * This return value is not great, but we do not want the
  2681. * interrupt core code to remove our interrupt handler
  2682. * because we don't appear to be handling an interrupt
  2683. * during a chip reset.
  2684. */
  2685. return IRQ_HANDLED;
  2686. qib_stats.sps_ints++;
  2687. if (dd->int_counter != (u32) -1)
  2688. dd->int_counter++;
  2689. /* Clear the interrupt bit we expect to be set. */
  2690. qib_write_kreg(dd, kr_intclear, ppd->hw_pidx ?
  2691. INT_MASK_PM(SDmaCleanupDone, 1) :
  2692. INT_MASK_PM(SDmaCleanupDone, 0));
  2693. qib_sdma_process_event(ppd, qib_sdma_event_e20_hw_started);
  2694. return IRQ_HANDLED;
  2695. }
  2696. /*
  2697. * Set up our chip-specific interrupt handler.
  2698. * The interrupt type has already been setup, so
  2699. * we just need to do the registration and error checking.
  2700. * If we are using MSIx interrupts, we may fall back to
  2701. * INTx later, if the interrupt handler doesn't get called
  2702. * within 1/2 second (see verify_interrupt()).
  2703. */
  2704. static void qib_setup_7322_interrupt(struct qib_devdata *dd, int clearpend)
  2705. {
  2706. int ret, i, msixnum;
  2707. u64 redirect[6];
  2708. u64 mask;
  2709. if (!dd->num_pports)
  2710. return;
  2711. if (clearpend) {
  2712. /*
  2713. * if not switching interrupt types, be sure interrupts are
  2714. * disabled, and then clear anything pending at this point,
  2715. * because we are starting clean.
  2716. */
  2717. qib_7322_set_intr_state(dd, 0);
  2718. /* clear the reset error, init error/hwerror mask */
  2719. qib_7322_init_hwerrors(dd);
  2720. /* clear any interrupt bits that might be set */
  2721. qib_write_kreg(dd, kr_intclear, ~0ULL);
  2722. /* make sure no pending MSIx intr, and clear diag reg */
  2723. qib_write_kreg(dd, kr_intgranted, ~0ULL);
  2724. qib_write_kreg(dd, kr_vecclr_wo_int, ~0ULL);
  2725. }
  2726. if (!dd->cspec->num_msix_entries) {
  2727. /* Try to get INTx interrupt */
  2728. try_intx:
  2729. if (!dd->pcidev->irq) {
  2730. qib_dev_err(dd, "irq is 0, BIOS error? "
  2731. "Interrupts won't work\n");
  2732. goto bail;
  2733. }
  2734. ret = request_irq(dd->pcidev->irq, qib_7322intr,
  2735. IRQF_SHARED, QIB_DRV_NAME, dd);
  2736. if (ret) {
  2737. qib_dev_err(dd, "Couldn't setup INTx "
  2738. "interrupt (irq=%d): %d\n",
  2739. dd->pcidev->irq, ret);
  2740. goto bail;
  2741. }
  2742. dd->cspec->irq = dd->pcidev->irq;
  2743. dd->cspec->main_int_mask = ~0ULL;
  2744. goto bail;
  2745. }
  2746. /* Try to get MSIx interrupts */
  2747. memset(redirect, 0, sizeof redirect);
  2748. mask = ~0ULL;
  2749. msixnum = 0;
  2750. for (i = 0; msixnum < dd->cspec->num_msix_entries; i++) {
  2751. irq_handler_t handler;
  2752. const char *name;
  2753. void *arg;
  2754. u64 val;
  2755. int lsb, reg, sh;
  2756. if (i < ARRAY_SIZE(irq_table)) {
  2757. if (irq_table[i].port) {
  2758. /* skip if for a non-configured port */
  2759. if (irq_table[i].port > dd->num_pports)
  2760. continue;
  2761. arg = dd->pport + irq_table[i].port - 1;
  2762. } else
  2763. arg = dd;
  2764. lsb = irq_table[i].lsb;
  2765. handler = irq_table[i].handler;
  2766. name = irq_table[i].name;
  2767. } else {
  2768. unsigned ctxt;
  2769. ctxt = i - ARRAY_SIZE(irq_table);
  2770. /* per krcvq context receive interrupt */
  2771. arg = dd->rcd[ctxt];
  2772. if (!arg)
  2773. continue;
  2774. lsb = QIB_I_RCVAVAIL_LSB + ctxt;
  2775. handler = qib_7322pintr;
  2776. name = QIB_DRV_NAME " (kctx)";
  2777. }
  2778. ret = request_irq(dd->cspec->msix_entries[msixnum].vector,
  2779. handler, 0, name, arg);
  2780. if (ret) {
  2781. /*
  2782. * Shouldn't happen since the enable said we could
  2783. * have as many as we are trying to setup here.
  2784. */
  2785. qib_dev_err(dd, "Couldn't setup MSIx "
  2786. "interrupt (vec=%d, irq=%d): %d\n", msixnum,
  2787. dd->cspec->msix_entries[msixnum].vector,
  2788. ret);
  2789. qib_7322_nomsix(dd);
  2790. goto try_intx;
  2791. }
  2792. dd->cspec->msix_arg[msixnum] = arg;
  2793. if (lsb >= 0) {
  2794. reg = lsb / IBA7322_REDIRECT_VEC_PER_REG;
  2795. sh = (lsb % IBA7322_REDIRECT_VEC_PER_REG) *
  2796. SYM_LSB(IntRedirect0, vec1);
  2797. mask &= ~(1ULL << lsb);
  2798. redirect[reg] |= ((u64) msixnum) << sh;
  2799. }
  2800. val = qib_read_kreg64(dd, 2 * msixnum + 1 +
  2801. (QIB_7322_MsixTable_OFFS / sizeof(u64)));
  2802. msixnum++;
  2803. }
  2804. /* Initialize the vector mapping */
  2805. for (i = 0; i < ARRAY_SIZE(redirect); i++)
  2806. qib_write_kreg(dd, kr_intredirect + i, redirect[i]);
  2807. dd->cspec->main_int_mask = mask;
  2808. bail:;
  2809. }
  2810. /**
  2811. * qib_7322_boardname - fill in the board name and note features
  2812. * @dd: the qlogic_ib device
  2813. *
  2814. * info will be based on the board revision register
  2815. */
  2816. static unsigned qib_7322_boardname(struct qib_devdata *dd)
  2817. {
  2818. /* Will need enumeration of board-types here */
  2819. char *n;
  2820. u32 boardid, namelen;
  2821. unsigned features = DUAL_PORT_CAP;
  2822. boardid = SYM_FIELD(dd->revision, Revision, BoardID);
  2823. switch (boardid) {
  2824. case 0:
  2825. n = "InfiniPath_QLE7342_Emulation";
  2826. break;
  2827. case 1:
  2828. n = "InfiniPath_QLE7340";
  2829. dd->flags |= QIB_HAS_QSFP;
  2830. features = PORT_SPD_CAP;
  2831. break;
  2832. case 2:
  2833. n = "InfiniPath_QLE7342";
  2834. dd->flags |= QIB_HAS_QSFP;
  2835. break;
  2836. case 3:
  2837. n = "InfiniPath_QMI7342";
  2838. break;
  2839. case 4:
  2840. n = "InfiniPath_Unsupported7342";
  2841. qib_dev_err(dd, "Unsupported version of QMH7342\n");
  2842. features = 0;
  2843. break;
  2844. case BOARD_QMH7342:
  2845. n = "InfiniPath_QMH7342";
  2846. features = 0x24;
  2847. break;
  2848. case BOARD_QME7342:
  2849. n = "InfiniPath_QME7342";
  2850. break;
  2851. case 8:
  2852. n = "InfiniPath_QME7362";
  2853. dd->flags |= QIB_HAS_QSFP;
  2854. break;
  2855. case 15:
  2856. n = "InfiniPath_QLE7342_TEST";
  2857. dd->flags |= QIB_HAS_QSFP;
  2858. break;
  2859. default:
  2860. n = "InfiniPath_QLE73xy_UNKNOWN";
  2861. qib_dev_err(dd, "Unknown 7322 board type %u\n", boardid);
  2862. break;
  2863. }
  2864. dd->board_atten = 1; /* index into txdds_Xdr */
  2865. namelen = strlen(n) + 1;
  2866. dd->boardname = kmalloc(namelen, GFP_KERNEL);
  2867. if (!dd->boardname)
  2868. qib_dev_err(dd, "Failed allocation for board name: %s\n", n);
  2869. else
  2870. snprintf(dd->boardname, namelen, "%s", n);
  2871. snprintf(dd->boardversion, sizeof(dd->boardversion),
  2872. "ChipABI %u.%u, %s, InfiniPath%u %u.%u, SW Compat %u\n",
  2873. QIB_CHIP_VERS_MAJ, QIB_CHIP_VERS_MIN, dd->boardname,
  2874. (unsigned)SYM_FIELD(dd->revision, Revision_R, Arch),
  2875. dd->majrev, dd->minrev,
  2876. (unsigned)SYM_FIELD(dd->revision, Revision_R, SW));
  2877. if (qib_singleport && (features >> PORT_SPD_CAP_SHIFT) & PORT_SPD_CAP) {
  2878. qib_devinfo(dd->pcidev, "IB%u: Forced to single port mode"
  2879. " by module parameter\n", dd->unit);
  2880. features &= PORT_SPD_CAP;
  2881. }
  2882. return features;
  2883. }
  2884. /*
  2885. * This routine sleeps, so it can only be called from user context, not
  2886. * from interrupt context.
  2887. */
  2888. static int qib_do_7322_reset(struct qib_devdata *dd)
  2889. {
  2890. u64 val;
  2891. u64 *msix_vecsave;
  2892. int i, msix_entries, ret = 1;
  2893. u16 cmdval;
  2894. u8 int_line, clinesz;
  2895. unsigned long flags;
  2896. /* Use dev_err so it shows up in logs, etc. */
  2897. qib_dev_err(dd, "Resetting InfiniPath unit %u\n", dd->unit);
  2898. qib_pcie_getcmd(dd, &cmdval, &int_line, &clinesz);
  2899. msix_entries = dd->cspec->num_msix_entries;
  2900. /* no interrupts till re-initted */
  2901. qib_7322_set_intr_state(dd, 0);
  2902. if (msix_entries) {
  2903. qib_7322_nomsix(dd);
  2904. /* can be up to 512 bytes, too big for stack */
  2905. msix_vecsave = kmalloc(2 * dd->cspec->num_msix_entries *
  2906. sizeof(u64), GFP_KERNEL);
  2907. if (!msix_vecsave)
  2908. qib_dev_err(dd, "No mem to save MSIx data\n");
  2909. } else
  2910. msix_vecsave = NULL;
  2911. /*
  2912. * Core PCI (as of 2.6.18) doesn't save or rewrite the full vector
  2913. * info that is set up by the BIOS, so we have to save and restore
  2914. * it ourselves. There is some risk something could change it,
  2915. * after we save it, but since we have disabled the MSIx, it
  2916. * shouldn't be touched...
  2917. */
  2918. for (i = 0; i < msix_entries; i++) {
  2919. u64 vecaddr, vecdata;
  2920. vecaddr = qib_read_kreg64(dd, 2 * i +
  2921. (QIB_7322_MsixTable_OFFS / sizeof(u64)));
  2922. vecdata = qib_read_kreg64(dd, 1 + 2 * i +
  2923. (QIB_7322_MsixTable_OFFS / sizeof(u64)));
  2924. if (msix_vecsave) {
  2925. msix_vecsave[2 * i] = vecaddr;
  2926. /* save it without the masked bit set */
  2927. msix_vecsave[1 + 2 * i] = vecdata & ~0x100000000ULL;
  2928. }
  2929. }
  2930. dd->pport->cpspec->ibdeltainprog = 0;
  2931. dd->pport->cpspec->ibsymdelta = 0;
  2932. dd->pport->cpspec->iblnkerrdelta = 0;
  2933. dd->pport->cpspec->ibmalfdelta = 0;
  2934. dd->int_counter = 0; /* so we check interrupts work again */
  2935. /*
  2936. * Keep chip from being accessed until we are ready. Use
  2937. * writeq() directly, to allow the write even though QIB_PRESENT
  2938. * isn't set.
  2939. */
  2940. dd->flags &= ~(QIB_INITTED | QIB_PRESENT | QIB_BADINTR);
  2941. dd->flags |= QIB_DOING_RESET;
  2942. val = dd->control | QLOGIC_IB_C_RESET;
  2943. writeq(val, &dd->kregbase[kr_control]);
  2944. for (i = 1; i <= 5; i++) {
  2945. /*
  2946. * Allow MBIST, etc. to complete; longer on each retry.
  2947. * We sometimes get machine checks from bus timeout if no
  2948. * response, so for now, make it *really* long.
  2949. */
  2950. msleep(1000 + (1 + i) * 3000);
  2951. qib_pcie_reenable(dd, cmdval, int_line, clinesz);
  2952. /*
  2953. * Use readq directly, so we don't need to mark it as PRESENT
  2954. * until we get a successful indication that all is well.
  2955. */
  2956. val = readq(&dd->kregbase[kr_revision]);
  2957. if (val == dd->revision)
  2958. break;
  2959. if (i == 5) {
  2960. qib_dev_err(dd, "Failed to initialize after reset, "
  2961. "unusable\n");
  2962. ret = 0;
  2963. goto bail;
  2964. }
  2965. }
  2966. dd->flags |= QIB_PRESENT; /* it's back */
  2967. if (msix_entries) {
  2968. /* restore the MSIx vector address and data if saved above */
  2969. for (i = 0; i < msix_entries; i++) {
  2970. dd->cspec->msix_entries[i].entry = i;
  2971. if (!msix_vecsave || !msix_vecsave[2 * i])
  2972. continue;
  2973. qib_write_kreg(dd, 2 * i +
  2974. (QIB_7322_MsixTable_OFFS / sizeof(u64)),
  2975. msix_vecsave[2 * i]);
  2976. qib_write_kreg(dd, 1 + 2 * i +
  2977. (QIB_7322_MsixTable_OFFS / sizeof(u64)),
  2978. msix_vecsave[1 + 2 * i]);
  2979. }
  2980. }
  2981. /* initialize the remaining registers. */
  2982. for (i = 0; i < dd->num_pports; ++i)
  2983. write_7322_init_portregs(&dd->pport[i]);
  2984. write_7322_initregs(dd);
  2985. if (qib_pcie_params(dd, dd->lbus_width,
  2986. &dd->cspec->num_msix_entries,
  2987. dd->cspec->msix_entries))
  2988. qib_dev_err(dd, "Reset failed to setup PCIe or interrupts; "
  2989. "continuing anyway\n");
  2990. qib_setup_7322_interrupt(dd, 1);
  2991. for (i = 0; i < dd->num_pports; ++i) {
  2992. struct qib_pportdata *ppd = &dd->pport[i];
  2993. spin_lock_irqsave(&ppd->lflags_lock, flags);
  2994. ppd->lflags |= QIBL_IB_FORCE_NOTIFY;
  2995. ppd->lflags &= ~QIBL_IB_AUTONEG_FAILED;
  2996. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  2997. }
  2998. bail:
  2999. dd->flags &= ~QIB_DOING_RESET; /* OK or not, no longer resetting */
  3000. kfree(msix_vecsave);
  3001. return ret;
  3002. }
  3003. /**
  3004. * qib_7322_put_tid - write a TID to the chip
  3005. * @dd: the qlogic_ib device
  3006. * @tidptr: pointer to the expected TID (in chip) to update
  3007. * @tidtype: 0 for eager, 1 for expected
  3008. * @pa: physical address of in memory buffer; tidinvalid if freeing
  3009. */
  3010. static void qib_7322_put_tid(struct qib_devdata *dd, u64 __iomem *tidptr,
  3011. u32 type, unsigned long pa)
  3012. {
  3013. if (!(dd->flags & QIB_PRESENT))
  3014. return;
  3015. if (pa != dd->tidinvalid) {
  3016. u64 chippa = pa >> IBA7322_TID_PA_SHIFT;
  3017. /* paranoia checks */
  3018. if (pa != (chippa << IBA7322_TID_PA_SHIFT)) {
  3019. qib_dev_err(dd, "Physaddr %lx not 2KB aligned!\n",
  3020. pa);
  3021. return;
  3022. }
  3023. if (chippa >= (1UL << IBA7322_TID_SZ_SHIFT)) {
  3024. qib_dev_err(dd, "Physical page address 0x%lx "
  3025. "larger than supported\n", pa);
  3026. return;
  3027. }
  3028. if (type == RCVHQ_RCV_TYPE_EAGER)
  3029. chippa |= dd->tidtemplate;
  3030. else /* for now, always full 4KB page */
  3031. chippa |= IBA7322_TID_SZ_4K;
  3032. pa = chippa;
  3033. }
  3034. writeq(pa, tidptr);
  3035. mmiowb();
  3036. }
  3037. /**
  3038. * qib_7322_clear_tids - clear all TID entries for a ctxt, expected and eager
  3039. * @dd: the qlogic_ib device
  3040. * @ctxt: the ctxt
  3041. *
  3042. * clear all TID entries for a ctxt, expected and eager.
  3043. * Used from qib_close().
  3044. */
  3045. static void qib_7322_clear_tids(struct qib_devdata *dd,
  3046. struct qib_ctxtdata *rcd)
  3047. {
  3048. u64 __iomem *tidbase;
  3049. unsigned long tidinv;
  3050. u32 ctxt;
  3051. int i;
  3052. if (!dd->kregbase || !rcd)
  3053. return;
  3054. ctxt = rcd->ctxt;
  3055. tidinv = dd->tidinvalid;
  3056. tidbase = (u64 __iomem *)
  3057. ((char __iomem *) dd->kregbase +
  3058. dd->rcvtidbase +
  3059. ctxt * dd->rcvtidcnt * sizeof(*tidbase));
  3060. for (i = 0; i < dd->rcvtidcnt; i++)
  3061. qib_7322_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EXPECTED,
  3062. tidinv);
  3063. tidbase = (u64 __iomem *)
  3064. ((char __iomem *) dd->kregbase +
  3065. dd->rcvegrbase +
  3066. rcd->rcvegr_tid_base * sizeof(*tidbase));
  3067. for (i = 0; i < rcd->rcvegrcnt; i++)
  3068. qib_7322_put_tid(dd, &tidbase[i], RCVHQ_RCV_TYPE_EAGER,
  3069. tidinv);
  3070. }
  3071. /**
  3072. * qib_7322_tidtemplate - setup constants for TID updates
  3073. * @dd: the qlogic_ib device
  3074. *
  3075. * We setup stuff that we use a lot, to avoid calculating each time
  3076. */
  3077. static void qib_7322_tidtemplate(struct qib_devdata *dd)
  3078. {
  3079. /*
  3080. * For now, we always allocate 4KB buffers (at init) so we can
  3081. * receive max size packets. We may want a module parameter to
  3082. * specify 2KB or 4KB and/or make it per port instead of per device
  3083. * for those who want to reduce memory footprint. Note that the
  3084. * rcvhdrentsize size must be large enough to hold the largest
  3085. * IB header (currently 96 bytes) that we expect to handle (plus of
  3086. * course the 2 dwords of RHF).
  3087. */
  3088. if (dd->rcvegrbufsize == 2048)
  3089. dd->tidtemplate = IBA7322_TID_SZ_2K;
  3090. else if (dd->rcvegrbufsize == 4096)
  3091. dd->tidtemplate = IBA7322_TID_SZ_4K;
  3092. dd->tidinvalid = 0;
  3093. }
  3094. /**
  3095. * qib_init_7322_get_base_info - set chip-specific flags for user code
  3096. * @rcd: the qlogic_ib ctxt
  3097. * @kbase: qib_base_info pointer
  3098. *
  3099. * We set the PCIE flag because the lower bandwidth on PCIe vs
  3100. * HyperTransport can affect some user packet algorithims.
  3101. */
  3102. static int qib_7322_get_base_info(struct qib_ctxtdata *rcd,
  3103. struct qib_base_info *kinfo)
  3104. {
  3105. kinfo->spi_runtime_flags |= QIB_RUNTIME_CTXT_MSB_IN_QP |
  3106. QIB_RUNTIME_PCIE | QIB_RUNTIME_NODMA_RTAIL |
  3107. QIB_RUNTIME_HDRSUPP | QIB_RUNTIME_SDMA;
  3108. if (rcd->dd->cspec->r1)
  3109. kinfo->spi_runtime_flags |= QIB_RUNTIME_RCHK;
  3110. if (rcd->dd->flags & QIB_USE_SPCL_TRIG)
  3111. kinfo->spi_runtime_flags |= QIB_RUNTIME_SPECIAL_TRIGGER;
  3112. return 0;
  3113. }
  3114. static struct qib_message_header *
  3115. qib_7322_get_msgheader(struct qib_devdata *dd, __le32 *rhf_addr)
  3116. {
  3117. u32 offset = qib_hdrget_offset(rhf_addr);
  3118. return (struct qib_message_header *)
  3119. (rhf_addr - dd->rhf_offset + offset);
  3120. }
  3121. /*
  3122. * Configure number of contexts.
  3123. */
  3124. static void qib_7322_config_ctxts(struct qib_devdata *dd)
  3125. {
  3126. unsigned long flags;
  3127. u32 nchipctxts;
  3128. nchipctxts = qib_read_kreg32(dd, kr_contextcnt);
  3129. dd->cspec->numctxts = nchipctxts;
  3130. if (qib_n_krcv_queues > 1 && dd->num_pports) {
  3131. dd->first_user_ctxt = NUM_IB_PORTS +
  3132. (qib_n_krcv_queues - 1) * dd->num_pports;
  3133. if (dd->first_user_ctxt > nchipctxts)
  3134. dd->first_user_ctxt = nchipctxts;
  3135. dd->n_krcv_queues = dd->first_user_ctxt / dd->num_pports;
  3136. } else {
  3137. dd->first_user_ctxt = NUM_IB_PORTS;
  3138. dd->n_krcv_queues = 1;
  3139. }
  3140. if (!qib_cfgctxts) {
  3141. int nctxts = dd->first_user_ctxt + num_online_cpus();
  3142. if (nctxts <= 6)
  3143. dd->ctxtcnt = 6;
  3144. else if (nctxts <= 10)
  3145. dd->ctxtcnt = 10;
  3146. else if (nctxts <= nchipctxts)
  3147. dd->ctxtcnt = nchipctxts;
  3148. } else if (qib_cfgctxts < dd->num_pports)
  3149. dd->ctxtcnt = dd->num_pports;
  3150. else if (qib_cfgctxts <= nchipctxts)
  3151. dd->ctxtcnt = qib_cfgctxts;
  3152. if (!dd->ctxtcnt) /* none of the above, set to max */
  3153. dd->ctxtcnt = nchipctxts;
  3154. /*
  3155. * Chip can be configured for 6, 10, or 18 ctxts, and choice
  3156. * affects number of eager TIDs per ctxt (1K, 2K, 4K).
  3157. * Lock to be paranoid about later motion, etc.
  3158. */
  3159. spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
  3160. if (dd->ctxtcnt > 10)
  3161. dd->rcvctrl |= 2ULL << SYM_LSB(RcvCtrl, ContextCfg);
  3162. else if (dd->ctxtcnt > 6)
  3163. dd->rcvctrl |= 1ULL << SYM_LSB(RcvCtrl, ContextCfg);
  3164. /* else configure for default 6 receive ctxts */
  3165. /* The XRC opcode is 5. */
  3166. dd->rcvctrl |= 5ULL << SYM_LSB(RcvCtrl, XrcTypeCode);
  3167. /*
  3168. * RcvCtrl *must* be written here so that the
  3169. * chip understands how to change rcvegrcnt below.
  3170. */
  3171. qib_write_kreg(dd, kr_rcvctrl, dd->rcvctrl);
  3172. spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
  3173. /* kr_rcvegrcnt changes based on the number of contexts enabled */
  3174. dd->cspec->rcvegrcnt = qib_read_kreg32(dd, kr_rcvegrcnt);
  3175. if (qib_rcvhdrcnt)
  3176. dd->rcvhdrcnt = max(dd->cspec->rcvegrcnt, qib_rcvhdrcnt);
  3177. else
  3178. dd->rcvhdrcnt = max(dd->cspec->rcvegrcnt,
  3179. dd->num_pports > 1 ? 1024U : 2048U);
  3180. }
  3181. static int qib_7322_get_ib_cfg(struct qib_pportdata *ppd, int which)
  3182. {
  3183. int lsb, ret = 0;
  3184. u64 maskr; /* right-justified mask */
  3185. switch (which) {
  3186. case QIB_IB_CFG_LWID_ENB: /* Get allowed Link-width */
  3187. ret = ppd->link_width_enabled;
  3188. goto done;
  3189. case QIB_IB_CFG_LWID: /* Get currently active Link-width */
  3190. ret = ppd->link_width_active;
  3191. goto done;
  3192. case QIB_IB_CFG_SPD_ENB: /* Get allowed Link speeds */
  3193. ret = ppd->link_speed_enabled;
  3194. goto done;
  3195. case QIB_IB_CFG_SPD: /* Get current Link spd */
  3196. ret = ppd->link_speed_active;
  3197. goto done;
  3198. case QIB_IB_CFG_RXPOL_ENB: /* Get Auto-RX-polarity enable */
  3199. lsb = SYM_LSB(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
  3200. maskr = SYM_RMASK(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
  3201. break;
  3202. case QIB_IB_CFG_LREV_ENB: /* Get Auto-Lane-reversal enable */
  3203. lsb = SYM_LSB(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
  3204. maskr = SYM_RMASK(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
  3205. break;
  3206. case QIB_IB_CFG_LINKLATENCY:
  3207. ret = qib_read_kreg_port(ppd, krp_ibcstatus_b) &
  3208. SYM_MASK(IBCStatusB_0, LinkRoundTripLatency);
  3209. goto done;
  3210. case QIB_IB_CFG_OP_VLS:
  3211. ret = ppd->vls_operational;
  3212. goto done;
  3213. case QIB_IB_CFG_VL_HIGH_CAP:
  3214. ret = 16;
  3215. goto done;
  3216. case QIB_IB_CFG_VL_LOW_CAP:
  3217. ret = 16;
  3218. goto done;
  3219. case QIB_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
  3220. ret = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
  3221. OverrunThreshold);
  3222. goto done;
  3223. case QIB_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
  3224. ret = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
  3225. PhyerrThreshold);
  3226. goto done;
  3227. case QIB_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
  3228. /* will only take effect when the link state changes */
  3229. ret = (ppd->cpspec->ibcctrl_a &
  3230. SYM_MASK(IBCCtrlA_0, LinkDownDefaultState)) ?
  3231. IB_LINKINITCMD_SLEEP : IB_LINKINITCMD_POLL;
  3232. goto done;
  3233. case QIB_IB_CFG_HRTBT: /* Get Heartbeat off/enable/auto */
  3234. lsb = IBA7322_IBC_HRTBT_LSB;
  3235. maskr = IBA7322_IBC_HRTBT_RMASK; /* OR of AUTO and ENB */
  3236. break;
  3237. case QIB_IB_CFG_PMA_TICKS:
  3238. /*
  3239. * 0x00 = 10x link transfer rate or 4 nsec. for 2.5Gbs
  3240. * Since the clock is always 250MHz, the value is 3, 1 or 0.
  3241. */
  3242. if (ppd->link_speed_active == QIB_IB_QDR)
  3243. ret = 3;
  3244. else if (ppd->link_speed_active == QIB_IB_DDR)
  3245. ret = 1;
  3246. else
  3247. ret = 0;
  3248. goto done;
  3249. default:
  3250. ret = -EINVAL;
  3251. goto done;
  3252. }
  3253. ret = (int)((ppd->cpspec->ibcctrl_b >> lsb) & maskr);
  3254. done:
  3255. return ret;
  3256. }
  3257. /*
  3258. * Below again cribbed liberally from older version. Do not lean
  3259. * heavily on it.
  3260. */
  3261. #define IBA7322_IBC_DLIDLMC_SHIFT QIB_7322_IBCCtrlB_0_IB_DLID_LSB
  3262. #define IBA7322_IBC_DLIDLMC_MASK (QIB_7322_IBCCtrlB_0_IB_DLID_RMASK \
  3263. | (QIB_7322_IBCCtrlB_0_IB_DLID_MASK_RMASK << 16))
  3264. static int qib_7322_set_ib_cfg(struct qib_pportdata *ppd, int which, u32 val)
  3265. {
  3266. struct qib_devdata *dd = ppd->dd;
  3267. u64 maskr; /* right-justified mask */
  3268. int lsb, ret = 0;
  3269. u16 lcmd, licmd;
  3270. unsigned long flags;
  3271. switch (which) {
  3272. case QIB_IB_CFG_LIDLMC:
  3273. /*
  3274. * Set LID and LMC. Combined to avoid possible hazard
  3275. * caller puts LMC in 16MSbits, DLID in 16LSbits of val
  3276. */
  3277. lsb = IBA7322_IBC_DLIDLMC_SHIFT;
  3278. maskr = IBA7322_IBC_DLIDLMC_MASK;
  3279. /*
  3280. * For header-checking, the SLID in the packet will
  3281. * be masked with SendIBSLMCMask, and compared
  3282. * with SendIBSLIDAssignMask. Make sure we do not
  3283. * set any bits not covered by the mask, or we get
  3284. * false-positives.
  3285. */
  3286. qib_write_kreg_port(ppd, krp_sendslid,
  3287. val & (val >> 16) & SendIBSLIDAssignMask);
  3288. qib_write_kreg_port(ppd, krp_sendslidmask,
  3289. (val >> 16) & SendIBSLMCMask);
  3290. break;
  3291. case QIB_IB_CFG_LWID_ENB: /* set allowed Link-width */
  3292. ppd->link_width_enabled = val;
  3293. /* convert IB value to chip register value */
  3294. if (val == IB_WIDTH_1X)
  3295. val = 0;
  3296. else if (val == IB_WIDTH_4X)
  3297. val = 1;
  3298. else
  3299. val = 3;
  3300. maskr = SYM_RMASK(IBCCtrlB_0, IB_NUM_CHANNELS);
  3301. lsb = SYM_LSB(IBCCtrlB_0, IB_NUM_CHANNELS);
  3302. break;
  3303. case QIB_IB_CFG_SPD_ENB: /* set allowed Link speeds */
  3304. /*
  3305. * As with width, only write the actual register if the
  3306. * link is currently down, otherwise takes effect on next
  3307. * link change. Since setting is being explicitly requested
  3308. * (via MAD or sysfs), clear autoneg failure status if speed
  3309. * autoneg is enabled.
  3310. */
  3311. ppd->link_speed_enabled = val;
  3312. val <<= IBA7322_IBC_SPEED_LSB;
  3313. maskr = IBA7322_IBC_SPEED_MASK | IBA7322_IBC_IBTA_1_2_MASK |
  3314. IBA7322_IBC_MAX_SPEED_MASK;
  3315. if (val & (val - 1)) {
  3316. /* Muliple speeds enabled */
  3317. val |= IBA7322_IBC_IBTA_1_2_MASK |
  3318. IBA7322_IBC_MAX_SPEED_MASK;
  3319. spin_lock_irqsave(&ppd->lflags_lock, flags);
  3320. ppd->lflags &= ~QIBL_IB_AUTONEG_FAILED;
  3321. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  3322. } else if (val & IBA7322_IBC_SPEED_QDR)
  3323. val |= IBA7322_IBC_IBTA_1_2_MASK;
  3324. /* IBTA 1.2 mode + min/max + speed bits are contiguous */
  3325. lsb = SYM_LSB(IBCCtrlB_0, IB_ENHANCED_MODE);
  3326. break;
  3327. case QIB_IB_CFG_RXPOL_ENB: /* set Auto-RX-polarity enable */
  3328. lsb = SYM_LSB(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
  3329. maskr = SYM_RMASK(IBCCtrlB_0, IB_POLARITY_REV_SUPP);
  3330. break;
  3331. case QIB_IB_CFG_LREV_ENB: /* set Auto-Lane-reversal enable */
  3332. lsb = SYM_LSB(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
  3333. maskr = SYM_RMASK(IBCCtrlB_0, IB_LANE_REV_SUPPORTED);
  3334. break;
  3335. case QIB_IB_CFG_OVERRUN_THRESH: /* IB overrun threshold */
  3336. maskr = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
  3337. OverrunThreshold);
  3338. if (maskr != val) {
  3339. ppd->cpspec->ibcctrl_a &=
  3340. ~SYM_MASK(IBCCtrlA_0, OverrunThreshold);
  3341. ppd->cpspec->ibcctrl_a |= (u64) val <<
  3342. SYM_LSB(IBCCtrlA_0, OverrunThreshold);
  3343. qib_write_kreg_port(ppd, krp_ibcctrl_a,
  3344. ppd->cpspec->ibcctrl_a);
  3345. qib_write_kreg(dd, kr_scratch, 0ULL);
  3346. }
  3347. goto bail;
  3348. case QIB_IB_CFG_PHYERR_THRESH: /* IB PHY error threshold */
  3349. maskr = SYM_FIELD(ppd->cpspec->ibcctrl_a, IBCCtrlA_0,
  3350. PhyerrThreshold);
  3351. if (maskr != val) {
  3352. ppd->cpspec->ibcctrl_a &=
  3353. ~SYM_MASK(IBCCtrlA_0, PhyerrThreshold);
  3354. ppd->cpspec->ibcctrl_a |= (u64) val <<
  3355. SYM_LSB(IBCCtrlA_0, PhyerrThreshold);
  3356. qib_write_kreg_port(ppd, krp_ibcctrl_a,
  3357. ppd->cpspec->ibcctrl_a);
  3358. qib_write_kreg(dd, kr_scratch, 0ULL);
  3359. }
  3360. goto bail;
  3361. case QIB_IB_CFG_PKEYS: /* update pkeys */
  3362. maskr = (u64) ppd->pkeys[0] | ((u64) ppd->pkeys[1] << 16) |
  3363. ((u64) ppd->pkeys[2] << 32) |
  3364. ((u64) ppd->pkeys[3] << 48);
  3365. qib_write_kreg_port(ppd, krp_partitionkey, maskr);
  3366. goto bail;
  3367. case QIB_IB_CFG_LINKDEFAULT: /* IB link default (sleep/poll) */
  3368. /* will only take effect when the link state changes */
  3369. if (val == IB_LINKINITCMD_POLL)
  3370. ppd->cpspec->ibcctrl_a &=
  3371. ~SYM_MASK(IBCCtrlA_0, LinkDownDefaultState);
  3372. else /* SLEEP */
  3373. ppd->cpspec->ibcctrl_a |=
  3374. SYM_MASK(IBCCtrlA_0, LinkDownDefaultState);
  3375. qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
  3376. qib_write_kreg(dd, kr_scratch, 0ULL);
  3377. goto bail;
  3378. case QIB_IB_CFG_MTU: /* update the MTU in IBC */
  3379. /*
  3380. * Update our housekeeping variables, and set IBC max
  3381. * size, same as init code; max IBC is max we allow in
  3382. * buffer, less the qword pbc, plus 1 for ICRC, in dwords
  3383. * Set even if it's unchanged, print debug message only
  3384. * on changes.
  3385. */
  3386. val = (ppd->ibmaxlen >> 2) + 1;
  3387. ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0, MaxPktLen);
  3388. ppd->cpspec->ibcctrl_a |= (u64)val <<
  3389. SYM_LSB(IBCCtrlA_0, MaxPktLen);
  3390. qib_write_kreg_port(ppd, krp_ibcctrl_a,
  3391. ppd->cpspec->ibcctrl_a);
  3392. qib_write_kreg(dd, kr_scratch, 0ULL);
  3393. goto bail;
  3394. case QIB_IB_CFG_LSTATE: /* set the IB link state */
  3395. switch (val & 0xffff0000) {
  3396. case IB_LINKCMD_DOWN:
  3397. lcmd = QLOGIC_IB_IBCC_LINKCMD_DOWN;
  3398. ppd->cpspec->ibmalfusesnap = 1;
  3399. ppd->cpspec->ibmalfsnap = read_7322_creg32_port(ppd,
  3400. crp_errlink);
  3401. if (!ppd->cpspec->ibdeltainprog &&
  3402. qib_compat_ddr_negotiate) {
  3403. ppd->cpspec->ibdeltainprog = 1;
  3404. ppd->cpspec->ibsymsnap =
  3405. read_7322_creg32_port(ppd,
  3406. crp_ibsymbolerr);
  3407. ppd->cpspec->iblnkerrsnap =
  3408. read_7322_creg32_port(ppd,
  3409. crp_iblinkerrrecov);
  3410. }
  3411. break;
  3412. case IB_LINKCMD_ARMED:
  3413. lcmd = QLOGIC_IB_IBCC_LINKCMD_ARMED;
  3414. if (ppd->cpspec->ibmalfusesnap) {
  3415. ppd->cpspec->ibmalfusesnap = 0;
  3416. ppd->cpspec->ibmalfdelta +=
  3417. read_7322_creg32_port(ppd,
  3418. crp_errlink) -
  3419. ppd->cpspec->ibmalfsnap;
  3420. }
  3421. break;
  3422. case IB_LINKCMD_ACTIVE:
  3423. lcmd = QLOGIC_IB_IBCC_LINKCMD_ACTIVE;
  3424. break;
  3425. default:
  3426. ret = -EINVAL;
  3427. qib_dev_err(dd, "bad linkcmd req 0x%x\n", val >> 16);
  3428. goto bail;
  3429. }
  3430. switch (val & 0xffff) {
  3431. case IB_LINKINITCMD_NOP:
  3432. licmd = 0;
  3433. break;
  3434. case IB_LINKINITCMD_POLL:
  3435. licmd = QLOGIC_IB_IBCC_LINKINITCMD_POLL;
  3436. break;
  3437. case IB_LINKINITCMD_SLEEP:
  3438. licmd = QLOGIC_IB_IBCC_LINKINITCMD_SLEEP;
  3439. break;
  3440. case IB_LINKINITCMD_DISABLE:
  3441. licmd = QLOGIC_IB_IBCC_LINKINITCMD_DISABLE;
  3442. ppd->cpspec->chase_end = 0;
  3443. /*
  3444. * stop state chase counter and timer, if running.
  3445. * wait forpending timer, but don't clear .data (ppd)!
  3446. */
  3447. if (ppd->cpspec->chase_timer.expires) {
  3448. del_timer_sync(&ppd->cpspec->chase_timer);
  3449. ppd->cpspec->chase_timer.expires = 0;
  3450. }
  3451. break;
  3452. default:
  3453. ret = -EINVAL;
  3454. qib_dev_err(dd, "bad linkinitcmd req 0x%x\n",
  3455. val & 0xffff);
  3456. goto bail;
  3457. }
  3458. qib_set_ib_7322_lstate(ppd, lcmd, licmd);
  3459. goto bail;
  3460. case QIB_IB_CFG_OP_VLS:
  3461. if (ppd->vls_operational != val) {
  3462. ppd->vls_operational = val;
  3463. set_vls(ppd);
  3464. }
  3465. goto bail;
  3466. case QIB_IB_CFG_VL_HIGH_LIMIT:
  3467. qib_write_kreg_port(ppd, krp_highprio_limit, val);
  3468. goto bail;
  3469. case QIB_IB_CFG_HRTBT: /* set Heartbeat off/enable/auto */
  3470. if (val > 3) {
  3471. ret = -EINVAL;
  3472. goto bail;
  3473. }
  3474. lsb = IBA7322_IBC_HRTBT_LSB;
  3475. maskr = IBA7322_IBC_HRTBT_RMASK; /* OR of AUTO and ENB */
  3476. break;
  3477. case QIB_IB_CFG_PORT:
  3478. /* val is the port number of the switch we are connected to. */
  3479. if (ppd->dd->cspec->r1) {
  3480. cancel_delayed_work(&ppd->cpspec->ipg_work);
  3481. ppd->cpspec->ipg_tries = 0;
  3482. }
  3483. goto bail;
  3484. default:
  3485. ret = -EINVAL;
  3486. goto bail;
  3487. }
  3488. ppd->cpspec->ibcctrl_b &= ~(maskr << lsb);
  3489. ppd->cpspec->ibcctrl_b |= (((u64) val & maskr) << lsb);
  3490. qib_write_kreg_port(ppd, krp_ibcctrl_b, ppd->cpspec->ibcctrl_b);
  3491. qib_write_kreg(dd, kr_scratch, 0);
  3492. bail:
  3493. return ret;
  3494. }
  3495. static int qib_7322_set_loopback(struct qib_pportdata *ppd, const char *what)
  3496. {
  3497. int ret = 0;
  3498. u64 val, ctrlb;
  3499. /* only IBC loopback, may add serdes and xgxs loopbacks later */
  3500. if (!strncmp(what, "ibc", 3)) {
  3501. ppd->cpspec->ibcctrl_a |= SYM_MASK(IBCCtrlA_0,
  3502. Loopback);
  3503. val = 0; /* disable heart beat, so link will come up */
  3504. qib_devinfo(ppd->dd->pcidev, "Enabling IB%u:%u IBC loopback\n",
  3505. ppd->dd->unit, ppd->port);
  3506. } else if (!strncmp(what, "off", 3)) {
  3507. ppd->cpspec->ibcctrl_a &= ~SYM_MASK(IBCCtrlA_0,
  3508. Loopback);
  3509. /* enable heart beat again */
  3510. val = IBA7322_IBC_HRTBT_RMASK << IBA7322_IBC_HRTBT_LSB;
  3511. qib_devinfo(ppd->dd->pcidev, "Disabling IB%u:%u IBC loopback "
  3512. "(normal)\n", ppd->dd->unit, ppd->port);
  3513. } else
  3514. ret = -EINVAL;
  3515. if (!ret) {
  3516. qib_write_kreg_port(ppd, krp_ibcctrl_a,
  3517. ppd->cpspec->ibcctrl_a);
  3518. ctrlb = ppd->cpspec->ibcctrl_b & ~(IBA7322_IBC_HRTBT_MASK
  3519. << IBA7322_IBC_HRTBT_LSB);
  3520. ppd->cpspec->ibcctrl_b = ctrlb | val;
  3521. qib_write_kreg_port(ppd, krp_ibcctrl_b,
  3522. ppd->cpspec->ibcctrl_b);
  3523. qib_write_kreg(ppd->dd, kr_scratch, 0);
  3524. }
  3525. return ret;
  3526. }
  3527. static void get_vl_weights(struct qib_pportdata *ppd, unsigned regno,
  3528. struct ib_vl_weight_elem *vl)
  3529. {
  3530. unsigned i;
  3531. for (i = 0; i < 16; i++, regno++, vl++) {
  3532. u32 val = qib_read_kreg_port(ppd, regno);
  3533. vl->vl = (val >> SYM_LSB(LowPriority0_0, VirtualLane)) &
  3534. SYM_RMASK(LowPriority0_0, VirtualLane);
  3535. vl->weight = (val >> SYM_LSB(LowPriority0_0, Weight)) &
  3536. SYM_RMASK(LowPriority0_0, Weight);
  3537. }
  3538. }
  3539. static void set_vl_weights(struct qib_pportdata *ppd, unsigned regno,
  3540. struct ib_vl_weight_elem *vl)
  3541. {
  3542. unsigned i;
  3543. for (i = 0; i < 16; i++, regno++, vl++) {
  3544. u64 val;
  3545. val = ((vl->vl & SYM_RMASK(LowPriority0_0, VirtualLane)) <<
  3546. SYM_LSB(LowPriority0_0, VirtualLane)) |
  3547. ((vl->weight & SYM_RMASK(LowPriority0_0, Weight)) <<
  3548. SYM_LSB(LowPriority0_0, Weight));
  3549. qib_write_kreg_port(ppd, regno, val);
  3550. }
  3551. if (!(ppd->p_sendctrl & SYM_MASK(SendCtrl_0, IBVLArbiterEn))) {
  3552. struct qib_devdata *dd = ppd->dd;
  3553. unsigned long flags;
  3554. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  3555. ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, IBVLArbiterEn);
  3556. qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
  3557. qib_write_kreg(dd, kr_scratch, 0);
  3558. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  3559. }
  3560. }
  3561. static int qib_7322_get_ib_table(struct qib_pportdata *ppd, int which, void *t)
  3562. {
  3563. switch (which) {
  3564. case QIB_IB_TBL_VL_HIGH_ARB:
  3565. get_vl_weights(ppd, krp_highprio_0, t);
  3566. break;
  3567. case QIB_IB_TBL_VL_LOW_ARB:
  3568. get_vl_weights(ppd, krp_lowprio_0, t);
  3569. break;
  3570. default:
  3571. return -EINVAL;
  3572. }
  3573. return 0;
  3574. }
  3575. static int qib_7322_set_ib_table(struct qib_pportdata *ppd, int which, void *t)
  3576. {
  3577. switch (which) {
  3578. case QIB_IB_TBL_VL_HIGH_ARB:
  3579. set_vl_weights(ppd, krp_highprio_0, t);
  3580. break;
  3581. case QIB_IB_TBL_VL_LOW_ARB:
  3582. set_vl_weights(ppd, krp_lowprio_0, t);
  3583. break;
  3584. default:
  3585. return -EINVAL;
  3586. }
  3587. return 0;
  3588. }
  3589. static void qib_update_7322_usrhead(struct qib_ctxtdata *rcd, u64 hd,
  3590. u32 updegr, u32 egrhd, u32 npkts)
  3591. {
  3592. /*
  3593. * Need to write timeout register before updating rcvhdrhead to ensure
  3594. * that the timer is enabled on reception of a packet.
  3595. */
  3596. if (hd >> IBA7322_HDRHEAD_PKTINT_SHIFT)
  3597. adjust_rcv_timeout(rcd, npkts);
  3598. qib_write_ureg(rcd->dd, ur_rcvhdrhead, hd, rcd->ctxt);
  3599. qib_write_ureg(rcd->dd, ur_rcvhdrhead, hd, rcd->ctxt);
  3600. if (updegr)
  3601. qib_write_ureg(rcd->dd, ur_rcvegrindexhead, egrhd, rcd->ctxt);
  3602. }
  3603. static u32 qib_7322_hdrqempty(struct qib_ctxtdata *rcd)
  3604. {
  3605. u32 head, tail;
  3606. head = qib_read_ureg32(rcd->dd, ur_rcvhdrhead, rcd->ctxt);
  3607. if (rcd->rcvhdrtail_kvaddr)
  3608. tail = qib_get_rcvhdrtail(rcd);
  3609. else
  3610. tail = qib_read_ureg32(rcd->dd, ur_rcvhdrtail, rcd->ctxt);
  3611. return head == tail;
  3612. }
  3613. #define RCVCTRL_COMMON_MODS (QIB_RCVCTRL_CTXT_ENB | \
  3614. QIB_RCVCTRL_CTXT_DIS | \
  3615. QIB_RCVCTRL_TIDFLOW_ENB | \
  3616. QIB_RCVCTRL_TIDFLOW_DIS | \
  3617. QIB_RCVCTRL_TAILUPD_ENB | \
  3618. QIB_RCVCTRL_TAILUPD_DIS | \
  3619. QIB_RCVCTRL_INTRAVAIL_ENB | \
  3620. QIB_RCVCTRL_INTRAVAIL_DIS | \
  3621. QIB_RCVCTRL_BP_ENB | \
  3622. QIB_RCVCTRL_BP_DIS)
  3623. #define RCVCTRL_PORT_MODS (QIB_RCVCTRL_CTXT_ENB | \
  3624. QIB_RCVCTRL_CTXT_DIS | \
  3625. QIB_RCVCTRL_PKEY_DIS | \
  3626. QIB_RCVCTRL_PKEY_ENB)
  3627. /*
  3628. * Modify the RCVCTRL register in chip-specific way. This
  3629. * is a function because bit positions and (future) register
  3630. * location is chip-specifc, but the needed operations are
  3631. * generic. <op> is a bit-mask because we often want to
  3632. * do multiple modifications.
  3633. */
  3634. static void rcvctrl_7322_mod(struct qib_pportdata *ppd, unsigned int op,
  3635. int ctxt)
  3636. {
  3637. struct qib_devdata *dd = ppd->dd;
  3638. struct qib_ctxtdata *rcd;
  3639. u64 mask, val;
  3640. unsigned long flags;
  3641. spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
  3642. if (op & QIB_RCVCTRL_TIDFLOW_ENB)
  3643. dd->rcvctrl |= SYM_MASK(RcvCtrl, TidFlowEnable);
  3644. if (op & QIB_RCVCTRL_TIDFLOW_DIS)
  3645. dd->rcvctrl &= ~SYM_MASK(RcvCtrl, TidFlowEnable);
  3646. if (op & QIB_RCVCTRL_TAILUPD_ENB)
  3647. dd->rcvctrl |= SYM_MASK(RcvCtrl, TailUpd);
  3648. if (op & QIB_RCVCTRL_TAILUPD_DIS)
  3649. dd->rcvctrl &= ~SYM_MASK(RcvCtrl, TailUpd);
  3650. if (op & QIB_RCVCTRL_PKEY_ENB)
  3651. ppd->p_rcvctrl &= ~SYM_MASK(RcvCtrl_0, RcvPartitionKeyDisable);
  3652. if (op & QIB_RCVCTRL_PKEY_DIS)
  3653. ppd->p_rcvctrl |= SYM_MASK(RcvCtrl_0, RcvPartitionKeyDisable);
  3654. if (ctxt < 0) {
  3655. mask = (1ULL << dd->ctxtcnt) - 1;
  3656. rcd = NULL;
  3657. } else {
  3658. mask = (1ULL << ctxt);
  3659. rcd = dd->rcd[ctxt];
  3660. }
  3661. if ((op & QIB_RCVCTRL_CTXT_ENB) && rcd) {
  3662. ppd->p_rcvctrl |=
  3663. (mask << SYM_LSB(RcvCtrl_0, ContextEnableKernel));
  3664. if (!(dd->flags & QIB_NODMA_RTAIL)) {
  3665. op |= QIB_RCVCTRL_TAILUPD_ENB; /* need reg write */
  3666. dd->rcvctrl |= SYM_MASK(RcvCtrl, TailUpd);
  3667. }
  3668. /* Write these registers before the context is enabled. */
  3669. qib_write_kreg_ctxt(dd, krc_rcvhdrtailaddr, ctxt,
  3670. rcd->rcvhdrqtailaddr_phys);
  3671. qib_write_kreg_ctxt(dd, krc_rcvhdraddr, ctxt,
  3672. rcd->rcvhdrq_phys);
  3673. rcd->seq_cnt = 1;
  3674. }
  3675. if (op & QIB_RCVCTRL_CTXT_DIS)
  3676. ppd->p_rcvctrl &=
  3677. ~(mask << SYM_LSB(RcvCtrl_0, ContextEnableKernel));
  3678. if (op & QIB_RCVCTRL_BP_ENB)
  3679. dd->rcvctrl |= mask << SYM_LSB(RcvCtrl, dontDropRHQFull);
  3680. if (op & QIB_RCVCTRL_BP_DIS)
  3681. dd->rcvctrl &= ~(mask << SYM_LSB(RcvCtrl, dontDropRHQFull));
  3682. if (op & QIB_RCVCTRL_INTRAVAIL_ENB)
  3683. dd->rcvctrl |= (mask << SYM_LSB(RcvCtrl, IntrAvail));
  3684. if (op & QIB_RCVCTRL_INTRAVAIL_DIS)
  3685. dd->rcvctrl &= ~(mask << SYM_LSB(RcvCtrl, IntrAvail));
  3686. /*
  3687. * Decide which registers to write depending on the ops enabled.
  3688. * Special case is "flush" (no bits set at all)
  3689. * which needs to write both.
  3690. */
  3691. if (op == 0 || (op & RCVCTRL_COMMON_MODS))
  3692. qib_write_kreg(dd, kr_rcvctrl, dd->rcvctrl);
  3693. if (op == 0 || (op & RCVCTRL_PORT_MODS))
  3694. qib_write_kreg_port(ppd, krp_rcvctrl, ppd->p_rcvctrl);
  3695. if ((op & QIB_RCVCTRL_CTXT_ENB) && dd->rcd[ctxt]) {
  3696. /*
  3697. * Init the context registers also; if we were
  3698. * disabled, tail and head should both be zero
  3699. * already from the enable, but since we don't
  3700. * know, we have to do it explicitly.
  3701. */
  3702. val = qib_read_ureg32(dd, ur_rcvegrindextail, ctxt);
  3703. qib_write_ureg(dd, ur_rcvegrindexhead, val, ctxt);
  3704. /* be sure enabling write seen; hd/tl should be 0 */
  3705. (void) qib_read_kreg32(dd, kr_scratch);
  3706. val = qib_read_ureg32(dd, ur_rcvhdrtail, ctxt);
  3707. dd->rcd[ctxt]->head = val;
  3708. /* If kctxt, interrupt on next receive. */
  3709. if (ctxt < dd->first_user_ctxt)
  3710. val |= dd->rhdrhead_intr_off;
  3711. qib_write_ureg(dd, ur_rcvhdrhead, val, ctxt);
  3712. } else if ((op & QIB_RCVCTRL_INTRAVAIL_ENB) &&
  3713. dd->rcd[ctxt] && dd->rhdrhead_intr_off) {
  3714. /* arm rcv interrupt */
  3715. val = dd->rcd[ctxt]->head | dd->rhdrhead_intr_off;
  3716. qib_write_ureg(dd, ur_rcvhdrhead, val, ctxt);
  3717. }
  3718. if (op & QIB_RCVCTRL_CTXT_DIS) {
  3719. unsigned f;
  3720. /* Now that the context is disabled, clear these registers. */
  3721. if (ctxt >= 0) {
  3722. qib_write_kreg_ctxt(dd, krc_rcvhdrtailaddr, ctxt, 0);
  3723. qib_write_kreg_ctxt(dd, krc_rcvhdraddr, ctxt, 0);
  3724. for (f = 0; f < NUM_TIDFLOWS_CTXT; f++)
  3725. qib_write_ureg(dd, ur_rcvflowtable + f,
  3726. TIDFLOW_ERRBITS, ctxt);
  3727. } else {
  3728. unsigned i;
  3729. for (i = 0; i < dd->cfgctxts; i++) {
  3730. qib_write_kreg_ctxt(dd, krc_rcvhdrtailaddr,
  3731. i, 0);
  3732. qib_write_kreg_ctxt(dd, krc_rcvhdraddr, i, 0);
  3733. for (f = 0; f < NUM_TIDFLOWS_CTXT; f++)
  3734. qib_write_ureg(dd, ur_rcvflowtable + f,
  3735. TIDFLOW_ERRBITS, i);
  3736. }
  3737. }
  3738. }
  3739. spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
  3740. }
  3741. /*
  3742. * Modify the SENDCTRL register in chip-specific way. This
  3743. * is a function where there are multiple such registers with
  3744. * slightly different layouts.
  3745. * The chip doesn't allow back-to-back sendctrl writes, so write
  3746. * the scratch register after writing sendctrl.
  3747. *
  3748. * Which register is written depends on the operation.
  3749. * Most operate on the common register, while
  3750. * SEND_ENB and SEND_DIS operate on the per-port ones.
  3751. * SEND_ENB is included in common because it can change SPCL_TRIG
  3752. */
  3753. #define SENDCTRL_COMMON_MODS (\
  3754. QIB_SENDCTRL_CLEAR | \
  3755. QIB_SENDCTRL_AVAIL_DIS | \
  3756. QIB_SENDCTRL_AVAIL_ENB | \
  3757. QIB_SENDCTRL_AVAIL_BLIP | \
  3758. QIB_SENDCTRL_DISARM | \
  3759. QIB_SENDCTRL_DISARM_ALL | \
  3760. QIB_SENDCTRL_SEND_ENB)
  3761. #define SENDCTRL_PORT_MODS (\
  3762. QIB_SENDCTRL_CLEAR | \
  3763. QIB_SENDCTRL_SEND_ENB | \
  3764. QIB_SENDCTRL_SEND_DIS | \
  3765. QIB_SENDCTRL_FLUSH)
  3766. static void sendctrl_7322_mod(struct qib_pportdata *ppd, u32 op)
  3767. {
  3768. struct qib_devdata *dd = ppd->dd;
  3769. u64 tmp_dd_sendctrl;
  3770. unsigned long flags;
  3771. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  3772. /* First the dd ones that are "sticky", saved in shadow */
  3773. if (op & QIB_SENDCTRL_CLEAR)
  3774. dd->sendctrl = 0;
  3775. if (op & QIB_SENDCTRL_AVAIL_DIS)
  3776. dd->sendctrl &= ~SYM_MASK(SendCtrl, SendBufAvailUpd);
  3777. else if (op & QIB_SENDCTRL_AVAIL_ENB) {
  3778. dd->sendctrl |= SYM_MASK(SendCtrl, SendBufAvailUpd);
  3779. if (dd->flags & QIB_USE_SPCL_TRIG)
  3780. dd->sendctrl |= SYM_MASK(SendCtrl, SpecialTriggerEn);
  3781. }
  3782. /* Then the ppd ones that are "sticky", saved in shadow */
  3783. if (op & QIB_SENDCTRL_SEND_DIS)
  3784. ppd->p_sendctrl &= ~SYM_MASK(SendCtrl_0, SendEnable);
  3785. else if (op & QIB_SENDCTRL_SEND_ENB)
  3786. ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, SendEnable);
  3787. if (op & QIB_SENDCTRL_DISARM_ALL) {
  3788. u32 i, last;
  3789. tmp_dd_sendctrl = dd->sendctrl;
  3790. last = dd->piobcnt2k + dd->piobcnt4k + NUM_VL15_BUFS;
  3791. /*
  3792. * Disarm any buffers that are not yet launched,
  3793. * disabling updates until done.
  3794. */
  3795. tmp_dd_sendctrl &= ~SYM_MASK(SendCtrl, SendBufAvailUpd);
  3796. for (i = 0; i < last; i++) {
  3797. qib_write_kreg(dd, kr_sendctrl,
  3798. tmp_dd_sendctrl |
  3799. SYM_MASK(SendCtrl, Disarm) | i);
  3800. qib_write_kreg(dd, kr_scratch, 0);
  3801. }
  3802. }
  3803. if (op & QIB_SENDCTRL_FLUSH) {
  3804. u64 tmp_ppd_sendctrl = ppd->p_sendctrl;
  3805. /*
  3806. * Now drain all the fifos. The Abort bit should never be
  3807. * needed, so for now, at least, we don't use it.
  3808. */
  3809. tmp_ppd_sendctrl |=
  3810. SYM_MASK(SendCtrl_0, TxeDrainRmFifo) |
  3811. SYM_MASK(SendCtrl_0, TxeDrainLaFifo) |
  3812. SYM_MASK(SendCtrl_0, TxeBypassIbc);
  3813. qib_write_kreg_port(ppd, krp_sendctrl, tmp_ppd_sendctrl);
  3814. qib_write_kreg(dd, kr_scratch, 0);
  3815. }
  3816. tmp_dd_sendctrl = dd->sendctrl;
  3817. if (op & QIB_SENDCTRL_DISARM)
  3818. tmp_dd_sendctrl |= SYM_MASK(SendCtrl, Disarm) |
  3819. ((op & QIB_7322_SendCtrl_DisarmSendBuf_RMASK) <<
  3820. SYM_LSB(SendCtrl, DisarmSendBuf));
  3821. if ((op & QIB_SENDCTRL_AVAIL_BLIP) &&
  3822. (dd->sendctrl & SYM_MASK(SendCtrl, SendBufAvailUpd)))
  3823. tmp_dd_sendctrl &= ~SYM_MASK(SendCtrl, SendBufAvailUpd);
  3824. if (op == 0 || (op & SENDCTRL_COMMON_MODS)) {
  3825. qib_write_kreg(dd, kr_sendctrl, tmp_dd_sendctrl);
  3826. qib_write_kreg(dd, kr_scratch, 0);
  3827. }
  3828. if (op == 0 || (op & SENDCTRL_PORT_MODS)) {
  3829. qib_write_kreg_port(ppd, krp_sendctrl, ppd->p_sendctrl);
  3830. qib_write_kreg(dd, kr_scratch, 0);
  3831. }
  3832. if (op & QIB_SENDCTRL_AVAIL_BLIP) {
  3833. qib_write_kreg(dd, kr_sendctrl, dd->sendctrl);
  3834. qib_write_kreg(dd, kr_scratch, 0);
  3835. }
  3836. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  3837. if (op & QIB_SENDCTRL_FLUSH) {
  3838. u32 v;
  3839. /*
  3840. * ensure writes have hit chip, then do a few
  3841. * more reads, to allow DMA of pioavail registers
  3842. * to occur, so in-memory copy is in sync with
  3843. * the chip. Not always safe to sleep.
  3844. */
  3845. v = qib_read_kreg32(dd, kr_scratch);
  3846. qib_write_kreg(dd, kr_scratch, v);
  3847. v = qib_read_kreg32(dd, kr_scratch);
  3848. qib_write_kreg(dd, kr_scratch, v);
  3849. qib_read_kreg32(dd, kr_scratch);
  3850. }
  3851. }
  3852. #define _PORT_VIRT_FLAG 0x8000U /* "virtual", need adjustments */
  3853. #define _PORT_64BIT_FLAG 0x10000U /* not "virtual", but 64bit */
  3854. #define _PORT_CNTR_IDXMASK 0x7fffU /* mask off flags above */
  3855. /**
  3856. * qib_portcntr_7322 - read a per-port chip counter
  3857. * @ppd: the qlogic_ib pport
  3858. * @creg: the counter to read (not a chip offset)
  3859. */
  3860. static u64 qib_portcntr_7322(struct qib_pportdata *ppd, u32 reg)
  3861. {
  3862. struct qib_devdata *dd = ppd->dd;
  3863. u64 ret = 0ULL;
  3864. u16 creg;
  3865. /* 0xffff for unimplemented or synthesized counters */
  3866. static const u32 xlator[] = {
  3867. [QIBPORTCNTR_PKTSEND] = crp_pktsend | _PORT_64BIT_FLAG,
  3868. [QIBPORTCNTR_WORDSEND] = crp_wordsend | _PORT_64BIT_FLAG,
  3869. [QIBPORTCNTR_PSXMITDATA] = crp_psxmitdatacount,
  3870. [QIBPORTCNTR_PSXMITPKTS] = crp_psxmitpktscount,
  3871. [QIBPORTCNTR_PSXMITWAIT] = crp_psxmitwaitcount,
  3872. [QIBPORTCNTR_SENDSTALL] = crp_sendstall,
  3873. [QIBPORTCNTR_PKTRCV] = crp_pktrcv | _PORT_64BIT_FLAG,
  3874. [QIBPORTCNTR_PSRCVDATA] = crp_psrcvdatacount,
  3875. [QIBPORTCNTR_PSRCVPKTS] = crp_psrcvpktscount,
  3876. [QIBPORTCNTR_RCVEBP] = crp_rcvebp,
  3877. [QIBPORTCNTR_RCVOVFL] = crp_rcvovfl,
  3878. [QIBPORTCNTR_WORDRCV] = crp_wordrcv | _PORT_64BIT_FLAG,
  3879. [QIBPORTCNTR_RXDROPPKT] = 0xffff, /* not needed for 7322 */
  3880. [QIBPORTCNTR_RXLOCALPHYERR] = crp_rxotherlocalphyerr,
  3881. [QIBPORTCNTR_RXVLERR] = crp_rxvlerr,
  3882. [QIBPORTCNTR_ERRICRC] = crp_erricrc,
  3883. [QIBPORTCNTR_ERRVCRC] = crp_errvcrc,
  3884. [QIBPORTCNTR_ERRLPCRC] = crp_errlpcrc,
  3885. [QIBPORTCNTR_BADFORMAT] = crp_badformat,
  3886. [QIBPORTCNTR_ERR_RLEN] = crp_err_rlen,
  3887. [QIBPORTCNTR_IBSYMBOLERR] = crp_ibsymbolerr,
  3888. [QIBPORTCNTR_INVALIDRLEN] = crp_invalidrlen,
  3889. [QIBPORTCNTR_UNSUPVL] = crp_txunsupvl,
  3890. [QIBPORTCNTR_EXCESSBUFOVFL] = crp_excessbufferovfl,
  3891. [QIBPORTCNTR_ERRLINK] = crp_errlink,
  3892. [QIBPORTCNTR_IBLINKDOWN] = crp_iblinkdown,
  3893. [QIBPORTCNTR_IBLINKERRRECOV] = crp_iblinkerrrecov,
  3894. [QIBPORTCNTR_LLI] = crp_locallinkintegrityerr,
  3895. [QIBPORTCNTR_VL15PKTDROP] = crp_vl15droppedpkt,
  3896. [QIBPORTCNTR_ERRPKEY] = crp_errpkey,
  3897. /*
  3898. * the next 3 aren't really counters, but were implemented
  3899. * as counters in older chips, so still get accessed as
  3900. * though they were counters from this code.
  3901. */
  3902. [QIBPORTCNTR_PSINTERVAL] = krp_psinterval,
  3903. [QIBPORTCNTR_PSSTART] = krp_psstart,
  3904. [QIBPORTCNTR_PSSTAT] = krp_psstat,
  3905. /* pseudo-counter, summed for all ports */
  3906. [QIBPORTCNTR_KHDROVFL] = 0xffff,
  3907. };
  3908. if (reg >= ARRAY_SIZE(xlator)) {
  3909. qib_devinfo(ppd->dd->pcidev,
  3910. "Unimplemented portcounter %u\n", reg);
  3911. goto done;
  3912. }
  3913. creg = xlator[reg] & _PORT_CNTR_IDXMASK;
  3914. /* handle non-counters and special cases first */
  3915. if (reg == QIBPORTCNTR_KHDROVFL) {
  3916. int i;
  3917. /* sum over all kernel contexts (skip if mini_init) */
  3918. for (i = 0; dd->rcd && i < dd->first_user_ctxt; i++) {
  3919. struct qib_ctxtdata *rcd = dd->rcd[i];
  3920. if (!rcd || rcd->ppd != ppd)
  3921. continue;
  3922. ret += read_7322_creg32(dd, cr_base_egrovfl + i);
  3923. }
  3924. goto done;
  3925. } else if (reg == QIBPORTCNTR_RXDROPPKT) {
  3926. /*
  3927. * Used as part of the synthesis of port_rcv_errors
  3928. * in the verbs code for IBTA counters. Not needed for 7322,
  3929. * because all the errors are already counted by other cntrs.
  3930. */
  3931. goto done;
  3932. } else if (reg == QIBPORTCNTR_PSINTERVAL ||
  3933. reg == QIBPORTCNTR_PSSTART || reg == QIBPORTCNTR_PSSTAT) {
  3934. /* were counters in older chips, now per-port kernel regs */
  3935. ret = qib_read_kreg_port(ppd, creg);
  3936. goto done;
  3937. }
  3938. /*
  3939. * Only fast increment counters are 64 bits; use 32 bit reads to
  3940. * avoid two independent reads when on Opteron.
  3941. */
  3942. if (xlator[reg] & _PORT_64BIT_FLAG)
  3943. ret = read_7322_creg_port(ppd, creg);
  3944. else
  3945. ret = read_7322_creg32_port(ppd, creg);
  3946. if (creg == crp_ibsymbolerr) {
  3947. if (ppd->cpspec->ibdeltainprog)
  3948. ret -= ret - ppd->cpspec->ibsymsnap;
  3949. ret -= ppd->cpspec->ibsymdelta;
  3950. } else if (creg == crp_iblinkerrrecov) {
  3951. if (ppd->cpspec->ibdeltainprog)
  3952. ret -= ret - ppd->cpspec->iblnkerrsnap;
  3953. ret -= ppd->cpspec->iblnkerrdelta;
  3954. } else if (creg == crp_errlink)
  3955. ret -= ppd->cpspec->ibmalfdelta;
  3956. else if (creg == crp_iblinkdown)
  3957. ret += ppd->cpspec->iblnkdowndelta;
  3958. done:
  3959. return ret;
  3960. }
  3961. /*
  3962. * Device counter names (not port-specific), one line per stat,
  3963. * single string. Used by utilities like ipathstats to print the stats
  3964. * in a way which works for different versions of drivers, without changing
  3965. * the utility. Names need to be 12 chars or less (w/o newline), for proper
  3966. * display by utility.
  3967. * Non-error counters are first.
  3968. * Start of "error" conters is indicated by a leading "E " on the first
  3969. * "error" counter, and doesn't count in label length.
  3970. * The EgrOvfl list needs to be last so we truncate them at the configured
  3971. * context count for the device.
  3972. * cntr7322indices contains the corresponding register indices.
  3973. */
  3974. static const char cntr7322names[] =
  3975. "Interrupts\n"
  3976. "HostBusStall\n"
  3977. "E RxTIDFull\n"
  3978. "RxTIDInvalid\n"
  3979. "RxTIDFloDrop\n" /* 7322 only */
  3980. "Ctxt0EgrOvfl\n"
  3981. "Ctxt1EgrOvfl\n"
  3982. "Ctxt2EgrOvfl\n"
  3983. "Ctxt3EgrOvfl\n"
  3984. "Ctxt4EgrOvfl\n"
  3985. "Ctxt5EgrOvfl\n"
  3986. "Ctxt6EgrOvfl\n"
  3987. "Ctxt7EgrOvfl\n"
  3988. "Ctxt8EgrOvfl\n"
  3989. "Ctxt9EgrOvfl\n"
  3990. "Ctx10EgrOvfl\n"
  3991. "Ctx11EgrOvfl\n"
  3992. "Ctx12EgrOvfl\n"
  3993. "Ctx13EgrOvfl\n"
  3994. "Ctx14EgrOvfl\n"
  3995. "Ctx15EgrOvfl\n"
  3996. "Ctx16EgrOvfl\n"
  3997. "Ctx17EgrOvfl\n"
  3998. ;
  3999. static const u32 cntr7322indices[] = {
  4000. cr_lbint | _PORT_64BIT_FLAG,
  4001. cr_lbstall | _PORT_64BIT_FLAG,
  4002. cr_tidfull,
  4003. cr_tidinvalid,
  4004. cr_rxtidflowdrop,
  4005. cr_base_egrovfl + 0,
  4006. cr_base_egrovfl + 1,
  4007. cr_base_egrovfl + 2,
  4008. cr_base_egrovfl + 3,
  4009. cr_base_egrovfl + 4,
  4010. cr_base_egrovfl + 5,
  4011. cr_base_egrovfl + 6,
  4012. cr_base_egrovfl + 7,
  4013. cr_base_egrovfl + 8,
  4014. cr_base_egrovfl + 9,
  4015. cr_base_egrovfl + 10,
  4016. cr_base_egrovfl + 11,
  4017. cr_base_egrovfl + 12,
  4018. cr_base_egrovfl + 13,
  4019. cr_base_egrovfl + 14,
  4020. cr_base_egrovfl + 15,
  4021. cr_base_egrovfl + 16,
  4022. cr_base_egrovfl + 17,
  4023. };
  4024. /*
  4025. * same as cntr7322names and cntr7322indices, but for port-specific counters.
  4026. * portcntr7322indices is somewhat complicated by some registers needing
  4027. * adjustments of various kinds, and those are ORed with _PORT_VIRT_FLAG
  4028. */
  4029. static const char portcntr7322names[] =
  4030. "TxPkt\n"
  4031. "TxFlowPkt\n"
  4032. "TxWords\n"
  4033. "RxPkt\n"
  4034. "RxFlowPkt\n"
  4035. "RxWords\n"
  4036. "TxFlowStall\n"
  4037. "TxDmaDesc\n" /* 7220 and 7322-only */
  4038. "E RxDlidFltr\n" /* 7220 and 7322-only */
  4039. "IBStatusChng\n"
  4040. "IBLinkDown\n"
  4041. "IBLnkRecov\n"
  4042. "IBRxLinkErr\n"
  4043. "IBSymbolErr\n"
  4044. "RxLLIErr\n"
  4045. "RxBadFormat\n"
  4046. "RxBadLen\n"
  4047. "RxBufOvrfl\n"
  4048. "RxEBP\n"
  4049. "RxFlowCtlErr\n"
  4050. "RxICRCerr\n"
  4051. "RxLPCRCerr\n"
  4052. "RxVCRCerr\n"
  4053. "RxInvalLen\n"
  4054. "RxInvalPKey\n"
  4055. "RxPktDropped\n"
  4056. "TxBadLength\n"
  4057. "TxDropped\n"
  4058. "TxInvalLen\n"
  4059. "TxUnderrun\n"
  4060. "TxUnsupVL\n"
  4061. "RxLclPhyErr\n" /* 7220 and 7322-only from here down */
  4062. "RxVL15Drop\n"
  4063. "RxVlErr\n"
  4064. "XcessBufOvfl\n"
  4065. "RxQPBadCtxt\n" /* 7322-only from here down */
  4066. "TXBadHeader\n"
  4067. ;
  4068. static const u32 portcntr7322indices[] = {
  4069. QIBPORTCNTR_PKTSEND | _PORT_VIRT_FLAG,
  4070. crp_pktsendflow,
  4071. QIBPORTCNTR_WORDSEND | _PORT_VIRT_FLAG,
  4072. QIBPORTCNTR_PKTRCV | _PORT_VIRT_FLAG,
  4073. crp_pktrcvflowctrl,
  4074. QIBPORTCNTR_WORDRCV | _PORT_VIRT_FLAG,
  4075. QIBPORTCNTR_SENDSTALL | _PORT_VIRT_FLAG,
  4076. crp_txsdmadesc | _PORT_64BIT_FLAG,
  4077. crp_rxdlidfltr,
  4078. crp_ibstatuschange,
  4079. QIBPORTCNTR_IBLINKDOWN | _PORT_VIRT_FLAG,
  4080. QIBPORTCNTR_IBLINKERRRECOV | _PORT_VIRT_FLAG,
  4081. QIBPORTCNTR_ERRLINK | _PORT_VIRT_FLAG,
  4082. QIBPORTCNTR_IBSYMBOLERR | _PORT_VIRT_FLAG,
  4083. QIBPORTCNTR_LLI | _PORT_VIRT_FLAG,
  4084. QIBPORTCNTR_BADFORMAT | _PORT_VIRT_FLAG,
  4085. QIBPORTCNTR_ERR_RLEN | _PORT_VIRT_FLAG,
  4086. QIBPORTCNTR_RCVOVFL | _PORT_VIRT_FLAG,
  4087. QIBPORTCNTR_RCVEBP | _PORT_VIRT_FLAG,
  4088. crp_rcvflowctrlviol,
  4089. QIBPORTCNTR_ERRICRC | _PORT_VIRT_FLAG,
  4090. QIBPORTCNTR_ERRLPCRC | _PORT_VIRT_FLAG,
  4091. QIBPORTCNTR_ERRVCRC | _PORT_VIRT_FLAG,
  4092. QIBPORTCNTR_INVALIDRLEN | _PORT_VIRT_FLAG,
  4093. QIBPORTCNTR_ERRPKEY | _PORT_VIRT_FLAG,
  4094. QIBPORTCNTR_RXDROPPKT | _PORT_VIRT_FLAG,
  4095. crp_txminmaxlenerr,
  4096. crp_txdroppedpkt,
  4097. crp_txlenerr,
  4098. crp_txunderrun,
  4099. crp_txunsupvl,
  4100. QIBPORTCNTR_RXLOCALPHYERR | _PORT_VIRT_FLAG,
  4101. QIBPORTCNTR_VL15PKTDROP | _PORT_VIRT_FLAG,
  4102. QIBPORTCNTR_RXVLERR | _PORT_VIRT_FLAG,
  4103. QIBPORTCNTR_EXCESSBUFOVFL | _PORT_VIRT_FLAG,
  4104. crp_rxqpinvalidctxt,
  4105. crp_txhdrerr,
  4106. };
  4107. /* do all the setup to make the counter reads efficient later */
  4108. static void init_7322_cntrnames(struct qib_devdata *dd)
  4109. {
  4110. int i, j = 0;
  4111. char *s;
  4112. for (i = 0, s = (char *)cntr7322names; s && j <= dd->cfgctxts;
  4113. i++) {
  4114. /* we always have at least one counter before the egrovfl */
  4115. if (!j && !strncmp("Ctxt0EgrOvfl", s + 1, 12))
  4116. j = 1;
  4117. s = strchr(s + 1, '\n');
  4118. if (s && j)
  4119. j++;
  4120. }
  4121. dd->cspec->ncntrs = i;
  4122. if (!s)
  4123. /* full list; size is without terminating null */
  4124. dd->cspec->cntrnamelen = sizeof(cntr7322names) - 1;
  4125. else
  4126. dd->cspec->cntrnamelen = 1 + s - cntr7322names;
  4127. dd->cspec->cntrs = kmalloc(dd->cspec->ncntrs
  4128. * sizeof(u64), GFP_KERNEL);
  4129. if (!dd->cspec->cntrs)
  4130. qib_dev_err(dd, "Failed allocation for counters\n");
  4131. for (i = 0, s = (char *)portcntr7322names; s; i++)
  4132. s = strchr(s + 1, '\n');
  4133. dd->cspec->nportcntrs = i - 1;
  4134. dd->cspec->portcntrnamelen = sizeof(portcntr7322names) - 1;
  4135. for (i = 0; i < dd->num_pports; ++i) {
  4136. dd->pport[i].cpspec->portcntrs = kmalloc(dd->cspec->nportcntrs
  4137. * sizeof(u64), GFP_KERNEL);
  4138. if (!dd->pport[i].cpspec->portcntrs)
  4139. qib_dev_err(dd, "Failed allocation for"
  4140. " portcounters\n");
  4141. }
  4142. }
  4143. static u32 qib_read_7322cntrs(struct qib_devdata *dd, loff_t pos, char **namep,
  4144. u64 **cntrp)
  4145. {
  4146. u32 ret;
  4147. if (namep) {
  4148. ret = dd->cspec->cntrnamelen;
  4149. if (pos >= ret)
  4150. ret = 0; /* final read after getting everything */
  4151. else
  4152. *namep = (char *) cntr7322names;
  4153. } else {
  4154. u64 *cntr = dd->cspec->cntrs;
  4155. int i;
  4156. ret = dd->cspec->ncntrs * sizeof(u64);
  4157. if (!cntr || pos >= ret) {
  4158. /* everything read, or couldn't get memory */
  4159. ret = 0;
  4160. goto done;
  4161. }
  4162. *cntrp = cntr;
  4163. for (i = 0; i < dd->cspec->ncntrs; i++)
  4164. if (cntr7322indices[i] & _PORT_64BIT_FLAG)
  4165. *cntr++ = read_7322_creg(dd,
  4166. cntr7322indices[i] &
  4167. _PORT_CNTR_IDXMASK);
  4168. else
  4169. *cntr++ = read_7322_creg32(dd,
  4170. cntr7322indices[i]);
  4171. }
  4172. done:
  4173. return ret;
  4174. }
  4175. static u32 qib_read_7322portcntrs(struct qib_devdata *dd, loff_t pos, u32 port,
  4176. char **namep, u64 **cntrp)
  4177. {
  4178. u32 ret;
  4179. if (namep) {
  4180. ret = dd->cspec->portcntrnamelen;
  4181. if (pos >= ret)
  4182. ret = 0; /* final read after getting everything */
  4183. else
  4184. *namep = (char *)portcntr7322names;
  4185. } else {
  4186. struct qib_pportdata *ppd = &dd->pport[port];
  4187. u64 *cntr = ppd->cpspec->portcntrs;
  4188. int i;
  4189. ret = dd->cspec->nportcntrs * sizeof(u64);
  4190. if (!cntr || pos >= ret) {
  4191. /* everything read, or couldn't get memory */
  4192. ret = 0;
  4193. goto done;
  4194. }
  4195. *cntrp = cntr;
  4196. for (i = 0; i < dd->cspec->nportcntrs; i++) {
  4197. if (portcntr7322indices[i] & _PORT_VIRT_FLAG)
  4198. *cntr++ = qib_portcntr_7322(ppd,
  4199. portcntr7322indices[i] &
  4200. _PORT_CNTR_IDXMASK);
  4201. else if (portcntr7322indices[i] & _PORT_64BIT_FLAG)
  4202. *cntr++ = read_7322_creg_port(ppd,
  4203. portcntr7322indices[i] &
  4204. _PORT_CNTR_IDXMASK);
  4205. else
  4206. *cntr++ = read_7322_creg32_port(ppd,
  4207. portcntr7322indices[i]);
  4208. }
  4209. }
  4210. done:
  4211. return ret;
  4212. }
  4213. /**
  4214. * qib_get_7322_faststats - get word counters from chip before they overflow
  4215. * @opaque - contains a pointer to the qlogic_ib device qib_devdata
  4216. *
  4217. * VESTIGIAL IBA7322 has no "small fast counters", so the only
  4218. * real purpose of this function is to maintain the notion of
  4219. * "active time", which in turn is only logged into the eeprom,
  4220. * which we don;t have, yet, for 7322-based boards.
  4221. *
  4222. * called from add_timer
  4223. */
  4224. static void qib_get_7322_faststats(unsigned long opaque)
  4225. {
  4226. struct qib_devdata *dd = (struct qib_devdata *) opaque;
  4227. struct qib_pportdata *ppd;
  4228. unsigned long flags;
  4229. u64 traffic_wds;
  4230. int pidx;
  4231. for (pidx = 0; pidx < dd->num_pports; ++pidx) {
  4232. ppd = dd->pport + pidx;
  4233. /*
  4234. * If port isn't enabled or not operational ports, or
  4235. * diags is running (can cause memory diags to fail)
  4236. * skip this port this time.
  4237. */
  4238. if (!ppd->link_speed_supported || !(dd->flags & QIB_INITTED)
  4239. || dd->diag_client)
  4240. continue;
  4241. /*
  4242. * Maintain an activity timer, based on traffic
  4243. * exceeding a threshold, so we need to check the word-counts
  4244. * even if they are 64-bit.
  4245. */
  4246. traffic_wds = qib_portcntr_7322(ppd, QIBPORTCNTR_WORDRCV) +
  4247. qib_portcntr_7322(ppd, QIBPORTCNTR_WORDSEND);
  4248. spin_lock_irqsave(&ppd->dd->eep_st_lock, flags);
  4249. traffic_wds -= ppd->dd->traffic_wds;
  4250. ppd->dd->traffic_wds += traffic_wds;
  4251. if (traffic_wds >= QIB_TRAFFIC_ACTIVE_THRESHOLD)
  4252. atomic_add(ACTIVITY_TIMER, &ppd->dd->active_time);
  4253. spin_unlock_irqrestore(&ppd->dd->eep_st_lock, flags);
  4254. if (ppd->cpspec->qdr_dfe_on && (ppd->link_speed_active &
  4255. QIB_IB_QDR) &&
  4256. (ppd->lflags & (QIBL_LINKINIT | QIBL_LINKARMED |
  4257. QIBL_LINKACTIVE)) &&
  4258. ppd->cpspec->qdr_dfe_time &&
  4259. time_after64(get_jiffies_64(), ppd->cpspec->qdr_dfe_time)) {
  4260. ppd->cpspec->qdr_dfe_on = 0;
  4261. qib_write_kreg_port(ppd, krp_static_adapt_dis(2),
  4262. ppd->dd->cspec->r1 ?
  4263. QDR_STATIC_ADAPT_INIT_R1 :
  4264. QDR_STATIC_ADAPT_INIT);
  4265. force_h1(ppd);
  4266. }
  4267. }
  4268. mod_timer(&dd->stats_timer, jiffies + HZ * ACTIVITY_TIMER);
  4269. }
  4270. /*
  4271. * If we were using MSIx, try to fallback to INTx.
  4272. */
  4273. static int qib_7322_intr_fallback(struct qib_devdata *dd)
  4274. {
  4275. if (!dd->cspec->num_msix_entries)
  4276. return 0; /* already using INTx */
  4277. qib_devinfo(dd->pcidev, "MSIx interrupt not detected,"
  4278. " trying INTx interrupts\n");
  4279. qib_7322_nomsix(dd);
  4280. qib_enable_intx(dd->pcidev);
  4281. qib_setup_7322_interrupt(dd, 0);
  4282. return 1;
  4283. }
  4284. /*
  4285. * Reset the XGXS (between serdes and IBC). Slightly less intrusive
  4286. * than resetting the IBC or external link state, and useful in some
  4287. * cases to cause some retraining. To do this right, we reset IBC
  4288. * as well, then return to previous state (which may be still in reset)
  4289. * NOTE: some callers of this "know" this writes the current value
  4290. * of cpspec->ibcctrl_a as part of it's operation, so if that changes,
  4291. * check all callers.
  4292. */
  4293. static void qib_7322_mini_pcs_reset(struct qib_pportdata *ppd)
  4294. {
  4295. u64 val;
  4296. struct qib_devdata *dd = ppd->dd;
  4297. const u64 reset_bits = SYM_MASK(IBPCSConfig_0, xcv_rreset) |
  4298. SYM_MASK(IBPCSConfig_0, xcv_treset) |
  4299. SYM_MASK(IBPCSConfig_0, tx_rx_reset);
  4300. val = qib_read_kreg_port(ppd, krp_ib_pcsconfig);
  4301. qib_write_kreg(dd, kr_hwerrmask,
  4302. dd->cspec->hwerrmask & ~HWE_MASK(statusValidNoEop));
  4303. qib_write_kreg_port(ppd, krp_ibcctrl_a,
  4304. ppd->cpspec->ibcctrl_a &
  4305. ~SYM_MASK(IBCCtrlA_0, IBLinkEn));
  4306. qib_write_kreg_port(ppd, krp_ib_pcsconfig, val | reset_bits);
  4307. qib_read_kreg32(dd, kr_scratch);
  4308. qib_write_kreg_port(ppd, krp_ib_pcsconfig, val & ~reset_bits);
  4309. qib_write_kreg_port(ppd, krp_ibcctrl_a, ppd->cpspec->ibcctrl_a);
  4310. qib_write_kreg(dd, kr_scratch, 0ULL);
  4311. qib_write_kreg(dd, kr_hwerrclear,
  4312. SYM_MASK(HwErrClear, statusValidNoEopClear));
  4313. qib_write_kreg(dd, kr_hwerrmask, dd->cspec->hwerrmask);
  4314. }
  4315. /*
  4316. * This code for non-IBTA-compliant IB speed negotiation is only known to
  4317. * work for the SDR to DDR transition, and only between an HCA and a switch
  4318. * with recent firmware. It is based on observed heuristics, rather than
  4319. * actual knowledge of the non-compliant speed negotiation.
  4320. * It has a number of hard-coded fields, since the hope is to rewrite this
  4321. * when a spec is available on how the negoation is intended to work.
  4322. */
  4323. static void autoneg_7322_sendpkt(struct qib_pportdata *ppd, u32 *hdr,
  4324. u32 dcnt, u32 *data)
  4325. {
  4326. int i;
  4327. u64 pbc;
  4328. u32 __iomem *piobuf;
  4329. u32 pnum, control, len;
  4330. struct qib_devdata *dd = ppd->dd;
  4331. i = 0;
  4332. len = 7 + dcnt + 1; /* 7 dword header, dword data, icrc */
  4333. control = qib_7322_setpbc_control(ppd, len, 0, 15);
  4334. pbc = ((u64) control << 32) | len;
  4335. while (!(piobuf = qib_7322_getsendbuf(ppd, pbc, &pnum))) {
  4336. if (i++ > 15)
  4337. return;
  4338. udelay(2);
  4339. }
  4340. /* disable header check on this packet, since it can't be valid */
  4341. dd->f_txchk_change(dd, pnum, 1, TXCHK_CHG_TYPE_DIS1, NULL);
  4342. writeq(pbc, piobuf);
  4343. qib_flush_wc();
  4344. qib_pio_copy(piobuf + 2, hdr, 7);
  4345. qib_pio_copy(piobuf + 9, data, dcnt);
  4346. if (dd->flags & QIB_USE_SPCL_TRIG) {
  4347. u32 spcl_off = (pnum >= dd->piobcnt2k) ? 2047 : 1023;
  4348. qib_flush_wc();
  4349. __raw_writel(0xaebecede, piobuf + spcl_off);
  4350. }
  4351. qib_flush_wc();
  4352. qib_sendbuf_done(dd, pnum);
  4353. /* and re-enable hdr check */
  4354. dd->f_txchk_change(dd, pnum, 1, TXCHK_CHG_TYPE_ENAB1, NULL);
  4355. }
  4356. /*
  4357. * _start packet gets sent twice at start, _done gets sent twice at end
  4358. */
  4359. static void qib_autoneg_7322_send(struct qib_pportdata *ppd, int which)
  4360. {
  4361. struct qib_devdata *dd = ppd->dd;
  4362. static u32 swapped;
  4363. u32 dw, i, hcnt, dcnt, *data;
  4364. static u32 hdr[7] = { 0xf002ffff, 0x48ffff, 0x6400abba };
  4365. static u32 madpayload_start[0x40] = {
  4366. 0x1810103, 0x1, 0x0, 0x0, 0x2c90000, 0x2c9, 0x0, 0x0,
  4367. 0xffffffff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  4368. 0x1, 0x1388, 0x15e, 0x1, /* rest 0's */
  4369. };
  4370. static u32 madpayload_done[0x40] = {
  4371. 0x1810103, 0x1, 0x0, 0x0, 0x2c90000, 0x2c9, 0x0, 0x0,
  4372. 0xffffffff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  4373. 0x40000001, 0x1388, 0x15e, /* rest 0's */
  4374. };
  4375. dcnt = ARRAY_SIZE(madpayload_start);
  4376. hcnt = ARRAY_SIZE(hdr);
  4377. if (!swapped) {
  4378. /* for maintainability, do it at runtime */
  4379. for (i = 0; i < hcnt; i++) {
  4380. dw = (__force u32) cpu_to_be32(hdr[i]);
  4381. hdr[i] = dw;
  4382. }
  4383. for (i = 0; i < dcnt; i++) {
  4384. dw = (__force u32) cpu_to_be32(madpayload_start[i]);
  4385. madpayload_start[i] = dw;
  4386. dw = (__force u32) cpu_to_be32(madpayload_done[i]);
  4387. madpayload_done[i] = dw;
  4388. }
  4389. swapped = 1;
  4390. }
  4391. data = which ? madpayload_done : madpayload_start;
  4392. autoneg_7322_sendpkt(ppd, hdr, dcnt, data);
  4393. qib_read_kreg64(dd, kr_scratch);
  4394. udelay(2);
  4395. autoneg_7322_sendpkt(ppd, hdr, dcnt, data);
  4396. qib_read_kreg64(dd, kr_scratch);
  4397. udelay(2);
  4398. }
  4399. /*
  4400. * Do the absolute minimum to cause an IB speed change, and make it
  4401. * ready, but don't actually trigger the change. The caller will
  4402. * do that when ready (if link is in Polling training state, it will
  4403. * happen immediately, otherwise when link next goes down)
  4404. *
  4405. * This routine should only be used as part of the DDR autonegotation
  4406. * code for devices that are not compliant with IB 1.2 (or code that
  4407. * fixes things up for same).
  4408. *
  4409. * When link has gone down, and autoneg enabled, or autoneg has
  4410. * failed and we give up until next time we set both speeds, and
  4411. * then we want IBTA enabled as well as "use max enabled speed.
  4412. */
  4413. static void set_7322_ibspeed_fast(struct qib_pportdata *ppd, u32 speed)
  4414. {
  4415. u64 newctrlb;
  4416. newctrlb = ppd->cpspec->ibcctrl_b & ~(IBA7322_IBC_SPEED_MASK |
  4417. IBA7322_IBC_IBTA_1_2_MASK |
  4418. IBA7322_IBC_MAX_SPEED_MASK);
  4419. if (speed & (speed - 1)) /* multiple speeds */
  4420. newctrlb |= (speed << IBA7322_IBC_SPEED_LSB) |
  4421. IBA7322_IBC_IBTA_1_2_MASK |
  4422. IBA7322_IBC_MAX_SPEED_MASK;
  4423. else
  4424. newctrlb |= speed == QIB_IB_QDR ?
  4425. IBA7322_IBC_SPEED_QDR | IBA7322_IBC_IBTA_1_2_MASK :
  4426. ((speed == QIB_IB_DDR ?
  4427. IBA7322_IBC_SPEED_DDR : IBA7322_IBC_SPEED_SDR));
  4428. if (newctrlb == ppd->cpspec->ibcctrl_b)
  4429. return;
  4430. ppd->cpspec->ibcctrl_b = newctrlb;
  4431. qib_write_kreg_port(ppd, krp_ibcctrl_b, ppd->cpspec->ibcctrl_b);
  4432. qib_write_kreg(ppd->dd, kr_scratch, 0);
  4433. }
  4434. /*
  4435. * This routine is only used when we are not talking to another
  4436. * IB 1.2-compliant device that we think can do DDR.
  4437. * (This includes all existing switch chips as of Oct 2007.)
  4438. * 1.2-compliant devices go directly to DDR prior to reaching INIT
  4439. */
  4440. static void try_7322_autoneg(struct qib_pportdata *ppd)
  4441. {
  4442. unsigned long flags;
  4443. spin_lock_irqsave(&ppd->lflags_lock, flags);
  4444. ppd->lflags |= QIBL_IB_AUTONEG_INPROG;
  4445. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  4446. qib_autoneg_7322_send(ppd, 0);
  4447. set_7322_ibspeed_fast(ppd, QIB_IB_DDR);
  4448. qib_7322_mini_pcs_reset(ppd);
  4449. /* 2 msec is minimum length of a poll cycle */
  4450. queue_delayed_work(ib_wq, &ppd->cpspec->autoneg_work,
  4451. msecs_to_jiffies(2));
  4452. }
  4453. /*
  4454. * Handle the empirically determined mechanism for auto-negotiation
  4455. * of DDR speed with switches.
  4456. */
  4457. static void autoneg_7322_work(struct work_struct *work)
  4458. {
  4459. struct qib_pportdata *ppd;
  4460. struct qib_devdata *dd;
  4461. u64 startms;
  4462. u32 i;
  4463. unsigned long flags;
  4464. ppd = container_of(work, struct qib_chippport_specific,
  4465. autoneg_work.work)->ppd;
  4466. dd = ppd->dd;
  4467. startms = jiffies_to_msecs(jiffies);
  4468. /*
  4469. * Busy wait for this first part, it should be at most a
  4470. * few hundred usec, since we scheduled ourselves for 2msec.
  4471. */
  4472. for (i = 0; i < 25; i++) {
  4473. if (SYM_FIELD(ppd->lastibcstat, IBCStatusA_0, LinkState)
  4474. == IB_7322_LT_STATE_POLLQUIET) {
  4475. qib_set_linkstate(ppd, QIB_IB_LINKDOWN_DISABLE);
  4476. break;
  4477. }
  4478. udelay(100);
  4479. }
  4480. if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG))
  4481. goto done; /* we got there early or told to stop */
  4482. /* we expect this to timeout */
  4483. if (wait_event_timeout(ppd->cpspec->autoneg_wait,
  4484. !(ppd->lflags & QIBL_IB_AUTONEG_INPROG),
  4485. msecs_to_jiffies(90)))
  4486. goto done;
  4487. qib_7322_mini_pcs_reset(ppd);
  4488. /* we expect this to timeout */
  4489. if (wait_event_timeout(ppd->cpspec->autoneg_wait,
  4490. !(ppd->lflags & QIBL_IB_AUTONEG_INPROG),
  4491. msecs_to_jiffies(1700)))
  4492. goto done;
  4493. qib_7322_mini_pcs_reset(ppd);
  4494. set_7322_ibspeed_fast(ppd, QIB_IB_SDR);
  4495. /*
  4496. * Wait up to 250 msec for link to train and get to INIT at DDR;
  4497. * this should terminate early.
  4498. */
  4499. wait_event_timeout(ppd->cpspec->autoneg_wait,
  4500. !(ppd->lflags & QIBL_IB_AUTONEG_INPROG),
  4501. msecs_to_jiffies(250));
  4502. done:
  4503. if (ppd->lflags & QIBL_IB_AUTONEG_INPROG) {
  4504. spin_lock_irqsave(&ppd->lflags_lock, flags);
  4505. ppd->lflags &= ~QIBL_IB_AUTONEG_INPROG;
  4506. if (ppd->cpspec->autoneg_tries == AUTONEG_TRIES) {
  4507. ppd->lflags |= QIBL_IB_AUTONEG_FAILED;
  4508. ppd->cpspec->autoneg_tries = 0;
  4509. }
  4510. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  4511. set_7322_ibspeed_fast(ppd, ppd->link_speed_enabled);
  4512. }
  4513. }
  4514. /*
  4515. * This routine is used to request IPG set in the QLogic switch.
  4516. * Only called if r1.
  4517. */
  4518. static void try_7322_ipg(struct qib_pportdata *ppd)
  4519. {
  4520. struct qib_ibport *ibp = &ppd->ibport_data;
  4521. struct ib_mad_send_buf *send_buf;
  4522. struct ib_mad_agent *agent;
  4523. struct ib_smp *smp;
  4524. unsigned delay;
  4525. int ret;
  4526. agent = ibp->send_agent;
  4527. if (!agent)
  4528. goto retry;
  4529. send_buf = ib_create_send_mad(agent, 0, 0, 0, IB_MGMT_MAD_HDR,
  4530. IB_MGMT_MAD_DATA, GFP_ATOMIC);
  4531. if (IS_ERR(send_buf))
  4532. goto retry;
  4533. if (!ibp->smi_ah) {
  4534. struct ib_ah_attr attr;
  4535. struct ib_ah *ah;
  4536. memset(&attr, 0, sizeof attr);
  4537. attr.dlid = be16_to_cpu(IB_LID_PERMISSIVE);
  4538. attr.port_num = ppd->port;
  4539. ah = ib_create_ah(ibp->qp0->ibqp.pd, &attr);
  4540. if (IS_ERR(ah))
  4541. ret = -EINVAL;
  4542. else {
  4543. send_buf->ah = ah;
  4544. ibp->smi_ah = to_iah(ah);
  4545. ret = 0;
  4546. }
  4547. } else {
  4548. send_buf->ah = &ibp->smi_ah->ibah;
  4549. ret = 0;
  4550. }
  4551. smp = send_buf->mad;
  4552. smp->base_version = IB_MGMT_BASE_VERSION;
  4553. smp->mgmt_class = IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE;
  4554. smp->class_version = 1;
  4555. smp->method = IB_MGMT_METHOD_SEND;
  4556. smp->hop_cnt = 1;
  4557. smp->attr_id = QIB_VENDOR_IPG;
  4558. smp->attr_mod = 0;
  4559. if (!ret)
  4560. ret = ib_post_send_mad(send_buf, NULL);
  4561. if (ret)
  4562. ib_free_send_mad(send_buf);
  4563. retry:
  4564. delay = 2 << ppd->cpspec->ipg_tries;
  4565. queue_delayed_work(ib_wq, &ppd->cpspec->ipg_work,
  4566. msecs_to_jiffies(delay));
  4567. }
  4568. /*
  4569. * Timeout handler for setting IPG.
  4570. * Only called if r1.
  4571. */
  4572. static void ipg_7322_work(struct work_struct *work)
  4573. {
  4574. struct qib_pportdata *ppd;
  4575. ppd = container_of(work, struct qib_chippport_specific,
  4576. ipg_work.work)->ppd;
  4577. if ((ppd->lflags & (QIBL_LINKINIT | QIBL_LINKARMED | QIBL_LINKACTIVE))
  4578. && ++ppd->cpspec->ipg_tries <= 10)
  4579. try_7322_ipg(ppd);
  4580. }
  4581. static u32 qib_7322_iblink_state(u64 ibcs)
  4582. {
  4583. u32 state = (u32)SYM_FIELD(ibcs, IBCStatusA_0, LinkState);
  4584. switch (state) {
  4585. case IB_7322_L_STATE_INIT:
  4586. state = IB_PORT_INIT;
  4587. break;
  4588. case IB_7322_L_STATE_ARM:
  4589. state = IB_PORT_ARMED;
  4590. break;
  4591. case IB_7322_L_STATE_ACTIVE:
  4592. /* fall through */
  4593. case IB_7322_L_STATE_ACT_DEFER:
  4594. state = IB_PORT_ACTIVE;
  4595. break;
  4596. default: /* fall through */
  4597. case IB_7322_L_STATE_DOWN:
  4598. state = IB_PORT_DOWN;
  4599. break;
  4600. }
  4601. return state;
  4602. }
  4603. /* returns the IBTA port state, rather than the IBC link training state */
  4604. static u8 qib_7322_phys_portstate(u64 ibcs)
  4605. {
  4606. u8 state = (u8)SYM_FIELD(ibcs, IBCStatusA_0, LinkTrainingState);
  4607. return qib_7322_physportstate[state];
  4608. }
  4609. static int qib_7322_ib_updown(struct qib_pportdata *ppd, int ibup, u64 ibcs)
  4610. {
  4611. int ret = 0, symadj = 0;
  4612. unsigned long flags;
  4613. int mult;
  4614. spin_lock_irqsave(&ppd->lflags_lock, flags);
  4615. ppd->lflags &= ~QIBL_IB_FORCE_NOTIFY;
  4616. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  4617. /* Update our picture of width and speed from chip */
  4618. if (ibcs & SYM_MASK(IBCStatusA_0, LinkSpeedQDR)) {
  4619. ppd->link_speed_active = QIB_IB_QDR;
  4620. mult = 4;
  4621. } else if (ibcs & SYM_MASK(IBCStatusA_0, LinkSpeedActive)) {
  4622. ppd->link_speed_active = QIB_IB_DDR;
  4623. mult = 2;
  4624. } else {
  4625. ppd->link_speed_active = QIB_IB_SDR;
  4626. mult = 1;
  4627. }
  4628. if (ibcs & SYM_MASK(IBCStatusA_0, LinkWidthActive)) {
  4629. ppd->link_width_active = IB_WIDTH_4X;
  4630. mult *= 4;
  4631. } else
  4632. ppd->link_width_active = IB_WIDTH_1X;
  4633. ppd->delay_mult = ib_rate_to_delay[mult_to_ib_rate(mult)];
  4634. if (!ibup) {
  4635. u64 clr;
  4636. /* Link went down. */
  4637. /* do IPG MAD again after linkdown, even if last time failed */
  4638. ppd->cpspec->ipg_tries = 0;
  4639. clr = qib_read_kreg_port(ppd, krp_ibcstatus_b) &
  4640. (SYM_MASK(IBCStatusB_0, heartbeat_timed_out) |
  4641. SYM_MASK(IBCStatusB_0, heartbeat_crosstalk));
  4642. if (clr)
  4643. qib_write_kreg_port(ppd, krp_ibcstatus_b, clr);
  4644. if (!(ppd->lflags & (QIBL_IB_AUTONEG_FAILED |
  4645. QIBL_IB_AUTONEG_INPROG)))
  4646. set_7322_ibspeed_fast(ppd, ppd->link_speed_enabled);
  4647. if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG)) {
  4648. /* unlock the Tx settings, speed may change */
  4649. qib_write_kreg_port(ppd, krp_tx_deemph_override,
  4650. SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  4651. reset_tx_deemphasis_override));
  4652. qib_cancel_sends(ppd);
  4653. /* on link down, ensure sane pcs state */
  4654. qib_7322_mini_pcs_reset(ppd);
  4655. spin_lock_irqsave(&ppd->sdma_lock, flags);
  4656. if (__qib_sdma_running(ppd))
  4657. __qib_sdma_process_event(ppd,
  4658. qib_sdma_event_e70_go_idle);
  4659. spin_unlock_irqrestore(&ppd->sdma_lock, flags);
  4660. }
  4661. clr = read_7322_creg32_port(ppd, crp_iblinkdown);
  4662. if (clr == ppd->cpspec->iblnkdownsnap)
  4663. ppd->cpspec->iblnkdowndelta++;
  4664. } else {
  4665. if (qib_compat_ddr_negotiate &&
  4666. !(ppd->lflags & (QIBL_IB_AUTONEG_FAILED |
  4667. QIBL_IB_AUTONEG_INPROG)) &&
  4668. ppd->link_speed_active == QIB_IB_SDR &&
  4669. (ppd->link_speed_enabled & QIB_IB_DDR)
  4670. && ppd->cpspec->autoneg_tries < AUTONEG_TRIES) {
  4671. /* we are SDR, and auto-negotiation enabled */
  4672. ++ppd->cpspec->autoneg_tries;
  4673. if (!ppd->cpspec->ibdeltainprog) {
  4674. ppd->cpspec->ibdeltainprog = 1;
  4675. ppd->cpspec->ibsymdelta +=
  4676. read_7322_creg32_port(ppd,
  4677. crp_ibsymbolerr) -
  4678. ppd->cpspec->ibsymsnap;
  4679. ppd->cpspec->iblnkerrdelta +=
  4680. read_7322_creg32_port(ppd,
  4681. crp_iblinkerrrecov) -
  4682. ppd->cpspec->iblnkerrsnap;
  4683. }
  4684. try_7322_autoneg(ppd);
  4685. ret = 1; /* no other IB status change processing */
  4686. } else if ((ppd->lflags & QIBL_IB_AUTONEG_INPROG) &&
  4687. ppd->link_speed_active == QIB_IB_SDR) {
  4688. qib_autoneg_7322_send(ppd, 1);
  4689. set_7322_ibspeed_fast(ppd, QIB_IB_DDR);
  4690. qib_7322_mini_pcs_reset(ppd);
  4691. udelay(2);
  4692. ret = 1; /* no other IB status change processing */
  4693. } else if ((ppd->lflags & QIBL_IB_AUTONEG_INPROG) &&
  4694. (ppd->link_speed_active & QIB_IB_DDR)) {
  4695. spin_lock_irqsave(&ppd->lflags_lock, flags);
  4696. ppd->lflags &= ~(QIBL_IB_AUTONEG_INPROG |
  4697. QIBL_IB_AUTONEG_FAILED);
  4698. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  4699. ppd->cpspec->autoneg_tries = 0;
  4700. /* re-enable SDR, for next link down */
  4701. set_7322_ibspeed_fast(ppd, ppd->link_speed_enabled);
  4702. wake_up(&ppd->cpspec->autoneg_wait);
  4703. symadj = 1;
  4704. } else if (ppd->lflags & QIBL_IB_AUTONEG_FAILED) {
  4705. /*
  4706. * Clear autoneg failure flag, and do setup
  4707. * so we'll try next time link goes down and
  4708. * back to INIT (possibly connected to a
  4709. * different device).
  4710. */
  4711. spin_lock_irqsave(&ppd->lflags_lock, flags);
  4712. ppd->lflags &= ~QIBL_IB_AUTONEG_FAILED;
  4713. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  4714. ppd->cpspec->ibcctrl_b |= IBA7322_IBC_IBTA_1_2_MASK;
  4715. symadj = 1;
  4716. }
  4717. if (!(ppd->lflags & QIBL_IB_AUTONEG_INPROG)) {
  4718. symadj = 1;
  4719. if (ppd->dd->cspec->r1 && ppd->cpspec->ipg_tries <= 10)
  4720. try_7322_ipg(ppd);
  4721. if (!ppd->cpspec->recovery_init)
  4722. setup_7322_link_recovery(ppd, 0);
  4723. ppd->cpspec->qdr_dfe_time = jiffies +
  4724. msecs_to_jiffies(QDR_DFE_DISABLE_DELAY);
  4725. }
  4726. ppd->cpspec->ibmalfusesnap = 0;
  4727. ppd->cpspec->ibmalfsnap = read_7322_creg32_port(ppd,
  4728. crp_errlink);
  4729. }
  4730. if (symadj) {
  4731. ppd->cpspec->iblnkdownsnap =
  4732. read_7322_creg32_port(ppd, crp_iblinkdown);
  4733. if (ppd->cpspec->ibdeltainprog) {
  4734. ppd->cpspec->ibdeltainprog = 0;
  4735. ppd->cpspec->ibsymdelta += read_7322_creg32_port(ppd,
  4736. crp_ibsymbolerr) - ppd->cpspec->ibsymsnap;
  4737. ppd->cpspec->iblnkerrdelta += read_7322_creg32_port(ppd,
  4738. crp_iblinkerrrecov) - ppd->cpspec->iblnkerrsnap;
  4739. }
  4740. } else if (!ibup && qib_compat_ddr_negotiate &&
  4741. !ppd->cpspec->ibdeltainprog &&
  4742. !(ppd->lflags & QIBL_IB_AUTONEG_INPROG)) {
  4743. ppd->cpspec->ibdeltainprog = 1;
  4744. ppd->cpspec->ibsymsnap = read_7322_creg32_port(ppd,
  4745. crp_ibsymbolerr);
  4746. ppd->cpspec->iblnkerrsnap = read_7322_creg32_port(ppd,
  4747. crp_iblinkerrrecov);
  4748. }
  4749. if (!ret)
  4750. qib_setup_7322_setextled(ppd, ibup);
  4751. return ret;
  4752. }
  4753. /*
  4754. * Does read/modify/write to appropriate registers to
  4755. * set output and direction bits selected by mask.
  4756. * these are in their canonical postions (e.g. lsb of
  4757. * dir will end up in D48 of extctrl on existing chips).
  4758. * returns contents of GP Inputs.
  4759. */
  4760. static int gpio_7322_mod(struct qib_devdata *dd, u32 out, u32 dir, u32 mask)
  4761. {
  4762. u64 read_val, new_out;
  4763. unsigned long flags;
  4764. if (mask) {
  4765. /* some bits being written, lock access to GPIO */
  4766. dir &= mask;
  4767. out &= mask;
  4768. spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
  4769. dd->cspec->extctrl &= ~((u64)mask << SYM_LSB(EXTCtrl, GPIOOe));
  4770. dd->cspec->extctrl |= ((u64) dir << SYM_LSB(EXTCtrl, GPIOOe));
  4771. new_out = (dd->cspec->gpio_out & ~mask) | out;
  4772. qib_write_kreg(dd, kr_extctrl, dd->cspec->extctrl);
  4773. qib_write_kreg(dd, kr_gpio_out, new_out);
  4774. dd->cspec->gpio_out = new_out;
  4775. spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
  4776. }
  4777. /*
  4778. * It is unlikely that a read at this time would get valid
  4779. * data on a pin whose direction line was set in the same
  4780. * call to this function. We include the read here because
  4781. * that allows us to potentially combine a change on one pin with
  4782. * a read on another, and because the old code did something like
  4783. * this.
  4784. */
  4785. read_val = qib_read_kreg64(dd, kr_extstatus);
  4786. return SYM_FIELD(read_val, EXTStatus, GPIOIn);
  4787. }
  4788. /* Enable writes to config EEPROM, if possible. Returns previous state */
  4789. static int qib_7322_eeprom_wen(struct qib_devdata *dd, int wen)
  4790. {
  4791. int prev_wen;
  4792. u32 mask;
  4793. mask = 1 << QIB_EEPROM_WEN_NUM;
  4794. prev_wen = ~gpio_7322_mod(dd, 0, 0, 0) >> QIB_EEPROM_WEN_NUM;
  4795. gpio_7322_mod(dd, wen ? 0 : mask, mask, mask);
  4796. return prev_wen & 1;
  4797. }
  4798. /*
  4799. * Read fundamental info we need to use the chip. These are
  4800. * the registers that describe chip capabilities, and are
  4801. * saved in shadow registers.
  4802. */
  4803. static void get_7322_chip_params(struct qib_devdata *dd)
  4804. {
  4805. u64 val;
  4806. u32 piobufs;
  4807. int mtu;
  4808. dd->palign = qib_read_kreg32(dd, kr_pagealign);
  4809. dd->uregbase = qib_read_kreg32(dd, kr_userregbase);
  4810. dd->rcvtidcnt = qib_read_kreg32(dd, kr_rcvtidcnt);
  4811. dd->rcvtidbase = qib_read_kreg32(dd, kr_rcvtidbase);
  4812. dd->rcvegrbase = qib_read_kreg32(dd, kr_rcvegrbase);
  4813. dd->piobufbase = qib_read_kreg64(dd, kr_sendpiobufbase);
  4814. dd->pio2k_bufbase = dd->piobufbase & 0xffffffff;
  4815. val = qib_read_kreg64(dd, kr_sendpiobufcnt);
  4816. dd->piobcnt2k = val & ~0U;
  4817. dd->piobcnt4k = val >> 32;
  4818. val = qib_read_kreg64(dd, kr_sendpiosize);
  4819. dd->piosize2k = val & ~0U;
  4820. dd->piosize4k = val >> 32;
  4821. mtu = ib_mtu_enum_to_int(qib_ibmtu);
  4822. if (mtu == -1)
  4823. mtu = QIB_DEFAULT_MTU;
  4824. dd->pport[0].ibmtu = (u32)mtu;
  4825. dd->pport[1].ibmtu = (u32)mtu;
  4826. /* these may be adjusted in init_chip_wc_pat() */
  4827. dd->pio2kbase = (u32 __iomem *)
  4828. ((char __iomem *) dd->kregbase + dd->pio2k_bufbase);
  4829. dd->pio4kbase = (u32 __iomem *)
  4830. ((char __iomem *) dd->kregbase +
  4831. (dd->piobufbase >> 32));
  4832. /*
  4833. * 4K buffers take 2 pages; we use roundup just to be
  4834. * paranoid; we calculate it once here, rather than on
  4835. * ever buf allocate
  4836. */
  4837. dd->align4k = ALIGN(dd->piosize4k, dd->palign);
  4838. piobufs = dd->piobcnt4k + dd->piobcnt2k + NUM_VL15_BUFS;
  4839. dd->pioavregs = ALIGN(piobufs, sizeof(u64) * BITS_PER_BYTE / 2) /
  4840. (sizeof(u64) * BITS_PER_BYTE / 2);
  4841. }
  4842. /*
  4843. * The chip base addresses in cspec and cpspec have to be set
  4844. * after possible init_chip_wc_pat(), rather than in
  4845. * get_7322_chip_params(), so split out as separate function
  4846. */
  4847. static void qib_7322_set_baseaddrs(struct qib_devdata *dd)
  4848. {
  4849. u32 cregbase;
  4850. cregbase = qib_read_kreg32(dd, kr_counterregbase);
  4851. dd->cspec->cregbase = (u64 __iomem *)(cregbase +
  4852. (char __iomem *)dd->kregbase);
  4853. dd->egrtidbase = (u64 __iomem *)
  4854. ((char __iomem *) dd->kregbase + dd->rcvegrbase);
  4855. /* port registers are defined as relative to base of chip */
  4856. dd->pport[0].cpspec->kpregbase =
  4857. (u64 __iomem *)((char __iomem *)dd->kregbase);
  4858. dd->pport[1].cpspec->kpregbase =
  4859. (u64 __iomem *)(dd->palign +
  4860. (char __iomem *)dd->kregbase);
  4861. dd->pport[0].cpspec->cpregbase =
  4862. (u64 __iomem *)(qib_read_kreg_port(&dd->pport[0],
  4863. kr_counterregbase) + (char __iomem *)dd->kregbase);
  4864. dd->pport[1].cpspec->cpregbase =
  4865. (u64 __iomem *)(qib_read_kreg_port(&dd->pport[1],
  4866. kr_counterregbase) + (char __iomem *)dd->kregbase);
  4867. }
  4868. /*
  4869. * This is a fairly special-purpose observer, so we only support
  4870. * the port-specific parts of SendCtrl
  4871. */
  4872. #define SENDCTRL_SHADOWED (SYM_MASK(SendCtrl_0, SendEnable) | \
  4873. SYM_MASK(SendCtrl_0, SDmaEnable) | \
  4874. SYM_MASK(SendCtrl_0, SDmaIntEnable) | \
  4875. SYM_MASK(SendCtrl_0, SDmaSingleDescriptor) | \
  4876. SYM_MASK(SendCtrl_0, SDmaHalt) | \
  4877. SYM_MASK(SendCtrl_0, IBVLArbiterEn) | \
  4878. SYM_MASK(SendCtrl_0, ForceCreditUpToDate))
  4879. static int sendctrl_hook(struct qib_devdata *dd,
  4880. const struct diag_observer *op, u32 offs,
  4881. u64 *data, u64 mask, int only_32)
  4882. {
  4883. unsigned long flags;
  4884. unsigned idx;
  4885. unsigned pidx;
  4886. struct qib_pportdata *ppd = NULL;
  4887. u64 local_data, all_bits;
  4888. /*
  4889. * The fixed correspondence between Physical ports and pports is
  4890. * severed. We need to hunt for the ppd that corresponds
  4891. * to the offset we got. And we have to do that without admitting
  4892. * we know the stride, apparently.
  4893. */
  4894. for (pidx = 0; pidx < dd->num_pports; ++pidx) {
  4895. u64 __iomem *psptr;
  4896. u32 psoffs;
  4897. ppd = dd->pport + pidx;
  4898. if (!ppd->cpspec->kpregbase)
  4899. continue;
  4900. psptr = ppd->cpspec->kpregbase + krp_sendctrl;
  4901. psoffs = (u32) (psptr - dd->kregbase) * sizeof(*psptr);
  4902. if (psoffs == offs)
  4903. break;
  4904. }
  4905. /* If pport is not being managed by driver, just avoid shadows. */
  4906. if (pidx >= dd->num_pports)
  4907. ppd = NULL;
  4908. /* In any case, "idx" is flat index in kreg space */
  4909. idx = offs / sizeof(u64);
  4910. all_bits = ~0ULL;
  4911. if (only_32)
  4912. all_bits >>= 32;
  4913. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  4914. if (!ppd || (mask & all_bits) != all_bits) {
  4915. /*
  4916. * At least some mask bits are zero, so we need
  4917. * to read. The judgement call is whether from
  4918. * reg or shadow. First-cut: read reg, and complain
  4919. * if any bits which should be shadowed are different
  4920. * from their shadowed value.
  4921. */
  4922. if (only_32)
  4923. local_data = (u64)qib_read_kreg32(dd, idx);
  4924. else
  4925. local_data = qib_read_kreg64(dd, idx);
  4926. *data = (local_data & ~mask) | (*data & mask);
  4927. }
  4928. if (mask) {
  4929. /*
  4930. * At least some mask bits are one, so we need
  4931. * to write, but only shadow some bits.
  4932. */
  4933. u64 sval, tval; /* Shadowed, transient */
  4934. /*
  4935. * New shadow val is bits we don't want to touch,
  4936. * ORed with bits we do, that are intended for shadow.
  4937. */
  4938. if (ppd) {
  4939. sval = ppd->p_sendctrl & ~mask;
  4940. sval |= *data & SENDCTRL_SHADOWED & mask;
  4941. ppd->p_sendctrl = sval;
  4942. } else
  4943. sval = *data & SENDCTRL_SHADOWED & mask;
  4944. tval = sval | (*data & ~SENDCTRL_SHADOWED & mask);
  4945. qib_write_kreg(dd, idx, tval);
  4946. qib_write_kreg(dd, kr_scratch, 0Ull);
  4947. }
  4948. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  4949. return only_32 ? 4 : 8;
  4950. }
  4951. static const struct diag_observer sendctrl_0_observer = {
  4952. sendctrl_hook, KREG_IDX(SendCtrl_0) * sizeof(u64),
  4953. KREG_IDX(SendCtrl_0) * sizeof(u64)
  4954. };
  4955. static const struct diag_observer sendctrl_1_observer = {
  4956. sendctrl_hook, KREG_IDX(SendCtrl_1) * sizeof(u64),
  4957. KREG_IDX(SendCtrl_1) * sizeof(u64)
  4958. };
  4959. static ushort sdma_fetch_prio = 8;
  4960. module_param_named(sdma_fetch_prio, sdma_fetch_prio, ushort, S_IRUGO);
  4961. MODULE_PARM_DESC(sdma_fetch_prio, "SDMA descriptor fetch priority");
  4962. /* Besides logging QSFP events, we set appropriate TxDDS values */
  4963. static void init_txdds_table(struct qib_pportdata *ppd, int override);
  4964. static void qsfp_7322_event(struct work_struct *work)
  4965. {
  4966. struct qib_qsfp_data *qd;
  4967. struct qib_pportdata *ppd;
  4968. u64 pwrup;
  4969. int ret;
  4970. u32 le2;
  4971. qd = container_of(work, struct qib_qsfp_data, work);
  4972. ppd = qd->ppd;
  4973. pwrup = qd->t_insert + msecs_to_jiffies(QSFP_PWR_LAG_MSEC);
  4974. /*
  4975. * Some QSFP's not only do not respond until the full power-up
  4976. * time, but may behave badly if we try. So hold off responding
  4977. * to insertion.
  4978. */
  4979. while (1) {
  4980. u64 now = get_jiffies_64();
  4981. if (time_after64(now, pwrup))
  4982. break;
  4983. msleep(20);
  4984. }
  4985. ret = qib_refresh_qsfp_cache(ppd, &qd->cache);
  4986. /*
  4987. * Need to change LE2 back to defaults if we couldn't
  4988. * read the cable type (to handle cable swaps), so do this
  4989. * even on failure to read cable information. We don't
  4990. * get here for QME, so IS_QME check not needed here.
  4991. */
  4992. if (!ret && !ppd->dd->cspec->r1) {
  4993. if (QSFP_IS_ACTIVE_FAR(qd->cache.tech))
  4994. le2 = LE2_QME;
  4995. else if (qd->cache.atten[1] >= qib_long_atten &&
  4996. QSFP_IS_CU(qd->cache.tech))
  4997. le2 = LE2_5m;
  4998. else
  4999. le2 = LE2_DEFAULT;
  5000. } else
  5001. le2 = LE2_DEFAULT;
  5002. ibsd_wr_allchans(ppd, 13, (le2 << 7), BMASK(9, 7));
  5003. init_txdds_table(ppd, 0);
  5004. }
  5005. /*
  5006. * There is little we can do but complain to the user if QSFP
  5007. * initialization fails.
  5008. */
  5009. static void qib_init_7322_qsfp(struct qib_pportdata *ppd)
  5010. {
  5011. unsigned long flags;
  5012. struct qib_qsfp_data *qd = &ppd->cpspec->qsfp_data;
  5013. struct qib_devdata *dd = ppd->dd;
  5014. u64 mod_prs_bit = QSFP_GPIO_MOD_PRS_N;
  5015. mod_prs_bit <<= (QSFP_GPIO_PORT2_SHIFT * ppd->hw_pidx);
  5016. qd->ppd = ppd;
  5017. qib_qsfp_init(qd, qsfp_7322_event);
  5018. spin_lock_irqsave(&dd->cspec->gpio_lock, flags);
  5019. dd->cspec->extctrl |= (mod_prs_bit << SYM_LSB(EXTCtrl, GPIOInvert));
  5020. dd->cspec->gpio_mask |= mod_prs_bit;
  5021. qib_write_kreg(dd, kr_extctrl, dd->cspec->extctrl);
  5022. qib_write_kreg(dd, kr_gpio_mask, dd->cspec->gpio_mask);
  5023. spin_unlock_irqrestore(&dd->cspec->gpio_lock, flags);
  5024. }
  5025. /*
  5026. * called at device initialization time, and also if the txselect
  5027. * module parameter is changed. This is used for cables that don't
  5028. * have valid QSFP EEPROMs (not present, or attenuation is zero).
  5029. * We initialize to the default, then if there is a specific
  5030. * unit,port match, we use that (and set it immediately, for the
  5031. * current speed, if the link is at INIT or better).
  5032. * String format is "default# unit#,port#=# ... u,p=#", separators must
  5033. * be a SPACE character. A newline terminates. The u,p=# tuples may
  5034. * optionally have "u,p=#,#", where the final # is the H1 value
  5035. * The last specific match is used (actually, all are used, but last
  5036. * one is the one that winds up set); if none at all, fall back on default.
  5037. */
  5038. static void set_no_qsfp_atten(struct qib_devdata *dd, int change)
  5039. {
  5040. char *nxt, *str;
  5041. u32 pidx, unit, port, deflt, h1;
  5042. unsigned long val;
  5043. int any = 0, seth1;
  5044. int txdds_size;
  5045. str = txselect_list;
  5046. /* default number is validated in setup_txselect() */
  5047. deflt = simple_strtoul(str, &nxt, 0);
  5048. for (pidx = 0; pidx < dd->num_pports; ++pidx)
  5049. dd->pport[pidx].cpspec->no_eep = deflt;
  5050. txdds_size = TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ;
  5051. if (IS_QME(dd) || IS_QMH(dd))
  5052. txdds_size += TXDDS_MFG_SZ;
  5053. while (*nxt && nxt[1]) {
  5054. str = ++nxt;
  5055. unit = simple_strtoul(str, &nxt, 0);
  5056. if (nxt == str || !*nxt || *nxt != ',') {
  5057. while (*nxt && *nxt++ != ' ') /* skip to next, if any */
  5058. ;
  5059. continue;
  5060. }
  5061. str = ++nxt;
  5062. port = simple_strtoul(str, &nxt, 0);
  5063. if (nxt == str || *nxt != '=') {
  5064. while (*nxt && *nxt++ != ' ') /* skip to next, if any */
  5065. ;
  5066. continue;
  5067. }
  5068. str = ++nxt;
  5069. val = simple_strtoul(str, &nxt, 0);
  5070. if (nxt == str) {
  5071. while (*nxt && *nxt++ != ' ') /* skip to next, if any */
  5072. ;
  5073. continue;
  5074. }
  5075. if (val >= txdds_size)
  5076. continue;
  5077. seth1 = 0;
  5078. h1 = 0; /* gcc thinks it might be used uninitted */
  5079. if (*nxt == ',' && nxt[1]) {
  5080. str = ++nxt;
  5081. h1 = (u32)simple_strtoul(str, &nxt, 0);
  5082. if (nxt == str)
  5083. while (*nxt && *nxt++ != ' ') /* skip */
  5084. ;
  5085. else
  5086. seth1 = 1;
  5087. }
  5088. for (pidx = 0; dd->unit == unit && pidx < dd->num_pports;
  5089. ++pidx) {
  5090. struct qib_pportdata *ppd = &dd->pport[pidx];
  5091. if (ppd->port != port || !ppd->link_speed_supported)
  5092. continue;
  5093. ppd->cpspec->no_eep = val;
  5094. if (seth1)
  5095. ppd->cpspec->h1_val = h1;
  5096. /* now change the IBC and serdes, overriding generic */
  5097. init_txdds_table(ppd, 1);
  5098. /* Re-enable the physical state machine on mezz boards
  5099. * now that the correct settings have been set. */
  5100. if (IS_QMH(dd) || IS_QME(dd))
  5101. qib_set_ib_7322_lstate(ppd, 0,
  5102. QLOGIC_IB_IBCC_LINKINITCMD_SLEEP);
  5103. any++;
  5104. }
  5105. if (*nxt == '\n')
  5106. break; /* done */
  5107. }
  5108. if (change && !any) {
  5109. /* no specific setting, use the default.
  5110. * Change the IBC and serdes, but since it's
  5111. * general, don't override specific settings.
  5112. */
  5113. for (pidx = 0; pidx < dd->num_pports; ++pidx)
  5114. if (dd->pport[pidx].link_speed_supported)
  5115. init_txdds_table(&dd->pport[pidx], 0);
  5116. }
  5117. }
  5118. /* handle the txselect parameter changing */
  5119. static int setup_txselect(const char *str, struct kernel_param *kp)
  5120. {
  5121. struct qib_devdata *dd;
  5122. unsigned long val;
  5123. char *n;
  5124. if (strlen(str) >= MAX_ATTEN_LEN) {
  5125. printk(KERN_INFO QIB_DRV_NAME " txselect_values string "
  5126. "too long\n");
  5127. return -ENOSPC;
  5128. }
  5129. val = simple_strtoul(str, &n, 0);
  5130. if (n == str || val >= (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ +
  5131. TXDDS_MFG_SZ)) {
  5132. printk(KERN_INFO QIB_DRV_NAME
  5133. "txselect_values must start with a number < %d\n",
  5134. TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ + TXDDS_MFG_SZ);
  5135. return -EINVAL;
  5136. }
  5137. strcpy(txselect_list, str);
  5138. list_for_each_entry(dd, &qib_dev_list, list)
  5139. if (dd->deviceid == PCI_DEVICE_ID_QLOGIC_IB_7322)
  5140. set_no_qsfp_atten(dd, 1);
  5141. return 0;
  5142. }
  5143. /*
  5144. * Write the final few registers that depend on some of the
  5145. * init setup. Done late in init, just before bringing up
  5146. * the serdes.
  5147. */
  5148. static int qib_late_7322_initreg(struct qib_devdata *dd)
  5149. {
  5150. int ret = 0, n;
  5151. u64 val;
  5152. qib_write_kreg(dd, kr_rcvhdrentsize, dd->rcvhdrentsize);
  5153. qib_write_kreg(dd, kr_rcvhdrsize, dd->rcvhdrsize);
  5154. qib_write_kreg(dd, kr_rcvhdrcnt, dd->rcvhdrcnt);
  5155. qib_write_kreg(dd, kr_sendpioavailaddr, dd->pioavailregs_phys);
  5156. val = qib_read_kreg64(dd, kr_sendpioavailaddr);
  5157. if (val != dd->pioavailregs_phys) {
  5158. qib_dev_err(dd, "Catastrophic software error, "
  5159. "SendPIOAvailAddr written as %lx, "
  5160. "read back as %llx\n",
  5161. (unsigned long) dd->pioavailregs_phys,
  5162. (unsigned long long) val);
  5163. ret = -EINVAL;
  5164. }
  5165. n = dd->piobcnt2k + dd->piobcnt4k + NUM_VL15_BUFS;
  5166. qib_7322_txchk_change(dd, 0, n, TXCHK_CHG_TYPE_KERN, NULL);
  5167. /* driver sends get pkey, lid, etc. checking also, to catch bugs */
  5168. qib_7322_txchk_change(dd, 0, n, TXCHK_CHG_TYPE_ENAB1, NULL);
  5169. qib_register_observer(dd, &sendctrl_0_observer);
  5170. qib_register_observer(dd, &sendctrl_1_observer);
  5171. dd->control &= ~QLOGIC_IB_C_SDMAFETCHPRIOEN;
  5172. qib_write_kreg(dd, kr_control, dd->control);
  5173. /*
  5174. * Set SendDmaFetchPriority and init Tx params, including
  5175. * QSFP handler on boards that have QSFP.
  5176. * First set our default attenuation entry for cables that
  5177. * don't have valid attenuation.
  5178. */
  5179. set_no_qsfp_atten(dd, 0);
  5180. for (n = 0; n < dd->num_pports; ++n) {
  5181. struct qib_pportdata *ppd = dd->pport + n;
  5182. qib_write_kreg_port(ppd, krp_senddmaprioritythld,
  5183. sdma_fetch_prio & 0xf);
  5184. /* Initialize qsfp if present on board. */
  5185. if (dd->flags & QIB_HAS_QSFP)
  5186. qib_init_7322_qsfp(ppd);
  5187. }
  5188. dd->control |= QLOGIC_IB_C_SDMAFETCHPRIOEN;
  5189. qib_write_kreg(dd, kr_control, dd->control);
  5190. return ret;
  5191. }
  5192. /* per IB port errors. */
  5193. #define SENDCTRL_PIBP (MASK_ACROSS(0, 1) | MASK_ACROSS(3, 3) | \
  5194. MASK_ACROSS(8, 15))
  5195. #define RCVCTRL_PIBP (MASK_ACROSS(0, 17) | MASK_ACROSS(39, 41))
  5196. #define ERRS_PIBP (MASK_ACROSS(57, 58) | MASK_ACROSS(54, 54) | \
  5197. MASK_ACROSS(36, 49) | MASK_ACROSS(29, 34) | MASK_ACROSS(14, 17) | \
  5198. MASK_ACROSS(0, 11))
  5199. /*
  5200. * Write the initialization per-port registers that need to be done at
  5201. * driver load and after reset completes (i.e., that aren't done as part
  5202. * of other init procedures called from qib_init.c).
  5203. * Some of these should be redundant on reset, but play safe.
  5204. */
  5205. static void write_7322_init_portregs(struct qib_pportdata *ppd)
  5206. {
  5207. u64 val;
  5208. int i;
  5209. if (!ppd->link_speed_supported) {
  5210. /* no buffer credits for this port */
  5211. for (i = 1; i < 8; i++)
  5212. qib_write_kreg_port(ppd, krp_rxcreditvl0 + i, 0);
  5213. qib_write_kreg_port(ppd, krp_ibcctrl_b, 0);
  5214. qib_write_kreg(ppd->dd, kr_scratch, 0);
  5215. return;
  5216. }
  5217. /*
  5218. * Set the number of supported virtual lanes in IBC,
  5219. * for flow control packet handling on unsupported VLs
  5220. */
  5221. val = qib_read_kreg_port(ppd, krp_ibsdtestiftx);
  5222. val &= ~SYM_MASK(IB_SDTEST_IF_TX_0, VL_CAP);
  5223. val |= (u64)(ppd->vls_supported - 1) <<
  5224. SYM_LSB(IB_SDTEST_IF_TX_0, VL_CAP);
  5225. qib_write_kreg_port(ppd, krp_ibsdtestiftx, val);
  5226. qib_write_kreg_port(ppd, krp_rcvbthqp, QIB_KD_QP);
  5227. /* enable tx header checking */
  5228. qib_write_kreg_port(ppd, krp_sendcheckcontrol, IBA7322_SENDCHK_PKEY |
  5229. IBA7322_SENDCHK_BTHQP | IBA7322_SENDCHK_SLID |
  5230. IBA7322_SENDCHK_RAW_IPV6 | IBA7322_SENDCHK_MINSZ);
  5231. qib_write_kreg_port(ppd, krp_ncmodectrl,
  5232. SYM_MASK(IBNCModeCtrl_0, ScrambleCapLocal));
  5233. /*
  5234. * Unconditionally clear the bufmask bits. If SDMA is
  5235. * enabled, we'll set them appropriately later.
  5236. */
  5237. qib_write_kreg_port(ppd, krp_senddmabufmask0, 0);
  5238. qib_write_kreg_port(ppd, krp_senddmabufmask1, 0);
  5239. qib_write_kreg_port(ppd, krp_senddmabufmask2, 0);
  5240. if (ppd->dd->cspec->r1)
  5241. ppd->p_sendctrl |= SYM_MASK(SendCtrl_0, ForceCreditUpToDate);
  5242. }
  5243. /*
  5244. * Write the initialization per-device registers that need to be done at
  5245. * driver load and after reset completes (i.e., that aren't done as part
  5246. * of other init procedures called from qib_init.c). Also write per-port
  5247. * registers that are affected by overall device config, such as QP mapping
  5248. * Some of these should be redundant on reset, but play safe.
  5249. */
  5250. static void write_7322_initregs(struct qib_devdata *dd)
  5251. {
  5252. struct qib_pportdata *ppd;
  5253. int i, pidx;
  5254. u64 val;
  5255. /* Set Multicast QPs received by port 2 to map to context one. */
  5256. qib_write_kreg(dd, KREG_IDX(RcvQPMulticastContext_1), 1);
  5257. for (pidx = 0; pidx < dd->num_pports; ++pidx) {
  5258. unsigned n, regno;
  5259. unsigned long flags;
  5260. if (dd->n_krcv_queues < 2 ||
  5261. !dd->pport[pidx].link_speed_supported)
  5262. continue;
  5263. ppd = &dd->pport[pidx];
  5264. /* be paranoid against later code motion, etc. */
  5265. spin_lock_irqsave(&dd->cspec->rcvmod_lock, flags);
  5266. ppd->p_rcvctrl |= SYM_MASK(RcvCtrl_0, RcvQPMapEnable);
  5267. spin_unlock_irqrestore(&dd->cspec->rcvmod_lock, flags);
  5268. /* Initialize QP to context mapping */
  5269. regno = krp_rcvqpmaptable;
  5270. val = 0;
  5271. if (dd->num_pports > 1)
  5272. n = dd->first_user_ctxt / dd->num_pports;
  5273. else
  5274. n = dd->first_user_ctxt - 1;
  5275. for (i = 0; i < 32; ) {
  5276. unsigned ctxt;
  5277. if (dd->num_pports > 1)
  5278. ctxt = (i % n) * dd->num_pports + pidx;
  5279. else if (i % n)
  5280. ctxt = (i % n) + 1;
  5281. else
  5282. ctxt = ppd->hw_pidx;
  5283. val |= ctxt << (5 * (i % 6));
  5284. i++;
  5285. if (i % 6 == 0) {
  5286. qib_write_kreg_port(ppd, regno, val);
  5287. val = 0;
  5288. regno++;
  5289. }
  5290. }
  5291. qib_write_kreg_port(ppd, regno, val);
  5292. }
  5293. /*
  5294. * Setup up interrupt mitigation for kernel contexts, but
  5295. * not user contexts (user contexts use interrupts when
  5296. * stalled waiting for any packet, so want those interrupts
  5297. * right away).
  5298. */
  5299. for (i = 0; i < dd->first_user_ctxt; i++) {
  5300. dd->cspec->rcvavail_timeout[i] = rcv_int_timeout;
  5301. qib_write_kreg(dd, kr_rcvavailtimeout + i, rcv_int_timeout);
  5302. }
  5303. /*
  5304. * Initialize as (disabled) rcvflow tables. Application code
  5305. * will setup each flow as it uses the flow.
  5306. * Doesn't clear any of the error bits that might be set.
  5307. */
  5308. val = TIDFLOW_ERRBITS; /* these are W1C */
  5309. for (i = 0; i < dd->cfgctxts; i++) {
  5310. int flow;
  5311. for (flow = 0; flow < NUM_TIDFLOWS_CTXT; flow++)
  5312. qib_write_ureg(dd, ur_rcvflowtable+flow, val, i);
  5313. }
  5314. /*
  5315. * dual cards init to dual port recovery, single port cards to
  5316. * the one port. Dual port cards may later adjust to 1 port,
  5317. * and then back to dual port if both ports are connected
  5318. * */
  5319. if (dd->num_pports)
  5320. setup_7322_link_recovery(dd->pport, dd->num_pports > 1);
  5321. }
  5322. static int qib_init_7322_variables(struct qib_devdata *dd)
  5323. {
  5324. struct qib_pportdata *ppd;
  5325. unsigned features, pidx, sbufcnt;
  5326. int ret, mtu;
  5327. u32 sbufs, updthresh;
  5328. /* pport structs are contiguous, allocated after devdata */
  5329. ppd = (struct qib_pportdata *)(dd + 1);
  5330. dd->pport = ppd;
  5331. ppd[0].dd = dd;
  5332. ppd[1].dd = dd;
  5333. dd->cspec = (struct qib_chip_specific *)(ppd + 2);
  5334. ppd[0].cpspec = (struct qib_chippport_specific *)(dd->cspec + 1);
  5335. ppd[1].cpspec = &ppd[0].cpspec[1];
  5336. ppd[0].cpspec->ppd = &ppd[0]; /* for autoneg_7322_work() */
  5337. ppd[1].cpspec->ppd = &ppd[1]; /* for autoneg_7322_work() */
  5338. spin_lock_init(&dd->cspec->rcvmod_lock);
  5339. spin_lock_init(&dd->cspec->gpio_lock);
  5340. /* we haven't yet set QIB_PRESENT, so use read directly */
  5341. dd->revision = readq(&dd->kregbase[kr_revision]);
  5342. if ((dd->revision & 0xffffffffU) == 0xffffffffU) {
  5343. qib_dev_err(dd, "Revision register read failure, "
  5344. "giving up initialization\n");
  5345. ret = -ENODEV;
  5346. goto bail;
  5347. }
  5348. dd->flags |= QIB_PRESENT; /* now register routines work */
  5349. dd->majrev = (u8) SYM_FIELD(dd->revision, Revision_R, ChipRevMajor);
  5350. dd->minrev = (u8) SYM_FIELD(dd->revision, Revision_R, ChipRevMinor);
  5351. dd->cspec->r1 = dd->minrev == 1;
  5352. get_7322_chip_params(dd);
  5353. features = qib_7322_boardname(dd);
  5354. /* now that piobcnt2k and 4k set, we can allocate these */
  5355. sbufcnt = dd->piobcnt2k + dd->piobcnt4k +
  5356. NUM_VL15_BUFS + BITS_PER_LONG - 1;
  5357. sbufcnt /= BITS_PER_LONG;
  5358. dd->cspec->sendchkenable = kmalloc(sbufcnt *
  5359. sizeof(*dd->cspec->sendchkenable), GFP_KERNEL);
  5360. dd->cspec->sendgrhchk = kmalloc(sbufcnt *
  5361. sizeof(*dd->cspec->sendgrhchk), GFP_KERNEL);
  5362. dd->cspec->sendibchk = kmalloc(sbufcnt *
  5363. sizeof(*dd->cspec->sendibchk), GFP_KERNEL);
  5364. if (!dd->cspec->sendchkenable || !dd->cspec->sendgrhchk ||
  5365. !dd->cspec->sendibchk) {
  5366. qib_dev_err(dd, "Failed allocation for hdrchk bitmaps\n");
  5367. ret = -ENOMEM;
  5368. goto bail;
  5369. }
  5370. ppd = dd->pport;
  5371. /*
  5372. * GPIO bits for TWSI data and clock,
  5373. * used for serial EEPROM.
  5374. */
  5375. dd->gpio_sda_num = _QIB_GPIO_SDA_NUM;
  5376. dd->gpio_scl_num = _QIB_GPIO_SCL_NUM;
  5377. dd->twsi_eeprom_dev = QIB_TWSI_EEPROM_DEV;
  5378. dd->flags |= QIB_HAS_INTX | QIB_HAS_LINK_LATENCY |
  5379. QIB_NODMA_RTAIL | QIB_HAS_VLSUPP | QIB_HAS_HDRSUPP |
  5380. QIB_HAS_THRESH_UPDATE |
  5381. (sdma_idle_cnt ? QIB_HAS_SDMA_TIMEOUT : 0);
  5382. dd->flags |= qib_special_trigger ?
  5383. QIB_USE_SPCL_TRIG : QIB_HAS_SEND_DMA;
  5384. /*
  5385. * Setup initial values. These may change when PAT is enabled, but
  5386. * we need these to do initial chip register accesses.
  5387. */
  5388. qib_7322_set_baseaddrs(dd);
  5389. mtu = ib_mtu_enum_to_int(qib_ibmtu);
  5390. if (mtu == -1)
  5391. mtu = QIB_DEFAULT_MTU;
  5392. dd->cspec->int_enable_mask = QIB_I_BITSEXTANT;
  5393. /* all hwerrors become interrupts, unless special purposed */
  5394. dd->cspec->hwerrmask = ~0ULL;
  5395. /* link_recovery setup causes these errors, so ignore them,
  5396. * other than clearing them when they occur */
  5397. dd->cspec->hwerrmask &=
  5398. ~(SYM_MASK(HwErrMask, IBSerdesPClkNotDetectMask_0) |
  5399. SYM_MASK(HwErrMask, IBSerdesPClkNotDetectMask_1) |
  5400. HWE_MASK(LATriggered));
  5401. for (pidx = 0; pidx < NUM_IB_PORTS; ++pidx) {
  5402. struct qib_chippport_specific *cp = ppd->cpspec;
  5403. ppd->link_speed_supported = features & PORT_SPD_CAP;
  5404. features >>= PORT_SPD_CAP_SHIFT;
  5405. if (!ppd->link_speed_supported) {
  5406. /* single port mode (7340, or configured) */
  5407. dd->skip_kctxt_mask |= 1 << pidx;
  5408. if (pidx == 0) {
  5409. /* Make sure port is disabled. */
  5410. qib_write_kreg_port(ppd, krp_rcvctrl, 0);
  5411. qib_write_kreg_port(ppd, krp_ibcctrl_a, 0);
  5412. ppd[0] = ppd[1];
  5413. dd->cspec->hwerrmask &= ~(SYM_MASK(HwErrMask,
  5414. IBSerdesPClkNotDetectMask_0)
  5415. | SYM_MASK(HwErrMask,
  5416. SDmaMemReadErrMask_0));
  5417. dd->cspec->int_enable_mask &= ~(
  5418. SYM_MASK(IntMask, SDmaCleanupDoneMask_0) |
  5419. SYM_MASK(IntMask, SDmaIdleIntMask_0) |
  5420. SYM_MASK(IntMask, SDmaProgressIntMask_0) |
  5421. SYM_MASK(IntMask, SDmaIntMask_0) |
  5422. SYM_MASK(IntMask, ErrIntMask_0) |
  5423. SYM_MASK(IntMask, SendDoneIntMask_0));
  5424. } else {
  5425. /* Make sure port is disabled. */
  5426. qib_write_kreg_port(ppd, krp_rcvctrl, 0);
  5427. qib_write_kreg_port(ppd, krp_ibcctrl_a, 0);
  5428. dd->cspec->hwerrmask &= ~(SYM_MASK(HwErrMask,
  5429. IBSerdesPClkNotDetectMask_1)
  5430. | SYM_MASK(HwErrMask,
  5431. SDmaMemReadErrMask_1));
  5432. dd->cspec->int_enable_mask &= ~(
  5433. SYM_MASK(IntMask, SDmaCleanupDoneMask_1) |
  5434. SYM_MASK(IntMask, SDmaIdleIntMask_1) |
  5435. SYM_MASK(IntMask, SDmaProgressIntMask_1) |
  5436. SYM_MASK(IntMask, SDmaIntMask_1) |
  5437. SYM_MASK(IntMask, ErrIntMask_1) |
  5438. SYM_MASK(IntMask, SendDoneIntMask_1));
  5439. }
  5440. continue;
  5441. }
  5442. dd->num_pports++;
  5443. qib_init_pportdata(ppd, dd, pidx, dd->num_pports);
  5444. ppd->link_width_supported = IB_WIDTH_1X | IB_WIDTH_4X;
  5445. ppd->link_width_enabled = IB_WIDTH_4X;
  5446. ppd->link_speed_enabled = ppd->link_speed_supported;
  5447. /*
  5448. * Set the initial values to reasonable default, will be set
  5449. * for real when link is up.
  5450. */
  5451. ppd->link_width_active = IB_WIDTH_4X;
  5452. ppd->link_speed_active = QIB_IB_SDR;
  5453. ppd->delay_mult = ib_rate_to_delay[IB_RATE_10_GBPS];
  5454. switch (qib_num_cfg_vls) {
  5455. case 1:
  5456. ppd->vls_supported = IB_VL_VL0;
  5457. break;
  5458. case 2:
  5459. ppd->vls_supported = IB_VL_VL0_1;
  5460. break;
  5461. default:
  5462. qib_devinfo(dd->pcidev,
  5463. "Invalid num_vls %u, using 4 VLs\n",
  5464. qib_num_cfg_vls);
  5465. qib_num_cfg_vls = 4;
  5466. /* fall through */
  5467. case 4:
  5468. ppd->vls_supported = IB_VL_VL0_3;
  5469. break;
  5470. case 8:
  5471. if (mtu <= 2048)
  5472. ppd->vls_supported = IB_VL_VL0_7;
  5473. else {
  5474. qib_devinfo(dd->pcidev,
  5475. "Invalid num_vls %u for MTU %d "
  5476. ", using 4 VLs\n",
  5477. qib_num_cfg_vls, mtu);
  5478. ppd->vls_supported = IB_VL_VL0_3;
  5479. qib_num_cfg_vls = 4;
  5480. }
  5481. break;
  5482. }
  5483. ppd->vls_operational = ppd->vls_supported;
  5484. init_waitqueue_head(&cp->autoneg_wait);
  5485. INIT_DELAYED_WORK(&cp->autoneg_work,
  5486. autoneg_7322_work);
  5487. if (ppd->dd->cspec->r1)
  5488. INIT_DELAYED_WORK(&cp->ipg_work, ipg_7322_work);
  5489. /*
  5490. * For Mez and similar cards, no qsfp info, so do
  5491. * the "cable info" setup here. Can be overridden
  5492. * in adapter-specific routines.
  5493. */
  5494. if (!(dd->flags & QIB_HAS_QSFP)) {
  5495. if (!IS_QMH(dd) && !IS_QME(dd))
  5496. qib_devinfo(dd->pcidev, "IB%u:%u: "
  5497. "Unknown mezzanine card type\n",
  5498. dd->unit, ppd->port);
  5499. cp->h1_val = IS_QMH(dd) ? H1_FORCE_QMH : H1_FORCE_QME;
  5500. /*
  5501. * Choose center value as default tx serdes setting
  5502. * until changed through module parameter.
  5503. */
  5504. ppd->cpspec->no_eep = IS_QMH(dd) ?
  5505. TXDDS_TABLE_SZ + 2 : TXDDS_TABLE_SZ + 4;
  5506. } else
  5507. cp->h1_val = H1_FORCE_VAL;
  5508. /* Avoid writes to chip for mini_init */
  5509. if (!qib_mini_init)
  5510. write_7322_init_portregs(ppd);
  5511. init_timer(&cp->chase_timer);
  5512. cp->chase_timer.function = reenable_chase;
  5513. cp->chase_timer.data = (unsigned long)ppd;
  5514. ppd++;
  5515. }
  5516. dd->rcvhdrentsize = qib_rcvhdrentsize ?
  5517. qib_rcvhdrentsize : QIB_RCVHDR_ENTSIZE;
  5518. dd->rcvhdrsize = qib_rcvhdrsize ?
  5519. qib_rcvhdrsize : QIB_DFLT_RCVHDRSIZE;
  5520. dd->rhf_offset = dd->rcvhdrentsize - sizeof(u64) / sizeof(u32);
  5521. /* we always allocate at least 2048 bytes for eager buffers */
  5522. dd->rcvegrbufsize = max(mtu, 2048);
  5523. qib_7322_tidtemplate(dd);
  5524. /*
  5525. * We can request a receive interrupt for 1 or
  5526. * more packets from current offset.
  5527. */
  5528. dd->rhdrhead_intr_off =
  5529. (u64) rcv_int_count << IBA7322_HDRHEAD_PKTINT_SHIFT;
  5530. /* setup the stats timer; the add_timer is done at end of init */
  5531. init_timer(&dd->stats_timer);
  5532. dd->stats_timer.function = qib_get_7322_faststats;
  5533. dd->stats_timer.data = (unsigned long) dd;
  5534. dd->ureg_align = 0x10000; /* 64KB alignment */
  5535. dd->piosize2kmax_dwords = dd->piosize2k >> 2;
  5536. qib_7322_config_ctxts(dd);
  5537. qib_set_ctxtcnt(dd);
  5538. if (qib_wc_pat) {
  5539. resource_size_t vl15off;
  5540. /*
  5541. * We do not set WC on the VL15 buffers to avoid
  5542. * a rare problem with unaligned writes from
  5543. * interrupt-flushed store buffers, so we need
  5544. * to map those separately here. We can't solve
  5545. * this for the rarely used mtrr case.
  5546. */
  5547. ret = init_chip_wc_pat(dd, 0);
  5548. if (ret)
  5549. goto bail;
  5550. /* vl15 buffers start just after the 4k buffers */
  5551. vl15off = dd->physaddr + (dd->piobufbase >> 32) +
  5552. dd->piobcnt4k * dd->align4k;
  5553. dd->piovl15base = ioremap_nocache(vl15off,
  5554. NUM_VL15_BUFS * dd->align4k);
  5555. if (!dd->piovl15base)
  5556. goto bail;
  5557. }
  5558. qib_7322_set_baseaddrs(dd); /* set chip access pointers now */
  5559. ret = 0;
  5560. if (qib_mini_init)
  5561. goto bail;
  5562. if (!dd->num_pports) {
  5563. qib_dev_err(dd, "No ports enabled, giving up initialization\n");
  5564. goto bail; /* no error, so can still figure out why err */
  5565. }
  5566. write_7322_initregs(dd);
  5567. ret = qib_create_ctxts(dd);
  5568. init_7322_cntrnames(dd);
  5569. updthresh = 8U; /* update threshold */
  5570. /* use all of 4KB buffers for the kernel SDMA, zero if !SDMA.
  5571. * reserve the update threshold amount for other kernel use, such
  5572. * as sending SMI, MAD, and ACKs, or 3, whichever is greater,
  5573. * unless we aren't enabling SDMA, in which case we want to use
  5574. * all the 4k bufs for the kernel.
  5575. * if this was less than the update threshold, we could wait
  5576. * a long time for an update. Coded this way because we
  5577. * sometimes change the update threshold for various reasons,
  5578. * and we want this to remain robust.
  5579. */
  5580. if (dd->flags & QIB_HAS_SEND_DMA) {
  5581. dd->cspec->sdmabufcnt = dd->piobcnt4k;
  5582. sbufs = updthresh > 3 ? updthresh : 3;
  5583. } else {
  5584. dd->cspec->sdmabufcnt = 0;
  5585. sbufs = dd->piobcnt4k;
  5586. }
  5587. dd->cspec->lastbuf_for_pio = dd->piobcnt2k + dd->piobcnt4k -
  5588. dd->cspec->sdmabufcnt;
  5589. dd->lastctxt_piobuf = dd->cspec->lastbuf_for_pio - sbufs;
  5590. dd->cspec->lastbuf_for_pio--; /* range is <= , not < */
  5591. dd->pbufsctxt = (dd->cfgctxts > dd->first_user_ctxt) ?
  5592. dd->lastctxt_piobuf / (dd->cfgctxts - dd->first_user_ctxt) : 0;
  5593. /*
  5594. * If we have 16 user contexts, we will have 7 sbufs
  5595. * per context, so reduce the update threshold to match. We
  5596. * want to update before we actually run out, at low pbufs/ctxt
  5597. * so give ourselves some margin.
  5598. */
  5599. if (dd->pbufsctxt >= 2 && dd->pbufsctxt - 2 < updthresh)
  5600. updthresh = dd->pbufsctxt - 2;
  5601. dd->cspec->updthresh_dflt = updthresh;
  5602. dd->cspec->updthresh = updthresh;
  5603. /* before full enable, no interrupts, no locking needed */
  5604. dd->sendctrl |= ((updthresh & SYM_RMASK(SendCtrl, AvailUpdThld))
  5605. << SYM_LSB(SendCtrl, AvailUpdThld)) |
  5606. SYM_MASK(SendCtrl, SendBufAvailPad64Byte);
  5607. dd->psxmitwait_supported = 1;
  5608. dd->psxmitwait_check_rate = QIB_7322_PSXMITWAIT_CHECK_RATE;
  5609. bail:
  5610. if (!dd->ctxtcnt)
  5611. dd->ctxtcnt = 1; /* for other initialization code */
  5612. return ret;
  5613. }
  5614. static u32 __iomem *qib_7322_getsendbuf(struct qib_pportdata *ppd, u64 pbc,
  5615. u32 *pbufnum)
  5616. {
  5617. u32 first, last, plen = pbc & QIB_PBC_LENGTH_MASK;
  5618. struct qib_devdata *dd = ppd->dd;
  5619. /* last is same for 2k and 4k, because we use 4k if all 2k busy */
  5620. if (pbc & PBC_7322_VL15_SEND) {
  5621. first = dd->piobcnt2k + dd->piobcnt4k + ppd->hw_pidx;
  5622. last = first;
  5623. } else {
  5624. if ((plen + 1) > dd->piosize2kmax_dwords)
  5625. first = dd->piobcnt2k;
  5626. else
  5627. first = 0;
  5628. last = dd->cspec->lastbuf_for_pio;
  5629. }
  5630. return qib_getsendbuf_range(dd, pbufnum, first, last);
  5631. }
  5632. static void qib_set_cntr_7322_sample(struct qib_pportdata *ppd, u32 intv,
  5633. u32 start)
  5634. {
  5635. qib_write_kreg_port(ppd, krp_psinterval, intv);
  5636. qib_write_kreg_port(ppd, krp_psstart, start);
  5637. }
  5638. /*
  5639. * Must be called with sdma_lock held, or before init finished.
  5640. */
  5641. static void qib_sdma_set_7322_desc_cnt(struct qib_pportdata *ppd, unsigned cnt)
  5642. {
  5643. qib_write_kreg_port(ppd, krp_senddmadesccnt, cnt);
  5644. }
  5645. static struct sdma_set_state_action sdma_7322_action_table[] = {
  5646. [qib_sdma_state_s00_hw_down] = {
  5647. .go_s99_running_tofalse = 1,
  5648. .op_enable = 0,
  5649. .op_intenable = 0,
  5650. .op_halt = 0,
  5651. .op_drain = 0,
  5652. },
  5653. [qib_sdma_state_s10_hw_start_up_wait] = {
  5654. .op_enable = 0,
  5655. .op_intenable = 1,
  5656. .op_halt = 1,
  5657. .op_drain = 0,
  5658. },
  5659. [qib_sdma_state_s20_idle] = {
  5660. .op_enable = 1,
  5661. .op_intenable = 1,
  5662. .op_halt = 1,
  5663. .op_drain = 0,
  5664. },
  5665. [qib_sdma_state_s30_sw_clean_up_wait] = {
  5666. .op_enable = 0,
  5667. .op_intenable = 1,
  5668. .op_halt = 1,
  5669. .op_drain = 0,
  5670. },
  5671. [qib_sdma_state_s40_hw_clean_up_wait] = {
  5672. .op_enable = 1,
  5673. .op_intenable = 1,
  5674. .op_halt = 1,
  5675. .op_drain = 0,
  5676. },
  5677. [qib_sdma_state_s50_hw_halt_wait] = {
  5678. .op_enable = 1,
  5679. .op_intenable = 1,
  5680. .op_halt = 1,
  5681. .op_drain = 1,
  5682. },
  5683. [qib_sdma_state_s99_running] = {
  5684. .op_enable = 1,
  5685. .op_intenable = 1,
  5686. .op_halt = 0,
  5687. .op_drain = 0,
  5688. .go_s99_running_totrue = 1,
  5689. },
  5690. };
  5691. static void qib_7322_sdma_init_early(struct qib_pportdata *ppd)
  5692. {
  5693. ppd->sdma_state.set_state_action = sdma_7322_action_table;
  5694. }
  5695. static int init_sdma_7322_regs(struct qib_pportdata *ppd)
  5696. {
  5697. struct qib_devdata *dd = ppd->dd;
  5698. unsigned lastbuf, erstbuf;
  5699. u64 senddmabufmask[3] = { 0 };
  5700. int n, ret = 0;
  5701. qib_write_kreg_port(ppd, krp_senddmabase, ppd->sdma_descq_phys);
  5702. qib_sdma_7322_setlengen(ppd);
  5703. qib_sdma_update_7322_tail(ppd, 0); /* Set SendDmaTail */
  5704. qib_write_kreg_port(ppd, krp_senddmareloadcnt, sdma_idle_cnt);
  5705. qib_write_kreg_port(ppd, krp_senddmadesccnt, 0);
  5706. qib_write_kreg_port(ppd, krp_senddmaheadaddr, ppd->sdma_head_phys);
  5707. if (dd->num_pports)
  5708. n = dd->cspec->sdmabufcnt / dd->num_pports; /* no remainder */
  5709. else
  5710. n = dd->cspec->sdmabufcnt; /* failsafe for init */
  5711. erstbuf = (dd->piobcnt2k + dd->piobcnt4k) -
  5712. ((dd->num_pports == 1 || ppd->port == 2) ? n :
  5713. dd->cspec->sdmabufcnt);
  5714. lastbuf = erstbuf + n;
  5715. ppd->sdma_state.first_sendbuf = erstbuf;
  5716. ppd->sdma_state.last_sendbuf = lastbuf;
  5717. for (; erstbuf < lastbuf; ++erstbuf) {
  5718. unsigned word = erstbuf / BITS_PER_LONG;
  5719. unsigned bit = erstbuf & (BITS_PER_LONG - 1);
  5720. BUG_ON(word >= 3);
  5721. senddmabufmask[word] |= 1ULL << bit;
  5722. }
  5723. qib_write_kreg_port(ppd, krp_senddmabufmask0, senddmabufmask[0]);
  5724. qib_write_kreg_port(ppd, krp_senddmabufmask1, senddmabufmask[1]);
  5725. qib_write_kreg_port(ppd, krp_senddmabufmask2, senddmabufmask[2]);
  5726. return ret;
  5727. }
  5728. /* sdma_lock must be held */
  5729. static u16 qib_sdma_7322_gethead(struct qib_pportdata *ppd)
  5730. {
  5731. struct qib_devdata *dd = ppd->dd;
  5732. int sane;
  5733. int use_dmahead;
  5734. u16 swhead;
  5735. u16 swtail;
  5736. u16 cnt;
  5737. u16 hwhead;
  5738. use_dmahead = __qib_sdma_running(ppd) &&
  5739. (dd->flags & QIB_HAS_SDMA_TIMEOUT);
  5740. retry:
  5741. hwhead = use_dmahead ?
  5742. (u16) le64_to_cpu(*ppd->sdma_head_dma) :
  5743. (u16) qib_read_kreg_port(ppd, krp_senddmahead);
  5744. swhead = ppd->sdma_descq_head;
  5745. swtail = ppd->sdma_descq_tail;
  5746. cnt = ppd->sdma_descq_cnt;
  5747. if (swhead < swtail)
  5748. /* not wrapped */
  5749. sane = (hwhead >= swhead) & (hwhead <= swtail);
  5750. else if (swhead > swtail)
  5751. /* wrapped around */
  5752. sane = ((hwhead >= swhead) && (hwhead < cnt)) ||
  5753. (hwhead <= swtail);
  5754. else
  5755. /* empty */
  5756. sane = (hwhead == swhead);
  5757. if (unlikely(!sane)) {
  5758. if (use_dmahead) {
  5759. /* try one more time, directly from the register */
  5760. use_dmahead = 0;
  5761. goto retry;
  5762. }
  5763. /* proceed as if no progress */
  5764. hwhead = swhead;
  5765. }
  5766. return hwhead;
  5767. }
  5768. static int qib_sdma_7322_busy(struct qib_pportdata *ppd)
  5769. {
  5770. u64 hwstatus = qib_read_kreg_port(ppd, krp_senddmastatus);
  5771. return (hwstatus & SYM_MASK(SendDmaStatus_0, ScoreBoardDrainInProg)) ||
  5772. (hwstatus & SYM_MASK(SendDmaStatus_0, HaltInProg)) ||
  5773. !(hwstatus & SYM_MASK(SendDmaStatus_0, InternalSDmaHalt)) ||
  5774. !(hwstatus & SYM_MASK(SendDmaStatus_0, ScbEmpty));
  5775. }
  5776. /*
  5777. * Compute the amount of delay before sending the next packet if the
  5778. * port's send rate differs from the static rate set for the QP.
  5779. * The delay affects the next packet and the amount of the delay is
  5780. * based on the length of the this packet.
  5781. */
  5782. static u32 qib_7322_setpbc_control(struct qib_pportdata *ppd, u32 plen,
  5783. u8 srate, u8 vl)
  5784. {
  5785. u8 snd_mult = ppd->delay_mult;
  5786. u8 rcv_mult = ib_rate_to_delay[srate];
  5787. u32 ret;
  5788. ret = rcv_mult > snd_mult ? ((plen + 1) >> 1) * snd_mult : 0;
  5789. /* Indicate VL15, else set the VL in the control word */
  5790. if (vl == 15)
  5791. ret |= PBC_7322_VL15_SEND_CTRL;
  5792. else
  5793. ret |= vl << PBC_VL_NUM_LSB;
  5794. ret |= ((u32)(ppd->hw_pidx)) << PBC_PORT_SEL_LSB;
  5795. return ret;
  5796. }
  5797. /*
  5798. * Enable the per-port VL15 send buffers for use.
  5799. * They follow the rest of the buffers, without a config parameter.
  5800. * This was in initregs, but that is done before the shadow
  5801. * is set up, and this has to be done after the shadow is
  5802. * set up.
  5803. */
  5804. static void qib_7322_initvl15_bufs(struct qib_devdata *dd)
  5805. {
  5806. unsigned vl15bufs;
  5807. vl15bufs = dd->piobcnt2k + dd->piobcnt4k;
  5808. qib_chg_pioavailkernel(dd, vl15bufs, NUM_VL15_BUFS,
  5809. TXCHK_CHG_TYPE_KERN, NULL);
  5810. }
  5811. static void qib_7322_init_ctxt(struct qib_ctxtdata *rcd)
  5812. {
  5813. if (rcd->ctxt < NUM_IB_PORTS) {
  5814. if (rcd->dd->num_pports > 1) {
  5815. rcd->rcvegrcnt = KCTXT0_EGRCNT / 2;
  5816. rcd->rcvegr_tid_base = rcd->ctxt ? rcd->rcvegrcnt : 0;
  5817. } else {
  5818. rcd->rcvegrcnt = KCTXT0_EGRCNT;
  5819. rcd->rcvegr_tid_base = 0;
  5820. }
  5821. } else {
  5822. rcd->rcvegrcnt = rcd->dd->cspec->rcvegrcnt;
  5823. rcd->rcvegr_tid_base = KCTXT0_EGRCNT +
  5824. (rcd->ctxt - NUM_IB_PORTS) * rcd->rcvegrcnt;
  5825. }
  5826. }
  5827. #define QTXSLEEPS 5000
  5828. static void qib_7322_txchk_change(struct qib_devdata *dd, u32 start,
  5829. u32 len, u32 which, struct qib_ctxtdata *rcd)
  5830. {
  5831. int i;
  5832. const int last = start + len - 1;
  5833. const int lastr = last / BITS_PER_LONG;
  5834. u32 sleeps = 0;
  5835. int wait = rcd != NULL;
  5836. unsigned long flags;
  5837. while (wait) {
  5838. unsigned long shadow;
  5839. int cstart, previ = -1;
  5840. /*
  5841. * when flipping from kernel to user, we can't change
  5842. * the checking type if the buffer is allocated to the
  5843. * driver. It's OK the other direction, because it's
  5844. * from close, and we have just disarm'ed all the
  5845. * buffers. All the kernel to kernel changes are also
  5846. * OK.
  5847. */
  5848. for (cstart = start; cstart <= last; cstart++) {
  5849. i = ((2 * cstart) + QLOGIC_IB_SENDPIOAVAIL_BUSY_SHIFT)
  5850. / BITS_PER_LONG;
  5851. if (i != previ) {
  5852. shadow = (unsigned long)
  5853. le64_to_cpu(dd->pioavailregs_dma[i]);
  5854. previ = i;
  5855. }
  5856. if (test_bit(((2 * cstart) +
  5857. QLOGIC_IB_SENDPIOAVAIL_BUSY_SHIFT)
  5858. % BITS_PER_LONG, &shadow))
  5859. break;
  5860. }
  5861. if (cstart > last)
  5862. break;
  5863. if (sleeps == QTXSLEEPS)
  5864. break;
  5865. /* make sure we see an updated copy next time around */
  5866. sendctrl_7322_mod(dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
  5867. sleeps++;
  5868. msleep(20);
  5869. }
  5870. switch (which) {
  5871. case TXCHK_CHG_TYPE_DIS1:
  5872. /*
  5873. * disable checking on a range; used by diags; just
  5874. * one buffer, but still written generically
  5875. */
  5876. for (i = start; i <= last; i++)
  5877. clear_bit(i, dd->cspec->sendchkenable);
  5878. break;
  5879. case TXCHK_CHG_TYPE_ENAB1:
  5880. /*
  5881. * (re)enable checking on a range; used by diags; just
  5882. * one buffer, but still written generically; read
  5883. * scratch to be sure buffer actually triggered, not
  5884. * just flushed from processor.
  5885. */
  5886. qib_read_kreg32(dd, kr_scratch);
  5887. for (i = start; i <= last; i++)
  5888. set_bit(i, dd->cspec->sendchkenable);
  5889. break;
  5890. case TXCHK_CHG_TYPE_KERN:
  5891. /* usable by kernel */
  5892. for (i = start; i <= last; i++) {
  5893. set_bit(i, dd->cspec->sendibchk);
  5894. clear_bit(i, dd->cspec->sendgrhchk);
  5895. }
  5896. spin_lock_irqsave(&dd->uctxt_lock, flags);
  5897. /* see if we need to raise avail update threshold */
  5898. for (i = dd->first_user_ctxt;
  5899. dd->cspec->updthresh != dd->cspec->updthresh_dflt
  5900. && i < dd->cfgctxts; i++)
  5901. if (dd->rcd[i] && dd->rcd[i]->subctxt_cnt &&
  5902. ((dd->rcd[i]->piocnt / dd->rcd[i]->subctxt_cnt) - 1)
  5903. < dd->cspec->updthresh_dflt)
  5904. break;
  5905. spin_unlock_irqrestore(&dd->uctxt_lock, flags);
  5906. if (i == dd->cfgctxts) {
  5907. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  5908. dd->cspec->updthresh = dd->cspec->updthresh_dflt;
  5909. dd->sendctrl &= ~SYM_MASK(SendCtrl, AvailUpdThld);
  5910. dd->sendctrl |= (dd->cspec->updthresh &
  5911. SYM_RMASK(SendCtrl, AvailUpdThld)) <<
  5912. SYM_LSB(SendCtrl, AvailUpdThld);
  5913. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  5914. sendctrl_7322_mod(dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
  5915. }
  5916. break;
  5917. case TXCHK_CHG_TYPE_USER:
  5918. /* for user process */
  5919. for (i = start; i <= last; i++) {
  5920. clear_bit(i, dd->cspec->sendibchk);
  5921. set_bit(i, dd->cspec->sendgrhchk);
  5922. }
  5923. spin_lock_irqsave(&dd->sendctrl_lock, flags);
  5924. if (rcd && rcd->subctxt_cnt && ((rcd->piocnt
  5925. / rcd->subctxt_cnt) - 1) < dd->cspec->updthresh) {
  5926. dd->cspec->updthresh = (rcd->piocnt /
  5927. rcd->subctxt_cnt) - 1;
  5928. dd->sendctrl &= ~SYM_MASK(SendCtrl, AvailUpdThld);
  5929. dd->sendctrl |= (dd->cspec->updthresh &
  5930. SYM_RMASK(SendCtrl, AvailUpdThld))
  5931. << SYM_LSB(SendCtrl, AvailUpdThld);
  5932. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  5933. sendctrl_7322_mod(dd->pport, QIB_SENDCTRL_AVAIL_BLIP);
  5934. } else
  5935. spin_unlock_irqrestore(&dd->sendctrl_lock, flags);
  5936. break;
  5937. default:
  5938. break;
  5939. }
  5940. for (i = start / BITS_PER_LONG; which >= 2 && i <= lastr; ++i)
  5941. qib_write_kreg(dd, kr_sendcheckmask + i,
  5942. dd->cspec->sendchkenable[i]);
  5943. for (i = start / BITS_PER_LONG; which < 2 && i <= lastr; ++i) {
  5944. qib_write_kreg(dd, kr_sendgrhcheckmask + i,
  5945. dd->cspec->sendgrhchk[i]);
  5946. qib_write_kreg(dd, kr_sendibpktmask + i,
  5947. dd->cspec->sendibchk[i]);
  5948. }
  5949. /*
  5950. * Be sure whatever we did was seen by the chip and acted upon,
  5951. * before we return. Mostly important for which >= 2.
  5952. */
  5953. qib_read_kreg32(dd, kr_scratch);
  5954. }
  5955. /* useful for trigger analyzers, etc. */
  5956. static void writescratch(struct qib_devdata *dd, u32 val)
  5957. {
  5958. qib_write_kreg(dd, kr_scratch, val);
  5959. }
  5960. /* Dummy for now, use chip regs soon */
  5961. static int qib_7322_tempsense_rd(struct qib_devdata *dd, int regnum)
  5962. {
  5963. return -ENXIO;
  5964. }
  5965. /**
  5966. * qib_init_iba7322_funcs - set up the chip-specific function pointers
  5967. * @dev: the pci_dev for qlogic_ib device
  5968. * @ent: pci_device_id struct for this dev
  5969. *
  5970. * Also allocates, inits, and returns the devdata struct for this
  5971. * device instance
  5972. *
  5973. * This is global, and is called directly at init to set up the
  5974. * chip-specific function pointers for later use.
  5975. */
  5976. struct qib_devdata *qib_init_iba7322_funcs(struct pci_dev *pdev,
  5977. const struct pci_device_id *ent)
  5978. {
  5979. struct qib_devdata *dd;
  5980. int ret, i;
  5981. u32 tabsize, actual_cnt = 0;
  5982. dd = qib_alloc_devdata(pdev,
  5983. NUM_IB_PORTS * sizeof(struct qib_pportdata) +
  5984. sizeof(struct qib_chip_specific) +
  5985. NUM_IB_PORTS * sizeof(struct qib_chippport_specific));
  5986. if (IS_ERR(dd))
  5987. goto bail;
  5988. dd->f_bringup_serdes = qib_7322_bringup_serdes;
  5989. dd->f_cleanup = qib_setup_7322_cleanup;
  5990. dd->f_clear_tids = qib_7322_clear_tids;
  5991. dd->f_free_irq = qib_7322_free_irq;
  5992. dd->f_get_base_info = qib_7322_get_base_info;
  5993. dd->f_get_msgheader = qib_7322_get_msgheader;
  5994. dd->f_getsendbuf = qib_7322_getsendbuf;
  5995. dd->f_gpio_mod = gpio_7322_mod;
  5996. dd->f_eeprom_wen = qib_7322_eeprom_wen;
  5997. dd->f_hdrqempty = qib_7322_hdrqempty;
  5998. dd->f_ib_updown = qib_7322_ib_updown;
  5999. dd->f_init_ctxt = qib_7322_init_ctxt;
  6000. dd->f_initvl15_bufs = qib_7322_initvl15_bufs;
  6001. dd->f_intr_fallback = qib_7322_intr_fallback;
  6002. dd->f_late_initreg = qib_late_7322_initreg;
  6003. dd->f_setpbc_control = qib_7322_setpbc_control;
  6004. dd->f_portcntr = qib_portcntr_7322;
  6005. dd->f_put_tid = qib_7322_put_tid;
  6006. dd->f_quiet_serdes = qib_7322_mini_quiet_serdes;
  6007. dd->f_rcvctrl = rcvctrl_7322_mod;
  6008. dd->f_read_cntrs = qib_read_7322cntrs;
  6009. dd->f_read_portcntrs = qib_read_7322portcntrs;
  6010. dd->f_reset = qib_do_7322_reset;
  6011. dd->f_init_sdma_regs = init_sdma_7322_regs;
  6012. dd->f_sdma_busy = qib_sdma_7322_busy;
  6013. dd->f_sdma_gethead = qib_sdma_7322_gethead;
  6014. dd->f_sdma_sendctrl = qib_7322_sdma_sendctrl;
  6015. dd->f_sdma_set_desc_cnt = qib_sdma_set_7322_desc_cnt;
  6016. dd->f_sdma_update_tail = qib_sdma_update_7322_tail;
  6017. dd->f_sendctrl = sendctrl_7322_mod;
  6018. dd->f_set_armlaunch = qib_set_7322_armlaunch;
  6019. dd->f_set_cntr_sample = qib_set_cntr_7322_sample;
  6020. dd->f_iblink_state = qib_7322_iblink_state;
  6021. dd->f_ibphys_portstate = qib_7322_phys_portstate;
  6022. dd->f_get_ib_cfg = qib_7322_get_ib_cfg;
  6023. dd->f_set_ib_cfg = qib_7322_set_ib_cfg;
  6024. dd->f_set_ib_loopback = qib_7322_set_loopback;
  6025. dd->f_get_ib_table = qib_7322_get_ib_table;
  6026. dd->f_set_ib_table = qib_7322_set_ib_table;
  6027. dd->f_set_intr_state = qib_7322_set_intr_state;
  6028. dd->f_setextled = qib_setup_7322_setextled;
  6029. dd->f_txchk_change = qib_7322_txchk_change;
  6030. dd->f_update_usrhead = qib_update_7322_usrhead;
  6031. dd->f_wantpiobuf_intr = qib_wantpiobuf_7322_intr;
  6032. dd->f_xgxs_reset = qib_7322_mini_pcs_reset;
  6033. dd->f_sdma_hw_clean_up = qib_7322_sdma_hw_clean_up;
  6034. dd->f_sdma_hw_start_up = qib_7322_sdma_hw_start_up;
  6035. dd->f_sdma_init_early = qib_7322_sdma_init_early;
  6036. dd->f_writescratch = writescratch;
  6037. dd->f_tempsense_rd = qib_7322_tempsense_rd;
  6038. /*
  6039. * Do remaining PCIe setup and save PCIe values in dd.
  6040. * Any error printing is already done by the init code.
  6041. * On return, we have the chip mapped, but chip registers
  6042. * are not set up until start of qib_init_7322_variables.
  6043. */
  6044. ret = qib_pcie_ddinit(dd, pdev, ent);
  6045. if (ret < 0)
  6046. goto bail_free;
  6047. /* initialize chip-specific variables */
  6048. ret = qib_init_7322_variables(dd);
  6049. if (ret)
  6050. goto bail_cleanup;
  6051. if (qib_mini_init || !dd->num_pports)
  6052. goto bail;
  6053. /*
  6054. * Determine number of vectors we want; depends on port count
  6055. * and number of configured kernel receive queues actually used.
  6056. * Should also depend on whether sdma is enabled or not, but
  6057. * that's such a rare testing case it's not worth worrying about.
  6058. */
  6059. tabsize = dd->first_user_ctxt + ARRAY_SIZE(irq_table);
  6060. for (i = 0; i < tabsize; i++)
  6061. if ((i < ARRAY_SIZE(irq_table) &&
  6062. irq_table[i].port <= dd->num_pports) ||
  6063. (i >= ARRAY_SIZE(irq_table) &&
  6064. dd->rcd[i - ARRAY_SIZE(irq_table)]))
  6065. actual_cnt++;
  6066. tabsize = actual_cnt;
  6067. dd->cspec->msix_entries = kmalloc(tabsize *
  6068. sizeof(struct msix_entry), GFP_KERNEL);
  6069. dd->cspec->msix_arg = kmalloc(tabsize *
  6070. sizeof(void *), GFP_KERNEL);
  6071. if (!dd->cspec->msix_entries || !dd->cspec->msix_arg) {
  6072. qib_dev_err(dd, "No memory for MSIx table\n");
  6073. tabsize = 0;
  6074. }
  6075. for (i = 0; i < tabsize; i++)
  6076. dd->cspec->msix_entries[i].entry = i;
  6077. if (qib_pcie_params(dd, 8, &tabsize, dd->cspec->msix_entries))
  6078. qib_dev_err(dd, "Failed to setup PCIe or interrupts; "
  6079. "continuing anyway\n");
  6080. /* may be less than we wanted, if not enough available */
  6081. dd->cspec->num_msix_entries = tabsize;
  6082. /* setup interrupt handler */
  6083. qib_setup_7322_interrupt(dd, 1);
  6084. /* clear diagctrl register, in case diags were running and crashed */
  6085. qib_write_kreg(dd, kr_hwdiagctrl, 0);
  6086. goto bail;
  6087. bail_cleanup:
  6088. qib_pcie_ddcleanup(dd);
  6089. bail_free:
  6090. qib_free_devdata(dd);
  6091. dd = ERR_PTR(ret);
  6092. bail:
  6093. return dd;
  6094. }
  6095. /*
  6096. * Set the table entry at the specified index from the table specifed.
  6097. * There are 3 * TXDDS_TABLE_SZ entries in all per port, with the first
  6098. * TXDDS_TABLE_SZ for SDR, the next for DDR, and the last for QDR.
  6099. * 'idx' below addresses the correct entry, while its 4 LSBs select the
  6100. * corresponding entry (one of TXDDS_TABLE_SZ) from the selected table.
  6101. */
  6102. #define DDS_ENT_AMP_LSB 14
  6103. #define DDS_ENT_MAIN_LSB 9
  6104. #define DDS_ENT_POST_LSB 5
  6105. #define DDS_ENT_PRE_XTRA_LSB 3
  6106. #define DDS_ENT_PRE_LSB 0
  6107. /*
  6108. * Set one entry in the TxDDS table for spec'd port
  6109. * ridx picks one of the entries, while tp points
  6110. * to the appropriate table entry.
  6111. */
  6112. static void set_txdds(struct qib_pportdata *ppd, int ridx,
  6113. const struct txdds_ent *tp)
  6114. {
  6115. struct qib_devdata *dd = ppd->dd;
  6116. u32 pack_ent;
  6117. int regidx;
  6118. /* Get correct offset in chip-space, and in source table */
  6119. regidx = KREG_IBPORT_IDX(IBSD_DDS_MAP_TABLE) + ridx;
  6120. /*
  6121. * We do not use qib_write_kreg_port() because it was intended
  6122. * only for registers in the lower "port specific" pages.
  6123. * So do index calculation by hand.
  6124. */
  6125. if (ppd->hw_pidx)
  6126. regidx += (dd->palign / sizeof(u64));
  6127. pack_ent = tp->amp << DDS_ENT_AMP_LSB;
  6128. pack_ent |= tp->main << DDS_ENT_MAIN_LSB;
  6129. pack_ent |= tp->pre << DDS_ENT_PRE_LSB;
  6130. pack_ent |= tp->post << DDS_ENT_POST_LSB;
  6131. qib_write_kreg(dd, regidx, pack_ent);
  6132. /* Prevent back-to-back writes by hitting scratch */
  6133. qib_write_kreg(ppd->dd, kr_scratch, 0);
  6134. }
  6135. static const struct vendor_txdds_ent vendor_txdds[] = {
  6136. { /* Amphenol 1m 30awg NoEq */
  6137. { 0x41, 0x50, 0x48 }, "584470002 ",
  6138. { 10, 0, 0, 5 }, { 10, 0, 0, 9 }, { 7, 1, 0, 13 },
  6139. },
  6140. { /* Amphenol 3m 28awg NoEq */
  6141. { 0x41, 0x50, 0x48 }, "584470004 ",
  6142. { 0, 0, 0, 8 }, { 0, 0, 0, 11 }, { 0, 1, 7, 15 },
  6143. },
  6144. { /* Finisar 3m OM2 Optical */
  6145. { 0x00, 0x90, 0x65 }, "FCBG410QB1C03-QL",
  6146. { 0, 0, 0, 3 }, { 0, 0, 0, 4 }, { 0, 0, 0, 13 },
  6147. },
  6148. { /* Finisar 30m OM2 Optical */
  6149. { 0x00, 0x90, 0x65 }, "FCBG410QB1C30-QL",
  6150. { 0, 0, 0, 1 }, { 0, 0, 0, 5 }, { 0, 0, 0, 11 },
  6151. },
  6152. { /* Finisar Default OM2 Optical */
  6153. { 0x00, 0x90, 0x65 }, NULL,
  6154. { 0, 0, 0, 2 }, { 0, 0, 0, 5 }, { 0, 0, 0, 12 },
  6155. },
  6156. { /* Gore 1m 30awg NoEq */
  6157. { 0x00, 0x21, 0x77 }, "QSN3300-1 ",
  6158. { 0, 0, 0, 6 }, { 0, 0, 0, 9 }, { 0, 1, 0, 15 },
  6159. },
  6160. { /* Gore 2m 30awg NoEq */
  6161. { 0x00, 0x21, 0x77 }, "QSN3300-2 ",
  6162. { 0, 0, 0, 8 }, { 0, 0, 0, 10 }, { 0, 1, 7, 15 },
  6163. },
  6164. { /* Gore 1m 28awg NoEq */
  6165. { 0x00, 0x21, 0x77 }, "QSN3800-1 ",
  6166. { 0, 0, 0, 6 }, { 0, 0, 0, 8 }, { 0, 1, 0, 15 },
  6167. },
  6168. { /* Gore 3m 28awg NoEq */
  6169. { 0x00, 0x21, 0x77 }, "QSN3800-3 ",
  6170. { 0, 0, 0, 9 }, { 0, 0, 0, 13 }, { 0, 1, 7, 15 },
  6171. },
  6172. { /* Gore 5m 24awg Eq */
  6173. { 0x00, 0x21, 0x77 }, "QSN7000-5 ",
  6174. { 0, 0, 0, 7 }, { 0, 0, 0, 9 }, { 0, 1, 3, 15 },
  6175. },
  6176. { /* Gore 7m 24awg Eq */
  6177. { 0x00, 0x21, 0x77 }, "QSN7000-7 ",
  6178. { 0, 0, 0, 9 }, { 0, 0, 0, 11 }, { 0, 2, 6, 15 },
  6179. },
  6180. { /* Gore 5m 26awg Eq */
  6181. { 0x00, 0x21, 0x77 }, "QSN7600-5 ",
  6182. { 0, 0, 0, 8 }, { 0, 0, 0, 11 }, { 0, 1, 9, 13 },
  6183. },
  6184. { /* Gore 7m 26awg Eq */
  6185. { 0x00, 0x21, 0x77 }, "QSN7600-7 ",
  6186. { 0, 0, 0, 8 }, { 0, 0, 0, 11 }, { 10, 1, 8, 15 },
  6187. },
  6188. { /* Intersil 12m 24awg Active */
  6189. { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP1224",
  6190. { 0, 0, 0, 2 }, { 0, 0, 0, 5 }, { 0, 3, 0, 9 },
  6191. },
  6192. { /* Intersil 10m 28awg Active */
  6193. { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP1028",
  6194. { 0, 0, 0, 6 }, { 0, 0, 0, 4 }, { 0, 2, 0, 2 },
  6195. },
  6196. { /* Intersil 7m 30awg Active */
  6197. { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP0730",
  6198. { 0, 0, 0, 6 }, { 0, 0, 0, 4 }, { 0, 1, 0, 3 },
  6199. },
  6200. { /* Intersil 5m 32awg Active */
  6201. { 0x00, 0x30, 0xB4 }, "QLX4000CQSFP0532",
  6202. { 0, 0, 0, 6 }, { 0, 0, 0, 6 }, { 0, 2, 0, 8 },
  6203. },
  6204. { /* Intersil Default Active */
  6205. { 0x00, 0x30, 0xB4 }, NULL,
  6206. { 0, 0, 0, 6 }, { 0, 0, 0, 5 }, { 0, 2, 0, 5 },
  6207. },
  6208. { /* Luxtera 20m Active Optical */
  6209. { 0x00, 0x25, 0x63 }, NULL,
  6210. { 0, 0, 0, 5 }, { 0, 0, 0, 8 }, { 0, 2, 0, 12 },
  6211. },
  6212. { /* Molex 1M Cu loopback */
  6213. { 0x00, 0x09, 0x3A }, "74763-0025 ",
  6214. { 2, 2, 6, 15 }, { 2, 2, 6, 15 }, { 2, 2, 6, 15 },
  6215. },
  6216. { /* Molex 2m 28awg NoEq */
  6217. { 0x00, 0x09, 0x3A }, "74757-2201 ",
  6218. { 0, 0, 0, 6 }, { 0, 0, 0, 9 }, { 0, 1, 1, 15 },
  6219. },
  6220. };
  6221. static const struct txdds_ent txdds_sdr[TXDDS_TABLE_SZ] = {
  6222. /* amp, pre, main, post */
  6223. { 2, 2, 15, 6 }, /* Loopback */
  6224. { 0, 0, 0, 1 }, /* 2 dB */
  6225. { 0, 0, 0, 2 }, /* 3 dB */
  6226. { 0, 0, 0, 3 }, /* 4 dB */
  6227. { 0, 0, 0, 4 }, /* 5 dB */
  6228. { 0, 0, 0, 5 }, /* 6 dB */
  6229. { 0, 0, 0, 6 }, /* 7 dB */
  6230. { 0, 0, 0, 7 }, /* 8 dB */
  6231. { 0, 0, 0, 8 }, /* 9 dB */
  6232. { 0, 0, 0, 9 }, /* 10 dB */
  6233. { 0, 0, 0, 10 }, /* 11 dB */
  6234. { 0, 0, 0, 11 }, /* 12 dB */
  6235. { 0, 0, 0, 12 }, /* 13 dB */
  6236. { 0, 0, 0, 13 }, /* 14 dB */
  6237. { 0, 0, 0, 14 }, /* 15 dB */
  6238. { 0, 0, 0, 15 }, /* 16 dB */
  6239. };
  6240. static const struct txdds_ent txdds_ddr[TXDDS_TABLE_SZ] = {
  6241. /* amp, pre, main, post */
  6242. { 2, 2, 15, 6 }, /* Loopback */
  6243. { 0, 0, 0, 8 }, /* 2 dB */
  6244. { 0, 0, 0, 8 }, /* 3 dB */
  6245. { 0, 0, 0, 9 }, /* 4 dB */
  6246. { 0, 0, 0, 9 }, /* 5 dB */
  6247. { 0, 0, 0, 10 }, /* 6 dB */
  6248. { 0, 0, 0, 10 }, /* 7 dB */
  6249. { 0, 0, 0, 11 }, /* 8 dB */
  6250. { 0, 0, 0, 11 }, /* 9 dB */
  6251. { 0, 0, 0, 12 }, /* 10 dB */
  6252. { 0, 0, 0, 12 }, /* 11 dB */
  6253. { 0, 0, 0, 13 }, /* 12 dB */
  6254. { 0, 0, 0, 13 }, /* 13 dB */
  6255. { 0, 0, 0, 14 }, /* 14 dB */
  6256. { 0, 0, 0, 14 }, /* 15 dB */
  6257. { 0, 0, 0, 15 }, /* 16 dB */
  6258. };
  6259. static const struct txdds_ent txdds_qdr[TXDDS_TABLE_SZ] = {
  6260. /* amp, pre, main, post */
  6261. { 2, 2, 15, 6 }, /* Loopback */
  6262. { 0, 1, 0, 7 }, /* 2 dB (also QMH7342) */
  6263. { 0, 1, 0, 9 }, /* 3 dB (also QMH7342) */
  6264. { 0, 1, 0, 11 }, /* 4 dB */
  6265. { 0, 1, 0, 13 }, /* 5 dB */
  6266. { 0, 1, 0, 15 }, /* 6 dB */
  6267. { 0, 1, 3, 15 }, /* 7 dB */
  6268. { 0, 1, 7, 15 }, /* 8 dB */
  6269. { 0, 1, 7, 15 }, /* 9 dB */
  6270. { 0, 1, 8, 15 }, /* 10 dB */
  6271. { 0, 1, 9, 15 }, /* 11 dB */
  6272. { 0, 1, 10, 15 }, /* 12 dB */
  6273. { 0, 2, 6, 15 }, /* 13 dB */
  6274. { 0, 2, 7, 15 }, /* 14 dB */
  6275. { 0, 2, 8, 15 }, /* 15 dB */
  6276. { 0, 2, 9, 15 }, /* 16 dB */
  6277. };
  6278. /*
  6279. * extra entries for use with txselect, for indices >= TXDDS_TABLE_SZ.
  6280. * These are mostly used for mez cards going through connectors
  6281. * and backplane traces, but can be used to add other "unusual"
  6282. * table values as well.
  6283. */
  6284. static const struct txdds_ent txdds_extra_sdr[TXDDS_EXTRA_SZ] = {
  6285. /* amp, pre, main, post */
  6286. { 0, 0, 0, 1 }, /* QMH7342 backplane settings */
  6287. { 0, 0, 0, 1 }, /* QMH7342 backplane settings */
  6288. { 0, 0, 0, 2 }, /* QMH7342 backplane settings */
  6289. { 0, 0, 0, 2 }, /* QMH7342 backplane settings */
  6290. { 0, 0, 0, 11 }, /* QME7342 backplane settings */
  6291. { 0, 0, 0, 11 }, /* QME7342 backplane settings */
  6292. { 0, 0, 0, 11 }, /* QME7342 backplane settings */
  6293. { 0, 0, 0, 11 }, /* QME7342 backplane settings */
  6294. { 0, 0, 0, 11 }, /* QME7342 backplane settings */
  6295. { 0, 0, 0, 11 }, /* QME7342 backplane settings */
  6296. { 0, 0, 0, 11 }, /* QME7342 backplane settings */
  6297. { 0, 0, 0, 3 }, /* QMH7342 backplane settings */
  6298. { 0, 0, 0, 4 }, /* QMH7342 backplane settings */
  6299. };
  6300. static const struct txdds_ent txdds_extra_ddr[TXDDS_EXTRA_SZ] = {
  6301. /* amp, pre, main, post */
  6302. { 0, 0, 0, 7 }, /* QMH7342 backplane settings */
  6303. { 0, 0, 0, 7 }, /* QMH7342 backplane settings */
  6304. { 0, 0, 0, 8 }, /* QMH7342 backplane settings */
  6305. { 0, 0, 0, 8 }, /* QMH7342 backplane settings */
  6306. { 0, 0, 0, 13 }, /* QME7342 backplane settings */
  6307. { 0, 0, 0, 13 }, /* QME7342 backplane settings */
  6308. { 0, 0, 0, 13 }, /* QME7342 backplane settings */
  6309. { 0, 0, 0, 13 }, /* QME7342 backplane settings */
  6310. { 0, 0, 0, 13 }, /* QME7342 backplane settings */
  6311. { 0, 0, 0, 13 }, /* QME7342 backplane settings */
  6312. { 0, 0, 0, 13 }, /* QME7342 backplane settings */
  6313. { 0, 0, 0, 9 }, /* QMH7342 backplane settings */
  6314. { 0, 0, 0, 10 }, /* QMH7342 backplane settings */
  6315. };
  6316. static const struct txdds_ent txdds_extra_qdr[TXDDS_EXTRA_SZ] = {
  6317. /* amp, pre, main, post */
  6318. { 0, 1, 0, 4 }, /* QMH7342 backplane settings */
  6319. { 0, 1, 0, 5 }, /* QMH7342 backplane settings */
  6320. { 0, 1, 0, 6 }, /* QMH7342 backplane settings */
  6321. { 0, 1, 0, 8 }, /* QMH7342 backplane settings */
  6322. { 0, 1, 12, 10 }, /* QME7342 backplane setting */
  6323. { 0, 1, 12, 11 }, /* QME7342 backplane setting */
  6324. { 0, 1, 12, 12 }, /* QME7342 backplane setting */
  6325. { 0, 1, 12, 14 }, /* QME7342 backplane setting */
  6326. { 0, 1, 12, 6 }, /* QME7342 backplane setting */
  6327. { 0, 1, 12, 7 }, /* QME7342 backplane setting */
  6328. { 0, 1, 12, 8 }, /* QME7342 backplane setting */
  6329. { 0, 1, 0, 10 }, /* QMH7342 backplane settings */
  6330. { 0, 1, 0, 12 }, /* QMH7342 backplane settings */
  6331. };
  6332. static const struct txdds_ent txdds_extra_mfg[TXDDS_MFG_SZ] = {
  6333. /* amp, pre, main, post */
  6334. { 0, 0, 0, 0 }, /* QME7342 mfg settings */
  6335. { 0, 0, 0, 6 }, /* QME7342 P2 mfg settings */
  6336. };
  6337. static const struct txdds_ent *get_atten_table(const struct txdds_ent *txdds,
  6338. unsigned atten)
  6339. {
  6340. /*
  6341. * The attenuation table starts at 2dB for entry 1,
  6342. * with entry 0 being the loopback entry.
  6343. */
  6344. if (atten <= 2)
  6345. atten = 1;
  6346. else if (atten > TXDDS_TABLE_SZ)
  6347. atten = TXDDS_TABLE_SZ - 1;
  6348. else
  6349. atten--;
  6350. return txdds + atten;
  6351. }
  6352. /*
  6353. * if override is set, the module parameter txselect has a value
  6354. * for this specific port, so use it, rather than our normal mechanism.
  6355. */
  6356. static void find_best_ent(struct qib_pportdata *ppd,
  6357. const struct txdds_ent **sdr_dds,
  6358. const struct txdds_ent **ddr_dds,
  6359. const struct txdds_ent **qdr_dds, int override)
  6360. {
  6361. struct qib_qsfp_cache *qd = &ppd->cpspec->qsfp_data.cache;
  6362. int idx;
  6363. /* Search table of known cables */
  6364. for (idx = 0; !override && idx < ARRAY_SIZE(vendor_txdds); ++idx) {
  6365. const struct vendor_txdds_ent *v = vendor_txdds + idx;
  6366. if (!memcmp(v->oui, qd->oui, QSFP_VOUI_LEN) &&
  6367. (!v->partnum ||
  6368. !memcmp(v->partnum, qd->partnum, QSFP_PN_LEN))) {
  6369. *sdr_dds = &v->sdr;
  6370. *ddr_dds = &v->ddr;
  6371. *qdr_dds = &v->qdr;
  6372. return;
  6373. }
  6374. }
  6375. /* Lookup serdes setting by cable type and attenuation */
  6376. if (!override && QSFP_IS_ACTIVE(qd->tech)) {
  6377. *sdr_dds = txdds_sdr + ppd->dd->board_atten;
  6378. *ddr_dds = txdds_ddr + ppd->dd->board_atten;
  6379. *qdr_dds = txdds_qdr + ppd->dd->board_atten;
  6380. return;
  6381. }
  6382. if (!override && QSFP_HAS_ATTEN(qd->tech) && (qd->atten[0] ||
  6383. qd->atten[1])) {
  6384. *sdr_dds = get_atten_table(txdds_sdr, qd->atten[0]);
  6385. *ddr_dds = get_atten_table(txdds_ddr, qd->atten[0]);
  6386. *qdr_dds = get_atten_table(txdds_qdr, qd->atten[1]);
  6387. return;
  6388. } else if (ppd->cpspec->no_eep < TXDDS_TABLE_SZ) {
  6389. /*
  6390. * If we have no (or incomplete) data from the cable
  6391. * EEPROM, or no QSFP, or override is set, use the
  6392. * module parameter value to index into the attentuation
  6393. * table.
  6394. */
  6395. idx = ppd->cpspec->no_eep;
  6396. *sdr_dds = &txdds_sdr[idx];
  6397. *ddr_dds = &txdds_ddr[idx];
  6398. *qdr_dds = &txdds_qdr[idx];
  6399. } else if (ppd->cpspec->no_eep < (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ)) {
  6400. /* similar to above, but index into the "extra" table. */
  6401. idx = ppd->cpspec->no_eep - TXDDS_TABLE_SZ;
  6402. *sdr_dds = &txdds_extra_sdr[idx];
  6403. *ddr_dds = &txdds_extra_ddr[idx];
  6404. *qdr_dds = &txdds_extra_qdr[idx];
  6405. } else if ((IS_QME(ppd->dd) || IS_QMH(ppd->dd)) &&
  6406. ppd->cpspec->no_eep < (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ +
  6407. TXDDS_MFG_SZ)) {
  6408. idx = ppd->cpspec->no_eep - (TXDDS_TABLE_SZ + TXDDS_EXTRA_SZ);
  6409. printk(KERN_INFO QIB_DRV_NAME
  6410. " IB%u:%u use idx %u into txdds_mfg\n",
  6411. ppd->dd->unit, ppd->port, idx);
  6412. *sdr_dds = &txdds_extra_mfg[idx];
  6413. *ddr_dds = &txdds_extra_mfg[idx];
  6414. *qdr_dds = &txdds_extra_mfg[idx];
  6415. } else {
  6416. /* this shouldn't happen, it's range checked */
  6417. *sdr_dds = txdds_sdr + qib_long_atten;
  6418. *ddr_dds = txdds_ddr + qib_long_atten;
  6419. *qdr_dds = txdds_qdr + qib_long_atten;
  6420. }
  6421. }
  6422. static void init_txdds_table(struct qib_pportdata *ppd, int override)
  6423. {
  6424. const struct txdds_ent *sdr_dds, *ddr_dds, *qdr_dds;
  6425. struct txdds_ent *dds;
  6426. int idx;
  6427. int single_ent = 0;
  6428. find_best_ent(ppd, &sdr_dds, &ddr_dds, &qdr_dds, override);
  6429. /* for mez cards or override, use the selected value for all entries */
  6430. if (!(ppd->dd->flags & QIB_HAS_QSFP) || override)
  6431. single_ent = 1;
  6432. /* Fill in the first entry with the best entry found. */
  6433. set_txdds(ppd, 0, sdr_dds);
  6434. set_txdds(ppd, TXDDS_TABLE_SZ, ddr_dds);
  6435. set_txdds(ppd, 2 * TXDDS_TABLE_SZ, qdr_dds);
  6436. if (ppd->lflags & (QIBL_LINKINIT | QIBL_LINKARMED |
  6437. QIBL_LINKACTIVE)) {
  6438. dds = (struct txdds_ent *)(ppd->link_speed_active ==
  6439. QIB_IB_QDR ? qdr_dds :
  6440. (ppd->link_speed_active ==
  6441. QIB_IB_DDR ? ddr_dds : sdr_dds));
  6442. write_tx_serdes_param(ppd, dds);
  6443. }
  6444. /* Fill in the remaining entries with the default table values. */
  6445. for (idx = 1; idx < ARRAY_SIZE(txdds_sdr); ++idx) {
  6446. set_txdds(ppd, idx, single_ent ? sdr_dds : txdds_sdr + idx);
  6447. set_txdds(ppd, idx + TXDDS_TABLE_SZ,
  6448. single_ent ? ddr_dds : txdds_ddr + idx);
  6449. set_txdds(ppd, idx + 2 * TXDDS_TABLE_SZ,
  6450. single_ent ? qdr_dds : txdds_qdr + idx);
  6451. }
  6452. }
  6453. #define KR_AHB_ACC KREG_IDX(ahb_access_ctrl)
  6454. #define KR_AHB_TRANS KREG_IDX(ahb_transaction_reg)
  6455. #define AHB_TRANS_RDY SYM_MASK(ahb_transaction_reg, ahb_rdy)
  6456. #define AHB_ADDR_LSB SYM_LSB(ahb_transaction_reg, ahb_address)
  6457. #define AHB_DATA_LSB SYM_LSB(ahb_transaction_reg, ahb_data)
  6458. #define AHB_WR SYM_MASK(ahb_transaction_reg, write_not_read)
  6459. #define AHB_TRANS_TRIES 10
  6460. /*
  6461. * The chan argument is 0=chan0, 1=chan1, 2=pll, 3=chan2, 4=chan4,
  6462. * 5=subsystem which is why most calls have "chan + chan >> 1"
  6463. * for the channel argument.
  6464. */
  6465. static u32 ahb_mod(struct qib_devdata *dd, int quad, int chan, int addr,
  6466. u32 data, u32 mask)
  6467. {
  6468. u32 rd_data, wr_data, sz_mask;
  6469. u64 trans, acc, prev_acc;
  6470. u32 ret = 0xBAD0BAD;
  6471. int tries;
  6472. prev_acc = qib_read_kreg64(dd, KR_AHB_ACC);
  6473. /* From this point on, make sure we return access */
  6474. acc = (quad << 1) | 1;
  6475. qib_write_kreg(dd, KR_AHB_ACC, acc);
  6476. for (tries = 1; tries < AHB_TRANS_TRIES; ++tries) {
  6477. trans = qib_read_kreg64(dd, KR_AHB_TRANS);
  6478. if (trans & AHB_TRANS_RDY)
  6479. break;
  6480. }
  6481. if (tries >= AHB_TRANS_TRIES) {
  6482. qib_dev_err(dd, "No ahb_rdy in %d tries\n", AHB_TRANS_TRIES);
  6483. goto bail;
  6484. }
  6485. /* If mask is not all 1s, we need to read, but different SerDes
  6486. * entities have different sizes
  6487. */
  6488. sz_mask = (1UL << ((quad == 1) ? 32 : 16)) - 1;
  6489. wr_data = data & mask & sz_mask;
  6490. if ((~mask & sz_mask) != 0) {
  6491. trans = ((chan << 6) | addr) << (AHB_ADDR_LSB + 1);
  6492. qib_write_kreg(dd, KR_AHB_TRANS, trans);
  6493. for (tries = 1; tries < AHB_TRANS_TRIES; ++tries) {
  6494. trans = qib_read_kreg64(dd, KR_AHB_TRANS);
  6495. if (trans & AHB_TRANS_RDY)
  6496. break;
  6497. }
  6498. if (tries >= AHB_TRANS_TRIES) {
  6499. qib_dev_err(dd, "No Rd ahb_rdy in %d tries\n",
  6500. AHB_TRANS_TRIES);
  6501. goto bail;
  6502. }
  6503. /* Re-read in case host split reads and read data first */
  6504. trans = qib_read_kreg64(dd, KR_AHB_TRANS);
  6505. rd_data = (uint32_t)(trans >> AHB_DATA_LSB);
  6506. wr_data |= (rd_data & ~mask & sz_mask);
  6507. }
  6508. /* If mask is not zero, we need to write. */
  6509. if (mask & sz_mask) {
  6510. trans = ((chan << 6) | addr) << (AHB_ADDR_LSB + 1);
  6511. trans |= ((uint64_t)wr_data << AHB_DATA_LSB);
  6512. trans |= AHB_WR;
  6513. qib_write_kreg(dd, KR_AHB_TRANS, trans);
  6514. for (tries = 1; tries < AHB_TRANS_TRIES; ++tries) {
  6515. trans = qib_read_kreg64(dd, KR_AHB_TRANS);
  6516. if (trans & AHB_TRANS_RDY)
  6517. break;
  6518. }
  6519. if (tries >= AHB_TRANS_TRIES) {
  6520. qib_dev_err(dd, "No Wr ahb_rdy in %d tries\n",
  6521. AHB_TRANS_TRIES);
  6522. goto bail;
  6523. }
  6524. }
  6525. ret = wr_data;
  6526. bail:
  6527. qib_write_kreg(dd, KR_AHB_ACC, prev_acc);
  6528. return ret;
  6529. }
  6530. static void ibsd_wr_allchans(struct qib_pportdata *ppd, int addr, unsigned data,
  6531. unsigned mask)
  6532. {
  6533. struct qib_devdata *dd = ppd->dd;
  6534. int chan;
  6535. u32 rbc;
  6536. for (chan = 0; chan < SERDES_CHANS; ++chan) {
  6537. ahb_mod(dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)), addr,
  6538. data, mask);
  6539. rbc = ahb_mod(dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  6540. addr, 0, 0);
  6541. }
  6542. }
  6543. static void serdes_7322_los_enable(struct qib_pportdata *ppd, int enable)
  6544. {
  6545. u64 data = qib_read_kreg_port(ppd, krp_serdesctrl);
  6546. u8 state = SYM_FIELD(data, IBSerdesCtrl_0, RXLOSEN);
  6547. if (enable && !state) {
  6548. printk(KERN_INFO QIB_DRV_NAME " IB%u:%u Turning LOS on\n",
  6549. ppd->dd->unit, ppd->port);
  6550. data |= SYM_MASK(IBSerdesCtrl_0, RXLOSEN);
  6551. } else if (!enable && state) {
  6552. printk(KERN_INFO QIB_DRV_NAME " IB%u:%u Turning LOS off\n",
  6553. ppd->dd->unit, ppd->port);
  6554. data &= ~SYM_MASK(IBSerdesCtrl_0, RXLOSEN);
  6555. }
  6556. qib_write_kreg_port(ppd, krp_serdesctrl, data);
  6557. }
  6558. static int serdes_7322_init(struct qib_pportdata *ppd)
  6559. {
  6560. int ret = 0;
  6561. if (ppd->dd->cspec->r1)
  6562. ret = serdes_7322_init_old(ppd);
  6563. else
  6564. ret = serdes_7322_init_new(ppd);
  6565. return ret;
  6566. }
  6567. static int serdes_7322_init_old(struct qib_pportdata *ppd)
  6568. {
  6569. u32 le_val;
  6570. /*
  6571. * Initialize the Tx DDS tables. Also done every QSFP event,
  6572. * for adapters with QSFP
  6573. */
  6574. init_txdds_table(ppd, 0);
  6575. /* ensure no tx overrides from earlier driver loads */
  6576. qib_write_kreg_port(ppd, krp_tx_deemph_override,
  6577. SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  6578. reset_tx_deemphasis_override));
  6579. /* Patch some SerDes defaults to "Better for IB" */
  6580. /* Timing Loop Bandwidth: cdr_timing[11:9] = 0 */
  6581. ibsd_wr_allchans(ppd, 2, 0, BMASK(11, 9));
  6582. /* Termination: rxtermctrl_r2d addr 11 bits [12:11] = 1 */
  6583. ibsd_wr_allchans(ppd, 11, (1 << 11), BMASK(12, 11));
  6584. /* Enable LE2: rxle2en_r2a addr 13 bit [6] = 1 */
  6585. ibsd_wr_allchans(ppd, 13, (1 << 6), (1 << 6));
  6586. /* May be overridden in qsfp_7322_event */
  6587. le_val = IS_QME(ppd->dd) ? LE2_QME : LE2_DEFAULT;
  6588. ibsd_wr_allchans(ppd, 13, (le_val << 7), BMASK(9, 7));
  6589. /* enable LE1 adaptation for all but QME, which is disabled */
  6590. le_val = IS_QME(ppd->dd) ? 0 : 1;
  6591. ibsd_wr_allchans(ppd, 13, (le_val << 5), (1 << 5));
  6592. /* Clear cmode-override, may be set from older driver */
  6593. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 0 << 14, 1 << 14);
  6594. /* Timing Recovery: rxtapsel addr 5 bits [9:8] = 0 */
  6595. ibsd_wr_allchans(ppd, 5, (0 << 8), BMASK(9, 8));
  6596. /* setup LoS params; these are subsystem, so chan == 5 */
  6597. /* LoS filter threshold_count on, ch 0-3, set to 8 */
  6598. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 5, 8 << 11, BMASK(14, 11));
  6599. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 7, 8 << 4, BMASK(7, 4));
  6600. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 8, 8 << 11, BMASK(14, 11));
  6601. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 8 << 4, BMASK(7, 4));
  6602. /* LoS filter threshold_count off, ch 0-3, set to 4 */
  6603. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 6, 4 << 0, BMASK(3, 0));
  6604. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 7, 4 << 8, BMASK(11, 8));
  6605. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 9, 4 << 0, BMASK(3, 0));
  6606. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 4 << 8, BMASK(11, 8));
  6607. /* LoS filter select enabled */
  6608. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 9, 1 << 15, 1 << 15);
  6609. /* LoS target data: SDR=4, DDR=2, QDR=1 */
  6610. ibsd_wr_allchans(ppd, 14, (1 << 3), BMASK(5, 3)); /* QDR */
  6611. ibsd_wr_allchans(ppd, 20, (2 << 10), BMASK(12, 10)); /* DDR */
  6612. ibsd_wr_allchans(ppd, 20, (4 << 13), BMASK(15, 13)); /* SDR */
  6613. serdes_7322_los_enable(ppd, 1);
  6614. /* rxbistena; set 0 to avoid effects of it switch later */
  6615. ibsd_wr_allchans(ppd, 9, 0 << 15, 1 << 15);
  6616. /* Configure 4 DFE taps, and only they adapt */
  6617. ibsd_wr_allchans(ppd, 16, 0 << 0, BMASK(1, 0));
  6618. /* gain hi stop 32 (22) (6:1) lo stop 7 (10:7) target 22 (13) (15:11) */
  6619. le_val = (ppd->dd->cspec->r1 || IS_QME(ppd->dd)) ? 0xb6c0 : 0x6bac;
  6620. ibsd_wr_allchans(ppd, 21, le_val, 0xfffe);
  6621. /*
  6622. * Set receive adaptation mode. SDR and DDR adaptation are
  6623. * always on, and QDR is initially enabled; later disabled.
  6624. */
  6625. qib_write_kreg_port(ppd, krp_static_adapt_dis(0), 0ULL);
  6626. qib_write_kreg_port(ppd, krp_static_adapt_dis(1), 0ULL);
  6627. qib_write_kreg_port(ppd, krp_static_adapt_dis(2),
  6628. ppd->dd->cspec->r1 ?
  6629. QDR_STATIC_ADAPT_DOWN_R1 : QDR_STATIC_ADAPT_DOWN);
  6630. ppd->cpspec->qdr_dfe_on = 1;
  6631. /* FLoop LOS gate: PPM filter enabled */
  6632. ibsd_wr_allchans(ppd, 38, 0 << 10, 1 << 10);
  6633. /* rx offset center enabled */
  6634. ibsd_wr_allchans(ppd, 12, 1 << 4, 1 << 4);
  6635. if (!ppd->dd->cspec->r1) {
  6636. ibsd_wr_allchans(ppd, 12, 1 << 12, 1 << 12);
  6637. ibsd_wr_allchans(ppd, 12, 2 << 8, 0x0f << 8);
  6638. }
  6639. /* Set the frequency loop bandwidth to 15 */
  6640. ibsd_wr_allchans(ppd, 2, 15 << 5, BMASK(8, 5));
  6641. return 0;
  6642. }
  6643. static int serdes_7322_init_new(struct qib_pportdata *ppd)
  6644. {
  6645. u64 tstart;
  6646. u32 le_val, rxcaldone;
  6647. int chan, chan_done = (1 << SERDES_CHANS) - 1;
  6648. /*
  6649. * Initialize the Tx DDS tables. Also done every QSFP event,
  6650. * for adapters with QSFP
  6651. */
  6652. init_txdds_table(ppd, 0);
  6653. /* Clear cmode-override, may be set from older driver */
  6654. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 0 << 14, 1 << 14);
  6655. /* ensure no tx overrides from earlier driver loads */
  6656. qib_write_kreg_port(ppd, krp_tx_deemph_override,
  6657. SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  6658. reset_tx_deemphasis_override));
  6659. /* START OF LSI SUGGESTED SERDES BRINGUP */
  6660. /* Reset - Calibration Setup */
  6661. /* Stop DFE adaptaion */
  6662. ibsd_wr_allchans(ppd, 1, 0, BMASK(9, 1));
  6663. /* Disable LE1 */
  6664. ibsd_wr_allchans(ppd, 13, 0, BMASK(5, 5));
  6665. /* Disable autoadapt for LE1 */
  6666. ibsd_wr_allchans(ppd, 1, 0, BMASK(15, 15));
  6667. /* Disable LE2 */
  6668. ibsd_wr_allchans(ppd, 13, 0, BMASK(6, 6));
  6669. /* Disable VGA */
  6670. ibsd_wr_allchans(ppd, 5, 0, BMASK(0, 0));
  6671. /* Disable AFE Offset Cancel */
  6672. ibsd_wr_allchans(ppd, 12, 0, BMASK(12, 12));
  6673. /* Disable Timing Loop */
  6674. ibsd_wr_allchans(ppd, 2, 0, BMASK(3, 3));
  6675. /* Disable Frequency Loop */
  6676. ibsd_wr_allchans(ppd, 2, 0, BMASK(4, 4));
  6677. /* Disable Baseline Wander Correction */
  6678. ibsd_wr_allchans(ppd, 13, 0, BMASK(13, 13));
  6679. /* Disable RX Calibration */
  6680. ibsd_wr_allchans(ppd, 4, 0, BMASK(10, 10));
  6681. /* Disable RX Offset Calibration */
  6682. ibsd_wr_allchans(ppd, 12, 0, BMASK(4, 4));
  6683. /* Select BB CDR */
  6684. ibsd_wr_allchans(ppd, 2, (1 << 15), BMASK(15, 15));
  6685. /* CDR Step Size */
  6686. ibsd_wr_allchans(ppd, 5, 0, BMASK(9, 8));
  6687. /* Enable phase Calibration */
  6688. ibsd_wr_allchans(ppd, 12, (1 << 5), BMASK(5, 5));
  6689. /* DFE Bandwidth [2:14-12] */
  6690. ibsd_wr_allchans(ppd, 2, (4 << 12), BMASK(14, 12));
  6691. /* DFE Config (4 taps only) */
  6692. ibsd_wr_allchans(ppd, 16, 0, BMASK(1, 0));
  6693. /* Gain Loop Bandwidth */
  6694. if (!ppd->dd->cspec->r1) {
  6695. ibsd_wr_allchans(ppd, 12, 1 << 12, BMASK(12, 12));
  6696. ibsd_wr_allchans(ppd, 12, 2 << 8, BMASK(11, 8));
  6697. } else {
  6698. ibsd_wr_allchans(ppd, 19, (3 << 11), BMASK(13, 11));
  6699. }
  6700. /* Baseline Wander Correction Gain [13:4-0] (leave as default) */
  6701. /* Baseline Wander Correction Gain [3:7-5] (leave as default) */
  6702. /* Data Rate Select [5:7-6] (leave as default) */
  6703. /* RX Parallel Word Width [3:10-8] (leave as default) */
  6704. /* RX REST */
  6705. /* Single- or Multi-channel reset */
  6706. /* RX Analog reset */
  6707. /* RX Digital reset */
  6708. ibsd_wr_allchans(ppd, 0, 0, BMASK(15, 13));
  6709. msleep(20);
  6710. /* RX Analog reset */
  6711. ibsd_wr_allchans(ppd, 0, (1 << 14), BMASK(14, 14));
  6712. msleep(20);
  6713. /* RX Digital reset */
  6714. ibsd_wr_allchans(ppd, 0, (1 << 13), BMASK(13, 13));
  6715. msleep(20);
  6716. /* setup LoS params; these are subsystem, so chan == 5 */
  6717. /* LoS filter threshold_count on, ch 0-3, set to 8 */
  6718. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 5, 8 << 11, BMASK(14, 11));
  6719. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 7, 8 << 4, BMASK(7, 4));
  6720. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 8, 8 << 11, BMASK(14, 11));
  6721. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 8 << 4, BMASK(7, 4));
  6722. /* LoS filter threshold_count off, ch 0-3, set to 4 */
  6723. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 6, 4 << 0, BMASK(3, 0));
  6724. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 7, 4 << 8, BMASK(11, 8));
  6725. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 9, 4 << 0, BMASK(3, 0));
  6726. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 10, 4 << 8, BMASK(11, 8));
  6727. /* LoS filter select enabled */
  6728. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), 5, 9, 1 << 15, 1 << 15);
  6729. /* LoS target data: SDR=4, DDR=2, QDR=1 */
  6730. ibsd_wr_allchans(ppd, 14, (1 << 3), BMASK(5, 3)); /* QDR */
  6731. ibsd_wr_allchans(ppd, 20, (2 << 10), BMASK(12, 10)); /* DDR */
  6732. ibsd_wr_allchans(ppd, 20, (4 << 13), BMASK(15, 13)); /* SDR */
  6733. /* Turn on LOS on initial SERDES init */
  6734. serdes_7322_los_enable(ppd, 1);
  6735. /* FLoop LOS gate: PPM filter enabled */
  6736. ibsd_wr_allchans(ppd, 38, 0 << 10, 1 << 10);
  6737. /* RX LATCH CALIBRATION */
  6738. /* Enable Eyefinder Phase Calibration latch */
  6739. ibsd_wr_allchans(ppd, 15, 1, BMASK(0, 0));
  6740. /* Enable RX Offset Calibration latch */
  6741. ibsd_wr_allchans(ppd, 12, (1 << 4), BMASK(4, 4));
  6742. msleep(20);
  6743. /* Start Calibration */
  6744. ibsd_wr_allchans(ppd, 4, (1 << 10), BMASK(10, 10));
  6745. tstart = get_jiffies_64();
  6746. while (chan_done &&
  6747. !time_after64(get_jiffies_64(),
  6748. tstart + msecs_to_jiffies(500))) {
  6749. msleep(20);
  6750. for (chan = 0; chan < SERDES_CHANS; ++chan) {
  6751. rxcaldone = ahb_mod(ppd->dd, IBSD(ppd->hw_pidx),
  6752. (chan + (chan >> 1)),
  6753. 25, 0, 0);
  6754. if ((~rxcaldone & (u32)BMASK(9, 9)) == 0 &&
  6755. (~chan_done & (1 << chan)) == 0)
  6756. chan_done &= ~(1 << chan);
  6757. }
  6758. }
  6759. if (chan_done) {
  6760. printk(KERN_INFO QIB_DRV_NAME
  6761. " Serdes %d calibration not done after .5 sec: 0x%x\n",
  6762. IBSD(ppd->hw_pidx), chan_done);
  6763. } else {
  6764. for (chan = 0; chan < SERDES_CHANS; ++chan) {
  6765. rxcaldone = ahb_mod(ppd->dd, IBSD(ppd->hw_pidx),
  6766. (chan + (chan >> 1)),
  6767. 25, 0, 0);
  6768. if ((~rxcaldone & (u32)BMASK(10, 10)) == 0)
  6769. printk(KERN_INFO QIB_DRV_NAME
  6770. " Serdes %d chan %d calibration "
  6771. "failed\n", IBSD(ppd->hw_pidx), chan);
  6772. }
  6773. }
  6774. /* Turn off Calibration */
  6775. ibsd_wr_allchans(ppd, 4, 0, BMASK(10, 10));
  6776. msleep(20);
  6777. /* BRING RX UP */
  6778. /* Set LE2 value (May be overridden in qsfp_7322_event) */
  6779. le_val = IS_QME(ppd->dd) ? LE2_QME : LE2_DEFAULT;
  6780. ibsd_wr_allchans(ppd, 13, (le_val << 7), BMASK(9, 7));
  6781. /* Set LE2 Loop bandwidth */
  6782. ibsd_wr_allchans(ppd, 3, (7 << 5), BMASK(7, 5));
  6783. /* Enable LE2 */
  6784. ibsd_wr_allchans(ppd, 13, (1 << 6), BMASK(6, 6));
  6785. msleep(20);
  6786. /* Enable H0 only */
  6787. ibsd_wr_allchans(ppd, 1, 1, BMASK(9, 1));
  6788. /* gain hi stop 32 (22) (6:1) lo stop 7 (10:7) target 22 (13) (15:11) */
  6789. le_val = (ppd->dd->cspec->r1 || IS_QME(ppd->dd)) ? 0xb6c0 : 0x6bac;
  6790. ibsd_wr_allchans(ppd, 21, le_val, 0xfffe);
  6791. /* Enable VGA */
  6792. ibsd_wr_allchans(ppd, 5, 0, BMASK(0, 0));
  6793. msleep(20);
  6794. /* Set Frequency Loop Bandwidth */
  6795. ibsd_wr_allchans(ppd, 2, (7 << 5), BMASK(8, 5));
  6796. /* Enable Frequency Loop */
  6797. ibsd_wr_allchans(ppd, 2, (1 << 4), BMASK(4, 4));
  6798. /* Set Timing Loop Bandwidth */
  6799. ibsd_wr_allchans(ppd, 2, 0, BMASK(11, 9));
  6800. /* Enable Timing Loop */
  6801. ibsd_wr_allchans(ppd, 2, (1 << 3), BMASK(3, 3));
  6802. msleep(50);
  6803. /* Enable DFE
  6804. * Set receive adaptation mode. SDR and DDR adaptation are
  6805. * always on, and QDR is initially enabled; later disabled.
  6806. */
  6807. qib_write_kreg_port(ppd, krp_static_adapt_dis(0), 0ULL);
  6808. qib_write_kreg_port(ppd, krp_static_adapt_dis(1), 0ULL);
  6809. qib_write_kreg_port(ppd, krp_static_adapt_dis(2),
  6810. ppd->dd->cspec->r1 ?
  6811. QDR_STATIC_ADAPT_DOWN_R1 : QDR_STATIC_ADAPT_DOWN);
  6812. ppd->cpspec->qdr_dfe_on = 1;
  6813. /* Disable LE1 */
  6814. ibsd_wr_allchans(ppd, 13, (0 << 5), (1 << 5));
  6815. /* Disable auto adapt for LE1 */
  6816. ibsd_wr_allchans(ppd, 1, (0 << 15), BMASK(15, 15));
  6817. msleep(20);
  6818. /* Enable AFE Offset Cancel */
  6819. ibsd_wr_allchans(ppd, 12, (1 << 12), BMASK(12, 12));
  6820. /* Enable Baseline Wander Correction */
  6821. ibsd_wr_allchans(ppd, 12, (1 << 13), BMASK(13, 13));
  6822. /* Termination: rxtermctrl_r2d addr 11 bits [12:11] = 1 */
  6823. ibsd_wr_allchans(ppd, 11, (1 << 11), BMASK(12, 11));
  6824. /* VGA output common mode */
  6825. ibsd_wr_allchans(ppd, 12, (3 << 2), BMASK(3, 2));
  6826. return 0;
  6827. }
  6828. /* start adjust QMH serdes parameters */
  6829. static void set_man_code(struct qib_pportdata *ppd, int chan, int code)
  6830. {
  6831. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  6832. 9, code << 9, 0x3f << 9);
  6833. }
  6834. static void set_man_mode_h1(struct qib_pportdata *ppd, int chan,
  6835. int enable, u32 tapenable)
  6836. {
  6837. if (enable)
  6838. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  6839. 1, 3 << 10, 0x1f << 10);
  6840. else
  6841. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  6842. 1, 0, 0x1f << 10);
  6843. }
  6844. /* Set clock to 1, 0, 1, 0 */
  6845. static void clock_man(struct qib_pportdata *ppd, int chan)
  6846. {
  6847. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  6848. 4, 0x4000, 0x4000);
  6849. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  6850. 4, 0, 0x4000);
  6851. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  6852. 4, 0x4000, 0x4000);
  6853. ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), (chan + (chan >> 1)),
  6854. 4, 0, 0x4000);
  6855. }
  6856. /*
  6857. * write the current Tx serdes pre,post,main,amp settings into the serdes.
  6858. * The caller must pass the settings appropriate for the current speed,
  6859. * or not care if they are correct for the current speed.
  6860. */
  6861. static void write_tx_serdes_param(struct qib_pportdata *ppd,
  6862. struct txdds_ent *txdds)
  6863. {
  6864. u64 deemph;
  6865. deemph = qib_read_kreg_port(ppd, krp_tx_deemph_override);
  6866. /* field names for amp, main, post, pre, respectively */
  6867. deemph &= ~(SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txampcntl_d2a) |
  6868. SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txc0_ena) |
  6869. SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txcp1_ena) |
  6870. SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0, txcn1_ena));
  6871. deemph |= SYM_MASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  6872. tx_override_deemphasis_select);
  6873. deemph |= (txdds->amp & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  6874. txampcntl_d2a)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  6875. txampcntl_d2a);
  6876. deemph |= (txdds->main & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  6877. txc0_ena)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  6878. txc0_ena);
  6879. deemph |= (txdds->post & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  6880. txcp1_ena)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  6881. txcp1_ena);
  6882. deemph |= (txdds->pre & SYM_RMASK(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  6883. txcn1_ena)) << SYM_LSB(IBSD_TX_DEEMPHASIS_OVERRIDE_0,
  6884. txcn1_ena);
  6885. qib_write_kreg_port(ppd, krp_tx_deemph_override, deemph);
  6886. }
  6887. /*
  6888. * Set the parameters for mez cards on link bounce, so they are
  6889. * always exactly what was requested. Similar logic to init_txdds
  6890. * but does just the serdes.
  6891. */
  6892. static void adj_tx_serdes(struct qib_pportdata *ppd)
  6893. {
  6894. const struct txdds_ent *sdr_dds, *ddr_dds, *qdr_dds;
  6895. struct txdds_ent *dds;
  6896. find_best_ent(ppd, &sdr_dds, &ddr_dds, &qdr_dds, 1);
  6897. dds = (struct txdds_ent *)(ppd->link_speed_active == QIB_IB_QDR ?
  6898. qdr_dds : (ppd->link_speed_active == QIB_IB_DDR ?
  6899. ddr_dds : sdr_dds));
  6900. write_tx_serdes_param(ppd, dds);
  6901. }
  6902. /* set QDR forced value for H1, if needed */
  6903. static void force_h1(struct qib_pportdata *ppd)
  6904. {
  6905. int chan;
  6906. ppd->cpspec->qdr_reforce = 0;
  6907. if (!ppd->dd->cspec->r1)
  6908. return;
  6909. for (chan = 0; chan < SERDES_CHANS; chan++) {
  6910. set_man_mode_h1(ppd, chan, 1, 0);
  6911. set_man_code(ppd, chan, ppd->cpspec->h1_val);
  6912. clock_man(ppd, chan);
  6913. set_man_mode_h1(ppd, chan, 0, 0);
  6914. }
  6915. }
  6916. #define SJA_EN SYM_MASK(SPC_JTAG_ACCESS_REG, SPC_JTAG_ACCESS_EN)
  6917. #define BISTEN_LSB SYM_LSB(SPC_JTAG_ACCESS_REG, bist_en)
  6918. #define R_OPCODE_LSB 3
  6919. #define R_OP_NOP 0
  6920. #define R_OP_SHIFT 2
  6921. #define R_OP_UPDATE 3
  6922. #define R_TDI_LSB 2
  6923. #define R_TDO_LSB 1
  6924. #define R_RDY 1
  6925. static int qib_r_grab(struct qib_devdata *dd)
  6926. {
  6927. u64 val;
  6928. val = SJA_EN;
  6929. qib_write_kreg(dd, kr_r_access, val);
  6930. qib_read_kreg32(dd, kr_scratch);
  6931. return 0;
  6932. }
  6933. /* qib_r_wait_for_rdy() not only waits for the ready bit, it
  6934. * returns the current state of R_TDO
  6935. */
  6936. static int qib_r_wait_for_rdy(struct qib_devdata *dd)
  6937. {
  6938. u64 val;
  6939. int timeout;
  6940. for (timeout = 0; timeout < 100 ; ++timeout) {
  6941. val = qib_read_kreg32(dd, kr_r_access);
  6942. if (val & R_RDY)
  6943. return (val >> R_TDO_LSB) & 1;
  6944. }
  6945. return -1;
  6946. }
  6947. static int qib_r_shift(struct qib_devdata *dd, int bisten,
  6948. int len, u8 *inp, u8 *outp)
  6949. {
  6950. u64 valbase, val;
  6951. int ret, pos;
  6952. valbase = SJA_EN | (bisten << BISTEN_LSB) |
  6953. (R_OP_SHIFT << R_OPCODE_LSB);
  6954. ret = qib_r_wait_for_rdy(dd);
  6955. if (ret < 0)
  6956. goto bail;
  6957. for (pos = 0; pos < len; ++pos) {
  6958. val = valbase;
  6959. if (outp) {
  6960. outp[pos >> 3] &= ~(1 << (pos & 7));
  6961. outp[pos >> 3] |= (ret << (pos & 7));
  6962. }
  6963. if (inp) {
  6964. int tdi = inp[pos >> 3] >> (pos & 7);
  6965. val |= ((tdi & 1) << R_TDI_LSB);
  6966. }
  6967. qib_write_kreg(dd, kr_r_access, val);
  6968. qib_read_kreg32(dd, kr_scratch);
  6969. ret = qib_r_wait_for_rdy(dd);
  6970. if (ret < 0)
  6971. break;
  6972. }
  6973. /* Restore to NOP between operations. */
  6974. val = SJA_EN | (bisten << BISTEN_LSB);
  6975. qib_write_kreg(dd, kr_r_access, val);
  6976. qib_read_kreg32(dd, kr_scratch);
  6977. ret = qib_r_wait_for_rdy(dd);
  6978. if (ret >= 0)
  6979. ret = pos;
  6980. bail:
  6981. return ret;
  6982. }
  6983. static int qib_r_update(struct qib_devdata *dd, int bisten)
  6984. {
  6985. u64 val;
  6986. int ret;
  6987. val = SJA_EN | (bisten << BISTEN_LSB) | (R_OP_UPDATE << R_OPCODE_LSB);
  6988. ret = qib_r_wait_for_rdy(dd);
  6989. if (ret >= 0) {
  6990. qib_write_kreg(dd, kr_r_access, val);
  6991. qib_read_kreg32(dd, kr_scratch);
  6992. }
  6993. return ret;
  6994. }
  6995. #define BISTEN_PORT_SEL 15
  6996. #define LEN_PORT_SEL 625
  6997. #define BISTEN_AT 17
  6998. #define LEN_AT 156
  6999. #define BISTEN_ETM 16
  7000. #define LEN_ETM 632
  7001. #define BIT2BYTE(x) (((x) + BITS_PER_BYTE - 1) / BITS_PER_BYTE)
  7002. /* these are common for all IB port use cases. */
  7003. static u8 reset_at[BIT2BYTE(LEN_AT)] = {
  7004. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7005. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00,
  7006. };
  7007. static u8 reset_atetm[BIT2BYTE(LEN_ETM)] = {
  7008. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7009. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7010. 0x00, 0x00, 0x00, 0x80, 0xe3, 0x81, 0x73, 0x3c, 0x70, 0x8e,
  7011. 0x07, 0xce, 0xf1, 0xc0, 0x39, 0x1e, 0x38, 0xc7, 0x03, 0xe7,
  7012. 0x78, 0xe0, 0x1c, 0x0f, 0x9c, 0x7f, 0x80, 0x73, 0x0f, 0x70,
  7013. 0xde, 0x01, 0xce, 0x39, 0xc0, 0xf9, 0x06, 0x38, 0xd7, 0x00,
  7014. 0xe7, 0x19, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7015. 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
  7016. };
  7017. static u8 at[BIT2BYTE(LEN_AT)] = {
  7018. 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
  7019. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00,
  7020. };
  7021. /* used for IB1 or IB2, only one in use */
  7022. static u8 atetm_1port[BIT2BYTE(LEN_ETM)] = {
  7023. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7024. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7025. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7026. 0x00, 0x10, 0xf2, 0x80, 0x83, 0x1e, 0x38, 0x00, 0x00, 0x00,
  7027. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7028. 0x00, 0x00, 0x50, 0xf4, 0x41, 0x00, 0x18, 0x78, 0xc8, 0x03,
  7029. 0x07, 0x7b, 0xa0, 0x3e, 0x00, 0x02, 0x00, 0x00, 0x18, 0x00,
  7030. 0x18, 0x00, 0x00, 0x00, 0x00, 0x4b, 0x00, 0x00, 0x00,
  7031. };
  7032. /* used when both IB1 and IB2 are in use */
  7033. static u8 atetm_2port[BIT2BYTE(LEN_ETM)] = {
  7034. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7035. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79,
  7036. 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  7037. 0x00, 0x00, 0xf8, 0x80, 0x83, 0x1e, 0x38, 0xe0, 0x03, 0x05,
  7038. 0x7b, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
  7039. 0xa2, 0x0f, 0x50, 0xf4, 0x41, 0x00, 0x18, 0x78, 0xd1, 0x07,
  7040. 0x02, 0x7c, 0x80, 0x3e, 0x00, 0x02, 0x00, 0x00, 0x3e, 0x00,
  7041. 0x02, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00,
  7042. };
  7043. /* used when only IB1 is in use */
  7044. static u8 portsel_port1[BIT2BYTE(LEN_PORT_SEL)] = {
  7045. 0x32, 0x65, 0xa4, 0x7b, 0x10, 0x98, 0xdc, 0xfe, 0x13, 0x13,
  7046. 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x73, 0x0c, 0x0c, 0x0c,
  7047. 0x0c, 0x0c, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
  7048. 0x13, 0x78, 0x78, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
  7049. 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x74, 0x32,
  7050. 0x32, 0x32, 0x32, 0x32, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
  7051. 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
  7052. 0x14, 0x14, 0x9f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
  7053. };
  7054. /* used when only IB2 is in use */
  7055. static u8 portsel_port2[BIT2BYTE(LEN_PORT_SEL)] = {
  7056. 0x32, 0x65, 0xa4, 0x7b, 0x10, 0x98, 0xdc, 0xfe, 0x39, 0x39,
  7057. 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x73, 0x32, 0x32, 0x32,
  7058. 0x32, 0x32, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39,
  7059. 0x39, 0x78, 0x78, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39,
  7060. 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x74, 0x32,
  7061. 0x32, 0x32, 0x32, 0x32, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a,
  7062. 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a, 0x3a,
  7063. 0x3a, 0x3a, 0x9f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
  7064. };
  7065. /* used when both IB1 and IB2 are in use */
  7066. static u8 portsel_2port[BIT2BYTE(LEN_PORT_SEL)] = {
  7067. 0x32, 0xba, 0x54, 0x76, 0x10, 0x98, 0xdc, 0xfe, 0x13, 0x13,
  7068. 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x73, 0x0c, 0x0c, 0x0c,
  7069. 0x0c, 0x0c, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
  7070. 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
  7071. 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x74, 0x32,
  7072. 0x32, 0x32, 0x32, 0x32, 0x14, 0x14, 0x14, 0x14, 0x14, 0x3a,
  7073. 0x3a, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
  7074. 0x14, 0x14, 0x9f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
  7075. };
  7076. /*
  7077. * Do setup to properly handle IB link recovery; if port is zero, we
  7078. * are initializing to cover both ports; otherwise we are initializing
  7079. * to cover a single port card, or the port has reached INIT and we may
  7080. * need to switch coverage types.
  7081. */
  7082. static void setup_7322_link_recovery(struct qib_pportdata *ppd, u32 both)
  7083. {
  7084. u8 *portsel, *etm;
  7085. struct qib_devdata *dd = ppd->dd;
  7086. if (!ppd->dd->cspec->r1)
  7087. return;
  7088. if (!both) {
  7089. dd->cspec->recovery_ports_initted++;
  7090. ppd->cpspec->recovery_init = 1;
  7091. }
  7092. if (!both && dd->cspec->recovery_ports_initted == 1) {
  7093. portsel = ppd->port == 1 ? portsel_port1 : portsel_port2;
  7094. etm = atetm_1port;
  7095. } else {
  7096. portsel = portsel_2port;
  7097. etm = atetm_2port;
  7098. }
  7099. if (qib_r_grab(dd) < 0 ||
  7100. qib_r_shift(dd, BISTEN_ETM, LEN_ETM, reset_atetm, NULL) < 0 ||
  7101. qib_r_update(dd, BISTEN_ETM) < 0 ||
  7102. qib_r_shift(dd, BISTEN_AT, LEN_AT, reset_at, NULL) < 0 ||
  7103. qib_r_update(dd, BISTEN_AT) < 0 ||
  7104. qib_r_shift(dd, BISTEN_PORT_SEL, LEN_PORT_SEL,
  7105. portsel, NULL) < 0 ||
  7106. qib_r_update(dd, BISTEN_PORT_SEL) < 0 ||
  7107. qib_r_shift(dd, BISTEN_AT, LEN_AT, at, NULL) < 0 ||
  7108. qib_r_update(dd, BISTEN_AT) < 0 ||
  7109. qib_r_shift(dd, BISTEN_ETM, LEN_ETM, etm, NULL) < 0 ||
  7110. qib_r_update(dd, BISTEN_ETM) < 0)
  7111. qib_dev_err(dd, "Failed IB link recovery setup\n");
  7112. }
  7113. static void check_7322_rxe_status(struct qib_pportdata *ppd)
  7114. {
  7115. struct qib_devdata *dd = ppd->dd;
  7116. u64 fmask;
  7117. if (dd->cspec->recovery_ports_initted != 1)
  7118. return; /* rest doesn't apply to dualport */
  7119. qib_write_kreg(dd, kr_control, dd->control |
  7120. SYM_MASK(Control, FreezeMode));
  7121. (void)qib_read_kreg64(dd, kr_scratch);
  7122. udelay(3); /* ibcreset asserted 400ns, be sure that's over */
  7123. fmask = qib_read_kreg64(dd, kr_act_fmask);
  7124. if (!fmask) {
  7125. /*
  7126. * require a powercycle before we'll work again, and make
  7127. * sure we get no more interrupts, and don't turn off
  7128. * freeze.
  7129. */
  7130. ppd->dd->cspec->stay_in_freeze = 1;
  7131. qib_7322_set_intr_state(ppd->dd, 0);
  7132. qib_write_kreg(dd, kr_fmask, 0ULL);
  7133. qib_dev_err(dd, "HCA unusable until powercycled\n");
  7134. return; /* eventually reset */
  7135. }
  7136. qib_write_kreg(ppd->dd, kr_hwerrclear,
  7137. SYM_MASK(HwErrClear, IBSerdesPClkNotDetectClear_1));
  7138. /* don't do the full clear_freeze(), not needed for this */
  7139. qib_write_kreg(dd, kr_control, dd->control);
  7140. qib_read_kreg32(dd, kr_scratch);
  7141. /* take IBC out of reset */
  7142. if (ppd->link_speed_supported) {
  7143. ppd->cpspec->ibcctrl_a &=
  7144. ~SYM_MASK(IBCCtrlA_0, IBStatIntReductionEn);
  7145. qib_write_kreg_port(ppd, krp_ibcctrl_a,
  7146. ppd->cpspec->ibcctrl_a);
  7147. qib_read_kreg32(dd, kr_scratch);
  7148. if (ppd->lflags & QIBL_IB_LINK_DISABLED)
  7149. qib_set_ib_7322_lstate(ppd, 0,
  7150. QLOGIC_IB_IBCC_LINKINITCMD_DISABLE);
  7151. }
  7152. }