qib_iba7322.c 252 KB

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