qib_iba7322.c 246 KB

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