qib_iba7322.c 265 KB

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