qib_iba7322.c 251 KB

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