qib_iba7322.c 263 KB

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