qib_iba7322.c 250 KB

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