qib_iba7322.c 236 KB

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