bnx2x_link.c 233 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258
  1. /* Copyright 2008-2011 Broadcom Corporation
  2. *
  3. * Unless you and Broadcom execute a separate written software license
  4. * agreement governing use of this software, this software is licensed to you
  5. * under the terms of the GNU General Public License version 2, available
  6. * at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL").
  7. *
  8. * Notwithstanding the above, under no circumstances may you combine this
  9. * software in any way with any other Broadcom software provided under a
  10. * license other than the GPL, without Broadcom's express prior written
  11. * consent.
  12. *
  13. * Written by Yaniv Rosner
  14. *
  15. */
  16. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  17. #include <linux/kernel.h>
  18. #include <linux/errno.h>
  19. #include <linux/pci.h>
  20. #include <linux/netdevice.h>
  21. #include <linux/delay.h>
  22. #include <linux/ethtool.h>
  23. #include <linux/mutex.h>
  24. #include "bnx2x.h"
  25. /********************************************************/
  26. #define ETH_HLEN 14
  27. /* L2 header size + 2*VLANs (8 bytes) + LLC SNAP (8 bytes) */
  28. #define ETH_OVREHEAD (ETH_HLEN + 8 + 8)
  29. #define ETH_MIN_PACKET_SIZE 60
  30. #define ETH_MAX_PACKET_SIZE 1500
  31. #define ETH_MAX_JUMBO_PACKET_SIZE 9600
  32. #define MDIO_ACCESS_TIMEOUT 1000
  33. #define BMAC_CONTROL_RX_ENABLE 2
  34. /***********************************************************/
  35. /* Shortcut definitions */
  36. /***********************************************************/
  37. #define NIG_LATCH_BC_ENABLE_MI_INT 0
  38. #define NIG_STATUS_EMAC0_MI_INT \
  39. NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_EMAC0_MISC_MI_INT
  40. #define NIG_STATUS_XGXS0_LINK10G \
  41. NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_XGXS0_LINK10G
  42. #define NIG_STATUS_XGXS0_LINK_STATUS \
  43. NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_XGXS0_LINK_STATUS
  44. #define NIG_STATUS_XGXS0_LINK_STATUS_SIZE \
  45. NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_XGXS0_LINK_STATUS_SIZE
  46. #define NIG_STATUS_SERDES0_LINK_STATUS \
  47. NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_SERDES0_LINK_STATUS
  48. #define NIG_MASK_MI_INT \
  49. NIG_MASK_INTERRUPT_PORT0_REG_MASK_EMAC0_MISC_MI_INT
  50. #define NIG_MASK_XGXS0_LINK10G \
  51. NIG_MASK_INTERRUPT_PORT0_REG_MASK_XGXS0_LINK10G
  52. #define NIG_MASK_XGXS0_LINK_STATUS \
  53. NIG_MASK_INTERRUPT_PORT0_REG_MASK_XGXS0_LINK_STATUS
  54. #define NIG_MASK_SERDES0_LINK_STATUS \
  55. NIG_MASK_INTERRUPT_PORT0_REG_MASK_SERDES0_LINK_STATUS
  56. #define MDIO_AN_CL73_OR_37_COMPLETE \
  57. (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE | \
  58. MDIO_GP_STATUS_TOP_AN_STATUS1_CL37_AUTONEG_COMPLETE)
  59. #define XGXS_RESET_BITS \
  60. (MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_RSTB_HW | \
  61. MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_IDDQ | \
  62. MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_PWRDWN | \
  63. MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_PWRDWN_SD | \
  64. MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_TXD_FIFO_RSTB)
  65. #define SERDES_RESET_BITS \
  66. (MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_RSTB_HW | \
  67. MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_IDDQ | \
  68. MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_PWRDWN | \
  69. MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_PWRDWN_SD)
  70. #define AUTONEG_CL37 SHARED_HW_CFG_AN_ENABLE_CL37
  71. #define AUTONEG_CL73 SHARED_HW_CFG_AN_ENABLE_CL73
  72. #define AUTONEG_BAM SHARED_HW_CFG_AN_ENABLE_BAM
  73. #define AUTONEG_PARALLEL \
  74. SHARED_HW_CFG_AN_ENABLE_PARALLEL_DETECTION
  75. #define AUTONEG_SGMII_FIBER_AUTODET \
  76. SHARED_HW_CFG_AN_EN_SGMII_FIBER_AUTO_DETECT
  77. #define AUTONEG_REMOTE_PHY SHARED_HW_CFG_AN_ENABLE_REMOTE_PHY
  78. #define GP_STATUS_PAUSE_RSOLUTION_TXSIDE \
  79. MDIO_GP_STATUS_TOP_AN_STATUS1_PAUSE_RSOLUTION_TXSIDE
  80. #define GP_STATUS_PAUSE_RSOLUTION_RXSIDE \
  81. MDIO_GP_STATUS_TOP_AN_STATUS1_PAUSE_RSOLUTION_RXSIDE
  82. #define GP_STATUS_SPEED_MASK \
  83. MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_MASK
  84. #define GP_STATUS_10M MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10M
  85. #define GP_STATUS_100M MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_100M
  86. #define GP_STATUS_1G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_1G
  87. #define GP_STATUS_2_5G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_2_5G
  88. #define GP_STATUS_5G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_5G
  89. #define GP_STATUS_6G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_6G
  90. #define GP_STATUS_10G_HIG \
  91. MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_HIG
  92. #define GP_STATUS_10G_CX4 \
  93. MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_CX4
  94. #define GP_STATUS_12G_HIG \
  95. MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_12G_HIG
  96. #define GP_STATUS_12_5G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_12_5G
  97. #define GP_STATUS_13G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_13G
  98. #define GP_STATUS_15G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_15G
  99. #define GP_STATUS_16G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_16G
  100. #define GP_STATUS_1G_KX MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_1G_KX
  101. #define GP_STATUS_10G_KX4 \
  102. MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_KX4
  103. #define LINK_10THD LINK_STATUS_SPEED_AND_DUPLEX_10THD
  104. #define LINK_10TFD LINK_STATUS_SPEED_AND_DUPLEX_10TFD
  105. #define LINK_100TXHD LINK_STATUS_SPEED_AND_DUPLEX_100TXHD
  106. #define LINK_100T4 LINK_STATUS_SPEED_AND_DUPLEX_100T4
  107. #define LINK_100TXFD LINK_STATUS_SPEED_AND_DUPLEX_100TXFD
  108. #define LINK_1000THD LINK_STATUS_SPEED_AND_DUPLEX_1000THD
  109. #define LINK_1000TFD LINK_STATUS_SPEED_AND_DUPLEX_1000TFD
  110. #define LINK_1000XFD LINK_STATUS_SPEED_AND_DUPLEX_1000XFD
  111. #define LINK_2500THD LINK_STATUS_SPEED_AND_DUPLEX_2500THD
  112. #define LINK_2500TFD LINK_STATUS_SPEED_AND_DUPLEX_2500TFD
  113. #define LINK_2500XFD LINK_STATUS_SPEED_AND_DUPLEX_2500XFD
  114. #define LINK_10GTFD LINK_STATUS_SPEED_AND_DUPLEX_10GTFD
  115. #define LINK_10GXFD LINK_STATUS_SPEED_AND_DUPLEX_10GXFD
  116. #define LINK_12GTFD LINK_STATUS_SPEED_AND_DUPLEX_12GTFD
  117. #define LINK_12GXFD LINK_STATUS_SPEED_AND_DUPLEX_12GXFD
  118. #define LINK_12_5GTFD LINK_STATUS_SPEED_AND_DUPLEX_12_5GTFD
  119. #define LINK_12_5GXFD LINK_STATUS_SPEED_AND_DUPLEX_12_5GXFD
  120. #define LINK_13GTFD LINK_STATUS_SPEED_AND_DUPLEX_13GTFD
  121. #define LINK_13GXFD LINK_STATUS_SPEED_AND_DUPLEX_13GXFD
  122. #define LINK_15GTFD LINK_STATUS_SPEED_AND_DUPLEX_15GTFD
  123. #define LINK_15GXFD LINK_STATUS_SPEED_AND_DUPLEX_15GXFD
  124. #define LINK_16GTFD LINK_STATUS_SPEED_AND_DUPLEX_16GTFD
  125. #define LINK_16GXFD LINK_STATUS_SPEED_AND_DUPLEX_16GXFD
  126. #define PHY_XGXS_FLAG 0x1
  127. #define PHY_SGMII_FLAG 0x2
  128. #define PHY_SERDES_FLAG 0x4
  129. /* */
  130. #define SFP_EEPROM_CON_TYPE_ADDR 0x2
  131. #define SFP_EEPROM_CON_TYPE_VAL_LC 0x7
  132. #define SFP_EEPROM_CON_TYPE_VAL_COPPER 0x21
  133. #define SFP_EEPROM_COMP_CODE_ADDR 0x3
  134. #define SFP_EEPROM_COMP_CODE_SR_MASK (1<<4)
  135. #define SFP_EEPROM_COMP_CODE_LR_MASK (1<<5)
  136. #define SFP_EEPROM_COMP_CODE_LRM_MASK (1<<6)
  137. #define SFP_EEPROM_FC_TX_TECH_ADDR 0x8
  138. #define SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_PASSIVE 0x4
  139. #define SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_ACTIVE 0x8
  140. #define SFP_EEPROM_OPTIONS_ADDR 0x40
  141. #define SFP_EEPROM_OPTIONS_LINEAR_RX_OUT_MASK 0x1
  142. #define SFP_EEPROM_OPTIONS_SIZE 2
  143. #define EDC_MODE_LINEAR 0x0022
  144. #define EDC_MODE_LIMITING 0x0044
  145. #define EDC_MODE_PASSIVE_DAC 0x0055
  146. #define ETS_BW_LIMIT_CREDIT_UPPER_BOUND (0x5000)
  147. #define ETS_BW_LIMIT_CREDIT_WEIGHT (0x5000)
  148. /**********************************************************/
  149. /* INTERFACE */
  150. /**********************************************************/
  151. #define CL22_WR_OVER_CL45(_bp, _phy, _bank, _addr, _val) \
  152. bnx2x_cl45_write(_bp, _phy, \
  153. (_phy)->def_md_devad, \
  154. (_bank + (_addr & 0xf)), \
  155. _val)
  156. #define CL22_RD_OVER_CL45(_bp, _phy, _bank, _addr, _val) \
  157. bnx2x_cl45_read(_bp, _phy, \
  158. (_phy)->def_md_devad, \
  159. (_bank + (_addr & 0xf)), \
  160. _val)
  161. static u32 bnx2x_bits_en(struct bnx2x *bp, u32 reg, u32 bits)
  162. {
  163. u32 val = REG_RD(bp, reg);
  164. val |= bits;
  165. REG_WR(bp, reg, val);
  166. return val;
  167. }
  168. static u32 bnx2x_bits_dis(struct bnx2x *bp, u32 reg, u32 bits)
  169. {
  170. u32 val = REG_RD(bp, reg);
  171. val &= ~bits;
  172. REG_WR(bp, reg, val);
  173. return val;
  174. }
  175. /******************************************************************/
  176. /* ETS section */
  177. /******************************************************************/
  178. void bnx2x_ets_disabled(struct link_params *params)
  179. {
  180. /* ETS disabled configuration*/
  181. struct bnx2x *bp = params->bp;
  182. DP(NETIF_MSG_LINK, "ETS disabled configuration\n");
  183. /*
  184. * mapping between entry priority to client number (0,1,2 -debug and
  185. * management clients, 3 - COS0 client, 4 - COS client)(HIGHEST)
  186. * 3bits client num.
  187. * PRI4 | PRI3 | PRI2 | PRI1 | PRI0
  188. * cos1-100 cos0-011 dbg1-010 dbg0-001 MCP-000
  189. */
  190. REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT, 0x4688);
  191. /*
  192. * Bitmap of 5bits length. Each bit specifies whether the entry behaves
  193. * as strict. Bits 0,1,2 - debug and management entries, 3 -
  194. * COS0 entry, 4 - COS1 entry.
  195. * COS1 | COS0 | DEBUG1 | DEBUG0 | MGMT
  196. * bit4 bit3 bit2 bit1 bit0
  197. * MCP and debug are strict
  198. */
  199. REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x7);
  200. /* defines which entries (clients) are subjected to WFQ arbitration */
  201. REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_SUBJECT2WFQ, 0);
  202. /*
  203. * For strict priority entries defines the number of consecutive
  204. * slots for the highest priority.
  205. */
  206. REG_WR(bp, NIG_REG_P0_TX_ARB_NUM_STRICT_ARB_SLOTS, 0x100);
  207. /*
  208. * mapping between the CREDIT_WEIGHT registers and actual client
  209. * numbers
  210. */
  211. REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_CREDIT_MAP, 0);
  212. REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_0, 0);
  213. REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_1, 0);
  214. REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_0, 0);
  215. REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_1, 0);
  216. REG_WR(bp, PBF_REG_HIGH_PRIORITY_COS_NUM, 0);
  217. /* ETS mode disable */
  218. REG_WR(bp, PBF_REG_ETS_ENABLED, 0);
  219. /*
  220. * If ETS mode is enabled (there is no strict priority) defines a WFQ
  221. * weight for COS0/COS1.
  222. */
  223. REG_WR(bp, PBF_REG_COS0_WEIGHT, 0x2710);
  224. REG_WR(bp, PBF_REG_COS1_WEIGHT, 0x2710);
  225. /* Upper bound that COS0_WEIGHT can reach in the WFQ arbiter */
  226. REG_WR(bp, PBF_REG_COS0_UPPER_BOUND, 0x989680);
  227. REG_WR(bp, PBF_REG_COS1_UPPER_BOUND, 0x989680);
  228. /* Defines the number of consecutive slots for the strict priority */
  229. REG_WR(bp, PBF_REG_NUM_STRICT_ARB_SLOTS, 0);
  230. }
  231. static void bnx2x_ets_bw_limit_common(const struct link_params *params)
  232. {
  233. /* ETS disabled configuration */
  234. struct bnx2x *bp = params->bp;
  235. DP(NETIF_MSG_LINK, "ETS enabled BW limit configuration\n");
  236. /*
  237. * defines which entries (clients) are subjected to WFQ arbitration
  238. * COS0 0x8
  239. * COS1 0x10
  240. */
  241. REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_SUBJECT2WFQ, 0x18);
  242. /*
  243. * mapping between the ARB_CREDIT_WEIGHT registers and actual
  244. * client numbers (WEIGHT_0 does not actually have to represent
  245. * client 0)
  246. * PRI4 | PRI3 | PRI2 | PRI1 | PRI0
  247. * cos1-001 cos0-000 dbg1-100 dbg0-011 MCP-010
  248. */
  249. REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_CREDIT_MAP, 0x111A);
  250. REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_0,
  251. ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
  252. REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_1,
  253. ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
  254. /* ETS mode enabled*/
  255. REG_WR(bp, PBF_REG_ETS_ENABLED, 1);
  256. /* Defines the number of consecutive slots for the strict priority */
  257. REG_WR(bp, PBF_REG_NUM_STRICT_ARB_SLOTS, 0);
  258. /*
  259. * Bitmap of 5bits length. Each bit specifies whether the entry behaves
  260. * as strict. Bits 0,1,2 - debug and management entries, 3 - COS0
  261. * entry, 4 - COS1 entry.
  262. * COS1 | COS0 | DEBUG21 | DEBUG0 | MGMT
  263. * bit4 bit3 bit2 bit1 bit0
  264. * MCP and debug are strict
  265. */
  266. REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x7);
  267. /* Upper bound that COS0_WEIGHT can reach in the WFQ arbiter.*/
  268. REG_WR(bp, PBF_REG_COS0_UPPER_BOUND,
  269. ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
  270. REG_WR(bp, PBF_REG_COS1_UPPER_BOUND,
  271. ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
  272. }
  273. void bnx2x_ets_bw_limit(const struct link_params *params, const u32 cos0_bw,
  274. const u32 cos1_bw)
  275. {
  276. /* ETS disabled configuration*/
  277. struct bnx2x *bp = params->bp;
  278. const u32 total_bw = cos0_bw + cos1_bw;
  279. u32 cos0_credit_weight = 0;
  280. u32 cos1_credit_weight = 0;
  281. DP(NETIF_MSG_LINK, "ETS enabled BW limit configuration\n");
  282. if ((0 == total_bw) ||
  283. (0 == cos0_bw) ||
  284. (0 == cos1_bw)) {
  285. DP(NETIF_MSG_LINK, "Total BW can't be zero\n");
  286. return;
  287. }
  288. cos0_credit_weight = (cos0_bw * ETS_BW_LIMIT_CREDIT_WEIGHT)/
  289. total_bw;
  290. cos1_credit_weight = (cos1_bw * ETS_BW_LIMIT_CREDIT_WEIGHT)/
  291. total_bw;
  292. bnx2x_ets_bw_limit_common(params);
  293. REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_0, cos0_credit_weight);
  294. REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_1, cos1_credit_weight);
  295. REG_WR(bp, PBF_REG_COS0_WEIGHT, cos0_credit_weight);
  296. REG_WR(bp, PBF_REG_COS1_WEIGHT, cos1_credit_weight);
  297. }
  298. u8 bnx2x_ets_strict(const struct link_params *params, const u8 strict_cos)
  299. {
  300. /* ETS disabled configuration*/
  301. struct bnx2x *bp = params->bp;
  302. u32 val = 0;
  303. DP(NETIF_MSG_LINK, "ETS enabled strict configuration\n");
  304. /*
  305. * Bitmap of 5bits length. Each bit specifies whether the entry behaves
  306. * as strict. Bits 0,1,2 - debug and management entries,
  307. * 3 - COS0 entry, 4 - COS1 entry.
  308. * COS1 | COS0 | DEBUG21 | DEBUG0 | MGMT
  309. * bit4 bit3 bit2 bit1 bit0
  310. * MCP and debug are strict
  311. */
  312. REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x1F);
  313. /*
  314. * For strict priority entries defines the number of consecutive slots
  315. * for the highest priority.
  316. */
  317. REG_WR(bp, NIG_REG_P0_TX_ARB_NUM_STRICT_ARB_SLOTS, 0x100);
  318. /* ETS mode disable */
  319. REG_WR(bp, PBF_REG_ETS_ENABLED, 0);
  320. /* Defines the number of consecutive slots for the strict priority */
  321. REG_WR(bp, PBF_REG_NUM_STRICT_ARB_SLOTS, 0x100);
  322. /* Defines the number of consecutive slots for the strict priority */
  323. REG_WR(bp, PBF_REG_HIGH_PRIORITY_COS_NUM, strict_cos);
  324. /*
  325. * mapping between entry priority to client number (0,1,2 -debug and
  326. * management clients, 3 - COS0 client, 4 - COS client)(HIGHEST)
  327. * 3bits client num.
  328. * PRI4 | PRI3 | PRI2 | PRI1 | PRI0
  329. * dbg0-010 dbg1-001 cos1-100 cos0-011 MCP-000
  330. * dbg0-010 dbg1-001 cos0-011 cos1-100 MCP-000
  331. */
  332. val = (0 == strict_cos) ? 0x2318 : 0x22E0;
  333. REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT, val);
  334. return 0;
  335. }
  336. /******************************************************************/
  337. /* PFC section */
  338. /******************************************************************/
  339. static void bnx2x_bmac2_get_pfc_stat(struct link_params *params,
  340. u32 pfc_frames_sent[2],
  341. u32 pfc_frames_received[2])
  342. {
  343. /* Read pfc statistic */
  344. struct bnx2x *bp = params->bp;
  345. u32 bmac_addr = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
  346. NIG_REG_INGRESS_BMAC0_MEM;
  347. DP(NETIF_MSG_LINK, "pfc statistic read from BMAC\n");
  348. REG_RD_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_STAT_GTPP,
  349. pfc_frames_sent, 2);
  350. REG_RD_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_STAT_GRPP,
  351. pfc_frames_received, 2);
  352. }
  353. static void bnx2x_emac_get_pfc_stat(struct link_params *params,
  354. u32 pfc_frames_sent[2],
  355. u32 pfc_frames_received[2])
  356. {
  357. /* Read pfc statistic */
  358. struct bnx2x *bp = params->bp;
  359. u32 emac_base = params->port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  360. u32 val_xon = 0;
  361. u32 val_xoff = 0;
  362. DP(NETIF_MSG_LINK, "pfc statistic read from EMAC\n");
  363. /* PFC received frames */
  364. val_xoff = REG_RD(bp, emac_base +
  365. EMAC_REG_RX_PFC_STATS_XOFF_RCVD);
  366. val_xoff &= EMAC_REG_RX_PFC_STATS_XOFF_RCVD_COUNT;
  367. val_xon = REG_RD(bp, emac_base + EMAC_REG_RX_PFC_STATS_XON_RCVD);
  368. val_xon &= EMAC_REG_RX_PFC_STATS_XON_RCVD_COUNT;
  369. pfc_frames_received[0] = val_xon + val_xoff;
  370. /* PFC received sent */
  371. val_xoff = REG_RD(bp, emac_base +
  372. EMAC_REG_RX_PFC_STATS_XOFF_SENT);
  373. val_xoff &= EMAC_REG_RX_PFC_STATS_XOFF_SENT_COUNT;
  374. val_xon = REG_RD(bp, emac_base + EMAC_REG_RX_PFC_STATS_XON_SENT);
  375. val_xon &= EMAC_REG_RX_PFC_STATS_XON_SENT_COUNT;
  376. pfc_frames_sent[0] = val_xon + val_xoff;
  377. }
  378. void bnx2x_pfc_statistic(struct link_params *params, struct link_vars *vars,
  379. u32 pfc_frames_sent[2],
  380. u32 pfc_frames_received[2])
  381. {
  382. /* Read pfc statistic */
  383. struct bnx2x *bp = params->bp;
  384. u32 val = 0;
  385. DP(NETIF_MSG_LINK, "pfc statistic\n");
  386. if (!vars->link_up)
  387. return;
  388. val = REG_RD(bp, MISC_REG_RESET_REG_2);
  389. if ((val & (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << params->port))
  390. == 0) {
  391. DP(NETIF_MSG_LINK, "About to read stats from EMAC\n");
  392. bnx2x_emac_get_pfc_stat(params, pfc_frames_sent,
  393. pfc_frames_received);
  394. } else {
  395. DP(NETIF_MSG_LINK, "About to read stats from BMAC\n");
  396. bnx2x_bmac2_get_pfc_stat(params, pfc_frames_sent,
  397. pfc_frames_received);
  398. }
  399. }
  400. /******************************************************************/
  401. /* MAC/PBF section */
  402. /******************************************************************/
  403. static void bnx2x_emac_init(struct link_params *params,
  404. struct link_vars *vars)
  405. {
  406. /* reset and unreset the emac core */
  407. struct bnx2x *bp = params->bp;
  408. u8 port = params->port;
  409. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  410. u32 val;
  411. u16 timeout;
  412. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  413. (MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE << port));
  414. udelay(5);
  415. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  416. (MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE << port));
  417. /* init emac - use read-modify-write */
  418. /* self clear reset */
  419. val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
  420. EMAC_WR(bp, EMAC_REG_EMAC_MODE, (val | EMAC_MODE_RESET));
  421. timeout = 200;
  422. do {
  423. val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
  424. DP(NETIF_MSG_LINK, "EMAC reset reg is %u\n", val);
  425. if (!timeout) {
  426. DP(NETIF_MSG_LINK, "EMAC timeout!\n");
  427. return;
  428. }
  429. timeout--;
  430. } while (val & EMAC_MODE_RESET);
  431. /* Set mac address */
  432. val = ((params->mac_addr[0] << 8) |
  433. params->mac_addr[1]);
  434. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH, val);
  435. val = ((params->mac_addr[2] << 24) |
  436. (params->mac_addr[3] << 16) |
  437. (params->mac_addr[4] << 8) |
  438. params->mac_addr[5]);
  439. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + 4, val);
  440. }
  441. static u8 bnx2x_emac_enable(struct link_params *params,
  442. struct link_vars *vars, u8 lb)
  443. {
  444. struct bnx2x *bp = params->bp;
  445. u8 port = params->port;
  446. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  447. u32 val;
  448. DP(NETIF_MSG_LINK, "enabling EMAC\n");
  449. /* enable emac and not bmac */
  450. REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + port*4, 1);
  451. /* ASIC */
  452. if (vars->phy_flags & PHY_XGXS_FLAG) {
  453. u32 ser_lane = ((params->lane_config &
  454. PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
  455. PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
  456. DP(NETIF_MSG_LINK, "XGXS\n");
  457. /* select the master lanes (out of 0-3) */
  458. REG_WR(bp, NIG_REG_XGXS_LANE_SEL_P0 + port*4, ser_lane);
  459. /* select XGXS */
  460. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  461. } else { /* SerDes */
  462. DP(NETIF_MSG_LINK, "SerDes\n");
  463. /* select SerDes */
  464. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 0);
  465. }
  466. bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_RX_MODE,
  467. EMAC_RX_MODE_RESET);
  468. bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
  469. EMAC_TX_MODE_RESET);
  470. if (CHIP_REV_IS_SLOW(bp)) {
  471. /* config GMII mode */
  472. val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
  473. EMAC_WR(bp, EMAC_REG_EMAC_MODE, (val | EMAC_MODE_PORT_GMII));
  474. } else { /* ASIC */
  475. /* pause enable/disable */
  476. bnx2x_bits_dis(bp, emac_base + EMAC_REG_EMAC_RX_MODE,
  477. EMAC_RX_MODE_FLOW_EN);
  478. bnx2x_bits_dis(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
  479. (EMAC_TX_MODE_EXT_PAUSE_EN |
  480. EMAC_TX_MODE_FLOW_EN));
  481. if (!(params->feature_config_flags &
  482. FEATURE_CONFIG_PFC_ENABLED)) {
  483. if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
  484. bnx2x_bits_en(bp, emac_base +
  485. EMAC_REG_EMAC_RX_MODE,
  486. EMAC_RX_MODE_FLOW_EN);
  487. if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
  488. bnx2x_bits_en(bp, emac_base +
  489. EMAC_REG_EMAC_TX_MODE,
  490. (EMAC_TX_MODE_EXT_PAUSE_EN |
  491. EMAC_TX_MODE_FLOW_EN));
  492. } else
  493. bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
  494. EMAC_TX_MODE_FLOW_EN);
  495. }
  496. /* KEEP_VLAN_TAG, promiscuous */
  497. val = REG_RD(bp, emac_base + EMAC_REG_EMAC_RX_MODE);
  498. val |= EMAC_RX_MODE_KEEP_VLAN_TAG | EMAC_RX_MODE_PROMISCUOUS;
  499. /*
  500. * Setting this bit causes MAC control frames (except for pause
  501. * frames) to be passed on for processing. This setting has no
  502. * affect on the operation of the pause frames. This bit effects
  503. * all packets regardless of RX Parser packet sorting logic.
  504. * Turn the PFC off to make sure we are in Xon state before
  505. * enabling it.
  506. */
  507. EMAC_WR(bp, EMAC_REG_RX_PFC_MODE, 0);
  508. if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED) {
  509. DP(NETIF_MSG_LINK, "PFC is enabled\n");
  510. /* Enable PFC again */
  511. EMAC_WR(bp, EMAC_REG_RX_PFC_MODE,
  512. EMAC_REG_RX_PFC_MODE_RX_EN |
  513. EMAC_REG_RX_PFC_MODE_TX_EN |
  514. EMAC_REG_RX_PFC_MODE_PRIORITIES);
  515. EMAC_WR(bp, EMAC_REG_RX_PFC_PARAM,
  516. ((0x0101 <<
  517. EMAC_REG_RX_PFC_PARAM_OPCODE_BITSHIFT) |
  518. (0x00ff <<
  519. EMAC_REG_RX_PFC_PARAM_PRIORITY_EN_BITSHIFT)));
  520. val |= EMAC_RX_MODE_KEEP_MAC_CONTROL;
  521. }
  522. EMAC_WR(bp, EMAC_REG_EMAC_RX_MODE, val);
  523. /* Set Loopback */
  524. val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
  525. if (lb)
  526. val |= 0x810;
  527. else
  528. val &= ~0x810;
  529. EMAC_WR(bp, EMAC_REG_EMAC_MODE, val);
  530. /* enable emac */
  531. REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 1);
  532. /* enable emac for jumbo packets */
  533. EMAC_WR(bp, EMAC_REG_EMAC_RX_MTU_SIZE,
  534. (EMAC_RX_MTU_SIZE_JUMBO_ENA |
  535. (ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD)));
  536. /* strip CRC */
  537. REG_WR(bp, NIG_REG_NIG_INGRESS_EMAC0_NO_CRC + port*4, 0x1);
  538. /* disable the NIG in/out to the bmac */
  539. REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0x0);
  540. REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + port*4, 0x0);
  541. REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0x0);
  542. /* enable the NIG in/out to the emac */
  543. REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0x1);
  544. val = 0;
  545. if ((params->feature_config_flags &
  546. FEATURE_CONFIG_PFC_ENABLED) ||
  547. (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
  548. val = 1;
  549. REG_WR(bp, NIG_REG_EMAC0_PAUSE_OUT_EN + port*4, val);
  550. REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0x1);
  551. REG_WR(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4, 0x0);
  552. vars->mac_type = MAC_TYPE_EMAC;
  553. return 0;
  554. }
  555. static void bnx2x_update_pfc_bmac1(struct link_params *params,
  556. struct link_vars *vars)
  557. {
  558. u32 wb_data[2];
  559. struct bnx2x *bp = params->bp;
  560. u32 bmac_addr = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
  561. NIG_REG_INGRESS_BMAC0_MEM;
  562. u32 val = 0x14;
  563. if ((!(params->feature_config_flags &
  564. FEATURE_CONFIG_PFC_ENABLED)) &&
  565. (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX))
  566. /* Enable BigMAC to react on received Pause packets */
  567. val |= (1<<5);
  568. wb_data[0] = val;
  569. wb_data[1] = 0;
  570. REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_CONTROL, wb_data, 2);
  571. /* tx control */
  572. val = 0xc0;
  573. if (!(params->feature_config_flags &
  574. FEATURE_CONFIG_PFC_ENABLED) &&
  575. (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
  576. val |= 0x800000;
  577. wb_data[0] = val;
  578. wb_data[1] = 0;
  579. REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_CONTROL, wb_data, 2);
  580. }
  581. static void bnx2x_update_pfc_bmac2(struct link_params *params,
  582. struct link_vars *vars,
  583. u8 is_lb)
  584. {
  585. /*
  586. * Set rx control: Strip CRC and enable BigMAC to relay
  587. * control packets to the system as well
  588. */
  589. u32 wb_data[2];
  590. struct bnx2x *bp = params->bp;
  591. u32 bmac_addr = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
  592. NIG_REG_INGRESS_BMAC0_MEM;
  593. u32 val = 0x14;
  594. if ((!(params->feature_config_flags &
  595. FEATURE_CONFIG_PFC_ENABLED)) &&
  596. (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX))
  597. /* Enable BigMAC to react on received Pause packets */
  598. val |= (1<<5);
  599. wb_data[0] = val;
  600. wb_data[1] = 0;
  601. REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_CONTROL, wb_data, 2);
  602. udelay(30);
  603. /* Tx control */
  604. val = 0xc0;
  605. if (!(params->feature_config_flags &
  606. FEATURE_CONFIG_PFC_ENABLED) &&
  607. (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
  608. val |= 0x800000;
  609. wb_data[0] = val;
  610. wb_data[1] = 0;
  611. REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_CONTROL, wb_data, 2);
  612. if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED) {
  613. DP(NETIF_MSG_LINK, "PFC is enabled\n");
  614. /* Enable PFC RX & TX & STATS and set 8 COS */
  615. wb_data[0] = 0x0;
  616. wb_data[0] |= (1<<0); /* RX */
  617. wb_data[0] |= (1<<1); /* TX */
  618. wb_data[0] |= (1<<2); /* Force initial Xon */
  619. wb_data[0] |= (1<<3); /* 8 cos */
  620. wb_data[0] |= (1<<5); /* STATS */
  621. wb_data[1] = 0;
  622. REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_PFC_CONTROL,
  623. wb_data, 2);
  624. /* Clear the force Xon */
  625. wb_data[0] &= ~(1<<2);
  626. } else {
  627. DP(NETIF_MSG_LINK, "PFC is disabled\n");
  628. /* disable PFC RX & TX & STATS and set 8 COS */
  629. wb_data[0] = 0x8;
  630. wb_data[1] = 0;
  631. }
  632. REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_PFC_CONTROL, wb_data, 2);
  633. /*
  634. * Set Time (based unit is 512 bit time) between automatic
  635. * re-sending of PP packets amd enable automatic re-send of
  636. * Per-Priroity Packet as long as pp_gen is asserted and
  637. * pp_disable is low.
  638. */
  639. val = 0x8000;
  640. if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
  641. val |= (1<<16); /* enable automatic re-send */
  642. wb_data[0] = val;
  643. wb_data[1] = 0;
  644. REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_PAUSE_CONTROL,
  645. wb_data, 2);
  646. /* mac control */
  647. val = 0x3; /* Enable RX and TX */
  648. if (is_lb) {
  649. val |= 0x4; /* Local loopback */
  650. DP(NETIF_MSG_LINK, "enable bmac loopback\n");
  651. }
  652. /* When PFC enabled, Pass pause frames towards the NIG. */
  653. if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
  654. val |= ((1<<6)|(1<<5));
  655. wb_data[0] = val;
  656. wb_data[1] = 0;
  657. REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_BMAC_CONTROL, wb_data, 2);
  658. }
  659. static void bnx2x_update_pfc_brb(struct link_params *params,
  660. struct link_vars *vars,
  661. struct bnx2x_nig_brb_pfc_port_params *pfc_params)
  662. {
  663. struct bnx2x *bp = params->bp;
  664. int set_pfc = params->feature_config_flags &
  665. FEATURE_CONFIG_PFC_ENABLED;
  666. /* default - pause configuration */
  667. u32 pause_xoff_th = PFC_BRB_MAC_PAUSE_XOFF_THRESHOLD_PAUSEABLE;
  668. u32 pause_xon_th = PFC_BRB_MAC_PAUSE_XON_THRESHOLD_PAUSEABLE;
  669. u32 full_xoff_th = PFC_BRB_MAC_FULL_XOFF_THRESHOLD_PAUSEABLE;
  670. u32 full_xon_th = PFC_BRB_MAC_FULL_XON_THRESHOLD_PAUSEABLE;
  671. if (set_pfc && pfc_params)
  672. /* First COS */
  673. if (!pfc_params->cos0_pauseable) {
  674. pause_xoff_th =
  675. PFC_BRB_MAC_PAUSE_XOFF_THRESHOLD_NON_PAUSEABLE;
  676. pause_xon_th =
  677. PFC_BRB_MAC_PAUSE_XON_THRESHOLD_NON_PAUSEABLE;
  678. full_xoff_th =
  679. PFC_BRB_MAC_FULL_XOFF_THRESHOLD_NON_PAUSEABLE;
  680. full_xon_th =
  681. PFC_BRB_MAC_FULL_XON_THRESHOLD_NON_PAUSEABLE;
  682. }
  683. /*
  684. * The number of free blocks below which the pause signal to class 0
  685. * of MAC #n is asserted. n=0,1
  686. */
  687. REG_WR(bp, BRB1_REG_PAUSE_0_XOFF_THRESHOLD_0 , pause_xoff_th);
  688. /*
  689. * The number of free blocks above which the pause signal to class 0
  690. * of MAC #n is de-asserted. n=0,1
  691. */
  692. REG_WR(bp, BRB1_REG_PAUSE_0_XON_THRESHOLD_0 , pause_xon_th);
  693. /*
  694. * The number of free blocks below which the full signal to class 0
  695. * of MAC #n is asserted. n=0,1
  696. */
  697. REG_WR(bp, BRB1_REG_FULL_0_XOFF_THRESHOLD_0 , full_xoff_th);
  698. /*
  699. * The number of free blocks above which the full signal to class 0
  700. * of MAC #n is de-asserted. n=0,1
  701. */
  702. REG_WR(bp, BRB1_REG_FULL_0_XON_THRESHOLD_0 , full_xon_th);
  703. if (set_pfc && pfc_params) {
  704. /* Second COS */
  705. if (pfc_params->cos1_pauseable) {
  706. pause_xoff_th =
  707. PFC_BRB_MAC_PAUSE_XOFF_THRESHOLD_PAUSEABLE;
  708. pause_xon_th =
  709. PFC_BRB_MAC_PAUSE_XON_THRESHOLD_PAUSEABLE;
  710. full_xoff_th =
  711. PFC_BRB_MAC_FULL_XOFF_THRESHOLD_PAUSEABLE;
  712. full_xon_th =
  713. PFC_BRB_MAC_FULL_XON_THRESHOLD_PAUSEABLE;
  714. } else {
  715. pause_xoff_th =
  716. PFC_BRB_MAC_PAUSE_XOFF_THRESHOLD_NON_PAUSEABLE;
  717. pause_xon_th =
  718. PFC_BRB_MAC_PAUSE_XON_THRESHOLD_NON_PAUSEABLE;
  719. full_xoff_th =
  720. PFC_BRB_MAC_FULL_XOFF_THRESHOLD_NON_PAUSEABLE;
  721. full_xon_th =
  722. PFC_BRB_MAC_FULL_XON_THRESHOLD_NON_PAUSEABLE;
  723. }
  724. /*
  725. * The number of free blocks below which the pause signal to
  726. * class 1 of MAC #n is asserted. n=0,1
  727. */
  728. REG_WR(bp, BRB1_REG_PAUSE_1_XOFF_THRESHOLD_0, pause_xoff_th);
  729. /*
  730. * The number of free blocks above which the pause signal to
  731. * class 1 of MAC #n is de-asserted. n=0,1
  732. */
  733. REG_WR(bp, BRB1_REG_PAUSE_1_XON_THRESHOLD_0, pause_xon_th);
  734. /*
  735. * The number of free blocks below which the full signal to
  736. * class 1 of MAC #n is asserted. n=0,1
  737. */
  738. REG_WR(bp, BRB1_REG_FULL_1_XOFF_THRESHOLD_0, full_xoff_th);
  739. /*
  740. * The number of free blocks above which the full signal to
  741. * class 1 of MAC #n is de-asserted. n=0,1
  742. */
  743. REG_WR(bp, BRB1_REG_FULL_1_XON_THRESHOLD_0, full_xon_th);
  744. }
  745. }
  746. static void bnx2x_update_pfc_nig(struct link_params *params,
  747. struct link_vars *vars,
  748. struct bnx2x_nig_brb_pfc_port_params *nig_params)
  749. {
  750. u32 xcm_mask = 0, ppp_enable = 0, pause_enable = 0, llfc_out_en = 0;
  751. u32 llfc_enable = 0, xcm0_out_en = 0, p0_hwpfc_enable = 0;
  752. u32 pkt_priority_to_cos = 0;
  753. u32 val;
  754. struct bnx2x *bp = params->bp;
  755. int port = params->port;
  756. int set_pfc = params->feature_config_flags &
  757. FEATURE_CONFIG_PFC_ENABLED;
  758. DP(NETIF_MSG_LINK, "updating pfc nig parameters\n");
  759. /*
  760. * When NIG_LLH0_XCM_MASK_REG_LLHX_XCM_MASK_BCN bit is set
  761. * MAC control frames (that are not pause packets)
  762. * will be forwarded to the XCM.
  763. */
  764. xcm_mask = REG_RD(bp,
  765. port ? NIG_REG_LLH1_XCM_MASK :
  766. NIG_REG_LLH0_XCM_MASK);
  767. /*
  768. * nig params will override non PFC params, since it's possible to
  769. * do transition from PFC to SAFC
  770. */
  771. if (set_pfc) {
  772. pause_enable = 0;
  773. llfc_out_en = 0;
  774. llfc_enable = 0;
  775. ppp_enable = 1;
  776. xcm_mask &= ~(port ? NIG_LLH1_XCM_MASK_REG_LLH1_XCM_MASK_BCN :
  777. NIG_LLH0_XCM_MASK_REG_LLH0_XCM_MASK_BCN);
  778. xcm0_out_en = 0;
  779. p0_hwpfc_enable = 1;
  780. } else {
  781. if (nig_params) {
  782. llfc_out_en = nig_params->llfc_out_en;
  783. llfc_enable = nig_params->llfc_enable;
  784. pause_enable = nig_params->pause_enable;
  785. } else /*defaul non PFC mode - PAUSE */
  786. pause_enable = 1;
  787. xcm_mask |= (port ? NIG_LLH1_XCM_MASK_REG_LLH1_XCM_MASK_BCN :
  788. NIG_LLH0_XCM_MASK_REG_LLH0_XCM_MASK_BCN);
  789. xcm0_out_en = 1;
  790. }
  791. REG_WR(bp, port ? NIG_REG_LLFC_OUT_EN_1 :
  792. NIG_REG_LLFC_OUT_EN_0, llfc_out_en);
  793. REG_WR(bp, port ? NIG_REG_LLFC_ENABLE_1 :
  794. NIG_REG_LLFC_ENABLE_0, llfc_enable);
  795. REG_WR(bp, port ? NIG_REG_PAUSE_ENABLE_1 :
  796. NIG_REG_PAUSE_ENABLE_0, pause_enable);
  797. REG_WR(bp, port ? NIG_REG_PPP_ENABLE_1 :
  798. NIG_REG_PPP_ENABLE_0, ppp_enable);
  799. REG_WR(bp, port ? NIG_REG_LLH1_XCM_MASK :
  800. NIG_REG_LLH0_XCM_MASK, xcm_mask);
  801. REG_WR(bp, NIG_REG_LLFC_EGRESS_SRC_ENABLE_0, 0x7);
  802. /* output enable for RX_XCM # IF */
  803. REG_WR(bp, NIG_REG_XCM0_OUT_EN, xcm0_out_en);
  804. /* HW PFC TX enable */
  805. REG_WR(bp, NIG_REG_P0_HWPFC_ENABLE, p0_hwpfc_enable);
  806. /* 0x2 = BMAC, 0x1= EMAC */
  807. switch (vars->mac_type) {
  808. case MAC_TYPE_EMAC:
  809. val = 1;
  810. break;
  811. case MAC_TYPE_BMAC:
  812. val = 0;
  813. break;
  814. default:
  815. val = 0;
  816. break;
  817. }
  818. REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT, val);
  819. if (nig_params) {
  820. pkt_priority_to_cos = nig_params->pkt_priority_to_cos;
  821. REG_WR(bp, port ? NIG_REG_P1_RX_COS0_PRIORITY_MASK :
  822. NIG_REG_P0_RX_COS0_PRIORITY_MASK,
  823. nig_params->rx_cos0_priority_mask);
  824. REG_WR(bp, port ? NIG_REG_P1_RX_COS1_PRIORITY_MASK :
  825. NIG_REG_P0_RX_COS1_PRIORITY_MASK,
  826. nig_params->rx_cos1_priority_mask);
  827. REG_WR(bp, port ? NIG_REG_LLFC_HIGH_PRIORITY_CLASSES_1 :
  828. NIG_REG_LLFC_HIGH_PRIORITY_CLASSES_0,
  829. nig_params->llfc_high_priority_classes);
  830. REG_WR(bp, port ? NIG_REG_LLFC_LOW_PRIORITY_CLASSES_1 :
  831. NIG_REG_LLFC_LOW_PRIORITY_CLASSES_0,
  832. nig_params->llfc_low_priority_classes);
  833. }
  834. REG_WR(bp, port ? NIG_REG_P1_PKT_PRIORITY_TO_COS :
  835. NIG_REG_P0_PKT_PRIORITY_TO_COS,
  836. pkt_priority_to_cos);
  837. }
  838. void bnx2x_update_pfc(struct link_params *params,
  839. struct link_vars *vars,
  840. struct bnx2x_nig_brb_pfc_port_params *pfc_params)
  841. {
  842. /*
  843. * The PFC and pause are orthogonal to one another, meaning when
  844. * PFC is enabled, the pause are disabled, and when PFC is
  845. * disabled, pause are set according to the pause result.
  846. */
  847. u32 val;
  848. struct bnx2x *bp = params->bp;
  849. /* update NIG params */
  850. bnx2x_update_pfc_nig(params, vars, pfc_params);
  851. /* update BRB params */
  852. bnx2x_update_pfc_brb(params, vars, pfc_params);
  853. if (!vars->link_up)
  854. return;
  855. val = REG_RD(bp, MISC_REG_RESET_REG_2);
  856. if ((val & (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << params->port))
  857. == 0) {
  858. DP(NETIF_MSG_LINK, "About to update PFC in EMAC\n");
  859. bnx2x_emac_enable(params, vars, 0);
  860. return;
  861. }
  862. DP(NETIF_MSG_LINK, "About to update PFC in BMAC\n");
  863. if (CHIP_IS_E2(bp))
  864. bnx2x_update_pfc_bmac2(params, vars, 0);
  865. else
  866. bnx2x_update_pfc_bmac1(params, vars);
  867. val = 0;
  868. if ((params->feature_config_flags &
  869. FEATURE_CONFIG_PFC_ENABLED) ||
  870. (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
  871. val = 1;
  872. REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + params->port*4, val);
  873. }
  874. static u8 bnx2x_bmac1_enable(struct link_params *params,
  875. struct link_vars *vars,
  876. u8 is_lb)
  877. {
  878. struct bnx2x *bp = params->bp;
  879. u8 port = params->port;
  880. u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
  881. NIG_REG_INGRESS_BMAC0_MEM;
  882. u32 wb_data[2];
  883. u32 val;
  884. DP(NETIF_MSG_LINK, "Enabling BigMAC1\n");
  885. /* XGXS control */
  886. wb_data[0] = 0x3c;
  887. wb_data[1] = 0;
  888. REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_BMAC_XGXS_CONTROL,
  889. wb_data, 2);
  890. /* tx MAC SA */
  891. wb_data[0] = ((params->mac_addr[2] << 24) |
  892. (params->mac_addr[3] << 16) |
  893. (params->mac_addr[4] << 8) |
  894. params->mac_addr[5]);
  895. wb_data[1] = ((params->mac_addr[0] << 8) |
  896. params->mac_addr[1]);
  897. REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_SOURCE_ADDR, wb_data, 2);
  898. /* mac control */
  899. val = 0x3;
  900. if (is_lb) {
  901. val |= 0x4;
  902. DP(NETIF_MSG_LINK, "enable bmac loopback\n");
  903. }
  904. wb_data[0] = val;
  905. wb_data[1] = 0;
  906. REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_BMAC_CONTROL, wb_data, 2);
  907. /* set rx mtu */
  908. wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
  909. wb_data[1] = 0;
  910. REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_MAX_SIZE, wb_data, 2);
  911. bnx2x_update_pfc_bmac1(params, vars);
  912. /* set tx mtu */
  913. wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
  914. wb_data[1] = 0;
  915. REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_MAX_SIZE, wb_data, 2);
  916. /* set cnt max size */
  917. wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
  918. wb_data[1] = 0;
  919. REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_CNT_MAX_SIZE, wb_data, 2);
  920. /* configure safc */
  921. wb_data[0] = 0x1000200;
  922. wb_data[1] = 0;
  923. REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_LLFC_MSG_FLDS,
  924. wb_data, 2);
  925. return 0;
  926. }
  927. static u8 bnx2x_bmac2_enable(struct link_params *params,
  928. struct link_vars *vars,
  929. u8 is_lb)
  930. {
  931. struct bnx2x *bp = params->bp;
  932. u8 port = params->port;
  933. u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
  934. NIG_REG_INGRESS_BMAC0_MEM;
  935. u32 wb_data[2];
  936. DP(NETIF_MSG_LINK, "Enabling BigMAC2\n");
  937. wb_data[0] = 0;
  938. wb_data[1] = 0;
  939. REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_BMAC_CONTROL, wb_data, 2);
  940. udelay(30);
  941. /* XGXS control: Reset phy HW, MDIO registers, PHY PLL and BMAC */
  942. wb_data[0] = 0x3c;
  943. wb_data[1] = 0;
  944. REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_BMAC_XGXS_CONTROL,
  945. wb_data, 2);
  946. udelay(30);
  947. /* tx MAC SA */
  948. wb_data[0] = ((params->mac_addr[2] << 24) |
  949. (params->mac_addr[3] << 16) |
  950. (params->mac_addr[4] << 8) |
  951. params->mac_addr[5]);
  952. wb_data[1] = ((params->mac_addr[0] << 8) |
  953. params->mac_addr[1]);
  954. REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_SOURCE_ADDR,
  955. wb_data, 2);
  956. udelay(30);
  957. /* Configure SAFC */
  958. wb_data[0] = 0x1000200;
  959. wb_data[1] = 0;
  960. REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_LLFC_MSG_FLDS,
  961. wb_data, 2);
  962. udelay(30);
  963. /* set rx mtu */
  964. wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
  965. wb_data[1] = 0;
  966. REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_MAX_SIZE, wb_data, 2);
  967. udelay(30);
  968. /* set tx mtu */
  969. wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
  970. wb_data[1] = 0;
  971. REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_MAX_SIZE, wb_data, 2);
  972. udelay(30);
  973. /* set cnt max size */
  974. wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD - 2;
  975. wb_data[1] = 0;
  976. REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_CNT_MAX_SIZE, wb_data, 2);
  977. udelay(30);
  978. bnx2x_update_pfc_bmac2(params, vars, is_lb);
  979. return 0;
  980. }
  981. static u8 bnx2x_bmac_enable(struct link_params *params,
  982. struct link_vars *vars,
  983. u8 is_lb)
  984. {
  985. u8 rc, port = params->port;
  986. struct bnx2x *bp = params->bp;
  987. u32 val;
  988. /* reset and unreset the BigMac */
  989. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  990. (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
  991. msleep(1);
  992. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  993. (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
  994. /* enable access for bmac registers */
  995. REG_WR(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4, 0x1);
  996. /* Enable BMAC according to BMAC type*/
  997. if (CHIP_IS_E2(bp))
  998. rc = bnx2x_bmac2_enable(params, vars, is_lb);
  999. else
  1000. rc = bnx2x_bmac1_enable(params, vars, is_lb);
  1001. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 0x1);
  1002. REG_WR(bp, NIG_REG_XGXS_LANE_SEL_P0 + port*4, 0x0);
  1003. REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + port*4, 0x0);
  1004. val = 0;
  1005. if ((params->feature_config_flags &
  1006. FEATURE_CONFIG_PFC_ENABLED) ||
  1007. (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
  1008. val = 1;
  1009. REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + port*4, val);
  1010. REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0x0);
  1011. REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0x0);
  1012. REG_WR(bp, NIG_REG_EMAC0_PAUSE_OUT_EN + port*4, 0x0);
  1013. REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0x1);
  1014. REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0x1);
  1015. vars->mac_type = MAC_TYPE_BMAC;
  1016. return rc;
  1017. }
  1018. static void bnx2x_update_mng(struct link_params *params, u32 link_status)
  1019. {
  1020. struct bnx2x *bp = params->bp;
  1021. REG_WR(bp, params->shmem_base +
  1022. offsetof(struct shmem_region,
  1023. port_mb[params->port].link_status), link_status);
  1024. }
  1025. static void bnx2x_bmac_rx_disable(struct bnx2x *bp, u8 port)
  1026. {
  1027. u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
  1028. NIG_REG_INGRESS_BMAC0_MEM;
  1029. u32 wb_data[2];
  1030. u32 nig_bmac_enable = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4);
  1031. /* Only if the bmac is out of reset */
  1032. if (REG_RD(bp, MISC_REG_RESET_REG_2) &
  1033. (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port) &&
  1034. nig_bmac_enable) {
  1035. if (CHIP_IS_E2(bp)) {
  1036. /* Clear Rx Enable bit in BMAC_CONTROL register */
  1037. REG_RD_DMAE(bp, bmac_addr +
  1038. BIGMAC2_REGISTER_BMAC_CONTROL,
  1039. wb_data, 2);
  1040. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  1041. REG_WR_DMAE(bp, bmac_addr +
  1042. BIGMAC2_REGISTER_BMAC_CONTROL,
  1043. wb_data, 2);
  1044. } else {
  1045. /* Clear Rx Enable bit in BMAC_CONTROL register */
  1046. REG_RD_DMAE(bp, bmac_addr +
  1047. BIGMAC_REGISTER_BMAC_CONTROL,
  1048. wb_data, 2);
  1049. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  1050. REG_WR_DMAE(bp, bmac_addr +
  1051. BIGMAC_REGISTER_BMAC_CONTROL,
  1052. wb_data, 2);
  1053. }
  1054. msleep(1);
  1055. }
  1056. }
  1057. static u8 bnx2x_pbf_update(struct link_params *params, u32 flow_ctrl,
  1058. u32 line_speed)
  1059. {
  1060. struct bnx2x *bp = params->bp;
  1061. u8 port = params->port;
  1062. u32 init_crd, crd;
  1063. u32 count = 1000;
  1064. /* disable port */
  1065. REG_WR(bp, PBF_REG_DISABLE_NEW_TASK_PROC_P0 + port*4, 0x1);
  1066. /* wait for init credit */
  1067. init_crd = REG_RD(bp, PBF_REG_P0_INIT_CRD + port*4);
  1068. crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
  1069. DP(NETIF_MSG_LINK, "init_crd 0x%x crd 0x%x\n", init_crd, crd);
  1070. while ((init_crd != crd) && count) {
  1071. msleep(5);
  1072. crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
  1073. count--;
  1074. }
  1075. crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
  1076. if (init_crd != crd) {
  1077. DP(NETIF_MSG_LINK, "BUG! init_crd 0x%x != crd 0x%x\n",
  1078. init_crd, crd);
  1079. return -EINVAL;
  1080. }
  1081. if (flow_ctrl & BNX2X_FLOW_CTRL_RX ||
  1082. line_speed == SPEED_10 ||
  1083. line_speed == SPEED_100 ||
  1084. line_speed == SPEED_1000 ||
  1085. line_speed == SPEED_2500) {
  1086. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 1);
  1087. /* update threshold */
  1088. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, 0);
  1089. /* update init credit */
  1090. init_crd = 778; /* (800-18-4) */
  1091. } else {
  1092. u32 thresh = (ETH_MAX_JUMBO_PACKET_SIZE +
  1093. ETH_OVREHEAD)/16;
  1094. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  1095. /* update threshold */
  1096. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, thresh);
  1097. /* update init credit */
  1098. switch (line_speed) {
  1099. case SPEED_10000:
  1100. init_crd = thresh + 553 - 22;
  1101. break;
  1102. case SPEED_12000:
  1103. init_crd = thresh + 664 - 22;
  1104. break;
  1105. case SPEED_13000:
  1106. init_crd = thresh + 742 - 22;
  1107. break;
  1108. case SPEED_16000:
  1109. init_crd = thresh + 778 - 22;
  1110. break;
  1111. default:
  1112. DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
  1113. line_speed);
  1114. return -EINVAL;
  1115. }
  1116. }
  1117. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, init_crd);
  1118. DP(NETIF_MSG_LINK, "PBF updated to speed %d credit %d\n",
  1119. line_speed, init_crd);
  1120. /* probe the credit changes */
  1121. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0x1);
  1122. msleep(5);
  1123. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0x0);
  1124. /* enable port */
  1125. REG_WR(bp, PBF_REG_DISABLE_NEW_TASK_PROC_P0 + port*4, 0x0);
  1126. return 0;
  1127. }
  1128. /**
  1129. * bnx2x_get_emac_base - retrive emac base address
  1130. *
  1131. * @bp: driver handle
  1132. * @mdc_mdio_access: access type
  1133. * @port: port id
  1134. *
  1135. * This function selects the MDC/MDIO access (through emac0 or
  1136. * emac1) depend on the mdc_mdio_access, port, port swapped. Each
  1137. * phy has a default access mode, which could also be overridden
  1138. * by nvram configuration. This parameter, whether this is the
  1139. * default phy configuration, or the nvram overrun
  1140. * configuration, is passed here as mdc_mdio_access and selects
  1141. * the emac_base for the CL45 read/writes operations
  1142. */
  1143. static u32 bnx2x_get_emac_base(struct bnx2x *bp,
  1144. u32 mdc_mdio_access, u8 port)
  1145. {
  1146. u32 emac_base = 0;
  1147. switch (mdc_mdio_access) {
  1148. case SHARED_HW_CFG_MDC_MDIO_ACCESS1_PHY_TYPE:
  1149. break;
  1150. case SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC0:
  1151. if (REG_RD(bp, NIG_REG_PORT_SWAP))
  1152. emac_base = GRCBASE_EMAC1;
  1153. else
  1154. emac_base = GRCBASE_EMAC0;
  1155. break;
  1156. case SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1:
  1157. if (REG_RD(bp, NIG_REG_PORT_SWAP))
  1158. emac_base = GRCBASE_EMAC0;
  1159. else
  1160. emac_base = GRCBASE_EMAC1;
  1161. break;
  1162. case SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH:
  1163. emac_base = (port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  1164. break;
  1165. case SHARED_HW_CFG_MDC_MDIO_ACCESS1_SWAPPED:
  1166. emac_base = (port) ? GRCBASE_EMAC0 : GRCBASE_EMAC1;
  1167. break;
  1168. default:
  1169. break;
  1170. }
  1171. return emac_base;
  1172. }
  1173. /******************************************************************/
  1174. /* CL45 access functions */
  1175. /******************************************************************/
  1176. static u8 bnx2x_cl45_write(struct bnx2x *bp, struct bnx2x_phy *phy,
  1177. u8 devad, u16 reg, u16 val)
  1178. {
  1179. u32 tmp, saved_mode;
  1180. u8 i, rc = 0;
  1181. /*
  1182. * Set clause 45 mode, slow down the MDIO clock to 2.5MHz
  1183. * (a value of 49==0x31) and make sure that the AUTO poll is off
  1184. */
  1185. saved_mode = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
  1186. tmp = saved_mode & ~(EMAC_MDIO_MODE_AUTO_POLL |
  1187. EMAC_MDIO_MODE_CLOCK_CNT);
  1188. tmp |= (EMAC_MDIO_MODE_CLAUSE_45 |
  1189. (49 << EMAC_MDIO_MODE_CLOCK_CNT_BITSHIFT));
  1190. REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, tmp);
  1191. REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
  1192. udelay(40);
  1193. /* address */
  1194. tmp = ((phy->addr << 21) | (devad << 16) | reg |
  1195. EMAC_MDIO_COMM_COMMAND_ADDRESS |
  1196. EMAC_MDIO_COMM_START_BUSY);
  1197. REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
  1198. for (i = 0; i < 50; i++) {
  1199. udelay(10);
  1200. tmp = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
  1201. if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
  1202. udelay(5);
  1203. break;
  1204. }
  1205. }
  1206. if (tmp & EMAC_MDIO_COMM_START_BUSY) {
  1207. DP(NETIF_MSG_LINK, "write phy register failed\n");
  1208. netdev_err(bp->dev, "MDC/MDIO access timeout\n");
  1209. rc = -EFAULT;
  1210. } else {
  1211. /* data */
  1212. tmp = ((phy->addr << 21) | (devad << 16) | val |
  1213. EMAC_MDIO_COMM_COMMAND_WRITE_45 |
  1214. EMAC_MDIO_COMM_START_BUSY);
  1215. REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
  1216. for (i = 0; i < 50; i++) {
  1217. udelay(10);
  1218. tmp = REG_RD(bp, phy->mdio_ctrl +
  1219. EMAC_REG_EMAC_MDIO_COMM);
  1220. if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
  1221. udelay(5);
  1222. break;
  1223. }
  1224. }
  1225. if (tmp & EMAC_MDIO_COMM_START_BUSY) {
  1226. DP(NETIF_MSG_LINK, "write phy register failed\n");
  1227. netdev_err(bp->dev, "MDC/MDIO access timeout\n");
  1228. rc = -EFAULT;
  1229. }
  1230. }
  1231. /* Restore the saved mode */
  1232. REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, saved_mode);
  1233. return rc;
  1234. }
  1235. static u8 bnx2x_cl45_read(struct bnx2x *bp, struct bnx2x_phy *phy,
  1236. u8 devad, u16 reg, u16 *ret_val)
  1237. {
  1238. u32 val, saved_mode;
  1239. u16 i;
  1240. u8 rc = 0;
  1241. /*
  1242. * Set clause 45 mode, slow down the MDIO clock to 2.5MHz
  1243. * (a value of 49==0x31) and make sure that the AUTO poll is off
  1244. */
  1245. saved_mode = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
  1246. val = saved_mode & ~((EMAC_MDIO_MODE_AUTO_POLL |
  1247. EMAC_MDIO_MODE_CLOCK_CNT));
  1248. val |= (EMAC_MDIO_MODE_CLAUSE_45 |
  1249. (49L << EMAC_MDIO_MODE_CLOCK_CNT_BITSHIFT));
  1250. REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, val);
  1251. REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
  1252. udelay(40);
  1253. /* address */
  1254. val = ((phy->addr << 21) | (devad << 16) | reg |
  1255. EMAC_MDIO_COMM_COMMAND_ADDRESS |
  1256. EMAC_MDIO_COMM_START_BUSY);
  1257. REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
  1258. for (i = 0; i < 50; i++) {
  1259. udelay(10);
  1260. val = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
  1261. if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
  1262. udelay(5);
  1263. break;
  1264. }
  1265. }
  1266. if (val & EMAC_MDIO_COMM_START_BUSY) {
  1267. DP(NETIF_MSG_LINK, "read phy register failed\n");
  1268. netdev_err(bp->dev, "MDC/MDIO access timeout\n");
  1269. *ret_val = 0;
  1270. rc = -EFAULT;
  1271. } else {
  1272. /* data */
  1273. val = ((phy->addr << 21) | (devad << 16) |
  1274. EMAC_MDIO_COMM_COMMAND_READ_45 |
  1275. EMAC_MDIO_COMM_START_BUSY);
  1276. REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
  1277. for (i = 0; i < 50; i++) {
  1278. udelay(10);
  1279. val = REG_RD(bp, phy->mdio_ctrl +
  1280. EMAC_REG_EMAC_MDIO_COMM);
  1281. if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
  1282. *ret_val = (u16)(val & EMAC_MDIO_COMM_DATA);
  1283. break;
  1284. }
  1285. }
  1286. if (val & EMAC_MDIO_COMM_START_BUSY) {
  1287. DP(NETIF_MSG_LINK, "read phy register failed\n");
  1288. netdev_err(bp->dev, "MDC/MDIO access timeout\n");
  1289. *ret_val = 0;
  1290. rc = -EFAULT;
  1291. }
  1292. }
  1293. /* Restore the saved mode */
  1294. REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, saved_mode);
  1295. return rc;
  1296. }
  1297. u8 bnx2x_phy_read(struct link_params *params, u8 phy_addr,
  1298. u8 devad, u16 reg, u16 *ret_val)
  1299. {
  1300. u8 phy_index;
  1301. /*
  1302. * Probe for the phy according to the given phy_addr, and execute
  1303. * the read request on it
  1304. */
  1305. for (phy_index = 0; phy_index < params->num_phys; phy_index++) {
  1306. if (params->phy[phy_index].addr == phy_addr) {
  1307. return bnx2x_cl45_read(params->bp,
  1308. &params->phy[phy_index], devad,
  1309. reg, ret_val);
  1310. }
  1311. }
  1312. return -EINVAL;
  1313. }
  1314. u8 bnx2x_phy_write(struct link_params *params, u8 phy_addr,
  1315. u8 devad, u16 reg, u16 val)
  1316. {
  1317. u8 phy_index;
  1318. /*
  1319. * Probe for the phy according to the given phy_addr, and execute
  1320. * the write request on it
  1321. */
  1322. for (phy_index = 0; phy_index < params->num_phys; phy_index++) {
  1323. if (params->phy[phy_index].addr == phy_addr) {
  1324. return bnx2x_cl45_write(params->bp,
  1325. &params->phy[phy_index], devad,
  1326. reg, val);
  1327. }
  1328. }
  1329. return -EINVAL;
  1330. }
  1331. static void bnx2x_set_aer_mmd_xgxs(struct link_params *params,
  1332. struct bnx2x_phy *phy)
  1333. {
  1334. u32 ser_lane;
  1335. u16 offset, aer_val;
  1336. struct bnx2x *bp = params->bp;
  1337. ser_lane = ((params->lane_config &
  1338. PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
  1339. PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
  1340. offset = phy->addr + ser_lane;
  1341. if (CHIP_IS_E2(bp))
  1342. aer_val = 0x3800 + offset - 1;
  1343. else
  1344. aer_val = 0x3800 + offset;
  1345. CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
  1346. MDIO_AER_BLOCK_AER_REG, aer_val);
  1347. }
  1348. static void bnx2x_set_aer_mmd_serdes(struct bnx2x *bp,
  1349. struct bnx2x_phy *phy)
  1350. {
  1351. CL22_WR_OVER_CL45(bp, phy,
  1352. MDIO_REG_BANK_AER_BLOCK,
  1353. MDIO_AER_BLOCK_AER_REG, 0x3800);
  1354. }
  1355. /******************************************************************/
  1356. /* Internal phy section */
  1357. /******************************************************************/
  1358. static void bnx2x_set_serdes_access(struct bnx2x *bp, u8 port)
  1359. {
  1360. u32 emac_base = (port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  1361. /* Set Clause 22 */
  1362. REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_ST + port*0x10, 1);
  1363. REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_COMM, 0x245f8000);
  1364. udelay(500);
  1365. REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_COMM, 0x245d000f);
  1366. udelay(500);
  1367. /* Set Clause 45 */
  1368. REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_ST + port*0x10, 0);
  1369. }
  1370. static void bnx2x_serdes_deassert(struct bnx2x *bp, u8 port)
  1371. {
  1372. u32 val;
  1373. DP(NETIF_MSG_LINK, "bnx2x_serdes_deassert\n");
  1374. val = SERDES_RESET_BITS << (port*16);
  1375. /* reset and unreset the SerDes/XGXS */
  1376. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR, val);
  1377. udelay(500);
  1378. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_SET, val);
  1379. bnx2x_set_serdes_access(bp, port);
  1380. REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_DEVAD + port*0x10,
  1381. DEFAULT_PHY_DEV_ADDR);
  1382. }
  1383. static void bnx2x_xgxs_deassert(struct link_params *params)
  1384. {
  1385. struct bnx2x *bp = params->bp;
  1386. u8 port;
  1387. u32 val;
  1388. DP(NETIF_MSG_LINK, "bnx2x_xgxs_deassert\n");
  1389. port = params->port;
  1390. val = XGXS_RESET_BITS << (port*16);
  1391. /* reset and unreset the SerDes/XGXS */
  1392. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR, val);
  1393. udelay(500);
  1394. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_SET, val);
  1395. REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_ST + port*0x18, 0);
  1396. REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18,
  1397. params->phy[INT_PHY].def_md_devad);
  1398. }
  1399. void bnx2x_link_status_update(struct link_params *params,
  1400. struct link_vars *vars)
  1401. {
  1402. struct bnx2x *bp = params->bp;
  1403. u8 link_10g;
  1404. u8 port = params->port;
  1405. vars->link_status = REG_RD(bp, params->shmem_base +
  1406. offsetof(struct shmem_region,
  1407. port_mb[port].link_status));
  1408. vars->link_up = (vars->link_status & LINK_STATUS_LINK_UP);
  1409. if (vars->link_up) {
  1410. DP(NETIF_MSG_LINK, "phy link up\n");
  1411. vars->phy_link_up = 1;
  1412. vars->duplex = DUPLEX_FULL;
  1413. switch (vars->link_status &
  1414. LINK_STATUS_SPEED_AND_DUPLEX_MASK) {
  1415. case LINK_10THD:
  1416. vars->duplex = DUPLEX_HALF;
  1417. /* fall thru */
  1418. case LINK_10TFD:
  1419. vars->line_speed = SPEED_10;
  1420. break;
  1421. case LINK_100TXHD:
  1422. vars->duplex = DUPLEX_HALF;
  1423. /* fall thru */
  1424. case LINK_100T4:
  1425. case LINK_100TXFD:
  1426. vars->line_speed = SPEED_100;
  1427. break;
  1428. case LINK_1000THD:
  1429. vars->duplex = DUPLEX_HALF;
  1430. /* fall thru */
  1431. case LINK_1000TFD:
  1432. vars->line_speed = SPEED_1000;
  1433. break;
  1434. case LINK_2500THD:
  1435. vars->duplex = DUPLEX_HALF;
  1436. /* fall thru */
  1437. case LINK_2500TFD:
  1438. vars->line_speed = SPEED_2500;
  1439. break;
  1440. case LINK_10GTFD:
  1441. vars->line_speed = SPEED_10000;
  1442. break;
  1443. case LINK_12GTFD:
  1444. vars->line_speed = SPEED_12000;
  1445. break;
  1446. case LINK_12_5GTFD:
  1447. vars->line_speed = SPEED_12500;
  1448. break;
  1449. case LINK_13GTFD:
  1450. vars->line_speed = SPEED_13000;
  1451. break;
  1452. case LINK_15GTFD:
  1453. vars->line_speed = SPEED_15000;
  1454. break;
  1455. case LINK_16GTFD:
  1456. vars->line_speed = SPEED_16000;
  1457. break;
  1458. default:
  1459. break;
  1460. }
  1461. vars->flow_ctrl = 0;
  1462. if (vars->link_status & LINK_STATUS_TX_FLOW_CONTROL_ENABLED)
  1463. vars->flow_ctrl |= BNX2X_FLOW_CTRL_TX;
  1464. if (vars->link_status & LINK_STATUS_RX_FLOW_CONTROL_ENABLED)
  1465. vars->flow_ctrl |= BNX2X_FLOW_CTRL_RX;
  1466. if (!vars->flow_ctrl)
  1467. vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  1468. if (vars->line_speed &&
  1469. ((vars->line_speed == SPEED_10) ||
  1470. (vars->line_speed == SPEED_100))) {
  1471. vars->phy_flags |= PHY_SGMII_FLAG;
  1472. } else {
  1473. vars->phy_flags &= ~PHY_SGMII_FLAG;
  1474. }
  1475. /* anything 10 and over uses the bmac */
  1476. link_10g = ((vars->line_speed == SPEED_10000) ||
  1477. (vars->line_speed == SPEED_12000) ||
  1478. (vars->line_speed == SPEED_12500) ||
  1479. (vars->line_speed == SPEED_13000) ||
  1480. (vars->line_speed == SPEED_15000) ||
  1481. (vars->line_speed == SPEED_16000));
  1482. if (link_10g)
  1483. vars->mac_type = MAC_TYPE_BMAC;
  1484. else
  1485. vars->mac_type = MAC_TYPE_EMAC;
  1486. } else { /* link down */
  1487. DP(NETIF_MSG_LINK, "phy link down\n");
  1488. vars->phy_link_up = 0;
  1489. vars->line_speed = 0;
  1490. vars->duplex = DUPLEX_FULL;
  1491. vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  1492. /* indicate no mac active */
  1493. vars->mac_type = MAC_TYPE_NONE;
  1494. }
  1495. DP(NETIF_MSG_LINK, "link_status 0x%x phy_link_up %x\n",
  1496. vars->link_status, vars->phy_link_up);
  1497. DP(NETIF_MSG_LINK, "line_speed %x duplex %x flow_ctrl 0x%x\n",
  1498. vars->line_speed, vars->duplex, vars->flow_ctrl);
  1499. }
  1500. static void bnx2x_set_master_ln(struct link_params *params,
  1501. struct bnx2x_phy *phy)
  1502. {
  1503. struct bnx2x *bp = params->bp;
  1504. u16 new_master_ln, ser_lane;
  1505. ser_lane = ((params->lane_config &
  1506. PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
  1507. PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
  1508. /* set the master_ln for AN */
  1509. CL22_RD_OVER_CL45(bp, phy,
  1510. MDIO_REG_BANK_XGXS_BLOCK2,
  1511. MDIO_XGXS_BLOCK2_TEST_MODE_LANE,
  1512. &new_master_ln);
  1513. CL22_WR_OVER_CL45(bp, phy,
  1514. MDIO_REG_BANK_XGXS_BLOCK2 ,
  1515. MDIO_XGXS_BLOCK2_TEST_MODE_LANE,
  1516. (new_master_ln | ser_lane));
  1517. }
  1518. static u8 bnx2x_reset_unicore(struct link_params *params,
  1519. struct bnx2x_phy *phy,
  1520. u8 set_serdes)
  1521. {
  1522. struct bnx2x *bp = params->bp;
  1523. u16 mii_control;
  1524. u16 i;
  1525. CL22_RD_OVER_CL45(bp, phy,
  1526. MDIO_REG_BANK_COMBO_IEEE0,
  1527. MDIO_COMBO_IEEE0_MII_CONTROL, &mii_control);
  1528. /* reset the unicore */
  1529. CL22_WR_OVER_CL45(bp, phy,
  1530. MDIO_REG_BANK_COMBO_IEEE0,
  1531. MDIO_COMBO_IEEE0_MII_CONTROL,
  1532. (mii_control |
  1533. MDIO_COMBO_IEEO_MII_CONTROL_RESET));
  1534. if (set_serdes)
  1535. bnx2x_set_serdes_access(bp, params->port);
  1536. /* wait for the reset to self clear */
  1537. for (i = 0; i < MDIO_ACCESS_TIMEOUT; i++) {
  1538. udelay(5);
  1539. /* the reset erased the previous bank value */
  1540. CL22_RD_OVER_CL45(bp, phy,
  1541. MDIO_REG_BANK_COMBO_IEEE0,
  1542. MDIO_COMBO_IEEE0_MII_CONTROL,
  1543. &mii_control);
  1544. if (!(mii_control & MDIO_COMBO_IEEO_MII_CONTROL_RESET)) {
  1545. udelay(5);
  1546. return 0;
  1547. }
  1548. }
  1549. netdev_err(bp->dev, "Warning: PHY was not initialized,"
  1550. " Port %d\n",
  1551. params->port);
  1552. DP(NETIF_MSG_LINK, "BUG! XGXS is still in reset!\n");
  1553. return -EINVAL;
  1554. }
  1555. static void bnx2x_set_swap_lanes(struct link_params *params,
  1556. struct bnx2x_phy *phy)
  1557. {
  1558. struct bnx2x *bp = params->bp;
  1559. /*
  1560. * Each two bits represents a lane number:
  1561. * No swap is 0123 => 0x1b no need to enable the swap
  1562. */
  1563. u16 ser_lane, rx_lane_swap, tx_lane_swap;
  1564. ser_lane = ((params->lane_config &
  1565. PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
  1566. PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
  1567. rx_lane_swap = ((params->lane_config &
  1568. PORT_HW_CFG_LANE_SWAP_CFG_RX_MASK) >>
  1569. PORT_HW_CFG_LANE_SWAP_CFG_RX_SHIFT);
  1570. tx_lane_swap = ((params->lane_config &
  1571. PORT_HW_CFG_LANE_SWAP_CFG_TX_MASK) >>
  1572. PORT_HW_CFG_LANE_SWAP_CFG_TX_SHIFT);
  1573. if (rx_lane_swap != 0x1b) {
  1574. CL22_WR_OVER_CL45(bp, phy,
  1575. MDIO_REG_BANK_XGXS_BLOCK2,
  1576. MDIO_XGXS_BLOCK2_RX_LN_SWAP,
  1577. (rx_lane_swap |
  1578. MDIO_XGXS_BLOCK2_RX_LN_SWAP_ENABLE |
  1579. MDIO_XGXS_BLOCK2_RX_LN_SWAP_FORCE_ENABLE));
  1580. } else {
  1581. CL22_WR_OVER_CL45(bp, phy,
  1582. MDIO_REG_BANK_XGXS_BLOCK2,
  1583. MDIO_XGXS_BLOCK2_RX_LN_SWAP, 0);
  1584. }
  1585. if (tx_lane_swap != 0x1b) {
  1586. CL22_WR_OVER_CL45(bp, phy,
  1587. MDIO_REG_BANK_XGXS_BLOCK2,
  1588. MDIO_XGXS_BLOCK2_TX_LN_SWAP,
  1589. (tx_lane_swap |
  1590. MDIO_XGXS_BLOCK2_TX_LN_SWAP_ENABLE));
  1591. } else {
  1592. CL22_WR_OVER_CL45(bp, phy,
  1593. MDIO_REG_BANK_XGXS_BLOCK2,
  1594. MDIO_XGXS_BLOCK2_TX_LN_SWAP, 0);
  1595. }
  1596. }
  1597. static void bnx2x_set_parallel_detection(struct bnx2x_phy *phy,
  1598. struct link_params *params)
  1599. {
  1600. struct bnx2x *bp = params->bp;
  1601. u16 control2;
  1602. CL22_RD_OVER_CL45(bp, phy,
  1603. MDIO_REG_BANK_SERDES_DIGITAL,
  1604. MDIO_SERDES_DIGITAL_A_1000X_CONTROL2,
  1605. &control2);
  1606. if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)
  1607. control2 |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL2_PRL_DT_EN;
  1608. else
  1609. control2 &= ~MDIO_SERDES_DIGITAL_A_1000X_CONTROL2_PRL_DT_EN;
  1610. DP(NETIF_MSG_LINK, "phy->speed_cap_mask = 0x%x, control2 = 0x%x\n",
  1611. phy->speed_cap_mask, control2);
  1612. CL22_WR_OVER_CL45(bp, phy,
  1613. MDIO_REG_BANK_SERDES_DIGITAL,
  1614. MDIO_SERDES_DIGITAL_A_1000X_CONTROL2,
  1615. control2);
  1616. if ((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) &&
  1617. (phy->speed_cap_mask &
  1618. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
  1619. DP(NETIF_MSG_LINK, "XGXS\n");
  1620. CL22_WR_OVER_CL45(bp, phy,
  1621. MDIO_REG_BANK_10G_PARALLEL_DETECT,
  1622. MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_LINK,
  1623. MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_LINK_CNT);
  1624. CL22_RD_OVER_CL45(bp, phy,
  1625. MDIO_REG_BANK_10G_PARALLEL_DETECT,
  1626. MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL,
  1627. &control2);
  1628. control2 |=
  1629. MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL_PARDET10G_EN;
  1630. CL22_WR_OVER_CL45(bp, phy,
  1631. MDIO_REG_BANK_10G_PARALLEL_DETECT,
  1632. MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL,
  1633. control2);
  1634. /* Disable parallel detection of HiG */
  1635. CL22_WR_OVER_CL45(bp, phy,
  1636. MDIO_REG_BANK_XGXS_BLOCK2,
  1637. MDIO_XGXS_BLOCK2_UNICORE_MODE_10G,
  1638. MDIO_XGXS_BLOCK2_UNICORE_MODE_10G_CX4_XGXS |
  1639. MDIO_XGXS_BLOCK2_UNICORE_MODE_10G_HIGIG_XGXS);
  1640. }
  1641. }
  1642. static void bnx2x_set_autoneg(struct bnx2x_phy *phy,
  1643. struct link_params *params,
  1644. struct link_vars *vars,
  1645. u8 enable_cl73)
  1646. {
  1647. struct bnx2x *bp = params->bp;
  1648. u16 reg_val;
  1649. /* CL37 Autoneg */
  1650. CL22_RD_OVER_CL45(bp, phy,
  1651. MDIO_REG_BANK_COMBO_IEEE0,
  1652. MDIO_COMBO_IEEE0_MII_CONTROL, &reg_val);
  1653. /* CL37 Autoneg Enabled */
  1654. if (vars->line_speed == SPEED_AUTO_NEG)
  1655. reg_val |= MDIO_COMBO_IEEO_MII_CONTROL_AN_EN;
  1656. else /* CL37 Autoneg Disabled */
  1657. reg_val &= ~(MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
  1658. MDIO_COMBO_IEEO_MII_CONTROL_RESTART_AN);
  1659. CL22_WR_OVER_CL45(bp, phy,
  1660. MDIO_REG_BANK_COMBO_IEEE0,
  1661. MDIO_COMBO_IEEE0_MII_CONTROL, reg_val);
  1662. /* Enable/Disable Autodetection */
  1663. CL22_RD_OVER_CL45(bp, phy,
  1664. MDIO_REG_BANK_SERDES_DIGITAL,
  1665. MDIO_SERDES_DIGITAL_A_1000X_CONTROL1, &reg_val);
  1666. reg_val &= ~(MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_SIGNAL_DETECT_EN |
  1667. MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_INVERT_SIGNAL_DETECT);
  1668. reg_val |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_FIBER_MODE;
  1669. if (vars->line_speed == SPEED_AUTO_NEG)
  1670. reg_val |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET;
  1671. else
  1672. reg_val &= ~MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET;
  1673. CL22_WR_OVER_CL45(bp, phy,
  1674. MDIO_REG_BANK_SERDES_DIGITAL,
  1675. MDIO_SERDES_DIGITAL_A_1000X_CONTROL1, reg_val);
  1676. /* Enable TetonII and BAM autoneg */
  1677. CL22_RD_OVER_CL45(bp, phy,
  1678. MDIO_REG_BANK_BAM_NEXT_PAGE,
  1679. MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL,
  1680. &reg_val);
  1681. if (vars->line_speed == SPEED_AUTO_NEG) {
  1682. /* Enable BAM aneg Mode and TetonII aneg Mode */
  1683. reg_val |= (MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_BAM_MODE |
  1684. MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_TETON_AN);
  1685. } else {
  1686. /* TetonII and BAM Autoneg Disabled */
  1687. reg_val &= ~(MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_BAM_MODE |
  1688. MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_TETON_AN);
  1689. }
  1690. CL22_WR_OVER_CL45(bp, phy,
  1691. MDIO_REG_BANK_BAM_NEXT_PAGE,
  1692. MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL,
  1693. reg_val);
  1694. if (enable_cl73) {
  1695. /* Enable Cl73 FSM status bits */
  1696. CL22_WR_OVER_CL45(bp, phy,
  1697. MDIO_REG_BANK_CL73_USERB0,
  1698. MDIO_CL73_USERB0_CL73_UCTRL,
  1699. 0xe);
  1700. /* Enable BAM Station Manager*/
  1701. CL22_WR_OVER_CL45(bp, phy,
  1702. MDIO_REG_BANK_CL73_USERB0,
  1703. MDIO_CL73_USERB0_CL73_BAM_CTRL1,
  1704. MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_EN |
  1705. MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_STATION_MNGR_EN |
  1706. MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_NP_AFTER_BP_EN);
  1707. /* Advertise CL73 link speeds */
  1708. CL22_RD_OVER_CL45(bp, phy,
  1709. MDIO_REG_BANK_CL73_IEEEB1,
  1710. MDIO_CL73_IEEEB1_AN_ADV2,
  1711. &reg_val);
  1712. if (phy->speed_cap_mask &
  1713. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1714. reg_val |= MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KX4;
  1715. if (phy->speed_cap_mask &
  1716. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)
  1717. reg_val |= MDIO_CL73_IEEEB1_AN_ADV2_ADVR_1000M_KX;
  1718. CL22_WR_OVER_CL45(bp, phy,
  1719. MDIO_REG_BANK_CL73_IEEEB1,
  1720. MDIO_CL73_IEEEB1_AN_ADV2,
  1721. reg_val);
  1722. /* CL73 Autoneg Enabled */
  1723. reg_val = MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN;
  1724. } else /* CL73 Autoneg Disabled */
  1725. reg_val = 0;
  1726. CL22_WR_OVER_CL45(bp, phy,
  1727. MDIO_REG_BANK_CL73_IEEEB0,
  1728. MDIO_CL73_IEEEB0_CL73_AN_CONTROL, reg_val);
  1729. }
  1730. /* program SerDes, forced speed */
  1731. static void bnx2x_program_serdes(struct bnx2x_phy *phy,
  1732. struct link_params *params,
  1733. struct link_vars *vars)
  1734. {
  1735. struct bnx2x *bp = params->bp;
  1736. u16 reg_val;
  1737. /* program duplex, disable autoneg and sgmii*/
  1738. CL22_RD_OVER_CL45(bp, phy,
  1739. MDIO_REG_BANK_COMBO_IEEE0,
  1740. MDIO_COMBO_IEEE0_MII_CONTROL, &reg_val);
  1741. reg_val &= ~(MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX |
  1742. MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
  1743. MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_MASK);
  1744. if (phy->req_duplex == DUPLEX_FULL)
  1745. reg_val |= MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX;
  1746. CL22_WR_OVER_CL45(bp, phy,
  1747. MDIO_REG_BANK_COMBO_IEEE0,
  1748. MDIO_COMBO_IEEE0_MII_CONTROL, reg_val);
  1749. /*
  1750. * program speed
  1751. * - needed only if the speed is greater than 1G (2.5G or 10G)
  1752. */
  1753. CL22_RD_OVER_CL45(bp, phy,
  1754. MDIO_REG_BANK_SERDES_DIGITAL,
  1755. MDIO_SERDES_DIGITAL_MISC1, &reg_val);
  1756. /* clearing the speed value before setting the right speed */
  1757. DP(NETIF_MSG_LINK, "MDIO_REG_BANK_SERDES_DIGITAL = 0x%x\n", reg_val);
  1758. reg_val &= ~(MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_MASK |
  1759. MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_SEL);
  1760. if (!((vars->line_speed == SPEED_1000) ||
  1761. (vars->line_speed == SPEED_100) ||
  1762. (vars->line_speed == SPEED_10))) {
  1763. reg_val |= (MDIO_SERDES_DIGITAL_MISC1_REFCLK_SEL_156_25M |
  1764. MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_SEL);
  1765. if (vars->line_speed == SPEED_10000)
  1766. reg_val |=
  1767. MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_10G_CX4;
  1768. if (vars->line_speed == SPEED_13000)
  1769. reg_val |=
  1770. MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_13G;
  1771. }
  1772. CL22_WR_OVER_CL45(bp, phy,
  1773. MDIO_REG_BANK_SERDES_DIGITAL,
  1774. MDIO_SERDES_DIGITAL_MISC1, reg_val);
  1775. }
  1776. static void bnx2x_set_brcm_cl37_advertisment(struct bnx2x_phy *phy,
  1777. struct link_params *params)
  1778. {
  1779. struct bnx2x *bp = params->bp;
  1780. u16 val = 0;
  1781. /* configure the 48 bits for BAM AN */
  1782. /* set extended capabilities */
  1783. if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G)
  1784. val |= MDIO_OVER_1G_UP1_2_5G;
  1785. if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1786. val |= MDIO_OVER_1G_UP1_10G;
  1787. CL22_WR_OVER_CL45(bp, phy,
  1788. MDIO_REG_BANK_OVER_1G,
  1789. MDIO_OVER_1G_UP1, val);
  1790. CL22_WR_OVER_CL45(bp, phy,
  1791. MDIO_REG_BANK_OVER_1G,
  1792. MDIO_OVER_1G_UP3, 0x400);
  1793. }
  1794. static void bnx2x_calc_ieee_aneg_adv(struct bnx2x_phy *phy,
  1795. struct link_params *params, u16 *ieee_fc)
  1796. {
  1797. struct bnx2x *bp = params->bp;
  1798. *ieee_fc = MDIO_COMBO_IEEE0_AUTO_NEG_ADV_FULL_DUPLEX;
  1799. /*
  1800. * Resolve pause mode and advertisement.
  1801. * Please refer to Table 28B-3 of the 802.3ab-1999 spec
  1802. */
  1803. switch (phy->req_flow_ctrl) {
  1804. case BNX2X_FLOW_CTRL_AUTO:
  1805. if (params->req_fc_auto_adv == BNX2X_FLOW_CTRL_BOTH)
  1806. *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
  1807. else
  1808. *ieee_fc |=
  1809. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
  1810. break;
  1811. case BNX2X_FLOW_CTRL_TX:
  1812. *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
  1813. break;
  1814. case BNX2X_FLOW_CTRL_RX:
  1815. case BNX2X_FLOW_CTRL_BOTH:
  1816. *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
  1817. break;
  1818. case BNX2X_FLOW_CTRL_NONE:
  1819. default:
  1820. *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE;
  1821. break;
  1822. }
  1823. DP(NETIF_MSG_LINK, "ieee_fc = 0x%x\n", *ieee_fc);
  1824. }
  1825. static void bnx2x_set_ieee_aneg_advertisment(struct bnx2x_phy *phy,
  1826. struct link_params *params,
  1827. u16 ieee_fc)
  1828. {
  1829. struct bnx2x *bp = params->bp;
  1830. u16 val;
  1831. /* for AN, we are always publishing full duplex */
  1832. CL22_WR_OVER_CL45(bp, phy,
  1833. MDIO_REG_BANK_COMBO_IEEE0,
  1834. MDIO_COMBO_IEEE0_AUTO_NEG_ADV, ieee_fc);
  1835. CL22_RD_OVER_CL45(bp, phy,
  1836. MDIO_REG_BANK_CL73_IEEEB1,
  1837. MDIO_CL73_IEEEB1_AN_ADV1, &val);
  1838. val &= ~MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_BOTH;
  1839. val |= ((ieee_fc<<3) & MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_MASK);
  1840. CL22_WR_OVER_CL45(bp, phy,
  1841. MDIO_REG_BANK_CL73_IEEEB1,
  1842. MDIO_CL73_IEEEB1_AN_ADV1, val);
  1843. }
  1844. static void bnx2x_restart_autoneg(struct bnx2x_phy *phy,
  1845. struct link_params *params,
  1846. u8 enable_cl73)
  1847. {
  1848. struct bnx2x *bp = params->bp;
  1849. u16 mii_control;
  1850. DP(NETIF_MSG_LINK, "bnx2x_restart_autoneg\n");
  1851. /* Enable and restart BAM/CL37 aneg */
  1852. if (enable_cl73) {
  1853. CL22_RD_OVER_CL45(bp, phy,
  1854. MDIO_REG_BANK_CL73_IEEEB0,
  1855. MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
  1856. &mii_control);
  1857. CL22_WR_OVER_CL45(bp, phy,
  1858. MDIO_REG_BANK_CL73_IEEEB0,
  1859. MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
  1860. (mii_control |
  1861. MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN |
  1862. MDIO_CL73_IEEEB0_CL73_AN_CONTROL_RESTART_AN));
  1863. } else {
  1864. CL22_RD_OVER_CL45(bp, phy,
  1865. MDIO_REG_BANK_COMBO_IEEE0,
  1866. MDIO_COMBO_IEEE0_MII_CONTROL,
  1867. &mii_control);
  1868. DP(NETIF_MSG_LINK,
  1869. "bnx2x_restart_autoneg mii_control before = 0x%x\n",
  1870. mii_control);
  1871. CL22_WR_OVER_CL45(bp, phy,
  1872. MDIO_REG_BANK_COMBO_IEEE0,
  1873. MDIO_COMBO_IEEE0_MII_CONTROL,
  1874. (mii_control |
  1875. MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
  1876. MDIO_COMBO_IEEO_MII_CONTROL_RESTART_AN));
  1877. }
  1878. }
  1879. static void bnx2x_initialize_sgmii_process(struct bnx2x_phy *phy,
  1880. struct link_params *params,
  1881. struct link_vars *vars)
  1882. {
  1883. struct bnx2x *bp = params->bp;
  1884. u16 control1;
  1885. /* in SGMII mode, the unicore is always slave */
  1886. CL22_RD_OVER_CL45(bp, phy,
  1887. MDIO_REG_BANK_SERDES_DIGITAL,
  1888. MDIO_SERDES_DIGITAL_A_1000X_CONTROL1,
  1889. &control1);
  1890. control1 |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_INVERT_SIGNAL_DETECT;
  1891. /* set sgmii mode (and not fiber) */
  1892. control1 &= ~(MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_FIBER_MODE |
  1893. MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET |
  1894. MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_MSTR_MODE);
  1895. CL22_WR_OVER_CL45(bp, phy,
  1896. MDIO_REG_BANK_SERDES_DIGITAL,
  1897. MDIO_SERDES_DIGITAL_A_1000X_CONTROL1,
  1898. control1);
  1899. /* if forced speed */
  1900. if (!(vars->line_speed == SPEED_AUTO_NEG)) {
  1901. /* set speed, disable autoneg */
  1902. u16 mii_control;
  1903. CL22_RD_OVER_CL45(bp, phy,
  1904. MDIO_REG_BANK_COMBO_IEEE0,
  1905. MDIO_COMBO_IEEE0_MII_CONTROL,
  1906. &mii_control);
  1907. mii_control &= ~(MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
  1908. MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_MASK|
  1909. MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX);
  1910. switch (vars->line_speed) {
  1911. case SPEED_100:
  1912. mii_control |=
  1913. MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_100;
  1914. break;
  1915. case SPEED_1000:
  1916. mii_control |=
  1917. MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_1000;
  1918. break;
  1919. case SPEED_10:
  1920. /* there is nothing to set for 10M */
  1921. break;
  1922. default:
  1923. /* invalid speed for SGMII */
  1924. DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
  1925. vars->line_speed);
  1926. break;
  1927. }
  1928. /* setting the full duplex */
  1929. if (phy->req_duplex == DUPLEX_FULL)
  1930. mii_control |=
  1931. MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX;
  1932. CL22_WR_OVER_CL45(bp, phy,
  1933. MDIO_REG_BANK_COMBO_IEEE0,
  1934. MDIO_COMBO_IEEE0_MII_CONTROL,
  1935. mii_control);
  1936. } else { /* AN mode */
  1937. /* enable and restart AN */
  1938. bnx2x_restart_autoneg(phy, params, 0);
  1939. }
  1940. }
  1941. /*
  1942. * link management
  1943. */
  1944. static void bnx2x_pause_resolve(struct link_vars *vars, u32 pause_result)
  1945. { /* LD LP */
  1946. switch (pause_result) { /* ASYM P ASYM P */
  1947. case 0xb: /* 1 0 1 1 */
  1948. vars->flow_ctrl = BNX2X_FLOW_CTRL_TX;
  1949. break;
  1950. case 0xe: /* 1 1 1 0 */
  1951. vars->flow_ctrl = BNX2X_FLOW_CTRL_RX;
  1952. break;
  1953. case 0x5: /* 0 1 0 1 */
  1954. case 0x7: /* 0 1 1 1 */
  1955. case 0xd: /* 1 1 0 1 */
  1956. case 0xf: /* 1 1 1 1 */
  1957. vars->flow_ctrl = BNX2X_FLOW_CTRL_BOTH;
  1958. break;
  1959. default:
  1960. break;
  1961. }
  1962. if (pause_result & (1<<0))
  1963. vars->link_status |= LINK_STATUS_LINK_PARTNER_SYMMETRIC_PAUSE;
  1964. if (pause_result & (1<<1))
  1965. vars->link_status |= LINK_STATUS_LINK_PARTNER_ASYMMETRIC_PAUSE;
  1966. }
  1967. static u8 bnx2x_direct_parallel_detect_used(struct bnx2x_phy *phy,
  1968. struct link_params *params)
  1969. {
  1970. struct bnx2x *bp = params->bp;
  1971. u16 pd_10g, status2_1000x;
  1972. if (phy->req_line_speed != SPEED_AUTO_NEG)
  1973. return 0;
  1974. CL22_RD_OVER_CL45(bp, phy,
  1975. MDIO_REG_BANK_SERDES_DIGITAL,
  1976. MDIO_SERDES_DIGITAL_A_1000X_STATUS2,
  1977. &status2_1000x);
  1978. CL22_RD_OVER_CL45(bp, phy,
  1979. MDIO_REG_BANK_SERDES_DIGITAL,
  1980. MDIO_SERDES_DIGITAL_A_1000X_STATUS2,
  1981. &status2_1000x);
  1982. if (status2_1000x & MDIO_SERDES_DIGITAL_A_1000X_STATUS2_AN_DISABLED) {
  1983. DP(NETIF_MSG_LINK, "1G parallel detect link on port %d\n",
  1984. params->port);
  1985. return 1;
  1986. }
  1987. CL22_RD_OVER_CL45(bp, phy,
  1988. MDIO_REG_BANK_10G_PARALLEL_DETECT,
  1989. MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_STATUS,
  1990. &pd_10g);
  1991. if (pd_10g & MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_STATUS_PD_LINK) {
  1992. DP(NETIF_MSG_LINK, "10G parallel detect link on port %d\n",
  1993. params->port);
  1994. return 1;
  1995. }
  1996. return 0;
  1997. }
  1998. static void bnx2x_flow_ctrl_resolve(struct bnx2x_phy *phy,
  1999. struct link_params *params,
  2000. struct link_vars *vars,
  2001. u32 gp_status)
  2002. {
  2003. struct bnx2x *bp = params->bp;
  2004. u16 ld_pause; /* local driver */
  2005. u16 lp_pause; /* link partner */
  2006. u16 pause_result;
  2007. vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  2008. /* resolve from gp_status in case of AN complete and not sgmii */
  2009. if (phy->req_flow_ctrl != BNX2X_FLOW_CTRL_AUTO)
  2010. vars->flow_ctrl = phy->req_flow_ctrl;
  2011. else if (phy->req_line_speed != SPEED_AUTO_NEG)
  2012. vars->flow_ctrl = params->req_fc_auto_adv;
  2013. else if ((gp_status & MDIO_AN_CL73_OR_37_COMPLETE) &&
  2014. (!(vars->phy_flags & PHY_SGMII_FLAG))) {
  2015. if (bnx2x_direct_parallel_detect_used(phy, params)) {
  2016. vars->flow_ctrl = params->req_fc_auto_adv;
  2017. return;
  2018. }
  2019. if ((gp_status &
  2020. (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE |
  2021. MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_MR_LP_NP_AN_ABLE)) ==
  2022. (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE |
  2023. MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_MR_LP_NP_AN_ABLE)) {
  2024. CL22_RD_OVER_CL45(bp, phy,
  2025. MDIO_REG_BANK_CL73_IEEEB1,
  2026. MDIO_CL73_IEEEB1_AN_ADV1,
  2027. &ld_pause);
  2028. CL22_RD_OVER_CL45(bp, phy,
  2029. MDIO_REG_BANK_CL73_IEEEB1,
  2030. MDIO_CL73_IEEEB1_AN_LP_ADV1,
  2031. &lp_pause);
  2032. pause_result = (ld_pause &
  2033. MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_MASK)
  2034. >> 8;
  2035. pause_result |= (lp_pause &
  2036. MDIO_CL73_IEEEB1_AN_LP_ADV1_PAUSE_MASK)
  2037. >> 10;
  2038. DP(NETIF_MSG_LINK, "pause_result CL73 0x%x\n",
  2039. pause_result);
  2040. } else {
  2041. CL22_RD_OVER_CL45(bp, phy,
  2042. MDIO_REG_BANK_COMBO_IEEE0,
  2043. MDIO_COMBO_IEEE0_AUTO_NEG_ADV,
  2044. &ld_pause);
  2045. CL22_RD_OVER_CL45(bp, phy,
  2046. MDIO_REG_BANK_COMBO_IEEE0,
  2047. MDIO_COMBO_IEEE0_AUTO_NEG_LINK_PARTNER_ABILITY1,
  2048. &lp_pause);
  2049. pause_result = (ld_pause &
  2050. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK)>>5;
  2051. pause_result |= (lp_pause &
  2052. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK)>>7;
  2053. DP(NETIF_MSG_LINK, "pause_result CL37 0x%x\n",
  2054. pause_result);
  2055. }
  2056. bnx2x_pause_resolve(vars, pause_result);
  2057. }
  2058. DP(NETIF_MSG_LINK, "flow_ctrl 0x%x\n", vars->flow_ctrl);
  2059. }
  2060. static void bnx2x_check_fallback_to_cl37(struct bnx2x_phy *phy,
  2061. struct link_params *params)
  2062. {
  2063. struct bnx2x *bp = params->bp;
  2064. u16 rx_status, ustat_val, cl37_fsm_recieved;
  2065. DP(NETIF_MSG_LINK, "bnx2x_check_fallback_to_cl37\n");
  2066. /* Step 1: Make sure signal is detected */
  2067. CL22_RD_OVER_CL45(bp, phy,
  2068. MDIO_REG_BANK_RX0,
  2069. MDIO_RX0_RX_STATUS,
  2070. &rx_status);
  2071. if ((rx_status & MDIO_RX0_RX_STATUS_SIGDET) !=
  2072. (MDIO_RX0_RX_STATUS_SIGDET)) {
  2073. DP(NETIF_MSG_LINK, "Signal is not detected. Restoring CL73."
  2074. "rx_status(0x80b0) = 0x%x\n", rx_status);
  2075. CL22_WR_OVER_CL45(bp, phy,
  2076. MDIO_REG_BANK_CL73_IEEEB0,
  2077. MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
  2078. MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN);
  2079. return;
  2080. }
  2081. /* Step 2: Check CL73 state machine */
  2082. CL22_RD_OVER_CL45(bp, phy,
  2083. MDIO_REG_BANK_CL73_USERB0,
  2084. MDIO_CL73_USERB0_CL73_USTAT1,
  2085. &ustat_val);
  2086. if ((ustat_val &
  2087. (MDIO_CL73_USERB0_CL73_USTAT1_LINK_STATUS_CHECK |
  2088. MDIO_CL73_USERB0_CL73_USTAT1_AN_GOOD_CHECK_BAM37)) !=
  2089. (MDIO_CL73_USERB0_CL73_USTAT1_LINK_STATUS_CHECK |
  2090. MDIO_CL73_USERB0_CL73_USTAT1_AN_GOOD_CHECK_BAM37)) {
  2091. DP(NETIF_MSG_LINK, "CL73 state-machine is not stable. "
  2092. "ustat_val(0x8371) = 0x%x\n", ustat_val);
  2093. return;
  2094. }
  2095. /*
  2096. * Step 3: Check CL37 Message Pages received to indicate LP
  2097. * supports only CL37
  2098. */
  2099. CL22_RD_OVER_CL45(bp, phy,
  2100. MDIO_REG_BANK_REMOTE_PHY,
  2101. MDIO_REMOTE_PHY_MISC_RX_STATUS,
  2102. &cl37_fsm_recieved);
  2103. if ((cl37_fsm_recieved &
  2104. (MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_OVER1G_MSG |
  2105. MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_BRCM_OUI_MSG)) !=
  2106. (MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_OVER1G_MSG |
  2107. MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_BRCM_OUI_MSG)) {
  2108. DP(NETIF_MSG_LINK, "No CL37 FSM were received. "
  2109. "misc_rx_status(0x8330) = 0x%x\n",
  2110. cl37_fsm_recieved);
  2111. return;
  2112. }
  2113. /*
  2114. * The combined cl37/cl73 fsm state information indicating that
  2115. * we are connected to a device which does not support cl73, but
  2116. * does support cl37 BAM. In this case we disable cl73 and
  2117. * restart cl37 auto-neg
  2118. */
  2119. /* Disable CL73 */
  2120. CL22_WR_OVER_CL45(bp, phy,
  2121. MDIO_REG_BANK_CL73_IEEEB0,
  2122. MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
  2123. 0);
  2124. /* Restart CL37 autoneg */
  2125. bnx2x_restart_autoneg(phy, params, 0);
  2126. DP(NETIF_MSG_LINK, "Disabling CL73, and restarting CL37 autoneg\n");
  2127. }
  2128. static void bnx2x_xgxs_an_resolve(struct bnx2x_phy *phy,
  2129. struct link_params *params,
  2130. struct link_vars *vars,
  2131. u32 gp_status)
  2132. {
  2133. if (gp_status & MDIO_AN_CL73_OR_37_COMPLETE)
  2134. vars->link_status |=
  2135. LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
  2136. if (bnx2x_direct_parallel_detect_used(phy, params))
  2137. vars->link_status |=
  2138. LINK_STATUS_PARALLEL_DETECTION_USED;
  2139. }
  2140. static u8 bnx2x_link_settings_status(struct bnx2x_phy *phy,
  2141. struct link_params *params,
  2142. struct link_vars *vars)
  2143. {
  2144. struct bnx2x *bp = params->bp;
  2145. u16 new_line_speed, gp_status;
  2146. u8 rc = 0;
  2147. /* Read gp_status */
  2148. CL22_RD_OVER_CL45(bp, phy,
  2149. MDIO_REG_BANK_GP_STATUS,
  2150. MDIO_GP_STATUS_TOP_AN_STATUS1,
  2151. &gp_status);
  2152. if (phy->req_line_speed == SPEED_AUTO_NEG)
  2153. vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_ENABLED;
  2154. if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS) {
  2155. DP(NETIF_MSG_LINK, "phy link up gp_status=0x%x\n",
  2156. gp_status);
  2157. vars->phy_link_up = 1;
  2158. vars->link_status |= LINK_STATUS_LINK_UP;
  2159. if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_DUPLEX_STATUS)
  2160. vars->duplex = DUPLEX_FULL;
  2161. else
  2162. vars->duplex = DUPLEX_HALF;
  2163. if (SINGLE_MEDIA_DIRECT(params)) {
  2164. bnx2x_flow_ctrl_resolve(phy, params, vars, gp_status);
  2165. if (phy->req_line_speed == SPEED_AUTO_NEG)
  2166. bnx2x_xgxs_an_resolve(phy, params, vars,
  2167. gp_status);
  2168. }
  2169. switch (gp_status & GP_STATUS_SPEED_MASK) {
  2170. case GP_STATUS_10M:
  2171. new_line_speed = SPEED_10;
  2172. if (vars->duplex == DUPLEX_FULL)
  2173. vars->link_status |= LINK_10TFD;
  2174. else
  2175. vars->link_status |= LINK_10THD;
  2176. break;
  2177. case GP_STATUS_100M:
  2178. new_line_speed = SPEED_100;
  2179. if (vars->duplex == DUPLEX_FULL)
  2180. vars->link_status |= LINK_100TXFD;
  2181. else
  2182. vars->link_status |= LINK_100TXHD;
  2183. break;
  2184. case GP_STATUS_1G:
  2185. case GP_STATUS_1G_KX:
  2186. new_line_speed = SPEED_1000;
  2187. if (vars->duplex == DUPLEX_FULL)
  2188. vars->link_status |= LINK_1000TFD;
  2189. else
  2190. vars->link_status |= LINK_1000THD;
  2191. break;
  2192. case GP_STATUS_2_5G:
  2193. new_line_speed = SPEED_2500;
  2194. if (vars->duplex == DUPLEX_FULL)
  2195. vars->link_status |= LINK_2500TFD;
  2196. else
  2197. vars->link_status |= LINK_2500THD;
  2198. break;
  2199. case GP_STATUS_5G:
  2200. case GP_STATUS_6G:
  2201. DP(NETIF_MSG_LINK,
  2202. "link speed unsupported gp_status 0x%x\n",
  2203. gp_status);
  2204. return -EINVAL;
  2205. case GP_STATUS_10G_KX4:
  2206. case GP_STATUS_10G_HIG:
  2207. case GP_STATUS_10G_CX4:
  2208. new_line_speed = SPEED_10000;
  2209. vars->link_status |= LINK_10GTFD;
  2210. break;
  2211. case GP_STATUS_12G_HIG:
  2212. new_line_speed = SPEED_12000;
  2213. vars->link_status |= LINK_12GTFD;
  2214. break;
  2215. case GP_STATUS_12_5G:
  2216. new_line_speed = SPEED_12500;
  2217. vars->link_status |= LINK_12_5GTFD;
  2218. break;
  2219. case GP_STATUS_13G:
  2220. new_line_speed = SPEED_13000;
  2221. vars->link_status |= LINK_13GTFD;
  2222. break;
  2223. case GP_STATUS_15G:
  2224. new_line_speed = SPEED_15000;
  2225. vars->link_status |= LINK_15GTFD;
  2226. break;
  2227. case GP_STATUS_16G:
  2228. new_line_speed = SPEED_16000;
  2229. vars->link_status |= LINK_16GTFD;
  2230. break;
  2231. default:
  2232. DP(NETIF_MSG_LINK,
  2233. "link speed unsupported gp_status 0x%x\n",
  2234. gp_status);
  2235. return -EINVAL;
  2236. }
  2237. vars->line_speed = new_line_speed;
  2238. } else { /* link_down */
  2239. DP(NETIF_MSG_LINK, "phy link down\n");
  2240. vars->phy_link_up = 0;
  2241. vars->duplex = DUPLEX_FULL;
  2242. vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  2243. vars->mac_type = MAC_TYPE_NONE;
  2244. if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
  2245. SINGLE_MEDIA_DIRECT(params)) {
  2246. /* Check signal is detected */
  2247. bnx2x_check_fallback_to_cl37(phy, params);
  2248. }
  2249. }
  2250. DP(NETIF_MSG_LINK, "gp_status 0x%x phy_link_up %x line_speed %x\n",
  2251. gp_status, vars->phy_link_up, vars->line_speed);
  2252. DP(NETIF_MSG_LINK, "duplex %x flow_ctrl 0x%x link_status 0x%x\n",
  2253. vars->duplex, vars->flow_ctrl, vars->link_status);
  2254. return rc;
  2255. }
  2256. static void bnx2x_set_gmii_tx_driver(struct link_params *params)
  2257. {
  2258. struct bnx2x *bp = params->bp;
  2259. struct bnx2x_phy *phy = &params->phy[INT_PHY];
  2260. u16 lp_up2;
  2261. u16 tx_driver;
  2262. u16 bank;
  2263. /* read precomp */
  2264. CL22_RD_OVER_CL45(bp, phy,
  2265. MDIO_REG_BANK_OVER_1G,
  2266. MDIO_OVER_1G_LP_UP2, &lp_up2);
  2267. /* bits [10:7] at lp_up2, positioned at [15:12] */
  2268. lp_up2 = (((lp_up2 & MDIO_OVER_1G_LP_UP2_PREEMPHASIS_MASK) >>
  2269. MDIO_OVER_1G_LP_UP2_PREEMPHASIS_SHIFT) <<
  2270. MDIO_TX0_TX_DRIVER_PREEMPHASIS_SHIFT);
  2271. if (lp_up2 == 0)
  2272. return;
  2273. for (bank = MDIO_REG_BANK_TX0; bank <= MDIO_REG_BANK_TX3;
  2274. bank += (MDIO_REG_BANK_TX1 - MDIO_REG_BANK_TX0)) {
  2275. CL22_RD_OVER_CL45(bp, phy,
  2276. bank,
  2277. MDIO_TX0_TX_DRIVER, &tx_driver);
  2278. /* replace tx_driver bits [15:12] */
  2279. if (lp_up2 !=
  2280. (tx_driver & MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK)) {
  2281. tx_driver &= ~MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK;
  2282. tx_driver |= lp_up2;
  2283. CL22_WR_OVER_CL45(bp, phy,
  2284. bank,
  2285. MDIO_TX0_TX_DRIVER, tx_driver);
  2286. }
  2287. }
  2288. }
  2289. static u8 bnx2x_emac_program(struct link_params *params,
  2290. struct link_vars *vars)
  2291. {
  2292. struct bnx2x *bp = params->bp;
  2293. u8 port = params->port;
  2294. u16 mode = 0;
  2295. DP(NETIF_MSG_LINK, "setting link speed & duplex\n");
  2296. bnx2x_bits_dis(bp, GRCBASE_EMAC0 + port*0x400 +
  2297. EMAC_REG_EMAC_MODE,
  2298. (EMAC_MODE_25G_MODE |
  2299. EMAC_MODE_PORT_MII_10M |
  2300. EMAC_MODE_HALF_DUPLEX));
  2301. switch (vars->line_speed) {
  2302. case SPEED_10:
  2303. mode |= EMAC_MODE_PORT_MII_10M;
  2304. break;
  2305. case SPEED_100:
  2306. mode |= EMAC_MODE_PORT_MII;
  2307. break;
  2308. case SPEED_1000:
  2309. mode |= EMAC_MODE_PORT_GMII;
  2310. break;
  2311. case SPEED_2500:
  2312. mode |= (EMAC_MODE_25G_MODE | EMAC_MODE_PORT_GMII);
  2313. break;
  2314. default:
  2315. /* 10G not valid for EMAC */
  2316. DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
  2317. vars->line_speed);
  2318. return -EINVAL;
  2319. }
  2320. if (vars->duplex == DUPLEX_HALF)
  2321. mode |= EMAC_MODE_HALF_DUPLEX;
  2322. bnx2x_bits_en(bp,
  2323. GRCBASE_EMAC0 + port*0x400 + EMAC_REG_EMAC_MODE,
  2324. mode);
  2325. bnx2x_set_led(params, vars, LED_MODE_OPER, vars->line_speed);
  2326. return 0;
  2327. }
  2328. static void bnx2x_set_preemphasis(struct bnx2x_phy *phy,
  2329. struct link_params *params)
  2330. {
  2331. u16 bank, i = 0;
  2332. struct bnx2x *bp = params->bp;
  2333. for (bank = MDIO_REG_BANK_RX0, i = 0; bank <= MDIO_REG_BANK_RX3;
  2334. bank += (MDIO_REG_BANK_RX1-MDIO_REG_BANK_RX0), i++) {
  2335. CL22_WR_OVER_CL45(bp, phy,
  2336. bank,
  2337. MDIO_RX0_RX_EQ_BOOST,
  2338. phy->rx_preemphasis[i]);
  2339. }
  2340. for (bank = MDIO_REG_BANK_TX0, i = 0; bank <= MDIO_REG_BANK_TX3;
  2341. bank += (MDIO_REG_BANK_TX1 - MDIO_REG_BANK_TX0), i++) {
  2342. CL22_WR_OVER_CL45(bp, phy,
  2343. bank,
  2344. MDIO_TX0_TX_DRIVER,
  2345. phy->tx_preemphasis[i]);
  2346. }
  2347. }
  2348. static void bnx2x_init_internal_phy(struct bnx2x_phy *phy,
  2349. struct link_params *params,
  2350. struct link_vars *vars)
  2351. {
  2352. struct bnx2x *bp = params->bp;
  2353. u8 enable_cl73 = (SINGLE_MEDIA_DIRECT(params) ||
  2354. (params->loopback_mode == LOOPBACK_XGXS));
  2355. if (!(vars->phy_flags & PHY_SGMII_FLAG)) {
  2356. if (SINGLE_MEDIA_DIRECT(params) &&
  2357. (params->feature_config_flags &
  2358. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED))
  2359. bnx2x_set_preemphasis(phy, params);
  2360. /* forced speed requested? */
  2361. if (vars->line_speed != SPEED_AUTO_NEG ||
  2362. (SINGLE_MEDIA_DIRECT(params) &&
  2363. params->loopback_mode == LOOPBACK_EXT)) {
  2364. DP(NETIF_MSG_LINK, "not SGMII, no AN\n");
  2365. /* disable autoneg */
  2366. bnx2x_set_autoneg(phy, params, vars, 0);
  2367. /* program speed and duplex */
  2368. bnx2x_program_serdes(phy, params, vars);
  2369. } else { /* AN_mode */
  2370. DP(NETIF_MSG_LINK, "not SGMII, AN\n");
  2371. /* AN enabled */
  2372. bnx2x_set_brcm_cl37_advertisment(phy, params);
  2373. /* program duplex & pause advertisement (for aneg) */
  2374. bnx2x_set_ieee_aneg_advertisment(phy, params,
  2375. vars->ieee_fc);
  2376. /* enable autoneg */
  2377. bnx2x_set_autoneg(phy, params, vars, enable_cl73);
  2378. /* enable and restart AN */
  2379. bnx2x_restart_autoneg(phy, params, enable_cl73);
  2380. }
  2381. } else { /* SGMII mode */
  2382. DP(NETIF_MSG_LINK, "SGMII\n");
  2383. bnx2x_initialize_sgmii_process(phy, params, vars);
  2384. }
  2385. }
  2386. static u8 bnx2x_init_serdes(struct bnx2x_phy *phy,
  2387. struct link_params *params,
  2388. struct link_vars *vars)
  2389. {
  2390. u8 rc;
  2391. vars->phy_flags |= PHY_SGMII_FLAG;
  2392. bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
  2393. bnx2x_set_aer_mmd_serdes(params->bp, phy);
  2394. rc = bnx2x_reset_unicore(params, phy, 1);
  2395. /* reset the SerDes and wait for reset bit return low */
  2396. if (rc != 0)
  2397. return rc;
  2398. bnx2x_set_aer_mmd_serdes(params->bp, phy);
  2399. return rc;
  2400. }
  2401. static u8 bnx2x_init_xgxs(struct bnx2x_phy *phy,
  2402. struct link_params *params,
  2403. struct link_vars *vars)
  2404. {
  2405. u8 rc;
  2406. vars->phy_flags = PHY_XGXS_FLAG;
  2407. if ((phy->req_line_speed &&
  2408. ((phy->req_line_speed == SPEED_100) ||
  2409. (phy->req_line_speed == SPEED_10))) ||
  2410. (!phy->req_line_speed &&
  2411. (phy->speed_cap_mask >=
  2412. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL) &&
  2413. (phy->speed_cap_mask <
  2414. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)
  2415. ))
  2416. vars->phy_flags |= PHY_SGMII_FLAG;
  2417. else
  2418. vars->phy_flags &= ~PHY_SGMII_FLAG;
  2419. bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
  2420. bnx2x_set_aer_mmd_xgxs(params, phy);
  2421. bnx2x_set_master_ln(params, phy);
  2422. rc = bnx2x_reset_unicore(params, phy, 0);
  2423. /* reset the SerDes and wait for reset bit return low */
  2424. if (rc != 0)
  2425. return rc;
  2426. bnx2x_set_aer_mmd_xgxs(params, phy);
  2427. /* setting the masterLn_def again after the reset */
  2428. bnx2x_set_master_ln(params, phy);
  2429. bnx2x_set_swap_lanes(params, phy);
  2430. return rc;
  2431. }
  2432. static u16 bnx2x_wait_reset_complete(struct bnx2x *bp,
  2433. struct bnx2x_phy *phy,
  2434. struct link_params *params)
  2435. {
  2436. u16 cnt, ctrl;
  2437. /* Wait for soft reset to get cleared up to 1 sec */
  2438. for (cnt = 0; cnt < 1000; cnt++) {
  2439. bnx2x_cl45_read(bp, phy,
  2440. MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, &ctrl);
  2441. if (!(ctrl & (1<<15)))
  2442. break;
  2443. msleep(1);
  2444. }
  2445. if (cnt == 1000)
  2446. netdev_err(bp->dev, "Warning: PHY was not initialized,"
  2447. " Port %d\n",
  2448. params->port);
  2449. DP(NETIF_MSG_LINK, "control reg 0x%x (after %d ms)\n", ctrl, cnt);
  2450. return cnt;
  2451. }
  2452. static void bnx2x_link_int_enable(struct link_params *params)
  2453. {
  2454. u8 port = params->port;
  2455. u32 mask;
  2456. struct bnx2x *bp = params->bp;
  2457. /* Setting the status to report on link up for either XGXS or SerDes */
  2458. if (params->switch_cfg == SWITCH_CFG_10G) {
  2459. mask = (NIG_MASK_XGXS0_LINK10G |
  2460. NIG_MASK_XGXS0_LINK_STATUS);
  2461. DP(NETIF_MSG_LINK, "enabled XGXS interrupt\n");
  2462. if (!(SINGLE_MEDIA_DIRECT(params)) &&
  2463. params->phy[INT_PHY].type !=
  2464. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) {
  2465. mask |= NIG_MASK_MI_INT;
  2466. DP(NETIF_MSG_LINK, "enabled external phy int\n");
  2467. }
  2468. } else { /* SerDes */
  2469. mask = NIG_MASK_SERDES0_LINK_STATUS;
  2470. DP(NETIF_MSG_LINK, "enabled SerDes interrupt\n");
  2471. if (!(SINGLE_MEDIA_DIRECT(params)) &&
  2472. params->phy[INT_PHY].type !=
  2473. PORT_HW_CFG_SERDES_EXT_PHY_TYPE_NOT_CONN) {
  2474. mask |= NIG_MASK_MI_INT;
  2475. DP(NETIF_MSG_LINK, "enabled external phy int\n");
  2476. }
  2477. }
  2478. bnx2x_bits_en(bp,
  2479. NIG_REG_MASK_INTERRUPT_PORT0 + port*4,
  2480. mask);
  2481. DP(NETIF_MSG_LINK, "port %x, is_xgxs %x, int_status 0x%x\n", port,
  2482. (params->switch_cfg == SWITCH_CFG_10G),
  2483. REG_RD(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4));
  2484. DP(NETIF_MSG_LINK, " int_mask 0x%x, MI_INT %x, SERDES_LINK %x\n",
  2485. REG_RD(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4),
  2486. REG_RD(bp, NIG_REG_EMAC0_STATUS_MISC_MI_INT + port*0x18),
  2487. REG_RD(bp, NIG_REG_SERDES0_STATUS_LINK_STATUS+port*0x3c));
  2488. DP(NETIF_MSG_LINK, " 10G %x, XGXS_LINK %x\n",
  2489. REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK10G + port*0x68),
  2490. REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK_STATUS + port*0x68));
  2491. }
  2492. static void bnx2x_rearm_latch_signal(struct bnx2x *bp, u8 port,
  2493. u8 exp_mi_int)
  2494. {
  2495. u32 latch_status = 0;
  2496. /*
  2497. * Disable the MI INT ( external phy int ) by writing 1 to the
  2498. * status register. Link down indication is high-active-signal,
  2499. * so in this case we need to write the status to clear the XOR
  2500. */
  2501. /* Read Latched signals */
  2502. latch_status = REG_RD(bp,
  2503. NIG_REG_LATCH_STATUS_0 + port*8);
  2504. DP(NETIF_MSG_LINK, "latch_status = 0x%x\n", latch_status);
  2505. /* Handle only those with latched-signal=up.*/
  2506. if (exp_mi_int)
  2507. bnx2x_bits_en(bp,
  2508. NIG_REG_STATUS_INTERRUPT_PORT0
  2509. + port*4,
  2510. NIG_STATUS_EMAC0_MI_INT);
  2511. else
  2512. bnx2x_bits_dis(bp,
  2513. NIG_REG_STATUS_INTERRUPT_PORT0
  2514. + port*4,
  2515. NIG_STATUS_EMAC0_MI_INT);
  2516. if (latch_status & 1) {
  2517. /* For all latched-signal=up : Re-Arm Latch signals */
  2518. REG_WR(bp, NIG_REG_LATCH_STATUS_0 + port*8,
  2519. (latch_status & 0xfffe) | (latch_status & 1));
  2520. }
  2521. /* For all latched-signal=up,Write original_signal to status */
  2522. }
  2523. static void bnx2x_link_int_ack(struct link_params *params,
  2524. struct link_vars *vars, u8 is_10g)
  2525. {
  2526. struct bnx2x *bp = params->bp;
  2527. u8 port = params->port;
  2528. /*
  2529. * First reset all status we assume only one line will be
  2530. * change at a time
  2531. */
  2532. bnx2x_bits_dis(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
  2533. (NIG_STATUS_XGXS0_LINK10G |
  2534. NIG_STATUS_XGXS0_LINK_STATUS |
  2535. NIG_STATUS_SERDES0_LINK_STATUS));
  2536. if (vars->phy_link_up) {
  2537. if (is_10g) {
  2538. /*
  2539. * Disable the 10G link interrupt by writing 1 to the
  2540. * status register
  2541. */
  2542. DP(NETIF_MSG_LINK, "10G XGXS phy link up\n");
  2543. bnx2x_bits_en(bp,
  2544. NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
  2545. NIG_STATUS_XGXS0_LINK10G);
  2546. } else if (params->switch_cfg == SWITCH_CFG_10G) {
  2547. /*
  2548. * Disable the link interrupt by writing 1 to the
  2549. * relevant lane in the status register
  2550. */
  2551. u32 ser_lane = ((params->lane_config &
  2552. PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
  2553. PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
  2554. DP(NETIF_MSG_LINK, "%d speed XGXS phy link up\n",
  2555. vars->line_speed);
  2556. bnx2x_bits_en(bp,
  2557. NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
  2558. ((1 << ser_lane) <<
  2559. NIG_STATUS_XGXS0_LINK_STATUS_SIZE));
  2560. } else { /* SerDes */
  2561. DP(NETIF_MSG_LINK, "SerDes phy link up\n");
  2562. /*
  2563. * Disable the link interrupt by writing 1 to the status
  2564. * register
  2565. */
  2566. bnx2x_bits_en(bp,
  2567. NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
  2568. NIG_STATUS_SERDES0_LINK_STATUS);
  2569. }
  2570. }
  2571. }
  2572. static u8 bnx2x_format_ver(u32 num, u8 *str, u16 *len)
  2573. {
  2574. u8 *str_ptr = str;
  2575. u32 mask = 0xf0000000;
  2576. u8 shift = 8*4;
  2577. u8 digit;
  2578. u8 remove_leading_zeros = 1;
  2579. if (*len < 10) {
  2580. /* Need more than 10chars for this format */
  2581. *str_ptr = '\0';
  2582. (*len)--;
  2583. return -EINVAL;
  2584. }
  2585. while (shift > 0) {
  2586. shift -= 4;
  2587. digit = ((num & mask) >> shift);
  2588. if (digit == 0 && remove_leading_zeros) {
  2589. mask = mask >> 4;
  2590. continue;
  2591. } else if (digit < 0xa)
  2592. *str_ptr = digit + '0';
  2593. else
  2594. *str_ptr = digit - 0xa + 'a';
  2595. remove_leading_zeros = 0;
  2596. str_ptr++;
  2597. (*len)--;
  2598. mask = mask >> 4;
  2599. if (shift == 4*4) {
  2600. *str_ptr = '.';
  2601. str_ptr++;
  2602. (*len)--;
  2603. remove_leading_zeros = 1;
  2604. }
  2605. }
  2606. return 0;
  2607. }
  2608. static u8 bnx2x_null_format_ver(u32 spirom_ver, u8 *str, u16 *len)
  2609. {
  2610. str[0] = '\0';
  2611. (*len)--;
  2612. return 0;
  2613. }
  2614. u8 bnx2x_get_ext_phy_fw_version(struct link_params *params, u8 driver_loaded,
  2615. u8 *version, u16 len)
  2616. {
  2617. struct bnx2x *bp;
  2618. u32 spirom_ver = 0;
  2619. u8 status = 0;
  2620. u8 *ver_p = version;
  2621. u16 remain_len = len;
  2622. if (version == NULL || params == NULL)
  2623. return -EINVAL;
  2624. bp = params->bp;
  2625. /* Extract first external phy*/
  2626. version[0] = '\0';
  2627. spirom_ver = REG_RD(bp, params->phy[EXT_PHY1].ver_addr);
  2628. if (params->phy[EXT_PHY1].format_fw_ver) {
  2629. status |= params->phy[EXT_PHY1].format_fw_ver(spirom_ver,
  2630. ver_p,
  2631. &remain_len);
  2632. ver_p += (len - remain_len);
  2633. }
  2634. if ((params->num_phys == MAX_PHYS) &&
  2635. (params->phy[EXT_PHY2].ver_addr != 0)) {
  2636. spirom_ver = REG_RD(bp, params->phy[EXT_PHY2].ver_addr);
  2637. if (params->phy[EXT_PHY2].format_fw_ver) {
  2638. *ver_p = '/';
  2639. ver_p++;
  2640. remain_len--;
  2641. status |= params->phy[EXT_PHY2].format_fw_ver(
  2642. spirom_ver,
  2643. ver_p,
  2644. &remain_len);
  2645. ver_p = version + (len - remain_len);
  2646. }
  2647. }
  2648. *ver_p = '\0';
  2649. return status;
  2650. }
  2651. static void bnx2x_set_xgxs_loopback(struct bnx2x_phy *phy,
  2652. struct link_params *params)
  2653. {
  2654. u8 port = params->port;
  2655. struct bnx2x *bp = params->bp;
  2656. if (phy->req_line_speed != SPEED_1000) {
  2657. u32 md_devad;
  2658. DP(NETIF_MSG_LINK, "XGXS 10G loopback enable\n");
  2659. /* change the uni_phy_addr in the nig */
  2660. md_devad = REG_RD(bp, (NIG_REG_XGXS0_CTRL_MD_DEVAD +
  2661. port*0x18));
  2662. REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18, 0x5);
  2663. bnx2x_cl45_write(bp, phy,
  2664. 5,
  2665. (MDIO_REG_BANK_AER_BLOCK +
  2666. (MDIO_AER_BLOCK_AER_REG & 0xf)),
  2667. 0x2800);
  2668. bnx2x_cl45_write(bp, phy,
  2669. 5,
  2670. (MDIO_REG_BANK_CL73_IEEEB0 +
  2671. (MDIO_CL73_IEEEB0_CL73_AN_CONTROL & 0xf)),
  2672. 0x6041);
  2673. msleep(200);
  2674. /* set aer mmd back */
  2675. bnx2x_set_aer_mmd_xgxs(params, phy);
  2676. /* and md_devad */
  2677. REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18, md_devad);
  2678. } else {
  2679. u16 mii_ctrl;
  2680. DP(NETIF_MSG_LINK, "XGXS 1G loopback enable\n");
  2681. bnx2x_cl45_read(bp, phy, 5,
  2682. (MDIO_REG_BANK_COMBO_IEEE0 +
  2683. (MDIO_COMBO_IEEE0_MII_CONTROL & 0xf)),
  2684. &mii_ctrl);
  2685. bnx2x_cl45_write(bp, phy, 5,
  2686. (MDIO_REG_BANK_COMBO_IEEE0 +
  2687. (MDIO_COMBO_IEEE0_MII_CONTROL & 0xf)),
  2688. mii_ctrl |
  2689. MDIO_COMBO_IEEO_MII_CONTROL_LOOPBACK);
  2690. }
  2691. }
  2692. u8 bnx2x_set_led(struct link_params *params,
  2693. struct link_vars *vars, u8 mode, u32 speed)
  2694. {
  2695. u8 port = params->port;
  2696. u16 hw_led_mode = params->hw_led_mode;
  2697. u8 rc = 0, phy_idx;
  2698. u32 tmp;
  2699. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  2700. struct bnx2x *bp = params->bp;
  2701. DP(NETIF_MSG_LINK, "bnx2x_set_led: port %x, mode %d\n", port, mode);
  2702. DP(NETIF_MSG_LINK, "speed 0x%x, hw_led_mode 0x%x\n",
  2703. speed, hw_led_mode);
  2704. /* In case */
  2705. for (phy_idx = EXT_PHY1; phy_idx < MAX_PHYS; phy_idx++) {
  2706. if (params->phy[phy_idx].set_link_led) {
  2707. params->phy[phy_idx].set_link_led(
  2708. &params->phy[phy_idx], params, mode);
  2709. }
  2710. }
  2711. switch (mode) {
  2712. case LED_MODE_FRONT_PANEL_OFF:
  2713. case LED_MODE_OFF:
  2714. REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 0);
  2715. REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4,
  2716. SHARED_HW_CFG_LED_MAC1);
  2717. tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
  2718. EMAC_WR(bp, EMAC_REG_EMAC_LED, (tmp | EMAC_LED_OVERRIDE));
  2719. break;
  2720. case LED_MODE_OPER:
  2721. /*
  2722. * For all other phys, OPER mode is same as ON, so in case
  2723. * link is down, do nothing
  2724. */
  2725. if (!vars->link_up)
  2726. break;
  2727. case LED_MODE_ON:
  2728. if (params->phy[EXT_PHY1].type ==
  2729. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727 &&
  2730. CHIP_IS_E2(bp) && params->num_phys == 2) {
  2731. /*
  2732. * This is a work-around for E2+8727 Configurations
  2733. */
  2734. if (mode == LED_MODE_ON ||
  2735. speed == SPEED_10000){
  2736. REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
  2737. REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 1);
  2738. tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
  2739. EMAC_WR(bp, EMAC_REG_EMAC_LED,
  2740. (tmp | EMAC_LED_OVERRIDE));
  2741. return rc;
  2742. }
  2743. } else if (SINGLE_MEDIA_DIRECT(params)) {
  2744. /*
  2745. * This is a work-around for HW issue found when link
  2746. * is up in CL73
  2747. */
  2748. REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
  2749. REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 1);
  2750. } else {
  2751. REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, hw_led_mode);
  2752. }
  2753. REG_WR(bp, NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0 + port*4, 0);
  2754. /* Set blinking rate to ~15.9Hz */
  2755. REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_P0 + port*4,
  2756. LED_BLINK_RATE_VAL);
  2757. REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_ENA_P0 +
  2758. port*4, 1);
  2759. tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
  2760. EMAC_WR(bp, EMAC_REG_EMAC_LED, (tmp & (~EMAC_LED_OVERRIDE)));
  2761. if (CHIP_IS_E1(bp) &&
  2762. ((speed == SPEED_2500) ||
  2763. (speed == SPEED_1000) ||
  2764. (speed == SPEED_100) ||
  2765. (speed == SPEED_10))) {
  2766. /*
  2767. * On Everest 1 Ax chip versions for speeds less than
  2768. * 10G LED scheme is different
  2769. */
  2770. REG_WR(bp, NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0
  2771. + port*4, 1);
  2772. REG_WR(bp, NIG_REG_LED_CONTROL_TRAFFIC_P0 +
  2773. port*4, 0);
  2774. REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_TRAFFIC_P0 +
  2775. port*4, 1);
  2776. }
  2777. break;
  2778. default:
  2779. rc = -EINVAL;
  2780. DP(NETIF_MSG_LINK, "bnx2x_set_led: Invalid led mode %d\n",
  2781. mode);
  2782. break;
  2783. }
  2784. return rc;
  2785. }
  2786. /*
  2787. * This function comes to reflect the actual link state read DIRECTLY from the
  2788. * HW
  2789. */
  2790. u8 bnx2x_test_link(struct link_params *params, struct link_vars *vars,
  2791. u8 is_serdes)
  2792. {
  2793. struct bnx2x *bp = params->bp;
  2794. u16 gp_status = 0, phy_index = 0;
  2795. u8 ext_phy_link_up = 0, serdes_phy_type;
  2796. struct link_vars temp_vars;
  2797. CL22_RD_OVER_CL45(bp, &params->phy[INT_PHY],
  2798. MDIO_REG_BANK_GP_STATUS,
  2799. MDIO_GP_STATUS_TOP_AN_STATUS1,
  2800. &gp_status);
  2801. /* link is up only if both local phy and external phy are up */
  2802. if (!(gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS))
  2803. return -ESRCH;
  2804. switch (params->num_phys) {
  2805. case 1:
  2806. /* No external PHY */
  2807. return 0;
  2808. case 2:
  2809. ext_phy_link_up = params->phy[EXT_PHY1].read_status(
  2810. &params->phy[EXT_PHY1],
  2811. params, &temp_vars);
  2812. break;
  2813. case 3: /* Dual Media */
  2814. for (phy_index = EXT_PHY1; phy_index < params->num_phys;
  2815. phy_index++) {
  2816. serdes_phy_type = ((params->phy[phy_index].media_type ==
  2817. ETH_PHY_SFP_FIBER) ||
  2818. (params->phy[phy_index].media_type ==
  2819. ETH_PHY_XFP_FIBER));
  2820. if (is_serdes != serdes_phy_type)
  2821. continue;
  2822. if (params->phy[phy_index].read_status) {
  2823. ext_phy_link_up |=
  2824. params->phy[phy_index].read_status(
  2825. &params->phy[phy_index],
  2826. params, &temp_vars);
  2827. }
  2828. }
  2829. break;
  2830. }
  2831. if (ext_phy_link_up)
  2832. return 0;
  2833. return -ESRCH;
  2834. }
  2835. static u8 bnx2x_link_initialize(struct link_params *params,
  2836. struct link_vars *vars)
  2837. {
  2838. u8 rc = 0;
  2839. u8 phy_index, non_ext_phy;
  2840. struct bnx2x *bp = params->bp;
  2841. /*
  2842. * In case of external phy existence, the line speed would be the
  2843. * line speed linked up by the external phy. In case it is direct
  2844. * only, then the line_speed during initialization will be
  2845. * equal to the req_line_speed
  2846. */
  2847. vars->line_speed = params->phy[INT_PHY].req_line_speed;
  2848. /*
  2849. * Initialize the internal phy in case this is a direct board
  2850. * (no external phys), or this board has external phy which requires
  2851. * to first.
  2852. */
  2853. if (params->phy[INT_PHY].config_init)
  2854. params->phy[INT_PHY].config_init(
  2855. &params->phy[INT_PHY],
  2856. params, vars);
  2857. /* init ext phy and enable link state int */
  2858. non_ext_phy = (SINGLE_MEDIA_DIRECT(params) ||
  2859. (params->loopback_mode == LOOPBACK_XGXS));
  2860. if (non_ext_phy ||
  2861. (params->phy[EXT_PHY1].flags & FLAGS_INIT_XGXS_FIRST) ||
  2862. (params->loopback_mode == LOOPBACK_EXT_PHY)) {
  2863. struct bnx2x_phy *phy = &params->phy[INT_PHY];
  2864. if (vars->line_speed == SPEED_AUTO_NEG)
  2865. bnx2x_set_parallel_detection(phy, params);
  2866. bnx2x_init_internal_phy(phy, params, vars);
  2867. }
  2868. /* Init external phy*/
  2869. if (!non_ext_phy)
  2870. for (phy_index = EXT_PHY1; phy_index < params->num_phys;
  2871. phy_index++) {
  2872. /*
  2873. * No need to initialize second phy in case of first
  2874. * phy only selection. In case of second phy, we do
  2875. * need to initialize the first phy, since they are
  2876. * connected.
  2877. */
  2878. if (phy_index == EXT_PHY2 &&
  2879. (bnx2x_phy_selection(params) ==
  2880. PORT_HW_CFG_PHY_SELECTION_FIRST_PHY)) {
  2881. DP(NETIF_MSG_LINK, "Ignoring second phy\n");
  2882. continue;
  2883. }
  2884. params->phy[phy_index].config_init(
  2885. &params->phy[phy_index],
  2886. params, vars);
  2887. }
  2888. /* Reset the interrupt indication after phy was initialized */
  2889. bnx2x_bits_dis(bp, NIG_REG_STATUS_INTERRUPT_PORT0 +
  2890. params->port*4,
  2891. (NIG_STATUS_XGXS0_LINK10G |
  2892. NIG_STATUS_XGXS0_LINK_STATUS |
  2893. NIG_STATUS_SERDES0_LINK_STATUS |
  2894. NIG_MASK_MI_INT));
  2895. return rc;
  2896. }
  2897. static void bnx2x_int_link_reset(struct bnx2x_phy *phy,
  2898. struct link_params *params)
  2899. {
  2900. /* reset the SerDes/XGXS */
  2901. REG_WR(params->bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR,
  2902. (0x1ff << (params->port*16)));
  2903. }
  2904. static void bnx2x_common_ext_link_reset(struct bnx2x_phy *phy,
  2905. struct link_params *params)
  2906. {
  2907. struct bnx2x *bp = params->bp;
  2908. u8 gpio_port;
  2909. /* HW reset */
  2910. if (CHIP_IS_E2(bp))
  2911. gpio_port = BP_PATH(bp);
  2912. else
  2913. gpio_port = params->port;
  2914. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
  2915. MISC_REGISTERS_GPIO_OUTPUT_LOW,
  2916. gpio_port);
  2917. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
  2918. MISC_REGISTERS_GPIO_OUTPUT_LOW,
  2919. gpio_port);
  2920. DP(NETIF_MSG_LINK, "reset external PHY\n");
  2921. }
  2922. static u8 bnx2x_update_link_down(struct link_params *params,
  2923. struct link_vars *vars)
  2924. {
  2925. struct bnx2x *bp = params->bp;
  2926. u8 port = params->port;
  2927. DP(NETIF_MSG_LINK, "Port %x: Link is down\n", port);
  2928. bnx2x_set_led(params, vars, LED_MODE_OFF, 0);
  2929. /* indicate no mac active */
  2930. vars->mac_type = MAC_TYPE_NONE;
  2931. /* update shared memory */
  2932. vars->link_status = 0;
  2933. vars->line_speed = 0;
  2934. bnx2x_update_mng(params, vars->link_status);
  2935. /* activate nig drain */
  2936. REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 1);
  2937. /* disable emac */
  2938. REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
  2939. msleep(10);
  2940. /* reset BigMac */
  2941. bnx2x_bmac_rx_disable(bp, params->port);
  2942. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  2943. (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
  2944. return 0;
  2945. }
  2946. static u8 bnx2x_update_link_up(struct link_params *params,
  2947. struct link_vars *vars,
  2948. u8 link_10g)
  2949. {
  2950. struct bnx2x *bp = params->bp;
  2951. u8 port = params->port;
  2952. u8 rc = 0;
  2953. vars->link_status |= LINK_STATUS_LINK_UP;
  2954. if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
  2955. vars->link_status |=
  2956. LINK_STATUS_TX_FLOW_CONTROL_ENABLED;
  2957. if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
  2958. vars->link_status |=
  2959. LINK_STATUS_RX_FLOW_CONTROL_ENABLED;
  2960. if (link_10g) {
  2961. bnx2x_bmac_enable(params, vars, 0);
  2962. bnx2x_set_led(params, vars,
  2963. LED_MODE_OPER, SPEED_10000);
  2964. } else {
  2965. rc = bnx2x_emac_program(params, vars);
  2966. bnx2x_emac_enable(params, vars, 0);
  2967. /* AN complete? */
  2968. if ((vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE)
  2969. && (!(vars->phy_flags & PHY_SGMII_FLAG)) &&
  2970. SINGLE_MEDIA_DIRECT(params))
  2971. bnx2x_set_gmii_tx_driver(params);
  2972. }
  2973. /* PBF - link up */
  2974. if (!(CHIP_IS_E2(bp)))
  2975. rc |= bnx2x_pbf_update(params, vars->flow_ctrl,
  2976. vars->line_speed);
  2977. /* disable drain */
  2978. REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 0);
  2979. /* update shared memory */
  2980. bnx2x_update_mng(params, vars->link_status);
  2981. msleep(20);
  2982. return rc;
  2983. }
  2984. /*
  2985. * The bnx2x_link_update function should be called upon link
  2986. * interrupt.
  2987. * Link is considered up as follows:
  2988. * - DIRECT_SINGLE_MEDIA - Only XGXS link (internal link) needs
  2989. * to be up
  2990. * - SINGLE_MEDIA - The link between the 577xx and the external
  2991. * phy (XGXS) need to up as well as the external link of the
  2992. * phy (PHY_EXT1)
  2993. * - DUAL_MEDIA - The link between the 577xx and the first
  2994. * external phy needs to be up, and at least one of the 2
  2995. * external phy link must be up.
  2996. */
  2997. u8 bnx2x_link_update(struct link_params *params, struct link_vars *vars)
  2998. {
  2999. struct bnx2x *bp = params->bp;
  3000. struct link_vars phy_vars[MAX_PHYS];
  3001. u8 port = params->port;
  3002. u8 link_10g, phy_index;
  3003. u8 ext_phy_link_up = 0, cur_link_up, rc = 0;
  3004. u8 is_mi_int = 0;
  3005. u16 ext_phy_line_speed = 0, prev_line_speed = vars->line_speed;
  3006. u8 active_external_phy = INT_PHY;
  3007. vars->link_status = 0;
  3008. for (phy_index = INT_PHY; phy_index < params->num_phys;
  3009. phy_index++) {
  3010. phy_vars[phy_index].flow_ctrl = 0;
  3011. phy_vars[phy_index].link_status = 0;
  3012. phy_vars[phy_index].line_speed = 0;
  3013. phy_vars[phy_index].duplex = DUPLEX_FULL;
  3014. phy_vars[phy_index].phy_link_up = 0;
  3015. phy_vars[phy_index].link_up = 0;
  3016. }
  3017. DP(NETIF_MSG_LINK, "port %x, XGXS?%x, int_status 0x%x\n",
  3018. port, (vars->phy_flags & PHY_XGXS_FLAG),
  3019. REG_RD(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4));
  3020. is_mi_int = (u8)(REG_RD(bp, NIG_REG_EMAC0_STATUS_MISC_MI_INT +
  3021. port*0x18) > 0);
  3022. DP(NETIF_MSG_LINK, "int_mask 0x%x MI_INT %x, SERDES_LINK %x\n",
  3023. REG_RD(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4),
  3024. is_mi_int,
  3025. REG_RD(bp, NIG_REG_SERDES0_STATUS_LINK_STATUS + port*0x3c));
  3026. DP(NETIF_MSG_LINK, " 10G %x, XGXS_LINK %x\n",
  3027. REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK10G + port*0x68),
  3028. REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK_STATUS + port*0x68));
  3029. /* disable emac */
  3030. REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
  3031. /*
  3032. * Step 1:
  3033. * Check external link change only for external phys, and apply
  3034. * priority selection between them in case the link on both phys
  3035. * is up. Note that the instead of the common vars, a temporary
  3036. * vars argument is used since each phy may have different link/
  3037. * speed/duplex result
  3038. */
  3039. for (phy_index = EXT_PHY1; phy_index < params->num_phys;
  3040. phy_index++) {
  3041. struct bnx2x_phy *phy = &params->phy[phy_index];
  3042. if (!phy->read_status)
  3043. continue;
  3044. /* Read link status and params of this ext phy */
  3045. cur_link_up = phy->read_status(phy, params,
  3046. &phy_vars[phy_index]);
  3047. if (cur_link_up) {
  3048. DP(NETIF_MSG_LINK, "phy in index %d link is up\n",
  3049. phy_index);
  3050. } else {
  3051. DP(NETIF_MSG_LINK, "phy in index %d link is down\n",
  3052. phy_index);
  3053. continue;
  3054. }
  3055. if (!ext_phy_link_up) {
  3056. ext_phy_link_up = 1;
  3057. active_external_phy = phy_index;
  3058. } else {
  3059. switch (bnx2x_phy_selection(params)) {
  3060. case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
  3061. case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
  3062. /*
  3063. * In this option, the first PHY makes sure to pass the
  3064. * traffic through itself only.
  3065. * Its not clear how to reset the link on the second phy
  3066. */
  3067. active_external_phy = EXT_PHY1;
  3068. break;
  3069. case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
  3070. /*
  3071. * In this option, the first PHY makes sure to pass the
  3072. * traffic through the second PHY.
  3073. */
  3074. active_external_phy = EXT_PHY2;
  3075. break;
  3076. default:
  3077. /*
  3078. * Link indication on both PHYs with the following cases
  3079. * is invalid:
  3080. * - FIRST_PHY means that second phy wasn't initialized,
  3081. * hence its link is expected to be down
  3082. * - SECOND_PHY means that first phy should not be able
  3083. * to link up by itself (using configuration)
  3084. * - DEFAULT should be overriden during initialiazation
  3085. */
  3086. DP(NETIF_MSG_LINK, "Invalid link indication"
  3087. "mpc=0x%x. DISABLING LINK !!!\n",
  3088. params->multi_phy_config);
  3089. ext_phy_link_up = 0;
  3090. break;
  3091. }
  3092. }
  3093. }
  3094. prev_line_speed = vars->line_speed;
  3095. /*
  3096. * Step 2:
  3097. * Read the status of the internal phy. In case of
  3098. * DIRECT_SINGLE_MEDIA board, this link is the external link,
  3099. * otherwise this is the link between the 577xx and the first
  3100. * external phy
  3101. */
  3102. if (params->phy[INT_PHY].read_status)
  3103. params->phy[INT_PHY].read_status(
  3104. &params->phy[INT_PHY],
  3105. params, vars);
  3106. /*
  3107. * The INT_PHY flow control reside in the vars. This include the
  3108. * case where the speed or flow control are not set to AUTO.
  3109. * Otherwise, the active external phy flow control result is set
  3110. * to the vars. The ext_phy_line_speed is needed to check if the
  3111. * speed is different between the internal phy and external phy.
  3112. * This case may be result of intermediate link speed change.
  3113. */
  3114. if (active_external_phy > INT_PHY) {
  3115. vars->flow_ctrl = phy_vars[active_external_phy].flow_ctrl;
  3116. /*
  3117. * Link speed is taken from the XGXS. AN and FC result from
  3118. * the external phy.
  3119. */
  3120. vars->link_status |= phy_vars[active_external_phy].link_status;
  3121. /*
  3122. * if active_external_phy is first PHY and link is up - disable
  3123. * disable TX on second external PHY
  3124. */
  3125. if (active_external_phy == EXT_PHY1) {
  3126. if (params->phy[EXT_PHY2].phy_specific_func) {
  3127. DP(NETIF_MSG_LINK, "Disabling TX on"
  3128. " EXT_PHY2\n");
  3129. params->phy[EXT_PHY2].phy_specific_func(
  3130. &params->phy[EXT_PHY2],
  3131. params, DISABLE_TX);
  3132. }
  3133. }
  3134. ext_phy_line_speed = phy_vars[active_external_phy].line_speed;
  3135. vars->duplex = phy_vars[active_external_phy].duplex;
  3136. if (params->phy[active_external_phy].supported &
  3137. SUPPORTED_FIBRE)
  3138. vars->link_status |= LINK_STATUS_SERDES_LINK;
  3139. DP(NETIF_MSG_LINK, "Active external phy selected: %x\n",
  3140. active_external_phy);
  3141. }
  3142. for (phy_index = EXT_PHY1; phy_index < params->num_phys;
  3143. phy_index++) {
  3144. if (params->phy[phy_index].flags &
  3145. FLAGS_REARM_LATCH_SIGNAL) {
  3146. bnx2x_rearm_latch_signal(bp, port,
  3147. phy_index ==
  3148. active_external_phy);
  3149. break;
  3150. }
  3151. }
  3152. DP(NETIF_MSG_LINK, "vars->flow_ctrl = 0x%x, vars->link_status = 0x%x,"
  3153. " ext_phy_line_speed = %d\n", vars->flow_ctrl,
  3154. vars->link_status, ext_phy_line_speed);
  3155. /*
  3156. * Upon link speed change set the NIG into drain mode. Comes to
  3157. * deals with possible FIFO glitch due to clk change when speed
  3158. * is decreased without link down indicator
  3159. */
  3160. if (vars->phy_link_up) {
  3161. if (!(SINGLE_MEDIA_DIRECT(params)) && ext_phy_link_up &&
  3162. (ext_phy_line_speed != vars->line_speed)) {
  3163. DP(NETIF_MSG_LINK, "Internal link speed %d is"
  3164. " different than the external"
  3165. " link speed %d\n", vars->line_speed,
  3166. ext_phy_line_speed);
  3167. vars->phy_link_up = 0;
  3168. } else if (prev_line_speed != vars->line_speed) {
  3169. REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4,
  3170. 0);
  3171. msleep(1);
  3172. }
  3173. }
  3174. /* anything 10 and over uses the bmac */
  3175. link_10g = ((vars->line_speed == SPEED_10000) ||
  3176. (vars->line_speed == SPEED_12000) ||
  3177. (vars->line_speed == SPEED_12500) ||
  3178. (vars->line_speed == SPEED_13000) ||
  3179. (vars->line_speed == SPEED_15000) ||
  3180. (vars->line_speed == SPEED_16000));
  3181. bnx2x_link_int_ack(params, vars, link_10g);
  3182. /*
  3183. * In case external phy link is up, and internal link is down
  3184. * (not initialized yet probably after link initialization, it
  3185. * needs to be initialized.
  3186. * Note that after link down-up as result of cable plug, the xgxs
  3187. * link would probably become up again without the need
  3188. * initialize it
  3189. */
  3190. if (!(SINGLE_MEDIA_DIRECT(params))) {
  3191. DP(NETIF_MSG_LINK, "ext_phy_link_up = %d, int_link_up = %d,"
  3192. " init_preceding = %d\n", ext_phy_link_up,
  3193. vars->phy_link_up,
  3194. params->phy[EXT_PHY1].flags &
  3195. FLAGS_INIT_XGXS_FIRST);
  3196. if (!(params->phy[EXT_PHY1].flags &
  3197. FLAGS_INIT_XGXS_FIRST)
  3198. && ext_phy_link_up && !vars->phy_link_up) {
  3199. vars->line_speed = ext_phy_line_speed;
  3200. if (vars->line_speed < SPEED_1000)
  3201. vars->phy_flags |= PHY_SGMII_FLAG;
  3202. else
  3203. vars->phy_flags &= ~PHY_SGMII_FLAG;
  3204. bnx2x_init_internal_phy(&params->phy[INT_PHY],
  3205. params,
  3206. vars);
  3207. }
  3208. }
  3209. /*
  3210. * Link is up only if both local phy and external phy (in case of
  3211. * non-direct board) are up
  3212. */
  3213. vars->link_up = (vars->phy_link_up &&
  3214. (ext_phy_link_up ||
  3215. SINGLE_MEDIA_DIRECT(params)));
  3216. if (vars->link_up)
  3217. rc = bnx2x_update_link_up(params, vars, link_10g);
  3218. else
  3219. rc = bnx2x_update_link_down(params, vars);
  3220. return rc;
  3221. }
  3222. /*****************************************************************************/
  3223. /* External Phy section */
  3224. /*****************************************************************************/
  3225. void bnx2x_ext_phy_hw_reset(struct bnx2x *bp, u8 port)
  3226. {
  3227. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
  3228. MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
  3229. msleep(1);
  3230. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
  3231. MISC_REGISTERS_GPIO_OUTPUT_HIGH, port);
  3232. }
  3233. static void bnx2x_save_spirom_version(struct bnx2x *bp, u8 port,
  3234. u32 spirom_ver, u32 ver_addr)
  3235. {
  3236. DP(NETIF_MSG_LINK, "FW version 0x%x:0x%x for port %d\n",
  3237. (u16)(spirom_ver>>16), (u16)spirom_ver, port);
  3238. if (ver_addr)
  3239. REG_WR(bp, ver_addr, spirom_ver);
  3240. }
  3241. static void bnx2x_save_bcm_spirom_ver(struct bnx2x *bp,
  3242. struct bnx2x_phy *phy,
  3243. u8 port)
  3244. {
  3245. u16 fw_ver1, fw_ver2;
  3246. bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
  3247. MDIO_PMA_REG_ROM_VER1, &fw_ver1);
  3248. bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
  3249. MDIO_PMA_REG_ROM_VER2, &fw_ver2);
  3250. bnx2x_save_spirom_version(bp, port, (u32)(fw_ver1<<16 | fw_ver2),
  3251. phy->ver_addr);
  3252. }
  3253. static void bnx2x_ext_phy_set_pause(struct link_params *params,
  3254. struct bnx2x_phy *phy,
  3255. struct link_vars *vars)
  3256. {
  3257. u16 val;
  3258. struct bnx2x *bp = params->bp;
  3259. /* read modify write pause advertizing */
  3260. bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV_PAUSE, &val);
  3261. val &= ~MDIO_AN_REG_ADV_PAUSE_BOTH;
  3262. /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
  3263. bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
  3264. if ((vars->ieee_fc &
  3265. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
  3266. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) {
  3267. val |= MDIO_AN_REG_ADV_PAUSE_ASYMMETRIC;
  3268. }
  3269. if ((vars->ieee_fc &
  3270. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
  3271. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) {
  3272. val |= MDIO_AN_REG_ADV_PAUSE_PAUSE;
  3273. }
  3274. DP(NETIF_MSG_LINK, "Ext phy AN advertize 0x%x\n", val);
  3275. bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV_PAUSE, val);
  3276. }
  3277. static u8 bnx2x_ext_phy_resolve_fc(struct bnx2x_phy *phy,
  3278. struct link_params *params,
  3279. struct link_vars *vars)
  3280. {
  3281. struct bnx2x *bp = params->bp;
  3282. u16 ld_pause; /* local */
  3283. u16 lp_pause; /* link partner */
  3284. u16 pause_result;
  3285. u8 ret = 0;
  3286. /* read twice */
  3287. vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  3288. if (phy->req_flow_ctrl != BNX2X_FLOW_CTRL_AUTO)
  3289. vars->flow_ctrl = phy->req_flow_ctrl;
  3290. else if (phy->req_line_speed != SPEED_AUTO_NEG)
  3291. vars->flow_ctrl = params->req_fc_auto_adv;
  3292. else if (vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) {
  3293. ret = 1;
  3294. bnx2x_cl45_read(bp, phy,
  3295. MDIO_AN_DEVAD,
  3296. MDIO_AN_REG_ADV_PAUSE, &ld_pause);
  3297. bnx2x_cl45_read(bp, phy,
  3298. MDIO_AN_DEVAD,
  3299. MDIO_AN_REG_LP_AUTO_NEG, &lp_pause);
  3300. pause_result = (ld_pause &
  3301. MDIO_AN_REG_ADV_PAUSE_MASK) >> 8;
  3302. pause_result |= (lp_pause &
  3303. MDIO_AN_REG_ADV_PAUSE_MASK) >> 10;
  3304. DP(NETIF_MSG_LINK, "Ext PHY pause result 0x%x\n",
  3305. pause_result);
  3306. bnx2x_pause_resolve(vars, pause_result);
  3307. }
  3308. return ret;
  3309. }
  3310. static void bnx2x_ext_phy_10G_an_resolve(struct bnx2x *bp,
  3311. struct bnx2x_phy *phy,
  3312. struct link_vars *vars)
  3313. {
  3314. u16 val;
  3315. bnx2x_cl45_read(bp, phy,
  3316. MDIO_AN_DEVAD,
  3317. MDIO_AN_REG_STATUS, &val);
  3318. bnx2x_cl45_read(bp, phy,
  3319. MDIO_AN_DEVAD,
  3320. MDIO_AN_REG_STATUS, &val);
  3321. if (val & (1<<5))
  3322. vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
  3323. if ((val & (1<<0)) == 0)
  3324. vars->link_status |= LINK_STATUS_PARALLEL_DETECTION_USED;
  3325. }
  3326. /******************************************************************/
  3327. /* common BCM8073/BCM8727 PHY SECTION */
  3328. /******************************************************************/
  3329. static void bnx2x_8073_resolve_fc(struct bnx2x_phy *phy,
  3330. struct link_params *params,
  3331. struct link_vars *vars)
  3332. {
  3333. struct bnx2x *bp = params->bp;
  3334. if (phy->req_line_speed == SPEED_10 ||
  3335. phy->req_line_speed == SPEED_100) {
  3336. vars->flow_ctrl = phy->req_flow_ctrl;
  3337. return;
  3338. }
  3339. if (bnx2x_ext_phy_resolve_fc(phy, params, vars) &&
  3340. (vars->flow_ctrl == BNX2X_FLOW_CTRL_NONE)) {
  3341. u16 pause_result;
  3342. u16 ld_pause; /* local */
  3343. u16 lp_pause; /* link partner */
  3344. bnx2x_cl45_read(bp, phy,
  3345. MDIO_AN_DEVAD,
  3346. MDIO_AN_REG_CL37_FC_LD, &ld_pause);
  3347. bnx2x_cl45_read(bp, phy,
  3348. MDIO_AN_DEVAD,
  3349. MDIO_AN_REG_CL37_FC_LP, &lp_pause);
  3350. pause_result = (ld_pause &
  3351. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) >> 5;
  3352. pause_result |= (lp_pause &
  3353. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) >> 7;
  3354. bnx2x_pause_resolve(vars, pause_result);
  3355. DP(NETIF_MSG_LINK, "Ext PHY CL37 pause result 0x%x\n",
  3356. pause_result);
  3357. }
  3358. }
  3359. static u8 bnx2x_8073_8727_external_rom_boot(struct bnx2x *bp,
  3360. struct bnx2x_phy *phy,
  3361. u8 port)
  3362. {
  3363. u32 count = 0;
  3364. u16 fw_ver1, fw_msgout;
  3365. u8 rc = 0;
  3366. /* Boot port from external ROM */
  3367. /* EDC grst */
  3368. bnx2x_cl45_write(bp, phy,
  3369. MDIO_PMA_DEVAD,
  3370. MDIO_PMA_REG_GEN_CTRL,
  3371. 0x0001);
  3372. /* ucode reboot and rst */
  3373. bnx2x_cl45_write(bp, phy,
  3374. MDIO_PMA_DEVAD,
  3375. MDIO_PMA_REG_GEN_CTRL,
  3376. 0x008c);
  3377. bnx2x_cl45_write(bp, phy,
  3378. MDIO_PMA_DEVAD,
  3379. MDIO_PMA_REG_MISC_CTRL1, 0x0001);
  3380. /* Reset internal microprocessor */
  3381. bnx2x_cl45_write(bp, phy,
  3382. MDIO_PMA_DEVAD,
  3383. MDIO_PMA_REG_GEN_CTRL,
  3384. MDIO_PMA_REG_GEN_CTRL_ROM_MICRO_RESET);
  3385. /* Release srst bit */
  3386. bnx2x_cl45_write(bp, phy,
  3387. MDIO_PMA_DEVAD,
  3388. MDIO_PMA_REG_GEN_CTRL,
  3389. MDIO_PMA_REG_GEN_CTRL_ROM_RESET_INTERNAL_MP);
  3390. /* Delay 100ms per the PHY specifications */
  3391. msleep(100);
  3392. /* 8073 sometimes taking longer to download */
  3393. do {
  3394. count++;
  3395. if (count > 300) {
  3396. DP(NETIF_MSG_LINK,
  3397. "bnx2x_8073_8727_external_rom_boot port %x:"
  3398. "Download failed. fw version = 0x%x\n",
  3399. port, fw_ver1);
  3400. rc = -EINVAL;
  3401. break;
  3402. }
  3403. bnx2x_cl45_read(bp, phy,
  3404. MDIO_PMA_DEVAD,
  3405. MDIO_PMA_REG_ROM_VER1, &fw_ver1);
  3406. bnx2x_cl45_read(bp, phy,
  3407. MDIO_PMA_DEVAD,
  3408. MDIO_PMA_REG_M8051_MSGOUT_REG, &fw_msgout);
  3409. msleep(1);
  3410. } while (fw_ver1 == 0 || fw_ver1 == 0x4321 ||
  3411. ((fw_msgout & 0xff) != 0x03 && (phy->type ==
  3412. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073)));
  3413. /* Clear ser_boot_ctl bit */
  3414. bnx2x_cl45_write(bp, phy,
  3415. MDIO_PMA_DEVAD,
  3416. MDIO_PMA_REG_MISC_CTRL1, 0x0000);
  3417. bnx2x_save_bcm_spirom_ver(bp, phy, port);
  3418. DP(NETIF_MSG_LINK,
  3419. "bnx2x_8073_8727_external_rom_boot port %x:"
  3420. "Download complete. fw version = 0x%x\n",
  3421. port, fw_ver1);
  3422. return rc;
  3423. }
  3424. /******************************************************************/
  3425. /* BCM8073 PHY SECTION */
  3426. /******************************************************************/
  3427. static u8 bnx2x_8073_is_snr_needed(struct bnx2x *bp, struct bnx2x_phy *phy)
  3428. {
  3429. /* This is only required for 8073A1, version 102 only */
  3430. u16 val;
  3431. /* Read 8073 HW revision*/
  3432. bnx2x_cl45_read(bp, phy,
  3433. MDIO_PMA_DEVAD,
  3434. MDIO_PMA_REG_8073_CHIP_REV, &val);
  3435. if (val != 1) {
  3436. /* No need to workaround in 8073 A1 */
  3437. return 0;
  3438. }
  3439. bnx2x_cl45_read(bp, phy,
  3440. MDIO_PMA_DEVAD,
  3441. MDIO_PMA_REG_ROM_VER2, &val);
  3442. /* SNR should be applied only for version 0x102 */
  3443. if (val != 0x102)
  3444. return 0;
  3445. return 1;
  3446. }
  3447. static u8 bnx2x_8073_xaui_wa(struct bnx2x *bp, struct bnx2x_phy *phy)
  3448. {
  3449. u16 val, cnt, cnt1 ;
  3450. bnx2x_cl45_read(bp, phy,
  3451. MDIO_PMA_DEVAD,
  3452. MDIO_PMA_REG_8073_CHIP_REV, &val);
  3453. if (val > 0) {
  3454. /* No need to workaround in 8073 A1 */
  3455. return 0;
  3456. }
  3457. /* XAUI workaround in 8073 A0: */
  3458. /*
  3459. * After loading the boot ROM and restarting Autoneg, poll
  3460. * Dev1, Reg $C820:
  3461. */
  3462. for (cnt = 0; cnt < 1000; cnt++) {
  3463. bnx2x_cl45_read(bp, phy,
  3464. MDIO_PMA_DEVAD,
  3465. MDIO_PMA_REG_8073_SPEED_LINK_STATUS,
  3466. &val);
  3467. /*
  3468. * If bit [14] = 0 or bit [13] = 0, continue on with
  3469. * system initialization (XAUI work-around not required, as
  3470. * these bits indicate 2.5G or 1G link up).
  3471. */
  3472. if (!(val & (1<<14)) || !(val & (1<<13))) {
  3473. DP(NETIF_MSG_LINK, "XAUI work-around not required\n");
  3474. return 0;
  3475. } else if (!(val & (1<<15))) {
  3476. DP(NETIF_MSG_LINK, "bit 15 went off\n");
  3477. /*
  3478. * If bit 15 is 0, then poll Dev1, Reg $C841 until it's
  3479. * MSB (bit15) goes to 1 (indicating that the XAUI
  3480. * workaround has completed), then continue on with
  3481. * system initialization.
  3482. */
  3483. for (cnt1 = 0; cnt1 < 1000; cnt1++) {
  3484. bnx2x_cl45_read(bp, phy,
  3485. MDIO_PMA_DEVAD,
  3486. MDIO_PMA_REG_8073_XAUI_WA, &val);
  3487. if (val & (1<<15)) {
  3488. DP(NETIF_MSG_LINK,
  3489. "XAUI workaround has completed\n");
  3490. return 0;
  3491. }
  3492. msleep(3);
  3493. }
  3494. break;
  3495. }
  3496. msleep(3);
  3497. }
  3498. DP(NETIF_MSG_LINK, "Warning: XAUI work-around timeout !!!\n");
  3499. return -EINVAL;
  3500. }
  3501. static void bnx2x_807x_force_10G(struct bnx2x *bp, struct bnx2x_phy *phy)
  3502. {
  3503. /* Force KR or KX */
  3504. bnx2x_cl45_write(bp, phy,
  3505. MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x2040);
  3506. bnx2x_cl45_write(bp, phy,
  3507. MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0x000b);
  3508. bnx2x_cl45_write(bp, phy,
  3509. MDIO_PMA_DEVAD, MDIO_PMA_REG_BCM_CTRL, 0x0000);
  3510. bnx2x_cl45_write(bp, phy,
  3511. MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x0000);
  3512. }
  3513. static void bnx2x_8073_set_pause_cl37(struct link_params *params,
  3514. struct bnx2x_phy *phy,
  3515. struct link_vars *vars)
  3516. {
  3517. u16 cl37_val;
  3518. struct bnx2x *bp = params->bp;
  3519. bnx2x_cl45_read(bp, phy,
  3520. MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, &cl37_val);
  3521. cl37_val &= ~MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
  3522. /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
  3523. bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
  3524. if ((vars->ieee_fc &
  3525. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC) ==
  3526. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC) {
  3527. cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC;
  3528. }
  3529. if ((vars->ieee_fc &
  3530. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
  3531. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) {
  3532. cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
  3533. }
  3534. if ((vars->ieee_fc &
  3535. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
  3536. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) {
  3537. cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
  3538. }
  3539. DP(NETIF_MSG_LINK,
  3540. "Ext phy AN advertize cl37 0x%x\n", cl37_val);
  3541. bnx2x_cl45_write(bp, phy,
  3542. MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, cl37_val);
  3543. msleep(500);
  3544. }
  3545. static u8 bnx2x_8073_config_init(struct bnx2x_phy *phy,
  3546. struct link_params *params,
  3547. struct link_vars *vars)
  3548. {
  3549. struct bnx2x *bp = params->bp;
  3550. u16 val = 0, tmp1;
  3551. u8 gpio_port;
  3552. DP(NETIF_MSG_LINK, "Init 8073\n");
  3553. if (CHIP_IS_E2(bp))
  3554. gpio_port = BP_PATH(bp);
  3555. else
  3556. gpio_port = params->port;
  3557. /* Restore normal power mode*/
  3558. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
  3559. MISC_REGISTERS_GPIO_OUTPUT_HIGH, gpio_port);
  3560. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
  3561. MISC_REGISTERS_GPIO_OUTPUT_HIGH, gpio_port);
  3562. /* enable LASI */
  3563. bnx2x_cl45_write(bp, phy,
  3564. MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM_CTRL, (1<<2));
  3565. bnx2x_cl45_write(bp, phy,
  3566. MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 0x0004);
  3567. bnx2x_8073_set_pause_cl37(params, phy, vars);
  3568. bnx2x_cl45_read(bp, phy,
  3569. MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &tmp1);
  3570. bnx2x_cl45_read(bp, phy,
  3571. MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM, &tmp1);
  3572. DP(NETIF_MSG_LINK, "Before rom RX_ALARM(port1): 0x%x\n", tmp1);
  3573. /* Swap polarity if required - Must be done only in non-1G mode */
  3574. if (params->lane_config & PORT_HW_CFG_SWAP_PHY_POLARITY_ENABLED) {
  3575. /* Configure the 8073 to swap _P and _N of the KR lines */
  3576. DP(NETIF_MSG_LINK, "Swapping polarity for the 8073\n");
  3577. /* 10G Rx/Tx and 1G Tx signal polarity swap */
  3578. bnx2x_cl45_read(bp, phy,
  3579. MDIO_PMA_DEVAD,
  3580. MDIO_PMA_REG_8073_OPT_DIGITAL_CTRL, &val);
  3581. bnx2x_cl45_write(bp, phy,
  3582. MDIO_PMA_DEVAD,
  3583. MDIO_PMA_REG_8073_OPT_DIGITAL_CTRL,
  3584. (val | (3<<9)));
  3585. }
  3586. /* Enable CL37 BAM */
  3587. if (REG_RD(bp, params->shmem_base +
  3588. offsetof(struct shmem_region, dev_info.
  3589. port_hw_config[params->port].default_cfg)) &
  3590. PORT_HW_CFG_ENABLE_BAM_ON_KR_ENABLED) {
  3591. bnx2x_cl45_read(bp, phy,
  3592. MDIO_AN_DEVAD,
  3593. MDIO_AN_REG_8073_BAM, &val);
  3594. bnx2x_cl45_write(bp, phy,
  3595. MDIO_AN_DEVAD,
  3596. MDIO_AN_REG_8073_BAM, val | 1);
  3597. DP(NETIF_MSG_LINK, "Enable CL37 BAM on KR\n");
  3598. }
  3599. if (params->loopback_mode == LOOPBACK_EXT) {
  3600. bnx2x_807x_force_10G(bp, phy);
  3601. DP(NETIF_MSG_LINK, "Forced speed 10G on 807X\n");
  3602. return 0;
  3603. } else {
  3604. bnx2x_cl45_write(bp, phy,
  3605. MDIO_PMA_DEVAD, MDIO_PMA_REG_BCM_CTRL, 0x0002);
  3606. }
  3607. if (phy->req_line_speed != SPEED_AUTO_NEG) {
  3608. if (phy->req_line_speed == SPEED_10000) {
  3609. val = (1<<7);
  3610. } else if (phy->req_line_speed == SPEED_2500) {
  3611. val = (1<<5);
  3612. /*
  3613. * Note that 2.5G works only when used with 1G
  3614. * advertisement
  3615. */
  3616. } else
  3617. val = (1<<5);
  3618. } else {
  3619. val = 0;
  3620. if (phy->speed_cap_mask &
  3621. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  3622. val |= (1<<7);
  3623. /* Note that 2.5G works only when used with 1G advertisement */
  3624. if (phy->speed_cap_mask &
  3625. (PORT_HW_CFG_SPEED_CAPABILITY_D0_1G |
  3626. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  3627. val |= (1<<5);
  3628. DP(NETIF_MSG_LINK, "807x autoneg val = 0x%x\n", val);
  3629. }
  3630. bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV, val);
  3631. bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_8073_2_5G, &tmp1);
  3632. if (((phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G) &&
  3633. (phy->req_line_speed == SPEED_AUTO_NEG)) ||
  3634. (phy->req_line_speed == SPEED_2500)) {
  3635. u16 phy_ver;
  3636. /* Allow 2.5G for A1 and above */
  3637. bnx2x_cl45_read(bp, phy,
  3638. MDIO_PMA_DEVAD, MDIO_PMA_REG_8073_CHIP_REV,
  3639. &phy_ver);
  3640. DP(NETIF_MSG_LINK, "Add 2.5G\n");
  3641. if (phy_ver > 0)
  3642. tmp1 |= 1;
  3643. else
  3644. tmp1 &= 0xfffe;
  3645. } else {
  3646. DP(NETIF_MSG_LINK, "Disable 2.5G\n");
  3647. tmp1 &= 0xfffe;
  3648. }
  3649. bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_8073_2_5G, tmp1);
  3650. /* Add support for CL37 (passive mode) II */
  3651. bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, &tmp1);
  3652. bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD,
  3653. (tmp1 | ((phy->req_duplex == DUPLEX_FULL) ?
  3654. 0x20 : 0x40)));
  3655. /* Add support for CL37 (passive mode) III */
  3656. bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
  3657. /*
  3658. * The SNR will improve about 2db by changing BW and FEE main
  3659. * tap. Rest commands are executed after link is up
  3660. * Change FFE main cursor to 5 in EDC register
  3661. */
  3662. if (bnx2x_8073_is_snr_needed(bp, phy))
  3663. bnx2x_cl45_write(bp, phy,
  3664. MDIO_PMA_DEVAD, MDIO_PMA_REG_EDC_FFE_MAIN,
  3665. 0xFB0C);
  3666. /* Enable FEC (Forware Error Correction) Request in the AN */
  3667. bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV2, &tmp1);
  3668. tmp1 |= (1<<15);
  3669. bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV2, tmp1);
  3670. bnx2x_ext_phy_set_pause(params, phy, vars);
  3671. /* Restart autoneg */
  3672. msleep(500);
  3673. bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
  3674. DP(NETIF_MSG_LINK, "807x Autoneg Restart: Advertise 1G=%x, 10G=%x\n",
  3675. ((val & (1<<5)) > 0), ((val & (1<<7)) > 0));
  3676. return 0;
  3677. }
  3678. static u8 bnx2x_8073_read_status(struct bnx2x_phy *phy,
  3679. struct link_params *params,
  3680. struct link_vars *vars)
  3681. {
  3682. struct bnx2x *bp = params->bp;
  3683. u8 link_up = 0;
  3684. u16 val1, val2;
  3685. u16 link_status = 0;
  3686. u16 an1000_status = 0;
  3687. bnx2x_cl45_read(bp, phy,
  3688. MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS, &val1);
  3689. DP(NETIF_MSG_LINK, "8703 LASI status 0x%x\n", val1);
  3690. /* clear the interrupt LASI status register */
  3691. bnx2x_cl45_read(bp, phy,
  3692. MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val2);
  3693. bnx2x_cl45_read(bp, phy,
  3694. MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val1);
  3695. DP(NETIF_MSG_LINK, "807x PCS status 0x%x->0x%x\n", val2, val1);
  3696. /* Clear MSG-OUT */
  3697. bnx2x_cl45_read(bp, phy,
  3698. MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &val1);
  3699. /* Check the LASI */
  3700. bnx2x_cl45_read(bp, phy,
  3701. MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM, &val2);
  3702. DP(NETIF_MSG_LINK, "KR 0x9003 0x%x\n", val2);
  3703. /* Check the link status */
  3704. bnx2x_cl45_read(bp, phy,
  3705. MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val2);
  3706. DP(NETIF_MSG_LINK, "KR PCS status 0x%x\n", val2);
  3707. bnx2x_cl45_read(bp, phy,
  3708. MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
  3709. bnx2x_cl45_read(bp, phy,
  3710. MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
  3711. link_up = ((val1 & 4) == 4);
  3712. DP(NETIF_MSG_LINK, "PMA_REG_STATUS=0x%x\n", val1);
  3713. if (link_up &&
  3714. ((phy->req_line_speed != SPEED_10000))) {
  3715. if (bnx2x_8073_xaui_wa(bp, phy) != 0)
  3716. return 0;
  3717. }
  3718. bnx2x_cl45_read(bp, phy,
  3719. MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &an1000_status);
  3720. bnx2x_cl45_read(bp, phy,
  3721. MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &an1000_status);
  3722. /* Check the link status on 1.1.2 */
  3723. bnx2x_cl45_read(bp, phy,
  3724. MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
  3725. bnx2x_cl45_read(bp, phy,
  3726. MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
  3727. DP(NETIF_MSG_LINK, "KR PMA status 0x%x->0x%x,"
  3728. "an_link_status=0x%x\n", val2, val1, an1000_status);
  3729. link_up = (((val1 & 4) == 4) || (an1000_status & (1<<1)));
  3730. if (link_up && bnx2x_8073_is_snr_needed(bp, phy)) {
  3731. /*
  3732. * The SNR will improve about 2dbby changing the BW and FEE main
  3733. * tap. The 1st write to change FFE main tap is set before
  3734. * restart AN. Change PLL Bandwidth in EDC register
  3735. */
  3736. bnx2x_cl45_write(bp, phy,
  3737. MDIO_PMA_DEVAD, MDIO_PMA_REG_PLL_BANDWIDTH,
  3738. 0x26BC);
  3739. /* Change CDR Bandwidth in EDC register */
  3740. bnx2x_cl45_write(bp, phy,
  3741. MDIO_PMA_DEVAD, MDIO_PMA_REG_CDR_BANDWIDTH,
  3742. 0x0333);
  3743. }
  3744. bnx2x_cl45_read(bp, phy,
  3745. MDIO_PMA_DEVAD, MDIO_PMA_REG_8073_SPEED_LINK_STATUS,
  3746. &link_status);
  3747. /* Bits 0..2 --> speed detected, bits 13..15--> link is down */
  3748. if ((link_status & (1<<2)) && (!(link_status & (1<<15)))) {
  3749. link_up = 1;
  3750. vars->line_speed = SPEED_10000;
  3751. DP(NETIF_MSG_LINK, "port %x: External link up in 10G\n",
  3752. params->port);
  3753. } else if ((link_status & (1<<1)) && (!(link_status & (1<<14)))) {
  3754. link_up = 1;
  3755. vars->line_speed = SPEED_2500;
  3756. DP(NETIF_MSG_LINK, "port %x: External link up in 2.5G\n",
  3757. params->port);
  3758. } else if ((link_status & (1<<0)) && (!(link_status & (1<<13)))) {
  3759. link_up = 1;
  3760. vars->line_speed = SPEED_1000;
  3761. DP(NETIF_MSG_LINK, "port %x: External link up in 1G\n",
  3762. params->port);
  3763. } else {
  3764. link_up = 0;
  3765. DP(NETIF_MSG_LINK, "port %x: External link is down\n",
  3766. params->port);
  3767. }
  3768. if (link_up) {
  3769. /* Swap polarity if required */
  3770. if (params->lane_config &
  3771. PORT_HW_CFG_SWAP_PHY_POLARITY_ENABLED) {
  3772. /* Configure the 8073 to swap P and N of the KR lines */
  3773. bnx2x_cl45_read(bp, phy,
  3774. MDIO_XS_DEVAD,
  3775. MDIO_XS_REG_8073_RX_CTRL_PCIE, &val1);
  3776. /*
  3777. * Set bit 3 to invert Rx in 1G mode and clear this bit
  3778. * when it`s in 10G mode.
  3779. */
  3780. if (vars->line_speed == SPEED_1000) {
  3781. DP(NETIF_MSG_LINK, "Swapping 1G polarity for"
  3782. "the 8073\n");
  3783. val1 |= (1<<3);
  3784. } else
  3785. val1 &= ~(1<<3);
  3786. bnx2x_cl45_write(bp, phy,
  3787. MDIO_XS_DEVAD,
  3788. MDIO_XS_REG_8073_RX_CTRL_PCIE,
  3789. val1);
  3790. }
  3791. bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
  3792. bnx2x_8073_resolve_fc(phy, params, vars);
  3793. vars->duplex = DUPLEX_FULL;
  3794. }
  3795. return link_up;
  3796. }
  3797. static void bnx2x_8073_link_reset(struct bnx2x_phy *phy,
  3798. struct link_params *params)
  3799. {
  3800. struct bnx2x *bp = params->bp;
  3801. u8 gpio_port;
  3802. if (CHIP_IS_E2(bp))
  3803. gpio_port = BP_PATH(bp);
  3804. else
  3805. gpio_port = params->port;
  3806. DP(NETIF_MSG_LINK, "Setting 8073 port %d into low power mode\n",
  3807. gpio_port);
  3808. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
  3809. MISC_REGISTERS_GPIO_OUTPUT_LOW,
  3810. gpio_port);
  3811. }
  3812. /******************************************************************/
  3813. /* BCM8705 PHY SECTION */
  3814. /******************************************************************/
  3815. static u8 bnx2x_8705_config_init(struct bnx2x_phy *phy,
  3816. struct link_params *params,
  3817. struct link_vars *vars)
  3818. {
  3819. struct bnx2x *bp = params->bp;
  3820. DP(NETIF_MSG_LINK, "init 8705\n");
  3821. /* Restore normal power mode*/
  3822. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
  3823. MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
  3824. /* HW reset */
  3825. bnx2x_ext_phy_hw_reset(bp, params->port);
  3826. bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0xa040);
  3827. bnx2x_wait_reset_complete(bp, phy, params);
  3828. bnx2x_cl45_write(bp, phy,
  3829. MDIO_PMA_DEVAD, MDIO_PMA_REG_MISC_CTRL, 0x8288);
  3830. bnx2x_cl45_write(bp, phy,
  3831. MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, 0x7fbf);
  3832. bnx2x_cl45_write(bp, phy,
  3833. MDIO_PMA_DEVAD, MDIO_PMA_REG_CMU_PLL_BYPASS, 0x0100);
  3834. bnx2x_cl45_write(bp, phy,
  3835. MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_CNTL, 0x1);
  3836. /* BCM8705 doesn't have microcode, hence the 0 */
  3837. bnx2x_save_spirom_version(bp, params->port, params->shmem_base, 0);
  3838. return 0;
  3839. }
  3840. static u8 bnx2x_8705_read_status(struct bnx2x_phy *phy,
  3841. struct link_params *params,
  3842. struct link_vars *vars)
  3843. {
  3844. u8 link_up = 0;
  3845. u16 val1, rx_sd;
  3846. struct bnx2x *bp = params->bp;
  3847. DP(NETIF_MSG_LINK, "read status 8705\n");
  3848. bnx2x_cl45_read(bp, phy,
  3849. MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_STATUS, &val1);
  3850. DP(NETIF_MSG_LINK, "8705 LASI status 0x%x\n", val1);
  3851. bnx2x_cl45_read(bp, phy,
  3852. MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_STATUS, &val1);
  3853. DP(NETIF_MSG_LINK, "8705 LASI status 0x%x\n", val1);
  3854. bnx2x_cl45_read(bp, phy,
  3855. MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_SD, &rx_sd);
  3856. bnx2x_cl45_read(bp, phy,
  3857. MDIO_PMA_DEVAD, 0xc809, &val1);
  3858. bnx2x_cl45_read(bp, phy,
  3859. MDIO_PMA_DEVAD, 0xc809, &val1);
  3860. DP(NETIF_MSG_LINK, "8705 1.c809 val=0x%x\n", val1);
  3861. link_up = ((rx_sd & 0x1) && (val1 & (1<<9)) && ((val1 & (1<<8)) == 0));
  3862. if (link_up) {
  3863. vars->line_speed = SPEED_10000;
  3864. bnx2x_ext_phy_resolve_fc(phy, params, vars);
  3865. }
  3866. return link_up;
  3867. }
  3868. /******************************************************************/
  3869. /* SFP+ module Section */
  3870. /******************************************************************/
  3871. static u8 bnx2x_get_gpio_port(struct link_params *params)
  3872. {
  3873. u8 gpio_port;
  3874. u32 swap_val, swap_override;
  3875. struct bnx2x *bp = params->bp;
  3876. if (CHIP_IS_E2(bp))
  3877. gpio_port = BP_PATH(bp);
  3878. else
  3879. gpio_port = params->port;
  3880. swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
  3881. swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
  3882. return gpio_port ^ (swap_val && swap_override);
  3883. }
  3884. static void bnx2x_sfp_set_transmitter(struct link_params *params,
  3885. struct bnx2x_phy *phy,
  3886. u8 tx_en)
  3887. {
  3888. u16 val;
  3889. u8 port = params->port;
  3890. struct bnx2x *bp = params->bp;
  3891. u32 tx_en_mode;
  3892. /* Disable/Enable transmitter ( TX laser of the SFP+ module.)*/
  3893. tx_en_mode = REG_RD(bp, params->shmem_base +
  3894. offsetof(struct shmem_region,
  3895. dev_info.port_hw_config[port].sfp_ctrl)) &
  3896. PORT_HW_CFG_TX_LASER_MASK;
  3897. DP(NETIF_MSG_LINK, "Setting transmitter tx_en=%x for port %x "
  3898. "mode = %x\n", tx_en, port, tx_en_mode);
  3899. switch (tx_en_mode) {
  3900. case PORT_HW_CFG_TX_LASER_MDIO:
  3901. bnx2x_cl45_read(bp, phy,
  3902. MDIO_PMA_DEVAD,
  3903. MDIO_PMA_REG_PHY_IDENTIFIER,
  3904. &val);
  3905. if (tx_en)
  3906. val &= ~(1<<15);
  3907. else
  3908. val |= (1<<15);
  3909. bnx2x_cl45_write(bp, phy,
  3910. MDIO_PMA_DEVAD,
  3911. MDIO_PMA_REG_PHY_IDENTIFIER,
  3912. val);
  3913. break;
  3914. case PORT_HW_CFG_TX_LASER_GPIO0:
  3915. case PORT_HW_CFG_TX_LASER_GPIO1:
  3916. case PORT_HW_CFG_TX_LASER_GPIO2:
  3917. case PORT_HW_CFG_TX_LASER_GPIO3:
  3918. {
  3919. u16 gpio_pin;
  3920. u8 gpio_port, gpio_mode;
  3921. if (tx_en)
  3922. gpio_mode = MISC_REGISTERS_GPIO_OUTPUT_HIGH;
  3923. else
  3924. gpio_mode = MISC_REGISTERS_GPIO_OUTPUT_LOW;
  3925. gpio_pin = tx_en_mode - PORT_HW_CFG_TX_LASER_GPIO0;
  3926. gpio_port = bnx2x_get_gpio_port(params);
  3927. bnx2x_set_gpio(bp, gpio_pin, gpio_mode, gpio_port);
  3928. break;
  3929. }
  3930. default:
  3931. DP(NETIF_MSG_LINK, "Invalid TX_LASER_MDIO 0x%x\n", tx_en_mode);
  3932. break;
  3933. }
  3934. }
  3935. static u8 bnx2x_8726_read_sfp_module_eeprom(struct bnx2x_phy *phy,
  3936. struct link_params *params,
  3937. u16 addr, u8 byte_cnt, u8 *o_buf)
  3938. {
  3939. struct bnx2x *bp = params->bp;
  3940. u16 val = 0;
  3941. u16 i;
  3942. if (byte_cnt > 16) {
  3943. DP(NETIF_MSG_LINK, "Reading from eeprom is"
  3944. " is limited to 0xf\n");
  3945. return -EINVAL;
  3946. }
  3947. /* Set the read command byte count */
  3948. bnx2x_cl45_write(bp, phy,
  3949. MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_BYTE_CNT,
  3950. (byte_cnt | 0xa000));
  3951. /* Set the read command address */
  3952. bnx2x_cl45_write(bp, phy,
  3953. MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_MEM_ADDR,
  3954. addr);
  3955. /* Activate read command */
  3956. bnx2x_cl45_write(bp, phy,
  3957. MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
  3958. 0x2c0f);
  3959. /* Wait up to 500us for command complete status */
  3960. for (i = 0; i < 100; i++) {
  3961. bnx2x_cl45_read(bp, phy,
  3962. MDIO_PMA_DEVAD,
  3963. MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
  3964. if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
  3965. MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE)
  3966. break;
  3967. udelay(5);
  3968. }
  3969. if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) !=
  3970. MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE) {
  3971. DP(NETIF_MSG_LINK,
  3972. "Got bad status 0x%x when reading from SFP+ EEPROM\n",
  3973. (val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK));
  3974. return -EINVAL;
  3975. }
  3976. /* Read the buffer */
  3977. for (i = 0; i < byte_cnt; i++) {
  3978. bnx2x_cl45_read(bp, phy,
  3979. MDIO_PMA_DEVAD,
  3980. MDIO_PMA_REG_8726_TWO_WIRE_DATA_BUF + i, &val);
  3981. o_buf[i] = (u8)(val & MDIO_PMA_REG_8726_TWO_WIRE_DATA_MASK);
  3982. }
  3983. for (i = 0; i < 100; i++) {
  3984. bnx2x_cl45_read(bp, phy,
  3985. MDIO_PMA_DEVAD,
  3986. MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
  3987. if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
  3988. MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_IDLE)
  3989. return 0;
  3990. msleep(1);
  3991. }
  3992. return -EINVAL;
  3993. }
  3994. static u8 bnx2x_8727_read_sfp_module_eeprom(struct bnx2x_phy *phy,
  3995. struct link_params *params,
  3996. u16 addr, u8 byte_cnt, u8 *o_buf)
  3997. {
  3998. struct bnx2x *bp = params->bp;
  3999. u16 val, i;
  4000. if (byte_cnt > 16) {
  4001. DP(NETIF_MSG_LINK, "Reading from eeprom is"
  4002. " is limited to 0xf\n");
  4003. return -EINVAL;
  4004. }
  4005. /* Need to read from 1.8000 to clear it */
  4006. bnx2x_cl45_read(bp, phy,
  4007. MDIO_PMA_DEVAD,
  4008. MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
  4009. &val);
  4010. /* Set the read command byte count */
  4011. bnx2x_cl45_write(bp, phy,
  4012. MDIO_PMA_DEVAD,
  4013. MDIO_PMA_REG_SFP_TWO_WIRE_BYTE_CNT,
  4014. ((byte_cnt < 2) ? 2 : byte_cnt));
  4015. /* Set the read command address */
  4016. bnx2x_cl45_write(bp, phy,
  4017. MDIO_PMA_DEVAD,
  4018. MDIO_PMA_REG_SFP_TWO_WIRE_MEM_ADDR,
  4019. addr);
  4020. /* Set the destination address */
  4021. bnx2x_cl45_write(bp, phy,
  4022. MDIO_PMA_DEVAD,
  4023. 0x8004,
  4024. MDIO_PMA_REG_8727_TWO_WIRE_DATA_BUF);
  4025. /* Activate read command */
  4026. bnx2x_cl45_write(bp, phy,
  4027. MDIO_PMA_DEVAD,
  4028. MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
  4029. 0x8002);
  4030. /*
  4031. * Wait appropriate time for two-wire command to finish before
  4032. * polling the status register
  4033. */
  4034. msleep(1);
  4035. /* Wait up to 500us for command complete status */
  4036. for (i = 0; i < 100; i++) {
  4037. bnx2x_cl45_read(bp, phy,
  4038. MDIO_PMA_DEVAD,
  4039. MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
  4040. if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
  4041. MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE)
  4042. break;
  4043. udelay(5);
  4044. }
  4045. if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) !=
  4046. MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE) {
  4047. DP(NETIF_MSG_LINK,
  4048. "Got bad status 0x%x when reading from SFP+ EEPROM\n",
  4049. (val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK));
  4050. return -EFAULT;
  4051. }
  4052. /* Read the buffer */
  4053. for (i = 0; i < byte_cnt; i++) {
  4054. bnx2x_cl45_read(bp, phy,
  4055. MDIO_PMA_DEVAD,
  4056. MDIO_PMA_REG_8727_TWO_WIRE_DATA_BUF + i, &val);
  4057. o_buf[i] = (u8)(val & MDIO_PMA_REG_8727_TWO_WIRE_DATA_MASK);
  4058. }
  4059. for (i = 0; i < 100; i++) {
  4060. bnx2x_cl45_read(bp, phy,
  4061. MDIO_PMA_DEVAD,
  4062. MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
  4063. if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
  4064. MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_IDLE)
  4065. return 0;
  4066. msleep(1);
  4067. }
  4068. return -EINVAL;
  4069. }
  4070. u8 bnx2x_read_sfp_module_eeprom(struct bnx2x_phy *phy,
  4071. struct link_params *params, u16 addr,
  4072. u8 byte_cnt, u8 *o_buf)
  4073. {
  4074. if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726)
  4075. return bnx2x_8726_read_sfp_module_eeprom(phy, params, addr,
  4076. byte_cnt, o_buf);
  4077. else if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727)
  4078. return bnx2x_8727_read_sfp_module_eeprom(phy, params, addr,
  4079. byte_cnt, o_buf);
  4080. return -EINVAL;
  4081. }
  4082. static u8 bnx2x_get_edc_mode(struct bnx2x_phy *phy,
  4083. struct link_params *params,
  4084. u16 *edc_mode)
  4085. {
  4086. struct bnx2x *bp = params->bp;
  4087. u8 val, check_limiting_mode = 0;
  4088. *edc_mode = EDC_MODE_LIMITING;
  4089. /* First check for copper cable */
  4090. if (bnx2x_read_sfp_module_eeprom(phy,
  4091. params,
  4092. SFP_EEPROM_CON_TYPE_ADDR,
  4093. 1,
  4094. &val) != 0) {
  4095. DP(NETIF_MSG_LINK, "Failed to read from SFP+ module EEPROM\n");
  4096. return -EINVAL;
  4097. }
  4098. switch (val) {
  4099. case SFP_EEPROM_CON_TYPE_VAL_COPPER:
  4100. {
  4101. u8 copper_module_type;
  4102. /*
  4103. * Check if its active cable (includes SFP+ module)
  4104. * of passive cable
  4105. */
  4106. if (bnx2x_read_sfp_module_eeprom(phy,
  4107. params,
  4108. SFP_EEPROM_FC_TX_TECH_ADDR,
  4109. 1,
  4110. &copper_module_type) !=
  4111. 0) {
  4112. DP(NETIF_MSG_LINK,
  4113. "Failed to read copper-cable-type"
  4114. " from SFP+ EEPROM\n");
  4115. return -EINVAL;
  4116. }
  4117. if (copper_module_type &
  4118. SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_ACTIVE) {
  4119. DP(NETIF_MSG_LINK, "Active Copper cable detected\n");
  4120. check_limiting_mode = 1;
  4121. } else if (copper_module_type &
  4122. SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_PASSIVE) {
  4123. DP(NETIF_MSG_LINK, "Passive Copper"
  4124. " cable detected\n");
  4125. *edc_mode =
  4126. EDC_MODE_PASSIVE_DAC;
  4127. } else {
  4128. DP(NETIF_MSG_LINK, "Unknown copper-cable-"
  4129. "type 0x%x !!!\n", copper_module_type);
  4130. return -EINVAL;
  4131. }
  4132. break;
  4133. }
  4134. case SFP_EEPROM_CON_TYPE_VAL_LC:
  4135. DP(NETIF_MSG_LINK, "Optic module detected\n");
  4136. check_limiting_mode = 1;
  4137. break;
  4138. default:
  4139. DP(NETIF_MSG_LINK, "Unable to determine module type 0x%x !!!\n",
  4140. val);
  4141. return -EINVAL;
  4142. }
  4143. if (check_limiting_mode) {
  4144. u8 options[SFP_EEPROM_OPTIONS_SIZE];
  4145. if (bnx2x_read_sfp_module_eeprom(phy,
  4146. params,
  4147. SFP_EEPROM_OPTIONS_ADDR,
  4148. SFP_EEPROM_OPTIONS_SIZE,
  4149. options) != 0) {
  4150. DP(NETIF_MSG_LINK, "Failed to read Option"
  4151. " field from module EEPROM\n");
  4152. return -EINVAL;
  4153. }
  4154. if ((options[0] & SFP_EEPROM_OPTIONS_LINEAR_RX_OUT_MASK))
  4155. *edc_mode = EDC_MODE_LINEAR;
  4156. else
  4157. *edc_mode = EDC_MODE_LIMITING;
  4158. }
  4159. DP(NETIF_MSG_LINK, "EDC mode is set to 0x%x\n", *edc_mode);
  4160. return 0;
  4161. }
  4162. /*
  4163. * This function read the relevant field from the module (SFP+), and verify it
  4164. * is compliant with this board
  4165. */
  4166. static u8 bnx2x_verify_sfp_module(struct bnx2x_phy *phy,
  4167. struct link_params *params)
  4168. {
  4169. struct bnx2x *bp = params->bp;
  4170. u32 val, cmd;
  4171. u32 fw_resp, fw_cmd_param;
  4172. char vendor_name[SFP_EEPROM_VENDOR_NAME_SIZE+1];
  4173. char vendor_pn[SFP_EEPROM_PART_NO_SIZE+1];
  4174. phy->flags &= ~FLAGS_SFP_NOT_APPROVED;
  4175. val = REG_RD(bp, params->shmem_base +
  4176. offsetof(struct shmem_region, dev_info.
  4177. port_feature_config[params->port].config));
  4178. if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
  4179. PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_NO_ENFORCEMENT) {
  4180. DP(NETIF_MSG_LINK, "NOT enforcing module verification\n");
  4181. return 0;
  4182. }
  4183. if (params->feature_config_flags &
  4184. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY) {
  4185. /* Use specific phy request */
  4186. cmd = DRV_MSG_CODE_VRFY_SPECIFIC_PHY_OPT_MDL;
  4187. } else if (params->feature_config_flags &
  4188. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY) {
  4189. /* Use first phy request only in case of non-dual media*/
  4190. if (DUAL_MEDIA(params)) {
  4191. DP(NETIF_MSG_LINK, "FW does not support OPT MDL "
  4192. "verification\n");
  4193. return -EINVAL;
  4194. }
  4195. cmd = DRV_MSG_CODE_VRFY_FIRST_PHY_OPT_MDL;
  4196. } else {
  4197. /* No support in OPT MDL detection */
  4198. DP(NETIF_MSG_LINK, "FW does not support OPT MDL "
  4199. "verification\n");
  4200. return -EINVAL;
  4201. }
  4202. fw_cmd_param = FW_PARAM_SET(phy->addr, phy->type, phy->mdio_ctrl);
  4203. fw_resp = bnx2x_fw_command(bp, cmd, fw_cmd_param);
  4204. if (fw_resp == FW_MSG_CODE_VRFY_OPT_MDL_SUCCESS) {
  4205. DP(NETIF_MSG_LINK, "Approved module\n");
  4206. return 0;
  4207. }
  4208. /* format the warning message */
  4209. if (bnx2x_read_sfp_module_eeprom(phy,
  4210. params,
  4211. SFP_EEPROM_VENDOR_NAME_ADDR,
  4212. SFP_EEPROM_VENDOR_NAME_SIZE,
  4213. (u8 *)vendor_name))
  4214. vendor_name[0] = '\0';
  4215. else
  4216. vendor_name[SFP_EEPROM_VENDOR_NAME_SIZE] = '\0';
  4217. if (bnx2x_read_sfp_module_eeprom(phy,
  4218. params,
  4219. SFP_EEPROM_PART_NO_ADDR,
  4220. SFP_EEPROM_PART_NO_SIZE,
  4221. (u8 *)vendor_pn))
  4222. vendor_pn[0] = '\0';
  4223. else
  4224. vendor_pn[SFP_EEPROM_PART_NO_SIZE] = '\0';
  4225. netdev_err(bp->dev, "Warning: Unqualified SFP+ module detected,"
  4226. " Port %d from %s part number %s\n",
  4227. params->port, vendor_name, vendor_pn);
  4228. phy->flags |= FLAGS_SFP_NOT_APPROVED;
  4229. return -EINVAL;
  4230. }
  4231. static u8 bnx2x_wait_for_sfp_module_initialized(struct bnx2x_phy *phy,
  4232. struct link_params *params)
  4233. {
  4234. u8 val;
  4235. struct bnx2x *bp = params->bp;
  4236. u16 timeout;
  4237. /*
  4238. * Initialization time after hot-plug may take up to 300ms for
  4239. * some phys type ( e.g. JDSU )
  4240. */
  4241. for (timeout = 0; timeout < 60; timeout++) {
  4242. if (bnx2x_read_sfp_module_eeprom(phy, params, 1, 1, &val)
  4243. == 0) {
  4244. DP(NETIF_MSG_LINK, "SFP+ module initialization "
  4245. "took %d ms\n", timeout * 5);
  4246. return 0;
  4247. }
  4248. msleep(5);
  4249. }
  4250. return -EINVAL;
  4251. }
  4252. static void bnx2x_8727_power_module(struct bnx2x *bp,
  4253. struct bnx2x_phy *phy,
  4254. u8 is_power_up) {
  4255. /* Make sure GPIOs are not using for LED mode */
  4256. u16 val;
  4257. /*
  4258. * In the GPIO register, bit 4 is use to determine if the GPIOs are
  4259. * operating as INPUT or as OUTPUT. Bit 1 is for input, and 0 for
  4260. * output
  4261. * Bits 0-1 determine the gpios value for OUTPUT in case bit 4 val is 0
  4262. * Bits 8-9 determine the gpios value for INPUT in case bit 4 val is 1
  4263. * where the 1st bit is the over-current(only input), and 2nd bit is
  4264. * for power( only output )
  4265. *
  4266. * In case of NOC feature is disabled and power is up, set GPIO control
  4267. * as input to enable listening of over-current indication
  4268. */
  4269. if (phy->flags & FLAGS_NOC)
  4270. return;
  4271. if (!(phy->flags &
  4272. FLAGS_NOC) && is_power_up)
  4273. val = (1<<4);
  4274. else
  4275. /*
  4276. * Set GPIO control to OUTPUT, and set the power bit
  4277. * to according to the is_power_up
  4278. */
  4279. val = ((!(is_power_up)) << 1);
  4280. bnx2x_cl45_write(bp, phy,
  4281. MDIO_PMA_DEVAD,
  4282. MDIO_PMA_REG_8727_GPIO_CTRL,
  4283. val);
  4284. }
  4285. static u8 bnx2x_8726_set_limiting_mode(struct bnx2x *bp,
  4286. struct bnx2x_phy *phy,
  4287. u16 edc_mode)
  4288. {
  4289. u16 cur_limiting_mode;
  4290. bnx2x_cl45_read(bp, phy,
  4291. MDIO_PMA_DEVAD,
  4292. MDIO_PMA_REG_ROM_VER2,
  4293. &cur_limiting_mode);
  4294. DP(NETIF_MSG_LINK, "Current Limiting mode is 0x%x\n",
  4295. cur_limiting_mode);
  4296. if (edc_mode == EDC_MODE_LIMITING) {
  4297. DP(NETIF_MSG_LINK, "Setting LIMITING MODE\n");
  4298. bnx2x_cl45_write(bp, phy,
  4299. MDIO_PMA_DEVAD,
  4300. MDIO_PMA_REG_ROM_VER2,
  4301. EDC_MODE_LIMITING);
  4302. } else { /* LRM mode ( default )*/
  4303. DP(NETIF_MSG_LINK, "Setting LRM MODE\n");
  4304. /*
  4305. * Changing to LRM mode takes quite few seconds. So do it only
  4306. * if current mode is limiting (default is LRM)
  4307. */
  4308. if (cur_limiting_mode != EDC_MODE_LIMITING)
  4309. return 0;
  4310. bnx2x_cl45_write(bp, phy,
  4311. MDIO_PMA_DEVAD,
  4312. MDIO_PMA_REG_LRM_MODE,
  4313. 0);
  4314. bnx2x_cl45_write(bp, phy,
  4315. MDIO_PMA_DEVAD,
  4316. MDIO_PMA_REG_ROM_VER2,
  4317. 0x128);
  4318. bnx2x_cl45_write(bp, phy,
  4319. MDIO_PMA_DEVAD,
  4320. MDIO_PMA_REG_MISC_CTRL0,
  4321. 0x4008);
  4322. bnx2x_cl45_write(bp, phy,
  4323. MDIO_PMA_DEVAD,
  4324. MDIO_PMA_REG_LRM_MODE,
  4325. 0xaaaa);
  4326. }
  4327. return 0;
  4328. }
  4329. static u8 bnx2x_8727_set_limiting_mode(struct bnx2x *bp,
  4330. struct bnx2x_phy *phy,
  4331. u16 edc_mode)
  4332. {
  4333. u16 phy_identifier;
  4334. u16 rom_ver2_val;
  4335. bnx2x_cl45_read(bp, phy,
  4336. MDIO_PMA_DEVAD,
  4337. MDIO_PMA_REG_PHY_IDENTIFIER,
  4338. &phy_identifier);
  4339. bnx2x_cl45_write(bp, phy,
  4340. MDIO_PMA_DEVAD,
  4341. MDIO_PMA_REG_PHY_IDENTIFIER,
  4342. (phy_identifier & ~(1<<9)));
  4343. bnx2x_cl45_read(bp, phy,
  4344. MDIO_PMA_DEVAD,
  4345. MDIO_PMA_REG_ROM_VER2,
  4346. &rom_ver2_val);
  4347. /* Keep the MSB 8-bits, and set the LSB 8-bits with the edc_mode */
  4348. bnx2x_cl45_write(bp, phy,
  4349. MDIO_PMA_DEVAD,
  4350. MDIO_PMA_REG_ROM_VER2,
  4351. (rom_ver2_val & 0xff00) | (edc_mode & 0x00ff));
  4352. bnx2x_cl45_write(bp, phy,
  4353. MDIO_PMA_DEVAD,
  4354. MDIO_PMA_REG_PHY_IDENTIFIER,
  4355. (phy_identifier | (1<<9)));
  4356. return 0;
  4357. }
  4358. static void bnx2x_8727_specific_func(struct bnx2x_phy *phy,
  4359. struct link_params *params,
  4360. u32 action)
  4361. {
  4362. struct bnx2x *bp = params->bp;
  4363. switch (action) {
  4364. case DISABLE_TX:
  4365. bnx2x_sfp_set_transmitter(params, phy, 0);
  4366. break;
  4367. case ENABLE_TX:
  4368. if (!(phy->flags & FLAGS_SFP_NOT_APPROVED))
  4369. bnx2x_sfp_set_transmitter(params, phy, 1);
  4370. break;
  4371. default:
  4372. DP(NETIF_MSG_LINK, "Function 0x%x not supported by 8727\n",
  4373. action);
  4374. return;
  4375. }
  4376. }
  4377. static void bnx2x_set_sfp_module_fault_led(struct link_params *params,
  4378. u8 gpio_mode)
  4379. {
  4380. struct bnx2x *bp = params->bp;
  4381. u32 fault_led_gpio = REG_RD(bp, params->shmem_base +
  4382. offsetof(struct shmem_region,
  4383. dev_info.port_hw_config[params->port].sfp_ctrl)) &
  4384. PORT_HW_CFG_FAULT_MODULE_LED_MASK;
  4385. switch (fault_led_gpio) {
  4386. case PORT_HW_CFG_FAULT_MODULE_LED_DISABLED:
  4387. return;
  4388. case PORT_HW_CFG_FAULT_MODULE_LED_GPIO0:
  4389. case PORT_HW_CFG_FAULT_MODULE_LED_GPIO1:
  4390. case PORT_HW_CFG_FAULT_MODULE_LED_GPIO2:
  4391. case PORT_HW_CFG_FAULT_MODULE_LED_GPIO3:
  4392. {
  4393. u8 gpio_port = bnx2x_get_gpio_port(params);
  4394. u16 gpio_pin = fault_led_gpio -
  4395. PORT_HW_CFG_FAULT_MODULE_LED_GPIO0;
  4396. DP(NETIF_MSG_LINK, "Set fault module-detected led "
  4397. "pin %x port %x mode %x\n",
  4398. gpio_pin, gpio_port, gpio_mode);
  4399. bnx2x_set_gpio(bp, gpio_pin, gpio_mode, gpio_port);
  4400. }
  4401. break;
  4402. default:
  4403. DP(NETIF_MSG_LINK, "Error: Invalid fault led mode 0x%x\n",
  4404. fault_led_gpio);
  4405. }
  4406. }
  4407. static u8 bnx2x_sfp_module_detection(struct bnx2x_phy *phy,
  4408. struct link_params *params)
  4409. {
  4410. struct bnx2x *bp = params->bp;
  4411. u16 edc_mode;
  4412. u8 rc = 0;
  4413. u32 val = REG_RD(bp, params->shmem_base +
  4414. offsetof(struct shmem_region, dev_info.
  4415. port_feature_config[params->port].config));
  4416. DP(NETIF_MSG_LINK, "SFP+ module plugged in/out detected on port %d\n",
  4417. params->port);
  4418. if (bnx2x_get_edc_mode(phy, params, &edc_mode) != 0) {
  4419. DP(NETIF_MSG_LINK, "Failed to get valid module type\n");
  4420. return -EINVAL;
  4421. } else if (bnx2x_verify_sfp_module(phy, params) != 0) {
  4422. /* check SFP+ module compatibility */
  4423. DP(NETIF_MSG_LINK, "Module verification failed!!\n");
  4424. rc = -EINVAL;
  4425. /* Turn on fault module-detected led */
  4426. bnx2x_set_sfp_module_fault_led(params,
  4427. MISC_REGISTERS_GPIO_HIGH);
  4428. if ((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727) &&
  4429. ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
  4430. PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_POWER_DOWN)) {
  4431. /* Shutdown SFP+ module */
  4432. DP(NETIF_MSG_LINK, "Shutdown SFP+ module!!\n");
  4433. bnx2x_8727_power_module(bp, phy, 0);
  4434. return rc;
  4435. }
  4436. } else {
  4437. /* Turn off fault module-detected led */
  4438. bnx2x_set_sfp_module_fault_led(params, MISC_REGISTERS_GPIO_LOW);
  4439. }
  4440. /* power up the SFP module */
  4441. if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727)
  4442. bnx2x_8727_power_module(bp, phy, 1);
  4443. /*
  4444. * Check and set limiting mode / LRM mode on 8726. On 8727 it
  4445. * is done automatically
  4446. */
  4447. if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726)
  4448. bnx2x_8726_set_limiting_mode(bp, phy, edc_mode);
  4449. else
  4450. bnx2x_8727_set_limiting_mode(bp, phy, edc_mode);
  4451. /*
  4452. * Enable transmit for this module if the module is approved, or
  4453. * if unapproved modules should also enable the Tx laser
  4454. */
  4455. if (rc == 0 ||
  4456. (val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) !=
  4457. PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER)
  4458. bnx2x_sfp_set_transmitter(params, phy, 1);
  4459. else
  4460. bnx2x_sfp_set_transmitter(params, phy, 0);
  4461. return rc;
  4462. }
  4463. void bnx2x_handle_module_detect_int(struct link_params *params)
  4464. {
  4465. struct bnx2x *bp = params->bp;
  4466. struct bnx2x_phy *phy = &params->phy[EXT_PHY1];
  4467. u32 gpio_val;
  4468. u8 port = params->port;
  4469. /* Set valid module led off */
  4470. bnx2x_set_sfp_module_fault_led(params, MISC_REGISTERS_GPIO_HIGH);
  4471. /* Get current gpio val reflecting module plugged in / out*/
  4472. gpio_val = bnx2x_get_gpio(bp, MISC_REGISTERS_GPIO_3, port);
  4473. /* Call the handling function in case module is detected */
  4474. if (gpio_val == 0) {
  4475. bnx2x_set_gpio_int(bp, MISC_REGISTERS_GPIO_3,
  4476. MISC_REGISTERS_GPIO_INT_OUTPUT_CLR,
  4477. port);
  4478. if (bnx2x_wait_for_sfp_module_initialized(phy, params) == 0)
  4479. bnx2x_sfp_module_detection(phy, params);
  4480. else
  4481. DP(NETIF_MSG_LINK, "SFP+ module is not initialized\n");
  4482. } else {
  4483. u32 val = REG_RD(bp, params->shmem_base +
  4484. offsetof(struct shmem_region, dev_info.
  4485. port_feature_config[params->port].
  4486. config));
  4487. bnx2x_set_gpio_int(bp, MISC_REGISTERS_GPIO_3,
  4488. MISC_REGISTERS_GPIO_INT_OUTPUT_SET,
  4489. port);
  4490. /*
  4491. * Module was plugged out.
  4492. * Disable transmit for this module
  4493. */
  4494. if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
  4495. PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER)
  4496. bnx2x_sfp_set_transmitter(params, phy, 0);
  4497. }
  4498. }
  4499. /******************************************************************/
  4500. /* common BCM8706/BCM8726 PHY SECTION */
  4501. /******************************************************************/
  4502. static u8 bnx2x_8706_8726_read_status(struct bnx2x_phy *phy,
  4503. struct link_params *params,
  4504. struct link_vars *vars)
  4505. {
  4506. u8 link_up = 0;
  4507. u16 val1, val2, rx_sd, pcs_status;
  4508. struct bnx2x *bp = params->bp;
  4509. DP(NETIF_MSG_LINK, "XGXS 8706/8726\n");
  4510. /* Clear RX Alarm*/
  4511. bnx2x_cl45_read(bp, phy,
  4512. MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM, &val2);
  4513. /* clear LASI indication*/
  4514. bnx2x_cl45_read(bp, phy,
  4515. MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS, &val1);
  4516. bnx2x_cl45_read(bp, phy,
  4517. MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS, &val2);
  4518. DP(NETIF_MSG_LINK, "8706/8726 LASI status 0x%x--> 0x%x\n", val1, val2);
  4519. bnx2x_cl45_read(bp, phy,
  4520. MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_SD, &rx_sd);
  4521. bnx2x_cl45_read(bp, phy,
  4522. MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &pcs_status);
  4523. bnx2x_cl45_read(bp, phy,
  4524. MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &val2);
  4525. bnx2x_cl45_read(bp, phy,
  4526. MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &val2);
  4527. DP(NETIF_MSG_LINK, "8706/8726 rx_sd 0x%x pcs_status 0x%x 1Gbps"
  4528. " link_status 0x%x\n", rx_sd, pcs_status, val2);
  4529. /*
  4530. * link is up if both bit 0 of pmd_rx_sd and bit 0 of pcs_status
  4531. * are set, or if the autoneg bit 1 is set
  4532. */
  4533. link_up = ((rx_sd & pcs_status & 0x1) || (val2 & (1<<1)));
  4534. if (link_up) {
  4535. if (val2 & (1<<1))
  4536. vars->line_speed = SPEED_1000;
  4537. else
  4538. vars->line_speed = SPEED_10000;
  4539. bnx2x_ext_phy_resolve_fc(phy, params, vars);
  4540. vars->duplex = DUPLEX_FULL;
  4541. }
  4542. return link_up;
  4543. }
  4544. /******************************************************************/
  4545. /* BCM8706 PHY SECTION */
  4546. /******************************************************************/
  4547. static u8 bnx2x_8706_config_init(struct bnx2x_phy *phy,
  4548. struct link_params *params,
  4549. struct link_vars *vars)
  4550. {
  4551. u32 tx_en_mode;
  4552. u16 cnt, val, tmp1;
  4553. struct bnx2x *bp = params->bp;
  4554. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
  4555. MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
  4556. /* HW reset */
  4557. bnx2x_ext_phy_hw_reset(bp, params->port);
  4558. bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0xa040);
  4559. bnx2x_wait_reset_complete(bp, phy, params);
  4560. /* Wait until fw is loaded */
  4561. for (cnt = 0; cnt < 100; cnt++) {
  4562. bnx2x_cl45_read(bp, phy,
  4563. MDIO_PMA_DEVAD, MDIO_PMA_REG_ROM_VER1, &val);
  4564. if (val)
  4565. break;
  4566. msleep(10);
  4567. }
  4568. DP(NETIF_MSG_LINK, "XGXS 8706 is initialized after %d ms\n", cnt);
  4569. if ((params->feature_config_flags &
  4570. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
  4571. u8 i;
  4572. u16 reg;
  4573. for (i = 0; i < 4; i++) {
  4574. reg = MDIO_XS_8706_REG_BANK_RX0 +
  4575. i*(MDIO_XS_8706_REG_BANK_RX1 -
  4576. MDIO_XS_8706_REG_BANK_RX0);
  4577. bnx2x_cl45_read(bp, phy, MDIO_XS_DEVAD, reg, &val);
  4578. /* Clear first 3 bits of the control */
  4579. val &= ~0x7;
  4580. /* Set control bits according to configuration */
  4581. val |= (phy->rx_preemphasis[i] & 0x7);
  4582. DP(NETIF_MSG_LINK, "Setting RX Equalizer to BCM8706"
  4583. " reg 0x%x <-- val 0x%x\n", reg, val);
  4584. bnx2x_cl45_write(bp, phy, MDIO_XS_DEVAD, reg, val);
  4585. }
  4586. }
  4587. /* Force speed */
  4588. if (phy->req_line_speed == SPEED_10000) {
  4589. DP(NETIF_MSG_LINK, "XGXS 8706 force 10Gbps\n");
  4590. bnx2x_cl45_write(bp, phy,
  4591. MDIO_PMA_DEVAD,
  4592. MDIO_PMA_REG_DIGITAL_CTRL, 0x400);
  4593. bnx2x_cl45_write(bp, phy,
  4594. MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 1);
  4595. } else {
  4596. /* Force 1Gbps using autoneg with 1G advertisement */
  4597. /* Allow CL37 through CL73 */
  4598. DP(NETIF_MSG_LINK, "XGXS 8706 AutoNeg\n");
  4599. bnx2x_cl45_write(bp, phy,
  4600. MDIO_AN_DEVAD, MDIO_AN_REG_CL37_CL73, 0x040c);
  4601. /* Enable Full-Duplex advertisement on CL37 */
  4602. bnx2x_cl45_write(bp, phy,
  4603. MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LP, 0x0020);
  4604. /* Enable CL37 AN */
  4605. bnx2x_cl45_write(bp, phy,
  4606. MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
  4607. /* 1G support */
  4608. bnx2x_cl45_write(bp, phy,
  4609. MDIO_AN_DEVAD, MDIO_AN_REG_ADV, (1<<5));
  4610. /* Enable clause 73 AN */
  4611. bnx2x_cl45_write(bp, phy,
  4612. MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
  4613. bnx2x_cl45_write(bp, phy,
  4614. MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM_CTRL,
  4615. 0x0400);
  4616. bnx2x_cl45_write(bp, phy,
  4617. MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL,
  4618. 0x0004);
  4619. }
  4620. bnx2x_save_bcm_spirom_ver(bp, phy, params->port);
  4621. /*
  4622. * If TX Laser is controlled by GPIO_0, do not let PHY go into low
  4623. * power mode, if TX Laser is disabled
  4624. */
  4625. tx_en_mode = REG_RD(bp, params->shmem_base +
  4626. offsetof(struct shmem_region,
  4627. dev_info.port_hw_config[params->port].sfp_ctrl))
  4628. & PORT_HW_CFG_TX_LASER_MASK;
  4629. if (tx_en_mode == PORT_HW_CFG_TX_LASER_GPIO0) {
  4630. DP(NETIF_MSG_LINK, "Enabling TXONOFF_PWRDN_DIS\n");
  4631. bnx2x_cl45_read(bp, phy,
  4632. MDIO_PMA_DEVAD, MDIO_PMA_REG_DIGITAL_CTRL, &tmp1);
  4633. tmp1 |= 0x1;
  4634. bnx2x_cl45_write(bp, phy,
  4635. MDIO_PMA_DEVAD, MDIO_PMA_REG_DIGITAL_CTRL, tmp1);
  4636. }
  4637. return 0;
  4638. }
  4639. static u8 bnx2x_8706_read_status(struct bnx2x_phy *phy,
  4640. struct link_params *params,
  4641. struct link_vars *vars)
  4642. {
  4643. return bnx2x_8706_8726_read_status(phy, params, vars);
  4644. }
  4645. /******************************************************************/
  4646. /* BCM8726 PHY SECTION */
  4647. /******************************************************************/
  4648. static void bnx2x_8726_config_loopback(struct bnx2x_phy *phy,
  4649. struct link_params *params)
  4650. {
  4651. struct bnx2x *bp = params->bp;
  4652. DP(NETIF_MSG_LINK, "PMA/PMD ext_phy_loopback: 8726\n");
  4653. bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x0001);
  4654. }
  4655. static void bnx2x_8726_external_rom_boot(struct bnx2x_phy *phy,
  4656. struct link_params *params)
  4657. {
  4658. struct bnx2x *bp = params->bp;
  4659. /* Need to wait 100ms after reset */
  4660. msleep(100);
  4661. /* Micro controller re-boot */
  4662. bnx2x_cl45_write(bp, phy,
  4663. MDIO_PMA_DEVAD, MDIO_PMA_REG_GEN_CTRL, 0x018B);
  4664. /* Set soft reset */
  4665. bnx2x_cl45_write(bp, phy,
  4666. MDIO_PMA_DEVAD,
  4667. MDIO_PMA_REG_GEN_CTRL,
  4668. MDIO_PMA_REG_GEN_CTRL_ROM_MICRO_RESET);
  4669. bnx2x_cl45_write(bp, phy,
  4670. MDIO_PMA_DEVAD,
  4671. MDIO_PMA_REG_MISC_CTRL1, 0x0001);
  4672. bnx2x_cl45_write(bp, phy,
  4673. MDIO_PMA_DEVAD,
  4674. MDIO_PMA_REG_GEN_CTRL,
  4675. MDIO_PMA_REG_GEN_CTRL_ROM_RESET_INTERNAL_MP);
  4676. /* wait for 150ms for microcode load */
  4677. msleep(150);
  4678. /* Disable serial boot control, tristates pins SS_N, SCK, MOSI, MISO */
  4679. bnx2x_cl45_write(bp, phy,
  4680. MDIO_PMA_DEVAD,
  4681. MDIO_PMA_REG_MISC_CTRL1, 0x0000);
  4682. msleep(200);
  4683. bnx2x_save_bcm_spirom_ver(bp, phy, params->port);
  4684. }
  4685. static u8 bnx2x_8726_read_status(struct bnx2x_phy *phy,
  4686. struct link_params *params,
  4687. struct link_vars *vars)
  4688. {
  4689. struct bnx2x *bp = params->bp;
  4690. u16 val1;
  4691. u8 link_up = bnx2x_8706_8726_read_status(phy, params, vars);
  4692. if (link_up) {
  4693. bnx2x_cl45_read(bp, phy,
  4694. MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER,
  4695. &val1);
  4696. if (val1 & (1<<15)) {
  4697. DP(NETIF_MSG_LINK, "Tx is disabled\n");
  4698. link_up = 0;
  4699. vars->line_speed = 0;
  4700. }
  4701. }
  4702. return link_up;
  4703. }
  4704. static u8 bnx2x_8726_config_init(struct bnx2x_phy *phy,
  4705. struct link_params *params,
  4706. struct link_vars *vars)
  4707. {
  4708. struct bnx2x *bp = params->bp;
  4709. u32 val;
  4710. u32 swap_val, swap_override, aeu_gpio_mask, offset;
  4711. DP(NETIF_MSG_LINK, "Initializing BCM8726\n");
  4712. bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
  4713. bnx2x_wait_reset_complete(bp, phy, params);
  4714. bnx2x_8726_external_rom_boot(phy, params);
  4715. /*
  4716. * Need to call module detected on initialization since the module
  4717. * detection triggered by actual module insertion might occur before
  4718. * driver is loaded, and when driver is loaded, it reset all
  4719. * registers, including the transmitter
  4720. */
  4721. bnx2x_sfp_module_detection(phy, params);
  4722. if (phy->req_line_speed == SPEED_1000) {
  4723. DP(NETIF_MSG_LINK, "Setting 1G force\n");
  4724. bnx2x_cl45_write(bp, phy,
  4725. MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x40);
  4726. bnx2x_cl45_write(bp, phy,
  4727. MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0xD);
  4728. bnx2x_cl45_write(bp, phy,
  4729. MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 0x5);
  4730. bnx2x_cl45_write(bp, phy,
  4731. MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM_CTRL,
  4732. 0x400);
  4733. } else if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
  4734. (phy->speed_cap_mask &
  4735. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G) &&
  4736. ((phy->speed_cap_mask &
  4737. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) !=
  4738. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
  4739. DP(NETIF_MSG_LINK, "Setting 1G clause37\n");
  4740. /* Set Flow control */
  4741. bnx2x_ext_phy_set_pause(params, phy, vars);
  4742. bnx2x_cl45_write(bp, phy,
  4743. MDIO_AN_DEVAD, MDIO_AN_REG_ADV, 0x20);
  4744. bnx2x_cl45_write(bp, phy,
  4745. MDIO_AN_DEVAD, MDIO_AN_REG_CL37_CL73, 0x040c);
  4746. bnx2x_cl45_write(bp, phy,
  4747. MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, 0x0020);
  4748. bnx2x_cl45_write(bp, phy,
  4749. MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
  4750. bnx2x_cl45_write(bp, phy,
  4751. MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
  4752. /*
  4753. * Enable RX-ALARM control to receive interrupt for 1G speed
  4754. * change
  4755. */
  4756. bnx2x_cl45_write(bp, phy,
  4757. MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 0x4);
  4758. bnx2x_cl45_write(bp, phy,
  4759. MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM_CTRL,
  4760. 0x400);
  4761. } else { /* Default 10G. Set only LASI control */
  4762. bnx2x_cl45_write(bp, phy,
  4763. MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 1);
  4764. }
  4765. /* Set TX PreEmphasis if needed */
  4766. if ((params->feature_config_flags &
  4767. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
  4768. DP(NETIF_MSG_LINK, "Setting TX_CTRL1 0x%x,"
  4769. "TX_CTRL2 0x%x\n",
  4770. phy->tx_preemphasis[0],
  4771. phy->tx_preemphasis[1]);
  4772. bnx2x_cl45_write(bp, phy,
  4773. MDIO_PMA_DEVAD,
  4774. MDIO_PMA_REG_8726_TX_CTRL1,
  4775. phy->tx_preemphasis[0]);
  4776. bnx2x_cl45_write(bp, phy,
  4777. MDIO_PMA_DEVAD,
  4778. MDIO_PMA_REG_8726_TX_CTRL2,
  4779. phy->tx_preemphasis[1]);
  4780. }
  4781. /* Set GPIO3 to trigger SFP+ module insertion/removal */
  4782. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
  4783. MISC_REGISTERS_GPIO_INPUT_HI_Z, params->port);
  4784. /* The GPIO should be swapped if the swap register is set and active */
  4785. swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
  4786. swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
  4787. /* Select function upon port-swap configuration */
  4788. if (params->port == 0) {
  4789. offset = MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0;
  4790. aeu_gpio_mask = (swap_val && swap_override) ?
  4791. AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1 :
  4792. AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0;
  4793. } else {
  4794. offset = MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0;
  4795. aeu_gpio_mask = (swap_val && swap_override) ?
  4796. AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0 :
  4797. AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1;
  4798. }
  4799. val = REG_RD(bp, offset);
  4800. /* add GPIO3 to group */
  4801. val |= aeu_gpio_mask;
  4802. REG_WR(bp, offset, val);
  4803. return 0;
  4804. }
  4805. static void bnx2x_8726_link_reset(struct bnx2x_phy *phy,
  4806. struct link_params *params)
  4807. {
  4808. struct bnx2x *bp = params->bp;
  4809. DP(NETIF_MSG_LINK, "bnx2x_8726_link_reset port %d\n", params->port);
  4810. /* Set serial boot control for external load */
  4811. bnx2x_cl45_write(bp, phy,
  4812. MDIO_PMA_DEVAD,
  4813. MDIO_PMA_REG_GEN_CTRL, 0x0001);
  4814. }
  4815. /******************************************************************/
  4816. /* BCM8727 PHY SECTION */
  4817. /******************************************************************/
  4818. static void bnx2x_8727_set_link_led(struct bnx2x_phy *phy,
  4819. struct link_params *params, u8 mode)
  4820. {
  4821. struct bnx2x *bp = params->bp;
  4822. u16 led_mode_bitmask = 0;
  4823. u16 gpio_pins_bitmask = 0;
  4824. u16 val;
  4825. /* Only NOC flavor requires to set the LED specifically */
  4826. if (!(phy->flags & FLAGS_NOC))
  4827. return;
  4828. switch (mode) {
  4829. case LED_MODE_FRONT_PANEL_OFF:
  4830. case LED_MODE_OFF:
  4831. led_mode_bitmask = 0;
  4832. gpio_pins_bitmask = 0x03;
  4833. break;
  4834. case LED_MODE_ON:
  4835. led_mode_bitmask = 0;
  4836. gpio_pins_bitmask = 0x02;
  4837. break;
  4838. case LED_MODE_OPER:
  4839. led_mode_bitmask = 0x60;
  4840. gpio_pins_bitmask = 0x11;
  4841. break;
  4842. }
  4843. bnx2x_cl45_read(bp, phy,
  4844. MDIO_PMA_DEVAD,
  4845. MDIO_PMA_REG_8727_PCS_OPT_CTRL,
  4846. &val);
  4847. val &= 0xff8f;
  4848. val |= led_mode_bitmask;
  4849. bnx2x_cl45_write(bp, phy,
  4850. MDIO_PMA_DEVAD,
  4851. MDIO_PMA_REG_8727_PCS_OPT_CTRL,
  4852. val);
  4853. bnx2x_cl45_read(bp, phy,
  4854. MDIO_PMA_DEVAD,
  4855. MDIO_PMA_REG_8727_GPIO_CTRL,
  4856. &val);
  4857. val &= 0xffe0;
  4858. val |= gpio_pins_bitmask;
  4859. bnx2x_cl45_write(bp, phy,
  4860. MDIO_PMA_DEVAD,
  4861. MDIO_PMA_REG_8727_GPIO_CTRL,
  4862. val);
  4863. }
  4864. static void bnx2x_8727_hw_reset(struct bnx2x_phy *phy,
  4865. struct link_params *params) {
  4866. u32 swap_val, swap_override;
  4867. u8 port;
  4868. /*
  4869. * The PHY reset is controlled by GPIO 1. Fake the port number
  4870. * to cancel the swap done in set_gpio()
  4871. */
  4872. struct bnx2x *bp = params->bp;
  4873. swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
  4874. swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
  4875. port = (swap_val && swap_override) ^ 1;
  4876. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
  4877. MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
  4878. }
  4879. static u8 bnx2x_8727_config_init(struct bnx2x_phy *phy,
  4880. struct link_params *params,
  4881. struct link_vars *vars)
  4882. {
  4883. u32 tx_en_mode;
  4884. u16 tmp1, val, mod_abs, tmp2;
  4885. u16 rx_alarm_ctrl_val;
  4886. u16 lasi_ctrl_val;
  4887. struct bnx2x *bp = params->bp;
  4888. /* Enable PMD link, MOD_ABS_FLT, and 1G link alarm */
  4889. bnx2x_wait_reset_complete(bp, phy, params);
  4890. rx_alarm_ctrl_val = (1<<2) | (1<<5) ;
  4891. lasi_ctrl_val = 0x0004;
  4892. DP(NETIF_MSG_LINK, "Initializing BCM8727\n");
  4893. /* enable LASI */
  4894. bnx2x_cl45_write(bp, phy,
  4895. MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM_CTRL,
  4896. rx_alarm_ctrl_val);
  4897. bnx2x_cl45_write(bp, phy,
  4898. MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, lasi_ctrl_val);
  4899. /*
  4900. * Initially configure MOD_ABS to interrupt when module is
  4901. * presence( bit 8)
  4902. */
  4903. bnx2x_cl45_read(bp, phy,
  4904. MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, &mod_abs);
  4905. /*
  4906. * Set EDC off by setting OPTXLOS signal input to low (bit 9).
  4907. * When the EDC is off it locks onto a reference clock and avoids
  4908. * becoming 'lost'
  4909. */
  4910. mod_abs &= ~(1<<8);
  4911. if (!(phy->flags & FLAGS_NOC))
  4912. mod_abs &= ~(1<<9);
  4913. bnx2x_cl45_write(bp, phy,
  4914. MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
  4915. /* Make MOD_ABS give interrupt on change */
  4916. bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_PCS_OPT_CTRL,
  4917. &val);
  4918. val |= (1<<12);
  4919. if (phy->flags & FLAGS_NOC)
  4920. val |= (3<<5);
  4921. /*
  4922. * Set 8727 GPIOs to input to allow reading from the 8727 GPIO0
  4923. * status which reflect SFP+ module over-current
  4924. */
  4925. if (!(phy->flags & FLAGS_NOC))
  4926. val &= 0xff8f; /* Reset bits 4-6 */
  4927. bnx2x_cl45_write(bp, phy,
  4928. MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_PCS_OPT_CTRL, val);
  4929. bnx2x_8727_power_module(bp, phy, 1);
  4930. bnx2x_cl45_read(bp, phy,
  4931. MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &tmp1);
  4932. bnx2x_cl45_read(bp, phy,
  4933. MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM, &tmp1);
  4934. /* Set option 1G speed */
  4935. if (phy->req_line_speed == SPEED_1000) {
  4936. DP(NETIF_MSG_LINK, "Setting 1G force\n");
  4937. bnx2x_cl45_write(bp, phy,
  4938. MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x40);
  4939. bnx2x_cl45_write(bp, phy,
  4940. MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0xD);
  4941. bnx2x_cl45_read(bp, phy,
  4942. MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, &tmp1);
  4943. DP(NETIF_MSG_LINK, "1.7 = 0x%x\n", tmp1);
  4944. /*
  4945. * Power down the XAUI until link is up in case of dual-media
  4946. * and 1G
  4947. */
  4948. if (DUAL_MEDIA(params)) {
  4949. bnx2x_cl45_read(bp, phy,
  4950. MDIO_PMA_DEVAD,
  4951. MDIO_PMA_REG_8727_PCS_GP, &val);
  4952. val |= (3<<10);
  4953. bnx2x_cl45_write(bp, phy,
  4954. MDIO_PMA_DEVAD,
  4955. MDIO_PMA_REG_8727_PCS_GP, val);
  4956. }
  4957. } else if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
  4958. ((phy->speed_cap_mask &
  4959. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) &&
  4960. ((phy->speed_cap_mask &
  4961. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) !=
  4962. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
  4963. DP(NETIF_MSG_LINK, "Setting 1G clause37\n");
  4964. bnx2x_cl45_write(bp, phy,
  4965. MDIO_AN_DEVAD, MDIO_AN_REG_8727_MISC_CTRL, 0);
  4966. bnx2x_cl45_write(bp, phy,
  4967. MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1300);
  4968. } else {
  4969. /*
  4970. * Since the 8727 has only single reset pin, need to set the 10G
  4971. * registers although it is default
  4972. */
  4973. bnx2x_cl45_write(bp, phy,
  4974. MDIO_AN_DEVAD, MDIO_AN_REG_8727_MISC_CTRL,
  4975. 0x0020);
  4976. bnx2x_cl45_write(bp, phy,
  4977. MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x0100);
  4978. bnx2x_cl45_write(bp, phy,
  4979. MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x2040);
  4980. bnx2x_cl45_write(bp, phy,
  4981. MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2,
  4982. 0x0008);
  4983. }
  4984. /*
  4985. * Set 2-wire transfer rate of SFP+ module EEPROM
  4986. * to 100Khz since some DACs(direct attached cables) do
  4987. * not work at 400Khz.
  4988. */
  4989. bnx2x_cl45_write(bp, phy,
  4990. MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TWO_WIRE_SLAVE_ADDR,
  4991. 0xa001);
  4992. /* Set TX PreEmphasis if needed */
  4993. if ((params->feature_config_flags &
  4994. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
  4995. DP(NETIF_MSG_LINK, "Setting TX_CTRL1 0x%x, TX_CTRL2 0x%x\n",
  4996. phy->tx_preemphasis[0],
  4997. phy->tx_preemphasis[1]);
  4998. bnx2x_cl45_write(bp, phy,
  4999. MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TX_CTRL1,
  5000. phy->tx_preemphasis[0]);
  5001. bnx2x_cl45_write(bp, phy,
  5002. MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TX_CTRL2,
  5003. phy->tx_preemphasis[1]);
  5004. }
  5005. /*
  5006. * If TX Laser is controlled by GPIO_0, do not let PHY go into low
  5007. * power mode, if TX Laser is disabled
  5008. */
  5009. tx_en_mode = REG_RD(bp, params->shmem_base +
  5010. offsetof(struct shmem_region,
  5011. dev_info.port_hw_config[params->port].sfp_ctrl))
  5012. & PORT_HW_CFG_TX_LASER_MASK;
  5013. if (tx_en_mode == PORT_HW_CFG_TX_LASER_GPIO0) {
  5014. DP(NETIF_MSG_LINK, "Enabling TXONOFF_PWRDN_DIS\n");
  5015. bnx2x_cl45_read(bp, phy,
  5016. MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_OPT_CFG_REG, &tmp2);
  5017. tmp2 |= 0x1000;
  5018. tmp2 &= 0xFFEF;
  5019. bnx2x_cl45_write(bp, phy,
  5020. MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_OPT_CFG_REG, tmp2);
  5021. }
  5022. return 0;
  5023. }
  5024. static void bnx2x_8727_handle_mod_abs(struct bnx2x_phy *phy,
  5025. struct link_params *params)
  5026. {
  5027. struct bnx2x *bp = params->bp;
  5028. u16 mod_abs, rx_alarm_status;
  5029. u32 val = REG_RD(bp, params->shmem_base +
  5030. offsetof(struct shmem_region, dev_info.
  5031. port_feature_config[params->port].
  5032. config));
  5033. bnx2x_cl45_read(bp, phy,
  5034. MDIO_PMA_DEVAD,
  5035. MDIO_PMA_REG_PHY_IDENTIFIER, &mod_abs);
  5036. if (mod_abs & (1<<8)) {
  5037. /* Module is absent */
  5038. DP(NETIF_MSG_LINK, "MOD_ABS indication "
  5039. "show module is absent\n");
  5040. /*
  5041. * 1. Set mod_abs to detect next module
  5042. * presence event
  5043. * 2. Set EDC off by setting OPTXLOS signal input to low
  5044. * (bit 9).
  5045. * When the EDC is off it locks onto a reference clock and
  5046. * avoids becoming 'lost'.
  5047. */
  5048. mod_abs &= ~(1<<8);
  5049. if (!(phy->flags & FLAGS_NOC))
  5050. mod_abs &= ~(1<<9);
  5051. bnx2x_cl45_write(bp, phy,
  5052. MDIO_PMA_DEVAD,
  5053. MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
  5054. /*
  5055. * Clear RX alarm since it stays up as long as
  5056. * the mod_abs wasn't changed
  5057. */
  5058. bnx2x_cl45_read(bp, phy,
  5059. MDIO_PMA_DEVAD,
  5060. MDIO_PMA_REG_RX_ALARM, &rx_alarm_status);
  5061. } else {
  5062. /* Module is present */
  5063. DP(NETIF_MSG_LINK, "MOD_ABS indication "
  5064. "show module is present\n");
  5065. /*
  5066. * First disable transmitter, and if the module is ok, the
  5067. * module_detection will enable it
  5068. * 1. Set mod_abs to detect next module absent event ( bit 8)
  5069. * 2. Restore the default polarity of the OPRXLOS signal and
  5070. * this signal will then correctly indicate the presence or
  5071. * absence of the Rx signal. (bit 9)
  5072. */
  5073. mod_abs |= (1<<8);
  5074. if (!(phy->flags & FLAGS_NOC))
  5075. mod_abs |= (1<<9);
  5076. bnx2x_cl45_write(bp, phy,
  5077. MDIO_PMA_DEVAD,
  5078. MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
  5079. /*
  5080. * Clear RX alarm since it stays up as long as the mod_abs
  5081. * wasn't changed. This is need to be done before calling the
  5082. * module detection, otherwise it will clear* the link update
  5083. * alarm
  5084. */
  5085. bnx2x_cl45_read(bp, phy,
  5086. MDIO_PMA_DEVAD,
  5087. MDIO_PMA_REG_RX_ALARM, &rx_alarm_status);
  5088. if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
  5089. PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER)
  5090. bnx2x_sfp_set_transmitter(params, phy, 0);
  5091. if (bnx2x_wait_for_sfp_module_initialized(phy, params) == 0)
  5092. bnx2x_sfp_module_detection(phy, params);
  5093. else
  5094. DP(NETIF_MSG_LINK, "SFP+ module is not initialized\n");
  5095. }
  5096. DP(NETIF_MSG_LINK, "8727 RX_ALARM_STATUS 0x%x\n",
  5097. rx_alarm_status);
  5098. /* No need to check link status in case of module plugged in/out */
  5099. }
  5100. static u8 bnx2x_8727_read_status(struct bnx2x_phy *phy,
  5101. struct link_params *params,
  5102. struct link_vars *vars)
  5103. {
  5104. struct bnx2x *bp = params->bp;
  5105. u8 link_up = 0;
  5106. u16 link_status = 0;
  5107. u16 rx_alarm_status, lasi_ctrl, val1;
  5108. /* If PHY is not initialized, do not check link status */
  5109. bnx2x_cl45_read(bp, phy,
  5110. MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL,
  5111. &lasi_ctrl);
  5112. if (!lasi_ctrl)
  5113. return 0;
  5114. /* Check the LASI */
  5115. bnx2x_cl45_read(bp, phy,
  5116. MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM,
  5117. &rx_alarm_status);
  5118. vars->line_speed = 0;
  5119. DP(NETIF_MSG_LINK, "8727 RX_ALARM_STATUS 0x%x\n", rx_alarm_status);
  5120. bnx2x_cl45_read(bp, phy,
  5121. MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS, &val1);
  5122. DP(NETIF_MSG_LINK, "8727 LASI status 0x%x\n", val1);
  5123. /* Clear MSG-OUT */
  5124. bnx2x_cl45_read(bp, phy,
  5125. MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &val1);
  5126. /*
  5127. * If a module is present and there is need to check
  5128. * for over current
  5129. */
  5130. if (!(phy->flags & FLAGS_NOC) && !(rx_alarm_status & (1<<5))) {
  5131. /* Check over-current using 8727 GPIO0 input*/
  5132. bnx2x_cl45_read(bp, phy,
  5133. MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_GPIO_CTRL,
  5134. &val1);
  5135. if ((val1 & (1<<8)) == 0) {
  5136. DP(NETIF_MSG_LINK, "8727 Power fault has been detected"
  5137. " on port %d\n", params->port);
  5138. netdev_err(bp->dev, "Error: Power fault on Port %d has"
  5139. " been detected and the power to "
  5140. "that SFP+ module has been removed"
  5141. " to prevent failure of the card."
  5142. " Please remove the SFP+ module and"
  5143. " restart the system to clear this"
  5144. " error.\n",
  5145. params->port);
  5146. /* Disable all RX_ALARMs except for mod_abs */
  5147. bnx2x_cl45_write(bp, phy,
  5148. MDIO_PMA_DEVAD,
  5149. MDIO_PMA_REG_RX_ALARM_CTRL, (1<<5));
  5150. bnx2x_cl45_read(bp, phy,
  5151. MDIO_PMA_DEVAD,
  5152. MDIO_PMA_REG_PHY_IDENTIFIER, &val1);
  5153. /* Wait for module_absent_event */
  5154. val1 |= (1<<8);
  5155. bnx2x_cl45_write(bp, phy,
  5156. MDIO_PMA_DEVAD,
  5157. MDIO_PMA_REG_PHY_IDENTIFIER, val1);
  5158. /* Clear RX alarm */
  5159. bnx2x_cl45_read(bp, phy,
  5160. MDIO_PMA_DEVAD,
  5161. MDIO_PMA_REG_RX_ALARM, &rx_alarm_status);
  5162. return 0;
  5163. }
  5164. } /* Over current check */
  5165. /* When module absent bit is set, check module */
  5166. if (rx_alarm_status & (1<<5)) {
  5167. bnx2x_8727_handle_mod_abs(phy, params);
  5168. /* Enable all mod_abs and link detection bits */
  5169. bnx2x_cl45_write(bp, phy,
  5170. MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_ALARM_CTRL,
  5171. ((1<<5) | (1<<2)));
  5172. }
  5173. DP(NETIF_MSG_LINK, "Enabling 8727 TX laser if SFP is approved\n");
  5174. bnx2x_8727_specific_func(phy, params, ENABLE_TX);
  5175. /* If transmitter is disabled, ignore false link up indication */
  5176. bnx2x_cl45_read(bp, phy,
  5177. MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, &val1);
  5178. if (val1 & (1<<15)) {
  5179. DP(NETIF_MSG_LINK, "Tx is disabled\n");
  5180. return 0;
  5181. }
  5182. bnx2x_cl45_read(bp, phy,
  5183. MDIO_PMA_DEVAD,
  5184. MDIO_PMA_REG_8073_SPEED_LINK_STATUS, &link_status);
  5185. /*
  5186. * Bits 0..2 --> speed detected,
  5187. * Bits 13..15--> link is down
  5188. */
  5189. if ((link_status & (1<<2)) && (!(link_status & (1<<15)))) {
  5190. link_up = 1;
  5191. vars->line_speed = SPEED_10000;
  5192. DP(NETIF_MSG_LINK, "port %x: External link up in 10G\n",
  5193. params->port);
  5194. } else if ((link_status & (1<<0)) && (!(link_status & (1<<13)))) {
  5195. link_up = 1;
  5196. vars->line_speed = SPEED_1000;
  5197. DP(NETIF_MSG_LINK, "port %x: External link up in 1G\n",
  5198. params->port);
  5199. } else {
  5200. link_up = 0;
  5201. DP(NETIF_MSG_LINK, "port %x: External link is down\n",
  5202. params->port);
  5203. }
  5204. if (link_up) {
  5205. bnx2x_ext_phy_resolve_fc(phy, params, vars);
  5206. vars->duplex = DUPLEX_FULL;
  5207. DP(NETIF_MSG_LINK, "duplex = 0x%x\n", vars->duplex);
  5208. }
  5209. if ((DUAL_MEDIA(params)) &&
  5210. (phy->req_line_speed == SPEED_1000)) {
  5211. bnx2x_cl45_read(bp, phy,
  5212. MDIO_PMA_DEVAD,
  5213. MDIO_PMA_REG_8727_PCS_GP, &val1);
  5214. /*
  5215. * In case of dual-media board and 1G, power up the XAUI side,
  5216. * otherwise power it down. For 10G it is done automatically
  5217. */
  5218. if (link_up)
  5219. val1 &= ~(3<<10);
  5220. else
  5221. val1 |= (3<<10);
  5222. bnx2x_cl45_write(bp, phy,
  5223. MDIO_PMA_DEVAD,
  5224. MDIO_PMA_REG_8727_PCS_GP, val1);
  5225. }
  5226. return link_up;
  5227. }
  5228. static void bnx2x_8727_link_reset(struct bnx2x_phy *phy,
  5229. struct link_params *params)
  5230. {
  5231. struct bnx2x *bp = params->bp;
  5232. /* Disable Transmitter */
  5233. bnx2x_sfp_set_transmitter(params, phy, 0);
  5234. /* Clear LASI */
  5235. bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 0);
  5236. }
  5237. /******************************************************************/
  5238. /* BCM8481/BCM84823/BCM84833 PHY SECTION */
  5239. /******************************************************************/
  5240. static void bnx2x_save_848xx_spirom_version(struct bnx2x_phy *phy,
  5241. struct link_params *params)
  5242. {
  5243. u16 val, fw_ver1, fw_ver2, cnt, adj;
  5244. struct bnx2x *bp = params->bp;
  5245. adj = 0;
  5246. if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  5247. adj = -1;
  5248. /* For the 32 bits registers in 848xx, access via MDIO2ARM interface.*/
  5249. /* (1) set register 0xc200_0014(SPI_BRIDGE_CTRL_2) to 0x03000000 */
  5250. bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA819 + adj, 0x0014);
  5251. bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81A + adj, 0xc200);
  5252. bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81B + adj, 0x0000);
  5253. bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81C + adj, 0x0300);
  5254. bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA817 + adj, 0x0009);
  5255. for (cnt = 0; cnt < 100; cnt++) {
  5256. bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA818 + adj, &val);
  5257. if (val & 1)
  5258. break;
  5259. udelay(5);
  5260. }
  5261. if (cnt == 100) {
  5262. DP(NETIF_MSG_LINK, "Unable to read 848xx phy fw version(1)\n");
  5263. bnx2x_save_spirom_version(bp, params->port, 0,
  5264. phy->ver_addr);
  5265. return;
  5266. }
  5267. /* 2) read register 0xc200_0000 (SPI_FW_STATUS) */
  5268. bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA819 + adj, 0x0000);
  5269. bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81A + adj, 0xc200);
  5270. bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA817 + adj, 0x000A);
  5271. for (cnt = 0; cnt < 100; cnt++) {
  5272. bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA818 + adj, &val);
  5273. if (val & 1)
  5274. break;
  5275. udelay(5);
  5276. }
  5277. if (cnt == 100) {
  5278. DP(NETIF_MSG_LINK, "Unable to read 848xx phy fw version(2)\n");
  5279. bnx2x_save_spirom_version(bp, params->port, 0,
  5280. phy->ver_addr);
  5281. return;
  5282. }
  5283. /* lower 16 bits of the register SPI_FW_STATUS */
  5284. bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA81B + adj, &fw_ver1);
  5285. /* upper 16 bits of register SPI_FW_STATUS */
  5286. bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA81C + adj, &fw_ver2);
  5287. bnx2x_save_spirom_version(bp, params->port, (fw_ver2<<16) | fw_ver1,
  5288. phy->ver_addr);
  5289. }
  5290. static void bnx2x_848xx_set_led(struct bnx2x *bp,
  5291. struct bnx2x_phy *phy)
  5292. {
  5293. u16 val, adj;
  5294. adj = 0;
  5295. if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  5296. adj = -1;
  5297. /* PHYC_CTL_LED_CTL */
  5298. bnx2x_cl45_read(bp, phy,
  5299. MDIO_PMA_DEVAD,
  5300. MDIO_PMA_REG_8481_LINK_SIGNAL + adj, &val);
  5301. val &= 0xFE00;
  5302. val |= 0x0092;
  5303. bnx2x_cl45_write(bp, phy,
  5304. MDIO_PMA_DEVAD,
  5305. MDIO_PMA_REG_8481_LINK_SIGNAL + adj, val);
  5306. bnx2x_cl45_write(bp, phy,
  5307. MDIO_PMA_DEVAD,
  5308. MDIO_PMA_REG_8481_LED1_MASK + adj,
  5309. 0x80);
  5310. bnx2x_cl45_write(bp, phy,
  5311. MDIO_PMA_DEVAD,
  5312. MDIO_PMA_REG_8481_LED2_MASK + adj,
  5313. 0x18);
  5314. /* Select activity source by Tx and Rx, as suggested by PHY AE */
  5315. bnx2x_cl45_write(bp, phy,
  5316. MDIO_PMA_DEVAD,
  5317. MDIO_PMA_REG_8481_LED3_MASK + adj,
  5318. 0x0006);
  5319. /* Select the closest activity blink rate to that in 10/100/1000 */
  5320. bnx2x_cl45_write(bp, phy,
  5321. MDIO_PMA_DEVAD,
  5322. MDIO_PMA_REG_8481_LED3_BLINK + adj,
  5323. 0);
  5324. bnx2x_cl45_read(bp, phy,
  5325. MDIO_PMA_DEVAD,
  5326. MDIO_PMA_REG_84823_CTL_LED_CTL_1 + adj, &val);
  5327. val |= MDIO_PMA_REG_84823_LED3_STRETCH_EN; /* stretch_en for LED3*/
  5328. bnx2x_cl45_write(bp, phy,
  5329. MDIO_PMA_DEVAD,
  5330. MDIO_PMA_REG_84823_CTL_LED_CTL_1 + adj, val);
  5331. /* 'Interrupt Mask' */
  5332. bnx2x_cl45_write(bp, phy,
  5333. MDIO_AN_DEVAD,
  5334. 0xFFFB, 0xFFFD);
  5335. }
  5336. static u8 bnx2x_848xx_cmn_config_init(struct bnx2x_phy *phy,
  5337. struct link_params *params,
  5338. struct link_vars *vars)
  5339. {
  5340. struct bnx2x *bp = params->bp;
  5341. u16 autoneg_val, an_1000_val, an_10_100_val;
  5342. /*
  5343. * This phy uses the NIG latch mechanism since link indication
  5344. * arrives through its LED4 and not via its LASI signal, so we
  5345. * get steady signal instead of clear on read
  5346. */
  5347. bnx2x_bits_en(bp, NIG_REG_LATCH_BC_0 + params->port*4,
  5348. 1 << NIG_LATCH_BC_ENABLE_MI_INT);
  5349. bnx2x_cl45_write(bp, phy,
  5350. MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x0000);
  5351. bnx2x_848xx_set_led(bp, phy);
  5352. /* set 1000 speed advertisement */
  5353. bnx2x_cl45_read(bp, phy,
  5354. MDIO_AN_DEVAD, MDIO_AN_REG_8481_1000T_CTRL,
  5355. &an_1000_val);
  5356. bnx2x_ext_phy_set_pause(params, phy, vars);
  5357. bnx2x_cl45_read(bp, phy,
  5358. MDIO_AN_DEVAD,
  5359. MDIO_AN_REG_8481_LEGACY_AN_ADV,
  5360. &an_10_100_val);
  5361. bnx2x_cl45_read(bp, phy,
  5362. MDIO_AN_DEVAD, MDIO_AN_REG_8481_LEGACY_MII_CTRL,
  5363. &autoneg_val);
  5364. /* Disable forced speed */
  5365. autoneg_val &= ~((1<<6) | (1<<8) | (1<<9) | (1<<12) | (1<<13));
  5366. an_10_100_val &= ~((1<<5) | (1<<6) | (1<<7) | (1<<8));
  5367. if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
  5368. (phy->speed_cap_mask &
  5369. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
  5370. (phy->req_line_speed == SPEED_1000)) {
  5371. an_1000_val |= (1<<8);
  5372. autoneg_val |= (1<<9 | 1<<12);
  5373. if (phy->req_duplex == DUPLEX_FULL)
  5374. an_1000_val |= (1<<9);
  5375. DP(NETIF_MSG_LINK, "Advertising 1G\n");
  5376. } else
  5377. an_1000_val &= ~((1<<8) | (1<<9));
  5378. bnx2x_cl45_write(bp, phy,
  5379. MDIO_AN_DEVAD, MDIO_AN_REG_8481_1000T_CTRL,
  5380. an_1000_val);
  5381. /* set 10 speed advertisement */
  5382. if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
  5383. (phy->speed_cap_mask &
  5384. (PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL |
  5385. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF)))) {
  5386. an_10_100_val |= (1<<7);
  5387. /* Enable autoneg and restart autoneg for legacy speeds */
  5388. autoneg_val |= (1<<9 | 1<<12);
  5389. if (phy->req_duplex == DUPLEX_FULL)
  5390. an_10_100_val |= (1<<8);
  5391. DP(NETIF_MSG_LINK, "Advertising 100M\n");
  5392. }
  5393. /* set 10 speed advertisement */
  5394. if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
  5395. (phy->speed_cap_mask &
  5396. (PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL |
  5397. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF)))) {
  5398. an_10_100_val |= (1<<5);
  5399. autoneg_val |= (1<<9 | 1<<12);
  5400. if (phy->req_duplex == DUPLEX_FULL)
  5401. an_10_100_val |= (1<<6);
  5402. DP(NETIF_MSG_LINK, "Advertising 10M\n");
  5403. }
  5404. /* Only 10/100 are allowed to work in FORCE mode */
  5405. if (phy->req_line_speed == SPEED_100) {
  5406. autoneg_val |= (1<<13);
  5407. /* Enabled AUTO-MDIX when autoneg is disabled */
  5408. bnx2x_cl45_write(bp, phy,
  5409. MDIO_AN_DEVAD, MDIO_AN_REG_8481_AUX_CTRL,
  5410. (1<<15 | 1<<9 | 7<<0));
  5411. DP(NETIF_MSG_LINK, "Setting 100M force\n");
  5412. }
  5413. if (phy->req_line_speed == SPEED_10) {
  5414. /* Enabled AUTO-MDIX when autoneg is disabled */
  5415. bnx2x_cl45_write(bp, phy,
  5416. MDIO_AN_DEVAD, MDIO_AN_REG_8481_AUX_CTRL,
  5417. (1<<15 | 1<<9 | 7<<0));
  5418. DP(NETIF_MSG_LINK, "Setting 10M force\n");
  5419. }
  5420. bnx2x_cl45_write(bp, phy,
  5421. MDIO_AN_DEVAD, MDIO_AN_REG_8481_LEGACY_AN_ADV,
  5422. an_10_100_val);
  5423. if (phy->req_duplex == DUPLEX_FULL)
  5424. autoneg_val |= (1<<8);
  5425. bnx2x_cl45_write(bp, phy,
  5426. MDIO_AN_DEVAD,
  5427. MDIO_AN_REG_8481_LEGACY_MII_CTRL, autoneg_val);
  5428. if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
  5429. (phy->speed_cap_mask &
  5430. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) ||
  5431. (phy->req_line_speed == SPEED_10000)) {
  5432. DP(NETIF_MSG_LINK, "Advertising 10G\n");
  5433. /* Restart autoneg for 10G*/
  5434. bnx2x_cl45_write(bp, phy,
  5435. MDIO_AN_DEVAD, MDIO_AN_REG_CTRL,
  5436. 0x3200);
  5437. } else if (phy->req_line_speed != SPEED_10 &&
  5438. phy->req_line_speed != SPEED_100) {
  5439. bnx2x_cl45_write(bp, phy,
  5440. MDIO_AN_DEVAD,
  5441. MDIO_AN_REG_8481_10GBASE_T_AN_CTRL,
  5442. 1);
  5443. }
  5444. /* Save spirom version */
  5445. bnx2x_save_848xx_spirom_version(phy, params);
  5446. return 0;
  5447. }
  5448. static u8 bnx2x_8481_config_init(struct bnx2x_phy *phy,
  5449. struct link_params *params,
  5450. struct link_vars *vars)
  5451. {
  5452. struct bnx2x *bp = params->bp;
  5453. /* Restore normal power mode*/
  5454. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
  5455. MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
  5456. /* HW reset */
  5457. bnx2x_ext_phy_hw_reset(bp, params->port);
  5458. bnx2x_wait_reset_complete(bp, phy, params);
  5459. bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
  5460. return bnx2x_848xx_cmn_config_init(phy, params, vars);
  5461. }
  5462. static u8 bnx2x_848x3_config_init(struct bnx2x_phy *phy,
  5463. struct link_params *params,
  5464. struct link_vars *vars)
  5465. {
  5466. struct bnx2x *bp = params->bp;
  5467. u8 port, initialize = 1;
  5468. u16 val, adj;
  5469. u16 temp;
  5470. u32 actual_phy_selection, cms_enable;
  5471. u8 rc = 0;
  5472. /* This is just for MDIO_CTL_REG_84823_MEDIA register. */
  5473. adj = 0;
  5474. if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  5475. adj = 3;
  5476. msleep(1);
  5477. if (CHIP_IS_E2(bp))
  5478. port = BP_PATH(bp);
  5479. else
  5480. port = params->port;
  5481. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
  5482. MISC_REGISTERS_GPIO_OUTPUT_HIGH,
  5483. port);
  5484. bnx2x_wait_reset_complete(bp, phy, params);
  5485. /* Wait for GPHY to come out of reset */
  5486. msleep(50);
  5487. /*
  5488. * BCM84823 requires that XGXS links up first @ 10G for normal behavior
  5489. */
  5490. temp = vars->line_speed;
  5491. vars->line_speed = SPEED_10000;
  5492. bnx2x_set_autoneg(&params->phy[INT_PHY], params, vars, 0);
  5493. bnx2x_program_serdes(&params->phy[INT_PHY], params, vars);
  5494. vars->line_speed = temp;
  5495. /* Set dual-media configuration according to configuration */
  5496. bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
  5497. MDIO_CTL_REG_84823_MEDIA + adj, &val);
  5498. val &= ~(MDIO_CTL_REG_84823_MEDIA_MAC_MASK |
  5499. MDIO_CTL_REG_84823_MEDIA_LINE_MASK |
  5500. MDIO_CTL_REG_84823_MEDIA_COPPER_CORE_DOWN |
  5501. MDIO_CTL_REG_84823_MEDIA_PRIORITY_MASK |
  5502. MDIO_CTL_REG_84823_MEDIA_FIBER_1G);
  5503. val |= MDIO_CTL_REG_84823_CTRL_MAC_XFI |
  5504. MDIO_CTL_REG_84823_MEDIA_LINE_XAUI_L;
  5505. actual_phy_selection = bnx2x_phy_selection(params);
  5506. switch (actual_phy_selection) {
  5507. case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
  5508. /* Do nothing. Essentially this is like the priority copper */
  5509. break;
  5510. case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
  5511. val |= MDIO_CTL_REG_84823_MEDIA_PRIORITY_COPPER;
  5512. break;
  5513. case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
  5514. val |= MDIO_CTL_REG_84823_MEDIA_PRIORITY_FIBER;
  5515. break;
  5516. case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
  5517. /* Do nothing here. The first PHY won't be initialized at all */
  5518. break;
  5519. case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
  5520. val |= MDIO_CTL_REG_84823_MEDIA_COPPER_CORE_DOWN;
  5521. initialize = 0;
  5522. break;
  5523. }
  5524. if (params->phy[EXT_PHY2].req_line_speed == SPEED_1000)
  5525. val |= MDIO_CTL_REG_84823_MEDIA_FIBER_1G;
  5526. bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
  5527. MDIO_CTL_REG_84823_MEDIA + adj, val);
  5528. DP(NETIF_MSG_LINK, "Multi_phy config = 0x%x, Media control = 0x%x\n",
  5529. params->multi_phy_config, val);
  5530. if (initialize)
  5531. rc = bnx2x_848xx_cmn_config_init(phy, params, vars);
  5532. else
  5533. bnx2x_save_848xx_spirom_version(phy, params);
  5534. cms_enable = REG_RD(bp, params->shmem_base +
  5535. offsetof(struct shmem_region,
  5536. dev_info.port_hw_config[params->port].default_cfg)) &
  5537. PORT_HW_CFG_ENABLE_CMS_MASK;
  5538. bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
  5539. MDIO_CTL_REG_84823_USER_CTRL_REG, &val);
  5540. if (cms_enable)
  5541. val |= MDIO_CTL_REG_84823_USER_CTRL_CMS;
  5542. else
  5543. val &= ~MDIO_CTL_REG_84823_USER_CTRL_CMS;
  5544. bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
  5545. MDIO_CTL_REG_84823_USER_CTRL_REG, val);
  5546. return rc;
  5547. }
  5548. static u8 bnx2x_848xx_read_status(struct bnx2x_phy *phy,
  5549. struct link_params *params,
  5550. struct link_vars *vars)
  5551. {
  5552. struct bnx2x *bp = params->bp;
  5553. u16 val, val1, val2, adj;
  5554. u8 link_up = 0;
  5555. /* Reg offset adjustment for 84833 */
  5556. adj = 0;
  5557. if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  5558. adj = -1;
  5559. /* Check 10G-BaseT link status */
  5560. /* Check PMD signal ok */
  5561. bnx2x_cl45_read(bp, phy,
  5562. MDIO_AN_DEVAD, 0xFFFA, &val1);
  5563. bnx2x_cl45_read(bp, phy,
  5564. MDIO_PMA_DEVAD, MDIO_PMA_REG_8481_PMD_SIGNAL + adj,
  5565. &val2);
  5566. DP(NETIF_MSG_LINK, "BCM848xx: PMD_SIGNAL 1.a811 = 0x%x\n", val2);
  5567. /* Check link 10G */
  5568. if (val2 & (1<<11)) {
  5569. vars->line_speed = SPEED_10000;
  5570. vars->duplex = DUPLEX_FULL;
  5571. link_up = 1;
  5572. bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
  5573. } else { /* Check Legacy speed link */
  5574. u16 legacy_status, legacy_speed;
  5575. /* Enable expansion register 0x42 (Operation mode status) */
  5576. bnx2x_cl45_write(bp, phy,
  5577. MDIO_AN_DEVAD,
  5578. MDIO_AN_REG_8481_EXPANSION_REG_ACCESS, 0xf42);
  5579. /* Get legacy speed operation status */
  5580. bnx2x_cl45_read(bp, phy,
  5581. MDIO_AN_DEVAD,
  5582. MDIO_AN_REG_8481_EXPANSION_REG_RD_RW,
  5583. &legacy_status);
  5584. DP(NETIF_MSG_LINK, "Legacy speed status"
  5585. " = 0x%x\n", legacy_status);
  5586. link_up = ((legacy_status & (1<<11)) == (1<<11));
  5587. if (link_up) {
  5588. legacy_speed = (legacy_status & (3<<9));
  5589. if (legacy_speed == (0<<9))
  5590. vars->line_speed = SPEED_10;
  5591. else if (legacy_speed == (1<<9))
  5592. vars->line_speed = SPEED_100;
  5593. else if (legacy_speed == (2<<9))
  5594. vars->line_speed = SPEED_1000;
  5595. else /* Should not happen */
  5596. vars->line_speed = 0;
  5597. if (legacy_status & (1<<8))
  5598. vars->duplex = DUPLEX_FULL;
  5599. else
  5600. vars->duplex = DUPLEX_HALF;
  5601. DP(NETIF_MSG_LINK, "Link is up in %dMbps,"
  5602. " is_duplex_full= %d\n", vars->line_speed,
  5603. (vars->duplex == DUPLEX_FULL));
  5604. /* Check legacy speed AN resolution */
  5605. bnx2x_cl45_read(bp, phy,
  5606. MDIO_AN_DEVAD,
  5607. MDIO_AN_REG_8481_LEGACY_MII_STATUS,
  5608. &val);
  5609. if (val & (1<<5))
  5610. vars->link_status |=
  5611. LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
  5612. bnx2x_cl45_read(bp, phy,
  5613. MDIO_AN_DEVAD,
  5614. MDIO_AN_REG_8481_LEGACY_AN_EXPANSION,
  5615. &val);
  5616. if ((val & (1<<0)) == 0)
  5617. vars->link_status |=
  5618. LINK_STATUS_PARALLEL_DETECTION_USED;
  5619. }
  5620. }
  5621. if (link_up) {
  5622. DP(NETIF_MSG_LINK, "BCM84823: link speed is %d\n",
  5623. vars->line_speed);
  5624. bnx2x_ext_phy_resolve_fc(phy, params, vars);
  5625. }
  5626. return link_up;
  5627. }
  5628. static u8 bnx2x_848xx_format_ver(u32 raw_ver, u8 *str, u16 *len)
  5629. {
  5630. u8 status = 0;
  5631. u32 spirom_ver;
  5632. spirom_ver = ((raw_ver & 0xF80) >> 7) << 16 | (raw_ver & 0x7F);
  5633. status = bnx2x_format_ver(spirom_ver, str, len);
  5634. return status;
  5635. }
  5636. static void bnx2x_8481_hw_reset(struct bnx2x_phy *phy,
  5637. struct link_params *params)
  5638. {
  5639. bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
  5640. MISC_REGISTERS_GPIO_OUTPUT_LOW, 0);
  5641. bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
  5642. MISC_REGISTERS_GPIO_OUTPUT_LOW, 1);
  5643. }
  5644. static void bnx2x_8481_link_reset(struct bnx2x_phy *phy,
  5645. struct link_params *params)
  5646. {
  5647. bnx2x_cl45_write(params->bp, phy,
  5648. MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x0000);
  5649. bnx2x_cl45_write(params->bp, phy,
  5650. MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1);
  5651. }
  5652. static void bnx2x_848x3_link_reset(struct bnx2x_phy *phy,
  5653. struct link_params *params)
  5654. {
  5655. struct bnx2x *bp = params->bp;
  5656. u8 port;
  5657. if (CHIP_IS_E2(bp))
  5658. port = BP_PATH(bp);
  5659. else
  5660. port = params->port;
  5661. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
  5662. MISC_REGISTERS_GPIO_OUTPUT_LOW,
  5663. port);
  5664. }
  5665. static void bnx2x_848xx_set_link_led(struct bnx2x_phy *phy,
  5666. struct link_params *params, u8 mode)
  5667. {
  5668. struct bnx2x *bp = params->bp;
  5669. u16 val;
  5670. switch (mode) {
  5671. case LED_MODE_OFF:
  5672. DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE OFF\n", params->port);
  5673. if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
  5674. SHARED_HW_CFG_LED_EXTPHY1) {
  5675. /* Set LED masks */
  5676. bnx2x_cl45_write(bp, phy,
  5677. MDIO_PMA_DEVAD,
  5678. MDIO_PMA_REG_8481_LED1_MASK,
  5679. 0x0);
  5680. bnx2x_cl45_write(bp, phy,
  5681. MDIO_PMA_DEVAD,
  5682. MDIO_PMA_REG_8481_LED2_MASK,
  5683. 0x0);
  5684. bnx2x_cl45_write(bp, phy,
  5685. MDIO_PMA_DEVAD,
  5686. MDIO_PMA_REG_8481_LED3_MASK,
  5687. 0x0);
  5688. bnx2x_cl45_write(bp, phy,
  5689. MDIO_PMA_DEVAD,
  5690. MDIO_PMA_REG_8481_LED5_MASK,
  5691. 0x0);
  5692. } else {
  5693. bnx2x_cl45_write(bp, phy,
  5694. MDIO_PMA_DEVAD,
  5695. MDIO_PMA_REG_8481_LED1_MASK,
  5696. 0x0);
  5697. }
  5698. break;
  5699. case LED_MODE_FRONT_PANEL_OFF:
  5700. DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE FRONT PANEL OFF\n",
  5701. params->port);
  5702. if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
  5703. SHARED_HW_CFG_LED_EXTPHY1) {
  5704. /* Set LED masks */
  5705. bnx2x_cl45_write(bp, phy,
  5706. MDIO_PMA_DEVAD,
  5707. MDIO_PMA_REG_8481_LED1_MASK,
  5708. 0x0);
  5709. bnx2x_cl45_write(bp, phy,
  5710. MDIO_PMA_DEVAD,
  5711. MDIO_PMA_REG_8481_LED2_MASK,
  5712. 0x0);
  5713. bnx2x_cl45_write(bp, phy,
  5714. MDIO_PMA_DEVAD,
  5715. MDIO_PMA_REG_8481_LED3_MASK,
  5716. 0x0);
  5717. bnx2x_cl45_write(bp, phy,
  5718. MDIO_PMA_DEVAD,
  5719. MDIO_PMA_REG_8481_LED5_MASK,
  5720. 0x20);
  5721. } else {
  5722. bnx2x_cl45_write(bp, phy,
  5723. MDIO_PMA_DEVAD,
  5724. MDIO_PMA_REG_8481_LED1_MASK,
  5725. 0x0);
  5726. }
  5727. break;
  5728. case LED_MODE_ON:
  5729. DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE ON\n", params->port);
  5730. if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
  5731. SHARED_HW_CFG_LED_EXTPHY1) {
  5732. /* Set control reg */
  5733. bnx2x_cl45_read(bp, phy,
  5734. MDIO_PMA_DEVAD,
  5735. MDIO_PMA_REG_8481_LINK_SIGNAL,
  5736. &val);
  5737. val &= 0x8000;
  5738. val |= 0x2492;
  5739. bnx2x_cl45_write(bp, phy,
  5740. MDIO_PMA_DEVAD,
  5741. MDIO_PMA_REG_8481_LINK_SIGNAL,
  5742. val);
  5743. /* Set LED masks */
  5744. bnx2x_cl45_write(bp, phy,
  5745. MDIO_PMA_DEVAD,
  5746. MDIO_PMA_REG_8481_LED1_MASK,
  5747. 0x0);
  5748. bnx2x_cl45_write(bp, phy,
  5749. MDIO_PMA_DEVAD,
  5750. MDIO_PMA_REG_8481_LED2_MASK,
  5751. 0x20);
  5752. bnx2x_cl45_write(bp, phy,
  5753. MDIO_PMA_DEVAD,
  5754. MDIO_PMA_REG_8481_LED3_MASK,
  5755. 0x20);
  5756. bnx2x_cl45_write(bp, phy,
  5757. MDIO_PMA_DEVAD,
  5758. MDIO_PMA_REG_8481_LED5_MASK,
  5759. 0x0);
  5760. } else {
  5761. bnx2x_cl45_write(bp, phy,
  5762. MDIO_PMA_DEVAD,
  5763. MDIO_PMA_REG_8481_LED1_MASK,
  5764. 0x20);
  5765. }
  5766. break;
  5767. case LED_MODE_OPER:
  5768. DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE OPER\n", params->port);
  5769. if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
  5770. SHARED_HW_CFG_LED_EXTPHY1) {
  5771. /* Set control reg */
  5772. bnx2x_cl45_read(bp, phy,
  5773. MDIO_PMA_DEVAD,
  5774. MDIO_PMA_REG_8481_LINK_SIGNAL,
  5775. &val);
  5776. if (!((val &
  5777. MDIO_PMA_REG_8481_LINK_SIGNAL_LED4_ENABLE_MASK)
  5778. >> MDIO_PMA_REG_8481_LINK_SIGNAL_LED4_ENABLE_SHIFT)) {
  5779. DP(NETIF_MSG_LINK, "Setting LINK_SIGNAL\n");
  5780. bnx2x_cl45_write(bp, phy,
  5781. MDIO_PMA_DEVAD,
  5782. MDIO_PMA_REG_8481_LINK_SIGNAL,
  5783. 0xa492);
  5784. }
  5785. /* Set LED masks */
  5786. bnx2x_cl45_write(bp, phy,
  5787. MDIO_PMA_DEVAD,
  5788. MDIO_PMA_REG_8481_LED1_MASK,
  5789. 0x10);
  5790. bnx2x_cl45_write(bp, phy,
  5791. MDIO_PMA_DEVAD,
  5792. MDIO_PMA_REG_8481_LED2_MASK,
  5793. 0x80);
  5794. bnx2x_cl45_write(bp, phy,
  5795. MDIO_PMA_DEVAD,
  5796. MDIO_PMA_REG_8481_LED3_MASK,
  5797. 0x98);
  5798. bnx2x_cl45_write(bp, phy,
  5799. MDIO_PMA_DEVAD,
  5800. MDIO_PMA_REG_8481_LED5_MASK,
  5801. 0x40);
  5802. } else {
  5803. bnx2x_cl45_write(bp, phy,
  5804. MDIO_PMA_DEVAD,
  5805. MDIO_PMA_REG_8481_LED1_MASK,
  5806. 0x80);
  5807. /* Tell LED3 to blink on source */
  5808. bnx2x_cl45_read(bp, phy,
  5809. MDIO_PMA_DEVAD,
  5810. MDIO_PMA_REG_8481_LINK_SIGNAL,
  5811. &val);
  5812. val &= ~(7<<6);
  5813. val |= (1<<6); /* A83B[8:6]= 1 */
  5814. bnx2x_cl45_write(bp, phy,
  5815. MDIO_PMA_DEVAD,
  5816. MDIO_PMA_REG_8481_LINK_SIGNAL,
  5817. val);
  5818. }
  5819. break;
  5820. }
  5821. }
  5822. /******************************************************************/
  5823. /* SFX7101 PHY SECTION */
  5824. /******************************************************************/
  5825. static void bnx2x_7101_config_loopback(struct bnx2x_phy *phy,
  5826. struct link_params *params)
  5827. {
  5828. struct bnx2x *bp = params->bp;
  5829. /* SFX7101_XGXS_TEST1 */
  5830. bnx2x_cl45_write(bp, phy,
  5831. MDIO_XS_DEVAD, MDIO_XS_SFX7101_XGXS_TEST1, 0x100);
  5832. }
  5833. static u8 bnx2x_7101_config_init(struct bnx2x_phy *phy,
  5834. struct link_params *params,
  5835. struct link_vars *vars)
  5836. {
  5837. u16 fw_ver1, fw_ver2, val;
  5838. struct bnx2x *bp = params->bp;
  5839. DP(NETIF_MSG_LINK, "Setting the SFX7101 LASI indication\n");
  5840. /* Restore normal power mode*/
  5841. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
  5842. MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
  5843. /* HW reset */
  5844. bnx2x_ext_phy_hw_reset(bp, params->port);
  5845. bnx2x_wait_reset_complete(bp, phy, params);
  5846. bnx2x_cl45_write(bp, phy,
  5847. MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_CTRL, 0x1);
  5848. DP(NETIF_MSG_LINK, "Setting the SFX7101 LED to blink on traffic\n");
  5849. bnx2x_cl45_write(bp, phy,
  5850. MDIO_PMA_DEVAD, MDIO_PMA_REG_7107_LED_CNTL, (1<<3));
  5851. bnx2x_ext_phy_set_pause(params, phy, vars);
  5852. /* Restart autoneg */
  5853. bnx2x_cl45_read(bp, phy,
  5854. MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, &val);
  5855. val |= 0x200;
  5856. bnx2x_cl45_write(bp, phy,
  5857. MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, val);
  5858. /* Save spirom version */
  5859. bnx2x_cl45_read(bp, phy,
  5860. MDIO_PMA_DEVAD, MDIO_PMA_REG_7101_VER1, &fw_ver1);
  5861. bnx2x_cl45_read(bp, phy,
  5862. MDIO_PMA_DEVAD, MDIO_PMA_REG_7101_VER2, &fw_ver2);
  5863. bnx2x_save_spirom_version(bp, params->port,
  5864. (u32)(fw_ver1<<16 | fw_ver2), phy->ver_addr);
  5865. return 0;
  5866. }
  5867. static u8 bnx2x_7101_read_status(struct bnx2x_phy *phy,
  5868. struct link_params *params,
  5869. struct link_vars *vars)
  5870. {
  5871. struct bnx2x *bp = params->bp;
  5872. u8 link_up;
  5873. u16 val1, val2;
  5874. bnx2x_cl45_read(bp, phy,
  5875. MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS, &val2);
  5876. bnx2x_cl45_read(bp, phy,
  5877. MDIO_PMA_DEVAD, MDIO_PMA_REG_LASI_STATUS, &val1);
  5878. DP(NETIF_MSG_LINK, "10G-base-T LASI status 0x%x->0x%x\n",
  5879. val2, val1);
  5880. bnx2x_cl45_read(bp, phy,
  5881. MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
  5882. bnx2x_cl45_read(bp, phy,
  5883. MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
  5884. DP(NETIF_MSG_LINK, "10G-base-T PMA status 0x%x->0x%x\n",
  5885. val2, val1);
  5886. link_up = ((val1 & 4) == 4);
  5887. /* if link is up print the AN outcome of the SFX7101 PHY */
  5888. if (link_up) {
  5889. bnx2x_cl45_read(bp, phy,
  5890. MDIO_AN_DEVAD, MDIO_AN_REG_MASTER_STATUS,
  5891. &val2);
  5892. vars->line_speed = SPEED_10000;
  5893. vars->duplex = DUPLEX_FULL;
  5894. DP(NETIF_MSG_LINK, "SFX7101 AN status 0x%x->Master=%x\n",
  5895. val2, (val2 & (1<<14)));
  5896. bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
  5897. bnx2x_ext_phy_resolve_fc(phy, params, vars);
  5898. }
  5899. return link_up;
  5900. }
  5901. static u8 bnx2x_7101_format_ver(u32 spirom_ver, u8 *str, u16 *len)
  5902. {
  5903. if (*len < 5)
  5904. return -EINVAL;
  5905. str[0] = (spirom_ver & 0xFF);
  5906. str[1] = (spirom_ver & 0xFF00) >> 8;
  5907. str[2] = (spirom_ver & 0xFF0000) >> 16;
  5908. str[3] = (spirom_ver & 0xFF000000) >> 24;
  5909. str[4] = '\0';
  5910. *len -= 5;
  5911. return 0;
  5912. }
  5913. void bnx2x_sfx7101_sp_sw_reset(struct bnx2x *bp, struct bnx2x_phy *phy)
  5914. {
  5915. u16 val, cnt;
  5916. bnx2x_cl45_read(bp, phy,
  5917. MDIO_PMA_DEVAD,
  5918. MDIO_PMA_REG_7101_RESET, &val);
  5919. for (cnt = 0; cnt < 10; cnt++) {
  5920. msleep(50);
  5921. /* Writes a self-clearing reset */
  5922. bnx2x_cl45_write(bp, phy,
  5923. MDIO_PMA_DEVAD,
  5924. MDIO_PMA_REG_7101_RESET,
  5925. (val | (1<<15)));
  5926. /* Wait for clear */
  5927. bnx2x_cl45_read(bp, phy,
  5928. MDIO_PMA_DEVAD,
  5929. MDIO_PMA_REG_7101_RESET, &val);
  5930. if ((val & (1<<15)) == 0)
  5931. break;
  5932. }
  5933. }
  5934. static void bnx2x_7101_hw_reset(struct bnx2x_phy *phy,
  5935. struct link_params *params) {
  5936. /* Low power mode is controlled by GPIO 2 */
  5937. bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_2,
  5938. MISC_REGISTERS_GPIO_OUTPUT_LOW, params->port);
  5939. /* The PHY reset is controlled by GPIO 1 */
  5940. bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
  5941. MISC_REGISTERS_GPIO_OUTPUT_LOW, params->port);
  5942. }
  5943. static void bnx2x_7101_set_link_led(struct bnx2x_phy *phy,
  5944. struct link_params *params, u8 mode)
  5945. {
  5946. u16 val = 0;
  5947. struct bnx2x *bp = params->bp;
  5948. switch (mode) {
  5949. case LED_MODE_FRONT_PANEL_OFF:
  5950. case LED_MODE_OFF:
  5951. val = 2;
  5952. break;
  5953. case LED_MODE_ON:
  5954. val = 1;
  5955. break;
  5956. case LED_MODE_OPER:
  5957. val = 0;
  5958. break;
  5959. }
  5960. bnx2x_cl45_write(bp, phy,
  5961. MDIO_PMA_DEVAD,
  5962. MDIO_PMA_REG_7107_LINK_LED_CNTL,
  5963. val);
  5964. }
  5965. /******************************************************************/
  5966. /* STATIC PHY DECLARATION */
  5967. /******************************************************************/
  5968. static struct bnx2x_phy phy_null = {
  5969. .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN,
  5970. .addr = 0,
  5971. .flags = FLAGS_INIT_XGXS_FIRST,
  5972. .def_md_devad = 0,
  5973. .reserved = 0,
  5974. .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  5975. .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  5976. .mdio_ctrl = 0,
  5977. .supported = 0,
  5978. .media_type = ETH_PHY_NOT_PRESENT,
  5979. .ver_addr = 0,
  5980. .req_flow_ctrl = 0,
  5981. .req_line_speed = 0,
  5982. .speed_cap_mask = 0,
  5983. .req_duplex = 0,
  5984. .rsrv = 0,
  5985. .config_init = (config_init_t)NULL,
  5986. .read_status = (read_status_t)NULL,
  5987. .link_reset = (link_reset_t)NULL,
  5988. .config_loopback = (config_loopback_t)NULL,
  5989. .format_fw_ver = (format_fw_ver_t)NULL,
  5990. .hw_reset = (hw_reset_t)NULL,
  5991. .set_link_led = (set_link_led_t)NULL,
  5992. .phy_specific_func = (phy_specific_func_t)NULL
  5993. };
  5994. static struct bnx2x_phy phy_serdes = {
  5995. .type = PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT,
  5996. .addr = 0xff,
  5997. .flags = 0,
  5998. .def_md_devad = 0,
  5999. .reserved = 0,
  6000. .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  6001. .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  6002. .mdio_ctrl = 0,
  6003. .supported = (SUPPORTED_10baseT_Half |
  6004. SUPPORTED_10baseT_Full |
  6005. SUPPORTED_100baseT_Half |
  6006. SUPPORTED_100baseT_Full |
  6007. SUPPORTED_1000baseT_Full |
  6008. SUPPORTED_2500baseX_Full |
  6009. SUPPORTED_TP |
  6010. SUPPORTED_Autoneg |
  6011. SUPPORTED_Pause |
  6012. SUPPORTED_Asym_Pause),
  6013. .media_type = ETH_PHY_UNSPECIFIED,
  6014. .ver_addr = 0,
  6015. .req_flow_ctrl = 0,
  6016. .req_line_speed = 0,
  6017. .speed_cap_mask = 0,
  6018. .req_duplex = 0,
  6019. .rsrv = 0,
  6020. .config_init = (config_init_t)bnx2x_init_serdes,
  6021. .read_status = (read_status_t)bnx2x_link_settings_status,
  6022. .link_reset = (link_reset_t)bnx2x_int_link_reset,
  6023. .config_loopback = (config_loopback_t)NULL,
  6024. .format_fw_ver = (format_fw_ver_t)NULL,
  6025. .hw_reset = (hw_reset_t)NULL,
  6026. .set_link_led = (set_link_led_t)NULL,
  6027. .phy_specific_func = (phy_specific_func_t)NULL
  6028. };
  6029. static struct bnx2x_phy phy_xgxs = {
  6030. .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT,
  6031. .addr = 0xff,
  6032. .flags = 0,
  6033. .def_md_devad = 0,
  6034. .reserved = 0,
  6035. .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  6036. .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  6037. .mdio_ctrl = 0,
  6038. .supported = (SUPPORTED_10baseT_Half |
  6039. SUPPORTED_10baseT_Full |
  6040. SUPPORTED_100baseT_Half |
  6041. SUPPORTED_100baseT_Full |
  6042. SUPPORTED_1000baseT_Full |
  6043. SUPPORTED_2500baseX_Full |
  6044. SUPPORTED_10000baseT_Full |
  6045. SUPPORTED_FIBRE |
  6046. SUPPORTED_Autoneg |
  6047. SUPPORTED_Pause |
  6048. SUPPORTED_Asym_Pause),
  6049. .media_type = ETH_PHY_UNSPECIFIED,
  6050. .ver_addr = 0,
  6051. .req_flow_ctrl = 0,
  6052. .req_line_speed = 0,
  6053. .speed_cap_mask = 0,
  6054. .req_duplex = 0,
  6055. .rsrv = 0,
  6056. .config_init = (config_init_t)bnx2x_init_xgxs,
  6057. .read_status = (read_status_t)bnx2x_link_settings_status,
  6058. .link_reset = (link_reset_t)bnx2x_int_link_reset,
  6059. .config_loopback = (config_loopback_t)bnx2x_set_xgxs_loopback,
  6060. .format_fw_ver = (format_fw_ver_t)NULL,
  6061. .hw_reset = (hw_reset_t)NULL,
  6062. .set_link_led = (set_link_led_t)NULL,
  6063. .phy_specific_func = (phy_specific_func_t)NULL
  6064. };
  6065. static struct bnx2x_phy phy_7101 = {
  6066. .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101,
  6067. .addr = 0xff,
  6068. .flags = FLAGS_FAN_FAILURE_DET_REQ,
  6069. .def_md_devad = 0,
  6070. .reserved = 0,
  6071. .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  6072. .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  6073. .mdio_ctrl = 0,
  6074. .supported = (SUPPORTED_10000baseT_Full |
  6075. SUPPORTED_TP |
  6076. SUPPORTED_Autoneg |
  6077. SUPPORTED_Pause |
  6078. SUPPORTED_Asym_Pause),
  6079. .media_type = ETH_PHY_BASE_T,
  6080. .ver_addr = 0,
  6081. .req_flow_ctrl = 0,
  6082. .req_line_speed = 0,
  6083. .speed_cap_mask = 0,
  6084. .req_duplex = 0,
  6085. .rsrv = 0,
  6086. .config_init = (config_init_t)bnx2x_7101_config_init,
  6087. .read_status = (read_status_t)bnx2x_7101_read_status,
  6088. .link_reset = (link_reset_t)bnx2x_common_ext_link_reset,
  6089. .config_loopback = (config_loopback_t)bnx2x_7101_config_loopback,
  6090. .format_fw_ver = (format_fw_ver_t)bnx2x_7101_format_ver,
  6091. .hw_reset = (hw_reset_t)bnx2x_7101_hw_reset,
  6092. .set_link_led = (set_link_led_t)bnx2x_7101_set_link_led,
  6093. .phy_specific_func = (phy_specific_func_t)NULL
  6094. };
  6095. static struct bnx2x_phy phy_8073 = {
  6096. .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073,
  6097. .addr = 0xff,
  6098. .flags = FLAGS_HW_LOCK_REQUIRED,
  6099. .def_md_devad = 0,
  6100. .reserved = 0,
  6101. .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  6102. .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  6103. .mdio_ctrl = 0,
  6104. .supported = (SUPPORTED_10000baseT_Full |
  6105. SUPPORTED_2500baseX_Full |
  6106. SUPPORTED_1000baseT_Full |
  6107. SUPPORTED_FIBRE |
  6108. SUPPORTED_Autoneg |
  6109. SUPPORTED_Pause |
  6110. SUPPORTED_Asym_Pause),
  6111. .media_type = ETH_PHY_UNSPECIFIED,
  6112. .ver_addr = 0,
  6113. .req_flow_ctrl = 0,
  6114. .req_line_speed = 0,
  6115. .speed_cap_mask = 0,
  6116. .req_duplex = 0,
  6117. .rsrv = 0,
  6118. .config_init = (config_init_t)bnx2x_8073_config_init,
  6119. .read_status = (read_status_t)bnx2x_8073_read_status,
  6120. .link_reset = (link_reset_t)bnx2x_8073_link_reset,
  6121. .config_loopback = (config_loopback_t)NULL,
  6122. .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
  6123. .hw_reset = (hw_reset_t)NULL,
  6124. .set_link_led = (set_link_led_t)NULL,
  6125. .phy_specific_func = (phy_specific_func_t)NULL
  6126. };
  6127. static struct bnx2x_phy phy_8705 = {
  6128. .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705,
  6129. .addr = 0xff,
  6130. .flags = FLAGS_INIT_XGXS_FIRST,
  6131. .def_md_devad = 0,
  6132. .reserved = 0,
  6133. .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  6134. .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  6135. .mdio_ctrl = 0,
  6136. .supported = (SUPPORTED_10000baseT_Full |
  6137. SUPPORTED_FIBRE |
  6138. SUPPORTED_Pause |
  6139. SUPPORTED_Asym_Pause),
  6140. .media_type = ETH_PHY_XFP_FIBER,
  6141. .ver_addr = 0,
  6142. .req_flow_ctrl = 0,
  6143. .req_line_speed = 0,
  6144. .speed_cap_mask = 0,
  6145. .req_duplex = 0,
  6146. .rsrv = 0,
  6147. .config_init = (config_init_t)bnx2x_8705_config_init,
  6148. .read_status = (read_status_t)bnx2x_8705_read_status,
  6149. .link_reset = (link_reset_t)bnx2x_common_ext_link_reset,
  6150. .config_loopback = (config_loopback_t)NULL,
  6151. .format_fw_ver = (format_fw_ver_t)bnx2x_null_format_ver,
  6152. .hw_reset = (hw_reset_t)NULL,
  6153. .set_link_led = (set_link_led_t)NULL,
  6154. .phy_specific_func = (phy_specific_func_t)NULL
  6155. };
  6156. static struct bnx2x_phy phy_8706 = {
  6157. .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706,
  6158. .addr = 0xff,
  6159. .flags = FLAGS_INIT_XGXS_FIRST,
  6160. .def_md_devad = 0,
  6161. .reserved = 0,
  6162. .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  6163. .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  6164. .mdio_ctrl = 0,
  6165. .supported = (SUPPORTED_10000baseT_Full |
  6166. SUPPORTED_1000baseT_Full |
  6167. SUPPORTED_FIBRE |
  6168. SUPPORTED_Pause |
  6169. SUPPORTED_Asym_Pause),
  6170. .media_type = ETH_PHY_SFP_FIBER,
  6171. .ver_addr = 0,
  6172. .req_flow_ctrl = 0,
  6173. .req_line_speed = 0,
  6174. .speed_cap_mask = 0,
  6175. .req_duplex = 0,
  6176. .rsrv = 0,
  6177. .config_init = (config_init_t)bnx2x_8706_config_init,
  6178. .read_status = (read_status_t)bnx2x_8706_read_status,
  6179. .link_reset = (link_reset_t)bnx2x_common_ext_link_reset,
  6180. .config_loopback = (config_loopback_t)NULL,
  6181. .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
  6182. .hw_reset = (hw_reset_t)NULL,
  6183. .set_link_led = (set_link_led_t)NULL,
  6184. .phy_specific_func = (phy_specific_func_t)NULL
  6185. };
  6186. static struct bnx2x_phy phy_8726 = {
  6187. .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726,
  6188. .addr = 0xff,
  6189. .flags = (FLAGS_HW_LOCK_REQUIRED |
  6190. FLAGS_INIT_XGXS_FIRST),
  6191. .def_md_devad = 0,
  6192. .reserved = 0,
  6193. .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  6194. .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  6195. .mdio_ctrl = 0,
  6196. .supported = (SUPPORTED_10000baseT_Full |
  6197. SUPPORTED_1000baseT_Full |
  6198. SUPPORTED_Autoneg |
  6199. SUPPORTED_FIBRE |
  6200. SUPPORTED_Pause |
  6201. SUPPORTED_Asym_Pause),
  6202. .media_type = ETH_PHY_SFP_FIBER,
  6203. .ver_addr = 0,
  6204. .req_flow_ctrl = 0,
  6205. .req_line_speed = 0,
  6206. .speed_cap_mask = 0,
  6207. .req_duplex = 0,
  6208. .rsrv = 0,
  6209. .config_init = (config_init_t)bnx2x_8726_config_init,
  6210. .read_status = (read_status_t)bnx2x_8726_read_status,
  6211. .link_reset = (link_reset_t)bnx2x_8726_link_reset,
  6212. .config_loopback = (config_loopback_t)bnx2x_8726_config_loopback,
  6213. .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
  6214. .hw_reset = (hw_reset_t)NULL,
  6215. .set_link_led = (set_link_led_t)NULL,
  6216. .phy_specific_func = (phy_specific_func_t)NULL
  6217. };
  6218. static struct bnx2x_phy phy_8727 = {
  6219. .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727,
  6220. .addr = 0xff,
  6221. .flags = FLAGS_FAN_FAILURE_DET_REQ,
  6222. .def_md_devad = 0,
  6223. .reserved = 0,
  6224. .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  6225. .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  6226. .mdio_ctrl = 0,
  6227. .supported = (SUPPORTED_10000baseT_Full |
  6228. SUPPORTED_1000baseT_Full |
  6229. SUPPORTED_FIBRE |
  6230. SUPPORTED_Pause |
  6231. SUPPORTED_Asym_Pause),
  6232. .media_type = ETH_PHY_SFP_FIBER,
  6233. .ver_addr = 0,
  6234. .req_flow_ctrl = 0,
  6235. .req_line_speed = 0,
  6236. .speed_cap_mask = 0,
  6237. .req_duplex = 0,
  6238. .rsrv = 0,
  6239. .config_init = (config_init_t)bnx2x_8727_config_init,
  6240. .read_status = (read_status_t)bnx2x_8727_read_status,
  6241. .link_reset = (link_reset_t)bnx2x_8727_link_reset,
  6242. .config_loopback = (config_loopback_t)NULL,
  6243. .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
  6244. .hw_reset = (hw_reset_t)bnx2x_8727_hw_reset,
  6245. .set_link_led = (set_link_led_t)bnx2x_8727_set_link_led,
  6246. .phy_specific_func = (phy_specific_func_t)bnx2x_8727_specific_func
  6247. };
  6248. static struct bnx2x_phy phy_8481 = {
  6249. .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481,
  6250. .addr = 0xff,
  6251. .flags = FLAGS_FAN_FAILURE_DET_REQ |
  6252. FLAGS_REARM_LATCH_SIGNAL,
  6253. .def_md_devad = 0,
  6254. .reserved = 0,
  6255. .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  6256. .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  6257. .mdio_ctrl = 0,
  6258. .supported = (SUPPORTED_10baseT_Half |
  6259. SUPPORTED_10baseT_Full |
  6260. SUPPORTED_100baseT_Half |
  6261. SUPPORTED_100baseT_Full |
  6262. SUPPORTED_1000baseT_Full |
  6263. SUPPORTED_10000baseT_Full |
  6264. SUPPORTED_TP |
  6265. SUPPORTED_Autoneg |
  6266. SUPPORTED_Pause |
  6267. SUPPORTED_Asym_Pause),
  6268. .media_type = ETH_PHY_BASE_T,
  6269. .ver_addr = 0,
  6270. .req_flow_ctrl = 0,
  6271. .req_line_speed = 0,
  6272. .speed_cap_mask = 0,
  6273. .req_duplex = 0,
  6274. .rsrv = 0,
  6275. .config_init = (config_init_t)bnx2x_8481_config_init,
  6276. .read_status = (read_status_t)bnx2x_848xx_read_status,
  6277. .link_reset = (link_reset_t)bnx2x_8481_link_reset,
  6278. .config_loopback = (config_loopback_t)NULL,
  6279. .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
  6280. .hw_reset = (hw_reset_t)bnx2x_8481_hw_reset,
  6281. .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
  6282. .phy_specific_func = (phy_specific_func_t)NULL
  6283. };
  6284. static struct bnx2x_phy phy_84823 = {
  6285. .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823,
  6286. .addr = 0xff,
  6287. .flags = FLAGS_FAN_FAILURE_DET_REQ |
  6288. FLAGS_REARM_LATCH_SIGNAL,
  6289. .def_md_devad = 0,
  6290. .reserved = 0,
  6291. .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  6292. .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  6293. .mdio_ctrl = 0,
  6294. .supported = (SUPPORTED_10baseT_Half |
  6295. SUPPORTED_10baseT_Full |
  6296. SUPPORTED_100baseT_Half |
  6297. SUPPORTED_100baseT_Full |
  6298. SUPPORTED_1000baseT_Full |
  6299. SUPPORTED_10000baseT_Full |
  6300. SUPPORTED_TP |
  6301. SUPPORTED_Autoneg |
  6302. SUPPORTED_Pause |
  6303. SUPPORTED_Asym_Pause),
  6304. .media_type = ETH_PHY_BASE_T,
  6305. .ver_addr = 0,
  6306. .req_flow_ctrl = 0,
  6307. .req_line_speed = 0,
  6308. .speed_cap_mask = 0,
  6309. .req_duplex = 0,
  6310. .rsrv = 0,
  6311. .config_init = (config_init_t)bnx2x_848x3_config_init,
  6312. .read_status = (read_status_t)bnx2x_848xx_read_status,
  6313. .link_reset = (link_reset_t)bnx2x_848x3_link_reset,
  6314. .config_loopback = (config_loopback_t)NULL,
  6315. .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
  6316. .hw_reset = (hw_reset_t)NULL,
  6317. .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
  6318. .phy_specific_func = (phy_specific_func_t)NULL
  6319. };
  6320. static struct bnx2x_phy phy_84833 = {
  6321. .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833,
  6322. .addr = 0xff,
  6323. .flags = FLAGS_FAN_FAILURE_DET_REQ |
  6324. FLAGS_REARM_LATCH_SIGNAL,
  6325. .def_md_devad = 0,
  6326. .reserved = 0,
  6327. .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  6328. .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  6329. .mdio_ctrl = 0,
  6330. .supported = (SUPPORTED_10baseT_Half |
  6331. SUPPORTED_10baseT_Full |
  6332. SUPPORTED_100baseT_Half |
  6333. SUPPORTED_100baseT_Full |
  6334. SUPPORTED_1000baseT_Full |
  6335. SUPPORTED_10000baseT_Full |
  6336. SUPPORTED_TP |
  6337. SUPPORTED_Autoneg |
  6338. SUPPORTED_Pause |
  6339. SUPPORTED_Asym_Pause),
  6340. .media_type = ETH_PHY_BASE_T,
  6341. .ver_addr = 0,
  6342. .req_flow_ctrl = 0,
  6343. .req_line_speed = 0,
  6344. .speed_cap_mask = 0,
  6345. .req_duplex = 0,
  6346. .rsrv = 0,
  6347. .config_init = (config_init_t)bnx2x_848x3_config_init,
  6348. .read_status = (read_status_t)bnx2x_848xx_read_status,
  6349. .link_reset = (link_reset_t)bnx2x_848x3_link_reset,
  6350. .config_loopback = (config_loopback_t)NULL,
  6351. .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
  6352. .hw_reset = (hw_reset_t)NULL,
  6353. .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
  6354. .phy_specific_func = (phy_specific_func_t)NULL
  6355. };
  6356. /*****************************************************************/
  6357. /* */
  6358. /* Populate the phy according. Main function: bnx2x_populate_phy */
  6359. /* */
  6360. /*****************************************************************/
  6361. static void bnx2x_populate_preemphasis(struct bnx2x *bp, u32 shmem_base,
  6362. struct bnx2x_phy *phy, u8 port,
  6363. u8 phy_index)
  6364. {
  6365. /* Get the 4 lanes xgxs config rx and tx */
  6366. u32 rx = 0, tx = 0, i;
  6367. for (i = 0; i < 2; i++) {
  6368. /*
  6369. * INT_PHY and EXT_PHY1 share the same value location in the
  6370. * shmem. When num_phys is greater than 1, than this value
  6371. * applies only to EXT_PHY1
  6372. */
  6373. if (phy_index == INT_PHY || phy_index == EXT_PHY1) {
  6374. rx = REG_RD(bp, shmem_base +
  6375. offsetof(struct shmem_region,
  6376. dev_info.port_hw_config[port].xgxs_config_rx[i<<1]));
  6377. tx = REG_RD(bp, shmem_base +
  6378. offsetof(struct shmem_region,
  6379. dev_info.port_hw_config[port].xgxs_config_tx[i<<1]));
  6380. } else {
  6381. rx = REG_RD(bp, shmem_base +
  6382. offsetof(struct shmem_region,
  6383. dev_info.port_hw_config[port].xgxs_config2_rx[i<<1]));
  6384. tx = REG_RD(bp, shmem_base +
  6385. offsetof(struct shmem_region,
  6386. dev_info.port_hw_config[port].xgxs_config2_rx[i<<1]));
  6387. }
  6388. phy->rx_preemphasis[i << 1] = ((rx>>16) & 0xffff);
  6389. phy->rx_preemphasis[(i << 1) + 1] = (rx & 0xffff);
  6390. phy->tx_preemphasis[i << 1] = ((tx>>16) & 0xffff);
  6391. phy->tx_preemphasis[(i << 1) + 1] = (tx & 0xffff);
  6392. }
  6393. }
  6394. static u32 bnx2x_get_ext_phy_config(struct bnx2x *bp, u32 shmem_base,
  6395. u8 phy_index, u8 port)
  6396. {
  6397. u32 ext_phy_config = 0;
  6398. switch (phy_index) {
  6399. case EXT_PHY1:
  6400. ext_phy_config = REG_RD(bp, shmem_base +
  6401. offsetof(struct shmem_region,
  6402. dev_info.port_hw_config[port].external_phy_config));
  6403. break;
  6404. case EXT_PHY2:
  6405. ext_phy_config = REG_RD(bp, shmem_base +
  6406. offsetof(struct shmem_region,
  6407. dev_info.port_hw_config[port].external_phy_config2));
  6408. break;
  6409. default:
  6410. DP(NETIF_MSG_LINK, "Invalid phy_index %d\n", phy_index);
  6411. return -EINVAL;
  6412. }
  6413. return ext_phy_config;
  6414. }
  6415. static u8 bnx2x_populate_int_phy(struct bnx2x *bp, u32 shmem_base, u8 port,
  6416. struct bnx2x_phy *phy)
  6417. {
  6418. u32 phy_addr;
  6419. u32 chip_id;
  6420. u32 switch_cfg = (REG_RD(bp, shmem_base +
  6421. offsetof(struct shmem_region,
  6422. dev_info.port_feature_config[port].link_config)) &
  6423. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  6424. chip_id = REG_RD(bp, MISC_REG_CHIP_NUM) << 16;
  6425. switch (switch_cfg) {
  6426. case SWITCH_CFG_1G:
  6427. phy_addr = REG_RD(bp,
  6428. NIG_REG_SERDES0_CTRL_PHY_ADDR +
  6429. port * 0x10);
  6430. *phy = phy_serdes;
  6431. break;
  6432. case SWITCH_CFG_10G:
  6433. phy_addr = REG_RD(bp,
  6434. NIG_REG_XGXS0_CTRL_PHY_ADDR +
  6435. port * 0x18);
  6436. *phy = phy_xgxs;
  6437. break;
  6438. default:
  6439. DP(NETIF_MSG_LINK, "Invalid switch_cfg\n");
  6440. return -EINVAL;
  6441. }
  6442. phy->addr = (u8)phy_addr;
  6443. phy->mdio_ctrl = bnx2x_get_emac_base(bp,
  6444. SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH,
  6445. port);
  6446. if (CHIP_IS_E2(bp))
  6447. phy->def_md_devad = E2_DEFAULT_PHY_DEV_ADDR;
  6448. else
  6449. phy->def_md_devad = DEFAULT_PHY_DEV_ADDR;
  6450. DP(NETIF_MSG_LINK, "Internal phy port=%d, addr=0x%x, mdio_ctl=0x%x\n",
  6451. port, phy->addr, phy->mdio_ctrl);
  6452. bnx2x_populate_preemphasis(bp, shmem_base, phy, port, INT_PHY);
  6453. return 0;
  6454. }
  6455. static u8 bnx2x_populate_ext_phy(struct bnx2x *bp,
  6456. u8 phy_index,
  6457. u32 shmem_base,
  6458. u32 shmem2_base,
  6459. u8 port,
  6460. struct bnx2x_phy *phy)
  6461. {
  6462. u32 ext_phy_config, phy_type, config2;
  6463. u32 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH;
  6464. ext_phy_config = bnx2x_get_ext_phy_config(bp, shmem_base,
  6465. phy_index, port);
  6466. phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  6467. /* Select the phy type */
  6468. switch (phy_type) {
  6469. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
  6470. mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_SWAPPED;
  6471. *phy = phy_8073;
  6472. break;
  6473. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705:
  6474. *phy = phy_8705;
  6475. break;
  6476. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706:
  6477. *phy = phy_8706;
  6478. break;
  6479. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
  6480. mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
  6481. *phy = phy_8726;
  6482. break;
  6483. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727_NOC:
  6484. /* BCM8727_NOC => BCM8727 no over current */
  6485. mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
  6486. *phy = phy_8727;
  6487. phy->flags |= FLAGS_NOC;
  6488. break;
  6489. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
  6490. mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
  6491. *phy = phy_8727;
  6492. break;
  6493. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481:
  6494. *phy = phy_8481;
  6495. break;
  6496. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823:
  6497. *phy = phy_84823;
  6498. break;
  6499. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833:
  6500. *phy = phy_84833;
  6501. break;
  6502. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
  6503. *phy = phy_7101;
  6504. break;
  6505. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
  6506. *phy = phy_null;
  6507. return -EINVAL;
  6508. default:
  6509. *phy = phy_null;
  6510. return 0;
  6511. }
  6512. phy->addr = XGXS_EXT_PHY_ADDR(ext_phy_config);
  6513. bnx2x_populate_preemphasis(bp, shmem_base, phy, port, phy_index);
  6514. /*
  6515. * The shmem address of the phy version is located on different
  6516. * structures. In case this structure is too old, do not set
  6517. * the address
  6518. */
  6519. config2 = REG_RD(bp, shmem_base + offsetof(struct shmem_region,
  6520. dev_info.shared_hw_config.config2));
  6521. if (phy_index == EXT_PHY1) {
  6522. phy->ver_addr = shmem_base + offsetof(struct shmem_region,
  6523. port_mb[port].ext_phy_fw_version);
  6524. /* Check specific mdc mdio settings */
  6525. if (config2 & SHARED_HW_CFG_MDC_MDIO_ACCESS1_MASK)
  6526. mdc_mdio_access = config2 &
  6527. SHARED_HW_CFG_MDC_MDIO_ACCESS1_MASK;
  6528. } else {
  6529. u32 size = REG_RD(bp, shmem2_base);
  6530. if (size >
  6531. offsetof(struct shmem2_region, ext_phy_fw_version2)) {
  6532. phy->ver_addr = shmem2_base +
  6533. offsetof(struct shmem2_region,
  6534. ext_phy_fw_version2[port]);
  6535. }
  6536. /* Check specific mdc mdio settings */
  6537. if (config2 & SHARED_HW_CFG_MDC_MDIO_ACCESS2_MASK)
  6538. mdc_mdio_access = (config2 &
  6539. SHARED_HW_CFG_MDC_MDIO_ACCESS2_MASK) >>
  6540. (SHARED_HW_CFG_MDC_MDIO_ACCESS2_SHIFT -
  6541. SHARED_HW_CFG_MDC_MDIO_ACCESS1_SHIFT);
  6542. }
  6543. phy->mdio_ctrl = bnx2x_get_emac_base(bp, mdc_mdio_access, port);
  6544. /*
  6545. * In case mdc/mdio_access of the external phy is different than the
  6546. * mdc/mdio access of the XGXS, a HW lock must be taken in each access
  6547. * to prevent one port interfere with another port's CL45 operations.
  6548. */
  6549. if (mdc_mdio_access != SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH)
  6550. phy->flags |= FLAGS_HW_LOCK_REQUIRED;
  6551. DP(NETIF_MSG_LINK, "phy_type 0x%x port %d found in index %d\n",
  6552. phy_type, port, phy_index);
  6553. DP(NETIF_MSG_LINK, " addr=0x%x, mdio_ctl=0x%x\n",
  6554. phy->addr, phy->mdio_ctrl);
  6555. return 0;
  6556. }
  6557. static u8 bnx2x_populate_phy(struct bnx2x *bp, u8 phy_index, u32 shmem_base,
  6558. u32 shmem2_base, u8 port, struct bnx2x_phy *phy)
  6559. {
  6560. u8 status = 0;
  6561. phy->type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN;
  6562. if (phy_index == INT_PHY)
  6563. return bnx2x_populate_int_phy(bp, shmem_base, port, phy);
  6564. status = bnx2x_populate_ext_phy(bp, phy_index, shmem_base, shmem2_base,
  6565. port, phy);
  6566. return status;
  6567. }
  6568. static void bnx2x_phy_def_cfg(struct link_params *params,
  6569. struct bnx2x_phy *phy,
  6570. u8 phy_index)
  6571. {
  6572. struct bnx2x *bp = params->bp;
  6573. u32 link_config;
  6574. /* Populate the default phy configuration for MF mode */
  6575. if (phy_index == EXT_PHY2) {
  6576. link_config = REG_RD(bp, params->shmem_base +
  6577. offsetof(struct shmem_region, dev_info.
  6578. port_feature_config[params->port].link_config2));
  6579. phy->speed_cap_mask = REG_RD(bp, params->shmem_base +
  6580. offsetof(struct shmem_region,
  6581. dev_info.
  6582. port_hw_config[params->port].speed_capability_mask2));
  6583. } else {
  6584. link_config = REG_RD(bp, params->shmem_base +
  6585. offsetof(struct shmem_region, dev_info.
  6586. port_feature_config[params->port].link_config));
  6587. phy->speed_cap_mask = REG_RD(bp, params->shmem_base +
  6588. offsetof(struct shmem_region,
  6589. dev_info.
  6590. port_hw_config[params->port].speed_capability_mask));
  6591. }
  6592. DP(NETIF_MSG_LINK, "Default config phy idx %x cfg 0x%x speed_cap_mask"
  6593. " 0x%x\n", phy_index, link_config, phy->speed_cap_mask);
  6594. phy->req_duplex = DUPLEX_FULL;
  6595. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  6596. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  6597. phy->req_duplex = DUPLEX_HALF;
  6598. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  6599. phy->req_line_speed = SPEED_10;
  6600. break;
  6601. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  6602. phy->req_duplex = DUPLEX_HALF;
  6603. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  6604. phy->req_line_speed = SPEED_100;
  6605. break;
  6606. case PORT_FEATURE_LINK_SPEED_1G:
  6607. phy->req_line_speed = SPEED_1000;
  6608. break;
  6609. case PORT_FEATURE_LINK_SPEED_2_5G:
  6610. phy->req_line_speed = SPEED_2500;
  6611. break;
  6612. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  6613. phy->req_line_speed = SPEED_10000;
  6614. break;
  6615. default:
  6616. phy->req_line_speed = SPEED_AUTO_NEG;
  6617. break;
  6618. }
  6619. switch (link_config & PORT_FEATURE_FLOW_CONTROL_MASK) {
  6620. case PORT_FEATURE_FLOW_CONTROL_AUTO:
  6621. phy->req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO;
  6622. break;
  6623. case PORT_FEATURE_FLOW_CONTROL_TX:
  6624. phy->req_flow_ctrl = BNX2X_FLOW_CTRL_TX;
  6625. break;
  6626. case PORT_FEATURE_FLOW_CONTROL_RX:
  6627. phy->req_flow_ctrl = BNX2X_FLOW_CTRL_RX;
  6628. break;
  6629. case PORT_FEATURE_FLOW_CONTROL_BOTH:
  6630. phy->req_flow_ctrl = BNX2X_FLOW_CTRL_BOTH;
  6631. break;
  6632. default:
  6633. phy->req_flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  6634. break;
  6635. }
  6636. }
  6637. u32 bnx2x_phy_selection(struct link_params *params)
  6638. {
  6639. u32 phy_config_swapped, prio_cfg;
  6640. u32 return_cfg = PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT;
  6641. phy_config_swapped = params->multi_phy_config &
  6642. PORT_HW_CFG_PHY_SWAPPED_ENABLED;
  6643. prio_cfg = params->multi_phy_config &
  6644. PORT_HW_CFG_PHY_SELECTION_MASK;
  6645. if (phy_config_swapped) {
  6646. switch (prio_cfg) {
  6647. case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
  6648. return_cfg = PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY;
  6649. break;
  6650. case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
  6651. return_cfg = PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY;
  6652. break;
  6653. case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
  6654. return_cfg = PORT_HW_CFG_PHY_SELECTION_FIRST_PHY;
  6655. break;
  6656. case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
  6657. return_cfg = PORT_HW_CFG_PHY_SELECTION_SECOND_PHY;
  6658. break;
  6659. }
  6660. } else
  6661. return_cfg = prio_cfg;
  6662. return return_cfg;
  6663. }
  6664. u8 bnx2x_phy_probe(struct link_params *params)
  6665. {
  6666. u8 phy_index, actual_phy_idx, link_cfg_idx;
  6667. u32 phy_config_swapped;
  6668. struct bnx2x *bp = params->bp;
  6669. struct bnx2x_phy *phy;
  6670. params->num_phys = 0;
  6671. DP(NETIF_MSG_LINK, "Begin phy probe\n");
  6672. phy_config_swapped = params->multi_phy_config &
  6673. PORT_HW_CFG_PHY_SWAPPED_ENABLED;
  6674. for (phy_index = INT_PHY; phy_index < MAX_PHYS;
  6675. phy_index++) {
  6676. link_cfg_idx = LINK_CONFIG_IDX(phy_index);
  6677. actual_phy_idx = phy_index;
  6678. if (phy_config_swapped) {
  6679. if (phy_index == EXT_PHY1)
  6680. actual_phy_idx = EXT_PHY2;
  6681. else if (phy_index == EXT_PHY2)
  6682. actual_phy_idx = EXT_PHY1;
  6683. }
  6684. DP(NETIF_MSG_LINK, "phy_config_swapped %x, phy_index %x,"
  6685. " actual_phy_idx %x\n", phy_config_swapped,
  6686. phy_index, actual_phy_idx);
  6687. phy = &params->phy[actual_phy_idx];
  6688. if (bnx2x_populate_phy(bp, phy_index, params->shmem_base,
  6689. params->shmem2_base, params->port,
  6690. phy) != 0) {
  6691. params->num_phys = 0;
  6692. DP(NETIF_MSG_LINK, "phy probe failed in phy index %d\n",
  6693. phy_index);
  6694. for (phy_index = INT_PHY;
  6695. phy_index < MAX_PHYS;
  6696. phy_index++)
  6697. *phy = phy_null;
  6698. return -EINVAL;
  6699. }
  6700. if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN)
  6701. break;
  6702. bnx2x_phy_def_cfg(params, phy, phy_index);
  6703. params->num_phys++;
  6704. }
  6705. DP(NETIF_MSG_LINK, "End phy probe. #phys found %x\n", params->num_phys);
  6706. return 0;
  6707. }
  6708. static void set_phy_vars(struct link_params *params)
  6709. {
  6710. struct bnx2x *bp = params->bp;
  6711. u8 actual_phy_idx, phy_index, link_cfg_idx;
  6712. u8 phy_config_swapped = params->multi_phy_config &
  6713. PORT_HW_CFG_PHY_SWAPPED_ENABLED;
  6714. for (phy_index = INT_PHY; phy_index < params->num_phys;
  6715. phy_index++) {
  6716. link_cfg_idx = LINK_CONFIG_IDX(phy_index);
  6717. actual_phy_idx = phy_index;
  6718. if (phy_config_swapped) {
  6719. if (phy_index == EXT_PHY1)
  6720. actual_phy_idx = EXT_PHY2;
  6721. else if (phy_index == EXT_PHY2)
  6722. actual_phy_idx = EXT_PHY1;
  6723. }
  6724. params->phy[actual_phy_idx].req_flow_ctrl =
  6725. params->req_flow_ctrl[link_cfg_idx];
  6726. params->phy[actual_phy_idx].req_line_speed =
  6727. params->req_line_speed[link_cfg_idx];
  6728. params->phy[actual_phy_idx].speed_cap_mask =
  6729. params->speed_cap_mask[link_cfg_idx];
  6730. params->phy[actual_phy_idx].req_duplex =
  6731. params->req_duplex[link_cfg_idx];
  6732. DP(NETIF_MSG_LINK, "req_flow_ctrl %x, req_line_speed %x,"
  6733. " speed_cap_mask %x\n",
  6734. params->phy[actual_phy_idx].req_flow_ctrl,
  6735. params->phy[actual_phy_idx].req_line_speed,
  6736. params->phy[actual_phy_idx].speed_cap_mask);
  6737. }
  6738. }
  6739. u8 bnx2x_phy_init(struct link_params *params, struct link_vars *vars)
  6740. {
  6741. struct bnx2x *bp = params->bp;
  6742. DP(NETIF_MSG_LINK, "Phy Initialization started\n");
  6743. DP(NETIF_MSG_LINK, "(1) req_speed %d, req_flowctrl %d\n",
  6744. params->req_line_speed[0], params->req_flow_ctrl[0]);
  6745. DP(NETIF_MSG_LINK, "(2) req_speed %d, req_flowctrl %d\n",
  6746. params->req_line_speed[1], params->req_flow_ctrl[1]);
  6747. vars->link_status = 0;
  6748. vars->phy_link_up = 0;
  6749. vars->link_up = 0;
  6750. vars->line_speed = 0;
  6751. vars->duplex = DUPLEX_FULL;
  6752. vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  6753. vars->mac_type = MAC_TYPE_NONE;
  6754. vars->phy_flags = 0;
  6755. /* disable attentions */
  6756. bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + params->port*4,
  6757. (NIG_MASK_XGXS0_LINK_STATUS |
  6758. NIG_MASK_XGXS0_LINK10G |
  6759. NIG_MASK_SERDES0_LINK_STATUS |
  6760. NIG_MASK_MI_INT));
  6761. bnx2x_emac_init(params, vars);
  6762. if (params->num_phys == 0) {
  6763. DP(NETIF_MSG_LINK, "No phy found for initialization !!\n");
  6764. return -EINVAL;
  6765. }
  6766. set_phy_vars(params);
  6767. DP(NETIF_MSG_LINK, "Num of phys on board: %d\n", params->num_phys);
  6768. if (params->loopback_mode == LOOPBACK_BMAC) {
  6769. vars->link_up = 1;
  6770. vars->line_speed = SPEED_10000;
  6771. vars->duplex = DUPLEX_FULL;
  6772. vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  6773. vars->mac_type = MAC_TYPE_BMAC;
  6774. vars->phy_flags = PHY_XGXS_FLAG;
  6775. bnx2x_xgxs_deassert(params);
  6776. /* set bmac loopback */
  6777. bnx2x_bmac_enable(params, vars, 1);
  6778. REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
  6779. } else if (params->loopback_mode == LOOPBACK_EMAC) {
  6780. vars->link_up = 1;
  6781. vars->line_speed = SPEED_1000;
  6782. vars->duplex = DUPLEX_FULL;
  6783. vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  6784. vars->mac_type = MAC_TYPE_EMAC;
  6785. vars->phy_flags = PHY_XGXS_FLAG;
  6786. bnx2x_xgxs_deassert(params);
  6787. /* set bmac loopback */
  6788. bnx2x_emac_enable(params, vars, 1);
  6789. bnx2x_emac_program(params, vars);
  6790. REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
  6791. } else if ((params->loopback_mode == LOOPBACK_XGXS) ||
  6792. (params->loopback_mode == LOOPBACK_EXT_PHY)) {
  6793. vars->link_up = 1;
  6794. vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  6795. vars->duplex = DUPLEX_FULL;
  6796. if (params->req_line_speed[0] == SPEED_1000) {
  6797. vars->line_speed = SPEED_1000;
  6798. vars->mac_type = MAC_TYPE_EMAC;
  6799. } else {
  6800. vars->line_speed = SPEED_10000;
  6801. vars->mac_type = MAC_TYPE_BMAC;
  6802. }
  6803. bnx2x_xgxs_deassert(params);
  6804. bnx2x_link_initialize(params, vars);
  6805. if (params->req_line_speed[0] == SPEED_1000) {
  6806. bnx2x_emac_program(params, vars);
  6807. bnx2x_emac_enable(params, vars, 0);
  6808. } else
  6809. bnx2x_bmac_enable(params, vars, 0);
  6810. if (params->loopback_mode == LOOPBACK_XGXS) {
  6811. /* set 10G XGXS loopback */
  6812. params->phy[INT_PHY].config_loopback(
  6813. &params->phy[INT_PHY],
  6814. params);
  6815. } else {
  6816. /* set external phy loopback */
  6817. u8 phy_index;
  6818. for (phy_index = EXT_PHY1;
  6819. phy_index < params->num_phys; phy_index++) {
  6820. if (params->phy[phy_index].config_loopback)
  6821. params->phy[phy_index].config_loopback(
  6822. &params->phy[phy_index],
  6823. params);
  6824. }
  6825. }
  6826. REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
  6827. bnx2x_set_led(params, vars,
  6828. LED_MODE_OPER, vars->line_speed);
  6829. } else
  6830. /* No loopback */
  6831. {
  6832. if (params->switch_cfg == SWITCH_CFG_10G)
  6833. bnx2x_xgxs_deassert(params);
  6834. else
  6835. bnx2x_serdes_deassert(bp, params->port);
  6836. bnx2x_link_initialize(params, vars);
  6837. msleep(30);
  6838. bnx2x_link_int_enable(params);
  6839. }
  6840. return 0;
  6841. }
  6842. u8 bnx2x_link_reset(struct link_params *params, struct link_vars *vars,
  6843. u8 reset_ext_phy)
  6844. {
  6845. struct bnx2x *bp = params->bp;
  6846. u8 phy_index, port = params->port, clear_latch_ind = 0;
  6847. DP(NETIF_MSG_LINK, "Resetting the link of port %d\n", port);
  6848. /* disable attentions */
  6849. vars->link_status = 0;
  6850. bnx2x_update_mng(params, vars->link_status);
  6851. bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4,
  6852. (NIG_MASK_XGXS0_LINK_STATUS |
  6853. NIG_MASK_XGXS0_LINK10G |
  6854. NIG_MASK_SERDES0_LINK_STATUS |
  6855. NIG_MASK_MI_INT));
  6856. /* activate nig drain */
  6857. REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 1);
  6858. /* disable nig egress interface */
  6859. REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0);
  6860. REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0);
  6861. /* Stop BigMac rx */
  6862. bnx2x_bmac_rx_disable(bp, port);
  6863. /* disable emac */
  6864. REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
  6865. msleep(10);
  6866. /* The PHY reset is controlled by GPIO 1
  6867. * Hold it as vars low
  6868. */
  6869. /* clear link led */
  6870. bnx2x_set_led(params, vars, LED_MODE_OFF, 0);
  6871. if (reset_ext_phy) {
  6872. for (phy_index = EXT_PHY1; phy_index < params->num_phys;
  6873. phy_index++) {
  6874. if (params->phy[phy_index].link_reset)
  6875. params->phy[phy_index].link_reset(
  6876. &params->phy[phy_index],
  6877. params);
  6878. if (params->phy[phy_index].flags &
  6879. FLAGS_REARM_LATCH_SIGNAL)
  6880. clear_latch_ind = 1;
  6881. }
  6882. }
  6883. if (clear_latch_ind) {
  6884. /* Clear latching indication */
  6885. bnx2x_rearm_latch_signal(bp, port, 0);
  6886. bnx2x_bits_dis(bp, NIG_REG_LATCH_BC_0 + port*4,
  6887. 1 << NIG_LATCH_BC_ENABLE_MI_INT);
  6888. }
  6889. if (params->phy[INT_PHY].link_reset)
  6890. params->phy[INT_PHY].link_reset(
  6891. &params->phy[INT_PHY], params);
  6892. /* reset BigMac */
  6893. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  6894. (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
  6895. /* disable nig ingress interface */
  6896. REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0);
  6897. REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0);
  6898. REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0);
  6899. REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0);
  6900. vars->link_up = 0;
  6901. return 0;
  6902. }
  6903. /****************************************************************************/
  6904. /* Common function */
  6905. /****************************************************************************/
  6906. static u8 bnx2x_8073_common_init_phy(struct bnx2x *bp,
  6907. u32 shmem_base_path[],
  6908. u32 shmem2_base_path[], u8 phy_index,
  6909. u32 chip_id)
  6910. {
  6911. struct bnx2x_phy phy[PORT_MAX];
  6912. struct bnx2x_phy *phy_blk[PORT_MAX];
  6913. u16 val;
  6914. s8 port = 0;
  6915. s8 port_of_path = 0;
  6916. u32 swap_val, swap_override;
  6917. swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
  6918. swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
  6919. port ^= (swap_val && swap_override);
  6920. bnx2x_ext_phy_hw_reset(bp, port);
  6921. /* PART1 - Reset both phys */
  6922. for (port = PORT_MAX - 1; port >= PORT_0; port--) {
  6923. u32 shmem_base, shmem2_base;
  6924. /* In E2, same phy is using for port0 of the two paths */
  6925. if (CHIP_IS_E2(bp)) {
  6926. shmem_base = shmem_base_path[port];
  6927. shmem2_base = shmem2_base_path[port];
  6928. port_of_path = 0;
  6929. } else {
  6930. shmem_base = shmem_base_path[0];
  6931. shmem2_base = shmem2_base_path[0];
  6932. port_of_path = port;
  6933. }
  6934. /* Extract the ext phy address for the port */
  6935. if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
  6936. port_of_path, &phy[port]) !=
  6937. 0) {
  6938. DP(NETIF_MSG_LINK, "populate_phy failed\n");
  6939. return -EINVAL;
  6940. }
  6941. /* disable attentions */
  6942. bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 +
  6943. port_of_path*4,
  6944. (NIG_MASK_XGXS0_LINK_STATUS |
  6945. NIG_MASK_XGXS0_LINK10G |
  6946. NIG_MASK_SERDES0_LINK_STATUS |
  6947. NIG_MASK_MI_INT));
  6948. /* Need to take the phy out of low power mode in order
  6949. to write to access its registers */
  6950. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
  6951. MISC_REGISTERS_GPIO_OUTPUT_HIGH,
  6952. port);
  6953. /* Reset the phy */
  6954. bnx2x_cl45_write(bp, &phy[port],
  6955. MDIO_PMA_DEVAD,
  6956. MDIO_PMA_REG_CTRL,
  6957. 1<<15);
  6958. }
  6959. /* Add delay of 150ms after reset */
  6960. msleep(150);
  6961. if (phy[PORT_0].addr & 0x1) {
  6962. phy_blk[PORT_0] = &(phy[PORT_1]);
  6963. phy_blk[PORT_1] = &(phy[PORT_0]);
  6964. } else {
  6965. phy_blk[PORT_0] = &(phy[PORT_0]);
  6966. phy_blk[PORT_1] = &(phy[PORT_1]);
  6967. }
  6968. /* PART2 - Download firmware to both phys */
  6969. for (port = PORT_MAX - 1; port >= PORT_0; port--) {
  6970. if (CHIP_IS_E2(bp))
  6971. port_of_path = 0;
  6972. else
  6973. port_of_path = port;
  6974. DP(NETIF_MSG_LINK, "Loading spirom for phy address 0x%x\n",
  6975. phy_blk[port]->addr);
  6976. if (bnx2x_8073_8727_external_rom_boot(bp, phy_blk[port],
  6977. port_of_path))
  6978. return -EINVAL;
  6979. /* Only set bit 10 = 1 (Tx power down) */
  6980. bnx2x_cl45_read(bp, phy_blk[port],
  6981. MDIO_PMA_DEVAD,
  6982. MDIO_PMA_REG_TX_POWER_DOWN, &val);
  6983. /* Phase1 of TX_POWER_DOWN reset */
  6984. bnx2x_cl45_write(bp, phy_blk[port],
  6985. MDIO_PMA_DEVAD,
  6986. MDIO_PMA_REG_TX_POWER_DOWN,
  6987. (val | 1<<10));
  6988. }
  6989. /*
  6990. * Toggle Transmitter: Power down and then up with 600ms delay
  6991. * between
  6992. */
  6993. msleep(600);
  6994. /* PART3 - complete TX_POWER_DOWN process, and set GPIO2 back to low */
  6995. for (port = PORT_MAX - 1; port >= PORT_0; port--) {
  6996. /* Phase2 of POWER_DOWN_RESET */
  6997. /* Release bit 10 (Release Tx power down) */
  6998. bnx2x_cl45_read(bp, phy_blk[port],
  6999. MDIO_PMA_DEVAD,
  7000. MDIO_PMA_REG_TX_POWER_DOWN, &val);
  7001. bnx2x_cl45_write(bp, phy_blk[port],
  7002. MDIO_PMA_DEVAD,
  7003. MDIO_PMA_REG_TX_POWER_DOWN, (val & (~(1<<10))));
  7004. msleep(15);
  7005. /* Read modify write the SPI-ROM version select register */
  7006. bnx2x_cl45_read(bp, phy_blk[port],
  7007. MDIO_PMA_DEVAD,
  7008. MDIO_PMA_REG_EDC_FFE_MAIN, &val);
  7009. bnx2x_cl45_write(bp, phy_blk[port],
  7010. MDIO_PMA_DEVAD,
  7011. MDIO_PMA_REG_EDC_FFE_MAIN, (val | (1<<12)));
  7012. /* set GPIO2 back to LOW */
  7013. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
  7014. MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
  7015. }
  7016. return 0;
  7017. }
  7018. static u8 bnx2x_8726_common_init_phy(struct bnx2x *bp,
  7019. u32 shmem_base_path[],
  7020. u32 shmem2_base_path[], u8 phy_index,
  7021. u32 chip_id)
  7022. {
  7023. u32 val;
  7024. s8 port;
  7025. struct bnx2x_phy phy;
  7026. /* Use port1 because of the static port-swap */
  7027. /* Enable the module detection interrupt */
  7028. val = REG_RD(bp, MISC_REG_GPIO_EVENT_EN);
  7029. val |= ((1<<MISC_REGISTERS_GPIO_3)|
  7030. (1<<(MISC_REGISTERS_GPIO_3 + MISC_REGISTERS_GPIO_PORT_SHIFT)));
  7031. REG_WR(bp, MISC_REG_GPIO_EVENT_EN, val);
  7032. bnx2x_ext_phy_hw_reset(bp, 0);
  7033. msleep(5);
  7034. for (port = 0; port < PORT_MAX; port++) {
  7035. u32 shmem_base, shmem2_base;
  7036. /* In E2, same phy is using for port0 of the two paths */
  7037. if (CHIP_IS_E2(bp)) {
  7038. shmem_base = shmem_base_path[port];
  7039. shmem2_base = shmem2_base_path[port];
  7040. } else {
  7041. shmem_base = shmem_base_path[0];
  7042. shmem2_base = shmem2_base_path[0];
  7043. }
  7044. /* Extract the ext phy address for the port */
  7045. if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
  7046. port, &phy) !=
  7047. 0) {
  7048. DP(NETIF_MSG_LINK, "populate phy failed\n");
  7049. return -EINVAL;
  7050. }
  7051. /* Reset phy*/
  7052. bnx2x_cl45_write(bp, &phy,
  7053. MDIO_PMA_DEVAD, MDIO_PMA_REG_GEN_CTRL, 0x0001);
  7054. /* Set fault module detected LED on */
  7055. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
  7056. MISC_REGISTERS_GPIO_HIGH,
  7057. port);
  7058. }
  7059. return 0;
  7060. }
  7061. static void bnx2x_get_ext_phy_reset_gpio(struct bnx2x *bp, u32 shmem_base,
  7062. u8 *io_gpio, u8 *io_port)
  7063. {
  7064. u32 phy_gpio_reset = REG_RD(bp, shmem_base +
  7065. offsetof(struct shmem_region,
  7066. dev_info.port_hw_config[PORT_0].default_cfg));
  7067. switch (phy_gpio_reset) {
  7068. case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P0:
  7069. *io_gpio = 0;
  7070. *io_port = 0;
  7071. break;
  7072. case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO1_P0:
  7073. *io_gpio = 1;
  7074. *io_port = 0;
  7075. break;
  7076. case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO2_P0:
  7077. *io_gpio = 2;
  7078. *io_port = 0;
  7079. break;
  7080. case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO3_P0:
  7081. *io_gpio = 3;
  7082. *io_port = 0;
  7083. break;
  7084. case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P1:
  7085. *io_gpio = 0;
  7086. *io_port = 1;
  7087. break;
  7088. case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO1_P1:
  7089. *io_gpio = 1;
  7090. *io_port = 1;
  7091. break;
  7092. case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO2_P1:
  7093. *io_gpio = 2;
  7094. *io_port = 1;
  7095. break;
  7096. case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO3_P1:
  7097. *io_gpio = 3;
  7098. *io_port = 1;
  7099. break;
  7100. default:
  7101. /* Don't override the io_gpio and io_port */
  7102. break;
  7103. }
  7104. }
  7105. static u8 bnx2x_8727_common_init_phy(struct bnx2x *bp,
  7106. u32 shmem_base_path[],
  7107. u32 shmem2_base_path[], u8 phy_index,
  7108. u32 chip_id)
  7109. {
  7110. s8 port, reset_gpio;
  7111. u32 swap_val, swap_override;
  7112. struct bnx2x_phy phy[PORT_MAX];
  7113. struct bnx2x_phy *phy_blk[PORT_MAX];
  7114. s8 port_of_path;
  7115. swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
  7116. swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
  7117. reset_gpio = MISC_REGISTERS_GPIO_1;
  7118. port = 1;
  7119. /*
  7120. * Retrieve the reset gpio/port which control the reset.
  7121. * Default is GPIO1, PORT1
  7122. */
  7123. bnx2x_get_ext_phy_reset_gpio(bp, shmem_base_path[0],
  7124. (u8 *)&reset_gpio, (u8 *)&port);
  7125. /* Calculate the port based on port swap */
  7126. port ^= (swap_val && swap_override);
  7127. /* Initiate PHY reset*/
  7128. bnx2x_set_gpio(bp, reset_gpio, MISC_REGISTERS_GPIO_OUTPUT_LOW,
  7129. port);
  7130. msleep(1);
  7131. bnx2x_set_gpio(bp, reset_gpio, MISC_REGISTERS_GPIO_OUTPUT_HIGH,
  7132. port);
  7133. msleep(5);
  7134. /* PART1 - Reset both phys */
  7135. for (port = PORT_MAX - 1; port >= PORT_0; port--) {
  7136. u32 shmem_base, shmem2_base;
  7137. /* In E2, same phy is using for port0 of the two paths */
  7138. if (CHIP_IS_E2(bp)) {
  7139. shmem_base = shmem_base_path[port];
  7140. shmem2_base = shmem2_base_path[port];
  7141. port_of_path = 0;
  7142. } else {
  7143. shmem_base = shmem_base_path[0];
  7144. shmem2_base = shmem2_base_path[0];
  7145. port_of_path = port;
  7146. }
  7147. /* Extract the ext phy address for the port */
  7148. if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
  7149. port_of_path, &phy[port]) !=
  7150. 0) {
  7151. DP(NETIF_MSG_LINK, "populate phy failed\n");
  7152. return -EINVAL;
  7153. }
  7154. /* disable attentions */
  7155. bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 +
  7156. port_of_path*4,
  7157. (NIG_MASK_XGXS0_LINK_STATUS |
  7158. NIG_MASK_XGXS0_LINK10G |
  7159. NIG_MASK_SERDES0_LINK_STATUS |
  7160. NIG_MASK_MI_INT));
  7161. /* Reset the phy */
  7162. bnx2x_cl45_write(bp, &phy[port],
  7163. MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
  7164. }
  7165. /* Add delay of 150ms after reset */
  7166. msleep(150);
  7167. if (phy[PORT_0].addr & 0x1) {
  7168. phy_blk[PORT_0] = &(phy[PORT_1]);
  7169. phy_blk[PORT_1] = &(phy[PORT_0]);
  7170. } else {
  7171. phy_blk[PORT_0] = &(phy[PORT_0]);
  7172. phy_blk[PORT_1] = &(phy[PORT_1]);
  7173. }
  7174. /* PART2 - Download firmware to both phys */
  7175. for (port = PORT_MAX - 1; port >= PORT_0; port--) {
  7176. if (CHIP_IS_E2(bp))
  7177. port_of_path = 0;
  7178. else
  7179. port_of_path = port;
  7180. DP(NETIF_MSG_LINK, "Loading spirom for phy address 0x%x\n",
  7181. phy_blk[port]->addr);
  7182. if (bnx2x_8073_8727_external_rom_boot(bp, phy_blk[port],
  7183. port_of_path))
  7184. return -EINVAL;
  7185. }
  7186. return 0;
  7187. }
  7188. static u8 bnx2x_ext_phy_common_init(struct bnx2x *bp, u32 shmem_base_path[],
  7189. u32 shmem2_base_path[], u8 phy_index,
  7190. u32 ext_phy_type, u32 chip_id)
  7191. {
  7192. u8 rc = 0;
  7193. switch (ext_phy_type) {
  7194. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
  7195. rc = bnx2x_8073_common_init_phy(bp, shmem_base_path,
  7196. shmem2_base_path,
  7197. phy_index, chip_id);
  7198. break;
  7199. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
  7200. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727_NOC:
  7201. rc = bnx2x_8727_common_init_phy(bp, shmem_base_path,
  7202. shmem2_base_path,
  7203. phy_index, chip_id);
  7204. break;
  7205. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
  7206. /*
  7207. * GPIO1 affects both ports, so there's need to pull
  7208. * it for single port alone
  7209. */
  7210. rc = bnx2x_8726_common_init_phy(bp, shmem_base_path,
  7211. shmem2_base_path,
  7212. phy_index, chip_id);
  7213. break;
  7214. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
  7215. rc = -EINVAL;
  7216. break;
  7217. default:
  7218. DP(NETIF_MSG_LINK,
  7219. "ext_phy 0x%x common init not required\n",
  7220. ext_phy_type);
  7221. break;
  7222. }
  7223. if (rc != 0)
  7224. netdev_err(bp->dev, "Warning: PHY was not initialized,"
  7225. " Port %d\n",
  7226. 0);
  7227. return rc;
  7228. }
  7229. u8 bnx2x_common_init_phy(struct bnx2x *bp, u32 shmem_base_path[],
  7230. u32 shmem2_base_path[], u32 chip_id)
  7231. {
  7232. u8 rc = 0;
  7233. u32 phy_ver;
  7234. u8 phy_index;
  7235. u32 ext_phy_type, ext_phy_config;
  7236. DP(NETIF_MSG_LINK, "Begin common phy init\n");
  7237. /* Check if common init was already done */
  7238. phy_ver = REG_RD(bp, shmem_base_path[0] +
  7239. offsetof(struct shmem_region,
  7240. port_mb[PORT_0].ext_phy_fw_version));
  7241. if (phy_ver) {
  7242. DP(NETIF_MSG_LINK, "Not doing common init; phy ver is 0x%x\n",
  7243. phy_ver);
  7244. return 0;
  7245. }
  7246. /* Read the ext_phy_type for arbitrary port(0) */
  7247. for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
  7248. phy_index++) {
  7249. ext_phy_config = bnx2x_get_ext_phy_config(bp,
  7250. shmem_base_path[0],
  7251. phy_index, 0);
  7252. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  7253. rc |= bnx2x_ext_phy_common_init(bp, shmem_base_path,
  7254. shmem2_base_path,
  7255. phy_index, ext_phy_type,
  7256. chip_id);
  7257. }
  7258. return rc;
  7259. }
  7260. u8 bnx2x_hw_lock_required(struct bnx2x *bp, u32 shmem_base, u32 shmem2_base)
  7261. {
  7262. u8 phy_index;
  7263. struct bnx2x_phy phy;
  7264. for (phy_index = INT_PHY; phy_index < MAX_PHYS;
  7265. phy_index++) {
  7266. if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
  7267. 0, &phy) != 0) {
  7268. DP(NETIF_MSG_LINK, "populate phy failed\n");
  7269. return 0;
  7270. }
  7271. if (phy.flags & FLAGS_HW_LOCK_REQUIRED)
  7272. return 1;
  7273. }
  7274. return 0;
  7275. }
  7276. u8 bnx2x_fan_failure_det_req(struct bnx2x *bp,
  7277. u32 shmem_base,
  7278. u32 shmem2_base,
  7279. u8 port)
  7280. {
  7281. u8 phy_index, fan_failure_det_req = 0;
  7282. struct bnx2x_phy phy;
  7283. for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
  7284. phy_index++) {
  7285. if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
  7286. port, &phy)
  7287. != 0) {
  7288. DP(NETIF_MSG_LINK, "populate phy failed\n");
  7289. return 0;
  7290. }
  7291. fan_failure_det_req |= (phy.flags &
  7292. FLAGS_FAN_FAILURE_DET_REQ);
  7293. }
  7294. return fan_failure_det_req;
  7295. }
  7296. void bnx2x_hw_reset_phy(struct link_params *params)
  7297. {
  7298. u8 phy_index;
  7299. for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
  7300. phy_index++) {
  7301. if (params->phy[phy_index].hw_reset) {
  7302. params->phy[phy_index].hw_reset(
  7303. &params->phy[phy_index],
  7304. params);
  7305. params->phy[phy_index] = phy_null;
  7306. }
  7307. }
  7308. }