qib_iba7322.c 247 KB

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