qib_iba7322.c 247 KB

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