bnx2x_link.c 411 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148
  1. /* Copyright 2008-2013 Broadcom Corporation
  2. * Copyright (c) 2014 QLogic Corporation
  3. * All rights reserved
  4. *
  5. * Unless you and QLogic execute a separate written software license
  6. * agreement governing use of this software, this software is licensed to you
  7. * under the terms of the GNU General Public License version 2, available
  8. * at http://www.gnu.org/licenses/gpl-2.0.html (the "GPL").
  9. *
  10. * Notwithstanding the above, under no circumstances may you combine this
  11. * software in any way with any other Qlogic software provided under a
  12. * license other than the GPL, without Qlogic's express prior written
  13. * consent.
  14. *
  15. * Written by Yaniv Rosner
  16. *
  17. */
  18. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  19. #include <linux/kernel.h>
  20. #include <linux/errno.h>
  21. #include <linux/pci.h>
  22. #include <linux/netdevice.h>
  23. #include <linux/delay.h>
  24. #include <linux/ethtool.h>
  25. #include <linux/mutex.h>
  26. #include "bnx2x.h"
  27. #include "bnx2x_cmn.h"
  28. typedef int (*read_sfp_module_eeprom_func_p)(struct bnx2x_phy *phy,
  29. struct link_params *params,
  30. u8 dev_addr, u16 addr, u8 byte_cnt,
  31. u8 *o_buf, u8);
  32. /********************************************************/
  33. #define ETH_HLEN 14
  34. /* L2 header size + 2*VLANs (8 bytes) + LLC SNAP (8 bytes) */
  35. #define ETH_OVREHEAD (ETH_HLEN + 8 + 8)
  36. #define ETH_MIN_PACKET_SIZE 60
  37. #define ETH_MAX_PACKET_SIZE 1500
  38. #define ETH_MAX_JUMBO_PACKET_SIZE 9600
  39. #define MDIO_ACCESS_TIMEOUT 1000
  40. #define WC_LANE_MAX 4
  41. #define I2C_SWITCH_WIDTH 2
  42. #define I2C_BSC0 0
  43. #define I2C_BSC1 1
  44. #define I2C_WA_RETRY_CNT 3
  45. #define I2C_WA_PWR_ITER (I2C_WA_RETRY_CNT - 1)
  46. #define MCPR_IMC_COMMAND_READ_OP 1
  47. #define MCPR_IMC_COMMAND_WRITE_OP 2
  48. /* LED Blink rate that will achieve ~15.9Hz */
  49. #define LED_BLINK_RATE_VAL_E3 354
  50. #define LED_BLINK_RATE_VAL_E1X_E2 480
  51. /***********************************************************/
  52. /* Shortcut definitions */
  53. /***********************************************************/
  54. #define NIG_LATCH_BC_ENABLE_MI_INT 0
  55. #define NIG_STATUS_EMAC0_MI_INT \
  56. NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_EMAC0_MISC_MI_INT
  57. #define NIG_STATUS_XGXS0_LINK10G \
  58. NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_XGXS0_LINK10G
  59. #define NIG_STATUS_XGXS0_LINK_STATUS \
  60. NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_XGXS0_LINK_STATUS
  61. #define NIG_STATUS_XGXS0_LINK_STATUS_SIZE \
  62. NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_XGXS0_LINK_STATUS_SIZE
  63. #define NIG_STATUS_SERDES0_LINK_STATUS \
  64. NIG_STATUS_INTERRUPT_PORT0_REG_STATUS_SERDES0_LINK_STATUS
  65. #define NIG_MASK_MI_INT \
  66. NIG_MASK_INTERRUPT_PORT0_REG_MASK_EMAC0_MISC_MI_INT
  67. #define NIG_MASK_XGXS0_LINK10G \
  68. NIG_MASK_INTERRUPT_PORT0_REG_MASK_XGXS0_LINK10G
  69. #define NIG_MASK_XGXS0_LINK_STATUS \
  70. NIG_MASK_INTERRUPT_PORT0_REG_MASK_XGXS0_LINK_STATUS
  71. #define NIG_MASK_SERDES0_LINK_STATUS \
  72. NIG_MASK_INTERRUPT_PORT0_REG_MASK_SERDES0_LINK_STATUS
  73. #define MDIO_AN_CL73_OR_37_COMPLETE \
  74. (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE | \
  75. MDIO_GP_STATUS_TOP_AN_STATUS1_CL37_AUTONEG_COMPLETE)
  76. #define XGXS_RESET_BITS \
  77. (MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_RSTB_HW | \
  78. MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_IDDQ | \
  79. MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_PWRDWN | \
  80. MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_PWRDWN_SD | \
  81. MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_XGXS0_TXD_FIFO_RSTB)
  82. #define SERDES_RESET_BITS \
  83. (MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_RSTB_HW | \
  84. MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_IDDQ | \
  85. MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_PWRDWN | \
  86. MISC_REGISTERS_RESET_REG_3_MISC_NIG_MUX_SERDES0_PWRDWN_SD)
  87. #define AUTONEG_CL37 SHARED_HW_CFG_AN_ENABLE_CL37
  88. #define AUTONEG_CL73 SHARED_HW_CFG_AN_ENABLE_CL73
  89. #define AUTONEG_BAM SHARED_HW_CFG_AN_ENABLE_BAM
  90. #define AUTONEG_PARALLEL \
  91. SHARED_HW_CFG_AN_ENABLE_PARALLEL_DETECTION
  92. #define AUTONEG_SGMII_FIBER_AUTODET \
  93. SHARED_HW_CFG_AN_EN_SGMII_FIBER_AUTO_DETECT
  94. #define AUTONEG_REMOTE_PHY SHARED_HW_CFG_AN_ENABLE_REMOTE_PHY
  95. #define GP_STATUS_PAUSE_RSOLUTION_TXSIDE \
  96. MDIO_GP_STATUS_TOP_AN_STATUS1_PAUSE_RSOLUTION_TXSIDE
  97. #define GP_STATUS_PAUSE_RSOLUTION_RXSIDE \
  98. MDIO_GP_STATUS_TOP_AN_STATUS1_PAUSE_RSOLUTION_RXSIDE
  99. #define GP_STATUS_SPEED_MASK \
  100. MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_MASK
  101. #define GP_STATUS_10M MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10M
  102. #define GP_STATUS_100M MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_100M
  103. #define GP_STATUS_1G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_1G
  104. #define GP_STATUS_2_5G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_2_5G
  105. #define GP_STATUS_5G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_5G
  106. #define GP_STATUS_6G MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_6G
  107. #define GP_STATUS_10G_HIG \
  108. MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_HIG
  109. #define GP_STATUS_10G_CX4 \
  110. MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_CX4
  111. #define GP_STATUS_1G_KX MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_1G_KX
  112. #define GP_STATUS_10G_KX4 \
  113. MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_KX4
  114. #define GP_STATUS_10G_KR MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_KR
  115. #define GP_STATUS_10G_XFI MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_XFI
  116. #define GP_STATUS_20G_DXGXS MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_20G_DXGXS
  117. #define GP_STATUS_10G_SFI MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_10G_SFI
  118. #define GP_STATUS_20G_KR2 MDIO_GP_STATUS_TOP_AN_STATUS1_ACTUAL_SPEED_20G_KR2
  119. #define LINK_10THD LINK_STATUS_SPEED_AND_DUPLEX_10THD
  120. #define LINK_10TFD LINK_STATUS_SPEED_AND_DUPLEX_10TFD
  121. #define LINK_100TXHD LINK_STATUS_SPEED_AND_DUPLEX_100TXHD
  122. #define LINK_100T4 LINK_STATUS_SPEED_AND_DUPLEX_100T4
  123. #define LINK_100TXFD LINK_STATUS_SPEED_AND_DUPLEX_100TXFD
  124. #define LINK_1000THD LINK_STATUS_SPEED_AND_DUPLEX_1000THD
  125. #define LINK_1000TFD LINK_STATUS_SPEED_AND_DUPLEX_1000TFD
  126. #define LINK_1000XFD LINK_STATUS_SPEED_AND_DUPLEX_1000XFD
  127. #define LINK_2500THD LINK_STATUS_SPEED_AND_DUPLEX_2500THD
  128. #define LINK_2500TFD LINK_STATUS_SPEED_AND_DUPLEX_2500TFD
  129. #define LINK_2500XFD LINK_STATUS_SPEED_AND_DUPLEX_2500XFD
  130. #define LINK_10GTFD LINK_STATUS_SPEED_AND_DUPLEX_10GTFD
  131. #define LINK_10GXFD LINK_STATUS_SPEED_AND_DUPLEX_10GXFD
  132. #define LINK_20GTFD LINK_STATUS_SPEED_AND_DUPLEX_20GTFD
  133. #define LINK_20GXFD LINK_STATUS_SPEED_AND_DUPLEX_20GXFD
  134. #define LINK_UPDATE_MASK \
  135. (LINK_STATUS_SPEED_AND_DUPLEX_MASK | \
  136. LINK_STATUS_LINK_UP | \
  137. LINK_STATUS_PHYSICAL_LINK_FLAG | \
  138. LINK_STATUS_AUTO_NEGOTIATE_COMPLETE | \
  139. LINK_STATUS_RX_FLOW_CONTROL_FLAG_MASK | \
  140. LINK_STATUS_TX_FLOW_CONTROL_FLAG_MASK | \
  141. LINK_STATUS_PARALLEL_DETECTION_FLAG_MASK | \
  142. LINK_STATUS_LINK_PARTNER_SYMMETRIC_PAUSE | \
  143. LINK_STATUS_LINK_PARTNER_ASYMMETRIC_PAUSE)
  144. #define SFP_EEPROM_CON_TYPE_ADDR 0x2
  145. #define SFP_EEPROM_CON_TYPE_VAL_UNKNOWN 0x0
  146. #define SFP_EEPROM_CON_TYPE_VAL_LC 0x7
  147. #define SFP_EEPROM_CON_TYPE_VAL_COPPER 0x21
  148. #define SFP_EEPROM_CON_TYPE_VAL_RJ45 0x22
  149. #define SFP_EEPROM_10G_COMP_CODE_ADDR 0x3
  150. #define SFP_EEPROM_10G_COMP_CODE_SR_MASK (1<<4)
  151. #define SFP_EEPROM_10G_COMP_CODE_LR_MASK (1<<5)
  152. #define SFP_EEPROM_10G_COMP_CODE_LRM_MASK (1<<6)
  153. #define SFP_EEPROM_1G_COMP_CODE_ADDR 0x6
  154. #define SFP_EEPROM_1G_COMP_CODE_SX (1<<0)
  155. #define SFP_EEPROM_1G_COMP_CODE_LX (1<<1)
  156. #define SFP_EEPROM_1G_COMP_CODE_CX (1<<2)
  157. #define SFP_EEPROM_1G_COMP_CODE_BASE_T (1<<3)
  158. #define SFP_EEPROM_FC_TX_TECH_ADDR 0x8
  159. #define SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_PASSIVE 0x4
  160. #define SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_ACTIVE 0x8
  161. #define SFP_EEPROM_OPTIONS_ADDR 0x40
  162. #define SFP_EEPROM_OPTIONS_LINEAR_RX_OUT_MASK 0x1
  163. #define SFP_EEPROM_OPTIONS_SIZE 2
  164. #define EDC_MODE_LINEAR 0x0022
  165. #define EDC_MODE_LIMITING 0x0044
  166. #define EDC_MODE_PASSIVE_DAC 0x0055
  167. #define EDC_MODE_ACTIVE_DAC 0x0066
  168. /* ETS defines*/
  169. #define DCBX_INVALID_COS (0xFF)
  170. #define ETS_BW_LIMIT_CREDIT_UPPER_BOUND (0x5000)
  171. #define ETS_BW_LIMIT_CREDIT_WEIGHT (0x5000)
  172. #define ETS_E3B0_NIG_MIN_W_VAL_UP_TO_10GBPS (1360)
  173. #define ETS_E3B0_NIG_MIN_W_VAL_20GBPS (2720)
  174. #define ETS_E3B0_PBF_MIN_W_VAL (10000)
  175. #define MAX_PACKET_SIZE (9700)
  176. #define MAX_KR_LINK_RETRY 4
  177. #define DEFAULT_TX_DRV_BRDCT 2
  178. #define DEFAULT_TX_DRV_IFIR 0
  179. #define DEFAULT_TX_DRV_POST2 3
  180. #define DEFAULT_TX_DRV_IPRE_DRIVER 6
  181. /**********************************************************/
  182. /* INTERFACE */
  183. /**********************************************************/
  184. #define CL22_WR_OVER_CL45(_bp, _phy, _bank, _addr, _val) \
  185. bnx2x_cl45_write(_bp, _phy, \
  186. (_phy)->def_md_devad, \
  187. (_bank + (_addr & 0xf)), \
  188. _val)
  189. #define CL22_RD_OVER_CL45(_bp, _phy, _bank, _addr, _val) \
  190. bnx2x_cl45_read(_bp, _phy, \
  191. (_phy)->def_md_devad, \
  192. (_bank + (_addr & 0xf)), \
  193. _val)
  194. static int bnx2x_check_half_open_conn(struct link_params *params,
  195. struct link_vars *vars, u8 notify);
  196. static int bnx2x_sfp_module_detection(struct bnx2x_phy *phy,
  197. struct link_params *params);
  198. static u32 bnx2x_bits_en(struct bnx2x *bp, u32 reg, u32 bits)
  199. {
  200. u32 val = REG_RD(bp, reg);
  201. val |= bits;
  202. REG_WR(bp, reg, val);
  203. return val;
  204. }
  205. static u32 bnx2x_bits_dis(struct bnx2x *bp, u32 reg, u32 bits)
  206. {
  207. u32 val = REG_RD(bp, reg);
  208. val &= ~bits;
  209. REG_WR(bp, reg, val);
  210. return val;
  211. }
  212. /*
  213. * bnx2x_check_lfa - This function checks if link reinitialization is required,
  214. * or link flap can be avoided.
  215. *
  216. * @params: link parameters
  217. * Returns 0 if Link Flap Avoidance conditions are met otherwise, the failed
  218. * condition code.
  219. */
  220. static int bnx2x_check_lfa(struct link_params *params)
  221. {
  222. u32 link_status, cfg_idx, lfa_mask, cfg_size;
  223. u32 cur_speed_cap_mask, cur_req_fc_auto_adv, additional_config;
  224. u32 saved_val, req_val, eee_status;
  225. struct bnx2x *bp = params->bp;
  226. additional_config =
  227. REG_RD(bp, params->lfa_base +
  228. offsetof(struct shmem_lfa, additional_config));
  229. /* NOTE: must be first condition checked -
  230. * to verify DCC bit is cleared in any case!
  231. */
  232. if (additional_config & NO_LFA_DUE_TO_DCC_MASK) {
  233. DP(NETIF_MSG_LINK, "No LFA due to DCC flap after clp exit\n");
  234. REG_WR(bp, params->lfa_base +
  235. offsetof(struct shmem_lfa, additional_config),
  236. additional_config & ~NO_LFA_DUE_TO_DCC_MASK);
  237. return LFA_DCC_LFA_DISABLED;
  238. }
  239. /* Verify that link is up */
  240. link_status = REG_RD(bp, params->shmem_base +
  241. offsetof(struct shmem_region,
  242. port_mb[params->port].link_status));
  243. if (!(link_status & LINK_STATUS_LINK_UP))
  244. return LFA_LINK_DOWN;
  245. /* if loaded after BOOT from SAN, don't flap the link in any case and
  246. * rely on link set by preboot driver
  247. */
  248. if (params->feature_config_flags & FEATURE_CONFIG_BOOT_FROM_SAN)
  249. return 0;
  250. /* Verify that loopback mode is not set */
  251. if (params->loopback_mode)
  252. return LFA_LOOPBACK_ENABLED;
  253. /* Verify that MFW supports LFA */
  254. if (!params->lfa_base)
  255. return LFA_MFW_IS_TOO_OLD;
  256. if (params->num_phys == 3) {
  257. cfg_size = 2;
  258. lfa_mask = 0xffffffff;
  259. } else {
  260. cfg_size = 1;
  261. lfa_mask = 0xffff;
  262. }
  263. /* Compare Duplex */
  264. saved_val = REG_RD(bp, params->lfa_base +
  265. offsetof(struct shmem_lfa, req_duplex));
  266. req_val = params->req_duplex[0] | (params->req_duplex[1] << 16);
  267. if ((saved_val & lfa_mask) != (req_val & lfa_mask)) {
  268. DP(NETIF_MSG_LINK, "Duplex mismatch %x vs. %x\n",
  269. (saved_val & lfa_mask), (req_val & lfa_mask));
  270. return LFA_DUPLEX_MISMATCH;
  271. }
  272. /* Compare Flow Control */
  273. saved_val = REG_RD(bp, params->lfa_base +
  274. offsetof(struct shmem_lfa, req_flow_ctrl));
  275. req_val = params->req_flow_ctrl[0] | (params->req_flow_ctrl[1] << 16);
  276. if ((saved_val & lfa_mask) != (req_val & lfa_mask)) {
  277. DP(NETIF_MSG_LINK, "Flow control mismatch %x vs. %x\n",
  278. (saved_val & lfa_mask), (req_val & lfa_mask));
  279. return LFA_FLOW_CTRL_MISMATCH;
  280. }
  281. /* Compare Link Speed */
  282. saved_val = REG_RD(bp, params->lfa_base +
  283. offsetof(struct shmem_lfa, req_line_speed));
  284. req_val = params->req_line_speed[0] | (params->req_line_speed[1] << 16);
  285. if ((saved_val & lfa_mask) != (req_val & lfa_mask)) {
  286. DP(NETIF_MSG_LINK, "Link speed mismatch %x vs. %x\n",
  287. (saved_val & lfa_mask), (req_val & lfa_mask));
  288. return LFA_LINK_SPEED_MISMATCH;
  289. }
  290. for (cfg_idx = 0; cfg_idx < cfg_size; cfg_idx++) {
  291. cur_speed_cap_mask = REG_RD(bp, params->lfa_base +
  292. offsetof(struct shmem_lfa,
  293. speed_cap_mask[cfg_idx]));
  294. if (cur_speed_cap_mask != params->speed_cap_mask[cfg_idx]) {
  295. DP(NETIF_MSG_LINK, "Speed Cap mismatch %x vs. %x\n",
  296. cur_speed_cap_mask,
  297. params->speed_cap_mask[cfg_idx]);
  298. return LFA_SPEED_CAP_MISMATCH;
  299. }
  300. }
  301. cur_req_fc_auto_adv =
  302. REG_RD(bp, params->lfa_base +
  303. offsetof(struct shmem_lfa, additional_config)) &
  304. REQ_FC_AUTO_ADV_MASK;
  305. if ((u16)cur_req_fc_auto_adv != params->req_fc_auto_adv) {
  306. DP(NETIF_MSG_LINK, "Flow Ctrl AN mismatch %x vs. %x\n",
  307. cur_req_fc_auto_adv, params->req_fc_auto_adv);
  308. return LFA_FLOW_CTRL_MISMATCH;
  309. }
  310. eee_status = REG_RD(bp, params->shmem2_base +
  311. offsetof(struct shmem2_region,
  312. eee_status[params->port]));
  313. if (((eee_status & SHMEM_EEE_LPI_REQUESTED_BIT) ^
  314. (params->eee_mode & EEE_MODE_ENABLE_LPI)) ||
  315. ((eee_status & SHMEM_EEE_REQUESTED_BIT) ^
  316. (params->eee_mode & EEE_MODE_ADV_LPI))) {
  317. DP(NETIF_MSG_LINK, "EEE mismatch %x vs. %x\n", params->eee_mode,
  318. eee_status);
  319. return LFA_EEE_MISMATCH;
  320. }
  321. /* LFA conditions are met */
  322. return 0;
  323. }
  324. /******************************************************************/
  325. /* EPIO/GPIO section */
  326. /******************************************************************/
  327. static void bnx2x_get_epio(struct bnx2x *bp, u32 epio_pin, u32 *en)
  328. {
  329. u32 epio_mask, gp_oenable;
  330. *en = 0;
  331. /* Sanity check */
  332. if (epio_pin > 31) {
  333. DP(NETIF_MSG_LINK, "Invalid EPIO pin %d to get\n", epio_pin);
  334. return;
  335. }
  336. epio_mask = 1 << epio_pin;
  337. /* Set this EPIO to output */
  338. gp_oenable = REG_RD(bp, MCP_REG_MCPR_GP_OENABLE);
  339. REG_WR(bp, MCP_REG_MCPR_GP_OENABLE, gp_oenable & ~epio_mask);
  340. *en = (REG_RD(bp, MCP_REG_MCPR_GP_INPUTS) & epio_mask) >> epio_pin;
  341. }
  342. static void bnx2x_set_epio(struct bnx2x *bp, u32 epio_pin, u32 en)
  343. {
  344. u32 epio_mask, gp_output, gp_oenable;
  345. /* Sanity check */
  346. if (epio_pin > 31) {
  347. DP(NETIF_MSG_LINK, "Invalid EPIO pin %d to set\n", epio_pin);
  348. return;
  349. }
  350. DP(NETIF_MSG_LINK, "Setting EPIO pin %d to %d\n", epio_pin, en);
  351. epio_mask = 1 << epio_pin;
  352. /* Set this EPIO to output */
  353. gp_output = REG_RD(bp, MCP_REG_MCPR_GP_OUTPUTS);
  354. if (en)
  355. gp_output |= epio_mask;
  356. else
  357. gp_output &= ~epio_mask;
  358. REG_WR(bp, MCP_REG_MCPR_GP_OUTPUTS, gp_output);
  359. /* Set the value for this EPIO */
  360. gp_oenable = REG_RD(bp, MCP_REG_MCPR_GP_OENABLE);
  361. REG_WR(bp, MCP_REG_MCPR_GP_OENABLE, gp_oenable | epio_mask);
  362. }
  363. static void bnx2x_set_cfg_pin(struct bnx2x *bp, u32 pin_cfg, u32 val)
  364. {
  365. if (pin_cfg == PIN_CFG_NA)
  366. return;
  367. if (pin_cfg >= PIN_CFG_EPIO0) {
  368. bnx2x_set_epio(bp, pin_cfg - PIN_CFG_EPIO0, val);
  369. } else {
  370. u8 gpio_num = (pin_cfg - PIN_CFG_GPIO0_P0) & 0x3;
  371. u8 gpio_port = (pin_cfg - PIN_CFG_GPIO0_P0) >> 2;
  372. bnx2x_set_gpio(bp, gpio_num, (u8)val, gpio_port);
  373. }
  374. }
  375. static u32 bnx2x_get_cfg_pin(struct bnx2x *bp, u32 pin_cfg, u32 *val)
  376. {
  377. if (pin_cfg == PIN_CFG_NA)
  378. return -EINVAL;
  379. if (pin_cfg >= PIN_CFG_EPIO0) {
  380. bnx2x_get_epio(bp, pin_cfg - PIN_CFG_EPIO0, val);
  381. } else {
  382. u8 gpio_num = (pin_cfg - PIN_CFG_GPIO0_P0) & 0x3;
  383. u8 gpio_port = (pin_cfg - PIN_CFG_GPIO0_P0) >> 2;
  384. *val = bnx2x_get_gpio(bp, gpio_num, gpio_port);
  385. }
  386. return 0;
  387. }
  388. /******************************************************************/
  389. /* ETS section */
  390. /******************************************************************/
  391. static void bnx2x_ets_e2e3a0_disabled(struct link_params *params)
  392. {
  393. /* ETS disabled configuration*/
  394. struct bnx2x *bp = params->bp;
  395. DP(NETIF_MSG_LINK, "ETS E2E3 disabled configuration\n");
  396. /* mapping between entry priority to client number (0,1,2 -debug and
  397. * management clients, 3 - COS0 client, 4 - COS client)(HIGHEST)
  398. * 3bits client num.
  399. * PRI4 | PRI3 | PRI2 | PRI1 | PRI0
  400. * cos1-100 cos0-011 dbg1-010 dbg0-001 MCP-000
  401. */
  402. REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT, 0x4688);
  403. /* Bitmap of 5bits length. Each bit specifies whether the entry behaves
  404. * as strict. Bits 0,1,2 - debug and management entries, 3 -
  405. * COS0 entry, 4 - COS1 entry.
  406. * COS1 | COS0 | DEBUG1 | DEBUG0 | MGMT
  407. * bit4 bit3 bit2 bit1 bit0
  408. * MCP and debug are strict
  409. */
  410. REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x7);
  411. /* defines which entries (clients) are subjected to WFQ arbitration */
  412. REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_SUBJECT2WFQ, 0);
  413. /* For strict priority entries defines the number of consecutive
  414. * slots for the highest priority.
  415. */
  416. REG_WR(bp, NIG_REG_P0_TX_ARB_NUM_STRICT_ARB_SLOTS, 0x100);
  417. /* mapping between the CREDIT_WEIGHT registers and actual client
  418. * numbers
  419. */
  420. REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_CREDIT_MAP, 0);
  421. REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_0, 0);
  422. REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_1, 0);
  423. REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_0, 0);
  424. REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_1, 0);
  425. REG_WR(bp, PBF_REG_HIGH_PRIORITY_COS_NUM, 0);
  426. /* ETS mode disable */
  427. REG_WR(bp, PBF_REG_ETS_ENABLED, 0);
  428. /* If ETS mode is enabled (there is no strict priority) defines a WFQ
  429. * weight for COS0/COS1.
  430. */
  431. REG_WR(bp, PBF_REG_COS0_WEIGHT, 0x2710);
  432. REG_WR(bp, PBF_REG_COS1_WEIGHT, 0x2710);
  433. /* Upper bound that COS0_WEIGHT can reach in the WFQ arbiter */
  434. REG_WR(bp, PBF_REG_COS0_UPPER_BOUND, 0x989680);
  435. REG_WR(bp, PBF_REG_COS1_UPPER_BOUND, 0x989680);
  436. /* Defines the number of consecutive slots for the strict priority */
  437. REG_WR(bp, PBF_REG_NUM_STRICT_ARB_SLOTS, 0);
  438. }
  439. /******************************************************************************
  440. * Description:
  441. * Getting min_w_val will be set according to line speed .
  442. *.
  443. ******************************************************************************/
  444. static u32 bnx2x_ets_get_min_w_val_nig(const struct link_vars *vars)
  445. {
  446. u32 min_w_val = 0;
  447. /* Calculate min_w_val.*/
  448. if (vars->link_up) {
  449. if (vars->line_speed == SPEED_20000)
  450. min_w_val = ETS_E3B0_NIG_MIN_W_VAL_20GBPS;
  451. else
  452. min_w_val = ETS_E3B0_NIG_MIN_W_VAL_UP_TO_10GBPS;
  453. } else
  454. min_w_val = ETS_E3B0_NIG_MIN_W_VAL_20GBPS;
  455. /* If the link isn't up (static configuration for example ) The
  456. * link will be according to 20GBPS.
  457. */
  458. return min_w_val;
  459. }
  460. /******************************************************************************
  461. * Description:
  462. * Getting credit upper bound form min_w_val.
  463. *.
  464. ******************************************************************************/
  465. static u32 bnx2x_ets_get_credit_upper_bound(const u32 min_w_val)
  466. {
  467. const u32 credit_upper_bound = (u32)MAXVAL((150 * min_w_val),
  468. MAX_PACKET_SIZE);
  469. return credit_upper_bound;
  470. }
  471. /******************************************************************************
  472. * Description:
  473. * Set credit upper bound for NIG.
  474. *.
  475. ******************************************************************************/
  476. static void bnx2x_ets_e3b0_set_credit_upper_bound_nig(
  477. const struct link_params *params,
  478. const u32 min_w_val)
  479. {
  480. struct bnx2x *bp = params->bp;
  481. const u8 port = params->port;
  482. const u32 credit_upper_bound =
  483. bnx2x_ets_get_credit_upper_bound(min_w_val);
  484. REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_0 :
  485. NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_0, credit_upper_bound);
  486. REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_1 :
  487. NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_1, credit_upper_bound);
  488. REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_2 :
  489. NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_2, credit_upper_bound);
  490. REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_3 :
  491. NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_3, credit_upper_bound);
  492. REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_4 :
  493. NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_4, credit_upper_bound);
  494. REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_UPPER_BOUND_5 :
  495. NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_5, credit_upper_bound);
  496. if (!port) {
  497. REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_6,
  498. credit_upper_bound);
  499. REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_7,
  500. credit_upper_bound);
  501. REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_8,
  502. credit_upper_bound);
  503. }
  504. }
  505. /******************************************************************************
  506. * Description:
  507. * Will return the NIG ETS registers to init values.Except
  508. * credit_upper_bound.
  509. * That isn't used in this configuration (No WFQ is enabled) and will be
  510. * configured according to spec
  511. *.
  512. ******************************************************************************/
  513. static void bnx2x_ets_e3b0_nig_disabled(const struct link_params *params,
  514. const struct link_vars *vars)
  515. {
  516. struct bnx2x *bp = params->bp;
  517. const u8 port = params->port;
  518. const u32 min_w_val = bnx2x_ets_get_min_w_val_nig(vars);
  519. /* Mapping between entry priority to client number (0,1,2 -debug and
  520. * management clients, 3 - COS0 client, 4 - COS1, ... 8 -
  521. * COS5)(HIGHEST) 4bits client num.TODO_ETS - Should be done by
  522. * reset value or init tool
  523. */
  524. if (port) {
  525. REG_WR(bp, NIG_REG_P1_TX_ARB_PRIORITY_CLIENT2_LSB, 0x543210);
  526. REG_WR(bp, NIG_REG_P1_TX_ARB_PRIORITY_CLIENT2_MSB, 0x0);
  527. } else {
  528. REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT2_LSB, 0x76543210);
  529. REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT2_MSB, 0x8);
  530. }
  531. /* For strict priority entries defines the number of consecutive
  532. * slots for the highest priority.
  533. */
  534. REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_NUM_STRICT_ARB_SLOTS :
  535. NIG_REG_P0_TX_ARB_NUM_STRICT_ARB_SLOTS, 0x100);
  536. /* Mapping between the CREDIT_WEIGHT registers and actual client
  537. * numbers
  538. */
  539. if (port) {
  540. /*Port 1 has 6 COS*/
  541. REG_WR(bp, NIG_REG_P1_TX_ARB_CLIENT_CREDIT_MAP2_LSB, 0x210543);
  542. REG_WR(bp, NIG_REG_P1_TX_ARB_CLIENT_CREDIT_MAP2_MSB, 0x0);
  543. } else {
  544. /*Port 0 has 9 COS*/
  545. REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_CREDIT_MAP2_LSB,
  546. 0x43210876);
  547. REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_CREDIT_MAP2_MSB, 0x5);
  548. }
  549. /* Bitmap of 5bits length. Each bit specifies whether the entry behaves
  550. * as strict. Bits 0,1,2 - debug and management entries, 3 -
  551. * COS0 entry, 4 - COS1 entry.
  552. * COS1 | COS0 | DEBUG1 | DEBUG0 | MGMT
  553. * bit4 bit3 bit2 bit1 bit0
  554. * MCP and debug are strict
  555. */
  556. if (port)
  557. REG_WR(bp, NIG_REG_P1_TX_ARB_CLIENT_IS_STRICT, 0x3f);
  558. else
  559. REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x1ff);
  560. /* defines which entries (clients) are subjected to WFQ arbitration */
  561. REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CLIENT_IS_SUBJECT2WFQ :
  562. NIG_REG_P0_TX_ARB_CLIENT_IS_SUBJECT2WFQ, 0);
  563. /* Please notice the register address are note continuous and a
  564. * for here is note appropriate.In 2 port mode port0 only COS0-5
  565. * can be used. DEBUG1,DEBUG1,MGMT are never used for WFQ* In 4
  566. * port mode port1 only COS0-2 can be used. DEBUG1,DEBUG1,MGMT
  567. * are never used for WFQ
  568. */
  569. REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_0 :
  570. NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_0, 0x0);
  571. REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_1 :
  572. NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_1, 0x0);
  573. REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_2 :
  574. NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_2, 0x0);
  575. REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_3 :
  576. NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_3, 0x0);
  577. REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_4 :
  578. NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_4, 0x0);
  579. REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_5 :
  580. NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_5, 0x0);
  581. if (!port) {
  582. REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_6, 0x0);
  583. REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_7, 0x0);
  584. REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_8, 0x0);
  585. }
  586. bnx2x_ets_e3b0_set_credit_upper_bound_nig(params, min_w_val);
  587. }
  588. /******************************************************************************
  589. * Description:
  590. * Set credit upper bound for PBF.
  591. *.
  592. ******************************************************************************/
  593. static void bnx2x_ets_e3b0_set_credit_upper_bound_pbf(
  594. const struct link_params *params,
  595. const u32 min_w_val)
  596. {
  597. struct bnx2x *bp = params->bp;
  598. const u32 credit_upper_bound =
  599. bnx2x_ets_get_credit_upper_bound(min_w_val);
  600. const u8 port = params->port;
  601. u32 base_upper_bound = 0;
  602. u8 max_cos = 0;
  603. u8 i = 0;
  604. /* In 2 port mode port0 has COS0-5 that can be used for WFQ.In 4
  605. * port mode port1 has COS0-2 that can be used for WFQ.
  606. */
  607. if (!port) {
  608. base_upper_bound = PBF_REG_COS0_UPPER_BOUND_P0;
  609. max_cos = DCBX_E3B0_MAX_NUM_COS_PORT0;
  610. } else {
  611. base_upper_bound = PBF_REG_COS0_UPPER_BOUND_P1;
  612. max_cos = DCBX_E3B0_MAX_NUM_COS_PORT1;
  613. }
  614. for (i = 0; i < max_cos; i++)
  615. REG_WR(bp, base_upper_bound + (i << 2), credit_upper_bound);
  616. }
  617. /******************************************************************************
  618. * Description:
  619. * Will return the PBF ETS registers to init values.Except
  620. * credit_upper_bound.
  621. * That isn't used in this configuration (No WFQ is enabled) and will be
  622. * configured according to spec
  623. *.
  624. ******************************************************************************/
  625. static void bnx2x_ets_e3b0_pbf_disabled(const struct link_params *params)
  626. {
  627. struct bnx2x *bp = params->bp;
  628. const u8 port = params->port;
  629. const u32 min_w_val_pbf = ETS_E3B0_PBF_MIN_W_VAL;
  630. u8 i = 0;
  631. u32 base_weight = 0;
  632. u8 max_cos = 0;
  633. /* Mapping between entry priority to client number 0 - COS0
  634. * client, 2 - COS1, ... 5 - COS5)(HIGHEST) 4bits client num.
  635. * TODO_ETS - Should be done by reset value or init tool
  636. */
  637. if (port)
  638. /* 0x688 (|011|0 10|00 1|000) */
  639. REG_WR(bp, PBF_REG_ETS_ARB_PRIORITY_CLIENT_P1 , 0x688);
  640. else
  641. /* (10 1|100 |011|0 10|00 1|000) */
  642. REG_WR(bp, PBF_REG_ETS_ARB_PRIORITY_CLIENT_P0 , 0x2C688);
  643. /* TODO_ETS - Should be done by reset value or init tool */
  644. if (port)
  645. /* 0x688 (|011|0 10|00 1|000)*/
  646. REG_WR(bp, PBF_REG_ETS_ARB_CLIENT_CREDIT_MAP_P1, 0x688);
  647. else
  648. /* 0x2C688 (10 1|100 |011|0 10|00 1|000) */
  649. REG_WR(bp, PBF_REG_ETS_ARB_CLIENT_CREDIT_MAP_P0, 0x2C688);
  650. REG_WR(bp, (port) ? PBF_REG_ETS_ARB_NUM_STRICT_ARB_SLOTS_P1 :
  651. PBF_REG_ETS_ARB_NUM_STRICT_ARB_SLOTS_P0 , 0x100);
  652. REG_WR(bp, (port) ? PBF_REG_ETS_ARB_CLIENT_IS_STRICT_P1 :
  653. PBF_REG_ETS_ARB_CLIENT_IS_STRICT_P0 , 0);
  654. REG_WR(bp, (port) ? PBF_REG_ETS_ARB_CLIENT_IS_SUBJECT2WFQ_P1 :
  655. PBF_REG_ETS_ARB_CLIENT_IS_SUBJECT2WFQ_P0 , 0);
  656. /* In 2 port mode port0 has COS0-5 that can be used for WFQ.
  657. * In 4 port mode port1 has COS0-2 that can be used for WFQ.
  658. */
  659. if (!port) {
  660. base_weight = PBF_REG_COS0_WEIGHT_P0;
  661. max_cos = DCBX_E3B0_MAX_NUM_COS_PORT0;
  662. } else {
  663. base_weight = PBF_REG_COS0_WEIGHT_P1;
  664. max_cos = DCBX_E3B0_MAX_NUM_COS_PORT1;
  665. }
  666. for (i = 0; i < max_cos; i++)
  667. REG_WR(bp, base_weight + (0x4 * i), 0);
  668. bnx2x_ets_e3b0_set_credit_upper_bound_pbf(params, min_w_val_pbf);
  669. }
  670. /******************************************************************************
  671. * Description:
  672. * E3B0 disable will return basically the values to init values.
  673. *.
  674. ******************************************************************************/
  675. static int bnx2x_ets_e3b0_disabled(const struct link_params *params,
  676. const struct link_vars *vars)
  677. {
  678. struct bnx2x *bp = params->bp;
  679. if (!CHIP_IS_E3B0(bp)) {
  680. DP(NETIF_MSG_LINK,
  681. "bnx2x_ets_e3b0_disabled the chip isn't E3B0\n");
  682. return -EINVAL;
  683. }
  684. bnx2x_ets_e3b0_nig_disabled(params, vars);
  685. bnx2x_ets_e3b0_pbf_disabled(params);
  686. return 0;
  687. }
  688. /******************************************************************************
  689. * Description:
  690. * Disable will return basically the values to init values.
  691. *
  692. ******************************************************************************/
  693. int bnx2x_ets_disabled(struct link_params *params,
  694. struct link_vars *vars)
  695. {
  696. struct bnx2x *bp = params->bp;
  697. int bnx2x_status = 0;
  698. if ((CHIP_IS_E2(bp)) || (CHIP_IS_E3A0(bp)))
  699. bnx2x_ets_e2e3a0_disabled(params);
  700. else if (CHIP_IS_E3B0(bp))
  701. bnx2x_status = bnx2x_ets_e3b0_disabled(params, vars);
  702. else {
  703. DP(NETIF_MSG_LINK, "bnx2x_ets_disabled - chip not supported\n");
  704. return -EINVAL;
  705. }
  706. return bnx2x_status;
  707. }
  708. /******************************************************************************
  709. * Description
  710. * Set the COS mappimg to SP and BW until this point all the COS are not
  711. * set as SP or BW.
  712. ******************************************************************************/
  713. static int bnx2x_ets_e3b0_cli_map(const struct link_params *params,
  714. const struct bnx2x_ets_params *ets_params,
  715. const u8 cos_sp_bitmap,
  716. const u8 cos_bw_bitmap)
  717. {
  718. struct bnx2x *bp = params->bp;
  719. const u8 port = params->port;
  720. const u8 nig_cli_sp_bitmap = 0x7 | (cos_sp_bitmap << 3);
  721. const u8 pbf_cli_sp_bitmap = cos_sp_bitmap;
  722. const u8 nig_cli_subject2wfq_bitmap = cos_bw_bitmap << 3;
  723. const u8 pbf_cli_subject2wfq_bitmap = cos_bw_bitmap;
  724. REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CLIENT_IS_STRICT :
  725. NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, nig_cli_sp_bitmap);
  726. REG_WR(bp, (port) ? PBF_REG_ETS_ARB_CLIENT_IS_STRICT_P1 :
  727. PBF_REG_ETS_ARB_CLIENT_IS_STRICT_P0 , pbf_cli_sp_bitmap);
  728. REG_WR(bp, (port) ? NIG_REG_P1_TX_ARB_CLIENT_IS_SUBJECT2WFQ :
  729. NIG_REG_P0_TX_ARB_CLIENT_IS_SUBJECT2WFQ,
  730. nig_cli_subject2wfq_bitmap);
  731. REG_WR(bp, (port) ? PBF_REG_ETS_ARB_CLIENT_IS_SUBJECT2WFQ_P1 :
  732. PBF_REG_ETS_ARB_CLIENT_IS_SUBJECT2WFQ_P0,
  733. pbf_cli_subject2wfq_bitmap);
  734. return 0;
  735. }
  736. /******************************************************************************
  737. * Description:
  738. * This function is needed because NIG ARB_CREDIT_WEIGHT_X are
  739. * not continues and ARB_CREDIT_WEIGHT_0 + offset is suitable.
  740. ******************************************************************************/
  741. static int bnx2x_ets_e3b0_set_cos_bw(struct bnx2x *bp,
  742. const u8 cos_entry,
  743. const u32 min_w_val_nig,
  744. const u32 min_w_val_pbf,
  745. const u16 total_bw,
  746. const u8 bw,
  747. const u8 port)
  748. {
  749. u32 nig_reg_adress_crd_weight = 0;
  750. u32 pbf_reg_adress_crd_weight = 0;
  751. /* Calculate and set BW for this COS - use 1 instead of 0 for BW */
  752. const u32 cos_bw_nig = ((bw ? bw : 1) * min_w_val_nig) / total_bw;
  753. const u32 cos_bw_pbf = ((bw ? bw : 1) * min_w_val_pbf) / total_bw;
  754. switch (cos_entry) {
  755. case 0:
  756. nig_reg_adress_crd_weight =
  757. (port) ? NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_0 :
  758. NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_0;
  759. pbf_reg_adress_crd_weight = (port) ?
  760. PBF_REG_COS0_WEIGHT_P1 : PBF_REG_COS0_WEIGHT_P0;
  761. break;
  762. case 1:
  763. nig_reg_adress_crd_weight = (port) ?
  764. NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_1 :
  765. NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_1;
  766. pbf_reg_adress_crd_weight = (port) ?
  767. PBF_REG_COS1_WEIGHT_P1 : PBF_REG_COS1_WEIGHT_P0;
  768. break;
  769. case 2:
  770. nig_reg_adress_crd_weight = (port) ?
  771. NIG_REG_P1_TX_ARB_CREDIT_WEIGHT_2 :
  772. NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_2;
  773. pbf_reg_adress_crd_weight = (port) ?
  774. PBF_REG_COS2_WEIGHT_P1 : PBF_REG_COS2_WEIGHT_P0;
  775. break;
  776. case 3:
  777. if (port)
  778. return -EINVAL;
  779. nig_reg_adress_crd_weight =
  780. NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_3;
  781. pbf_reg_adress_crd_weight =
  782. PBF_REG_COS3_WEIGHT_P0;
  783. break;
  784. case 4:
  785. if (port)
  786. return -EINVAL;
  787. nig_reg_adress_crd_weight =
  788. NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_4;
  789. pbf_reg_adress_crd_weight = PBF_REG_COS4_WEIGHT_P0;
  790. break;
  791. case 5:
  792. if (port)
  793. return -EINVAL;
  794. nig_reg_adress_crd_weight =
  795. NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_5;
  796. pbf_reg_adress_crd_weight = PBF_REG_COS5_WEIGHT_P0;
  797. break;
  798. }
  799. REG_WR(bp, nig_reg_adress_crd_weight, cos_bw_nig);
  800. REG_WR(bp, pbf_reg_adress_crd_weight, cos_bw_pbf);
  801. return 0;
  802. }
  803. /******************************************************************************
  804. * Description:
  805. * Calculate the total BW.A value of 0 isn't legal.
  806. *
  807. ******************************************************************************/
  808. static int bnx2x_ets_e3b0_get_total_bw(
  809. const struct link_params *params,
  810. struct bnx2x_ets_params *ets_params,
  811. u16 *total_bw)
  812. {
  813. struct bnx2x *bp = params->bp;
  814. u8 cos_idx = 0;
  815. u8 is_bw_cos_exist = 0;
  816. *total_bw = 0 ;
  817. /* Calculate total BW requested */
  818. for (cos_idx = 0; cos_idx < ets_params->num_of_cos; cos_idx++) {
  819. if (ets_params->cos[cos_idx].state == bnx2x_cos_state_bw) {
  820. is_bw_cos_exist = 1;
  821. if (!ets_params->cos[cos_idx].params.bw_params.bw) {
  822. DP(NETIF_MSG_LINK, "bnx2x_ets_E3B0_config BW"
  823. "was set to 0\n");
  824. /* This is to prevent a state when ramrods
  825. * can't be sent
  826. */
  827. ets_params->cos[cos_idx].params.bw_params.bw
  828. = 1;
  829. }
  830. *total_bw +=
  831. ets_params->cos[cos_idx].params.bw_params.bw;
  832. }
  833. }
  834. /* Check total BW is valid */
  835. if ((is_bw_cos_exist == 1) && (*total_bw != 100)) {
  836. if (*total_bw == 0) {
  837. DP(NETIF_MSG_LINK,
  838. "bnx2x_ets_E3B0_config total BW shouldn't be 0\n");
  839. return -EINVAL;
  840. }
  841. DP(NETIF_MSG_LINK,
  842. "bnx2x_ets_E3B0_config total BW should be 100\n");
  843. /* We can handle a case whre the BW isn't 100 this can happen
  844. * if the TC are joined.
  845. */
  846. }
  847. return 0;
  848. }
  849. /******************************************************************************
  850. * Description:
  851. * Invalidate all the sp_pri_to_cos.
  852. *
  853. ******************************************************************************/
  854. static void bnx2x_ets_e3b0_sp_pri_to_cos_init(u8 *sp_pri_to_cos)
  855. {
  856. u8 pri = 0;
  857. for (pri = 0; pri < DCBX_MAX_NUM_COS; pri++)
  858. sp_pri_to_cos[pri] = DCBX_INVALID_COS;
  859. }
  860. /******************************************************************************
  861. * Description:
  862. * Calculate and set the SP (ARB_PRIORITY_CLIENT) NIG and PBF registers
  863. * according to sp_pri_to_cos.
  864. *
  865. ******************************************************************************/
  866. static int bnx2x_ets_e3b0_sp_pri_to_cos_set(const struct link_params *params,
  867. u8 *sp_pri_to_cos, const u8 pri,
  868. const u8 cos_entry)
  869. {
  870. struct bnx2x *bp = params->bp;
  871. const u8 port = params->port;
  872. const u8 max_num_of_cos = (port) ? DCBX_E3B0_MAX_NUM_COS_PORT1 :
  873. DCBX_E3B0_MAX_NUM_COS_PORT0;
  874. if (pri >= max_num_of_cos) {
  875. DP(NETIF_MSG_LINK, "bnx2x_ets_e3b0_sp_pri_to_cos_set invalid "
  876. "parameter Illegal strict priority\n");
  877. return -EINVAL;
  878. }
  879. if (sp_pri_to_cos[pri] != DCBX_INVALID_COS) {
  880. DP(NETIF_MSG_LINK, "bnx2x_ets_e3b0_sp_pri_to_cos_set invalid "
  881. "parameter There can't be two COS's with "
  882. "the same strict pri\n");
  883. return -EINVAL;
  884. }
  885. sp_pri_to_cos[pri] = cos_entry;
  886. return 0;
  887. }
  888. /******************************************************************************
  889. * Description:
  890. * Returns the correct value according to COS and priority in
  891. * the sp_pri_cli register.
  892. *
  893. ******************************************************************************/
  894. static u64 bnx2x_e3b0_sp_get_pri_cli_reg(const u8 cos, const u8 cos_offset,
  895. const u8 pri_set,
  896. const u8 pri_offset,
  897. const u8 entry_size)
  898. {
  899. u64 pri_cli_nig = 0;
  900. pri_cli_nig = ((u64)(cos + cos_offset)) << (entry_size *
  901. (pri_set + pri_offset));
  902. return pri_cli_nig;
  903. }
  904. /******************************************************************************
  905. * Description:
  906. * Returns the correct value according to COS and priority in the
  907. * sp_pri_cli register for NIG.
  908. *
  909. ******************************************************************************/
  910. static u64 bnx2x_e3b0_sp_get_pri_cli_reg_nig(const u8 cos, const u8 pri_set)
  911. {
  912. /* MCP Dbg0 and dbg1 are always with higher strict pri*/
  913. const u8 nig_cos_offset = 3;
  914. const u8 nig_pri_offset = 3;
  915. return bnx2x_e3b0_sp_get_pri_cli_reg(cos, nig_cos_offset, pri_set,
  916. nig_pri_offset, 4);
  917. }
  918. /******************************************************************************
  919. * Description:
  920. * Returns the correct value according to COS and priority in the
  921. * sp_pri_cli register for PBF.
  922. *
  923. ******************************************************************************/
  924. static u64 bnx2x_e3b0_sp_get_pri_cli_reg_pbf(const u8 cos, const u8 pri_set)
  925. {
  926. const u8 pbf_cos_offset = 0;
  927. const u8 pbf_pri_offset = 0;
  928. return bnx2x_e3b0_sp_get_pri_cli_reg(cos, pbf_cos_offset, pri_set,
  929. pbf_pri_offset, 3);
  930. }
  931. /******************************************************************************
  932. * Description:
  933. * Calculate and set the SP (ARB_PRIORITY_CLIENT) NIG and PBF registers
  934. * according to sp_pri_to_cos.(which COS has higher priority)
  935. *
  936. ******************************************************************************/
  937. static int bnx2x_ets_e3b0_sp_set_pri_cli_reg(const struct link_params *params,
  938. u8 *sp_pri_to_cos)
  939. {
  940. struct bnx2x *bp = params->bp;
  941. u8 i = 0;
  942. const u8 port = params->port;
  943. /* MCP Dbg0 and dbg1 are always with higher strict pri*/
  944. u64 pri_cli_nig = 0x210;
  945. u32 pri_cli_pbf = 0x0;
  946. u8 pri_set = 0;
  947. u8 pri_bitmask = 0;
  948. const u8 max_num_of_cos = (port) ? DCBX_E3B0_MAX_NUM_COS_PORT1 :
  949. DCBX_E3B0_MAX_NUM_COS_PORT0;
  950. u8 cos_bit_to_set = (1 << max_num_of_cos) - 1;
  951. /* Set all the strict priority first */
  952. for (i = 0; i < max_num_of_cos; i++) {
  953. if (sp_pri_to_cos[i] != DCBX_INVALID_COS) {
  954. if (sp_pri_to_cos[i] >= DCBX_MAX_NUM_COS) {
  955. DP(NETIF_MSG_LINK,
  956. "bnx2x_ets_e3b0_sp_set_pri_cli_reg "
  957. "invalid cos entry\n");
  958. return -EINVAL;
  959. }
  960. pri_cli_nig |= bnx2x_e3b0_sp_get_pri_cli_reg_nig(
  961. sp_pri_to_cos[i], pri_set);
  962. pri_cli_pbf |= bnx2x_e3b0_sp_get_pri_cli_reg_pbf(
  963. sp_pri_to_cos[i], pri_set);
  964. pri_bitmask = 1 << sp_pri_to_cos[i];
  965. /* COS is used remove it from bitmap.*/
  966. if (!(pri_bitmask & cos_bit_to_set)) {
  967. DP(NETIF_MSG_LINK,
  968. "bnx2x_ets_e3b0_sp_set_pri_cli_reg "
  969. "invalid There can't be two COS's with"
  970. " the same strict pri\n");
  971. return -EINVAL;
  972. }
  973. cos_bit_to_set &= ~pri_bitmask;
  974. pri_set++;
  975. }
  976. }
  977. /* Set all the Non strict priority i= COS*/
  978. for (i = 0; i < max_num_of_cos; i++) {
  979. pri_bitmask = 1 << i;
  980. /* Check if COS was already used for SP */
  981. if (pri_bitmask & cos_bit_to_set) {
  982. /* COS wasn't used for SP */
  983. pri_cli_nig |= bnx2x_e3b0_sp_get_pri_cli_reg_nig(
  984. i, pri_set);
  985. pri_cli_pbf |= bnx2x_e3b0_sp_get_pri_cli_reg_pbf(
  986. i, pri_set);
  987. /* COS is used remove it from bitmap.*/
  988. cos_bit_to_set &= ~pri_bitmask;
  989. pri_set++;
  990. }
  991. }
  992. if (pri_set != max_num_of_cos) {
  993. DP(NETIF_MSG_LINK, "bnx2x_ets_e3b0_sp_set_pri_cli_reg not all "
  994. "entries were set\n");
  995. return -EINVAL;
  996. }
  997. if (port) {
  998. /* Only 6 usable clients*/
  999. REG_WR(bp, NIG_REG_P1_TX_ARB_PRIORITY_CLIENT2_LSB,
  1000. (u32)pri_cli_nig);
  1001. REG_WR(bp, PBF_REG_ETS_ARB_PRIORITY_CLIENT_P1 , pri_cli_pbf);
  1002. } else {
  1003. /* Only 9 usable clients*/
  1004. const u32 pri_cli_nig_lsb = (u32) (pri_cli_nig);
  1005. const u32 pri_cli_nig_msb = (u32) ((pri_cli_nig >> 32) & 0xF);
  1006. REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT2_LSB,
  1007. pri_cli_nig_lsb);
  1008. REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT2_MSB,
  1009. pri_cli_nig_msb);
  1010. REG_WR(bp, PBF_REG_ETS_ARB_PRIORITY_CLIENT_P0 , pri_cli_pbf);
  1011. }
  1012. return 0;
  1013. }
  1014. /******************************************************************************
  1015. * Description:
  1016. * Configure the COS to ETS according to BW and SP settings.
  1017. ******************************************************************************/
  1018. int bnx2x_ets_e3b0_config(const struct link_params *params,
  1019. const struct link_vars *vars,
  1020. struct bnx2x_ets_params *ets_params)
  1021. {
  1022. struct bnx2x *bp = params->bp;
  1023. int bnx2x_status = 0;
  1024. const u8 port = params->port;
  1025. u16 total_bw = 0;
  1026. const u32 min_w_val_nig = bnx2x_ets_get_min_w_val_nig(vars);
  1027. const u32 min_w_val_pbf = ETS_E3B0_PBF_MIN_W_VAL;
  1028. u8 cos_bw_bitmap = 0;
  1029. u8 cos_sp_bitmap = 0;
  1030. u8 sp_pri_to_cos[DCBX_MAX_NUM_COS] = {0};
  1031. const u8 max_num_of_cos = (port) ? DCBX_E3B0_MAX_NUM_COS_PORT1 :
  1032. DCBX_E3B0_MAX_NUM_COS_PORT0;
  1033. u8 cos_entry = 0;
  1034. if (!CHIP_IS_E3B0(bp)) {
  1035. DP(NETIF_MSG_LINK,
  1036. "bnx2x_ets_e3b0_disabled the chip isn't E3B0\n");
  1037. return -EINVAL;
  1038. }
  1039. if ((ets_params->num_of_cos > max_num_of_cos)) {
  1040. DP(NETIF_MSG_LINK, "bnx2x_ets_E3B0_config the number of COS "
  1041. "isn't supported\n");
  1042. return -EINVAL;
  1043. }
  1044. /* Prepare sp strict priority parameters*/
  1045. bnx2x_ets_e3b0_sp_pri_to_cos_init(sp_pri_to_cos);
  1046. /* Prepare BW parameters*/
  1047. bnx2x_status = bnx2x_ets_e3b0_get_total_bw(params, ets_params,
  1048. &total_bw);
  1049. if (bnx2x_status) {
  1050. DP(NETIF_MSG_LINK,
  1051. "bnx2x_ets_E3B0_config get_total_bw failed\n");
  1052. return -EINVAL;
  1053. }
  1054. /* Upper bound is set according to current link speed (min_w_val
  1055. * should be the same for upper bound and COS credit val).
  1056. */
  1057. bnx2x_ets_e3b0_set_credit_upper_bound_nig(params, min_w_val_nig);
  1058. bnx2x_ets_e3b0_set_credit_upper_bound_pbf(params, min_w_val_pbf);
  1059. for (cos_entry = 0; cos_entry < ets_params->num_of_cos; cos_entry++) {
  1060. if (bnx2x_cos_state_bw == ets_params->cos[cos_entry].state) {
  1061. cos_bw_bitmap |= (1 << cos_entry);
  1062. /* The function also sets the BW in HW(not the mappin
  1063. * yet)
  1064. */
  1065. bnx2x_status = bnx2x_ets_e3b0_set_cos_bw(
  1066. bp, cos_entry, min_w_val_nig, min_w_val_pbf,
  1067. total_bw,
  1068. ets_params->cos[cos_entry].params.bw_params.bw,
  1069. port);
  1070. } else if (bnx2x_cos_state_strict ==
  1071. ets_params->cos[cos_entry].state){
  1072. cos_sp_bitmap |= (1 << cos_entry);
  1073. bnx2x_status = bnx2x_ets_e3b0_sp_pri_to_cos_set(
  1074. params,
  1075. sp_pri_to_cos,
  1076. ets_params->cos[cos_entry].params.sp_params.pri,
  1077. cos_entry);
  1078. } else {
  1079. DP(NETIF_MSG_LINK,
  1080. "bnx2x_ets_e3b0_config cos state not valid\n");
  1081. return -EINVAL;
  1082. }
  1083. if (bnx2x_status) {
  1084. DP(NETIF_MSG_LINK,
  1085. "bnx2x_ets_e3b0_config set cos bw failed\n");
  1086. return bnx2x_status;
  1087. }
  1088. }
  1089. /* Set SP register (which COS has higher priority) */
  1090. bnx2x_status = bnx2x_ets_e3b0_sp_set_pri_cli_reg(params,
  1091. sp_pri_to_cos);
  1092. if (bnx2x_status) {
  1093. DP(NETIF_MSG_LINK,
  1094. "bnx2x_ets_E3B0_config set_pri_cli_reg failed\n");
  1095. return bnx2x_status;
  1096. }
  1097. /* Set client mapping of BW and strict */
  1098. bnx2x_status = bnx2x_ets_e3b0_cli_map(params, ets_params,
  1099. cos_sp_bitmap,
  1100. cos_bw_bitmap);
  1101. if (bnx2x_status) {
  1102. DP(NETIF_MSG_LINK, "bnx2x_ets_E3B0_config SP failed\n");
  1103. return bnx2x_status;
  1104. }
  1105. return 0;
  1106. }
  1107. static void bnx2x_ets_bw_limit_common(const struct link_params *params)
  1108. {
  1109. /* ETS disabled configuration */
  1110. struct bnx2x *bp = params->bp;
  1111. DP(NETIF_MSG_LINK, "ETS enabled BW limit configuration\n");
  1112. /* Defines which entries (clients) are subjected to WFQ arbitration
  1113. * COS0 0x8
  1114. * COS1 0x10
  1115. */
  1116. REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_SUBJECT2WFQ, 0x18);
  1117. /* Mapping between the ARB_CREDIT_WEIGHT registers and actual
  1118. * client numbers (WEIGHT_0 does not actually have to represent
  1119. * client 0)
  1120. * PRI4 | PRI3 | PRI2 | PRI1 | PRI0
  1121. * cos1-001 cos0-000 dbg1-100 dbg0-011 MCP-010
  1122. */
  1123. REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_CREDIT_MAP, 0x111A);
  1124. REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_0,
  1125. ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
  1126. REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_UPPER_BOUND_1,
  1127. ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
  1128. /* ETS mode enabled*/
  1129. REG_WR(bp, PBF_REG_ETS_ENABLED, 1);
  1130. /* Defines the number of consecutive slots for the strict priority */
  1131. REG_WR(bp, PBF_REG_NUM_STRICT_ARB_SLOTS, 0);
  1132. /* Bitmap of 5bits length. Each bit specifies whether the entry behaves
  1133. * as strict. Bits 0,1,2 - debug and management entries, 3 - COS0
  1134. * entry, 4 - COS1 entry.
  1135. * COS1 | COS0 | DEBUG21 | DEBUG0 | MGMT
  1136. * bit4 bit3 bit2 bit1 bit0
  1137. * MCP and debug are strict
  1138. */
  1139. REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x7);
  1140. /* Upper bound that COS0_WEIGHT can reach in the WFQ arbiter.*/
  1141. REG_WR(bp, PBF_REG_COS0_UPPER_BOUND,
  1142. ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
  1143. REG_WR(bp, PBF_REG_COS1_UPPER_BOUND,
  1144. ETS_BW_LIMIT_CREDIT_UPPER_BOUND);
  1145. }
  1146. void bnx2x_ets_bw_limit(const struct link_params *params, const u32 cos0_bw,
  1147. const u32 cos1_bw)
  1148. {
  1149. /* ETS disabled configuration*/
  1150. struct bnx2x *bp = params->bp;
  1151. const u32 total_bw = cos0_bw + cos1_bw;
  1152. u32 cos0_credit_weight = 0;
  1153. u32 cos1_credit_weight = 0;
  1154. DP(NETIF_MSG_LINK, "ETS enabled BW limit configuration\n");
  1155. if ((!total_bw) ||
  1156. (!cos0_bw) ||
  1157. (!cos1_bw)) {
  1158. DP(NETIF_MSG_LINK, "Total BW can't be zero\n");
  1159. return;
  1160. }
  1161. cos0_credit_weight = (cos0_bw * ETS_BW_LIMIT_CREDIT_WEIGHT)/
  1162. total_bw;
  1163. cos1_credit_weight = (cos1_bw * ETS_BW_LIMIT_CREDIT_WEIGHT)/
  1164. total_bw;
  1165. bnx2x_ets_bw_limit_common(params);
  1166. REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_0, cos0_credit_weight);
  1167. REG_WR(bp, NIG_REG_P0_TX_ARB_CREDIT_WEIGHT_1, cos1_credit_weight);
  1168. REG_WR(bp, PBF_REG_COS0_WEIGHT, cos0_credit_weight);
  1169. REG_WR(bp, PBF_REG_COS1_WEIGHT, cos1_credit_weight);
  1170. }
  1171. int bnx2x_ets_strict(const struct link_params *params, const u8 strict_cos)
  1172. {
  1173. /* ETS disabled configuration*/
  1174. struct bnx2x *bp = params->bp;
  1175. u32 val = 0;
  1176. DP(NETIF_MSG_LINK, "ETS enabled strict configuration\n");
  1177. /* Bitmap of 5bits length. Each bit specifies whether the entry behaves
  1178. * as strict. Bits 0,1,2 - debug and management entries,
  1179. * 3 - COS0 entry, 4 - COS1 entry.
  1180. * COS1 | COS0 | DEBUG21 | DEBUG0 | MGMT
  1181. * bit4 bit3 bit2 bit1 bit0
  1182. * MCP and debug are strict
  1183. */
  1184. REG_WR(bp, NIG_REG_P0_TX_ARB_CLIENT_IS_STRICT, 0x1F);
  1185. /* For strict priority entries defines the number of consecutive slots
  1186. * for the highest priority.
  1187. */
  1188. REG_WR(bp, NIG_REG_P0_TX_ARB_NUM_STRICT_ARB_SLOTS, 0x100);
  1189. /* ETS mode disable */
  1190. REG_WR(bp, PBF_REG_ETS_ENABLED, 0);
  1191. /* Defines the number of consecutive slots for the strict priority */
  1192. REG_WR(bp, PBF_REG_NUM_STRICT_ARB_SLOTS, 0x100);
  1193. /* Defines the number of consecutive slots for the strict priority */
  1194. REG_WR(bp, PBF_REG_HIGH_PRIORITY_COS_NUM, strict_cos);
  1195. /* Mapping between entry priority to client number (0,1,2 -debug and
  1196. * management clients, 3 - COS0 client, 4 - COS client)(HIGHEST)
  1197. * 3bits client num.
  1198. * PRI4 | PRI3 | PRI2 | PRI1 | PRI0
  1199. * dbg0-010 dbg1-001 cos1-100 cos0-011 MCP-000
  1200. * dbg0-010 dbg1-001 cos0-011 cos1-100 MCP-000
  1201. */
  1202. val = (!strict_cos) ? 0x2318 : 0x22E0;
  1203. REG_WR(bp, NIG_REG_P0_TX_ARB_PRIORITY_CLIENT, val);
  1204. return 0;
  1205. }
  1206. /******************************************************************/
  1207. /* PFC section */
  1208. /******************************************************************/
  1209. static void bnx2x_update_pfc_xmac(struct link_params *params,
  1210. struct link_vars *vars,
  1211. u8 is_lb)
  1212. {
  1213. struct bnx2x *bp = params->bp;
  1214. u32 xmac_base;
  1215. u32 pause_val, pfc0_val, pfc1_val;
  1216. /* XMAC base adrr */
  1217. xmac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  1218. /* Initialize pause and pfc registers */
  1219. pause_val = 0x18000;
  1220. pfc0_val = 0xFFFF8000;
  1221. pfc1_val = 0x2;
  1222. /* No PFC support */
  1223. if (!(params->feature_config_flags &
  1224. FEATURE_CONFIG_PFC_ENABLED)) {
  1225. /* RX flow control - Process pause frame in receive direction
  1226. */
  1227. if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
  1228. pause_val |= XMAC_PAUSE_CTRL_REG_RX_PAUSE_EN;
  1229. /* TX flow control - Send pause packet when buffer is full */
  1230. if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
  1231. pause_val |= XMAC_PAUSE_CTRL_REG_TX_PAUSE_EN;
  1232. } else {/* PFC support */
  1233. pfc1_val |= XMAC_PFC_CTRL_HI_REG_PFC_REFRESH_EN |
  1234. XMAC_PFC_CTRL_HI_REG_PFC_STATS_EN |
  1235. XMAC_PFC_CTRL_HI_REG_RX_PFC_EN |
  1236. XMAC_PFC_CTRL_HI_REG_TX_PFC_EN |
  1237. XMAC_PFC_CTRL_HI_REG_FORCE_PFC_XON;
  1238. /* Write pause and PFC registers */
  1239. REG_WR(bp, xmac_base + XMAC_REG_PAUSE_CTRL, pause_val);
  1240. REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL, pfc0_val);
  1241. REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL_HI, pfc1_val);
  1242. pfc1_val &= ~XMAC_PFC_CTRL_HI_REG_FORCE_PFC_XON;
  1243. }
  1244. /* Write pause and PFC registers */
  1245. REG_WR(bp, xmac_base + XMAC_REG_PAUSE_CTRL, pause_val);
  1246. REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL, pfc0_val);
  1247. REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL_HI, pfc1_val);
  1248. /* Set MAC address for source TX Pause/PFC frames */
  1249. REG_WR(bp, xmac_base + XMAC_REG_CTRL_SA_LO,
  1250. ((params->mac_addr[2] << 24) |
  1251. (params->mac_addr[3] << 16) |
  1252. (params->mac_addr[4] << 8) |
  1253. (params->mac_addr[5])));
  1254. REG_WR(bp, xmac_base + XMAC_REG_CTRL_SA_HI,
  1255. ((params->mac_addr[0] << 8) |
  1256. (params->mac_addr[1])));
  1257. udelay(30);
  1258. }
  1259. /******************************************************************/
  1260. /* MAC/PBF section */
  1261. /******************************************************************/
  1262. static void bnx2x_set_mdio_clk(struct bnx2x *bp, u32 chip_id,
  1263. u32 emac_base)
  1264. {
  1265. u32 new_mode, cur_mode;
  1266. u32 clc_cnt;
  1267. /* Set clause 45 mode, slow down the MDIO clock to 2.5MHz
  1268. * (a value of 49==0x31) and make sure that the AUTO poll is off
  1269. */
  1270. cur_mode = REG_RD(bp, emac_base + EMAC_REG_EMAC_MDIO_MODE);
  1271. if (USES_WARPCORE(bp))
  1272. clc_cnt = 74L << EMAC_MDIO_MODE_CLOCK_CNT_BITSHIFT;
  1273. else
  1274. clc_cnt = 49L << EMAC_MDIO_MODE_CLOCK_CNT_BITSHIFT;
  1275. if (((cur_mode & EMAC_MDIO_MODE_CLOCK_CNT) == clc_cnt) &&
  1276. (cur_mode & (EMAC_MDIO_MODE_CLAUSE_45)))
  1277. return;
  1278. new_mode = cur_mode &
  1279. ~(EMAC_MDIO_MODE_AUTO_POLL | EMAC_MDIO_MODE_CLOCK_CNT);
  1280. new_mode |= clc_cnt;
  1281. new_mode |= (EMAC_MDIO_MODE_CLAUSE_45);
  1282. DP(NETIF_MSG_LINK, "Changing emac_mode from 0x%x to 0x%x\n",
  1283. cur_mode, new_mode);
  1284. REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_MODE, new_mode);
  1285. udelay(40);
  1286. }
  1287. static void bnx2x_set_mdio_emac_per_phy(struct bnx2x *bp,
  1288. struct link_params *params)
  1289. {
  1290. u8 phy_index;
  1291. /* Set mdio clock per phy */
  1292. for (phy_index = INT_PHY; phy_index < params->num_phys;
  1293. phy_index++)
  1294. bnx2x_set_mdio_clk(bp, params->chip_id,
  1295. params->phy[phy_index].mdio_ctrl);
  1296. }
  1297. static u8 bnx2x_is_4_port_mode(struct bnx2x *bp)
  1298. {
  1299. u32 port4mode_ovwr_val;
  1300. /* Check 4-port override enabled */
  1301. port4mode_ovwr_val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  1302. if (port4mode_ovwr_val & (1<<0)) {
  1303. /* Return 4-port mode override value */
  1304. return ((port4mode_ovwr_val & (1<<1)) == (1<<1));
  1305. }
  1306. /* Return 4-port mode from input pin */
  1307. return (u8)REG_RD(bp, MISC_REG_PORT4MODE_EN);
  1308. }
  1309. static void bnx2x_emac_init(struct link_params *params,
  1310. struct link_vars *vars)
  1311. {
  1312. /* reset and unreset the emac core */
  1313. struct bnx2x *bp = params->bp;
  1314. u8 port = params->port;
  1315. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  1316. u32 val;
  1317. u16 timeout;
  1318. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  1319. (MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE << port));
  1320. udelay(5);
  1321. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  1322. (MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE << port));
  1323. /* init emac - use read-modify-write */
  1324. /* self clear reset */
  1325. val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
  1326. EMAC_WR(bp, EMAC_REG_EMAC_MODE, (val | EMAC_MODE_RESET));
  1327. timeout = 200;
  1328. do {
  1329. val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
  1330. DP(NETIF_MSG_LINK, "EMAC reset reg is %u\n", val);
  1331. if (!timeout) {
  1332. DP(NETIF_MSG_LINK, "EMAC timeout!\n");
  1333. return;
  1334. }
  1335. timeout--;
  1336. } while (val & EMAC_MODE_RESET);
  1337. bnx2x_set_mdio_emac_per_phy(bp, params);
  1338. /* Set mac address */
  1339. val = ((params->mac_addr[0] << 8) |
  1340. params->mac_addr[1]);
  1341. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH, val);
  1342. val = ((params->mac_addr[2] << 24) |
  1343. (params->mac_addr[3] << 16) |
  1344. (params->mac_addr[4] << 8) |
  1345. params->mac_addr[5]);
  1346. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + 4, val);
  1347. }
  1348. static void bnx2x_set_xumac_nig(struct link_params *params,
  1349. u16 tx_pause_en,
  1350. u8 enable)
  1351. {
  1352. struct bnx2x *bp = params->bp;
  1353. REG_WR(bp, params->port ? NIG_REG_P1_MAC_IN_EN : NIG_REG_P0_MAC_IN_EN,
  1354. enable);
  1355. REG_WR(bp, params->port ? NIG_REG_P1_MAC_OUT_EN : NIG_REG_P0_MAC_OUT_EN,
  1356. enable);
  1357. REG_WR(bp, params->port ? NIG_REG_P1_MAC_PAUSE_OUT_EN :
  1358. NIG_REG_P0_MAC_PAUSE_OUT_EN, tx_pause_en);
  1359. }
  1360. static void bnx2x_set_umac_rxtx(struct link_params *params, u8 en)
  1361. {
  1362. u32 umac_base = params->port ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  1363. u32 val;
  1364. struct bnx2x *bp = params->bp;
  1365. if (!(REG_RD(bp, MISC_REG_RESET_REG_2) &
  1366. (MISC_REGISTERS_RESET_REG_2_UMAC0 << params->port)))
  1367. return;
  1368. val = REG_RD(bp, umac_base + UMAC_REG_COMMAND_CONFIG);
  1369. if (en)
  1370. val |= (UMAC_COMMAND_CONFIG_REG_TX_ENA |
  1371. UMAC_COMMAND_CONFIG_REG_RX_ENA);
  1372. else
  1373. val &= ~(UMAC_COMMAND_CONFIG_REG_TX_ENA |
  1374. UMAC_COMMAND_CONFIG_REG_RX_ENA);
  1375. /* Disable RX and TX */
  1376. REG_WR(bp, umac_base + UMAC_REG_COMMAND_CONFIG, val);
  1377. }
  1378. static void bnx2x_umac_enable(struct link_params *params,
  1379. struct link_vars *vars, u8 lb)
  1380. {
  1381. u32 val;
  1382. u32 umac_base = params->port ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  1383. struct bnx2x *bp = params->bp;
  1384. /* Reset UMAC */
  1385. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  1386. (MISC_REGISTERS_RESET_REG_2_UMAC0 << params->port));
  1387. usleep_range(1000, 2000);
  1388. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  1389. (MISC_REGISTERS_RESET_REG_2_UMAC0 << params->port));
  1390. DP(NETIF_MSG_LINK, "enabling UMAC\n");
  1391. /* This register opens the gate for the UMAC despite its name */
  1392. REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + params->port*4, 1);
  1393. val = UMAC_COMMAND_CONFIG_REG_PROMIS_EN |
  1394. UMAC_COMMAND_CONFIG_REG_PAD_EN |
  1395. UMAC_COMMAND_CONFIG_REG_SW_RESET |
  1396. UMAC_COMMAND_CONFIG_REG_NO_LGTH_CHECK;
  1397. switch (vars->line_speed) {
  1398. case SPEED_10:
  1399. val |= (0<<2);
  1400. break;
  1401. case SPEED_100:
  1402. val |= (1<<2);
  1403. break;
  1404. case SPEED_1000:
  1405. val |= (2<<2);
  1406. break;
  1407. case SPEED_2500:
  1408. val |= (3<<2);
  1409. break;
  1410. default:
  1411. DP(NETIF_MSG_LINK, "Invalid speed for UMAC %d\n",
  1412. vars->line_speed);
  1413. break;
  1414. }
  1415. if (!(vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
  1416. val |= UMAC_COMMAND_CONFIG_REG_IGNORE_TX_PAUSE;
  1417. if (!(vars->flow_ctrl & BNX2X_FLOW_CTRL_RX))
  1418. val |= UMAC_COMMAND_CONFIG_REG_PAUSE_IGNORE;
  1419. if (vars->duplex == DUPLEX_HALF)
  1420. val |= UMAC_COMMAND_CONFIG_REG_HD_ENA;
  1421. REG_WR(bp, umac_base + UMAC_REG_COMMAND_CONFIG, val);
  1422. udelay(50);
  1423. /* Configure UMAC for EEE */
  1424. if (vars->eee_status & SHMEM_EEE_ADV_STATUS_MASK) {
  1425. DP(NETIF_MSG_LINK, "configured UMAC for EEE\n");
  1426. REG_WR(bp, umac_base + UMAC_REG_UMAC_EEE_CTRL,
  1427. UMAC_UMAC_EEE_CTRL_REG_EEE_EN);
  1428. REG_WR(bp, umac_base + UMAC_REG_EEE_WAKE_TIMER, 0x11);
  1429. } else {
  1430. REG_WR(bp, umac_base + UMAC_REG_UMAC_EEE_CTRL, 0x0);
  1431. }
  1432. /* Set MAC address for source TX Pause/PFC frames (under SW reset) */
  1433. REG_WR(bp, umac_base + UMAC_REG_MAC_ADDR0,
  1434. ((params->mac_addr[2] << 24) |
  1435. (params->mac_addr[3] << 16) |
  1436. (params->mac_addr[4] << 8) |
  1437. (params->mac_addr[5])));
  1438. REG_WR(bp, umac_base + UMAC_REG_MAC_ADDR1,
  1439. ((params->mac_addr[0] << 8) |
  1440. (params->mac_addr[1])));
  1441. /* Enable RX and TX */
  1442. val &= ~UMAC_COMMAND_CONFIG_REG_PAD_EN;
  1443. val |= UMAC_COMMAND_CONFIG_REG_TX_ENA |
  1444. UMAC_COMMAND_CONFIG_REG_RX_ENA;
  1445. REG_WR(bp, umac_base + UMAC_REG_COMMAND_CONFIG, val);
  1446. udelay(50);
  1447. /* Remove SW Reset */
  1448. val &= ~UMAC_COMMAND_CONFIG_REG_SW_RESET;
  1449. /* Check loopback mode */
  1450. if (lb)
  1451. val |= UMAC_COMMAND_CONFIG_REG_LOOP_ENA;
  1452. REG_WR(bp, umac_base + UMAC_REG_COMMAND_CONFIG, val);
  1453. /* Maximum Frame Length (RW). Defines a 14-Bit maximum frame
  1454. * length used by the MAC receive logic to check frames.
  1455. */
  1456. REG_WR(bp, umac_base + UMAC_REG_MAXFR, 0x2710);
  1457. bnx2x_set_xumac_nig(params,
  1458. ((vars->flow_ctrl & BNX2X_FLOW_CTRL_TX) != 0), 1);
  1459. vars->mac_type = MAC_TYPE_UMAC;
  1460. }
  1461. /* Define the XMAC mode */
  1462. static void bnx2x_xmac_init(struct link_params *params, u32 max_speed)
  1463. {
  1464. struct bnx2x *bp = params->bp;
  1465. u32 is_port4mode = bnx2x_is_4_port_mode(bp);
  1466. /* In 4-port mode, need to set the mode only once, so if XMAC is
  1467. * already out of reset, it means the mode has already been set,
  1468. * and it must not* reset the XMAC again, since it controls both
  1469. * ports of the path
  1470. */
  1471. if (((CHIP_NUM(bp) == CHIP_NUM_57840_4_10) ||
  1472. (CHIP_NUM(bp) == CHIP_NUM_57840_2_20) ||
  1473. (CHIP_NUM(bp) == CHIP_NUM_57840_OBSOLETE)) &&
  1474. is_port4mode &&
  1475. (REG_RD(bp, MISC_REG_RESET_REG_2) &
  1476. MISC_REGISTERS_RESET_REG_2_XMAC)) {
  1477. DP(NETIF_MSG_LINK,
  1478. "XMAC already out of reset in 4-port mode\n");
  1479. return;
  1480. }
  1481. /* Hard reset */
  1482. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  1483. MISC_REGISTERS_RESET_REG_2_XMAC);
  1484. usleep_range(1000, 2000);
  1485. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  1486. MISC_REGISTERS_RESET_REG_2_XMAC);
  1487. if (is_port4mode) {
  1488. DP(NETIF_MSG_LINK, "Init XMAC to 2 ports x 10G per path\n");
  1489. /* Set the number of ports on the system side to up to 2 */
  1490. REG_WR(bp, MISC_REG_XMAC_CORE_PORT_MODE, 1);
  1491. /* Set the number of ports on the Warp Core to 10G */
  1492. REG_WR(bp, MISC_REG_XMAC_PHY_PORT_MODE, 3);
  1493. } else {
  1494. /* Set the number of ports on the system side to 1 */
  1495. REG_WR(bp, MISC_REG_XMAC_CORE_PORT_MODE, 0);
  1496. if (max_speed == SPEED_10000) {
  1497. DP(NETIF_MSG_LINK,
  1498. "Init XMAC to 10G x 1 port per path\n");
  1499. /* Set the number of ports on the Warp Core to 10G */
  1500. REG_WR(bp, MISC_REG_XMAC_PHY_PORT_MODE, 3);
  1501. } else {
  1502. DP(NETIF_MSG_LINK,
  1503. "Init XMAC to 20G x 2 ports per path\n");
  1504. /* Set the number of ports on the Warp Core to 20G */
  1505. REG_WR(bp, MISC_REG_XMAC_PHY_PORT_MODE, 1);
  1506. }
  1507. }
  1508. /* Soft reset */
  1509. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  1510. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT);
  1511. usleep_range(1000, 2000);
  1512. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  1513. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT);
  1514. }
  1515. static void bnx2x_set_xmac_rxtx(struct link_params *params, u8 en)
  1516. {
  1517. u8 port = params->port;
  1518. struct bnx2x *bp = params->bp;
  1519. u32 pfc_ctrl, xmac_base = (port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  1520. u32 val;
  1521. if (REG_RD(bp, MISC_REG_RESET_REG_2) &
  1522. MISC_REGISTERS_RESET_REG_2_XMAC) {
  1523. /* Send an indication to change the state in the NIG back to XON
  1524. * Clearing this bit enables the next set of this bit to get
  1525. * rising edge
  1526. */
  1527. pfc_ctrl = REG_RD(bp, xmac_base + XMAC_REG_PFC_CTRL_HI);
  1528. REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL_HI,
  1529. (pfc_ctrl & ~(1<<1)));
  1530. REG_WR(bp, xmac_base + XMAC_REG_PFC_CTRL_HI,
  1531. (pfc_ctrl | (1<<1)));
  1532. DP(NETIF_MSG_LINK, "Disable XMAC on port %x\n", port);
  1533. val = REG_RD(bp, xmac_base + XMAC_REG_CTRL);
  1534. if (en)
  1535. val |= (XMAC_CTRL_REG_TX_EN | XMAC_CTRL_REG_RX_EN);
  1536. else
  1537. val &= ~(XMAC_CTRL_REG_TX_EN | XMAC_CTRL_REG_RX_EN);
  1538. REG_WR(bp, xmac_base + XMAC_REG_CTRL, val);
  1539. }
  1540. }
  1541. static int bnx2x_xmac_enable(struct link_params *params,
  1542. struct link_vars *vars, u8 lb)
  1543. {
  1544. u32 val, xmac_base;
  1545. struct bnx2x *bp = params->bp;
  1546. DP(NETIF_MSG_LINK, "enabling XMAC\n");
  1547. xmac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  1548. bnx2x_xmac_init(params, vars->line_speed);
  1549. /* This register determines on which events the MAC will assert
  1550. * error on the i/f to the NIG along w/ EOP.
  1551. */
  1552. /* This register tells the NIG whether to send traffic to UMAC
  1553. * or XMAC
  1554. */
  1555. REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + params->port*4, 0);
  1556. /* When XMAC is in XLGMII mode, disable sending idles for fault
  1557. * detection.
  1558. */
  1559. if (!(params->phy[INT_PHY].flags & FLAGS_TX_ERROR_CHECK)) {
  1560. REG_WR(bp, xmac_base + XMAC_REG_RX_LSS_CTRL,
  1561. (XMAC_RX_LSS_CTRL_REG_LOCAL_FAULT_DISABLE |
  1562. XMAC_RX_LSS_CTRL_REG_REMOTE_FAULT_DISABLE));
  1563. REG_WR(bp, xmac_base + XMAC_REG_CLEAR_RX_LSS_STATUS, 0);
  1564. REG_WR(bp, xmac_base + XMAC_REG_CLEAR_RX_LSS_STATUS,
  1565. XMAC_CLEAR_RX_LSS_STATUS_REG_CLEAR_LOCAL_FAULT_STATUS |
  1566. XMAC_CLEAR_RX_LSS_STATUS_REG_CLEAR_REMOTE_FAULT_STATUS);
  1567. }
  1568. /* Set Max packet size */
  1569. REG_WR(bp, xmac_base + XMAC_REG_RX_MAX_SIZE, 0x2710);
  1570. /* CRC append for Tx packets */
  1571. REG_WR(bp, xmac_base + XMAC_REG_TX_CTRL, 0xC800);
  1572. /* update PFC */
  1573. bnx2x_update_pfc_xmac(params, vars, 0);
  1574. if (vars->eee_status & SHMEM_EEE_ADV_STATUS_MASK) {
  1575. DP(NETIF_MSG_LINK, "Setting XMAC for EEE\n");
  1576. REG_WR(bp, xmac_base + XMAC_REG_EEE_TIMERS_HI, 0x1380008);
  1577. REG_WR(bp, xmac_base + XMAC_REG_EEE_CTRL, 0x1);
  1578. } else {
  1579. REG_WR(bp, xmac_base + XMAC_REG_EEE_CTRL, 0x0);
  1580. }
  1581. /* Enable TX and RX */
  1582. val = XMAC_CTRL_REG_TX_EN | XMAC_CTRL_REG_RX_EN;
  1583. /* Set MAC in XLGMII mode for dual-mode */
  1584. if ((vars->line_speed == SPEED_20000) &&
  1585. (params->phy[INT_PHY].supported &
  1586. SUPPORTED_20000baseKR2_Full))
  1587. val |= XMAC_CTRL_REG_XLGMII_ALIGN_ENB;
  1588. /* Check loopback mode */
  1589. if (lb)
  1590. val |= XMAC_CTRL_REG_LINE_LOCAL_LPBK;
  1591. REG_WR(bp, xmac_base + XMAC_REG_CTRL, val);
  1592. bnx2x_set_xumac_nig(params,
  1593. ((vars->flow_ctrl & BNX2X_FLOW_CTRL_TX) != 0), 1);
  1594. vars->mac_type = MAC_TYPE_XMAC;
  1595. return 0;
  1596. }
  1597. static int bnx2x_emac_enable(struct link_params *params,
  1598. struct link_vars *vars, u8 lb)
  1599. {
  1600. struct bnx2x *bp = params->bp;
  1601. u8 port = params->port;
  1602. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  1603. u32 val;
  1604. DP(NETIF_MSG_LINK, "enabling EMAC\n");
  1605. /* Disable BMAC */
  1606. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  1607. (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
  1608. /* enable emac and not bmac */
  1609. REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + port*4, 1);
  1610. /* ASIC */
  1611. if (vars->phy_flags & PHY_XGXS_FLAG) {
  1612. u32 ser_lane = ((params->lane_config &
  1613. PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
  1614. PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
  1615. DP(NETIF_MSG_LINK, "XGXS\n");
  1616. /* select the master lanes (out of 0-3) */
  1617. REG_WR(bp, NIG_REG_XGXS_LANE_SEL_P0 + port*4, ser_lane);
  1618. /* select XGXS */
  1619. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  1620. } else { /* SerDes */
  1621. DP(NETIF_MSG_LINK, "SerDes\n");
  1622. /* select SerDes */
  1623. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 0);
  1624. }
  1625. bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_RX_MODE,
  1626. EMAC_RX_MODE_RESET);
  1627. bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
  1628. EMAC_TX_MODE_RESET);
  1629. /* pause enable/disable */
  1630. bnx2x_bits_dis(bp, emac_base + EMAC_REG_EMAC_RX_MODE,
  1631. EMAC_RX_MODE_FLOW_EN);
  1632. bnx2x_bits_dis(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
  1633. (EMAC_TX_MODE_EXT_PAUSE_EN |
  1634. EMAC_TX_MODE_FLOW_EN));
  1635. if (!(params->feature_config_flags &
  1636. FEATURE_CONFIG_PFC_ENABLED)) {
  1637. if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
  1638. bnx2x_bits_en(bp, emac_base +
  1639. EMAC_REG_EMAC_RX_MODE,
  1640. EMAC_RX_MODE_FLOW_EN);
  1641. if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
  1642. bnx2x_bits_en(bp, emac_base +
  1643. EMAC_REG_EMAC_TX_MODE,
  1644. (EMAC_TX_MODE_EXT_PAUSE_EN |
  1645. EMAC_TX_MODE_FLOW_EN));
  1646. } else
  1647. bnx2x_bits_en(bp, emac_base + EMAC_REG_EMAC_TX_MODE,
  1648. EMAC_TX_MODE_FLOW_EN);
  1649. /* KEEP_VLAN_TAG, promiscuous */
  1650. val = REG_RD(bp, emac_base + EMAC_REG_EMAC_RX_MODE);
  1651. val |= EMAC_RX_MODE_KEEP_VLAN_TAG | EMAC_RX_MODE_PROMISCUOUS;
  1652. /* Setting this bit causes MAC control frames (except for pause
  1653. * frames) to be passed on for processing. This setting has no
  1654. * affect on the operation of the pause frames. This bit effects
  1655. * all packets regardless of RX Parser packet sorting logic.
  1656. * Turn the PFC off to make sure we are in Xon state before
  1657. * enabling it.
  1658. */
  1659. EMAC_WR(bp, EMAC_REG_RX_PFC_MODE, 0);
  1660. if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED) {
  1661. DP(NETIF_MSG_LINK, "PFC is enabled\n");
  1662. /* Enable PFC again */
  1663. EMAC_WR(bp, EMAC_REG_RX_PFC_MODE,
  1664. EMAC_REG_RX_PFC_MODE_RX_EN |
  1665. EMAC_REG_RX_PFC_MODE_TX_EN |
  1666. EMAC_REG_RX_PFC_MODE_PRIORITIES);
  1667. EMAC_WR(bp, EMAC_REG_RX_PFC_PARAM,
  1668. ((0x0101 <<
  1669. EMAC_REG_RX_PFC_PARAM_OPCODE_BITSHIFT) |
  1670. (0x00ff <<
  1671. EMAC_REG_RX_PFC_PARAM_PRIORITY_EN_BITSHIFT)));
  1672. val |= EMAC_RX_MODE_KEEP_MAC_CONTROL;
  1673. }
  1674. EMAC_WR(bp, EMAC_REG_EMAC_RX_MODE, val);
  1675. /* Set Loopback */
  1676. val = REG_RD(bp, emac_base + EMAC_REG_EMAC_MODE);
  1677. if (lb)
  1678. val |= 0x810;
  1679. else
  1680. val &= ~0x810;
  1681. EMAC_WR(bp, EMAC_REG_EMAC_MODE, val);
  1682. /* Enable emac */
  1683. REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 1);
  1684. /* Enable emac for jumbo packets */
  1685. EMAC_WR(bp, EMAC_REG_EMAC_RX_MTU_SIZE,
  1686. (EMAC_RX_MTU_SIZE_JUMBO_ENA |
  1687. (ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD)));
  1688. /* Strip CRC */
  1689. REG_WR(bp, NIG_REG_NIG_INGRESS_EMAC0_NO_CRC + port*4, 0x1);
  1690. /* Disable the NIG in/out to the bmac */
  1691. REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0x0);
  1692. REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + port*4, 0x0);
  1693. REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0x0);
  1694. /* Enable the NIG in/out to the emac */
  1695. REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0x1);
  1696. val = 0;
  1697. if ((params->feature_config_flags &
  1698. FEATURE_CONFIG_PFC_ENABLED) ||
  1699. (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
  1700. val = 1;
  1701. REG_WR(bp, NIG_REG_EMAC0_PAUSE_OUT_EN + port*4, val);
  1702. REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0x1);
  1703. REG_WR(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4, 0x0);
  1704. vars->mac_type = MAC_TYPE_EMAC;
  1705. return 0;
  1706. }
  1707. static void bnx2x_update_pfc_bmac1(struct link_params *params,
  1708. struct link_vars *vars)
  1709. {
  1710. u32 wb_data[2];
  1711. struct bnx2x *bp = params->bp;
  1712. u32 bmac_addr = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
  1713. NIG_REG_INGRESS_BMAC0_MEM;
  1714. u32 val = 0x14;
  1715. if ((!(params->feature_config_flags &
  1716. FEATURE_CONFIG_PFC_ENABLED)) &&
  1717. (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX))
  1718. /* Enable BigMAC to react on received Pause packets */
  1719. val |= (1<<5);
  1720. wb_data[0] = val;
  1721. wb_data[1] = 0;
  1722. REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_CONTROL, wb_data, 2);
  1723. /* TX control */
  1724. val = 0xc0;
  1725. if (!(params->feature_config_flags &
  1726. FEATURE_CONFIG_PFC_ENABLED) &&
  1727. (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
  1728. val |= 0x800000;
  1729. wb_data[0] = val;
  1730. wb_data[1] = 0;
  1731. REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_CONTROL, wb_data, 2);
  1732. }
  1733. static void bnx2x_update_pfc_bmac2(struct link_params *params,
  1734. struct link_vars *vars,
  1735. u8 is_lb)
  1736. {
  1737. /* Set rx control: Strip CRC and enable BigMAC to relay
  1738. * control packets to the system as well
  1739. */
  1740. u32 wb_data[2];
  1741. struct bnx2x *bp = params->bp;
  1742. u32 bmac_addr = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
  1743. NIG_REG_INGRESS_BMAC0_MEM;
  1744. u32 val = 0x14;
  1745. if ((!(params->feature_config_flags &
  1746. FEATURE_CONFIG_PFC_ENABLED)) &&
  1747. (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX))
  1748. /* Enable BigMAC to react on received Pause packets */
  1749. val |= (1<<5);
  1750. wb_data[0] = val;
  1751. wb_data[1] = 0;
  1752. REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_CONTROL, wb_data, 2);
  1753. udelay(30);
  1754. /* Tx control */
  1755. val = 0xc0;
  1756. if (!(params->feature_config_flags &
  1757. FEATURE_CONFIG_PFC_ENABLED) &&
  1758. (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
  1759. val |= 0x800000;
  1760. wb_data[0] = val;
  1761. wb_data[1] = 0;
  1762. REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_CONTROL, wb_data, 2);
  1763. if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED) {
  1764. DP(NETIF_MSG_LINK, "PFC is enabled\n");
  1765. /* Enable PFC RX & TX & STATS and set 8 COS */
  1766. wb_data[0] = 0x0;
  1767. wb_data[0] |= (1<<0); /* RX */
  1768. wb_data[0] |= (1<<1); /* TX */
  1769. wb_data[0] |= (1<<2); /* Force initial Xon */
  1770. wb_data[0] |= (1<<3); /* 8 cos */
  1771. wb_data[0] |= (1<<5); /* STATS */
  1772. wb_data[1] = 0;
  1773. REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_PFC_CONTROL,
  1774. wb_data, 2);
  1775. /* Clear the force Xon */
  1776. wb_data[0] &= ~(1<<2);
  1777. } else {
  1778. DP(NETIF_MSG_LINK, "PFC is disabled\n");
  1779. /* Disable PFC RX & TX & STATS and set 8 COS */
  1780. wb_data[0] = 0x8;
  1781. wb_data[1] = 0;
  1782. }
  1783. REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_PFC_CONTROL, wb_data, 2);
  1784. /* Set Time (based unit is 512 bit time) between automatic
  1785. * re-sending of PP packets amd enable automatic re-send of
  1786. * Per-Priroity Packet as long as pp_gen is asserted and
  1787. * pp_disable is low.
  1788. */
  1789. val = 0x8000;
  1790. if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
  1791. val |= (1<<16); /* enable automatic re-send */
  1792. wb_data[0] = val;
  1793. wb_data[1] = 0;
  1794. REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_PAUSE_CONTROL,
  1795. wb_data, 2);
  1796. /* mac control */
  1797. val = 0x3; /* Enable RX and TX */
  1798. if (is_lb) {
  1799. val |= 0x4; /* Local loopback */
  1800. DP(NETIF_MSG_LINK, "enable bmac loopback\n");
  1801. }
  1802. /* When PFC enabled, Pass pause frames towards the NIG. */
  1803. if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
  1804. val |= ((1<<6)|(1<<5));
  1805. wb_data[0] = val;
  1806. wb_data[1] = 0;
  1807. REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_BMAC_CONTROL, wb_data, 2);
  1808. }
  1809. /******************************************************************************
  1810. * Description:
  1811. * This function is needed because NIG ARB_CREDIT_WEIGHT_X are
  1812. * not continues and ARB_CREDIT_WEIGHT_0 + offset is suitable.
  1813. ******************************************************************************/
  1814. static int bnx2x_pfc_nig_rx_priority_mask(struct bnx2x *bp,
  1815. u8 cos_entry,
  1816. u32 priority_mask, u8 port)
  1817. {
  1818. u32 nig_reg_rx_priority_mask_add = 0;
  1819. switch (cos_entry) {
  1820. case 0:
  1821. nig_reg_rx_priority_mask_add = (port) ?
  1822. NIG_REG_P1_RX_COS0_PRIORITY_MASK :
  1823. NIG_REG_P0_RX_COS0_PRIORITY_MASK;
  1824. break;
  1825. case 1:
  1826. nig_reg_rx_priority_mask_add = (port) ?
  1827. NIG_REG_P1_RX_COS1_PRIORITY_MASK :
  1828. NIG_REG_P0_RX_COS1_PRIORITY_MASK;
  1829. break;
  1830. case 2:
  1831. nig_reg_rx_priority_mask_add = (port) ?
  1832. NIG_REG_P1_RX_COS2_PRIORITY_MASK :
  1833. NIG_REG_P0_RX_COS2_PRIORITY_MASK;
  1834. break;
  1835. case 3:
  1836. if (port)
  1837. return -EINVAL;
  1838. nig_reg_rx_priority_mask_add = NIG_REG_P0_RX_COS3_PRIORITY_MASK;
  1839. break;
  1840. case 4:
  1841. if (port)
  1842. return -EINVAL;
  1843. nig_reg_rx_priority_mask_add = NIG_REG_P0_RX_COS4_PRIORITY_MASK;
  1844. break;
  1845. case 5:
  1846. if (port)
  1847. return -EINVAL;
  1848. nig_reg_rx_priority_mask_add = NIG_REG_P0_RX_COS5_PRIORITY_MASK;
  1849. break;
  1850. }
  1851. REG_WR(bp, nig_reg_rx_priority_mask_add, priority_mask);
  1852. return 0;
  1853. }
  1854. static void bnx2x_update_mng(struct link_params *params, u32 link_status)
  1855. {
  1856. struct bnx2x *bp = params->bp;
  1857. REG_WR(bp, params->shmem_base +
  1858. offsetof(struct shmem_region,
  1859. port_mb[params->port].link_status), link_status);
  1860. }
  1861. static void bnx2x_update_link_attr(struct link_params *params, u32 link_attr)
  1862. {
  1863. struct bnx2x *bp = params->bp;
  1864. if (SHMEM2_HAS(bp, link_attr_sync))
  1865. REG_WR(bp, params->shmem2_base +
  1866. offsetof(struct shmem2_region,
  1867. link_attr_sync[params->port]), link_attr);
  1868. }
  1869. static void bnx2x_update_pfc_nig(struct link_params *params,
  1870. struct link_vars *vars,
  1871. struct bnx2x_nig_brb_pfc_port_params *nig_params)
  1872. {
  1873. u32 xcm_mask = 0, ppp_enable = 0, pause_enable = 0, llfc_out_en = 0;
  1874. u32 llfc_enable = 0, xcm_out_en = 0, hwpfc_enable = 0;
  1875. u32 pkt_priority_to_cos = 0;
  1876. struct bnx2x *bp = params->bp;
  1877. u8 port = params->port;
  1878. int set_pfc = params->feature_config_flags &
  1879. FEATURE_CONFIG_PFC_ENABLED;
  1880. DP(NETIF_MSG_LINK, "updating pfc nig parameters\n");
  1881. /* When NIG_LLH0_XCM_MASK_REG_LLHX_XCM_MASK_BCN bit is set
  1882. * MAC control frames (that are not pause packets)
  1883. * will be forwarded to the XCM.
  1884. */
  1885. xcm_mask = REG_RD(bp, port ? NIG_REG_LLH1_XCM_MASK :
  1886. NIG_REG_LLH0_XCM_MASK);
  1887. /* NIG params will override non PFC params, since it's possible to
  1888. * do transition from PFC to SAFC
  1889. */
  1890. if (set_pfc) {
  1891. pause_enable = 0;
  1892. llfc_out_en = 0;
  1893. llfc_enable = 0;
  1894. if (CHIP_IS_E3(bp))
  1895. ppp_enable = 0;
  1896. else
  1897. ppp_enable = 1;
  1898. xcm_mask &= ~(port ? NIG_LLH1_XCM_MASK_REG_LLH1_XCM_MASK_BCN :
  1899. NIG_LLH0_XCM_MASK_REG_LLH0_XCM_MASK_BCN);
  1900. xcm_out_en = 0;
  1901. hwpfc_enable = 1;
  1902. } else {
  1903. if (nig_params) {
  1904. llfc_out_en = nig_params->llfc_out_en;
  1905. llfc_enable = nig_params->llfc_enable;
  1906. pause_enable = nig_params->pause_enable;
  1907. } else /* Default non PFC mode - PAUSE */
  1908. pause_enable = 1;
  1909. xcm_mask |= (port ? NIG_LLH1_XCM_MASK_REG_LLH1_XCM_MASK_BCN :
  1910. NIG_LLH0_XCM_MASK_REG_LLH0_XCM_MASK_BCN);
  1911. xcm_out_en = 1;
  1912. }
  1913. if (CHIP_IS_E3(bp))
  1914. REG_WR(bp, port ? NIG_REG_BRB1_PAUSE_IN_EN :
  1915. NIG_REG_BRB0_PAUSE_IN_EN, pause_enable);
  1916. REG_WR(bp, port ? NIG_REG_LLFC_OUT_EN_1 :
  1917. NIG_REG_LLFC_OUT_EN_0, llfc_out_en);
  1918. REG_WR(bp, port ? NIG_REG_LLFC_ENABLE_1 :
  1919. NIG_REG_LLFC_ENABLE_0, llfc_enable);
  1920. REG_WR(bp, port ? NIG_REG_PAUSE_ENABLE_1 :
  1921. NIG_REG_PAUSE_ENABLE_0, pause_enable);
  1922. REG_WR(bp, port ? NIG_REG_PPP_ENABLE_1 :
  1923. NIG_REG_PPP_ENABLE_0, ppp_enable);
  1924. REG_WR(bp, port ? NIG_REG_LLH1_XCM_MASK :
  1925. NIG_REG_LLH0_XCM_MASK, xcm_mask);
  1926. REG_WR(bp, port ? NIG_REG_LLFC_EGRESS_SRC_ENABLE_1 :
  1927. NIG_REG_LLFC_EGRESS_SRC_ENABLE_0, 0x7);
  1928. /* Output enable for RX_XCM # IF */
  1929. REG_WR(bp, port ? NIG_REG_XCM1_OUT_EN :
  1930. NIG_REG_XCM0_OUT_EN, xcm_out_en);
  1931. /* HW PFC TX enable */
  1932. REG_WR(bp, port ? NIG_REG_P1_HWPFC_ENABLE :
  1933. NIG_REG_P0_HWPFC_ENABLE, hwpfc_enable);
  1934. if (nig_params) {
  1935. u8 i = 0;
  1936. pkt_priority_to_cos = nig_params->pkt_priority_to_cos;
  1937. for (i = 0; i < nig_params->num_of_rx_cos_priority_mask; i++)
  1938. bnx2x_pfc_nig_rx_priority_mask(bp, i,
  1939. nig_params->rx_cos_priority_mask[i], port);
  1940. REG_WR(bp, port ? NIG_REG_LLFC_HIGH_PRIORITY_CLASSES_1 :
  1941. NIG_REG_LLFC_HIGH_PRIORITY_CLASSES_0,
  1942. nig_params->llfc_high_priority_classes);
  1943. REG_WR(bp, port ? NIG_REG_LLFC_LOW_PRIORITY_CLASSES_1 :
  1944. NIG_REG_LLFC_LOW_PRIORITY_CLASSES_0,
  1945. nig_params->llfc_low_priority_classes);
  1946. }
  1947. REG_WR(bp, port ? NIG_REG_P1_PKT_PRIORITY_TO_COS :
  1948. NIG_REG_P0_PKT_PRIORITY_TO_COS,
  1949. pkt_priority_to_cos);
  1950. }
  1951. int bnx2x_update_pfc(struct link_params *params,
  1952. struct link_vars *vars,
  1953. struct bnx2x_nig_brb_pfc_port_params *pfc_params)
  1954. {
  1955. /* The PFC and pause are orthogonal to one another, meaning when
  1956. * PFC is enabled, the pause are disabled, and when PFC is
  1957. * disabled, pause are set according to the pause result.
  1958. */
  1959. u32 val;
  1960. struct bnx2x *bp = params->bp;
  1961. u8 bmac_loopback = (params->loopback_mode == LOOPBACK_BMAC);
  1962. if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
  1963. vars->link_status |= LINK_STATUS_PFC_ENABLED;
  1964. else
  1965. vars->link_status &= ~LINK_STATUS_PFC_ENABLED;
  1966. bnx2x_update_mng(params, vars->link_status);
  1967. /* Update NIG params */
  1968. bnx2x_update_pfc_nig(params, vars, pfc_params);
  1969. if (!vars->link_up)
  1970. return 0;
  1971. DP(NETIF_MSG_LINK, "About to update PFC in BMAC\n");
  1972. if (CHIP_IS_E3(bp)) {
  1973. if (vars->mac_type == MAC_TYPE_XMAC)
  1974. bnx2x_update_pfc_xmac(params, vars, 0);
  1975. } else {
  1976. val = REG_RD(bp, MISC_REG_RESET_REG_2);
  1977. if ((val &
  1978. (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << params->port))
  1979. == 0) {
  1980. DP(NETIF_MSG_LINK, "About to update PFC in EMAC\n");
  1981. bnx2x_emac_enable(params, vars, 0);
  1982. return 0;
  1983. }
  1984. if (CHIP_IS_E2(bp))
  1985. bnx2x_update_pfc_bmac2(params, vars, bmac_loopback);
  1986. else
  1987. bnx2x_update_pfc_bmac1(params, vars);
  1988. val = 0;
  1989. if ((params->feature_config_flags &
  1990. FEATURE_CONFIG_PFC_ENABLED) ||
  1991. (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
  1992. val = 1;
  1993. REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + params->port*4, val);
  1994. }
  1995. return 0;
  1996. }
  1997. static int bnx2x_bmac1_enable(struct link_params *params,
  1998. struct link_vars *vars,
  1999. u8 is_lb)
  2000. {
  2001. struct bnx2x *bp = params->bp;
  2002. u8 port = params->port;
  2003. u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
  2004. NIG_REG_INGRESS_BMAC0_MEM;
  2005. u32 wb_data[2];
  2006. u32 val;
  2007. DP(NETIF_MSG_LINK, "Enabling BigMAC1\n");
  2008. /* XGXS control */
  2009. wb_data[0] = 0x3c;
  2010. wb_data[1] = 0;
  2011. REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_BMAC_XGXS_CONTROL,
  2012. wb_data, 2);
  2013. /* TX MAC SA */
  2014. wb_data[0] = ((params->mac_addr[2] << 24) |
  2015. (params->mac_addr[3] << 16) |
  2016. (params->mac_addr[4] << 8) |
  2017. params->mac_addr[5]);
  2018. wb_data[1] = ((params->mac_addr[0] << 8) |
  2019. params->mac_addr[1]);
  2020. REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_SOURCE_ADDR, wb_data, 2);
  2021. /* MAC control */
  2022. val = 0x3;
  2023. if (is_lb) {
  2024. val |= 0x4;
  2025. DP(NETIF_MSG_LINK, "enable bmac loopback\n");
  2026. }
  2027. wb_data[0] = val;
  2028. wb_data[1] = 0;
  2029. REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_BMAC_CONTROL, wb_data, 2);
  2030. /* Set rx mtu */
  2031. wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
  2032. wb_data[1] = 0;
  2033. REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_MAX_SIZE, wb_data, 2);
  2034. bnx2x_update_pfc_bmac1(params, vars);
  2035. /* Set tx mtu */
  2036. wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
  2037. wb_data[1] = 0;
  2038. REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_TX_MAX_SIZE, wb_data, 2);
  2039. /* Set cnt max size */
  2040. wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
  2041. wb_data[1] = 0;
  2042. REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_CNT_MAX_SIZE, wb_data, 2);
  2043. /* Configure SAFC */
  2044. wb_data[0] = 0x1000200;
  2045. wb_data[1] = 0;
  2046. REG_WR_DMAE(bp, bmac_addr + BIGMAC_REGISTER_RX_LLFC_MSG_FLDS,
  2047. wb_data, 2);
  2048. return 0;
  2049. }
  2050. static int bnx2x_bmac2_enable(struct link_params *params,
  2051. struct link_vars *vars,
  2052. u8 is_lb)
  2053. {
  2054. struct bnx2x *bp = params->bp;
  2055. u8 port = params->port;
  2056. u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
  2057. NIG_REG_INGRESS_BMAC0_MEM;
  2058. u32 wb_data[2];
  2059. DP(NETIF_MSG_LINK, "Enabling BigMAC2\n");
  2060. wb_data[0] = 0;
  2061. wb_data[1] = 0;
  2062. REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_BMAC_CONTROL, wb_data, 2);
  2063. udelay(30);
  2064. /* XGXS control: Reset phy HW, MDIO registers, PHY PLL and BMAC */
  2065. wb_data[0] = 0x3c;
  2066. wb_data[1] = 0;
  2067. REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_BMAC_XGXS_CONTROL,
  2068. wb_data, 2);
  2069. udelay(30);
  2070. /* TX MAC SA */
  2071. wb_data[0] = ((params->mac_addr[2] << 24) |
  2072. (params->mac_addr[3] << 16) |
  2073. (params->mac_addr[4] << 8) |
  2074. params->mac_addr[5]);
  2075. wb_data[1] = ((params->mac_addr[0] << 8) |
  2076. params->mac_addr[1]);
  2077. REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_SOURCE_ADDR,
  2078. wb_data, 2);
  2079. udelay(30);
  2080. /* Configure SAFC */
  2081. wb_data[0] = 0x1000200;
  2082. wb_data[1] = 0;
  2083. REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_LLFC_MSG_FLDS,
  2084. wb_data, 2);
  2085. udelay(30);
  2086. /* Set RX MTU */
  2087. wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
  2088. wb_data[1] = 0;
  2089. REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_RX_MAX_SIZE, wb_data, 2);
  2090. udelay(30);
  2091. /* Set TX MTU */
  2092. wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD;
  2093. wb_data[1] = 0;
  2094. REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_TX_MAX_SIZE, wb_data, 2);
  2095. udelay(30);
  2096. /* Set cnt max size */
  2097. wb_data[0] = ETH_MAX_JUMBO_PACKET_SIZE + ETH_OVREHEAD - 2;
  2098. wb_data[1] = 0;
  2099. REG_WR_DMAE(bp, bmac_addr + BIGMAC2_REGISTER_CNT_MAX_SIZE, wb_data, 2);
  2100. udelay(30);
  2101. bnx2x_update_pfc_bmac2(params, vars, is_lb);
  2102. return 0;
  2103. }
  2104. static int bnx2x_bmac_enable(struct link_params *params,
  2105. struct link_vars *vars,
  2106. u8 is_lb, u8 reset_bmac)
  2107. {
  2108. int rc = 0;
  2109. u8 port = params->port;
  2110. struct bnx2x *bp = params->bp;
  2111. u32 val;
  2112. /* Reset and unreset the BigMac */
  2113. if (reset_bmac) {
  2114. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  2115. (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
  2116. usleep_range(1000, 2000);
  2117. }
  2118. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  2119. (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
  2120. /* Enable access for bmac registers */
  2121. REG_WR(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4, 0x1);
  2122. /* Enable BMAC according to BMAC type*/
  2123. if (CHIP_IS_E2(bp))
  2124. rc = bnx2x_bmac2_enable(params, vars, is_lb);
  2125. else
  2126. rc = bnx2x_bmac1_enable(params, vars, is_lb);
  2127. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 0x1);
  2128. REG_WR(bp, NIG_REG_XGXS_LANE_SEL_P0 + port*4, 0x0);
  2129. REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + port*4, 0x0);
  2130. val = 0;
  2131. if ((params->feature_config_flags &
  2132. FEATURE_CONFIG_PFC_ENABLED) ||
  2133. (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX))
  2134. val = 1;
  2135. REG_WR(bp, NIG_REG_BMAC0_PAUSE_OUT_EN + port*4, val);
  2136. REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0x0);
  2137. REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0x0);
  2138. REG_WR(bp, NIG_REG_EMAC0_PAUSE_OUT_EN + port*4, 0x0);
  2139. REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0x1);
  2140. REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0x1);
  2141. vars->mac_type = MAC_TYPE_BMAC;
  2142. return rc;
  2143. }
  2144. static void bnx2x_set_bmac_rx(struct bnx2x *bp, u32 chip_id, u8 port, u8 en)
  2145. {
  2146. u32 bmac_addr = port ? NIG_REG_INGRESS_BMAC1_MEM :
  2147. NIG_REG_INGRESS_BMAC0_MEM;
  2148. u32 wb_data[2];
  2149. u32 nig_bmac_enable = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port*4);
  2150. if (CHIP_IS_E2(bp))
  2151. bmac_addr += BIGMAC2_REGISTER_BMAC_CONTROL;
  2152. else
  2153. bmac_addr += BIGMAC_REGISTER_BMAC_CONTROL;
  2154. /* Only if the bmac is out of reset */
  2155. if (REG_RD(bp, MISC_REG_RESET_REG_2) &
  2156. (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port) &&
  2157. nig_bmac_enable) {
  2158. /* Clear Rx Enable bit in BMAC_CONTROL register */
  2159. REG_RD_DMAE(bp, bmac_addr, wb_data, 2);
  2160. if (en)
  2161. wb_data[0] |= BMAC_CONTROL_RX_ENABLE;
  2162. else
  2163. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  2164. REG_WR_DMAE(bp, bmac_addr, wb_data, 2);
  2165. usleep_range(1000, 2000);
  2166. }
  2167. }
  2168. static int bnx2x_pbf_update(struct link_params *params, u32 flow_ctrl,
  2169. u32 line_speed)
  2170. {
  2171. struct bnx2x *bp = params->bp;
  2172. u8 port = params->port;
  2173. u32 init_crd, crd;
  2174. u32 count = 1000;
  2175. /* Disable port */
  2176. REG_WR(bp, PBF_REG_DISABLE_NEW_TASK_PROC_P0 + port*4, 0x1);
  2177. /* Wait for init credit */
  2178. init_crd = REG_RD(bp, PBF_REG_P0_INIT_CRD + port*4);
  2179. crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
  2180. DP(NETIF_MSG_LINK, "init_crd 0x%x crd 0x%x\n", init_crd, crd);
  2181. while ((init_crd != crd) && count) {
  2182. usleep_range(5000, 10000);
  2183. crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
  2184. count--;
  2185. }
  2186. crd = REG_RD(bp, PBF_REG_P0_CREDIT + port*8);
  2187. if (init_crd != crd) {
  2188. DP(NETIF_MSG_LINK, "BUG! init_crd 0x%x != crd 0x%x\n",
  2189. init_crd, crd);
  2190. return -EINVAL;
  2191. }
  2192. if (flow_ctrl & BNX2X_FLOW_CTRL_RX ||
  2193. line_speed == SPEED_10 ||
  2194. line_speed == SPEED_100 ||
  2195. line_speed == SPEED_1000 ||
  2196. line_speed == SPEED_2500) {
  2197. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 1);
  2198. /* Update threshold */
  2199. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, 0);
  2200. /* Update init credit */
  2201. init_crd = 778; /* (800-18-4) */
  2202. } else {
  2203. u32 thresh = (ETH_MAX_JUMBO_PACKET_SIZE +
  2204. ETH_OVREHEAD)/16;
  2205. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  2206. /* Update threshold */
  2207. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, thresh);
  2208. /* Update init credit */
  2209. switch (line_speed) {
  2210. case SPEED_10000:
  2211. init_crd = thresh + 553 - 22;
  2212. break;
  2213. default:
  2214. DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
  2215. line_speed);
  2216. return -EINVAL;
  2217. }
  2218. }
  2219. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, init_crd);
  2220. DP(NETIF_MSG_LINK, "PBF updated to speed %d credit %d\n",
  2221. line_speed, init_crd);
  2222. /* Probe the credit changes */
  2223. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0x1);
  2224. usleep_range(5000, 10000);
  2225. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0x0);
  2226. /* Enable port */
  2227. REG_WR(bp, PBF_REG_DISABLE_NEW_TASK_PROC_P0 + port*4, 0x0);
  2228. return 0;
  2229. }
  2230. /**
  2231. * bnx2x_get_emac_base - retrive emac base address
  2232. *
  2233. * @bp: driver handle
  2234. * @mdc_mdio_access: access type
  2235. * @port: port id
  2236. *
  2237. * This function selects the MDC/MDIO access (through emac0 or
  2238. * emac1) depend on the mdc_mdio_access, port, port swapped. Each
  2239. * phy has a default access mode, which could also be overridden
  2240. * by nvram configuration. This parameter, whether this is the
  2241. * default phy configuration, or the nvram overrun
  2242. * configuration, is passed here as mdc_mdio_access and selects
  2243. * the emac_base for the CL45 read/writes operations
  2244. */
  2245. static u32 bnx2x_get_emac_base(struct bnx2x *bp,
  2246. u32 mdc_mdio_access, u8 port)
  2247. {
  2248. u32 emac_base = 0;
  2249. switch (mdc_mdio_access) {
  2250. case SHARED_HW_CFG_MDC_MDIO_ACCESS1_PHY_TYPE:
  2251. break;
  2252. case SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC0:
  2253. if (REG_RD(bp, NIG_REG_PORT_SWAP))
  2254. emac_base = GRCBASE_EMAC1;
  2255. else
  2256. emac_base = GRCBASE_EMAC0;
  2257. break;
  2258. case SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1:
  2259. if (REG_RD(bp, NIG_REG_PORT_SWAP))
  2260. emac_base = GRCBASE_EMAC0;
  2261. else
  2262. emac_base = GRCBASE_EMAC1;
  2263. break;
  2264. case SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH:
  2265. emac_base = (port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  2266. break;
  2267. case SHARED_HW_CFG_MDC_MDIO_ACCESS1_SWAPPED:
  2268. emac_base = (port) ? GRCBASE_EMAC0 : GRCBASE_EMAC1;
  2269. break;
  2270. default:
  2271. break;
  2272. }
  2273. return emac_base;
  2274. }
  2275. /******************************************************************/
  2276. /* CL22 access functions */
  2277. /******************************************************************/
  2278. static int bnx2x_cl22_write(struct bnx2x *bp,
  2279. struct bnx2x_phy *phy,
  2280. u16 reg, u16 val)
  2281. {
  2282. u32 tmp, mode;
  2283. u8 i;
  2284. int rc = 0;
  2285. /* Switch to CL22 */
  2286. mode = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
  2287. REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE,
  2288. mode & ~EMAC_MDIO_MODE_CLAUSE_45);
  2289. /* Address */
  2290. tmp = ((phy->addr << 21) | (reg << 16) | val |
  2291. EMAC_MDIO_COMM_COMMAND_WRITE_22 |
  2292. EMAC_MDIO_COMM_START_BUSY);
  2293. REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
  2294. for (i = 0; i < 50; i++) {
  2295. udelay(10);
  2296. tmp = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
  2297. if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
  2298. udelay(5);
  2299. break;
  2300. }
  2301. }
  2302. if (tmp & EMAC_MDIO_COMM_START_BUSY) {
  2303. DP(NETIF_MSG_LINK, "write phy register failed\n");
  2304. rc = -EFAULT;
  2305. }
  2306. REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, mode);
  2307. return rc;
  2308. }
  2309. static int bnx2x_cl22_read(struct bnx2x *bp,
  2310. struct bnx2x_phy *phy,
  2311. u16 reg, u16 *ret_val)
  2312. {
  2313. u32 val, mode;
  2314. u16 i;
  2315. int rc = 0;
  2316. /* Switch to CL22 */
  2317. mode = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE);
  2318. REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE,
  2319. mode & ~EMAC_MDIO_MODE_CLAUSE_45);
  2320. /* Address */
  2321. val = ((phy->addr << 21) | (reg << 16) |
  2322. EMAC_MDIO_COMM_COMMAND_READ_22 |
  2323. EMAC_MDIO_COMM_START_BUSY);
  2324. REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
  2325. for (i = 0; i < 50; i++) {
  2326. udelay(10);
  2327. val = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
  2328. if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
  2329. *ret_val = (u16)(val & EMAC_MDIO_COMM_DATA);
  2330. udelay(5);
  2331. break;
  2332. }
  2333. }
  2334. if (val & EMAC_MDIO_COMM_START_BUSY) {
  2335. DP(NETIF_MSG_LINK, "read phy register failed\n");
  2336. *ret_val = 0;
  2337. rc = -EFAULT;
  2338. }
  2339. REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_MODE, mode);
  2340. return rc;
  2341. }
  2342. /******************************************************************/
  2343. /* CL45 access functions */
  2344. /******************************************************************/
  2345. static int bnx2x_cl45_read(struct bnx2x *bp, struct bnx2x_phy *phy,
  2346. u8 devad, u16 reg, u16 *ret_val)
  2347. {
  2348. u32 val;
  2349. u16 i;
  2350. int rc = 0;
  2351. u32 chip_id;
  2352. if (phy->flags & FLAGS_MDC_MDIO_WA_G) {
  2353. chip_id = (REG_RD(bp, MISC_REG_CHIP_NUM) << 16) |
  2354. ((REG_RD(bp, MISC_REG_CHIP_REV) & 0xf) << 12);
  2355. bnx2x_set_mdio_clk(bp, chip_id, phy->mdio_ctrl);
  2356. }
  2357. if (phy->flags & FLAGS_MDC_MDIO_WA_B0)
  2358. bnx2x_bits_en(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_STATUS,
  2359. EMAC_MDIO_STATUS_10MB);
  2360. /* Address */
  2361. val = ((phy->addr << 21) | (devad << 16) | reg |
  2362. EMAC_MDIO_COMM_COMMAND_ADDRESS |
  2363. EMAC_MDIO_COMM_START_BUSY);
  2364. REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
  2365. for (i = 0; i < 50; i++) {
  2366. udelay(10);
  2367. val = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
  2368. if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
  2369. udelay(5);
  2370. break;
  2371. }
  2372. }
  2373. if (val & EMAC_MDIO_COMM_START_BUSY) {
  2374. DP(NETIF_MSG_LINK, "read phy register failed\n");
  2375. netdev_err(bp->dev, "MDC/MDIO access timeout\n");
  2376. *ret_val = 0;
  2377. rc = -EFAULT;
  2378. } else {
  2379. /* Data */
  2380. val = ((phy->addr << 21) | (devad << 16) |
  2381. EMAC_MDIO_COMM_COMMAND_READ_45 |
  2382. EMAC_MDIO_COMM_START_BUSY);
  2383. REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, val);
  2384. for (i = 0; i < 50; i++) {
  2385. udelay(10);
  2386. val = REG_RD(bp, phy->mdio_ctrl +
  2387. EMAC_REG_EMAC_MDIO_COMM);
  2388. if (!(val & EMAC_MDIO_COMM_START_BUSY)) {
  2389. *ret_val = (u16)(val & EMAC_MDIO_COMM_DATA);
  2390. break;
  2391. }
  2392. }
  2393. if (val & EMAC_MDIO_COMM_START_BUSY) {
  2394. DP(NETIF_MSG_LINK, "read phy register failed\n");
  2395. netdev_err(bp->dev, "MDC/MDIO access timeout\n");
  2396. *ret_val = 0;
  2397. rc = -EFAULT;
  2398. }
  2399. }
  2400. /* Work around for E3 A0 */
  2401. if (phy->flags & FLAGS_MDC_MDIO_WA) {
  2402. phy->flags ^= FLAGS_DUMMY_READ;
  2403. if (phy->flags & FLAGS_DUMMY_READ) {
  2404. u16 temp_val;
  2405. bnx2x_cl45_read(bp, phy, devad, 0xf, &temp_val);
  2406. }
  2407. }
  2408. if (phy->flags & FLAGS_MDC_MDIO_WA_B0)
  2409. bnx2x_bits_dis(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_STATUS,
  2410. EMAC_MDIO_STATUS_10MB);
  2411. return rc;
  2412. }
  2413. static int bnx2x_cl45_write(struct bnx2x *bp, struct bnx2x_phy *phy,
  2414. u8 devad, u16 reg, u16 val)
  2415. {
  2416. u32 tmp;
  2417. u8 i;
  2418. int rc = 0;
  2419. u32 chip_id;
  2420. if (phy->flags & FLAGS_MDC_MDIO_WA_G) {
  2421. chip_id = (REG_RD(bp, MISC_REG_CHIP_NUM) << 16) |
  2422. ((REG_RD(bp, MISC_REG_CHIP_REV) & 0xf) << 12);
  2423. bnx2x_set_mdio_clk(bp, chip_id, phy->mdio_ctrl);
  2424. }
  2425. if (phy->flags & FLAGS_MDC_MDIO_WA_B0)
  2426. bnx2x_bits_en(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_STATUS,
  2427. EMAC_MDIO_STATUS_10MB);
  2428. /* Address */
  2429. tmp = ((phy->addr << 21) | (devad << 16) | reg |
  2430. EMAC_MDIO_COMM_COMMAND_ADDRESS |
  2431. EMAC_MDIO_COMM_START_BUSY);
  2432. REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
  2433. for (i = 0; i < 50; i++) {
  2434. udelay(10);
  2435. tmp = REG_RD(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM);
  2436. if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
  2437. udelay(5);
  2438. break;
  2439. }
  2440. }
  2441. if (tmp & EMAC_MDIO_COMM_START_BUSY) {
  2442. DP(NETIF_MSG_LINK, "write phy register failed\n");
  2443. netdev_err(bp->dev, "MDC/MDIO access timeout\n");
  2444. rc = -EFAULT;
  2445. } else {
  2446. /* Data */
  2447. tmp = ((phy->addr << 21) | (devad << 16) | val |
  2448. EMAC_MDIO_COMM_COMMAND_WRITE_45 |
  2449. EMAC_MDIO_COMM_START_BUSY);
  2450. REG_WR(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_COMM, tmp);
  2451. for (i = 0; i < 50; i++) {
  2452. udelay(10);
  2453. tmp = REG_RD(bp, phy->mdio_ctrl +
  2454. EMAC_REG_EMAC_MDIO_COMM);
  2455. if (!(tmp & EMAC_MDIO_COMM_START_BUSY)) {
  2456. udelay(5);
  2457. break;
  2458. }
  2459. }
  2460. if (tmp & EMAC_MDIO_COMM_START_BUSY) {
  2461. DP(NETIF_MSG_LINK, "write phy register failed\n");
  2462. netdev_err(bp->dev, "MDC/MDIO access timeout\n");
  2463. rc = -EFAULT;
  2464. }
  2465. }
  2466. /* Work around for E3 A0 */
  2467. if (phy->flags & FLAGS_MDC_MDIO_WA) {
  2468. phy->flags ^= FLAGS_DUMMY_READ;
  2469. if (phy->flags & FLAGS_DUMMY_READ) {
  2470. u16 temp_val;
  2471. bnx2x_cl45_read(bp, phy, devad, 0xf, &temp_val);
  2472. }
  2473. }
  2474. if (phy->flags & FLAGS_MDC_MDIO_WA_B0)
  2475. bnx2x_bits_dis(bp, phy->mdio_ctrl + EMAC_REG_EMAC_MDIO_STATUS,
  2476. EMAC_MDIO_STATUS_10MB);
  2477. return rc;
  2478. }
  2479. /******************************************************************/
  2480. /* EEE section */
  2481. /******************************************************************/
  2482. static u8 bnx2x_eee_has_cap(struct link_params *params)
  2483. {
  2484. struct bnx2x *bp = params->bp;
  2485. if (REG_RD(bp, params->shmem2_base) <=
  2486. offsetof(struct shmem2_region, eee_status[params->port]))
  2487. return 0;
  2488. return 1;
  2489. }
  2490. static int bnx2x_eee_nvram_to_time(u32 nvram_mode, u32 *idle_timer)
  2491. {
  2492. switch (nvram_mode) {
  2493. case PORT_FEAT_CFG_EEE_POWER_MODE_BALANCED:
  2494. *idle_timer = EEE_MODE_NVRAM_BALANCED_TIME;
  2495. break;
  2496. case PORT_FEAT_CFG_EEE_POWER_MODE_AGGRESSIVE:
  2497. *idle_timer = EEE_MODE_NVRAM_AGGRESSIVE_TIME;
  2498. break;
  2499. case PORT_FEAT_CFG_EEE_POWER_MODE_LOW_LATENCY:
  2500. *idle_timer = EEE_MODE_NVRAM_LATENCY_TIME;
  2501. break;
  2502. default:
  2503. *idle_timer = 0;
  2504. break;
  2505. }
  2506. return 0;
  2507. }
  2508. static int bnx2x_eee_time_to_nvram(u32 idle_timer, u32 *nvram_mode)
  2509. {
  2510. switch (idle_timer) {
  2511. case EEE_MODE_NVRAM_BALANCED_TIME:
  2512. *nvram_mode = PORT_FEAT_CFG_EEE_POWER_MODE_BALANCED;
  2513. break;
  2514. case EEE_MODE_NVRAM_AGGRESSIVE_TIME:
  2515. *nvram_mode = PORT_FEAT_CFG_EEE_POWER_MODE_AGGRESSIVE;
  2516. break;
  2517. case EEE_MODE_NVRAM_LATENCY_TIME:
  2518. *nvram_mode = PORT_FEAT_CFG_EEE_POWER_MODE_LOW_LATENCY;
  2519. break;
  2520. default:
  2521. *nvram_mode = PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED;
  2522. break;
  2523. }
  2524. return 0;
  2525. }
  2526. static u32 bnx2x_eee_calc_timer(struct link_params *params)
  2527. {
  2528. u32 eee_mode, eee_idle;
  2529. struct bnx2x *bp = params->bp;
  2530. if (params->eee_mode & EEE_MODE_OVERRIDE_NVRAM) {
  2531. if (params->eee_mode & EEE_MODE_OUTPUT_TIME) {
  2532. /* time value in eee_mode --> used directly*/
  2533. eee_idle = params->eee_mode & EEE_MODE_TIMER_MASK;
  2534. } else {
  2535. /* hsi value in eee_mode --> time */
  2536. if (bnx2x_eee_nvram_to_time(params->eee_mode &
  2537. EEE_MODE_NVRAM_MASK,
  2538. &eee_idle))
  2539. return 0;
  2540. }
  2541. } else {
  2542. /* hsi values in nvram --> time*/
  2543. eee_mode = ((REG_RD(bp, params->shmem_base +
  2544. offsetof(struct shmem_region, dev_info.
  2545. port_feature_config[params->port].
  2546. eee_power_mode)) &
  2547. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  2548. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  2549. if (bnx2x_eee_nvram_to_time(eee_mode, &eee_idle))
  2550. return 0;
  2551. }
  2552. return eee_idle;
  2553. }
  2554. static int bnx2x_eee_set_timers(struct link_params *params,
  2555. struct link_vars *vars)
  2556. {
  2557. u32 eee_idle = 0, eee_mode;
  2558. struct bnx2x *bp = params->bp;
  2559. eee_idle = bnx2x_eee_calc_timer(params);
  2560. if (eee_idle) {
  2561. REG_WR(bp, MISC_REG_CPMU_LP_IDLE_THR_P0 + (params->port << 2),
  2562. eee_idle);
  2563. } else if ((params->eee_mode & EEE_MODE_ENABLE_LPI) &&
  2564. (params->eee_mode & EEE_MODE_OVERRIDE_NVRAM) &&
  2565. (params->eee_mode & EEE_MODE_OUTPUT_TIME)) {
  2566. DP(NETIF_MSG_LINK, "Error: Tx LPI is enabled with timer 0\n");
  2567. return -EINVAL;
  2568. }
  2569. vars->eee_status &= ~(SHMEM_EEE_TIMER_MASK | SHMEM_EEE_TIME_OUTPUT_BIT);
  2570. if (params->eee_mode & EEE_MODE_OUTPUT_TIME) {
  2571. /* eee_idle in 1u --> eee_status in 16u */
  2572. eee_idle >>= 4;
  2573. vars->eee_status |= (eee_idle & SHMEM_EEE_TIMER_MASK) |
  2574. SHMEM_EEE_TIME_OUTPUT_BIT;
  2575. } else {
  2576. if (bnx2x_eee_time_to_nvram(eee_idle, &eee_mode))
  2577. return -EINVAL;
  2578. vars->eee_status |= eee_mode;
  2579. }
  2580. return 0;
  2581. }
  2582. static int bnx2x_eee_initial_config(struct link_params *params,
  2583. struct link_vars *vars, u8 mode)
  2584. {
  2585. vars->eee_status |= ((u32) mode) << SHMEM_EEE_SUPPORTED_SHIFT;
  2586. /* Propagate params' bits --> vars (for migration exposure) */
  2587. if (params->eee_mode & EEE_MODE_ENABLE_LPI)
  2588. vars->eee_status |= SHMEM_EEE_LPI_REQUESTED_BIT;
  2589. else
  2590. vars->eee_status &= ~SHMEM_EEE_LPI_REQUESTED_BIT;
  2591. if (params->eee_mode & EEE_MODE_ADV_LPI)
  2592. vars->eee_status |= SHMEM_EEE_REQUESTED_BIT;
  2593. else
  2594. vars->eee_status &= ~SHMEM_EEE_REQUESTED_BIT;
  2595. return bnx2x_eee_set_timers(params, vars);
  2596. }
  2597. static int bnx2x_eee_disable(struct bnx2x_phy *phy,
  2598. struct link_params *params,
  2599. struct link_vars *vars)
  2600. {
  2601. struct bnx2x *bp = params->bp;
  2602. /* Make Certain LPI is disabled */
  2603. REG_WR(bp, MISC_REG_CPMU_LP_FW_ENABLE_P0 + (params->port << 2), 0);
  2604. bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_EEE_ADV, 0x0);
  2605. vars->eee_status &= ~SHMEM_EEE_ADV_STATUS_MASK;
  2606. return 0;
  2607. }
  2608. static int bnx2x_eee_advertise(struct bnx2x_phy *phy,
  2609. struct link_params *params,
  2610. struct link_vars *vars, u8 modes)
  2611. {
  2612. struct bnx2x *bp = params->bp;
  2613. u16 val = 0;
  2614. /* Mask events preventing LPI generation */
  2615. REG_WR(bp, MISC_REG_CPMU_LP_MASK_EXT_P0 + (params->port << 2), 0xfc20);
  2616. if (modes & SHMEM_EEE_10G_ADV) {
  2617. DP(NETIF_MSG_LINK, "Advertise 10GBase-T EEE\n");
  2618. val |= 0x8;
  2619. }
  2620. if (modes & SHMEM_EEE_1G_ADV) {
  2621. DP(NETIF_MSG_LINK, "Advertise 1GBase-T EEE\n");
  2622. val |= 0x4;
  2623. }
  2624. bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_EEE_ADV, val);
  2625. vars->eee_status &= ~SHMEM_EEE_ADV_STATUS_MASK;
  2626. vars->eee_status |= (modes << SHMEM_EEE_ADV_STATUS_SHIFT);
  2627. return 0;
  2628. }
  2629. static void bnx2x_update_mng_eee(struct link_params *params, u32 eee_status)
  2630. {
  2631. struct bnx2x *bp = params->bp;
  2632. if (bnx2x_eee_has_cap(params))
  2633. REG_WR(bp, params->shmem2_base +
  2634. offsetof(struct shmem2_region,
  2635. eee_status[params->port]), eee_status);
  2636. }
  2637. static void bnx2x_eee_an_resolve(struct bnx2x_phy *phy,
  2638. struct link_params *params,
  2639. struct link_vars *vars)
  2640. {
  2641. struct bnx2x *bp = params->bp;
  2642. u16 adv = 0, lp = 0;
  2643. u32 lp_adv = 0;
  2644. u8 neg = 0;
  2645. bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_EEE_ADV, &adv);
  2646. bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_LP_EEE_ADV, &lp);
  2647. if (lp & 0x2) {
  2648. lp_adv |= SHMEM_EEE_100M_ADV;
  2649. if (adv & 0x2) {
  2650. if (vars->line_speed == SPEED_100)
  2651. neg = 1;
  2652. DP(NETIF_MSG_LINK, "EEE negotiated - 100M\n");
  2653. }
  2654. }
  2655. if (lp & 0x14) {
  2656. lp_adv |= SHMEM_EEE_1G_ADV;
  2657. if (adv & 0x14) {
  2658. if (vars->line_speed == SPEED_1000)
  2659. neg = 1;
  2660. DP(NETIF_MSG_LINK, "EEE negotiated - 1G\n");
  2661. }
  2662. }
  2663. if (lp & 0x68) {
  2664. lp_adv |= SHMEM_EEE_10G_ADV;
  2665. if (adv & 0x68) {
  2666. if (vars->line_speed == SPEED_10000)
  2667. neg = 1;
  2668. DP(NETIF_MSG_LINK, "EEE negotiated - 10G\n");
  2669. }
  2670. }
  2671. vars->eee_status &= ~SHMEM_EEE_LP_ADV_STATUS_MASK;
  2672. vars->eee_status |= (lp_adv << SHMEM_EEE_LP_ADV_STATUS_SHIFT);
  2673. if (neg) {
  2674. DP(NETIF_MSG_LINK, "EEE is active\n");
  2675. vars->eee_status |= SHMEM_EEE_ACTIVE_BIT;
  2676. }
  2677. }
  2678. /******************************************************************/
  2679. /* BSC access functions from E3 */
  2680. /******************************************************************/
  2681. static void bnx2x_bsc_module_sel(struct link_params *params)
  2682. {
  2683. int idx;
  2684. u32 board_cfg, sfp_ctrl;
  2685. u32 i2c_pins[I2C_SWITCH_WIDTH], i2c_val[I2C_SWITCH_WIDTH];
  2686. struct bnx2x *bp = params->bp;
  2687. u8 port = params->port;
  2688. /* Read I2C output PINs */
  2689. board_cfg = REG_RD(bp, params->shmem_base +
  2690. offsetof(struct shmem_region,
  2691. dev_info.shared_hw_config.board));
  2692. i2c_pins[I2C_BSC0] = board_cfg & SHARED_HW_CFG_E3_I2C_MUX0_MASK;
  2693. i2c_pins[I2C_BSC1] = (board_cfg & SHARED_HW_CFG_E3_I2C_MUX1_MASK) >>
  2694. SHARED_HW_CFG_E3_I2C_MUX1_SHIFT;
  2695. /* Read I2C output value */
  2696. sfp_ctrl = REG_RD(bp, params->shmem_base +
  2697. offsetof(struct shmem_region,
  2698. dev_info.port_hw_config[port].e3_cmn_pin_cfg));
  2699. i2c_val[I2C_BSC0] = (sfp_ctrl & PORT_HW_CFG_E3_I2C_MUX0_MASK) > 0;
  2700. i2c_val[I2C_BSC1] = (sfp_ctrl & PORT_HW_CFG_E3_I2C_MUX1_MASK) > 0;
  2701. DP(NETIF_MSG_LINK, "Setting BSC switch\n");
  2702. for (idx = 0; idx < I2C_SWITCH_WIDTH; idx++)
  2703. bnx2x_set_cfg_pin(bp, i2c_pins[idx], i2c_val[idx]);
  2704. }
  2705. static int bnx2x_bsc_read(struct link_params *params,
  2706. struct bnx2x *bp,
  2707. u8 sl_devid,
  2708. u16 sl_addr,
  2709. u8 lc_addr,
  2710. u8 xfer_cnt,
  2711. u32 *data_array)
  2712. {
  2713. u32 val, i;
  2714. int rc = 0;
  2715. if (xfer_cnt > 16) {
  2716. DP(NETIF_MSG_LINK, "invalid xfer_cnt %d. Max is 16 bytes\n",
  2717. xfer_cnt);
  2718. return -EINVAL;
  2719. }
  2720. bnx2x_bsc_module_sel(params);
  2721. xfer_cnt = 16 - lc_addr;
  2722. /* Enable the engine */
  2723. val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
  2724. val |= MCPR_IMC_COMMAND_ENABLE;
  2725. REG_WR(bp, MCP_REG_MCPR_IMC_COMMAND, val);
  2726. /* Program slave device ID */
  2727. val = (sl_devid << 16) | sl_addr;
  2728. REG_WR(bp, MCP_REG_MCPR_IMC_SLAVE_CONTROL, val);
  2729. /* Start xfer with 0 byte to update the address pointer ???*/
  2730. val = (MCPR_IMC_COMMAND_ENABLE) |
  2731. (MCPR_IMC_COMMAND_WRITE_OP <<
  2732. MCPR_IMC_COMMAND_OPERATION_BITSHIFT) |
  2733. (lc_addr << MCPR_IMC_COMMAND_TRANSFER_ADDRESS_BITSHIFT) | (0);
  2734. REG_WR(bp, MCP_REG_MCPR_IMC_COMMAND, val);
  2735. /* Poll for completion */
  2736. i = 0;
  2737. val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
  2738. while (((val >> MCPR_IMC_COMMAND_IMC_STATUS_BITSHIFT) & 0x3) != 1) {
  2739. udelay(10);
  2740. val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
  2741. if (i++ > 1000) {
  2742. DP(NETIF_MSG_LINK, "wr 0 byte timed out after %d try\n",
  2743. i);
  2744. rc = -EFAULT;
  2745. break;
  2746. }
  2747. }
  2748. if (rc == -EFAULT)
  2749. return rc;
  2750. /* Start xfer with read op */
  2751. val = (MCPR_IMC_COMMAND_ENABLE) |
  2752. (MCPR_IMC_COMMAND_READ_OP <<
  2753. MCPR_IMC_COMMAND_OPERATION_BITSHIFT) |
  2754. (lc_addr << MCPR_IMC_COMMAND_TRANSFER_ADDRESS_BITSHIFT) |
  2755. (xfer_cnt);
  2756. REG_WR(bp, MCP_REG_MCPR_IMC_COMMAND, val);
  2757. /* Poll for completion */
  2758. i = 0;
  2759. val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
  2760. while (((val >> MCPR_IMC_COMMAND_IMC_STATUS_BITSHIFT) & 0x3) != 1) {
  2761. udelay(10);
  2762. val = REG_RD(bp, MCP_REG_MCPR_IMC_COMMAND);
  2763. if (i++ > 1000) {
  2764. DP(NETIF_MSG_LINK, "rd op timed out after %d try\n", i);
  2765. rc = -EFAULT;
  2766. break;
  2767. }
  2768. }
  2769. if (rc == -EFAULT)
  2770. return rc;
  2771. for (i = (lc_addr >> 2); i < 4; i++) {
  2772. data_array[i] = REG_RD(bp, (MCP_REG_MCPR_IMC_DATAREG0 + i*4));
  2773. #ifdef __BIG_ENDIAN
  2774. data_array[i] = ((data_array[i] & 0x000000ff) << 24) |
  2775. ((data_array[i] & 0x0000ff00) << 8) |
  2776. ((data_array[i] & 0x00ff0000) >> 8) |
  2777. ((data_array[i] & 0xff000000) >> 24);
  2778. #endif
  2779. }
  2780. return rc;
  2781. }
  2782. static void bnx2x_cl45_read_or_write(struct bnx2x *bp, struct bnx2x_phy *phy,
  2783. u8 devad, u16 reg, u16 or_val)
  2784. {
  2785. u16 val;
  2786. bnx2x_cl45_read(bp, phy, devad, reg, &val);
  2787. bnx2x_cl45_write(bp, phy, devad, reg, val | or_val);
  2788. }
  2789. static void bnx2x_cl45_read_and_write(struct bnx2x *bp,
  2790. struct bnx2x_phy *phy,
  2791. u8 devad, u16 reg, u16 and_val)
  2792. {
  2793. u16 val;
  2794. bnx2x_cl45_read(bp, phy, devad, reg, &val);
  2795. bnx2x_cl45_write(bp, phy, devad, reg, val & and_val);
  2796. }
  2797. int bnx2x_phy_read(struct link_params *params, u8 phy_addr,
  2798. u8 devad, u16 reg, u16 *ret_val)
  2799. {
  2800. u8 phy_index;
  2801. /* Probe for the phy according to the given phy_addr, and execute
  2802. * the read request on it
  2803. */
  2804. for (phy_index = 0; phy_index < params->num_phys; phy_index++) {
  2805. if (params->phy[phy_index].addr == phy_addr) {
  2806. return bnx2x_cl45_read(params->bp,
  2807. &params->phy[phy_index], devad,
  2808. reg, ret_val);
  2809. }
  2810. }
  2811. return -EINVAL;
  2812. }
  2813. int bnx2x_phy_write(struct link_params *params, u8 phy_addr,
  2814. u8 devad, u16 reg, u16 val)
  2815. {
  2816. u8 phy_index;
  2817. /* Probe for the phy according to the given phy_addr, and execute
  2818. * the write request on it
  2819. */
  2820. for (phy_index = 0; phy_index < params->num_phys; phy_index++) {
  2821. if (params->phy[phy_index].addr == phy_addr) {
  2822. return bnx2x_cl45_write(params->bp,
  2823. &params->phy[phy_index], devad,
  2824. reg, val);
  2825. }
  2826. }
  2827. return -EINVAL;
  2828. }
  2829. static u8 bnx2x_get_warpcore_lane(struct bnx2x_phy *phy,
  2830. struct link_params *params)
  2831. {
  2832. u8 lane = 0;
  2833. struct bnx2x *bp = params->bp;
  2834. u32 path_swap, path_swap_ovr;
  2835. u8 path, port;
  2836. path = BP_PATH(bp);
  2837. port = params->port;
  2838. if (bnx2x_is_4_port_mode(bp)) {
  2839. u32 port_swap, port_swap_ovr;
  2840. /* Figure out path swap value */
  2841. path_swap_ovr = REG_RD(bp, MISC_REG_FOUR_PORT_PATH_SWAP_OVWR);
  2842. if (path_swap_ovr & 0x1)
  2843. path_swap = (path_swap_ovr & 0x2);
  2844. else
  2845. path_swap = REG_RD(bp, MISC_REG_FOUR_PORT_PATH_SWAP);
  2846. if (path_swap)
  2847. path = path ^ 1;
  2848. /* Figure out port swap value */
  2849. port_swap_ovr = REG_RD(bp, MISC_REG_FOUR_PORT_PORT_SWAP_OVWR);
  2850. if (port_swap_ovr & 0x1)
  2851. port_swap = (port_swap_ovr & 0x2);
  2852. else
  2853. port_swap = REG_RD(bp, MISC_REG_FOUR_PORT_PORT_SWAP);
  2854. if (port_swap)
  2855. port = port ^ 1;
  2856. lane = (port<<1) + path;
  2857. } else { /* Two port mode - no port swap */
  2858. /* Figure out path swap value */
  2859. path_swap_ovr =
  2860. REG_RD(bp, MISC_REG_TWO_PORT_PATH_SWAP_OVWR);
  2861. if (path_swap_ovr & 0x1) {
  2862. path_swap = (path_swap_ovr & 0x2);
  2863. } else {
  2864. path_swap =
  2865. REG_RD(bp, MISC_REG_TWO_PORT_PATH_SWAP);
  2866. }
  2867. if (path_swap)
  2868. path = path ^ 1;
  2869. lane = path << 1 ;
  2870. }
  2871. return lane;
  2872. }
  2873. static void bnx2x_set_aer_mmd(struct link_params *params,
  2874. struct bnx2x_phy *phy)
  2875. {
  2876. u32 ser_lane;
  2877. u16 offset, aer_val;
  2878. struct bnx2x *bp = params->bp;
  2879. ser_lane = ((params->lane_config &
  2880. PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
  2881. PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
  2882. offset = (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) ?
  2883. (phy->addr + ser_lane) : 0;
  2884. if (USES_WARPCORE(bp)) {
  2885. aer_val = bnx2x_get_warpcore_lane(phy, params);
  2886. /* In Dual-lane mode, two lanes are joined together,
  2887. * so in order to configure them, the AER broadcast method is
  2888. * used here.
  2889. * 0x200 is the broadcast address for lanes 0,1
  2890. * 0x201 is the broadcast address for lanes 2,3
  2891. */
  2892. if (phy->flags & FLAGS_WC_DUAL_MODE)
  2893. aer_val = (aer_val >> 1) | 0x200;
  2894. } else if (CHIP_IS_E2(bp))
  2895. aer_val = 0x3800 + offset - 1;
  2896. else
  2897. aer_val = 0x3800 + offset;
  2898. CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
  2899. MDIO_AER_BLOCK_AER_REG, aer_val);
  2900. }
  2901. /******************************************************************/
  2902. /* Internal phy section */
  2903. /******************************************************************/
  2904. static void bnx2x_set_serdes_access(struct bnx2x *bp, u8 port)
  2905. {
  2906. u32 emac_base = (port) ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  2907. /* Set Clause 22 */
  2908. REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_ST + port*0x10, 1);
  2909. REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_COMM, 0x245f8000);
  2910. udelay(500);
  2911. REG_WR(bp, emac_base + EMAC_REG_EMAC_MDIO_COMM, 0x245d000f);
  2912. udelay(500);
  2913. /* Set Clause 45 */
  2914. REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_ST + port*0x10, 0);
  2915. }
  2916. static void bnx2x_serdes_deassert(struct bnx2x *bp, u8 port)
  2917. {
  2918. u32 val;
  2919. DP(NETIF_MSG_LINK, "bnx2x_serdes_deassert\n");
  2920. val = SERDES_RESET_BITS << (port*16);
  2921. /* Reset and unreset the SerDes/XGXS */
  2922. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR, val);
  2923. udelay(500);
  2924. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_SET, val);
  2925. bnx2x_set_serdes_access(bp, port);
  2926. REG_WR(bp, NIG_REG_SERDES0_CTRL_MD_DEVAD + port*0x10,
  2927. DEFAULT_PHY_DEV_ADDR);
  2928. }
  2929. static void bnx2x_xgxs_specific_func(struct bnx2x_phy *phy,
  2930. struct link_params *params,
  2931. u32 action)
  2932. {
  2933. struct bnx2x *bp = params->bp;
  2934. switch (action) {
  2935. case PHY_INIT:
  2936. /* Set correct devad */
  2937. REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_ST + params->port*0x18, 0);
  2938. REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + params->port*0x18,
  2939. phy->def_md_devad);
  2940. break;
  2941. }
  2942. }
  2943. static void bnx2x_xgxs_deassert(struct link_params *params)
  2944. {
  2945. struct bnx2x *bp = params->bp;
  2946. u8 port;
  2947. u32 val;
  2948. DP(NETIF_MSG_LINK, "bnx2x_xgxs_deassert\n");
  2949. port = params->port;
  2950. val = XGXS_RESET_BITS << (port*16);
  2951. /* Reset and unreset the SerDes/XGXS */
  2952. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR, val);
  2953. udelay(500);
  2954. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_SET, val);
  2955. bnx2x_xgxs_specific_func(&params->phy[INT_PHY], params,
  2956. PHY_INIT);
  2957. }
  2958. static void bnx2x_calc_ieee_aneg_adv(struct bnx2x_phy *phy,
  2959. struct link_params *params, u16 *ieee_fc)
  2960. {
  2961. struct bnx2x *bp = params->bp;
  2962. *ieee_fc = MDIO_COMBO_IEEE0_AUTO_NEG_ADV_FULL_DUPLEX;
  2963. /* Resolve pause mode and advertisement Please refer to Table
  2964. * 28B-3 of the 802.3ab-1999 spec
  2965. */
  2966. switch (phy->req_flow_ctrl) {
  2967. case BNX2X_FLOW_CTRL_AUTO:
  2968. switch (params->req_fc_auto_adv) {
  2969. case BNX2X_FLOW_CTRL_BOTH:
  2970. case BNX2X_FLOW_CTRL_RX:
  2971. *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
  2972. break;
  2973. case BNX2X_FLOW_CTRL_TX:
  2974. *ieee_fc |=
  2975. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
  2976. break;
  2977. default:
  2978. break;
  2979. }
  2980. break;
  2981. case BNX2X_FLOW_CTRL_TX:
  2982. *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
  2983. break;
  2984. case BNX2X_FLOW_CTRL_RX:
  2985. case BNX2X_FLOW_CTRL_BOTH:
  2986. *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
  2987. break;
  2988. case BNX2X_FLOW_CTRL_NONE:
  2989. default:
  2990. *ieee_fc |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE;
  2991. break;
  2992. }
  2993. DP(NETIF_MSG_LINK, "ieee_fc = 0x%x\n", *ieee_fc);
  2994. }
  2995. static void set_phy_vars(struct link_params *params,
  2996. struct link_vars *vars)
  2997. {
  2998. struct bnx2x *bp = params->bp;
  2999. u8 actual_phy_idx, phy_index, link_cfg_idx;
  3000. u8 phy_config_swapped = params->multi_phy_config &
  3001. PORT_HW_CFG_PHY_SWAPPED_ENABLED;
  3002. for (phy_index = INT_PHY; phy_index < params->num_phys;
  3003. phy_index++) {
  3004. link_cfg_idx = LINK_CONFIG_IDX(phy_index);
  3005. actual_phy_idx = phy_index;
  3006. if (phy_config_swapped) {
  3007. if (phy_index == EXT_PHY1)
  3008. actual_phy_idx = EXT_PHY2;
  3009. else if (phy_index == EXT_PHY2)
  3010. actual_phy_idx = EXT_PHY1;
  3011. }
  3012. params->phy[actual_phy_idx].req_flow_ctrl =
  3013. params->req_flow_ctrl[link_cfg_idx];
  3014. params->phy[actual_phy_idx].req_line_speed =
  3015. params->req_line_speed[link_cfg_idx];
  3016. params->phy[actual_phy_idx].speed_cap_mask =
  3017. params->speed_cap_mask[link_cfg_idx];
  3018. params->phy[actual_phy_idx].req_duplex =
  3019. params->req_duplex[link_cfg_idx];
  3020. if (params->req_line_speed[link_cfg_idx] ==
  3021. SPEED_AUTO_NEG)
  3022. vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_ENABLED;
  3023. DP(NETIF_MSG_LINK, "req_flow_ctrl %x, req_line_speed %x,"
  3024. " speed_cap_mask %x\n",
  3025. params->phy[actual_phy_idx].req_flow_ctrl,
  3026. params->phy[actual_phy_idx].req_line_speed,
  3027. params->phy[actual_phy_idx].speed_cap_mask);
  3028. }
  3029. }
  3030. static void bnx2x_ext_phy_set_pause(struct link_params *params,
  3031. struct bnx2x_phy *phy,
  3032. struct link_vars *vars)
  3033. {
  3034. u16 val;
  3035. struct bnx2x *bp = params->bp;
  3036. /* Read modify write pause advertizing */
  3037. bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV_PAUSE, &val);
  3038. val &= ~MDIO_AN_REG_ADV_PAUSE_BOTH;
  3039. /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
  3040. bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
  3041. if ((vars->ieee_fc &
  3042. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
  3043. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) {
  3044. val |= MDIO_AN_REG_ADV_PAUSE_ASYMMETRIC;
  3045. }
  3046. if ((vars->ieee_fc &
  3047. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
  3048. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) {
  3049. val |= MDIO_AN_REG_ADV_PAUSE_PAUSE;
  3050. }
  3051. DP(NETIF_MSG_LINK, "Ext phy AN advertize 0x%x\n", val);
  3052. bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV_PAUSE, val);
  3053. }
  3054. static void bnx2x_pause_resolve(struct bnx2x_phy *phy,
  3055. struct link_params *params,
  3056. struct link_vars *vars,
  3057. u32 pause_result)
  3058. {
  3059. struct bnx2x *bp = params->bp;
  3060. /* LD LP */
  3061. switch (pause_result) { /* ASYM P ASYM P */
  3062. case 0xb: /* 1 0 1 1 */
  3063. DP(NETIF_MSG_LINK, "Flow Control: TX only\n");
  3064. vars->flow_ctrl = BNX2X_FLOW_CTRL_TX;
  3065. break;
  3066. case 0xe: /* 1 1 1 0 */
  3067. DP(NETIF_MSG_LINK, "Flow Control: RX only\n");
  3068. vars->flow_ctrl = BNX2X_FLOW_CTRL_RX;
  3069. break;
  3070. case 0x5: /* 0 1 0 1 */
  3071. case 0x7: /* 0 1 1 1 */
  3072. case 0xd: /* 1 1 0 1 */
  3073. case 0xf: /* 1 1 1 1 */
  3074. /* If the user selected to advertise RX ONLY,
  3075. * although we advertised both, need to enable
  3076. * RX only.
  3077. */
  3078. if (params->req_fc_auto_adv == BNX2X_FLOW_CTRL_BOTH) {
  3079. DP(NETIF_MSG_LINK, "Flow Control: RX & TX\n");
  3080. vars->flow_ctrl = BNX2X_FLOW_CTRL_BOTH;
  3081. } else {
  3082. DP(NETIF_MSG_LINK, "Flow Control: RX only\n");
  3083. vars->flow_ctrl = BNX2X_FLOW_CTRL_RX;
  3084. }
  3085. break;
  3086. default:
  3087. DP(NETIF_MSG_LINK, "Flow Control: None\n");
  3088. vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  3089. break;
  3090. }
  3091. if (pause_result & (1<<0))
  3092. vars->link_status |= LINK_STATUS_LINK_PARTNER_SYMMETRIC_PAUSE;
  3093. if (pause_result & (1<<1))
  3094. vars->link_status |= LINK_STATUS_LINK_PARTNER_ASYMMETRIC_PAUSE;
  3095. }
  3096. static void bnx2x_ext_phy_update_adv_fc(struct bnx2x_phy *phy,
  3097. struct link_params *params,
  3098. struct link_vars *vars)
  3099. {
  3100. u16 ld_pause; /* local */
  3101. u16 lp_pause; /* link partner */
  3102. u16 pause_result;
  3103. struct bnx2x *bp = params->bp;
  3104. if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE) {
  3105. bnx2x_cl22_read(bp, phy, 0x4, &ld_pause);
  3106. bnx2x_cl22_read(bp, phy, 0x5, &lp_pause);
  3107. } else if (CHIP_IS_E3(bp) &&
  3108. SINGLE_MEDIA_DIRECT(params)) {
  3109. u8 lane = bnx2x_get_warpcore_lane(phy, params);
  3110. u16 gp_status, gp_mask;
  3111. bnx2x_cl45_read(bp, phy,
  3112. MDIO_AN_DEVAD, MDIO_WC_REG_GP2_STATUS_GP_2_4,
  3113. &gp_status);
  3114. gp_mask = (MDIO_WC_REG_GP2_STATUS_GP_2_4_CL73_AN_CMPL |
  3115. MDIO_WC_REG_GP2_STATUS_GP_2_4_CL37_LP_AN_CAP) <<
  3116. lane;
  3117. if ((gp_status & gp_mask) == gp_mask) {
  3118. bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
  3119. MDIO_AN_REG_ADV_PAUSE, &ld_pause);
  3120. bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
  3121. MDIO_AN_REG_LP_AUTO_NEG, &lp_pause);
  3122. } else {
  3123. bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
  3124. MDIO_AN_REG_CL37_FC_LD, &ld_pause);
  3125. bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
  3126. MDIO_AN_REG_CL37_FC_LP, &lp_pause);
  3127. ld_pause = ((ld_pause &
  3128. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH)
  3129. << 3);
  3130. lp_pause = ((lp_pause &
  3131. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH)
  3132. << 3);
  3133. }
  3134. } else {
  3135. bnx2x_cl45_read(bp, phy,
  3136. MDIO_AN_DEVAD,
  3137. MDIO_AN_REG_ADV_PAUSE, &ld_pause);
  3138. bnx2x_cl45_read(bp, phy,
  3139. MDIO_AN_DEVAD,
  3140. MDIO_AN_REG_LP_AUTO_NEG, &lp_pause);
  3141. }
  3142. pause_result = (ld_pause &
  3143. MDIO_AN_REG_ADV_PAUSE_MASK) >> 8;
  3144. pause_result |= (lp_pause &
  3145. MDIO_AN_REG_ADV_PAUSE_MASK) >> 10;
  3146. DP(NETIF_MSG_LINK, "Ext PHY pause result 0x%x\n", pause_result);
  3147. bnx2x_pause_resolve(phy, params, vars, pause_result);
  3148. }
  3149. static u8 bnx2x_ext_phy_resolve_fc(struct bnx2x_phy *phy,
  3150. struct link_params *params,
  3151. struct link_vars *vars)
  3152. {
  3153. u8 ret = 0;
  3154. vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  3155. if (phy->req_flow_ctrl != BNX2X_FLOW_CTRL_AUTO) {
  3156. /* Update the advertised flow-controled of LD/LP in AN */
  3157. if (phy->req_line_speed == SPEED_AUTO_NEG)
  3158. bnx2x_ext_phy_update_adv_fc(phy, params, vars);
  3159. /* But set the flow-control result as the requested one */
  3160. vars->flow_ctrl = phy->req_flow_ctrl;
  3161. } else if (phy->req_line_speed != SPEED_AUTO_NEG)
  3162. vars->flow_ctrl = params->req_fc_auto_adv;
  3163. else if (vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) {
  3164. ret = 1;
  3165. bnx2x_ext_phy_update_adv_fc(phy, params, vars);
  3166. }
  3167. return ret;
  3168. }
  3169. /******************************************************************/
  3170. /* Warpcore section */
  3171. /******************************************************************/
  3172. /* The init_internal_warpcore should mirror the xgxs,
  3173. * i.e. reset the lane (if needed), set aer for the
  3174. * init configuration, and set/clear SGMII flag. Internal
  3175. * phy init is done purely in phy_init stage.
  3176. */
  3177. #define WC_TX_DRIVER(post2, idriver, ipre, ifir) \
  3178. ((post2 << MDIO_WC_REG_TX0_TX_DRIVER_POST2_COEFF_OFFSET) | \
  3179. (idriver << MDIO_WC_REG_TX0_TX_DRIVER_IDRIVER_OFFSET) | \
  3180. (ipre << MDIO_WC_REG_TX0_TX_DRIVER_IPRE_DRIVER_OFFSET) | \
  3181. (ifir << MDIO_WC_REG_TX0_TX_DRIVER_IFIR_OFFSET))
  3182. #define WC_TX_FIR(post, main, pre) \
  3183. ((post << MDIO_WC_REG_TX_FIR_TAP_POST_TAP_OFFSET) | \
  3184. (main << MDIO_WC_REG_TX_FIR_TAP_MAIN_TAP_OFFSET) | \
  3185. (pre << MDIO_WC_REG_TX_FIR_TAP_PRE_TAP_OFFSET))
  3186. static void bnx2x_warpcore_enable_AN_KR2(struct bnx2x_phy *phy,
  3187. struct link_params *params,
  3188. struct link_vars *vars)
  3189. {
  3190. struct bnx2x *bp = params->bp;
  3191. u16 i;
  3192. static struct bnx2x_reg_set reg_set[] = {
  3193. /* Step 1 - Program the TX/RX alignment markers */
  3194. {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL5, 0xa157},
  3195. {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL7, 0xcbe2},
  3196. {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL6, 0x7537},
  3197. {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL9, 0xa157},
  3198. {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_RX_CTRL11, 0xcbe2},
  3199. {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_RX_CTRL10, 0x7537},
  3200. /* Step 2 - Configure the NP registers */
  3201. {MDIO_WC_DEVAD, MDIO_WC_REG_CL73_USERB0_CTRL, 0x000a},
  3202. {MDIO_WC_DEVAD, MDIO_WC_REG_CL73_BAM_CTRL1, 0x6400},
  3203. {MDIO_WC_DEVAD, MDIO_WC_REG_CL73_BAM_CTRL3, 0x0620},
  3204. {MDIO_WC_DEVAD, MDIO_WC_REG_CL73_BAM_CODE_FIELD, 0x0157},
  3205. {MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_OUI1, 0x6464},
  3206. {MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_OUI2, 0x3150},
  3207. {MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_OUI3, 0x3150},
  3208. {MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_LD_BAM_CODE, 0x0157},
  3209. {MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_LD_UD_CODE, 0x0620}
  3210. };
  3211. DP(NETIF_MSG_LINK, "Enabling 20G-KR2\n");
  3212. bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
  3213. MDIO_WC_REG_CL49_USERB0_CTRL, (3<<6));
  3214. for (i = 0; i < ARRAY_SIZE(reg_set); i++)
  3215. bnx2x_cl45_write(bp, phy, reg_set[i].devad, reg_set[i].reg,
  3216. reg_set[i].val);
  3217. /* Start KR2 work-around timer which handles BCM8073 link-parner */
  3218. params->link_attr_sync |= LINK_ATTR_SYNC_KR2_ENABLE;
  3219. bnx2x_update_link_attr(params, params->link_attr_sync);
  3220. }
  3221. static void bnx2x_disable_kr2(struct link_params *params,
  3222. struct link_vars *vars,
  3223. struct bnx2x_phy *phy)
  3224. {
  3225. struct bnx2x *bp = params->bp;
  3226. int i;
  3227. static struct bnx2x_reg_set reg_set[] = {
  3228. /* Step 1 - Program the TX/RX alignment markers */
  3229. {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL5, 0x7690},
  3230. {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL7, 0xe647},
  3231. {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL6, 0xc4f0},
  3232. {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_TX_CTRL9, 0x7690},
  3233. {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_RX_CTRL11, 0xe647},
  3234. {MDIO_WC_DEVAD, MDIO_WC_REG_CL82_USERB1_RX_CTRL10, 0xc4f0},
  3235. {MDIO_WC_DEVAD, MDIO_WC_REG_CL73_USERB0_CTRL, 0x000c},
  3236. {MDIO_WC_DEVAD, MDIO_WC_REG_CL73_BAM_CTRL1, 0x6000},
  3237. {MDIO_WC_DEVAD, MDIO_WC_REG_CL73_BAM_CTRL3, 0x0000},
  3238. {MDIO_WC_DEVAD, MDIO_WC_REG_CL73_BAM_CODE_FIELD, 0x0002},
  3239. {MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_OUI1, 0x0000},
  3240. {MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_OUI2, 0x0af7},
  3241. {MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_OUI3, 0x0af7},
  3242. {MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_LD_BAM_CODE, 0x0002},
  3243. {MDIO_WC_DEVAD, MDIO_WC_REG_ETA_CL73_LD_UD_CODE, 0x0000}
  3244. };
  3245. DP(NETIF_MSG_LINK, "Disabling 20G-KR2\n");
  3246. for (i = 0; i < ARRAY_SIZE(reg_set); i++)
  3247. bnx2x_cl45_write(bp, phy, reg_set[i].devad, reg_set[i].reg,
  3248. reg_set[i].val);
  3249. params->link_attr_sync &= ~LINK_ATTR_SYNC_KR2_ENABLE;
  3250. bnx2x_update_link_attr(params, params->link_attr_sync);
  3251. vars->check_kr2_recovery_cnt = CHECK_KR2_RECOVERY_CNT;
  3252. }
  3253. static void bnx2x_warpcore_set_lpi_passthrough(struct bnx2x_phy *phy,
  3254. struct link_params *params)
  3255. {
  3256. struct bnx2x *bp = params->bp;
  3257. DP(NETIF_MSG_LINK, "Configure WC for LPI pass through\n");
  3258. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3259. MDIO_WC_REG_EEE_COMBO_CONTROL0, 0x7c);
  3260. bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
  3261. MDIO_WC_REG_DIGITAL4_MISC5, 0xc000);
  3262. }
  3263. static void bnx2x_warpcore_restart_AN_KR(struct bnx2x_phy *phy,
  3264. struct link_params *params)
  3265. {
  3266. /* Restart autoneg on the leading lane only */
  3267. struct bnx2x *bp = params->bp;
  3268. u16 lane = bnx2x_get_warpcore_lane(phy, params);
  3269. CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
  3270. MDIO_AER_BLOCK_AER_REG, lane);
  3271. bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
  3272. MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x1200);
  3273. /* Restore AER */
  3274. bnx2x_set_aer_mmd(params, phy);
  3275. }
  3276. static void bnx2x_warpcore_enable_AN_KR(struct bnx2x_phy *phy,
  3277. struct link_params *params,
  3278. struct link_vars *vars) {
  3279. u16 lane, i, cl72_ctrl, an_adv = 0, val;
  3280. u32 wc_lane_config;
  3281. struct bnx2x *bp = params->bp;
  3282. static struct bnx2x_reg_set reg_set[] = {
  3283. {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, 0x7},
  3284. {MDIO_PMA_DEVAD, MDIO_WC_REG_IEEE0BLK_AUTONEGNP, 0x0},
  3285. {MDIO_WC_DEVAD, MDIO_WC_REG_RX66_CONTROL, 0x7415},
  3286. {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_MISC2, 0x6190},
  3287. /* Disable Autoneg: re-enable it after adv is done. */
  3288. {MDIO_AN_DEVAD, MDIO_WC_REG_IEEE0BLK_MIICNTL, 0},
  3289. {MDIO_PMA_DEVAD, MDIO_WC_REG_PMD_KR_CONTROL, 0x2},
  3290. {MDIO_WC_DEVAD, MDIO_WC_REG_CL72_USERB0_CL72_TX_FIR_TAP, 0},
  3291. };
  3292. DP(NETIF_MSG_LINK, "Enable Auto Negotiation for KR\n");
  3293. /* Set to default registers that may be overriden by 10G force */
  3294. for (i = 0; i < ARRAY_SIZE(reg_set); i++)
  3295. bnx2x_cl45_write(bp, phy, reg_set[i].devad, reg_set[i].reg,
  3296. reg_set[i].val);
  3297. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
  3298. MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL, &cl72_ctrl);
  3299. cl72_ctrl &= 0x08ff;
  3300. cl72_ctrl |= 0x3800;
  3301. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3302. MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL, cl72_ctrl);
  3303. /* Check adding advertisement for 1G KX */
  3304. if (((vars->line_speed == SPEED_AUTO_NEG) &&
  3305. (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
  3306. (vars->line_speed == SPEED_1000)) {
  3307. u16 addr = MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2;
  3308. an_adv |= (1<<5);
  3309. /* Enable CL37 1G Parallel Detect */
  3310. bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD, addr, 0x1);
  3311. DP(NETIF_MSG_LINK, "Advertize 1G\n");
  3312. }
  3313. if (((vars->line_speed == SPEED_AUTO_NEG) &&
  3314. (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) ||
  3315. (vars->line_speed == SPEED_10000)) {
  3316. /* Check adding advertisement for 10G KR */
  3317. an_adv |= (1<<7);
  3318. /* Enable 10G Parallel Detect */
  3319. CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
  3320. MDIO_AER_BLOCK_AER_REG, 0);
  3321. bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
  3322. MDIO_WC_REG_PAR_DET_10G_CTRL, 1);
  3323. bnx2x_set_aer_mmd(params, phy);
  3324. DP(NETIF_MSG_LINK, "Advertize 10G\n");
  3325. }
  3326. /* Set Transmit PMD settings */
  3327. lane = bnx2x_get_warpcore_lane(phy, params);
  3328. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3329. MDIO_WC_REG_TX0_TX_DRIVER + 0x10*lane,
  3330. WC_TX_DRIVER(0x02, 0x06, 0x09, 0));
  3331. /* Configure the next lane if dual mode */
  3332. if (phy->flags & FLAGS_WC_DUAL_MODE)
  3333. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3334. MDIO_WC_REG_TX0_TX_DRIVER + 0x10*(lane+1),
  3335. WC_TX_DRIVER(0x02, 0x06, 0x09, 0));
  3336. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3337. MDIO_WC_REG_CL72_USERB0_CL72_OS_DEF_CTRL,
  3338. 0x03f0);
  3339. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3340. MDIO_WC_REG_CL72_USERB0_CL72_2P5_DEF_CTRL,
  3341. 0x03f0);
  3342. /* Advertised speeds */
  3343. bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
  3344. MDIO_WC_REG_AN_IEEE1BLK_AN_ADVERTISEMENT1, an_adv);
  3345. /* Advertised and set FEC (Forward Error Correction) */
  3346. bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
  3347. MDIO_WC_REG_AN_IEEE1BLK_AN_ADVERTISEMENT2,
  3348. (MDIO_WC_REG_AN_IEEE1BLK_AN_ADV2_FEC_ABILITY |
  3349. MDIO_WC_REG_AN_IEEE1BLK_AN_ADV2_FEC_REQ));
  3350. /* Enable CL37 BAM */
  3351. if (REG_RD(bp, params->shmem_base +
  3352. offsetof(struct shmem_region, dev_info.
  3353. port_hw_config[params->port].default_cfg)) &
  3354. PORT_HW_CFG_ENABLE_BAM_ON_KR_ENABLED) {
  3355. bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
  3356. MDIO_WC_REG_DIGITAL6_MP5_NEXTPAGECTRL,
  3357. 1);
  3358. DP(NETIF_MSG_LINK, "Enable CL37 BAM on KR\n");
  3359. }
  3360. /* Advertise pause */
  3361. bnx2x_ext_phy_set_pause(params, phy, vars);
  3362. vars->rx_tx_asic_rst = MAX_KR_LINK_RETRY;
  3363. bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
  3364. MDIO_WC_REG_DIGITAL5_MISC7, 0x100);
  3365. /* Over 1G - AN local device user page 1 */
  3366. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3367. MDIO_WC_REG_DIGITAL3_UP1, 0x1f);
  3368. if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
  3369. (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_20G)) ||
  3370. (phy->req_line_speed == SPEED_20000)) {
  3371. CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
  3372. MDIO_AER_BLOCK_AER_REG, lane);
  3373. bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
  3374. MDIO_WC_REG_RX1_PCI_CTRL + (0x10*lane),
  3375. (1<<11));
  3376. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3377. MDIO_WC_REG_XGXS_X2_CONTROL3, 0x7);
  3378. bnx2x_set_aer_mmd(params, phy);
  3379. bnx2x_warpcore_enable_AN_KR2(phy, params, vars);
  3380. } else {
  3381. /* Enable Auto-Detect to support 1G over CL37 as well */
  3382. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3383. MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1, 0x10);
  3384. wc_lane_config = REG_RD(bp, params->shmem_base +
  3385. offsetof(struct shmem_region, dev_info.
  3386. shared_hw_config.wc_lane_config));
  3387. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
  3388. MDIO_WC_REG_RX0_PCI_CTRL + (lane << 4), &val);
  3389. /* Force cl48 sync_status LOW to avoid getting stuck in CL73
  3390. * parallel-detect loop when CL73 and CL37 are enabled.
  3391. */
  3392. val |= 1 << 11;
  3393. /* Restore Polarity settings in case it was run over by
  3394. * previous link owner
  3395. */
  3396. if (wc_lane_config &
  3397. (SHARED_HW_CFG_RX_LANE0_POL_FLIP_ENABLED << lane))
  3398. val |= 3 << 2;
  3399. else
  3400. val &= ~(3 << 2);
  3401. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3402. MDIO_WC_REG_RX0_PCI_CTRL + (lane << 4),
  3403. val);
  3404. bnx2x_disable_kr2(params, vars, phy);
  3405. }
  3406. /* Enable Autoneg: only on the main lane */
  3407. bnx2x_warpcore_restart_AN_KR(phy, params);
  3408. }
  3409. static void bnx2x_warpcore_set_10G_KR(struct bnx2x_phy *phy,
  3410. struct link_params *params,
  3411. struct link_vars *vars)
  3412. {
  3413. struct bnx2x *bp = params->bp;
  3414. u16 val16, i, lane;
  3415. static struct bnx2x_reg_set reg_set[] = {
  3416. /* Disable Autoneg */
  3417. {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, 0x7},
  3418. {MDIO_WC_DEVAD, MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL,
  3419. 0x3f00},
  3420. {MDIO_AN_DEVAD, MDIO_WC_REG_AN_IEEE1BLK_AN_ADVERTISEMENT1, 0},
  3421. {MDIO_AN_DEVAD, MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x0},
  3422. {MDIO_WC_DEVAD, MDIO_WC_REG_DIGITAL3_UP1, 0x1},
  3423. {MDIO_WC_DEVAD, MDIO_WC_REG_DIGITAL5_MISC7, 0xa},
  3424. /* Leave cl72 training enable, needed for KR */
  3425. {MDIO_PMA_DEVAD, MDIO_WC_REG_PMD_KR_CONTROL, 0x2}
  3426. };
  3427. for (i = 0; i < ARRAY_SIZE(reg_set); i++)
  3428. bnx2x_cl45_write(bp, phy, reg_set[i].devad, reg_set[i].reg,
  3429. reg_set[i].val);
  3430. lane = bnx2x_get_warpcore_lane(phy, params);
  3431. /* Global registers */
  3432. CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
  3433. MDIO_AER_BLOCK_AER_REG, 0);
  3434. /* Disable CL36 PCS Tx */
  3435. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
  3436. MDIO_WC_REG_XGXSBLK1_LANECTRL0, &val16);
  3437. val16 &= ~(0x0011 << lane);
  3438. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3439. MDIO_WC_REG_XGXSBLK1_LANECTRL0, val16);
  3440. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
  3441. MDIO_WC_REG_XGXSBLK1_LANECTRL1, &val16);
  3442. val16 |= (0x0303 << (lane << 1));
  3443. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3444. MDIO_WC_REG_XGXSBLK1_LANECTRL1, val16);
  3445. /* Restore AER */
  3446. bnx2x_set_aer_mmd(params, phy);
  3447. /* Set speed via PMA/PMD register */
  3448. bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD,
  3449. MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x2040);
  3450. bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD,
  3451. MDIO_WC_REG_IEEE0BLK_AUTONEGNP, 0xB);
  3452. /* Enable encoded forced speed */
  3453. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3454. MDIO_WC_REG_SERDESDIGITAL_MISC2, 0x30);
  3455. /* Turn TX scramble payload only the 64/66 scrambler */
  3456. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3457. MDIO_WC_REG_TX66_CONTROL, 0x9);
  3458. /* Turn RX scramble payload only the 64/66 scrambler */
  3459. bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
  3460. MDIO_WC_REG_RX66_CONTROL, 0xF9);
  3461. /* Set and clear loopback to cause a reset to 64/66 decoder */
  3462. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3463. MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x4000);
  3464. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3465. MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x0);
  3466. }
  3467. static void bnx2x_warpcore_set_10G_XFI(struct bnx2x_phy *phy,
  3468. struct link_params *params,
  3469. u8 is_xfi)
  3470. {
  3471. struct bnx2x *bp = params->bp;
  3472. u16 misc1_val, tap_val, tx_driver_val, lane, val;
  3473. u32 cfg_tap_val, tx_drv_brdct, tx_equal;
  3474. u32 ifir_val, ipost2_val, ipre_driver_val;
  3475. /* Hold rxSeqStart */
  3476. bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
  3477. MDIO_WC_REG_DSC2B0_DSC_MISC_CTRL0, 0x8000);
  3478. /* Hold tx_fifo_reset */
  3479. bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
  3480. MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3, 0x1);
  3481. /* Disable CL73 AN */
  3482. bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0);
  3483. /* Disable 100FX Enable and Auto-Detect */
  3484. bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
  3485. MDIO_WC_REG_FX100_CTRL1, 0xFFFA);
  3486. /* Disable 100FX Idle detect */
  3487. bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
  3488. MDIO_WC_REG_FX100_CTRL3, 0x0080);
  3489. /* Set Block address to Remote PHY & Clear forced_speed[5] */
  3490. bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
  3491. MDIO_WC_REG_DIGITAL4_MISC3, 0xFF7F);
  3492. /* Turn off auto-detect & fiber mode */
  3493. bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
  3494. MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1,
  3495. 0xFFEE);
  3496. /* Set filter_force_link, disable_false_link and parallel_detect */
  3497. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
  3498. MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, &val);
  3499. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3500. MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
  3501. ((val | 0x0006) & 0xFFFE));
  3502. /* Set XFI / SFI */
  3503. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
  3504. MDIO_WC_REG_SERDESDIGITAL_MISC1, &misc1_val);
  3505. misc1_val &= ~(0x1f);
  3506. if (is_xfi) {
  3507. misc1_val |= 0x5;
  3508. tap_val = WC_TX_FIR(0x08, 0x37, 0x00);
  3509. tx_driver_val = WC_TX_DRIVER(0x00, 0x02, 0x03, 0);
  3510. } else {
  3511. cfg_tap_val = REG_RD(bp, params->shmem_base +
  3512. offsetof(struct shmem_region, dev_info.
  3513. port_hw_config[params->port].
  3514. sfi_tap_values));
  3515. tx_equal = cfg_tap_val & PORT_HW_CFG_TX_EQUALIZATION_MASK;
  3516. misc1_val |= 0x9;
  3517. /* TAP values are controlled by nvram, if value there isn't 0 */
  3518. if (tx_equal)
  3519. tap_val = (u16)tx_equal;
  3520. else
  3521. tap_val = WC_TX_FIR(0x0f, 0x2b, 0x02);
  3522. ifir_val = DEFAULT_TX_DRV_IFIR;
  3523. ipost2_val = DEFAULT_TX_DRV_POST2;
  3524. ipre_driver_val = DEFAULT_TX_DRV_IPRE_DRIVER;
  3525. tx_drv_brdct = DEFAULT_TX_DRV_BRDCT;
  3526. /* If any of the IFIR/IPRE_DRIVER/POST@ is set, apply all
  3527. * configuration.
  3528. */
  3529. if (cfg_tap_val & (PORT_HW_CFG_TX_DRV_IFIR_MASK |
  3530. PORT_HW_CFG_TX_DRV_IPREDRIVER_MASK |
  3531. PORT_HW_CFG_TX_DRV_POST2_MASK)) {
  3532. ifir_val = (cfg_tap_val &
  3533. PORT_HW_CFG_TX_DRV_IFIR_MASK) >>
  3534. PORT_HW_CFG_TX_DRV_IFIR_SHIFT;
  3535. ipre_driver_val = (cfg_tap_val &
  3536. PORT_HW_CFG_TX_DRV_IPREDRIVER_MASK)
  3537. >> PORT_HW_CFG_TX_DRV_IPREDRIVER_SHIFT;
  3538. ipost2_val = (cfg_tap_val &
  3539. PORT_HW_CFG_TX_DRV_POST2_MASK) >>
  3540. PORT_HW_CFG_TX_DRV_POST2_SHIFT;
  3541. }
  3542. if (cfg_tap_val & PORT_HW_CFG_TX_DRV_BROADCAST_MASK) {
  3543. tx_drv_brdct = (cfg_tap_val &
  3544. PORT_HW_CFG_TX_DRV_BROADCAST_MASK) >>
  3545. PORT_HW_CFG_TX_DRV_BROADCAST_SHIFT;
  3546. }
  3547. tx_driver_val = WC_TX_DRIVER(ipost2_val, tx_drv_brdct,
  3548. ipre_driver_val, ifir_val);
  3549. }
  3550. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3551. MDIO_WC_REG_SERDESDIGITAL_MISC1, misc1_val);
  3552. /* Set Transmit PMD settings */
  3553. lane = bnx2x_get_warpcore_lane(phy, params);
  3554. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3555. MDIO_WC_REG_TX_FIR_TAP,
  3556. tap_val | MDIO_WC_REG_TX_FIR_TAP_ENABLE);
  3557. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3558. MDIO_WC_REG_TX0_TX_DRIVER + 0x10*lane,
  3559. tx_driver_val);
  3560. /* Enable fiber mode, enable and invert sig_det */
  3561. bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
  3562. MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1, 0xd);
  3563. /* Set Block address to Remote PHY & Set forced_speed[5], 40bit mode */
  3564. bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
  3565. MDIO_WC_REG_DIGITAL4_MISC3, 0x8080);
  3566. bnx2x_warpcore_set_lpi_passthrough(phy, params);
  3567. /* 10G XFI Full Duplex */
  3568. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3569. MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x100);
  3570. /* Release tx_fifo_reset */
  3571. bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
  3572. MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3,
  3573. 0xFFFE);
  3574. /* Release rxSeqStart */
  3575. bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
  3576. MDIO_WC_REG_DSC2B0_DSC_MISC_CTRL0, 0x7FFF);
  3577. }
  3578. static void bnx2x_warpcore_set_20G_force_KR2(struct bnx2x_phy *phy,
  3579. struct link_params *params)
  3580. {
  3581. u16 val;
  3582. struct bnx2x *bp = params->bp;
  3583. /* Set global registers, so set AER lane to 0 */
  3584. CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
  3585. MDIO_AER_BLOCK_AER_REG, 0);
  3586. /* Disable sequencer */
  3587. bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
  3588. MDIO_WC_REG_XGXSBLK0_XGXSCONTROL, ~(1<<13));
  3589. bnx2x_set_aer_mmd(params, phy);
  3590. bnx2x_cl45_read_and_write(bp, phy, MDIO_PMA_DEVAD,
  3591. MDIO_WC_REG_PMD_KR_CONTROL, ~(1<<1));
  3592. bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
  3593. MDIO_AN_REG_CTRL, 0);
  3594. /* Turn off CL73 */
  3595. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
  3596. MDIO_WC_REG_CL73_USERB0_CTRL, &val);
  3597. val &= ~(1<<5);
  3598. val |= (1<<6);
  3599. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3600. MDIO_WC_REG_CL73_USERB0_CTRL, val);
  3601. /* Set 20G KR2 force speed */
  3602. bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
  3603. MDIO_WC_REG_SERDESDIGITAL_MISC1, 0x1f);
  3604. bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
  3605. MDIO_WC_REG_DIGITAL4_MISC3, (1<<7));
  3606. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
  3607. MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL, &val);
  3608. val &= ~(3<<14);
  3609. val |= (1<<15);
  3610. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3611. MDIO_WC_REG_CL72_USERB0_CL72_MISC1_CONTROL, val);
  3612. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3613. MDIO_WC_REG_CL72_USERB0_CL72_TX_FIR_TAP, 0x835A);
  3614. /* Enable sequencer (over lane 0) */
  3615. CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
  3616. MDIO_AER_BLOCK_AER_REG, 0);
  3617. bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
  3618. MDIO_WC_REG_XGXSBLK0_XGXSCONTROL, (1<<13));
  3619. bnx2x_set_aer_mmd(params, phy);
  3620. }
  3621. static void bnx2x_warpcore_set_20G_DXGXS(struct bnx2x *bp,
  3622. struct bnx2x_phy *phy,
  3623. u16 lane)
  3624. {
  3625. /* Rx0 anaRxControl1G */
  3626. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3627. MDIO_WC_REG_RX0_ANARXCONTROL1G, 0x90);
  3628. /* Rx2 anaRxControl1G */
  3629. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3630. MDIO_WC_REG_RX2_ANARXCONTROL1G, 0x90);
  3631. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3632. MDIO_WC_REG_RX66_SCW0, 0xE070);
  3633. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3634. MDIO_WC_REG_RX66_SCW1, 0xC0D0);
  3635. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3636. MDIO_WC_REG_RX66_SCW2, 0xA0B0);
  3637. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3638. MDIO_WC_REG_RX66_SCW3, 0x8090);
  3639. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3640. MDIO_WC_REG_RX66_SCW0_MASK, 0xF0F0);
  3641. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3642. MDIO_WC_REG_RX66_SCW1_MASK, 0xF0F0);
  3643. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3644. MDIO_WC_REG_RX66_SCW2_MASK, 0xF0F0);
  3645. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3646. MDIO_WC_REG_RX66_SCW3_MASK, 0xF0F0);
  3647. /* Serdes Digital Misc1 */
  3648. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3649. MDIO_WC_REG_SERDESDIGITAL_MISC1, 0x6008);
  3650. /* Serdes Digital4 Misc3 */
  3651. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3652. MDIO_WC_REG_DIGITAL4_MISC3, 0x8088);
  3653. /* Set Transmit PMD settings */
  3654. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3655. MDIO_WC_REG_TX_FIR_TAP,
  3656. (WC_TX_FIR(0x12, 0x2d, 0x00) |
  3657. MDIO_WC_REG_TX_FIR_TAP_ENABLE));
  3658. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3659. MDIO_WC_REG_TX0_TX_DRIVER + 0x10*lane,
  3660. WC_TX_DRIVER(0x02, 0x02, 0x02, 0));
  3661. }
  3662. static void bnx2x_warpcore_set_sgmii_speed(struct bnx2x_phy *phy,
  3663. struct link_params *params,
  3664. u8 fiber_mode,
  3665. u8 always_autoneg)
  3666. {
  3667. struct bnx2x *bp = params->bp;
  3668. u16 val16, digctrl_kx1, digctrl_kx2;
  3669. /* Clear XFI clock comp in non-10G single lane mode. */
  3670. bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
  3671. MDIO_WC_REG_RX66_CONTROL, ~(3<<13));
  3672. bnx2x_warpcore_set_lpi_passthrough(phy, params);
  3673. if (always_autoneg || phy->req_line_speed == SPEED_AUTO_NEG) {
  3674. /* SGMII Autoneg */
  3675. bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
  3676. MDIO_WC_REG_COMBO_IEEE0_MIICTRL,
  3677. 0x1000);
  3678. DP(NETIF_MSG_LINK, "set SGMII AUTONEG\n");
  3679. } else {
  3680. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
  3681. MDIO_WC_REG_COMBO_IEEE0_MIICTRL, &val16);
  3682. val16 &= 0xcebf;
  3683. switch (phy->req_line_speed) {
  3684. case SPEED_10:
  3685. break;
  3686. case SPEED_100:
  3687. val16 |= 0x2000;
  3688. break;
  3689. case SPEED_1000:
  3690. val16 |= 0x0040;
  3691. break;
  3692. default:
  3693. DP(NETIF_MSG_LINK,
  3694. "Speed not supported: 0x%x\n", phy->req_line_speed);
  3695. return;
  3696. }
  3697. if (phy->req_duplex == DUPLEX_FULL)
  3698. val16 |= 0x0100;
  3699. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3700. MDIO_WC_REG_COMBO_IEEE0_MIICTRL, val16);
  3701. DP(NETIF_MSG_LINK, "set SGMII force speed %d\n",
  3702. phy->req_line_speed);
  3703. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
  3704. MDIO_WC_REG_COMBO_IEEE0_MIICTRL, &val16);
  3705. DP(NETIF_MSG_LINK, " (readback) %x\n", val16);
  3706. }
  3707. /* SGMII Slave mode and disable signal detect */
  3708. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
  3709. MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1, &digctrl_kx1);
  3710. if (fiber_mode)
  3711. digctrl_kx1 = 1;
  3712. else
  3713. digctrl_kx1 &= 0xff4a;
  3714. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3715. MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1,
  3716. digctrl_kx1);
  3717. /* Turn off parallel detect */
  3718. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
  3719. MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2, &digctrl_kx2);
  3720. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3721. MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
  3722. (digctrl_kx2 & ~(1<<2)));
  3723. /* Re-enable parallel detect */
  3724. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3725. MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
  3726. (digctrl_kx2 | (1<<2)));
  3727. /* Enable autodet */
  3728. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3729. MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1,
  3730. (digctrl_kx1 | 0x10));
  3731. }
  3732. static void bnx2x_warpcore_reset_lane(struct bnx2x *bp,
  3733. struct bnx2x_phy *phy,
  3734. u8 reset)
  3735. {
  3736. u16 val;
  3737. /* Take lane out of reset after configuration is finished */
  3738. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
  3739. MDIO_WC_REG_DIGITAL5_MISC6, &val);
  3740. if (reset)
  3741. val |= 0xC000;
  3742. else
  3743. val &= 0x3FFF;
  3744. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3745. MDIO_WC_REG_DIGITAL5_MISC6, val);
  3746. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
  3747. MDIO_WC_REG_DIGITAL5_MISC6, &val);
  3748. }
  3749. /* Clear SFI/XFI link settings registers */
  3750. static void bnx2x_warpcore_clear_regs(struct bnx2x_phy *phy,
  3751. struct link_params *params,
  3752. u16 lane)
  3753. {
  3754. struct bnx2x *bp = params->bp;
  3755. u16 i;
  3756. static struct bnx2x_reg_set wc_regs[] = {
  3757. {MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0},
  3758. {MDIO_WC_DEVAD, MDIO_WC_REG_FX100_CTRL1, 0x014a},
  3759. {MDIO_WC_DEVAD, MDIO_WC_REG_FX100_CTRL3, 0x0800},
  3760. {MDIO_WC_DEVAD, MDIO_WC_REG_DIGITAL4_MISC3, 0x8008},
  3761. {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X1,
  3762. 0x0195},
  3763. {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X2,
  3764. 0x0007},
  3765. {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_CONTROL1000X3,
  3766. 0x0002},
  3767. {MDIO_WC_DEVAD, MDIO_WC_REG_SERDESDIGITAL_MISC1, 0x6000},
  3768. {MDIO_WC_DEVAD, MDIO_WC_REG_TX_FIR_TAP, 0x0000},
  3769. {MDIO_WC_DEVAD, MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x2040},
  3770. {MDIO_WC_DEVAD, MDIO_WC_REG_COMBO_IEEE0_MIICTRL, 0x0140}
  3771. };
  3772. /* Set XFI clock comp as default. */
  3773. bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
  3774. MDIO_WC_REG_RX66_CONTROL, (3<<13));
  3775. for (i = 0; i < ARRAY_SIZE(wc_regs); i++)
  3776. bnx2x_cl45_write(bp, phy, wc_regs[i].devad, wc_regs[i].reg,
  3777. wc_regs[i].val);
  3778. lane = bnx2x_get_warpcore_lane(phy, params);
  3779. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  3780. MDIO_WC_REG_TX0_TX_DRIVER + 0x10*lane, 0x0990);
  3781. }
  3782. static int bnx2x_get_mod_abs_int_cfg(struct bnx2x *bp,
  3783. u32 chip_id,
  3784. u32 shmem_base, u8 port,
  3785. u8 *gpio_num, u8 *gpio_port)
  3786. {
  3787. u32 cfg_pin;
  3788. *gpio_num = 0;
  3789. *gpio_port = 0;
  3790. if (CHIP_IS_E3(bp)) {
  3791. cfg_pin = (REG_RD(bp, shmem_base +
  3792. offsetof(struct shmem_region,
  3793. dev_info.port_hw_config[port].e3_sfp_ctrl)) &
  3794. PORT_HW_CFG_E3_MOD_ABS_MASK) >>
  3795. PORT_HW_CFG_E3_MOD_ABS_SHIFT;
  3796. /* Should not happen. This function called upon interrupt
  3797. * triggered by GPIO ( since EPIO can only generate interrupts
  3798. * to MCP).
  3799. * So if this function was called and none of the GPIOs was set,
  3800. * it means the shit hit the fan.
  3801. */
  3802. if ((cfg_pin < PIN_CFG_GPIO0_P0) ||
  3803. (cfg_pin > PIN_CFG_GPIO3_P1)) {
  3804. DP(NETIF_MSG_LINK,
  3805. "No cfg pin %x for module detect indication\n",
  3806. cfg_pin);
  3807. return -EINVAL;
  3808. }
  3809. *gpio_num = (cfg_pin - PIN_CFG_GPIO0_P0) & 0x3;
  3810. *gpio_port = (cfg_pin - PIN_CFG_GPIO0_P0) >> 2;
  3811. } else {
  3812. *gpio_num = MISC_REGISTERS_GPIO_3;
  3813. *gpio_port = port;
  3814. }
  3815. return 0;
  3816. }
  3817. static int bnx2x_is_sfp_module_plugged(struct bnx2x_phy *phy,
  3818. struct link_params *params)
  3819. {
  3820. struct bnx2x *bp = params->bp;
  3821. u8 gpio_num, gpio_port;
  3822. u32 gpio_val;
  3823. if (bnx2x_get_mod_abs_int_cfg(bp, params->chip_id,
  3824. params->shmem_base, params->port,
  3825. &gpio_num, &gpio_port) != 0)
  3826. return 0;
  3827. gpio_val = bnx2x_get_gpio(bp, gpio_num, gpio_port);
  3828. /* Call the handling function in case module is detected */
  3829. if (gpio_val == 0)
  3830. return 1;
  3831. else
  3832. return 0;
  3833. }
  3834. static int bnx2x_warpcore_get_sigdet(struct bnx2x_phy *phy,
  3835. struct link_params *params)
  3836. {
  3837. u16 gp2_status_reg0, lane;
  3838. struct bnx2x *bp = params->bp;
  3839. lane = bnx2x_get_warpcore_lane(phy, params);
  3840. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD, MDIO_WC_REG_GP2_STATUS_GP_2_0,
  3841. &gp2_status_reg0);
  3842. return (gp2_status_reg0 >> (8+lane)) & 0x1;
  3843. }
  3844. static void bnx2x_warpcore_config_runtime(struct bnx2x_phy *phy,
  3845. struct link_params *params,
  3846. struct link_vars *vars)
  3847. {
  3848. struct bnx2x *bp = params->bp;
  3849. u32 serdes_net_if;
  3850. u16 gp_status1 = 0, lnkup = 0, lnkup_kr = 0;
  3851. vars->turn_to_run_wc_rt = vars->turn_to_run_wc_rt ? 0 : 1;
  3852. if (!vars->turn_to_run_wc_rt)
  3853. return;
  3854. if (vars->rx_tx_asic_rst) {
  3855. u16 lane = bnx2x_get_warpcore_lane(phy, params);
  3856. serdes_net_if = (REG_RD(bp, params->shmem_base +
  3857. offsetof(struct shmem_region, dev_info.
  3858. port_hw_config[params->port].default_cfg)) &
  3859. PORT_HW_CFG_NET_SERDES_IF_MASK);
  3860. switch (serdes_net_if) {
  3861. case PORT_HW_CFG_NET_SERDES_IF_KR:
  3862. /* Do we get link yet? */
  3863. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD, 0x81d1,
  3864. &gp_status1);
  3865. lnkup = (gp_status1 >> (8+lane)) & 0x1;/* 1G */
  3866. /*10G KR*/
  3867. lnkup_kr = (gp_status1 >> (12+lane)) & 0x1;
  3868. if (lnkup_kr || lnkup) {
  3869. vars->rx_tx_asic_rst = 0;
  3870. } else {
  3871. /* Reset the lane to see if link comes up.*/
  3872. bnx2x_warpcore_reset_lane(bp, phy, 1);
  3873. bnx2x_warpcore_reset_lane(bp, phy, 0);
  3874. /* Restart Autoneg */
  3875. bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
  3876. MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x1200);
  3877. vars->rx_tx_asic_rst--;
  3878. DP(NETIF_MSG_LINK, "0x%x retry left\n",
  3879. vars->rx_tx_asic_rst);
  3880. }
  3881. break;
  3882. default:
  3883. break;
  3884. }
  3885. } /*params->rx_tx_asic_rst*/
  3886. }
  3887. static void bnx2x_warpcore_config_sfi(struct bnx2x_phy *phy,
  3888. struct link_params *params)
  3889. {
  3890. u16 lane = bnx2x_get_warpcore_lane(phy, params);
  3891. struct bnx2x *bp = params->bp;
  3892. bnx2x_warpcore_clear_regs(phy, params, lane);
  3893. if ((params->req_line_speed[LINK_CONFIG_IDX(INT_PHY)] ==
  3894. SPEED_10000) &&
  3895. (phy->media_type != ETH_PHY_SFP_1G_FIBER)) {
  3896. DP(NETIF_MSG_LINK, "Setting 10G SFI\n");
  3897. bnx2x_warpcore_set_10G_XFI(phy, params, 0);
  3898. } else {
  3899. DP(NETIF_MSG_LINK, "Setting 1G Fiber\n");
  3900. bnx2x_warpcore_set_sgmii_speed(phy, params, 1, 0);
  3901. }
  3902. }
  3903. static void bnx2x_sfp_e3_set_transmitter(struct link_params *params,
  3904. struct bnx2x_phy *phy,
  3905. u8 tx_en)
  3906. {
  3907. struct bnx2x *bp = params->bp;
  3908. u32 cfg_pin;
  3909. u8 port = params->port;
  3910. cfg_pin = REG_RD(bp, params->shmem_base +
  3911. offsetof(struct shmem_region,
  3912. dev_info.port_hw_config[port].e3_sfp_ctrl)) &
  3913. PORT_HW_CFG_E3_TX_LASER_MASK;
  3914. /* Set the !tx_en since this pin is DISABLE_TX_LASER */
  3915. DP(NETIF_MSG_LINK, "Setting WC TX to %d\n", tx_en);
  3916. /* For 20G, the expected pin to be used is 3 pins after the current */
  3917. bnx2x_set_cfg_pin(bp, cfg_pin, tx_en ^ 1);
  3918. if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_20G)
  3919. bnx2x_set_cfg_pin(bp, cfg_pin + 3, tx_en ^ 1);
  3920. }
  3921. static void bnx2x_warpcore_config_init(struct bnx2x_phy *phy,
  3922. struct link_params *params,
  3923. struct link_vars *vars)
  3924. {
  3925. struct bnx2x *bp = params->bp;
  3926. u32 serdes_net_if;
  3927. u8 fiber_mode;
  3928. u16 lane = bnx2x_get_warpcore_lane(phy, params);
  3929. serdes_net_if = (REG_RD(bp, params->shmem_base +
  3930. offsetof(struct shmem_region, dev_info.
  3931. port_hw_config[params->port].default_cfg)) &
  3932. PORT_HW_CFG_NET_SERDES_IF_MASK);
  3933. DP(NETIF_MSG_LINK, "Begin Warpcore init, link_speed %d, "
  3934. "serdes_net_if = 0x%x\n",
  3935. vars->line_speed, serdes_net_if);
  3936. bnx2x_set_aer_mmd(params, phy);
  3937. bnx2x_warpcore_reset_lane(bp, phy, 1);
  3938. vars->phy_flags |= PHY_XGXS_FLAG;
  3939. if ((serdes_net_if == PORT_HW_CFG_NET_SERDES_IF_SGMII) ||
  3940. (phy->req_line_speed &&
  3941. ((phy->req_line_speed == SPEED_100) ||
  3942. (phy->req_line_speed == SPEED_10)))) {
  3943. vars->phy_flags |= PHY_SGMII_FLAG;
  3944. DP(NETIF_MSG_LINK, "Setting SGMII mode\n");
  3945. bnx2x_warpcore_clear_regs(phy, params, lane);
  3946. bnx2x_warpcore_set_sgmii_speed(phy, params, 0, 1);
  3947. } else {
  3948. switch (serdes_net_if) {
  3949. case PORT_HW_CFG_NET_SERDES_IF_KR:
  3950. /* Enable KR Auto Neg */
  3951. if (params->loopback_mode != LOOPBACK_EXT)
  3952. bnx2x_warpcore_enable_AN_KR(phy, params, vars);
  3953. else {
  3954. DP(NETIF_MSG_LINK, "Setting KR 10G-Force\n");
  3955. bnx2x_warpcore_set_10G_KR(phy, params, vars);
  3956. }
  3957. break;
  3958. case PORT_HW_CFG_NET_SERDES_IF_XFI:
  3959. bnx2x_warpcore_clear_regs(phy, params, lane);
  3960. if (vars->line_speed == SPEED_10000) {
  3961. DP(NETIF_MSG_LINK, "Setting 10G XFI\n");
  3962. bnx2x_warpcore_set_10G_XFI(phy, params, 1);
  3963. } else {
  3964. if (SINGLE_MEDIA_DIRECT(params)) {
  3965. DP(NETIF_MSG_LINK, "1G Fiber\n");
  3966. fiber_mode = 1;
  3967. } else {
  3968. DP(NETIF_MSG_LINK, "10/100/1G SGMII\n");
  3969. fiber_mode = 0;
  3970. }
  3971. bnx2x_warpcore_set_sgmii_speed(phy,
  3972. params,
  3973. fiber_mode,
  3974. 0);
  3975. }
  3976. break;
  3977. case PORT_HW_CFG_NET_SERDES_IF_SFI:
  3978. /* Issue Module detection if module is plugged, or
  3979. * enabled transmitter to avoid current leakage in case
  3980. * no module is connected
  3981. */
  3982. if ((params->loopback_mode == LOOPBACK_NONE) ||
  3983. (params->loopback_mode == LOOPBACK_EXT)) {
  3984. if (bnx2x_is_sfp_module_plugged(phy, params))
  3985. bnx2x_sfp_module_detection(phy, params);
  3986. else
  3987. bnx2x_sfp_e3_set_transmitter(params,
  3988. phy, 1);
  3989. }
  3990. bnx2x_warpcore_config_sfi(phy, params);
  3991. break;
  3992. case PORT_HW_CFG_NET_SERDES_IF_DXGXS:
  3993. if (vars->line_speed != SPEED_20000) {
  3994. DP(NETIF_MSG_LINK, "Speed not supported yet\n");
  3995. return;
  3996. }
  3997. DP(NETIF_MSG_LINK, "Setting 20G DXGXS\n");
  3998. bnx2x_warpcore_set_20G_DXGXS(bp, phy, lane);
  3999. /* Issue Module detection */
  4000. bnx2x_sfp_module_detection(phy, params);
  4001. break;
  4002. case PORT_HW_CFG_NET_SERDES_IF_KR2:
  4003. if (!params->loopback_mode) {
  4004. bnx2x_warpcore_enable_AN_KR(phy, params, vars);
  4005. } else {
  4006. DP(NETIF_MSG_LINK, "Setting KR 20G-Force\n");
  4007. bnx2x_warpcore_set_20G_force_KR2(phy, params);
  4008. }
  4009. break;
  4010. default:
  4011. DP(NETIF_MSG_LINK,
  4012. "Unsupported Serdes Net Interface 0x%x\n",
  4013. serdes_net_if);
  4014. return;
  4015. }
  4016. }
  4017. /* Take lane out of reset after configuration is finished */
  4018. bnx2x_warpcore_reset_lane(bp, phy, 0);
  4019. DP(NETIF_MSG_LINK, "Exit config init\n");
  4020. }
  4021. static void bnx2x_warpcore_link_reset(struct bnx2x_phy *phy,
  4022. struct link_params *params)
  4023. {
  4024. struct bnx2x *bp = params->bp;
  4025. u16 val16, lane;
  4026. bnx2x_sfp_e3_set_transmitter(params, phy, 0);
  4027. bnx2x_set_mdio_emac_per_phy(bp, params);
  4028. bnx2x_set_aer_mmd(params, phy);
  4029. /* Global register */
  4030. bnx2x_warpcore_reset_lane(bp, phy, 1);
  4031. /* Clear loopback settings (if any) */
  4032. /* 10G & 20G */
  4033. bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
  4034. MDIO_WC_REG_COMBO_IEEE0_MIICTRL, 0xBFFF);
  4035. bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
  4036. MDIO_WC_REG_IEEE0BLK_MIICNTL, 0xfffe);
  4037. /* Update those 1-copy registers */
  4038. CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
  4039. MDIO_AER_BLOCK_AER_REG, 0);
  4040. /* Enable 1G MDIO (1-copy) */
  4041. bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
  4042. MDIO_WC_REG_XGXSBLK0_XGXSCONTROL,
  4043. ~0x10);
  4044. bnx2x_cl45_read_and_write(bp, phy, MDIO_WC_DEVAD,
  4045. MDIO_WC_REG_XGXSBLK1_LANECTRL2, 0xff00);
  4046. lane = bnx2x_get_warpcore_lane(phy, params);
  4047. /* Disable CL36 PCS Tx */
  4048. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
  4049. MDIO_WC_REG_XGXSBLK1_LANECTRL0, &val16);
  4050. val16 |= (0x11 << lane);
  4051. if (phy->flags & FLAGS_WC_DUAL_MODE)
  4052. val16 |= (0x22 << lane);
  4053. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  4054. MDIO_WC_REG_XGXSBLK1_LANECTRL0, val16);
  4055. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
  4056. MDIO_WC_REG_XGXSBLK1_LANECTRL1, &val16);
  4057. val16 &= ~(0x0303 << (lane << 1));
  4058. val16 |= (0x0101 << (lane << 1));
  4059. if (phy->flags & FLAGS_WC_DUAL_MODE) {
  4060. val16 &= ~(0x0c0c << (lane << 1));
  4061. val16 |= (0x0404 << (lane << 1));
  4062. }
  4063. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  4064. MDIO_WC_REG_XGXSBLK1_LANECTRL1, val16);
  4065. /* Restore AER */
  4066. bnx2x_set_aer_mmd(params, phy);
  4067. }
  4068. static void bnx2x_set_warpcore_loopback(struct bnx2x_phy *phy,
  4069. struct link_params *params)
  4070. {
  4071. struct bnx2x *bp = params->bp;
  4072. u16 val16;
  4073. u32 lane;
  4074. DP(NETIF_MSG_LINK, "Setting Warpcore loopback type %x, speed %d\n",
  4075. params->loopback_mode, phy->req_line_speed);
  4076. if (phy->req_line_speed < SPEED_10000 ||
  4077. phy->supported & SUPPORTED_20000baseKR2_Full) {
  4078. /* 10/100/1000/20G-KR2 */
  4079. /* Update those 1-copy registers */
  4080. CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
  4081. MDIO_AER_BLOCK_AER_REG, 0);
  4082. /* Enable 1G MDIO (1-copy) */
  4083. bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
  4084. MDIO_WC_REG_XGXSBLK0_XGXSCONTROL,
  4085. 0x10);
  4086. /* Set 1G loopback based on lane (1-copy) */
  4087. lane = bnx2x_get_warpcore_lane(phy, params);
  4088. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
  4089. MDIO_WC_REG_XGXSBLK1_LANECTRL2, &val16);
  4090. val16 |= (1<<lane);
  4091. if (phy->flags & FLAGS_WC_DUAL_MODE)
  4092. val16 |= (2<<lane);
  4093. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  4094. MDIO_WC_REG_XGXSBLK1_LANECTRL2,
  4095. val16);
  4096. /* Switch back to 4-copy registers */
  4097. bnx2x_set_aer_mmd(params, phy);
  4098. } else {
  4099. /* 10G / 20G-DXGXS */
  4100. bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
  4101. MDIO_WC_REG_COMBO_IEEE0_MIICTRL,
  4102. 0x4000);
  4103. bnx2x_cl45_read_or_write(bp, phy, MDIO_WC_DEVAD,
  4104. MDIO_WC_REG_IEEE0BLK_MIICNTL, 0x1);
  4105. }
  4106. }
  4107. static void bnx2x_sync_link(struct link_params *params,
  4108. struct link_vars *vars)
  4109. {
  4110. struct bnx2x *bp = params->bp;
  4111. u8 link_10g_plus;
  4112. if (vars->link_status & LINK_STATUS_PHYSICAL_LINK_FLAG)
  4113. vars->phy_flags |= PHY_PHYSICAL_LINK_FLAG;
  4114. vars->link_up = (vars->link_status & LINK_STATUS_LINK_UP);
  4115. if (vars->link_up) {
  4116. DP(NETIF_MSG_LINK, "phy link up\n");
  4117. vars->phy_link_up = 1;
  4118. vars->duplex = DUPLEX_FULL;
  4119. switch (vars->link_status &
  4120. LINK_STATUS_SPEED_AND_DUPLEX_MASK) {
  4121. case LINK_10THD:
  4122. vars->duplex = DUPLEX_HALF;
  4123. /* Fall thru */
  4124. case LINK_10TFD:
  4125. vars->line_speed = SPEED_10;
  4126. break;
  4127. case LINK_100TXHD:
  4128. vars->duplex = DUPLEX_HALF;
  4129. /* Fall thru */
  4130. case LINK_100T4:
  4131. case LINK_100TXFD:
  4132. vars->line_speed = SPEED_100;
  4133. break;
  4134. case LINK_1000THD:
  4135. vars->duplex = DUPLEX_HALF;
  4136. /* Fall thru */
  4137. case LINK_1000TFD:
  4138. vars->line_speed = SPEED_1000;
  4139. break;
  4140. case LINK_2500THD:
  4141. vars->duplex = DUPLEX_HALF;
  4142. /* Fall thru */
  4143. case LINK_2500TFD:
  4144. vars->line_speed = SPEED_2500;
  4145. break;
  4146. case LINK_10GTFD:
  4147. vars->line_speed = SPEED_10000;
  4148. break;
  4149. case LINK_20GTFD:
  4150. vars->line_speed = SPEED_20000;
  4151. break;
  4152. default:
  4153. break;
  4154. }
  4155. vars->flow_ctrl = 0;
  4156. if (vars->link_status & LINK_STATUS_TX_FLOW_CONTROL_ENABLED)
  4157. vars->flow_ctrl |= BNX2X_FLOW_CTRL_TX;
  4158. if (vars->link_status & LINK_STATUS_RX_FLOW_CONTROL_ENABLED)
  4159. vars->flow_ctrl |= BNX2X_FLOW_CTRL_RX;
  4160. if (!vars->flow_ctrl)
  4161. vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  4162. if (vars->line_speed &&
  4163. ((vars->line_speed == SPEED_10) ||
  4164. (vars->line_speed == SPEED_100))) {
  4165. vars->phy_flags |= PHY_SGMII_FLAG;
  4166. } else {
  4167. vars->phy_flags &= ~PHY_SGMII_FLAG;
  4168. }
  4169. if (vars->line_speed &&
  4170. USES_WARPCORE(bp) &&
  4171. (vars->line_speed == SPEED_1000))
  4172. vars->phy_flags |= PHY_SGMII_FLAG;
  4173. /* Anything 10 and over uses the bmac */
  4174. link_10g_plus = (vars->line_speed >= SPEED_10000);
  4175. if (link_10g_plus) {
  4176. if (USES_WARPCORE(bp))
  4177. vars->mac_type = MAC_TYPE_XMAC;
  4178. else
  4179. vars->mac_type = MAC_TYPE_BMAC;
  4180. } else {
  4181. if (USES_WARPCORE(bp))
  4182. vars->mac_type = MAC_TYPE_UMAC;
  4183. else
  4184. vars->mac_type = MAC_TYPE_EMAC;
  4185. }
  4186. } else { /* Link down */
  4187. DP(NETIF_MSG_LINK, "phy link down\n");
  4188. vars->phy_link_up = 0;
  4189. vars->line_speed = 0;
  4190. vars->duplex = DUPLEX_FULL;
  4191. vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  4192. /* Indicate no mac active */
  4193. vars->mac_type = MAC_TYPE_NONE;
  4194. if (vars->link_status & LINK_STATUS_PHYSICAL_LINK_FLAG)
  4195. vars->phy_flags |= PHY_HALF_OPEN_CONN_FLAG;
  4196. if (vars->link_status & LINK_STATUS_SFP_TX_FAULT)
  4197. vars->phy_flags |= PHY_SFP_TX_FAULT_FLAG;
  4198. }
  4199. }
  4200. void bnx2x_link_status_update(struct link_params *params,
  4201. struct link_vars *vars)
  4202. {
  4203. struct bnx2x *bp = params->bp;
  4204. u8 port = params->port;
  4205. u32 sync_offset, media_types;
  4206. /* Update PHY configuration */
  4207. set_phy_vars(params, vars);
  4208. vars->link_status = REG_RD(bp, params->shmem_base +
  4209. offsetof(struct shmem_region,
  4210. port_mb[port].link_status));
  4211. /* Force link UP in non LOOPBACK_EXT loopback mode(s) */
  4212. if (params->loopback_mode != LOOPBACK_NONE &&
  4213. params->loopback_mode != LOOPBACK_EXT)
  4214. vars->link_status |= LINK_STATUS_LINK_UP;
  4215. if (bnx2x_eee_has_cap(params))
  4216. vars->eee_status = REG_RD(bp, params->shmem2_base +
  4217. offsetof(struct shmem2_region,
  4218. eee_status[params->port]));
  4219. vars->phy_flags = PHY_XGXS_FLAG;
  4220. bnx2x_sync_link(params, vars);
  4221. /* Sync media type */
  4222. sync_offset = params->shmem_base +
  4223. offsetof(struct shmem_region,
  4224. dev_info.port_hw_config[port].media_type);
  4225. media_types = REG_RD(bp, sync_offset);
  4226. params->phy[INT_PHY].media_type =
  4227. (media_types & PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK) >>
  4228. PORT_HW_CFG_MEDIA_TYPE_PHY0_SHIFT;
  4229. params->phy[EXT_PHY1].media_type =
  4230. (media_types & PORT_HW_CFG_MEDIA_TYPE_PHY1_MASK) >>
  4231. PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT;
  4232. params->phy[EXT_PHY2].media_type =
  4233. (media_types & PORT_HW_CFG_MEDIA_TYPE_PHY2_MASK) >>
  4234. PORT_HW_CFG_MEDIA_TYPE_PHY2_SHIFT;
  4235. DP(NETIF_MSG_LINK, "media_types = 0x%x\n", media_types);
  4236. /* Sync AEU offset */
  4237. sync_offset = params->shmem_base +
  4238. offsetof(struct shmem_region,
  4239. dev_info.port_hw_config[port].aeu_int_mask);
  4240. vars->aeu_int_mask = REG_RD(bp, sync_offset);
  4241. /* Sync PFC status */
  4242. if (vars->link_status & LINK_STATUS_PFC_ENABLED)
  4243. params->feature_config_flags |=
  4244. FEATURE_CONFIG_PFC_ENABLED;
  4245. else
  4246. params->feature_config_flags &=
  4247. ~FEATURE_CONFIG_PFC_ENABLED;
  4248. if (SHMEM2_HAS(bp, link_attr_sync))
  4249. params->link_attr_sync = SHMEM2_RD(bp,
  4250. link_attr_sync[params->port]);
  4251. DP(NETIF_MSG_LINK, "link_status 0x%x phy_link_up %x int_mask 0x%x\n",
  4252. vars->link_status, vars->phy_link_up, vars->aeu_int_mask);
  4253. DP(NETIF_MSG_LINK, "line_speed %x duplex %x flow_ctrl 0x%x\n",
  4254. vars->line_speed, vars->duplex, vars->flow_ctrl);
  4255. }
  4256. static void bnx2x_set_master_ln(struct link_params *params,
  4257. struct bnx2x_phy *phy)
  4258. {
  4259. struct bnx2x *bp = params->bp;
  4260. u16 new_master_ln, ser_lane;
  4261. ser_lane = ((params->lane_config &
  4262. PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
  4263. PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
  4264. /* Set the master_ln for AN */
  4265. CL22_RD_OVER_CL45(bp, phy,
  4266. MDIO_REG_BANK_XGXS_BLOCK2,
  4267. MDIO_XGXS_BLOCK2_TEST_MODE_LANE,
  4268. &new_master_ln);
  4269. CL22_WR_OVER_CL45(bp, phy,
  4270. MDIO_REG_BANK_XGXS_BLOCK2 ,
  4271. MDIO_XGXS_BLOCK2_TEST_MODE_LANE,
  4272. (new_master_ln | ser_lane));
  4273. }
  4274. static int bnx2x_reset_unicore(struct link_params *params,
  4275. struct bnx2x_phy *phy,
  4276. u8 set_serdes)
  4277. {
  4278. struct bnx2x *bp = params->bp;
  4279. u16 mii_control;
  4280. u16 i;
  4281. CL22_RD_OVER_CL45(bp, phy,
  4282. MDIO_REG_BANK_COMBO_IEEE0,
  4283. MDIO_COMBO_IEEE0_MII_CONTROL, &mii_control);
  4284. /* Reset the unicore */
  4285. CL22_WR_OVER_CL45(bp, phy,
  4286. MDIO_REG_BANK_COMBO_IEEE0,
  4287. MDIO_COMBO_IEEE0_MII_CONTROL,
  4288. (mii_control |
  4289. MDIO_COMBO_IEEO_MII_CONTROL_RESET));
  4290. if (set_serdes)
  4291. bnx2x_set_serdes_access(bp, params->port);
  4292. /* Wait for the reset to self clear */
  4293. for (i = 0; i < MDIO_ACCESS_TIMEOUT; i++) {
  4294. udelay(5);
  4295. /* The reset erased the previous bank value */
  4296. CL22_RD_OVER_CL45(bp, phy,
  4297. MDIO_REG_BANK_COMBO_IEEE0,
  4298. MDIO_COMBO_IEEE0_MII_CONTROL,
  4299. &mii_control);
  4300. if (!(mii_control & MDIO_COMBO_IEEO_MII_CONTROL_RESET)) {
  4301. udelay(5);
  4302. return 0;
  4303. }
  4304. }
  4305. netdev_err(bp->dev, "Warning: PHY was not initialized,"
  4306. " Port %d\n",
  4307. params->port);
  4308. DP(NETIF_MSG_LINK, "BUG! XGXS is still in reset!\n");
  4309. return -EINVAL;
  4310. }
  4311. static void bnx2x_set_swap_lanes(struct link_params *params,
  4312. struct bnx2x_phy *phy)
  4313. {
  4314. struct bnx2x *bp = params->bp;
  4315. /* Each two bits represents a lane number:
  4316. * No swap is 0123 => 0x1b no need to enable the swap
  4317. */
  4318. u16 rx_lane_swap, tx_lane_swap;
  4319. rx_lane_swap = ((params->lane_config &
  4320. PORT_HW_CFG_LANE_SWAP_CFG_RX_MASK) >>
  4321. PORT_HW_CFG_LANE_SWAP_CFG_RX_SHIFT);
  4322. tx_lane_swap = ((params->lane_config &
  4323. PORT_HW_CFG_LANE_SWAP_CFG_TX_MASK) >>
  4324. PORT_HW_CFG_LANE_SWAP_CFG_TX_SHIFT);
  4325. if (rx_lane_swap != 0x1b) {
  4326. CL22_WR_OVER_CL45(bp, phy,
  4327. MDIO_REG_BANK_XGXS_BLOCK2,
  4328. MDIO_XGXS_BLOCK2_RX_LN_SWAP,
  4329. (rx_lane_swap |
  4330. MDIO_XGXS_BLOCK2_RX_LN_SWAP_ENABLE |
  4331. MDIO_XGXS_BLOCK2_RX_LN_SWAP_FORCE_ENABLE));
  4332. } else {
  4333. CL22_WR_OVER_CL45(bp, phy,
  4334. MDIO_REG_BANK_XGXS_BLOCK2,
  4335. MDIO_XGXS_BLOCK2_RX_LN_SWAP, 0);
  4336. }
  4337. if (tx_lane_swap != 0x1b) {
  4338. CL22_WR_OVER_CL45(bp, phy,
  4339. MDIO_REG_BANK_XGXS_BLOCK2,
  4340. MDIO_XGXS_BLOCK2_TX_LN_SWAP,
  4341. (tx_lane_swap |
  4342. MDIO_XGXS_BLOCK2_TX_LN_SWAP_ENABLE));
  4343. } else {
  4344. CL22_WR_OVER_CL45(bp, phy,
  4345. MDIO_REG_BANK_XGXS_BLOCK2,
  4346. MDIO_XGXS_BLOCK2_TX_LN_SWAP, 0);
  4347. }
  4348. }
  4349. static void bnx2x_set_parallel_detection(struct bnx2x_phy *phy,
  4350. struct link_params *params)
  4351. {
  4352. struct bnx2x *bp = params->bp;
  4353. u16 control2;
  4354. CL22_RD_OVER_CL45(bp, phy,
  4355. MDIO_REG_BANK_SERDES_DIGITAL,
  4356. MDIO_SERDES_DIGITAL_A_1000X_CONTROL2,
  4357. &control2);
  4358. if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)
  4359. control2 |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL2_PRL_DT_EN;
  4360. else
  4361. control2 &= ~MDIO_SERDES_DIGITAL_A_1000X_CONTROL2_PRL_DT_EN;
  4362. DP(NETIF_MSG_LINK, "phy->speed_cap_mask = 0x%x, control2 = 0x%x\n",
  4363. phy->speed_cap_mask, control2);
  4364. CL22_WR_OVER_CL45(bp, phy,
  4365. MDIO_REG_BANK_SERDES_DIGITAL,
  4366. MDIO_SERDES_DIGITAL_A_1000X_CONTROL2,
  4367. control2);
  4368. if ((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) &&
  4369. (phy->speed_cap_mask &
  4370. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
  4371. DP(NETIF_MSG_LINK, "XGXS\n");
  4372. CL22_WR_OVER_CL45(bp, phy,
  4373. MDIO_REG_BANK_10G_PARALLEL_DETECT,
  4374. MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_LINK,
  4375. MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_LINK_CNT);
  4376. CL22_RD_OVER_CL45(bp, phy,
  4377. MDIO_REG_BANK_10G_PARALLEL_DETECT,
  4378. MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL,
  4379. &control2);
  4380. control2 |=
  4381. MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL_PARDET10G_EN;
  4382. CL22_WR_OVER_CL45(bp, phy,
  4383. MDIO_REG_BANK_10G_PARALLEL_DETECT,
  4384. MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_CONTROL,
  4385. control2);
  4386. /* Disable parallel detection of HiG */
  4387. CL22_WR_OVER_CL45(bp, phy,
  4388. MDIO_REG_BANK_XGXS_BLOCK2,
  4389. MDIO_XGXS_BLOCK2_UNICORE_MODE_10G,
  4390. MDIO_XGXS_BLOCK2_UNICORE_MODE_10G_CX4_XGXS |
  4391. MDIO_XGXS_BLOCK2_UNICORE_MODE_10G_HIGIG_XGXS);
  4392. }
  4393. }
  4394. static void bnx2x_set_autoneg(struct bnx2x_phy *phy,
  4395. struct link_params *params,
  4396. struct link_vars *vars,
  4397. u8 enable_cl73)
  4398. {
  4399. struct bnx2x *bp = params->bp;
  4400. u16 reg_val;
  4401. /* CL37 Autoneg */
  4402. CL22_RD_OVER_CL45(bp, phy,
  4403. MDIO_REG_BANK_COMBO_IEEE0,
  4404. MDIO_COMBO_IEEE0_MII_CONTROL, &reg_val);
  4405. /* CL37 Autoneg Enabled */
  4406. if (vars->line_speed == SPEED_AUTO_NEG)
  4407. reg_val |= MDIO_COMBO_IEEO_MII_CONTROL_AN_EN;
  4408. else /* CL37 Autoneg Disabled */
  4409. reg_val &= ~(MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
  4410. MDIO_COMBO_IEEO_MII_CONTROL_RESTART_AN);
  4411. CL22_WR_OVER_CL45(bp, phy,
  4412. MDIO_REG_BANK_COMBO_IEEE0,
  4413. MDIO_COMBO_IEEE0_MII_CONTROL, reg_val);
  4414. /* Enable/Disable Autodetection */
  4415. CL22_RD_OVER_CL45(bp, phy,
  4416. MDIO_REG_BANK_SERDES_DIGITAL,
  4417. MDIO_SERDES_DIGITAL_A_1000X_CONTROL1, &reg_val);
  4418. reg_val &= ~(MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_SIGNAL_DETECT_EN |
  4419. MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_INVERT_SIGNAL_DETECT);
  4420. reg_val |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_FIBER_MODE;
  4421. if (vars->line_speed == SPEED_AUTO_NEG)
  4422. reg_val |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET;
  4423. else
  4424. reg_val &= ~MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET;
  4425. CL22_WR_OVER_CL45(bp, phy,
  4426. MDIO_REG_BANK_SERDES_DIGITAL,
  4427. MDIO_SERDES_DIGITAL_A_1000X_CONTROL1, reg_val);
  4428. /* Enable TetonII and BAM autoneg */
  4429. CL22_RD_OVER_CL45(bp, phy,
  4430. MDIO_REG_BANK_BAM_NEXT_PAGE,
  4431. MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL,
  4432. &reg_val);
  4433. if (vars->line_speed == SPEED_AUTO_NEG) {
  4434. /* Enable BAM aneg Mode and TetonII aneg Mode */
  4435. reg_val |= (MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_BAM_MODE |
  4436. MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_TETON_AN);
  4437. } else {
  4438. /* TetonII and BAM Autoneg Disabled */
  4439. reg_val &= ~(MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_BAM_MODE |
  4440. MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL_TETON_AN);
  4441. }
  4442. CL22_WR_OVER_CL45(bp, phy,
  4443. MDIO_REG_BANK_BAM_NEXT_PAGE,
  4444. MDIO_BAM_NEXT_PAGE_MP5_NEXT_PAGE_CTRL,
  4445. reg_val);
  4446. if (enable_cl73) {
  4447. /* Enable Cl73 FSM status bits */
  4448. CL22_WR_OVER_CL45(bp, phy,
  4449. MDIO_REG_BANK_CL73_USERB0,
  4450. MDIO_CL73_USERB0_CL73_UCTRL,
  4451. 0xe);
  4452. /* Enable BAM Station Manager*/
  4453. CL22_WR_OVER_CL45(bp, phy,
  4454. MDIO_REG_BANK_CL73_USERB0,
  4455. MDIO_CL73_USERB0_CL73_BAM_CTRL1,
  4456. MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_EN |
  4457. MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_STATION_MNGR_EN |
  4458. MDIO_CL73_USERB0_CL73_BAM_CTRL1_BAM_NP_AFTER_BP_EN);
  4459. /* Advertise CL73 link speeds */
  4460. CL22_RD_OVER_CL45(bp, phy,
  4461. MDIO_REG_BANK_CL73_IEEEB1,
  4462. MDIO_CL73_IEEEB1_AN_ADV2,
  4463. &reg_val);
  4464. if (phy->speed_cap_mask &
  4465. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  4466. reg_val |= MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KX4;
  4467. if (phy->speed_cap_mask &
  4468. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)
  4469. reg_val |= MDIO_CL73_IEEEB1_AN_ADV2_ADVR_1000M_KX;
  4470. CL22_WR_OVER_CL45(bp, phy,
  4471. MDIO_REG_BANK_CL73_IEEEB1,
  4472. MDIO_CL73_IEEEB1_AN_ADV2,
  4473. reg_val);
  4474. /* CL73 Autoneg Enabled */
  4475. reg_val = MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN;
  4476. } else /* CL73 Autoneg Disabled */
  4477. reg_val = 0;
  4478. CL22_WR_OVER_CL45(bp, phy,
  4479. MDIO_REG_BANK_CL73_IEEEB0,
  4480. MDIO_CL73_IEEEB0_CL73_AN_CONTROL, reg_val);
  4481. }
  4482. /* Program SerDes, forced speed */
  4483. static void bnx2x_program_serdes(struct bnx2x_phy *phy,
  4484. struct link_params *params,
  4485. struct link_vars *vars)
  4486. {
  4487. struct bnx2x *bp = params->bp;
  4488. u16 reg_val;
  4489. /* Program duplex, disable autoneg and sgmii*/
  4490. CL22_RD_OVER_CL45(bp, phy,
  4491. MDIO_REG_BANK_COMBO_IEEE0,
  4492. MDIO_COMBO_IEEE0_MII_CONTROL, &reg_val);
  4493. reg_val &= ~(MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX |
  4494. MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
  4495. MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_MASK);
  4496. if (phy->req_duplex == DUPLEX_FULL)
  4497. reg_val |= MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX;
  4498. CL22_WR_OVER_CL45(bp, phy,
  4499. MDIO_REG_BANK_COMBO_IEEE0,
  4500. MDIO_COMBO_IEEE0_MII_CONTROL, reg_val);
  4501. /* Program speed
  4502. * - needed only if the speed is greater than 1G (2.5G or 10G)
  4503. */
  4504. CL22_RD_OVER_CL45(bp, phy,
  4505. MDIO_REG_BANK_SERDES_DIGITAL,
  4506. MDIO_SERDES_DIGITAL_MISC1, &reg_val);
  4507. /* Clearing the speed value before setting the right speed */
  4508. DP(NETIF_MSG_LINK, "MDIO_REG_BANK_SERDES_DIGITAL = 0x%x\n", reg_val);
  4509. reg_val &= ~(MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_MASK |
  4510. MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_SEL);
  4511. if (!((vars->line_speed == SPEED_1000) ||
  4512. (vars->line_speed == SPEED_100) ||
  4513. (vars->line_speed == SPEED_10))) {
  4514. reg_val |= (MDIO_SERDES_DIGITAL_MISC1_REFCLK_SEL_156_25M |
  4515. MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_SEL);
  4516. if (vars->line_speed == SPEED_10000)
  4517. reg_val |=
  4518. MDIO_SERDES_DIGITAL_MISC1_FORCE_SPEED_10G_CX4;
  4519. }
  4520. CL22_WR_OVER_CL45(bp, phy,
  4521. MDIO_REG_BANK_SERDES_DIGITAL,
  4522. MDIO_SERDES_DIGITAL_MISC1, reg_val);
  4523. }
  4524. static void bnx2x_set_brcm_cl37_advertisement(struct bnx2x_phy *phy,
  4525. struct link_params *params)
  4526. {
  4527. struct bnx2x *bp = params->bp;
  4528. u16 val = 0;
  4529. /* Set extended capabilities */
  4530. if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G)
  4531. val |= MDIO_OVER_1G_UP1_2_5G;
  4532. if (phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  4533. val |= MDIO_OVER_1G_UP1_10G;
  4534. CL22_WR_OVER_CL45(bp, phy,
  4535. MDIO_REG_BANK_OVER_1G,
  4536. MDIO_OVER_1G_UP1, val);
  4537. CL22_WR_OVER_CL45(bp, phy,
  4538. MDIO_REG_BANK_OVER_1G,
  4539. MDIO_OVER_1G_UP3, 0x400);
  4540. }
  4541. static void bnx2x_set_ieee_aneg_advertisement(struct bnx2x_phy *phy,
  4542. struct link_params *params,
  4543. u16 ieee_fc)
  4544. {
  4545. struct bnx2x *bp = params->bp;
  4546. u16 val;
  4547. /* For AN, we are always publishing full duplex */
  4548. CL22_WR_OVER_CL45(bp, phy,
  4549. MDIO_REG_BANK_COMBO_IEEE0,
  4550. MDIO_COMBO_IEEE0_AUTO_NEG_ADV, ieee_fc);
  4551. CL22_RD_OVER_CL45(bp, phy,
  4552. MDIO_REG_BANK_CL73_IEEEB1,
  4553. MDIO_CL73_IEEEB1_AN_ADV1, &val);
  4554. val &= ~MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_BOTH;
  4555. val |= ((ieee_fc<<3) & MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_MASK);
  4556. CL22_WR_OVER_CL45(bp, phy,
  4557. MDIO_REG_BANK_CL73_IEEEB1,
  4558. MDIO_CL73_IEEEB1_AN_ADV1, val);
  4559. }
  4560. static void bnx2x_restart_autoneg(struct bnx2x_phy *phy,
  4561. struct link_params *params,
  4562. u8 enable_cl73)
  4563. {
  4564. struct bnx2x *bp = params->bp;
  4565. u16 mii_control;
  4566. DP(NETIF_MSG_LINK, "bnx2x_restart_autoneg\n");
  4567. /* Enable and restart BAM/CL37 aneg */
  4568. if (enable_cl73) {
  4569. CL22_RD_OVER_CL45(bp, phy,
  4570. MDIO_REG_BANK_CL73_IEEEB0,
  4571. MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
  4572. &mii_control);
  4573. CL22_WR_OVER_CL45(bp, phy,
  4574. MDIO_REG_BANK_CL73_IEEEB0,
  4575. MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
  4576. (mii_control |
  4577. MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN |
  4578. MDIO_CL73_IEEEB0_CL73_AN_CONTROL_RESTART_AN));
  4579. } else {
  4580. CL22_RD_OVER_CL45(bp, phy,
  4581. MDIO_REG_BANK_COMBO_IEEE0,
  4582. MDIO_COMBO_IEEE0_MII_CONTROL,
  4583. &mii_control);
  4584. DP(NETIF_MSG_LINK,
  4585. "bnx2x_restart_autoneg mii_control before = 0x%x\n",
  4586. mii_control);
  4587. CL22_WR_OVER_CL45(bp, phy,
  4588. MDIO_REG_BANK_COMBO_IEEE0,
  4589. MDIO_COMBO_IEEE0_MII_CONTROL,
  4590. (mii_control |
  4591. MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
  4592. MDIO_COMBO_IEEO_MII_CONTROL_RESTART_AN));
  4593. }
  4594. }
  4595. static void bnx2x_initialize_sgmii_process(struct bnx2x_phy *phy,
  4596. struct link_params *params,
  4597. struct link_vars *vars)
  4598. {
  4599. struct bnx2x *bp = params->bp;
  4600. u16 control1;
  4601. /* In SGMII mode, the unicore is always slave */
  4602. CL22_RD_OVER_CL45(bp, phy,
  4603. MDIO_REG_BANK_SERDES_DIGITAL,
  4604. MDIO_SERDES_DIGITAL_A_1000X_CONTROL1,
  4605. &control1);
  4606. control1 |= MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_INVERT_SIGNAL_DETECT;
  4607. /* Set sgmii mode (and not fiber) */
  4608. control1 &= ~(MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_FIBER_MODE |
  4609. MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_AUTODET |
  4610. MDIO_SERDES_DIGITAL_A_1000X_CONTROL1_MSTR_MODE);
  4611. CL22_WR_OVER_CL45(bp, phy,
  4612. MDIO_REG_BANK_SERDES_DIGITAL,
  4613. MDIO_SERDES_DIGITAL_A_1000X_CONTROL1,
  4614. control1);
  4615. /* If forced speed */
  4616. if (!(vars->line_speed == SPEED_AUTO_NEG)) {
  4617. /* Set speed, disable autoneg */
  4618. u16 mii_control;
  4619. CL22_RD_OVER_CL45(bp, phy,
  4620. MDIO_REG_BANK_COMBO_IEEE0,
  4621. MDIO_COMBO_IEEE0_MII_CONTROL,
  4622. &mii_control);
  4623. mii_control &= ~(MDIO_COMBO_IEEO_MII_CONTROL_AN_EN |
  4624. MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_MASK|
  4625. MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX);
  4626. switch (vars->line_speed) {
  4627. case SPEED_100:
  4628. mii_control |=
  4629. MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_100;
  4630. break;
  4631. case SPEED_1000:
  4632. mii_control |=
  4633. MDIO_COMBO_IEEO_MII_CONTROL_MAN_SGMII_SP_1000;
  4634. break;
  4635. case SPEED_10:
  4636. /* There is nothing to set for 10M */
  4637. break;
  4638. default:
  4639. /* Invalid speed for SGMII */
  4640. DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
  4641. vars->line_speed);
  4642. break;
  4643. }
  4644. /* Setting the full duplex */
  4645. if (phy->req_duplex == DUPLEX_FULL)
  4646. mii_control |=
  4647. MDIO_COMBO_IEEO_MII_CONTROL_FULL_DUPLEX;
  4648. CL22_WR_OVER_CL45(bp, phy,
  4649. MDIO_REG_BANK_COMBO_IEEE0,
  4650. MDIO_COMBO_IEEE0_MII_CONTROL,
  4651. mii_control);
  4652. } else { /* AN mode */
  4653. /* Enable and restart AN */
  4654. bnx2x_restart_autoneg(phy, params, 0);
  4655. }
  4656. }
  4657. /* Link management
  4658. */
  4659. static int bnx2x_direct_parallel_detect_used(struct bnx2x_phy *phy,
  4660. struct link_params *params)
  4661. {
  4662. struct bnx2x *bp = params->bp;
  4663. u16 pd_10g, status2_1000x;
  4664. if (phy->req_line_speed != SPEED_AUTO_NEG)
  4665. return 0;
  4666. CL22_RD_OVER_CL45(bp, phy,
  4667. MDIO_REG_BANK_SERDES_DIGITAL,
  4668. MDIO_SERDES_DIGITAL_A_1000X_STATUS2,
  4669. &status2_1000x);
  4670. CL22_RD_OVER_CL45(bp, phy,
  4671. MDIO_REG_BANK_SERDES_DIGITAL,
  4672. MDIO_SERDES_DIGITAL_A_1000X_STATUS2,
  4673. &status2_1000x);
  4674. if (status2_1000x & MDIO_SERDES_DIGITAL_A_1000X_STATUS2_AN_DISABLED) {
  4675. DP(NETIF_MSG_LINK, "1G parallel detect link on port %d\n",
  4676. params->port);
  4677. return 1;
  4678. }
  4679. CL22_RD_OVER_CL45(bp, phy,
  4680. MDIO_REG_BANK_10G_PARALLEL_DETECT,
  4681. MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_STATUS,
  4682. &pd_10g);
  4683. if (pd_10g & MDIO_10G_PARALLEL_DETECT_PAR_DET_10G_STATUS_PD_LINK) {
  4684. DP(NETIF_MSG_LINK, "10G parallel detect link on port %d\n",
  4685. params->port);
  4686. return 1;
  4687. }
  4688. return 0;
  4689. }
  4690. static void bnx2x_update_adv_fc(struct bnx2x_phy *phy,
  4691. struct link_params *params,
  4692. struct link_vars *vars,
  4693. u32 gp_status)
  4694. {
  4695. u16 ld_pause; /* local driver */
  4696. u16 lp_pause; /* link partner */
  4697. u16 pause_result;
  4698. struct bnx2x *bp = params->bp;
  4699. if ((gp_status &
  4700. (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE |
  4701. MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_MR_LP_NP_AN_ABLE)) ==
  4702. (MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_AUTONEG_COMPLETE |
  4703. MDIO_GP_STATUS_TOP_AN_STATUS1_CL73_MR_LP_NP_AN_ABLE)) {
  4704. CL22_RD_OVER_CL45(bp, phy,
  4705. MDIO_REG_BANK_CL73_IEEEB1,
  4706. MDIO_CL73_IEEEB1_AN_ADV1,
  4707. &ld_pause);
  4708. CL22_RD_OVER_CL45(bp, phy,
  4709. MDIO_REG_BANK_CL73_IEEEB1,
  4710. MDIO_CL73_IEEEB1_AN_LP_ADV1,
  4711. &lp_pause);
  4712. pause_result = (ld_pause &
  4713. MDIO_CL73_IEEEB1_AN_ADV1_PAUSE_MASK) >> 8;
  4714. pause_result |= (lp_pause &
  4715. MDIO_CL73_IEEEB1_AN_LP_ADV1_PAUSE_MASK) >> 10;
  4716. DP(NETIF_MSG_LINK, "pause_result CL73 0x%x\n", pause_result);
  4717. } else {
  4718. CL22_RD_OVER_CL45(bp, phy,
  4719. MDIO_REG_BANK_COMBO_IEEE0,
  4720. MDIO_COMBO_IEEE0_AUTO_NEG_ADV,
  4721. &ld_pause);
  4722. CL22_RD_OVER_CL45(bp, phy,
  4723. MDIO_REG_BANK_COMBO_IEEE0,
  4724. MDIO_COMBO_IEEE0_AUTO_NEG_LINK_PARTNER_ABILITY1,
  4725. &lp_pause);
  4726. pause_result = (ld_pause &
  4727. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK)>>5;
  4728. pause_result |= (lp_pause &
  4729. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK)>>7;
  4730. DP(NETIF_MSG_LINK, "pause_result CL37 0x%x\n", pause_result);
  4731. }
  4732. bnx2x_pause_resolve(phy, params, vars, pause_result);
  4733. }
  4734. static void bnx2x_flow_ctrl_resolve(struct bnx2x_phy *phy,
  4735. struct link_params *params,
  4736. struct link_vars *vars,
  4737. u32 gp_status)
  4738. {
  4739. struct bnx2x *bp = params->bp;
  4740. vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  4741. /* Resolve from gp_status in case of AN complete and not sgmii */
  4742. if (phy->req_flow_ctrl != BNX2X_FLOW_CTRL_AUTO) {
  4743. /* Update the advertised flow-controled of LD/LP in AN */
  4744. if (phy->req_line_speed == SPEED_AUTO_NEG)
  4745. bnx2x_update_adv_fc(phy, params, vars, gp_status);
  4746. /* But set the flow-control result as the requested one */
  4747. vars->flow_ctrl = phy->req_flow_ctrl;
  4748. } else if (phy->req_line_speed != SPEED_AUTO_NEG)
  4749. vars->flow_ctrl = params->req_fc_auto_adv;
  4750. else if ((gp_status & MDIO_AN_CL73_OR_37_COMPLETE) &&
  4751. (!(vars->phy_flags & PHY_SGMII_FLAG))) {
  4752. if (bnx2x_direct_parallel_detect_used(phy, params)) {
  4753. vars->flow_ctrl = params->req_fc_auto_adv;
  4754. return;
  4755. }
  4756. bnx2x_update_adv_fc(phy, params, vars, gp_status);
  4757. }
  4758. DP(NETIF_MSG_LINK, "flow_ctrl 0x%x\n", vars->flow_ctrl);
  4759. }
  4760. static void bnx2x_check_fallback_to_cl37(struct bnx2x_phy *phy,
  4761. struct link_params *params)
  4762. {
  4763. struct bnx2x *bp = params->bp;
  4764. u16 rx_status, ustat_val, cl37_fsm_received;
  4765. DP(NETIF_MSG_LINK, "bnx2x_check_fallback_to_cl37\n");
  4766. /* Step 1: Make sure signal is detected */
  4767. CL22_RD_OVER_CL45(bp, phy,
  4768. MDIO_REG_BANK_RX0,
  4769. MDIO_RX0_RX_STATUS,
  4770. &rx_status);
  4771. if ((rx_status & MDIO_RX0_RX_STATUS_SIGDET) !=
  4772. (MDIO_RX0_RX_STATUS_SIGDET)) {
  4773. DP(NETIF_MSG_LINK, "Signal is not detected. Restoring CL73."
  4774. "rx_status(0x80b0) = 0x%x\n", rx_status);
  4775. CL22_WR_OVER_CL45(bp, phy,
  4776. MDIO_REG_BANK_CL73_IEEEB0,
  4777. MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
  4778. MDIO_CL73_IEEEB0_CL73_AN_CONTROL_AN_EN);
  4779. return;
  4780. }
  4781. /* Step 2: Check CL73 state machine */
  4782. CL22_RD_OVER_CL45(bp, phy,
  4783. MDIO_REG_BANK_CL73_USERB0,
  4784. MDIO_CL73_USERB0_CL73_USTAT1,
  4785. &ustat_val);
  4786. if ((ustat_val &
  4787. (MDIO_CL73_USERB0_CL73_USTAT1_LINK_STATUS_CHECK |
  4788. MDIO_CL73_USERB0_CL73_USTAT1_AN_GOOD_CHECK_BAM37)) !=
  4789. (MDIO_CL73_USERB0_CL73_USTAT1_LINK_STATUS_CHECK |
  4790. MDIO_CL73_USERB0_CL73_USTAT1_AN_GOOD_CHECK_BAM37)) {
  4791. DP(NETIF_MSG_LINK, "CL73 state-machine is not stable. "
  4792. "ustat_val(0x8371) = 0x%x\n", ustat_val);
  4793. return;
  4794. }
  4795. /* Step 3: Check CL37 Message Pages received to indicate LP
  4796. * supports only CL37
  4797. */
  4798. CL22_RD_OVER_CL45(bp, phy,
  4799. MDIO_REG_BANK_REMOTE_PHY,
  4800. MDIO_REMOTE_PHY_MISC_RX_STATUS,
  4801. &cl37_fsm_received);
  4802. if ((cl37_fsm_received &
  4803. (MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_OVER1G_MSG |
  4804. MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_BRCM_OUI_MSG)) !=
  4805. (MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_OVER1G_MSG |
  4806. MDIO_REMOTE_PHY_MISC_RX_STATUS_CL37_FSM_RECEIVED_BRCM_OUI_MSG)) {
  4807. DP(NETIF_MSG_LINK, "No CL37 FSM were received. "
  4808. "misc_rx_status(0x8330) = 0x%x\n",
  4809. cl37_fsm_received);
  4810. return;
  4811. }
  4812. /* The combined cl37/cl73 fsm state information indicating that
  4813. * we are connected to a device which does not support cl73, but
  4814. * does support cl37 BAM. In this case we disable cl73 and
  4815. * restart cl37 auto-neg
  4816. */
  4817. /* Disable CL73 */
  4818. CL22_WR_OVER_CL45(bp, phy,
  4819. MDIO_REG_BANK_CL73_IEEEB0,
  4820. MDIO_CL73_IEEEB0_CL73_AN_CONTROL,
  4821. 0);
  4822. /* Restart CL37 autoneg */
  4823. bnx2x_restart_autoneg(phy, params, 0);
  4824. DP(NETIF_MSG_LINK, "Disabling CL73, and restarting CL37 autoneg\n");
  4825. }
  4826. static void bnx2x_xgxs_an_resolve(struct bnx2x_phy *phy,
  4827. struct link_params *params,
  4828. struct link_vars *vars,
  4829. u32 gp_status)
  4830. {
  4831. if (gp_status & MDIO_AN_CL73_OR_37_COMPLETE)
  4832. vars->link_status |=
  4833. LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
  4834. if (bnx2x_direct_parallel_detect_used(phy, params))
  4835. vars->link_status |=
  4836. LINK_STATUS_PARALLEL_DETECTION_USED;
  4837. }
  4838. static int bnx2x_get_link_speed_duplex(struct bnx2x_phy *phy,
  4839. struct link_params *params,
  4840. struct link_vars *vars,
  4841. u16 is_link_up,
  4842. u16 speed_mask,
  4843. u16 is_duplex)
  4844. {
  4845. struct bnx2x *bp = params->bp;
  4846. if (phy->req_line_speed == SPEED_AUTO_NEG)
  4847. vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_ENABLED;
  4848. if (is_link_up) {
  4849. DP(NETIF_MSG_LINK, "phy link up\n");
  4850. vars->phy_link_up = 1;
  4851. vars->link_status |= LINK_STATUS_LINK_UP;
  4852. switch (speed_mask) {
  4853. case GP_STATUS_10M:
  4854. vars->line_speed = SPEED_10;
  4855. if (is_duplex == DUPLEX_FULL)
  4856. vars->link_status |= LINK_10TFD;
  4857. else
  4858. vars->link_status |= LINK_10THD;
  4859. break;
  4860. case GP_STATUS_100M:
  4861. vars->line_speed = SPEED_100;
  4862. if (is_duplex == DUPLEX_FULL)
  4863. vars->link_status |= LINK_100TXFD;
  4864. else
  4865. vars->link_status |= LINK_100TXHD;
  4866. break;
  4867. case GP_STATUS_1G:
  4868. case GP_STATUS_1G_KX:
  4869. vars->line_speed = SPEED_1000;
  4870. if (is_duplex == DUPLEX_FULL)
  4871. vars->link_status |= LINK_1000TFD;
  4872. else
  4873. vars->link_status |= LINK_1000THD;
  4874. break;
  4875. case GP_STATUS_2_5G:
  4876. vars->line_speed = SPEED_2500;
  4877. if (is_duplex == DUPLEX_FULL)
  4878. vars->link_status |= LINK_2500TFD;
  4879. else
  4880. vars->link_status |= LINK_2500THD;
  4881. break;
  4882. case GP_STATUS_5G:
  4883. case GP_STATUS_6G:
  4884. DP(NETIF_MSG_LINK,
  4885. "link speed unsupported gp_status 0x%x\n",
  4886. speed_mask);
  4887. return -EINVAL;
  4888. case GP_STATUS_10G_KX4:
  4889. case GP_STATUS_10G_HIG:
  4890. case GP_STATUS_10G_CX4:
  4891. case GP_STATUS_10G_KR:
  4892. case GP_STATUS_10G_SFI:
  4893. case GP_STATUS_10G_XFI:
  4894. vars->line_speed = SPEED_10000;
  4895. vars->link_status |= LINK_10GTFD;
  4896. break;
  4897. case GP_STATUS_20G_DXGXS:
  4898. case GP_STATUS_20G_KR2:
  4899. vars->line_speed = SPEED_20000;
  4900. vars->link_status |= LINK_20GTFD;
  4901. break;
  4902. default:
  4903. DP(NETIF_MSG_LINK,
  4904. "link speed unsupported gp_status 0x%x\n",
  4905. speed_mask);
  4906. return -EINVAL;
  4907. }
  4908. } else { /* link_down */
  4909. DP(NETIF_MSG_LINK, "phy link down\n");
  4910. vars->phy_link_up = 0;
  4911. vars->duplex = DUPLEX_FULL;
  4912. vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  4913. vars->mac_type = MAC_TYPE_NONE;
  4914. }
  4915. DP(NETIF_MSG_LINK, " phy_link_up %x line_speed %d\n",
  4916. vars->phy_link_up, vars->line_speed);
  4917. return 0;
  4918. }
  4919. static int bnx2x_link_settings_status(struct bnx2x_phy *phy,
  4920. struct link_params *params,
  4921. struct link_vars *vars)
  4922. {
  4923. struct bnx2x *bp = params->bp;
  4924. u16 gp_status, duplex = DUPLEX_HALF, link_up = 0, speed_mask;
  4925. int rc = 0;
  4926. /* Read gp_status */
  4927. CL22_RD_OVER_CL45(bp, phy,
  4928. MDIO_REG_BANK_GP_STATUS,
  4929. MDIO_GP_STATUS_TOP_AN_STATUS1,
  4930. &gp_status);
  4931. if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_DUPLEX_STATUS)
  4932. duplex = DUPLEX_FULL;
  4933. if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS)
  4934. link_up = 1;
  4935. speed_mask = gp_status & GP_STATUS_SPEED_MASK;
  4936. DP(NETIF_MSG_LINK, "gp_status 0x%x, is_link_up %d, speed_mask 0x%x\n",
  4937. gp_status, link_up, speed_mask);
  4938. rc = bnx2x_get_link_speed_duplex(phy, params, vars, link_up, speed_mask,
  4939. duplex);
  4940. if (rc == -EINVAL)
  4941. return rc;
  4942. if (gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS) {
  4943. if (SINGLE_MEDIA_DIRECT(params)) {
  4944. vars->duplex = duplex;
  4945. bnx2x_flow_ctrl_resolve(phy, params, vars, gp_status);
  4946. if (phy->req_line_speed == SPEED_AUTO_NEG)
  4947. bnx2x_xgxs_an_resolve(phy, params, vars,
  4948. gp_status);
  4949. }
  4950. } else { /* Link_down */
  4951. if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
  4952. SINGLE_MEDIA_DIRECT(params)) {
  4953. /* Check signal is detected */
  4954. bnx2x_check_fallback_to_cl37(phy, params);
  4955. }
  4956. }
  4957. /* Read LP advertised speeds*/
  4958. if (SINGLE_MEDIA_DIRECT(params) &&
  4959. (vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE)) {
  4960. u16 val;
  4961. CL22_RD_OVER_CL45(bp, phy, MDIO_REG_BANK_CL73_IEEEB1,
  4962. MDIO_CL73_IEEEB1_AN_LP_ADV2, &val);
  4963. if (val & MDIO_CL73_IEEEB1_AN_ADV2_ADVR_1000M_KX)
  4964. vars->link_status |=
  4965. LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE;
  4966. if (val & (MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KX4 |
  4967. MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KR))
  4968. vars->link_status |=
  4969. LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
  4970. CL22_RD_OVER_CL45(bp, phy, MDIO_REG_BANK_OVER_1G,
  4971. MDIO_OVER_1G_LP_UP1, &val);
  4972. if (val & MDIO_OVER_1G_UP1_2_5G)
  4973. vars->link_status |=
  4974. LINK_STATUS_LINK_PARTNER_2500XFD_CAPABLE;
  4975. if (val & (MDIO_OVER_1G_UP1_10G | MDIO_OVER_1G_UP1_10GH))
  4976. vars->link_status |=
  4977. LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
  4978. }
  4979. DP(NETIF_MSG_LINK, "duplex %x flow_ctrl 0x%x link_status 0x%x\n",
  4980. vars->duplex, vars->flow_ctrl, vars->link_status);
  4981. return rc;
  4982. }
  4983. static int bnx2x_warpcore_read_status(struct bnx2x_phy *phy,
  4984. struct link_params *params,
  4985. struct link_vars *vars)
  4986. {
  4987. struct bnx2x *bp = params->bp;
  4988. u8 lane;
  4989. u16 gp_status1, gp_speed, link_up, duplex = DUPLEX_FULL;
  4990. int rc = 0;
  4991. lane = bnx2x_get_warpcore_lane(phy, params);
  4992. /* Read gp_status */
  4993. if ((params->loopback_mode) &&
  4994. (phy->flags & FLAGS_WC_DUAL_MODE)) {
  4995. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
  4996. MDIO_WC_REG_DIGITAL5_LINK_STATUS, &link_up);
  4997. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
  4998. MDIO_WC_REG_DIGITAL5_LINK_STATUS, &link_up);
  4999. link_up &= 0x1;
  5000. } else if ((phy->req_line_speed > SPEED_10000) &&
  5001. (phy->supported & SUPPORTED_20000baseMLD2_Full)) {
  5002. u16 temp_link_up;
  5003. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
  5004. 1, &temp_link_up);
  5005. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
  5006. 1, &link_up);
  5007. DP(NETIF_MSG_LINK, "PCS RX link status = 0x%x-->0x%x\n",
  5008. temp_link_up, link_up);
  5009. link_up &= (1<<2);
  5010. if (link_up)
  5011. bnx2x_ext_phy_resolve_fc(phy, params, vars);
  5012. } else {
  5013. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
  5014. MDIO_WC_REG_GP2_STATUS_GP_2_1,
  5015. &gp_status1);
  5016. DP(NETIF_MSG_LINK, "0x81d1 = 0x%x\n", gp_status1);
  5017. /* Check for either KR, 1G, or AN up. */
  5018. link_up = ((gp_status1 >> 8) |
  5019. (gp_status1 >> 12) |
  5020. (gp_status1)) &
  5021. (1 << lane);
  5022. if (phy->supported & SUPPORTED_20000baseKR2_Full) {
  5023. u16 an_link;
  5024. bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
  5025. MDIO_AN_REG_STATUS, &an_link);
  5026. bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
  5027. MDIO_AN_REG_STATUS, &an_link);
  5028. link_up |= (an_link & (1<<2));
  5029. }
  5030. if (link_up && SINGLE_MEDIA_DIRECT(params)) {
  5031. u16 pd, gp_status4;
  5032. if (phy->req_line_speed == SPEED_AUTO_NEG) {
  5033. /* Check Autoneg complete */
  5034. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
  5035. MDIO_WC_REG_GP2_STATUS_GP_2_4,
  5036. &gp_status4);
  5037. if (gp_status4 & ((1<<12)<<lane))
  5038. vars->link_status |=
  5039. LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
  5040. /* Check parallel detect used */
  5041. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
  5042. MDIO_WC_REG_PAR_DET_10G_STATUS,
  5043. &pd);
  5044. if (pd & (1<<15))
  5045. vars->link_status |=
  5046. LINK_STATUS_PARALLEL_DETECTION_USED;
  5047. }
  5048. bnx2x_ext_phy_resolve_fc(phy, params, vars);
  5049. vars->duplex = duplex;
  5050. }
  5051. }
  5052. if ((vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) &&
  5053. SINGLE_MEDIA_DIRECT(params)) {
  5054. u16 val;
  5055. bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
  5056. MDIO_AN_REG_LP_AUTO_NEG2, &val);
  5057. if (val & MDIO_CL73_IEEEB1_AN_ADV2_ADVR_1000M_KX)
  5058. vars->link_status |=
  5059. LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE;
  5060. if (val & (MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KX4 |
  5061. MDIO_CL73_IEEEB1_AN_ADV2_ADVR_10G_KR))
  5062. vars->link_status |=
  5063. LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
  5064. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
  5065. MDIO_WC_REG_DIGITAL3_LP_UP1, &val);
  5066. if (val & MDIO_OVER_1G_UP1_2_5G)
  5067. vars->link_status |=
  5068. LINK_STATUS_LINK_PARTNER_2500XFD_CAPABLE;
  5069. if (val & (MDIO_OVER_1G_UP1_10G | MDIO_OVER_1G_UP1_10GH))
  5070. vars->link_status |=
  5071. LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
  5072. }
  5073. if (lane < 2) {
  5074. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
  5075. MDIO_WC_REG_GP2_STATUS_GP_2_2, &gp_speed);
  5076. } else {
  5077. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
  5078. MDIO_WC_REG_GP2_STATUS_GP_2_3, &gp_speed);
  5079. }
  5080. DP(NETIF_MSG_LINK, "lane %d gp_speed 0x%x\n", lane, gp_speed);
  5081. if ((lane & 1) == 0)
  5082. gp_speed <<= 8;
  5083. gp_speed &= 0x3f00;
  5084. link_up = !!link_up;
  5085. rc = bnx2x_get_link_speed_duplex(phy, params, vars, link_up, gp_speed,
  5086. duplex);
  5087. /* In case of KR link down, start up the recovering procedure */
  5088. if ((!link_up) && (phy->media_type == ETH_PHY_KR) &&
  5089. (!(phy->flags & FLAGS_WC_DUAL_MODE)))
  5090. vars->rx_tx_asic_rst = MAX_KR_LINK_RETRY;
  5091. DP(NETIF_MSG_LINK, "duplex %x flow_ctrl 0x%x link_status 0x%x\n",
  5092. vars->duplex, vars->flow_ctrl, vars->link_status);
  5093. return rc;
  5094. }
  5095. static void bnx2x_set_gmii_tx_driver(struct link_params *params)
  5096. {
  5097. struct bnx2x *bp = params->bp;
  5098. struct bnx2x_phy *phy = &params->phy[INT_PHY];
  5099. u16 lp_up2;
  5100. u16 tx_driver;
  5101. u16 bank;
  5102. /* Read precomp */
  5103. CL22_RD_OVER_CL45(bp, phy,
  5104. MDIO_REG_BANK_OVER_1G,
  5105. MDIO_OVER_1G_LP_UP2, &lp_up2);
  5106. /* Bits [10:7] at lp_up2, positioned at [15:12] */
  5107. lp_up2 = (((lp_up2 & MDIO_OVER_1G_LP_UP2_PREEMPHASIS_MASK) >>
  5108. MDIO_OVER_1G_LP_UP2_PREEMPHASIS_SHIFT) <<
  5109. MDIO_TX0_TX_DRIVER_PREEMPHASIS_SHIFT);
  5110. if (lp_up2 == 0)
  5111. return;
  5112. for (bank = MDIO_REG_BANK_TX0; bank <= MDIO_REG_BANK_TX3;
  5113. bank += (MDIO_REG_BANK_TX1 - MDIO_REG_BANK_TX0)) {
  5114. CL22_RD_OVER_CL45(bp, phy,
  5115. bank,
  5116. MDIO_TX0_TX_DRIVER, &tx_driver);
  5117. /* Replace tx_driver bits [15:12] */
  5118. if (lp_up2 !=
  5119. (tx_driver & MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK)) {
  5120. tx_driver &= ~MDIO_TX0_TX_DRIVER_PREEMPHASIS_MASK;
  5121. tx_driver |= lp_up2;
  5122. CL22_WR_OVER_CL45(bp, phy,
  5123. bank,
  5124. MDIO_TX0_TX_DRIVER, tx_driver);
  5125. }
  5126. }
  5127. }
  5128. static int bnx2x_emac_program(struct link_params *params,
  5129. struct link_vars *vars)
  5130. {
  5131. struct bnx2x *bp = params->bp;
  5132. u8 port = params->port;
  5133. u16 mode = 0;
  5134. DP(NETIF_MSG_LINK, "setting link speed & duplex\n");
  5135. bnx2x_bits_dis(bp, GRCBASE_EMAC0 + port*0x400 +
  5136. EMAC_REG_EMAC_MODE,
  5137. (EMAC_MODE_25G_MODE |
  5138. EMAC_MODE_PORT_MII_10M |
  5139. EMAC_MODE_HALF_DUPLEX));
  5140. switch (vars->line_speed) {
  5141. case SPEED_10:
  5142. mode |= EMAC_MODE_PORT_MII_10M;
  5143. break;
  5144. case SPEED_100:
  5145. mode |= EMAC_MODE_PORT_MII;
  5146. break;
  5147. case SPEED_1000:
  5148. mode |= EMAC_MODE_PORT_GMII;
  5149. break;
  5150. case SPEED_2500:
  5151. mode |= (EMAC_MODE_25G_MODE | EMAC_MODE_PORT_GMII);
  5152. break;
  5153. default:
  5154. /* 10G not valid for EMAC */
  5155. DP(NETIF_MSG_LINK, "Invalid line_speed 0x%x\n",
  5156. vars->line_speed);
  5157. return -EINVAL;
  5158. }
  5159. if (vars->duplex == DUPLEX_HALF)
  5160. mode |= EMAC_MODE_HALF_DUPLEX;
  5161. bnx2x_bits_en(bp,
  5162. GRCBASE_EMAC0 + port*0x400 + EMAC_REG_EMAC_MODE,
  5163. mode);
  5164. bnx2x_set_led(params, vars, LED_MODE_OPER, vars->line_speed);
  5165. return 0;
  5166. }
  5167. static void bnx2x_set_preemphasis(struct bnx2x_phy *phy,
  5168. struct link_params *params)
  5169. {
  5170. u16 bank, i = 0;
  5171. struct bnx2x *bp = params->bp;
  5172. for (bank = MDIO_REG_BANK_RX0, i = 0; bank <= MDIO_REG_BANK_RX3;
  5173. bank += (MDIO_REG_BANK_RX1-MDIO_REG_BANK_RX0), i++) {
  5174. CL22_WR_OVER_CL45(bp, phy,
  5175. bank,
  5176. MDIO_RX0_RX_EQ_BOOST,
  5177. phy->rx_preemphasis[i]);
  5178. }
  5179. for (bank = MDIO_REG_BANK_TX0, i = 0; bank <= MDIO_REG_BANK_TX3;
  5180. bank += (MDIO_REG_BANK_TX1 - MDIO_REG_BANK_TX0), i++) {
  5181. CL22_WR_OVER_CL45(bp, phy,
  5182. bank,
  5183. MDIO_TX0_TX_DRIVER,
  5184. phy->tx_preemphasis[i]);
  5185. }
  5186. }
  5187. static void bnx2x_xgxs_config_init(struct bnx2x_phy *phy,
  5188. struct link_params *params,
  5189. struct link_vars *vars)
  5190. {
  5191. struct bnx2x *bp = params->bp;
  5192. u8 enable_cl73 = (SINGLE_MEDIA_DIRECT(params) ||
  5193. (params->loopback_mode == LOOPBACK_XGXS));
  5194. if (!(vars->phy_flags & PHY_SGMII_FLAG)) {
  5195. if (SINGLE_MEDIA_DIRECT(params) &&
  5196. (params->feature_config_flags &
  5197. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED))
  5198. bnx2x_set_preemphasis(phy, params);
  5199. /* Forced speed requested? */
  5200. if (vars->line_speed != SPEED_AUTO_NEG ||
  5201. (SINGLE_MEDIA_DIRECT(params) &&
  5202. params->loopback_mode == LOOPBACK_EXT)) {
  5203. DP(NETIF_MSG_LINK, "not SGMII, no AN\n");
  5204. /* Disable autoneg */
  5205. bnx2x_set_autoneg(phy, params, vars, 0);
  5206. /* Program speed and duplex */
  5207. bnx2x_program_serdes(phy, params, vars);
  5208. } else { /* AN_mode */
  5209. DP(NETIF_MSG_LINK, "not SGMII, AN\n");
  5210. /* AN enabled */
  5211. bnx2x_set_brcm_cl37_advertisement(phy, params);
  5212. /* Program duplex & pause advertisement (for aneg) */
  5213. bnx2x_set_ieee_aneg_advertisement(phy, params,
  5214. vars->ieee_fc);
  5215. /* Enable autoneg */
  5216. bnx2x_set_autoneg(phy, params, vars, enable_cl73);
  5217. /* Enable and restart AN */
  5218. bnx2x_restart_autoneg(phy, params, enable_cl73);
  5219. }
  5220. } else { /* SGMII mode */
  5221. DP(NETIF_MSG_LINK, "SGMII\n");
  5222. bnx2x_initialize_sgmii_process(phy, params, vars);
  5223. }
  5224. }
  5225. static int bnx2x_prepare_xgxs(struct bnx2x_phy *phy,
  5226. struct link_params *params,
  5227. struct link_vars *vars)
  5228. {
  5229. int rc;
  5230. vars->phy_flags |= PHY_XGXS_FLAG;
  5231. if ((phy->req_line_speed &&
  5232. ((phy->req_line_speed == SPEED_100) ||
  5233. (phy->req_line_speed == SPEED_10))) ||
  5234. (!phy->req_line_speed &&
  5235. (phy->speed_cap_mask >=
  5236. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL) &&
  5237. (phy->speed_cap_mask <
  5238. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
  5239. (phy->type == PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT_SD))
  5240. vars->phy_flags |= PHY_SGMII_FLAG;
  5241. else
  5242. vars->phy_flags &= ~PHY_SGMII_FLAG;
  5243. bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
  5244. bnx2x_set_aer_mmd(params, phy);
  5245. if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  5246. bnx2x_set_master_ln(params, phy);
  5247. rc = bnx2x_reset_unicore(params, phy, 0);
  5248. /* Reset the SerDes and wait for reset bit return low */
  5249. if (rc)
  5250. return rc;
  5251. bnx2x_set_aer_mmd(params, phy);
  5252. /* Setting the masterLn_def again after the reset */
  5253. if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) {
  5254. bnx2x_set_master_ln(params, phy);
  5255. bnx2x_set_swap_lanes(params, phy);
  5256. }
  5257. return rc;
  5258. }
  5259. static u16 bnx2x_wait_reset_complete(struct bnx2x *bp,
  5260. struct bnx2x_phy *phy,
  5261. struct link_params *params)
  5262. {
  5263. u16 cnt, ctrl;
  5264. /* Wait for soft reset to get cleared up to 1 sec */
  5265. for (cnt = 0; cnt < 1000; cnt++) {
  5266. if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE)
  5267. bnx2x_cl22_read(bp, phy,
  5268. MDIO_PMA_REG_CTRL, &ctrl);
  5269. else
  5270. bnx2x_cl45_read(bp, phy,
  5271. MDIO_PMA_DEVAD,
  5272. MDIO_PMA_REG_CTRL, &ctrl);
  5273. if (!(ctrl & (1<<15)))
  5274. break;
  5275. usleep_range(1000, 2000);
  5276. }
  5277. if (cnt == 1000)
  5278. netdev_err(bp->dev, "Warning: PHY was not initialized,"
  5279. " Port %d\n",
  5280. params->port);
  5281. DP(NETIF_MSG_LINK, "control reg 0x%x (after %d ms)\n", ctrl, cnt);
  5282. return cnt;
  5283. }
  5284. static void bnx2x_link_int_enable(struct link_params *params)
  5285. {
  5286. u8 port = params->port;
  5287. u32 mask;
  5288. struct bnx2x *bp = params->bp;
  5289. /* Setting the status to report on link up for either XGXS or SerDes */
  5290. if (CHIP_IS_E3(bp)) {
  5291. mask = NIG_MASK_XGXS0_LINK_STATUS;
  5292. if (!(SINGLE_MEDIA_DIRECT(params)))
  5293. mask |= NIG_MASK_MI_INT;
  5294. } else if (params->switch_cfg == SWITCH_CFG_10G) {
  5295. mask = (NIG_MASK_XGXS0_LINK10G |
  5296. NIG_MASK_XGXS0_LINK_STATUS);
  5297. DP(NETIF_MSG_LINK, "enabled XGXS interrupt\n");
  5298. if (!(SINGLE_MEDIA_DIRECT(params)) &&
  5299. params->phy[INT_PHY].type !=
  5300. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) {
  5301. mask |= NIG_MASK_MI_INT;
  5302. DP(NETIF_MSG_LINK, "enabled external phy int\n");
  5303. }
  5304. } else { /* SerDes */
  5305. mask = NIG_MASK_SERDES0_LINK_STATUS;
  5306. DP(NETIF_MSG_LINK, "enabled SerDes interrupt\n");
  5307. if (!(SINGLE_MEDIA_DIRECT(params)) &&
  5308. params->phy[INT_PHY].type !=
  5309. PORT_HW_CFG_SERDES_EXT_PHY_TYPE_NOT_CONN) {
  5310. mask |= NIG_MASK_MI_INT;
  5311. DP(NETIF_MSG_LINK, "enabled external phy int\n");
  5312. }
  5313. }
  5314. bnx2x_bits_en(bp,
  5315. NIG_REG_MASK_INTERRUPT_PORT0 + port*4,
  5316. mask);
  5317. DP(NETIF_MSG_LINK, "port %x, is_xgxs %x, int_status 0x%x\n", port,
  5318. (params->switch_cfg == SWITCH_CFG_10G),
  5319. REG_RD(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4));
  5320. DP(NETIF_MSG_LINK, " int_mask 0x%x, MI_INT %x, SERDES_LINK %x\n",
  5321. REG_RD(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4),
  5322. REG_RD(bp, NIG_REG_EMAC0_STATUS_MISC_MI_INT + port*0x18),
  5323. REG_RD(bp, NIG_REG_SERDES0_STATUS_LINK_STATUS+port*0x3c));
  5324. DP(NETIF_MSG_LINK, " 10G %x, XGXS_LINK %x\n",
  5325. REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK10G + port*0x68),
  5326. REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK_STATUS + port*0x68));
  5327. }
  5328. static void bnx2x_rearm_latch_signal(struct bnx2x *bp, u8 port,
  5329. u8 exp_mi_int)
  5330. {
  5331. u32 latch_status = 0;
  5332. /* Disable the MI INT ( external phy int ) by writing 1 to the
  5333. * status register. Link down indication is high-active-signal,
  5334. * so in this case we need to write the status to clear the XOR
  5335. */
  5336. /* Read Latched signals */
  5337. latch_status = REG_RD(bp,
  5338. NIG_REG_LATCH_STATUS_0 + port*8);
  5339. DP(NETIF_MSG_LINK, "latch_status = 0x%x\n", latch_status);
  5340. /* Handle only those with latched-signal=up.*/
  5341. if (exp_mi_int)
  5342. bnx2x_bits_en(bp,
  5343. NIG_REG_STATUS_INTERRUPT_PORT0
  5344. + port*4,
  5345. NIG_STATUS_EMAC0_MI_INT);
  5346. else
  5347. bnx2x_bits_dis(bp,
  5348. NIG_REG_STATUS_INTERRUPT_PORT0
  5349. + port*4,
  5350. NIG_STATUS_EMAC0_MI_INT);
  5351. if (latch_status & 1) {
  5352. /* For all latched-signal=up : Re-Arm Latch signals */
  5353. REG_WR(bp, NIG_REG_LATCH_STATUS_0 + port*8,
  5354. (latch_status & 0xfffe) | (latch_status & 1));
  5355. }
  5356. /* For all latched-signal=up,Write original_signal to status */
  5357. }
  5358. static void bnx2x_link_int_ack(struct link_params *params,
  5359. struct link_vars *vars, u8 is_10g_plus)
  5360. {
  5361. struct bnx2x *bp = params->bp;
  5362. u8 port = params->port;
  5363. u32 mask;
  5364. /* First reset all status we assume only one line will be
  5365. * change at a time
  5366. */
  5367. bnx2x_bits_dis(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
  5368. (NIG_STATUS_XGXS0_LINK10G |
  5369. NIG_STATUS_XGXS0_LINK_STATUS |
  5370. NIG_STATUS_SERDES0_LINK_STATUS));
  5371. if (vars->phy_link_up) {
  5372. if (USES_WARPCORE(bp))
  5373. mask = NIG_STATUS_XGXS0_LINK_STATUS;
  5374. else {
  5375. if (is_10g_plus)
  5376. mask = NIG_STATUS_XGXS0_LINK10G;
  5377. else if (params->switch_cfg == SWITCH_CFG_10G) {
  5378. /* Disable the link interrupt by writing 1 to
  5379. * the relevant lane in the status register
  5380. */
  5381. u32 ser_lane =
  5382. ((params->lane_config &
  5383. PORT_HW_CFG_LANE_SWAP_CFG_MASTER_MASK) >>
  5384. PORT_HW_CFG_LANE_SWAP_CFG_MASTER_SHIFT);
  5385. mask = ((1 << ser_lane) <<
  5386. NIG_STATUS_XGXS0_LINK_STATUS_SIZE);
  5387. } else
  5388. mask = NIG_STATUS_SERDES0_LINK_STATUS;
  5389. }
  5390. DP(NETIF_MSG_LINK, "Ack link up interrupt with mask 0x%x\n",
  5391. mask);
  5392. bnx2x_bits_en(bp,
  5393. NIG_REG_STATUS_INTERRUPT_PORT0 + port*4,
  5394. mask);
  5395. }
  5396. }
  5397. static int bnx2x_format_ver(u32 num, u8 *str, u16 *len)
  5398. {
  5399. u8 *str_ptr = str;
  5400. u32 mask = 0xf0000000;
  5401. u8 shift = 8*4;
  5402. u8 digit;
  5403. u8 remove_leading_zeros = 1;
  5404. if (*len < 10) {
  5405. /* Need more than 10chars for this format */
  5406. *str_ptr = '\0';
  5407. (*len)--;
  5408. return -EINVAL;
  5409. }
  5410. while (shift > 0) {
  5411. shift -= 4;
  5412. digit = ((num & mask) >> shift);
  5413. if (digit == 0 && remove_leading_zeros) {
  5414. *str_ptr = '0';
  5415. } else {
  5416. if (digit < 0xa)
  5417. *str_ptr = digit + '0';
  5418. else
  5419. *str_ptr = digit - 0xa + 'a';
  5420. remove_leading_zeros = 0;
  5421. str_ptr++;
  5422. (*len)--;
  5423. }
  5424. mask = mask >> 4;
  5425. if (shift == 4*4) {
  5426. if (remove_leading_zeros) {
  5427. str_ptr++;
  5428. (*len)--;
  5429. }
  5430. *str_ptr = '.';
  5431. str_ptr++;
  5432. (*len)--;
  5433. remove_leading_zeros = 1;
  5434. }
  5435. }
  5436. if (remove_leading_zeros)
  5437. (*len)--;
  5438. return 0;
  5439. }
  5440. static int bnx2x_3_seq_format_ver(u32 num, u8 *str, u16 *len)
  5441. {
  5442. u8 *str_ptr = str;
  5443. u32 mask = 0x00f00000;
  5444. u8 shift = 8*3;
  5445. u8 digit;
  5446. u8 remove_leading_zeros = 1;
  5447. if (*len < 10) {
  5448. /* Need more than 10chars for this format */
  5449. *str_ptr = '\0';
  5450. (*len)--;
  5451. return -EINVAL;
  5452. }
  5453. while (shift > 0) {
  5454. shift -= 4;
  5455. digit = ((num & mask) >> shift);
  5456. if (digit == 0 && remove_leading_zeros) {
  5457. *str_ptr = '0';
  5458. } else {
  5459. if (digit < 0xa)
  5460. *str_ptr = digit + '0';
  5461. else
  5462. *str_ptr = digit - 0xa + 'a';
  5463. remove_leading_zeros = 0;
  5464. str_ptr++;
  5465. (*len)--;
  5466. }
  5467. mask = mask >> 4;
  5468. if ((shift == 4*4) || (shift == 4*2)) {
  5469. if (remove_leading_zeros) {
  5470. str_ptr++;
  5471. (*len)--;
  5472. }
  5473. *str_ptr = '.';
  5474. str_ptr++;
  5475. (*len)--;
  5476. remove_leading_zeros = 1;
  5477. }
  5478. }
  5479. if (remove_leading_zeros)
  5480. (*len)--;
  5481. return 0;
  5482. }
  5483. static int bnx2x_null_format_ver(u32 spirom_ver, u8 *str, u16 *len)
  5484. {
  5485. str[0] = '\0';
  5486. (*len)--;
  5487. return 0;
  5488. }
  5489. int bnx2x_get_ext_phy_fw_version(struct link_params *params, u8 *version,
  5490. u16 len)
  5491. {
  5492. struct bnx2x *bp;
  5493. u32 spirom_ver = 0;
  5494. int status = 0;
  5495. u8 *ver_p = version;
  5496. u16 remain_len = len;
  5497. if (version == NULL || params == NULL)
  5498. return -EINVAL;
  5499. bp = params->bp;
  5500. /* Extract first external phy*/
  5501. version[0] = '\0';
  5502. spirom_ver = REG_RD(bp, params->phy[EXT_PHY1].ver_addr);
  5503. if (params->phy[EXT_PHY1].format_fw_ver) {
  5504. status |= params->phy[EXT_PHY1].format_fw_ver(spirom_ver,
  5505. ver_p,
  5506. &remain_len);
  5507. ver_p += (len - remain_len);
  5508. }
  5509. if ((params->num_phys == MAX_PHYS) &&
  5510. (params->phy[EXT_PHY2].ver_addr != 0)) {
  5511. spirom_ver = REG_RD(bp, params->phy[EXT_PHY2].ver_addr);
  5512. if (params->phy[EXT_PHY2].format_fw_ver) {
  5513. *ver_p = '/';
  5514. ver_p++;
  5515. remain_len--;
  5516. status |= params->phy[EXT_PHY2].format_fw_ver(
  5517. spirom_ver,
  5518. ver_p,
  5519. &remain_len);
  5520. ver_p = version + (len - remain_len);
  5521. }
  5522. }
  5523. *ver_p = '\0';
  5524. return status;
  5525. }
  5526. static void bnx2x_set_xgxs_loopback(struct bnx2x_phy *phy,
  5527. struct link_params *params)
  5528. {
  5529. u8 port = params->port;
  5530. struct bnx2x *bp = params->bp;
  5531. if (phy->req_line_speed != SPEED_1000) {
  5532. u32 md_devad = 0;
  5533. DP(NETIF_MSG_LINK, "XGXS 10G loopback enable\n");
  5534. if (!CHIP_IS_E3(bp)) {
  5535. /* Change the uni_phy_addr in the nig */
  5536. md_devad = REG_RD(bp, (NIG_REG_XGXS0_CTRL_MD_DEVAD +
  5537. port*0x18));
  5538. REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18,
  5539. 0x5);
  5540. }
  5541. bnx2x_cl45_write(bp, phy,
  5542. 5,
  5543. (MDIO_REG_BANK_AER_BLOCK +
  5544. (MDIO_AER_BLOCK_AER_REG & 0xf)),
  5545. 0x2800);
  5546. bnx2x_cl45_write(bp, phy,
  5547. 5,
  5548. (MDIO_REG_BANK_CL73_IEEEB0 +
  5549. (MDIO_CL73_IEEEB0_CL73_AN_CONTROL & 0xf)),
  5550. 0x6041);
  5551. msleep(200);
  5552. /* Set aer mmd back */
  5553. bnx2x_set_aer_mmd(params, phy);
  5554. if (!CHIP_IS_E3(bp)) {
  5555. /* And md_devad */
  5556. REG_WR(bp, NIG_REG_XGXS0_CTRL_MD_DEVAD + port*0x18,
  5557. md_devad);
  5558. }
  5559. } else {
  5560. u16 mii_ctrl;
  5561. DP(NETIF_MSG_LINK, "XGXS 1G loopback enable\n");
  5562. bnx2x_cl45_read(bp, phy, 5,
  5563. (MDIO_REG_BANK_COMBO_IEEE0 +
  5564. (MDIO_COMBO_IEEE0_MII_CONTROL & 0xf)),
  5565. &mii_ctrl);
  5566. bnx2x_cl45_write(bp, phy, 5,
  5567. (MDIO_REG_BANK_COMBO_IEEE0 +
  5568. (MDIO_COMBO_IEEE0_MII_CONTROL & 0xf)),
  5569. mii_ctrl |
  5570. MDIO_COMBO_IEEO_MII_CONTROL_LOOPBACK);
  5571. }
  5572. }
  5573. int bnx2x_set_led(struct link_params *params,
  5574. struct link_vars *vars, u8 mode, u32 speed)
  5575. {
  5576. u8 port = params->port;
  5577. u16 hw_led_mode = params->hw_led_mode;
  5578. int rc = 0;
  5579. u8 phy_idx;
  5580. u32 tmp;
  5581. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  5582. struct bnx2x *bp = params->bp;
  5583. DP(NETIF_MSG_LINK, "bnx2x_set_led: port %x, mode %d\n", port, mode);
  5584. DP(NETIF_MSG_LINK, "speed 0x%x, hw_led_mode 0x%x\n",
  5585. speed, hw_led_mode);
  5586. /* In case */
  5587. for (phy_idx = EXT_PHY1; phy_idx < MAX_PHYS; phy_idx++) {
  5588. if (params->phy[phy_idx].set_link_led) {
  5589. params->phy[phy_idx].set_link_led(
  5590. &params->phy[phy_idx], params, mode);
  5591. }
  5592. }
  5593. switch (mode) {
  5594. case LED_MODE_FRONT_PANEL_OFF:
  5595. case LED_MODE_OFF:
  5596. REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 0);
  5597. REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4,
  5598. SHARED_HW_CFG_LED_MAC1);
  5599. tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
  5600. if (params->phy[EXT_PHY1].type ==
  5601. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE)
  5602. tmp &= ~(EMAC_LED_1000MB_OVERRIDE |
  5603. EMAC_LED_100MB_OVERRIDE |
  5604. EMAC_LED_10MB_OVERRIDE);
  5605. else
  5606. tmp |= EMAC_LED_OVERRIDE;
  5607. EMAC_WR(bp, EMAC_REG_EMAC_LED, tmp);
  5608. break;
  5609. case LED_MODE_OPER:
  5610. /* For all other phys, OPER mode is same as ON, so in case
  5611. * link is down, do nothing
  5612. */
  5613. if (!vars->link_up)
  5614. break;
  5615. case LED_MODE_ON:
  5616. if (((params->phy[EXT_PHY1].type ==
  5617. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727) ||
  5618. (params->phy[EXT_PHY1].type ==
  5619. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722)) &&
  5620. CHIP_IS_E2(bp) && params->num_phys == 2) {
  5621. /* This is a work-around for E2+8727 Configurations */
  5622. if (mode == LED_MODE_ON ||
  5623. speed == SPEED_10000){
  5624. REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
  5625. REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 1);
  5626. tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
  5627. EMAC_WR(bp, EMAC_REG_EMAC_LED,
  5628. (tmp | EMAC_LED_OVERRIDE));
  5629. /* Return here without enabling traffic
  5630. * LED blink and setting rate in ON mode.
  5631. * In oper mode, enabling LED blink
  5632. * and setting rate is needed.
  5633. */
  5634. if (mode == LED_MODE_ON)
  5635. return rc;
  5636. }
  5637. } else if (SINGLE_MEDIA_DIRECT(params)) {
  5638. /* This is a work-around for HW issue found when link
  5639. * is up in CL73
  5640. */
  5641. if ((!CHIP_IS_E3(bp)) ||
  5642. (CHIP_IS_E3(bp) &&
  5643. mode == LED_MODE_ON))
  5644. REG_WR(bp, NIG_REG_LED_10G_P0 + port*4, 1);
  5645. if (CHIP_IS_E1x(bp) ||
  5646. CHIP_IS_E2(bp) ||
  5647. (mode == LED_MODE_ON))
  5648. REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
  5649. else
  5650. REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4,
  5651. hw_led_mode);
  5652. } else if ((params->phy[EXT_PHY1].type ==
  5653. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE) &&
  5654. (mode == LED_MODE_ON)) {
  5655. REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4, 0);
  5656. tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
  5657. EMAC_WR(bp, EMAC_REG_EMAC_LED, tmp |
  5658. EMAC_LED_OVERRIDE | EMAC_LED_1000MB_OVERRIDE);
  5659. /* Break here; otherwise, it'll disable the
  5660. * intended override.
  5661. */
  5662. break;
  5663. } else {
  5664. u32 nig_led_mode = ((params->hw_led_mode <<
  5665. SHARED_HW_CFG_LED_MODE_SHIFT) ==
  5666. SHARED_HW_CFG_LED_EXTPHY2) ?
  5667. (SHARED_HW_CFG_LED_PHY1 >>
  5668. SHARED_HW_CFG_LED_MODE_SHIFT) : hw_led_mode;
  5669. REG_WR(bp, NIG_REG_LED_MODE_P0 + port*4,
  5670. nig_led_mode);
  5671. }
  5672. REG_WR(bp, NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0 + port*4, 0);
  5673. /* Set blinking rate to ~15.9Hz */
  5674. if (CHIP_IS_E3(bp))
  5675. REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_P0 + port*4,
  5676. LED_BLINK_RATE_VAL_E3);
  5677. else
  5678. REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_P0 + port*4,
  5679. LED_BLINK_RATE_VAL_E1X_E2);
  5680. REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_RATE_ENA_P0 +
  5681. port*4, 1);
  5682. tmp = EMAC_RD(bp, EMAC_REG_EMAC_LED);
  5683. EMAC_WR(bp, EMAC_REG_EMAC_LED,
  5684. (tmp & (~EMAC_LED_OVERRIDE)));
  5685. if (CHIP_IS_E1(bp) &&
  5686. ((speed == SPEED_2500) ||
  5687. (speed == SPEED_1000) ||
  5688. (speed == SPEED_100) ||
  5689. (speed == SPEED_10))) {
  5690. /* For speeds less than 10G LED scheme is different */
  5691. REG_WR(bp, NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0
  5692. + port*4, 1);
  5693. REG_WR(bp, NIG_REG_LED_CONTROL_TRAFFIC_P0 +
  5694. port*4, 0);
  5695. REG_WR(bp, NIG_REG_LED_CONTROL_BLINK_TRAFFIC_P0 +
  5696. port*4, 1);
  5697. }
  5698. break;
  5699. default:
  5700. rc = -EINVAL;
  5701. DP(NETIF_MSG_LINK, "bnx2x_set_led: Invalid led mode %d\n",
  5702. mode);
  5703. break;
  5704. }
  5705. return rc;
  5706. }
  5707. /* This function comes to reflect the actual link state read DIRECTLY from the
  5708. * HW
  5709. */
  5710. int bnx2x_test_link(struct link_params *params, struct link_vars *vars,
  5711. u8 is_serdes)
  5712. {
  5713. struct bnx2x *bp = params->bp;
  5714. u16 gp_status = 0, phy_index = 0;
  5715. u8 ext_phy_link_up = 0, serdes_phy_type;
  5716. struct link_vars temp_vars;
  5717. struct bnx2x_phy *int_phy = &params->phy[INT_PHY];
  5718. if (CHIP_IS_E3(bp)) {
  5719. u16 link_up;
  5720. if (params->req_line_speed[LINK_CONFIG_IDX(INT_PHY)]
  5721. > SPEED_10000) {
  5722. /* Check 20G link */
  5723. bnx2x_cl45_read(bp, int_phy, MDIO_WC_DEVAD,
  5724. 1, &link_up);
  5725. bnx2x_cl45_read(bp, int_phy, MDIO_WC_DEVAD,
  5726. 1, &link_up);
  5727. link_up &= (1<<2);
  5728. } else {
  5729. /* Check 10G link and below*/
  5730. u8 lane = bnx2x_get_warpcore_lane(int_phy, params);
  5731. bnx2x_cl45_read(bp, int_phy, MDIO_WC_DEVAD,
  5732. MDIO_WC_REG_GP2_STATUS_GP_2_1,
  5733. &gp_status);
  5734. gp_status = ((gp_status >> 8) & 0xf) |
  5735. ((gp_status >> 12) & 0xf);
  5736. link_up = gp_status & (1 << lane);
  5737. }
  5738. if (!link_up)
  5739. return -ESRCH;
  5740. } else {
  5741. CL22_RD_OVER_CL45(bp, int_phy,
  5742. MDIO_REG_BANK_GP_STATUS,
  5743. MDIO_GP_STATUS_TOP_AN_STATUS1,
  5744. &gp_status);
  5745. /* Link is up only if both local phy and external phy are up */
  5746. if (!(gp_status & MDIO_GP_STATUS_TOP_AN_STATUS1_LINK_STATUS))
  5747. return -ESRCH;
  5748. }
  5749. /* In XGXS loopback mode, do not check external PHY */
  5750. if (params->loopback_mode == LOOPBACK_XGXS)
  5751. return 0;
  5752. switch (params->num_phys) {
  5753. case 1:
  5754. /* No external PHY */
  5755. return 0;
  5756. case 2:
  5757. ext_phy_link_up = params->phy[EXT_PHY1].read_status(
  5758. &params->phy[EXT_PHY1],
  5759. params, &temp_vars);
  5760. break;
  5761. case 3: /* Dual Media */
  5762. for (phy_index = EXT_PHY1; phy_index < params->num_phys;
  5763. phy_index++) {
  5764. serdes_phy_type = ((params->phy[phy_index].media_type ==
  5765. ETH_PHY_SFPP_10G_FIBER) ||
  5766. (params->phy[phy_index].media_type ==
  5767. ETH_PHY_SFP_1G_FIBER) ||
  5768. (params->phy[phy_index].media_type ==
  5769. ETH_PHY_XFP_FIBER) ||
  5770. (params->phy[phy_index].media_type ==
  5771. ETH_PHY_DA_TWINAX));
  5772. if (is_serdes != serdes_phy_type)
  5773. continue;
  5774. if (params->phy[phy_index].read_status) {
  5775. ext_phy_link_up |=
  5776. params->phy[phy_index].read_status(
  5777. &params->phy[phy_index],
  5778. params, &temp_vars);
  5779. }
  5780. }
  5781. break;
  5782. }
  5783. if (ext_phy_link_up)
  5784. return 0;
  5785. return -ESRCH;
  5786. }
  5787. static int bnx2x_link_initialize(struct link_params *params,
  5788. struct link_vars *vars)
  5789. {
  5790. u8 phy_index, non_ext_phy;
  5791. struct bnx2x *bp = params->bp;
  5792. /* In case of external phy existence, the line speed would be the
  5793. * line speed linked up by the external phy. In case it is direct
  5794. * only, then the line_speed during initialization will be
  5795. * equal to the req_line_speed
  5796. */
  5797. vars->line_speed = params->phy[INT_PHY].req_line_speed;
  5798. /* Initialize the internal phy in case this is a direct board
  5799. * (no external phys), or this board has external phy which requires
  5800. * to first.
  5801. */
  5802. if (!USES_WARPCORE(bp))
  5803. bnx2x_prepare_xgxs(&params->phy[INT_PHY], params, vars);
  5804. /* init ext phy and enable link state int */
  5805. non_ext_phy = (SINGLE_MEDIA_DIRECT(params) ||
  5806. (params->loopback_mode == LOOPBACK_XGXS));
  5807. if (non_ext_phy ||
  5808. (params->phy[EXT_PHY1].flags & FLAGS_INIT_XGXS_FIRST) ||
  5809. (params->loopback_mode == LOOPBACK_EXT_PHY)) {
  5810. struct bnx2x_phy *phy = &params->phy[INT_PHY];
  5811. if (vars->line_speed == SPEED_AUTO_NEG &&
  5812. (CHIP_IS_E1x(bp) ||
  5813. CHIP_IS_E2(bp)))
  5814. bnx2x_set_parallel_detection(phy, params);
  5815. if (params->phy[INT_PHY].config_init)
  5816. params->phy[INT_PHY].config_init(phy, params, vars);
  5817. }
  5818. /* Re-read this value in case it was changed inside config_init due to
  5819. * limitations of optic module
  5820. */
  5821. vars->line_speed = params->phy[INT_PHY].req_line_speed;
  5822. /* Init external phy*/
  5823. if (non_ext_phy) {
  5824. if (params->phy[INT_PHY].supported &
  5825. SUPPORTED_FIBRE)
  5826. vars->link_status |= LINK_STATUS_SERDES_LINK;
  5827. } else {
  5828. for (phy_index = EXT_PHY1; phy_index < params->num_phys;
  5829. phy_index++) {
  5830. /* No need to initialize second phy in case of first
  5831. * phy only selection. In case of second phy, we do
  5832. * need to initialize the first phy, since they are
  5833. * connected.
  5834. */
  5835. if (params->phy[phy_index].supported &
  5836. SUPPORTED_FIBRE)
  5837. vars->link_status |= LINK_STATUS_SERDES_LINK;
  5838. if (phy_index == EXT_PHY2 &&
  5839. (bnx2x_phy_selection(params) ==
  5840. PORT_HW_CFG_PHY_SELECTION_FIRST_PHY)) {
  5841. DP(NETIF_MSG_LINK,
  5842. "Not initializing second phy\n");
  5843. continue;
  5844. }
  5845. params->phy[phy_index].config_init(
  5846. &params->phy[phy_index],
  5847. params, vars);
  5848. }
  5849. }
  5850. /* Reset the interrupt indication after phy was initialized */
  5851. bnx2x_bits_dis(bp, NIG_REG_STATUS_INTERRUPT_PORT0 +
  5852. params->port*4,
  5853. (NIG_STATUS_XGXS0_LINK10G |
  5854. NIG_STATUS_XGXS0_LINK_STATUS |
  5855. NIG_STATUS_SERDES0_LINK_STATUS |
  5856. NIG_MASK_MI_INT));
  5857. return 0;
  5858. }
  5859. static void bnx2x_int_link_reset(struct bnx2x_phy *phy,
  5860. struct link_params *params)
  5861. {
  5862. /* Reset the SerDes/XGXS */
  5863. REG_WR(params->bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_3_CLEAR,
  5864. (0x1ff << (params->port*16)));
  5865. }
  5866. static void bnx2x_common_ext_link_reset(struct bnx2x_phy *phy,
  5867. struct link_params *params)
  5868. {
  5869. struct bnx2x *bp = params->bp;
  5870. u8 gpio_port;
  5871. /* HW reset */
  5872. if (CHIP_IS_E2(bp))
  5873. gpio_port = BP_PATH(bp);
  5874. else
  5875. gpio_port = params->port;
  5876. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
  5877. MISC_REGISTERS_GPIO_OUTPUT_LOW,
  5878. gpio_port);
  5879. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
  5880. MISC_REGISTERS_GPIO_OUTPUT_LOW,
  5881. gpio_port);
  5882. DP(NETIF_MSG_LINK, "reset external PHY\n");
  5883. }
  5884. static int bnx2x_update_link_down(struct link_params *params,
  5885. struct link_vars *vars)
  5886. {
  5887. struct bnx2x *bp = params->bp;
  5888. u8 port = params->port;
  5889. DP(NETIF_MSG_LINK, "Port %x: Link is down\n", port);
  5890. bnx2x_set_led(params, vars, LED_MODE_OFF, 0);
  5891. vars->phy_flags &= ~PHY_PHYSICAL_LINK_FLAG;
  5892. /* Indicate no mac active */
  5893. vars->mac_type = MAC_TYPE_NONE;
  5894. /* Update shared memory */
  5895. vars->link_status &= ~LINK_UPDATE_MASK;
  5896. vars->line_speed = 0;
  5897. bnx2x_update_mng(params, vars->link_status);
  5898. /* Activate nig drain */
  5899. REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 1);
  5900. /* Disable emac */
  5901. if (!CHIP_IS_E3(bp))
  5902. REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
  5903. usleep_range(10000, 20000);
  5904. /* Reset BigMac/Xmac */
  5905. if (CHIP_IS_E1x(bp) ||
  5906. CHIP_IS_E2(bp))
  5907. bnx2x_set_bmac_rx(bp, params->chip_id, params->port, 0);
  5908. if (CHIP_IS_E3(bp)) {
  5909. /* Prevent LPI Generation by chip */
  5910. REG_WR(bp, MISC_REG_CPMU_LP_FW_ENABLE_P0 + (params->port << 2),
  5911. 0);
  5912. REG_WR(bp, MISC_REG_CPMU_LP_MASK_ENT_P0 + (params->port << 2),
  5913. 0);
  5914. vars->eee_status &= ~(SHMEM_EEE_LP_ADV_STATUS_MASK |
  5915. SHMEM_EEE_ACTIVE_BIT);
  5916. bnx2x_update_mng_eee(params, vars->eee_status);
  5917. bnx2x_set_xmac_rxtx(params, 0);
  5918. bnx2x_set_umac_rxtx(params, 0);
  5919. }
  5920. return 0;
  5921. }
  5922. static int bnx2x_update_link_up(struct link_params *params,
  5923. struct link_vars *vars,
  5924. u8 link_10g)
  5925. {
  5926. struct bnx2x *bp = params->bp;
  5927. u8 phy_idx, port = params->port;
  5928. int rc = 0;
  5929. vars->link_status |= (LINK_STATUS_LINK_UP |
  5930. LINK_STATUS_PHYSICAL_LINK_FLAG);
  5931. vars->phy_flags |= PHY_PHYSICAL_LINK_FLAG;
  5932. if (vars->flow_ctrl & BNX2X_FLOW_CTRL_TX)
  5933. vars->link_status |=
  5934. LINK_STATUS_TX_FLOW_CONTROL_ENABLED;
  5935. if (vars->flow_ctrl & BNX2X_FLOW_CTRL_RX)
  5936. vars->link_status |=
  5937. LINK_STATUS_RX_FLOW_CONTROL_ENABLED;
  5938. if (USES_WARPCORE(bp)) {
  5939. if (link_10g) {
  5940. if (bnx2x_xmac_enable(params, vars, 0) ==
  5941. -ESRCH) {
  5942. DP(NETIF_MSG_LINK, "Found errors on XMAC\n");
  5943. vars->link_up = 0;
  5944. vars->phy_flags |= PHY_HALF_OPEN_CONN_FLAG;
  5945. vars->link_status &= ~LINK_STATUS_LINK_UP;
  5946. }
  5947. } else
  5948. bnx2x_umac_enable(params, vars, 0);
  5949. bnx2x_set_led(params, vars,
  5950. LED_MODE_OPER, vars->line_speed);
  5951. if ((vars->eee_status & SHMEM_EEE_ACTIVE_BIT) &&
  5952. (vars->eee_status & SHMEM_EEE_LPI_REQUESTED_BIT)) {
  5953. DP(NETIF_MSG_LINK, "Enabling LPI assertion\n");
  5954. REG_WR(bp, MISC_REG_CPMU_LP_FW_ENABLE_P0 +
  5955. (params->port << 2), 1);
  5956. REG_WR(bp, MISC_REG_CPMU_LP_DR_ENABLE, 1);
  5957. REG_WR(bp, MISC_REG_CPMU_LP_MASK_ENT_P0 +
  5958. (params->port << 2), 0xfc20);
  5959. }
  5960. }
  5961. if ((CHIP_IS_E1x(bp) ||
  5962. CHIP_IS_E2(bp))) {
  5963. if (link_10g) {
  5964. if (bnx2x_bmac_enable(params, vars, 0, 1) ==
  5965. -ESRCH) {
  5966. DP(NETIF_MSG_LINK, "Found errors on BMAC\n");
  5967. vars->link_up = 0;
  5968. vars->phy_flags |= PHY_HALF_OPEN_CONN_FLAG;
  5969. vars->link_status &= ~LINK_STATUS_LINK_UP;
  5970. }
  5971. bnx2x_set_led(params, vars,
  5972. LED_MODE_OPER, SPEED_10000);
  5973. } else {
  5974. rc = bnx2x_emac_program(params, vars);
  5975. bnx2x_emac_enable(params, vars, 0);
  5976. /* AN complete? */
  5977. if ((vars->link_status &
  5978. LINK_STATUS_AUTO_NEGOTIATE_COMPLETE)
  5979. && (!(vars->phy_flags & PHY_SGMII_FLAG)) &&
  5980. SINGLE_MEDIA_DIRECT(params))
  5981. bnx2x_set_gmii_tx_driver(params);
  5982. }
  5983. }
  5984. /* PBF - link up */
  5985. if (CHIP_IS_E1x(bp))
  5986. rc |= bnx2x_pbf_update(params, vars->flow_ctrl,
  5987. vars->line_speed);
  5988. /* Disable drain */
  5989. REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 0);
  5990. /* Update shared memory */
  5991. bnx2x_update_mng(params, vars->link_status);
  5992. bnx2x_update_mng_eee(params, vars->eee_status);
  5993. /* Check remote fault */
  5994. for (phy_idx = INT_PHY; phy_idx < MAX_PHYS; phy_idx++) {
  5995. if (params->phy[phy_idx].flags & FLAGS_TX_ERROR_CHECK) {
  5996. bnx2x_check_half_open_conn(params, vars, 0);
  5997. break;
  5998. }
  5999. }
  6000. msleep(20);
  6001. return rc;
  6002. }
  6003. static void bnx2x_chng_link_count(struct link_params *params, bool clear)
  6004. {
  6005. struct bnx2x *bp = params->bp;
  6006. u32 addr, val;
  6007. /* Verify the link_change_count is supported by the MFW */
  6008. if (!(SHMEM2_HAS(bp, link_change_count)))
  6009. return;
  6010. addr = params->shmem2_base +
  6011. offsetof(struct shmem2_region, link_change_count[params->port]);
  6012. if (clear)
  6013. val = 0;
  6014. else
  6015. val = REG_RD(bp, addr) + 1;
  6016. REG_WR(bp, addr, val);
  6017. }
  6018. /* The bnx2x_link_update function should be called upon link
  6019. * interrupt.
  6020. * Link is considered up as follows:
  6021. * - DIRECT_SINGLE_MEDIA - Only XGXS link (internal link) needs
  6022. * to be up
  6023. * - SINGLE_MEDIA - The link between the 577xx and the external
  6024. * phy (XGXS) need to up as well as the external link of the
  6025. * phy (PHY_EXT1)
  6026. * - DUAL_MEDIA - The link between the 577xx and the first
  6027. * external phy needs to be up, and at least one of the 2
  6028. * external phy link must be up.
  6029. */
  6030. int bnx2x_link_update(struct link_params *params, struct link_vars *vars)
  6031. {
  6032. struct bnx2x *bp = params->bp;
  6033. struct link_vars phy_vars[MAX_PHYS];
  6034. u8 port = params->port;
  6035. u8 link_10g_plus, phy_index;
  6036. u32 prev_link_status = vars->link_status;
  6037. u8 ext_phy_link_up = 0, cur_link_up;
  6038. int rc = 0;
  6039. u8 is_mi_int = 0;
  6040. u16 ext_phy_line_speed = 0, prev_line_speed = vars->line_speed;
  6041. u8 active_external_phy = INT_PHY;
  6042. vars->phy_flags &= ~PHY_HALF_OPEN_CONN_FLAG;
  6043. vars->link_status &= ~LINK_UPDATE_MASK;
  6044. for (phy_index = INT_PHY; phy_index < params->num_phys;
  6045. phy_index++) {
  6046. phy_vars[phy_index].flow_ctrl = 0;
  6047. phy_vars[phy_index].link_status = 0;
  6048. phy_vars[phy_index].line_speed = 0;
  6049. phy_vars[phy_index].duplex = DUPLEX_FULL;
  6050. phy_vars[phy_index].phy_link_up = 0;
  6051. phy_vars[phy_index].link_up = 0;
  6052. phy_vars[phy_index].fault_detected = 0;
  6053. /* different consideration, since vars holds inner state */
  6054. phy_vars[phy_index].eee_status = vars->eee_status;
  6055. }
  6056. if (USES_WARPCORE(bp))
  6057. bnx2x_set_aer_mmd(params, &params->phy[INT_PHY]);
  6058. DP(NETIF_MSG_LINK, "port %x, XGXS?%x, int_status 0x%x\n",
  6059. port, (vars->phy_flags & PHY_XGXS_FLAG),
  6060. REG_RD(bp, NIG_REG_STATUS_INTERRUPT_PORT0 + port*4));
  6061. is_mi_int = (u8)(REG_RD(bp, NIG_REG_EMAC0_STATUS_MISC_MI_INT +
  6062. port*0x18) > 0);
  6063. DP(NETIF_MSG_LINK, "int_mask 0x%x MI_INT %x, SERDES_LINK %x\n",
  6064. REG_RD(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4),
  6065. is_mi_int,
  6066. REG_RD(bp, NIG_REG_SERDES0_STATUS_LINK_STATUS + port*0x3c));
  6067. DP(NETIF_MSG_LINK, " 10G %x, XGXS_LINK %x\n",
  6068. REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK10G + port*0x68),
  6069. REG_RD(bp, NIG_REG_XGXS0_STATUS_LINK_STATUS + port*0x68));
  6070. /* Disable emac */
  6071. if (!CHIP_IS_E3(bp))
  6072. REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
  6073. /* Step 1:
  6074. * Check external link change only for external phys, and apply
  6075. * priority selection between them in case the link on both phys
  6076. * is up. Note that instead of the common vars, a temporary
  6077. * vars argument is used since each phy may have different link/
  6078. * speed/duplex result
  6079. */
  6080. for (phy_index = EXT_PHY1; phy_index < params->num_phys;
  6081. phy_index++) {
  6082. struct bnx2x_phy *phy = &params->phy[phy_index];
  6083. if (!phy->read_status)
  6084. continue;
  6085. /* Read link status and params of this ext phy */
  6086. cur_link_up = phy->read_status(phy, params,
  6087. &phy_vars[phy_index]);
  6088. if (cur_link_up) {
  6089. DP(NETIF_MSG_LINK, "phy in index %d link is up\n",
  6090. phy_index);
  6091. } else {
  6092. DP(NETIF_MSG_LINK, "phy in index %d link is down\n",
  6093. phy_index);
  6094. continue;
  6095. }
  6096. if (!ext_phy_link_up) {
  6097. ext_phy_link_up = 1;
  6098. active_external_phy = phy_index;
  6099. } else {
  6100. switch (bnx2x_phy_selection(params)) {
  6101. case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
  6102. case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
  6103. /* In this option, the first PHY makes sure to pass the
  6104. * traffic through itself only.
  6105. * Its not clear how to reset the link on the second phy
  6106. */
  6107. active_external_phy = EXT_PHY1;
  6108. break;
  6109. case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
  6110. /* In this option, the first PHY makes sure to pass the
  6111. * traffic through the second PHY.
  6112. */
  6113. active_external_phy = EXT_PHY2;
  6114. break;
  6115. default:
  6116. /* Link indication on both PHYs with the following cases
  6117. * is invalid:
  6118. * - FIRST_PHY means that second phy wasn't initialized,
  6119. * hence its link is expected to be down
  6120. * - SECOND_PHY means that first phy should not be able
  6121. * to link up by itself (using configuration)
  6122. * - DEFAULT should be overriden during initialiazation
  6123. */
  6124. DP(NETIF_MSG_LINK, "Invalid link indication"
  6125. "mpc=0x%x. DISABLING LINK !!!\n",
  6126. params->multi_phy_config);
  6127. ext_phy_link_up = 0;
  6128. break;
  6129. }
  6130. }
  6131. }
  6132. prev_line_speed = vars->line_speed;
  6133. /* Step 2:
  6134. * Read the status of the internal phy. In case of
  6135. * DIRECT_SINGLE_MEDIA board, this link is the external link,
  6136. * otherwise this is the link between the 577xx and the first
  6137. * external phy
  6138. */
  6139. if (params->phy[INT_PHY].read_status)
  6140. params->phy[INT_PHY].read_status(
  6141. &params->phy[INT_PHY],
  6142. params, vars);
  6143. /* The INT_PHY flow control reside in the vars. This include the
  6144. * case where the speed or flow control are not set to AUTO.
  6145. * Otherwise, the active external phy flow control result is set
  6146. * to the vars. The ext_phy_line_speed is needed to check if the
  6147. * speed is different between the internal phy and external phy.
  6148. * This case may be result of intermediate link speed change.
  6149. */
  6150. if (active_external_phy > INT_PHY) {
  6151. vars->flow_ctrl = phy_vars[active_external_phy].flow_ctrl;
  6152. /* Link speed is taken from the XGXS. AN and FC result from
  6153. * the external phy.
  6154. */
  6155. vars->link_status |= phy_vars[active_external_phy].link_status;
  6156. /* if active_external_phy is first PHY and link is up - disable
  6157. * disable TX on second external PHY
  6158. */
  6159. if (active_external_phy == EXT_PHY1) {
  6160. if (params->phy[EXT_PHY2].phy_specific_func) {
  6161. DP(NETIF_MSG_LINK,
  6162. "Disabling TX on EXT_PHY2\n");
  6163. params->phy[EXT_PHY2].phy_specific_func(
  6164. &params->phy[EXT_PHY2],
  6165. params, DISABLE_TX);
  6166. }
  6167. }
  6168. ext_phy_line_speed = phy_vars[active_external_phy].line_speed;
  6169. vars->duplex = phy_vars[active_external_phy].duplex;
  6170. if (params->phy[active_external_phy].supported &
  6171. SUPPORTED_FIBRE)
  6172. vars->link_status |= LINK_STATUS_SERDES_LINK;
  6173. else
  6174. vars->link_status &= ~LINK_STATUS_SERDES_LINK;
  6175. vars->eee_status = phy_vars[active_external_phy].eee_status;
  6176. DP(NETIF_MSG_LINK, "Active external phy selected: %x\n",
  6177. active_external_phy);
  6178. }
  6179. for (phy_index = EXT_PHY1; phy_index < params->num_phys;
  6180. phy_index++) {
  6181. if (params->phy[phy_index].flags &
  6182. FLAGS_REARM_LATCH_SIGNAL) {
  6183. bnx2x_rearm_latch_signal(bp, port,
  6184. phy_index ==
  6185. active_external_phy);
  6186. break;
  6187. }
  6188. }
  6189. DP(NETIF_MSG_LINK, "vars->flow_ctrl = 0x%x, vars->link_status = 0x%x,"
  6190. " ext_phy_line_speed = %d\n", vars->flow_ctrl,
  6191. vars->link_status, ext_phy_line_speed);
  6192. /* Upon link speed change set the NIG into drain mode. Comes to
  6193. * deals with possible FIFO glitch due to clk change when speed
  6194. * is decreased without link down indicator
  6195. */
  6196. if (vars->phy_link_up) {
  6197. if (!(SINGLE_MEDIA_DIRECT(params)) && ext_phy_link_up &&
  6198. (ext_phy_line_speed != vars->line_speed)) {
  6199. DP(NETIF_MSG_LINK, "Internal link speed %d is"
  6200. " different than the external"
  6201. " link speed %d\n", vars->line_speed,
  6202. ext_phy_line_speed);
  6203. vars->phy_link_up = 0;
  6204. } else if (prev_line_speed != vars->line_speed) {
  6205. REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4,
  6206. 0);
  6207. usleep_range(1000, 2000);
  6208. }
  6209. }
  6210. /* Anything 10 and over uses the bmac */
  6211. link_10g_plus = (vars->line_speed >= SPEED_10000);
  6212. bnx2x_link_int_ack(params, vars, link_10g_plus);
  6213. /* In case external phy link is up, and internal link is down
  6214. * (not initialized yet probably after link initialization, it
  6215. * needs to be initialized.
  6216. * Note that after link down-up as result of cable plug, the xgxs
  6217. * link would probably become up again without the need
  6218. * initialize it
  6219. */
  6220. if (!(SINGLE_MEDIA_DIRECT(params))) {
  6221. DP(NETIF_MSG_LINK, "ext_phy_link_up = %d, int_link_up = %d,"
  6222. " init_preceding = %d\n", ext_phy_link_up,
  6223. vars->phy_link_up,
  6224. params->phy[EXT_PHY1].flags &
  6225. FLAGS_INIT_XGXS_FIRST);
  6226. if (!(params->phy[EXT_PHY1].flags &
  6227. FLAGS_INIT_XGXS_FIRST)
  6228. && ext_phy_link_up && !vars->phy_link_up) {
  6229. vars->line_speed = ext_phy_line_speed;
  6230. if (vars->line_speed < SPEED_1000)
  6231. vars->phy_flags |= PHY_SGMII_FLAG;
  6232. else
  6233. vars->phy_flags &= ~PHY_SGMII_FLAG;
  6234. if (params->phy[INT_PHY].config_init)
  6235. params->phy[INT_PHY].config_init(
  6236. &params->phy[INT_PHY], params,
  6237. vars);
  6238. }
  6239. }
  6240. /* Link is up only if both local phy and external phy (in case of
  6241. * non-direct board) are up and no fault detected on active PHY.
  6242. */
  6243. vars->link_up = (vars->phy_link_up &&
  6244. (ext_phy_link_up ||
  6245. SINGLE_MEDIA_DIRECT(params)) &&
  6246. (phy_vars[active_external_phy].fault_detected == 0));
  6247. /* Update the PFC configuration in case it was changed */
  6248. if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
  6249. vars->link_status |= LINK_STATUS_PFC_ENABLED;
  6250. else
  6251. vars->link_status &= ~LINK_STATUS_PFC_ENABLED;
  6252. if (vars->link_up)
  6253. rc = bnx2x_update_link_up(params, vars, link_10g_plus);
  6254. else
  6255. rc = bnx2x_update_link_down(params, vars);
  6256. if ((prev_link_status ^ vars->link_status) & LINK_STATUS_LINK_UP)
  6257. bnx2x_chng_link_count(params, false);
  6258. /* Update MCP link status was changed */
  6259. if (params->feature_config_flags & FEATURE_CONFIG_BC_SUPPORTS_AFEX)
  6260. bnx2x_fw_command(bp, DRV_MSG_CODE_LINK_STATUS_CHANGED, 0);
  6261. return rc;
  6262. }
  6263. /*****************************************************************************/
  6264. /* External Phy section */
  6265. /*****************************************************************************/
  6266. void bnx2x_ext_phy_hw_reset(struct bnx2x *bp, u8 port)
  6267. {
  6268. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
  6269. MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
  6270. usleep_range(1000, 2000);
  6271. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
  6272. MISC_REGISTERS_GPIO_OUTPUT_HIGH, port);
  6273. }
  6274. static void bnx2x_save_spirom_version(struct bnx2x *bp, u8 port,
  6275. u32 spirom_ver, u32 ver_addr)
  6276. {
  6277. DP(NETIF_MSG_LINK, "FW version 0x%x:0x%x for port %d\n",
  6278. (u16)(spirom_ver>>16), (u16)spirom_ver, port);
  6279. if (ver_addr)
  6280. REG_WR(bp, ver_addr, spirom_ver);
  6281. }
  6282. static void bnx2x_save_bcm_spirom_ver(struct bnx2x *bp,
  6283. struct bnx2x_phy *phy,
  6284. u8 port)
  6285. {
  6286. u16 fw_ver1, fw_ver2;
  6287. bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
  6288. MDIO_PMA_REG_ROM_VER1, &fw_ver1);
  6289. bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
  6290. MDIO_PMA_REG_ROM_VER2, &fw_ver2);
  6291. bnx2x_save_spirom_version(bp, port, (u32)(fw_ver1<<16 | fw_ver2),
  6292. phy->ver_addr);
  6293. }
  6294. static void bnx2x_ext_phy_10G_an_resolve(struct bnx2x *bp,
  6295. struct bnx2x_phy *phy,
  6296. struct link_vars *vars)
  6297. {
  6298. u16 val;
  6299. bnx2x_cl45_read(bp, phy,
  6300. MDIO_AN_DEVAD,
  6301. MDIO_AN_REG_STATUS, &val);
  6302. bnx2x_cl45_read(bp, phy,
  6303. MDIO_AN_DEVAD,
  6304. MDIO_AN_REG_STATUS, &val);
  6305. if (val & (1<<5))
  6306. vars->link_status |= LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
  6307. if ((val & (1<<0)) == 0)
  6308. vars->link_status |= LINK_STATUS_PARALLEL_DETECTION_USED;
  6309. }
  6310. /******************************************************************/
  6311. /* common BCM8073/BCM8727 PHY SECTION */
  6312. /******************************************************************/
  6313. static void bnx2x_8073_resolve_fc(struct bnx2x_phy *phy,
  6314. struct link_params *params,
  6315. struct link_vars *vars)
  6316. {
  6317. struct bnx2x *bp = params->bp;
  6318. if (phy->req_line_speed == SPEED_10 ||
  6319. phy->req_line_speed == SPEED_100) {
  6320. vars->flow_ctrl = phy->req_flow_ctrl;
  6321. return;
  6322. }
  6323. if (bnx2x_ext_phy_resolve_fc(phy, params, vars) &&
  6324. (vars->flow_ctrl == BNX2X_FLOW_CTRL_NONE)) {
  6325. u16 pause_result;
  6326. u16 ld_pause; /* local */
  6327. u16 lp_pause; /* link partner */
  6328. bnx2x_cl45_read(bp, phy,
  6329. MDIO_AN_DEVAD,
  6330. MDIO_AN_REG_CL37_FC_LD, &ld_pause);
  6331. bnx2x_cl45_read(bp, phy,
  6332. MDIO_AN_DEVAD,
  6333. MDIO_AN_REG_CL37_FC_LP, &lp_pause);
  6334. pause_result = (ld_pause &
  6335. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) >> 5;
  6336. pause_result |= (lp_pause &
  6337. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) >> 7;
  6338. bnx2x_pause_resolve(phy, params, vars, pause_result);
  6339. DP(NETIF_MSG_LINK, "Ext PHY CL37 pause result 0x%x\n",
  6340. pause_result);
  6341. }
  6342. }
  6343. static int bnx2x_8073_8727_external_rom_boot(struct bnx2x *bp,
  6344. struct bnx2x_phy *phy,
  6345. u8 port)
  6346. {
  6347. u32 count = 0;
  6348. u16 fw_ver1, fw_msgout;
  6349. int rc = 0;
  6350. /* Boot port from external ROM */
  6351. /* EDC grst */
  6352. bnx2x_cl45_write(bp, phy,
  6353. MDIO_PMA_DEVAD,
  6354. MDIO_PMA_REG_GEN_CTRL,
  6355. 0x0001);
  6356. /* Ucode reboot and rst */
  6357. bnx2x_cl45_write(bp, phy,
  6358. MDIO_PMA_DEVAD,
  6359. MDIO_PMA_REG_GEN_CTRL,
  6360. 0x008c);
  6361. bnx2x_cl45_write(bp, phy,
  6362. MDIO_PMA_DEVAD,
  6363. MDIO_PMA_REG_MISC_CTRL1, 0x0001);
  6364. /* Reset internal microprocessor */
  6365. bnx2x_cl45_write(bp, phy,
  6366. MDIO_PMA_DEVAD,
  6367. MDIO_PMA_REG_GEN_CTRL,
  6368. MDIO_PMA_REG_GEN_CTRL_ROM_MICRO_RESET);
  6369. /* Release srst bit */
  6370. bnx2x_cl45_write(bp, phy,
  6371. MDIO_PMA_DEVAD,
  6372. MDIO_PMA_REG_GEN_CTRL,
  6373. MDIO_PMA_REG_GEN_CTRL_ROM_RESET_INTERNAL_MP);
  6374. /* Delay 100ms per the PHY specifications */
  6375. msleep(100);
  6376. /* 8073 sometimes taking longer to download */
  6377. do {
  6378. count++;
  6379. if (count > 300) {
  6380. DP(NETIF_MSG_LINK,
  6381. "bnx2x_8073_8727_external_rom_boot port %x:"
  6382. "Download failed. fw version = 0x%x\n",
  6383. port, fw_ver1);
  6384. rc = -EINVAL;
  6385. break;
  6386. }
  6387. bnx2x_cl45_read(bp, phy,
  6388. MDIO_PMA_DEVAD,
  6389. MDIO_PMA_REG_ROM_VER1, &fw_ver1);
  6390. bnx2x_cl45_read(bp, phy,
  6391. MDIO_PMA_DEVAD,
  6392. MDIO_PMA_REG_M8051_MSGOUT_REG, &fw_msgout);
  6393. usleep_range(1000, 2000);
  6394. } while (fw_ver1 == 0 || fw_ver1 == 0x4321 ||
  6395. ((fw_msgout & 0xff) != 0x03 && (phy->type ==
  6396. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073)));
  6397. /* Clear ser_boot_ctl bit */
  6398. bnx2x_cl45_write(bp, phy,
  6399. MDIO_PMA_DEVAD,
  6400. MDIO_PMA_REG_MISC_CTRL1, 0x0000);
  6401. bnx2x_save_bcm_spirom_ver(bp, phy, port);
  6402. DP(NETIF_MSG_LINK,
  6403. "bnx2x_8073_8727_external_rom_boot port %x:"
  6404. "Download complete. fw version = 0x%x\n",
  6405. port, fw_ver1);
  6406. return rc;
  6407. }
  6408. /******************************************************************/
  6409. /* BCM8073 PHY SECTION */
  6410. /******************************************************************/
  6411. static int bnx2x_8073_is_snr_needed(struct bnx2x *bp, struct bnx2x_phy *phy)
  6412. {
  6413. /* This is only required for 8073A1, version 102 only */
  6414. u16 val;
  6415. /* Read 8073 HW revision*/
  6416. bnx2x_cl45_read(bp, phy,
  6417. MDIO_PMA_DEVAD,
  6418. MDIO_PMA_REG_8073_CHIP_REV, &val);
  6419. if (val != 1) {
  6420. /* No need to workaround in 8073 A1 */
  6421. return 0;
  6422. }
  6423. bnx2x_cl45_read(bp, phy,
  6424. MDIO_PMA_DEVAD,
  6425. MDIO_PMA_REG_ROM_VER2, &val);
  6426. /* SNR should be applied only for version 0x102 */
  6427. if (val != 0x102)
  6428. return 0;
  6429. return 1;
  6430. }
  6431. static int bnx2x_8073_xaui_wa(struct bnx2x *bp, struct bnx2x_phy *phy)
  6432. {
  6433. u16 val, cnt, cnt1 ;
  6434. bnx2x_cl45_read(bp, phy,
  6435. MDIO_PMA_DEVAD,
  6436. MDIO_PMA_REG_8073_CHIP_REV, &val);
  6437. if (val > 0) {
  6438. /* No need to workaround in 8073 A1 */
  6439. return 0;
  6440. }
  6441. /* XAUI workaround in 8073 A0: */
  6442. /* After loading the boot ROM and restarting Autoneg, poll
  6443. * Dev1, Reg $C820:
  6444. */
  6445. for (cnt = 0; cnt < 1000; cnt++) {
  6446. bnx2x_cl45_read(bp, phy,
  6447. MDIO_PMA_DEVAD,
  6448. MDIO_PMA_REG_8073_SPEED_LINK_STATUS,
  6449. &val);
  6450. /* If bit [14] = 0 or bit [13] = 0, continue on with
  6451. * system initialization (XAUI work-around not required, as
  6452. * these bits indicate 2.5G or 1G link up).
  6453. */
  6454. if (!(val & (1<<14)) || !(val & (1<<13))) {
  6455. DP(NETIF_MSG_LINK, "XAUI work-around not required\n");
  6456. return 0;
  6457. } else if (!(val & (1<<15))) {
  6458. DP(NETIF_MSG_LINK, "bit 15 went off\n");
  6459. /* If bit 15 is 0, then poll Dev1, Reg $C841 until it's
  6460. * MSB (bit15) goes to 1 (indicating that the XAUI
  6461. * workaround has completed), then continue on with
  6462. * system initialization.
  6463. */
  6464. for (cnt1 = 0; cnt1 < 1000; cnt1++) {
  6465. bnx2x_cl45_read(bp, phy,
  6466. MDIO_PMA_DEVAD,
  6467. MDIO_PMA_REG_8073_XAUI_WA, &val);
  6468. if (val & (1<<15)) {
  6469. DP(NETIF_MSG_LINK,
  6470. "XAUI workaround has completed\n");
  6471. return 0;
  6472. }
  6473. usleep_range(3000, 6000);
  6474. }
  6475. break;
  6476. }
  6477. usleep_range(3000, 6000);
  6478. }
  6479. DP(NETIF_MSG_LINK, "Warning: XAUI work-around timeout !!!\n");
  6480. return -EINVAL;
  6481. }
  6482. static void bnx2x_807x_force_10G(struct bnx2x *bp, struct bnx2x_phy *phy)
  6483. {
  6484. /* Force KR or KX */
  6485. bnx2x_cl45_write(bp, phy,
  6486. MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x2040);
  6487. bnx2x_cl45_write(bp, phy,
  6488. MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0x000b);
  6489. bnx2x_cl45_write(bp, phy,
  6490. MDIO_PMA_DEVAD, MDIO_PMA_REG_BCM_CTRL, 0x0000);
  6491. bnx2x_cl45_write(bp, phy,
  6492. MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x0000);
  6493. }
  6494. static void bnx2x_8073_set_pause_cl37(struct link_params *params,
  6495. struct bnx2x_phy *phy,
  6496. struct link_vars *vars)
  6497. {
  6498. u16 cl37_val;
  6499. struct bnx2x *bp = params->bp;
  6500. bnx2x_cl45_read(bp, phy,
  6501. MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, &cl37_val);
  6502. cl37_val &= ~MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
  6503. /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
  6504. bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
  6505. if ((vars->ieee_fc &
  6506. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC) ==
  6507. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC) {
  6508. cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_SYMMETRIC;
  6509. }
  6510. if ((vars->ieee_fc &
  6511. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
  6512. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) {
  6513. cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC;
  6514. }
  6515. if ((vars->ieee_fc &
  6516. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
  6517. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) {
  6518. cl37_val |= MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH;
  6519. }
  6520. DP(NETIF_MSG_LINK,
  6521. "Ext phy AN advertize cl37 0x%x\n", cl37_val);
  6522. bnx2x_cl45_write(bp, phy,
  6523. MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, cl37_val);
  6524. msleep(500);
  6525. }
  6526. static void bnx2x_8073_specific_func(struct bnx2x_phy *phy,
  6527. struct link_params *params,
  6528. u32 action)
  6529. {
  6530. struct bnx2x *bp = params->bp;
  6531. switch (action) {
  6532. case PHY_INIT:
  6533. /* Enable LASI */
  6534. bnx2x_cl45_write(bp, phy,
  6535. MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL, (1<<2));
  6536. bnx2x_cl45_write(bp, phy,
  6537. MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x0004);
  6538. break;
  6539. }
  6540. }
  6541. static int bnx2x_8073_config_init(struct bnx2x_phy *phy,
  6542. struct link_params *params,
  6543. struct link_vars *vars)
  6544. {
  6545. struct bnx2x *bp = params->bp;
  6546. u16 val = 0, tmp1;
  6547. u8 gpio_port;
  6548. DP(NETIF_MSG_LINK, "Init 8073\n");
  6549. if (CHIP_IS_E2(bp))
  6550. gpio_port = BP_PATH(bp);
  6551. else
  6552. gpio_port = params->port;
  6553. /* Restore normal power mode*/
  6554. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
  6555. MISC_REGISTERS_GPIO_OUTPUT_HIGH, gpio_port);
  6556. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
  6557. MISC_REGISTERS_GPIO_OUTPUT_HIGH, gpio_port);
  6558. bnx2x_8073_specific_func(phy, params, PHY_INIT);
  6559. bnx2x_8073_set_pause_cl37(params, phy, vars);
  6560. bnx2x_cl45_read(bp, phy,
  6561. MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &tmp1);
  6562. bnx2x_cl45_read(bp, phy,
  6563. MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT, &tmp1);
  6564. DP(NETIF_MSG_LINK, "Before rom RX_ALARM(port1): 0x%x\n", tmp1);
  6565. /* Swap polarity if required - Must be done only in non-1G mode */
  6566. if (params->lane_config & PORT_HW_CFG_SWAP_PHY_POLARITY_ENABLED) {
  6567. /* Configure the 8073 to swap _P and _N of the KR lines */
  6568. DP(NETIF_MSG_LINK, "Swapping polarity for the 8073\n");
  6569. /* 10G Rx/Tx and 1G Tx signal polarity swap */
  6570. bnx2x_cl45_read(bp, phy,
  6571. MDIO_PMA_DEVAD,
  6572. MDIO_PMA_REG_8073_OPT_DIGITAL_CTRL, &val);
  6573. bnx2x_cl45_write(bp, phy,
  6574. MDIO_PMA_DEVAD,
  6575. MDIO_PMA_REG_8073_OPT_DIGITAL_CTRL,
  6576. (val | (3<<9)));
  6577. }
  6578. /* Enable CL37 BAM */
  6579. if (REG_RD(bp, params->shmem_base +
  6580. offsetof(struct shmem_region, dev_info.
  6581. port_hw_config[params->port].default_cfg)) &
  6582. PORT_HW_CFG_ENABLE_BAM_ON_KR_ENABLED) {
  6583. bnx2x_cl45_read(bp, phy,
  6584. MDIO_AN_DEVAD,
  6585. MDIO_AN_REG_8073_BAM, &val);
  6586. bnx2x_cl45_write(bp, phy,
  6587. MDIO_AN_DEVAD,
  6588. MDIO_AN_REG_8073_BAM, val | 1);
  6589. DP(NETIF_MSG_LINK, "Enable CL37 BAM on KR\n");
  6590. }
  6591. if (params->loopback_mode == LOOPBACK_EXT) {
  6592. bnx2x_807x_force_10G(bp, phy);
  6593. DP(NETIF_MSG_LINK, "Forced speed 10G on 807X\n");
  6594. return 0;
  6595. } else {
  6596. bnx2x_cl45_write(bp, phy,
  6597. MDIO_PMA_DEVAD, MDIO_PMA_REG_BCM_CTRL, 0x0002);
  6598. }
  6599. if (phy->req_line_speed != SPEED_AUTO_NEG) {
  6600. if (phy->req_line_speed == SPEED_10000) {
  6601. val = (1<<7);
  6602. } else if (phy->req_line_speed == SPEED_2500) {
  6603. val = (1<<5);
  6604. /* Note that 2.5G works only when used with 1G
  6605. * advertisement
  6606. */
  6607. } else
  6608. val = (1<<5);
  6609. } else {
  6610. val = 0;
  6611. if (phy->speed_cap_mask &
  6612. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  6613. val |= (1<<7);
  6614. /* Note that 2.5G works only when used with 1G advertisement */
  6615. if (phy->speed_cap_mask &
  6616. (PORT_HW_CFG_SPEED_CAPABILITY_D0_1G |
  6617. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  6618. val |= (1<<5);
  6619. DP(NETIF_MSG_LINK, "807x autoneg val = 0x%x\n", val);
  6620. }
  6621. bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV, val);
  6622. bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_8073_2_5G, &tmp1);
  6623. if (((phy->speed_cap_mask & PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G) &&
  6624. (phy->req_line_speed == SPEED_AUTO_NEG)) ||
  6625. (phy->req_line_speed == SPEED_2500)) {
  6626. u16 phy_ver;
  6627. /* Allow 2.5G for A1 and above */
  6628. bnx2x_cl45_read(bp, phy,
  6629. MDIO_PMA_DEVAD, MDIO_PMA_REG_8073_CHIP_REV,
  6630. &phy_ver);
  6631. DP(NETIF_MSG_LINK, "Add 2.5G\n");
  6632. if (phy_ver > 0)
  6633. tmp1 |= 1;
  6634. else
  6635. tmp1 &= 0xfffe;
  6636. } else {
  6637. DP(NETIF_MSG_LINK, "Disable 2.5G\n");
  6638. tmp1 &= 0xfffe;
  6639. }
  6640. bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_8073_2_5G, tmp1);
  6641. /* Add support for CL37 (passive mode) II */
  6642. bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, &tmp1);
  6643. bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD,
  6644. (tmp1 | ((phy->req_duplex == DUPLEX_FULL) ?
  6645. 0x20 : 0x40)));
  6646. /* Add support for CL37 (passive mode) III */
  6647. bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
  6648. /* The SNR will improve about 2db by changing BW and FEE main
  6649. * tap. Rest commands are executed after link is up
  6650. * Change FFE main cursor to 5 in EDC register
  6651. */
  6652. if (bnx2x_8073_is_snr_needed(bp, phy))
  6653. bnx2x_cl45_write(bp, phy,
  6654. MDIO_PMA_DEVAD, MDIO_PMA_REG_EDC_FFE_MAIN,
  6655. 0xFB0C);
  6656. /* Enable FEC (Forware Error Correction) Request in the AN */
  6657. bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV2, &tmp1);
  6658. tmp1 |= (1<<15);
  6659. bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_ADV2, tmp1);
  6660. bnx2x_ext_phy_set_pause(params, phy, vars);
  6661. /* Restart autoneg */
  6662. msleep(500);
  6663. bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
  6664. DP(NETIF_MSG_LINK, "807x Autoneg Restart: Advertise 1G=%x, 10G=%x\n",
  6665. ((val & (1<<5)) > 0), ((val & (1<<7)) > 0));
  6666. return 0;
  6667. }
  6668. static u8 bnx2x_8073_read_status(struct bnx2x_phy *phy,
  6669. struct link_params *params,
  6670. struct link_vars *vars)
  6671. {
  6672. struct bnx2x *bp = params->bp;
  6673. u8 link_up = 0;
  6674. u16 val1, val2;
  6675. u16 link_status = 0;
  6676. u16 an1000_status = 0;
  6677. bnx2x_cl45_read(bp, phy,
  6678. MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val1);
  6679. DP(NETIF_MSG_LINK, "8703 LASI status 0x%x\n", val1);
  6680. /* Clear the interrupt LASI status register */
  6681. bnx2x_cl45_read(bp, phy,
  6682. MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val2);
  6683. bnx2x_cl45_read(bp, phy,
  6684. MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val1);
  6685. DP(NETIF_MSG_LINK, "807x PCS status 0x%x->0x%x\n", val2, val1);
  6686. /* Clear MSG-OUT */
  6687. bnx2x_cl45_read(bp, phy,
  6688. MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &val1);
  6689. /* Check the LASI */
  6690. bnx2x_cl45_read(bp, phy,
  6691. MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT, &val2);
  6692. DP(NETIF_MSG_LINK, "KR 0x9003 0x%x\n", val2);
  6693. /* Check the link status */
  6694. bnx2x_cl45_read(bp, phy,
  6695. MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &val2);
  6696. DP(NETIF_MSG_LINK, "KR PCS status 0x%x\n", val2);
  6697. bnx2x_cl45_read(bp, phy,
  6698. MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
  6699. bnx2x_cl45_read(bp, phy,
  6700. MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
  6701. link_up = ((val1 & 4) == 4);
  6702. DP(NETIF_MSG_LINK, "PMA_REG_STATUS=0x%x\n", val1);
  6703. if (link_up &&
  6704. ((phy->req_line_speed != SPEED_10000))) {
  6705. if (bnx2x_8073_xaui_wa(bp, phy) != 0)
  6706. return 0;
  6707. }
  6708. bnx2x_cl45_read(bp, phy,
  6709. MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &an1000_status);
  6710. bnx2x_cl45_read(bp, phy,
  6711. MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &an1000_status);
  6712. /* Check the link status on 1.1.2 */
  6713. bnx2x_cl45_read(bp, phy,
  6714. MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
  6715. bnx2x_cl45_read(bp, phy,
  6716. MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
  6717. DP(NETIF_MSG_LINK, "KR PMA status 0x%x->0x%x,"
  6718. "an_link_status=0x%x\n", val2, val1, an1000_status);
  6719. link_up = (((val1 & 4) == 4) || (an1000_status & (1<<1)));
  6720. if (link_up && bnx2x_8073_is_snr_needed(bp, phy)) {
  6721. /* The SNR will improve about 2dbby changing the BW and FEE main
  6722. * tap. The 1st write to change FFE main tap is set before
  6723. * restart AN. Change PLL Bandwidth in EDC register
  6724. */
  6725. bnx2x_cl45_write(bp, phy,
  6726. MDIO_PMA_DEVAD, MDIO_PMA_REG_PLL_BANDWIDTH,
  6727. 0x26BC);
  6728. /* Change CDR Bandwidth in EDC register */
  6729. bnx2x_cl45_write(bp, phy,
  6730. MDIO_PMA_DEVAD, MDIO_PMA_REG_CDR_BANDWIDTH,
  6731. 0x0333);
  6732. }
  6733. bnx2x_cl45_read(bp, phy,
  6734. MDIO_PMA_DEVAD, MDIO_PMA_REG_8073_SPEED_LINK_STATUS,
  6735. &link_status);
  6736. /* Bits 0..2 --> speed detected, bits 13..15--> link is down */
  6737. if ((link_status & (1<<2)) && (!(link_status & (1<<15)))) {
  6738. link_up = 1;
  6739. vars->line_speed = SPEED_10000;
  6740. DP(NETIF_MSG_LINK, "port %x: External link up in 10G\n",
  6741. params->port);
  6742. } else if ((link_status & (1<<1)) && (!(link_status & (1<<14)))) {
  6743. link_up = 1;
  6744. vars->line_speed = SPEED_2500;
  6745. DP(NETIF_MSG_LINK, "port %x: External link up in 2.5G\n",
  6746. params->port);
  6747. } else if ((link_status & (1<<0)) && (!(link_status & (1<<13)))) {
  6748. link_up = 1;
  6749. vars->line_speed = SPEED_1000;
  6750. DP(NETIF_MSG_LINK, "port %x: External link up in 1G\n",
  6751. params->port);
  6752. } else {
  6753. link_up = 0;
  6754. DP(NETIF_MSG_LINK, "port %x: External link is down\n",
  6755. params->port);
  6756. }
  6757. if (link_up) {
  6758. /* Swap polarity if required */
  6759. if (params->lane_config &
  6760. PORT_HW_CFG_SWAP_PHY_POLARITY_ENABLED) {
  6761. /* Configure the 8073 to swap P and N of the KR lines */
  6762. bnx2x_cl45_read(bp, phy,
  6763. MDIO_XS_DEVAD,
  6764. MDIO_XS_REG_8073_RX_CTRL_PCIE, &val1);
  6765. /* Set bit 3 to invert Rx in 1G mode and clear this bit
  6766. * when it`s in 10G mode.
  6767. */
  6768. if (vars->line_speed == SPEED_1000) {
  6769. DP(NETIF_MSG_LINK, "Swapping 1G polarity for"
  6770. "the 8073\n");
  6771. val1 |= (1<<3);
  6772. } else
  6773. val1 &= ~(1<<3);
  6774. bnx2x_cl45_write(bp, phy,
  6775. MDIO_XS_DEVAD,
  6776. MDIO_XS_REG_8073_RX_CTRL_PCIE,
  6777. val1);
  6778. }
  6779. bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
  6780. bnx2x_8073_resolve_fc(phy, params, vars);
  6781. vars->duplex = DUPLEX_FULL;
  6782. }
  6783. if (vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) {
  6784. bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
  6785. MDIO_AN_REG_LP_AUTO_NEG2, &val1);
  6786. if (val1 & (1<<5))
  6787. vars->link_status |=
  6788. LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE;
  6789. if (val1 & (1<<7))
  6790. vars->link_status |=
  6791. LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
  6792. }
  6793. return link_up;
  6794. }
  6795. static void bnx2x_8073_link_reset(struct bnx2x_phy *phy,
  6796. struct link_params *params)
  6797. {
  6798. struct bnx2x *bp = params->bp;
  6799. u8 gpio_port;
  6800. if (CHIP_IS_E2(bp))
  6801. gpio_port = BP_PATH(bp);
  6802. else
  6803. gpio_port = params->port;
  6804. DP(NETIF_MSG_LINK, "Setting 8073 port %d into low power mode\n",
  6805. gpio_port);
  6806. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
  6807. MISC_REGISTERS_GPIO_OUTPUT_LOW,
  6808. gpio_port);
  6809. }
  6810. /******************************************************************/
  6811. /* BCM8705 PHY SECTION */
  6812. /******************************************************************/
  6813. static int bnx2x_8705_config_init(struct bnx2x_phy *phy,
  6814. struct link_params *params,
  6815. struct link_vars *vars)
  6816. {
  6817. struct bnx2x *bp = params->bp;
  6818. DP(NETIF_MSG_LINK, "init 8705\n");
  6819. /* Restore normal power mode*/
  6820. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
  6821. MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
  6822. /* HW reset */
  6823. bnx2x_ext_phy_hw_reset(bp, params->port);
  6824. bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0xa040);
  6825. bnx2x_wait_reset_complete(bp, phy, params);
  6826. bnx2x_cl45_write(bp, phy,
  6827. MDIO_PMA_DEVAD, MDIO_PMA_REG_MISC_CTRL, 0x8288);
  6828. bnx2x_cl45_write(bp, phy,
  6829. MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, 0x7fbf);
  6830. bnx2x_cl45_write(bp, phy,
  6831. MDIO_PMA_DEVAD, MDIO_PMA_REG_CMU_PLL_BYPASS, 0x0100);
  6832. bnx2x_cl45_write(bp, phy,
  6833. MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_CNTL, 0x1);
  6834. /* BCM8705 doesn't have microcode, hence the 0 */
  6835. bnx2x_save_spirom_version(bp, params->port, params->shmem_base, 0);
  6836. return 0;
  6837. }
  6838. static u8 bnx2x_8705_read_status(struct bnx2x_phy *phy,
  6839. struct link_params *params,
  6840. struct link_vars *vars)
  6841. {
  6842. u8 link_up = 0;
  6843. u16 val1, rx_sd;
  6844. struct bnx2x *bp = params->bp;
  6845. DP(NETIF_MSG_LINK, "read status 8705\n");
  6846. bnx2x_cl45_read(bp, phy,
  6847. MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_STATUS, &val1);
  6848. DP(NETIF_MSG_LINK, "8705 LASI status 0x%x\n", val1);
  6849. bnx2x_cl45_read(bp, phy,
  6850. MDIO_WIS_DEVAD, MDIO_WIS_REG_LASI_STATUS, &val1);
  6851. DP(NETIF_MSG_LINK, "8705 LASI status 0x%x\n", val1);
  6852. bnx2x_cl45_read(bp, phy,
  6853. MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_SD, &rx_sd);
  6854. bnx2x_cl45_read(bp, phy,
  6855. MDIO_PMA_DEVAD, 0xc809, &val1);
  6856. bnx2x_cl45_read(bp, phy,
  6857. MDIO_PMA_DEVAD, 0xc809, &val1);
  6858. DP(NETIF_MSG_LINK, "8705 1.c809 val=0x%x\n", val1);
  6859. link_up = ((rx_sd & 0x1) && (val1 & (1<<9)) && ((val1 & (1<<8)) == 0));
  6860. if (link_up) {
  6861. vars->line_speed = SPEED_10000;
  6862. bnx2x_ext_phy_resolve_fc(phy, params, vars);
  6863. }
  6864. return link_up;
  6865. }
  6866. /******************************************************************/
  6867. /* SFP+ module Section */
  6868. /******************************************************************/
  6869. static void bnx2x_set_disable_pmd_transmit(struct link_params *params,
  6870. struct bnx2x_phy *phy,
  6871. u8 pmd_dis)
  6872. {
  6873. struct bnx2x *bp = params->bp;
  6874. /* Disable transmitter only for bootcodes which can enable it afterwards
  6875. * (for D3 link)
  6876. */
  6877. if (pmd_dis) {
  6878. if (params->feature_config_flags &
  6879. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED)
  6880. DP(NETIF_MSG_LINK, "Disabling PMD transmitter\n");
  6881. else {
  6882. DP(NETIF_MSG_LINK, "NOT disabling PMD transmitter\n");
  6883. return;
  6884. }
  6885. } else
  6886. DP(NETIF_MSG_LINK, "Enabling PMD transmitter\n");
  6887. bnx2x_cl45_write(bp, phy,
  6888. MDIO_PMA_DEVAD,
  6889. MDIO_PMA_REG_TX_DISABLE, pmd_dis);
  6890. }
  6891. static u8 bnx2x_get_gpio_port(struct link_params *params)
  6892. {
  6893. u8 gpio_port;
  6894. u32 swap_val, swap_override;
  6895. struct bnx2x *bp = params->bp;
  6896. if (CHIP_IS_E2(bp))
  6897. gpio_port = BP_PATH(bp);
  6898. else
  6899. gpio_port = params->port;
  6900. swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
  6901. swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
  6902. return gpio_port ^ (swap_val && swap_override);
  6903. }
  6904. static void bnx2x_sfp_e1e2_set_transmitter(struct link_params *params,
  6905. struct bnx2x_phy *phy,
  6906. u8 tx_en)
  6907. {
  6908. u16 val;
  6909. u8 port = params->port;
  6910. struct bnx2x *bp = params->bp;
  6911. u32 tx_en_mode;
  6912. /* Disable/Enable transmitter ( TX laser of the SFP+ module.)*/
  6913. tx_en_mode = REG_RD(bp, params->shmem_base +
  6914. offsetof(struct shmem_region,
  6915. dev_info.port_hw_config[port].sfp_ctrl)) &
  6916. PORT_HW_CFG_TX_LASER_MASK;
  6917. DP(NETIF_MSG_LINK, "Setting transmitter tx_en=%x for port %x "
  6918. "mode = %x\n", tx_en, port, tx_en_mode);
  6919. switch (tx_en_mode) {
  6920. case PORT_HW_CFG_TX_LASER_MDIO:
  6921. bnx2x_cl45_read(bp, phy,
  6922. MDIO_PMA_DEVAD,
  6923. MDIO_PMA_REG_PHY_IDENTIFIER,
  6924. &val);
  6925. if (tx_en)
  6926. val &= ~(1<<15);
  6927. else
  6928. val |= (1<<15);
  6929. bnx2x_cl45_write(bp, phy,
  6930. MDIO_PMA_DEVAD,
  6931. MDIO_PMA_REG_PHY_IDENTIFIER,
  6932. val);
  6933. break;
  6934. case PORT_HW_CFG_TX_LASER_GPIO0:
  6935. case PORT_HW_CFG_TX_LASER_GPIO1:
  6936. case PORT_HW_CFG_TX_LASER_GPIO2:
  6937. case PORT_HW_CFG_TX_LASER_GPIO3:
  6938. {
  6939. u16 gpio_pin;
  6940. u8 gpio_port, gpio_mode;
  6941. if (tx_en)
  6942. gpio_mode = MISC_REGISTERS_GPIO_OUTPUT_HIGH;
  6943. else
  6944. gpio_mode = MISC_REGISTERS_GPIO_OUTPUT_LOW;
  6945. gpio_pin = tx_en_mode - PORT_HW_CFG_TX_LASER_GPIO0;
  6946. gpio_port = bnx2x_get_gpio_port(params);
  6947. bnx2x_set_gpio(bp, gpio_pin, gpio_mode, gpio_port);
  6948. break;
  6949. }
  6950. default:
  6951. DP(NETIF_MSG_LINK, "Invalid TX_LASER_MDIO 0x%x\n", tx_en_mode);
  6952. break;
  6953. }
  6954. }
  6955. static void bnx2x_sfp_set_transmitter(struct link_params *params,
  6956. struct bnx2x_phy *phy,
  6957. u8 tx_en)
  6958. {
  6959. struct bnx2x *bp = params->bp;
  6960. DP(NETIF_MSG_LINK, "Setting SFP+ transmitter to %d\n", tx_en);
  6961. if (CHIP_IS_E3(bp))
  6962. bnx2x_sfp_e3_set_transmitter(params, phy, tx_en);
  6963. else
  6964. bnx2x_sfp_e1e2_set_transmitter(params, phy, tx_en);
  6965. }
  6966. static int bnx2x_8726_read_sfp_module_eeprom(struct bnx2x_phy *phy,
  6967. struct link_params *params,
  6968. u8 dev_addr, u16 addr, u8 byte_cnt,
  6969. u8 *o_buf, u8 is_init)
  6970. {
  6971. struct bnx2x *bp = params->bp;
  6972. u16 val = 0;
  6973. u16 i;
  6974. if (byte_cnt > SFP_EEPROM_PAGE_SIZE) {
  6975. DP(NETIF_MSG_LINK,
  6976. "Reading from eeprom is limited to 0xf\n");
  6977. return -EINVAL;
  6978. }
  6979. /* Set the read command byte count */
  6980. bnx2x_cl45_write(bp, phy,
  6981. MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_BYTE_CNT,
  6982. (byte_cnt | (dev_addr << 8)));
  6983. /* Set the read command address */
  6984. bnx2x_cl45_write(bp, phy,
  6985. MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_MEM_ADDR,
  6986. addr);
  6987. /* Activate read command */
  6988. bnx2x_cl45_write(bp, phy,
  6989. MDIO_PMA_DEVAD, MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
  6990. 0x2c0f);
  6991. /* Wait up to 500us for command complete status */
  6992. for (i = 0; i < 100; i++) {
  6993. bnx2x_cl45_read(bp, phy,
  6994. MDIO_PMA_DEVAD,
  6995. MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
  6996. if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
  6997. MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE)
  6998. break;
  6999. udelay(5);
  7000. }
  7001. if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) !=
  7002. MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE) {
  7003. DP(NETIF_MSG_LINK,
  7004. "Got bad status 0x%x when reading from SFP+ EEPROM\n",
  7005. (val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK));
  7006. return -EINVAL;
  7007. }
  7008. /* Read the buffer */
  7009. for (i = 0; i < byte_cnt; i++) {
  7010. bnx2x_cl45_read(bp, phy,
  7011. MDIO_PMA_DEVAD,
  7012. MDIO_PMA_REG_8726_TWO_WIRE_DATA_BUF + i, &val);
  7013. o_buf[i] = (u8)(val & MDIO_PMA_REG_8726_TWO_WIRE_DATA_MASK);
  7014. }
  7015. for (i = 0; i < 100; i++) {
  7016. bnx2x_cl45_read(bp, phy,
  7017. MDIO_PMA_DEVAD,
  7018. MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
  7019. if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
  7020. MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_IDLE)
  7021. return 0;
  7022. usleep_range(1000, 2000);
  7023. }
  7024. return -EINVAL;
  7025. }
  7026. static void bnx2x_warpcore_power_module(struct link_params *params,
  7027. u8 power)
  7028. {
  7029. u32 pin_cfg;
  7030. struct bnx2x *bp = params->bp;
  7031. pin_cfg = (REG_RD(bp, params->shmem_base +
  7032. offsetof(struct shmem_region,
  7033. dev_info.port_hw_config[params->port].e3_sfp_ctrl)) &
  7034. PORT_HW_CFG_E3_PWR_DIS_MASK) >>
  7035. PORT_HW_CFG_E3_PWR_DIS_SHIFT;
  7036. if (pin_cfg == PIN_CFG_NA)
  7037. return;
  7038. DP(NETIF_MSG_LINK, "Setting SFP+ module power to %d using pin cfg %d\n",
  7039. power, pin_cfg);
  7040. /* Low ==> corresponding SFP+ module is powered
  7041. * high ==> the SFP+ module is powered down
  7042. */
  7043. bnx2x_set_cfg_pin(bp, pin_cfg, power ^ 1);
  7044. }
  7045. static int bnx2x_warpcore_read_sfp_module_eeprom(struct bnx2x_phy *phy,
  7046. struct link_params *params,
  7047. u8 dev_addr,
  7048. u16 addr, u8 byte_cnt,
  7049. u8 *o_buf, u8 is_init)
  7050. {
  7051. int rc = 0;
  7052. u8 i, j = 0, cnt = 0;
  7053. u32 data_array[4];
  7054. u16 addr32;
  7055. struct bnx2x *bp = params->bp;
  7056. if (byte_cnt > SFP_EEPROM_PAGE_SIZE) {
  7057. DP(NETIF_MSG_LINK,
  7058. "Reading from eeprom is limited to 16 bytes\n");
  7059. return -EINVAL;
  7060. }
  7061. /* 4 byte aligned address */
  7062. addr32 = addr & (~0x3);
  7063. do {
  7064. if ((!is_init) && (cnt == I2C_WA_PWR_ITER)) {
  7065. bnx2x_warpcore_power_module(params, 0);
  7066. /* Note that 100us are not enough here */
  7067. usleep_range(1000, 2000);
  7068. bnx2x_warpcore_power_module(params, 1);
  7069. }
  7070. rc = bnx2x_bsc_read(params, bp, dev_addr, addr32, 0, byte_cnt,
  7071. data_array);
  7072. } while ((rc != 0) && (++cnt < I2C_WA_RETRY_CNT));
  7073. if (rc == 0) {
  7074. for (i = (addr - addr32); i < byte_cnt + (addr - addr32); i++) {
  7075. o_buf[j] = *((u8 *)data_array + i);
  7076. j++;
  7077. }
  7078. }
  7079. return rc;
  7080. }
  7081. static int bnx2x_8727_read_sfp_module_eeprom(struct bnx2x_phy *phy,
  7082. struct link_params *params,
  7083. u8 dev_addr, u16 addr, u8 byte_cnt,
  7084. u8 *o_buf, u8 is_init)
  7085. {
  7086. struct bnx2x *bp = params->bp;
  7087. u16 val, i;
  7088. if (byte_cnt > SFP_EEPROM_PAGE_SIZE) {
  7089. DP(NETIF_MSG_LINK,
  7090. "Reading from eeprom is limited to 0xf\n");
  7091. return -EINVAL;
  7092. }
  7093. /* Set 2-wire transfer rate of SFP+ module EEPROM
  7094. * to 100Khz since some DACs(direct attached cables) do
  7095. * not work at 400Khz.
  7096. */
  7097. bnx2x_cl45_write(bp, phy,
  7098. MDIO_PMA_DEVAD,
  7099. MDIO_PMA_REG_8727_TWO_WIRE_SLAVE_ADDR,
  7100. ((dev_addr << 8) | 1));
  7101. /* Need to read from 1.8000 to clear it */
  7102. bnx2x_cl45_read(bp, phy,
  7103. MDIO_PMA_DEVAD,
  7104. MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
  7105. &val);
  7106. /* Set the read command byte count */
  7107. bnx2x_cl45_write(bp, phy,
  7108. MDIO_PMA_DEVAD,
  7109. MDIO_PMA_REG_SFP_TWO_WIRE_BYTE_CNT,
  7110. ((byte_cnt < 2) ? 2 : byte_cnt));
  7111. /* Set the read command address */
  7112. bnx2x_cl45_write(bp, phy,
  7113. MDIO_PMA_DEVAD,
  7114. MDIO_PMA_REG_SFP_TWO_WIRE_MEM_ADDR,
  7115. addr);
  7116. /* Set the destination address */
  7117. bnx2x_cl45_write(bp, phy,
  7118. MDIO_PMA_DEVAD,
  7119. 0x8004,
  7120. MDIO_PMA_REG_8727_TWO_WIRE_DATA_BUF);
  7121. /* Activate read command */
  7122. bnx2x_cl45_write(bp, phy,
  7123. MDIO_PMA_DEVAD,
  7124. MDIO_PMA_REG_SFP_TWO_WIRE_CTRL,
  7125. 0x8002);
  7126. /* Wait appropriate time for two-wire command to finish before
  7127. * polling the status register
  7128. */
  7129. usleep_range(1000, 2000);
  7130. /* Wait up to 500us for command complete status */
  7131. for (i = 0; i < 100; i++) {
  7132. bnx2x_cl45_read(bp, phy,
  7133. MDIO_PMA_DEVAD,
  7134. MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
  7135. if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
  7136. MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE)
  7137. break;
  7138. udelay(5);
  7139. }
  7140. if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) !=
  7141. MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_COMPLETE) {
  7142. DP(NETIF_MSG_LINK,
  7143. "Got bad status 0x%x when reading from SFP+ EEPROM\n",
  7144. (val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK));
  7145. return -EFAULT;
  7146. }
  7147. /* Read the buffer */
  7148. for (i = 0; i < byte_cnt; i++) {
  7149. bnx2x_cl45_read(bp, phy,
  7150. MDIO_PMA_DEVAD,
  7151. MDIO_PMA_REG_8727_TWO_WIRE_DATA_BUF + i, &val);
  7152. o_buf[i] = (u8)(val & MDIO_PMA_REG_8727_TWO_WIRE_DATA_MASK);
  7153. }
  7154. for (i = 0; i < 100; i++) {
  7155. bnx2x_cl45_read(bp, phy,
  7156. MDIO_PMA_DEVAD,
  7157. MDIO_PMA_REG_SFP_TWO_WIRE_CTRL, &val);
  7158. if ((val & MDIO_PMA_REG_SFP_TWO_WIRE_CTRL_STATUS_MASK) ==
  7159. MDIO_PMA_REG_SFP_TWO_WIRE_STATUS_IDLE)
  7160. return 0;
  7161. usleep_range(1000, 2000);
  7162. }
  7163. return -EINVAL;
  7164. }
  7165. int bnx2x_read_sfp_module_eeprom(struct bnx2x_phy *phy,
  7166. struct link_params *params, u8 dev_addr,
  7167. u16 addr, u16 byte_cnt, u8 *o_buf)
  7168. {
  7169. int rc = 0;
  7170. struct bnx2x *bp = params->bp;
  7171. u8 xfer_size;
  7172. u8 *user_data = o_buf;
  7173. read_sfp_module_eeprom_func_p read_func;
  7174. if ((dev_addr != 0xa0) && (dev_addr != 0xa2)) {
  7175. DP(NETIF_MSG_LINK, "invalid dev_addr 0x%x\n", dev_addr);
  7176. return -EINVAL;
  7177. }
  7178. switch (phy->type) {
  7179. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
  7180. read_func = bnx2x_8726_read_sfp_module_eeprom;
  7181. break;
  7182. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
  7183. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
  7184. read_func = bnx2x_8727_read_sfp_module_eeprom;
  7185. break;
  7186. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
  7187. read_func = bnx2x_warpcore_read_sfp_module_eeprom;
  7188. break;
  7189. default:
  7190. return -EOPNOTSUPP;
  7191. }
  7192. while (!rc && (byte_cnt > 0)) {
  7193. xfer_size = (byte_cnt > SFP_EEPROM_PAGE_SIZE) ?
  7194. SFP_EEPROM_PAGE_SIZE : byte_cnt;
  7195. rc = read_func(phy, params, dev_addr, addr, xfer_size,
  7196. user_data, 0);
  7197. byte_cnt -= xfer_size;
  7198. user_data += xfer_size;
  7199. addr += xfer_size;
  7200. }
  7201. return rc;
  7202. }
  7203. static int bnx2x_get_edc_mode(struct bnx2x_phy *phy,
  7204. struct link_params *params,
  7205. u16 *edc_mode)
  7206. {
  7207. struct bnx2x *bp = params->bp;
  7208. u32 sync_offset = 0, phy_idx, media_types;
  7209. u8 val[SFP_EEPROM_FC_TX_TECH_ADDR + 1], check_limiting_mode = 0;
  7210. *edc_mode = EDC_MODE_LIMITING;
  7211. phy->media_type = ETH_PHY_UNSPECIFIED;
  7212. /* First check for copper cable */
  7213. if (bnx2x_read_sfp_module_eeprom(phy,
  7214. params,
  7215. I2C_DEV_ADDR_A0,
  7216. 0,
  7217. SFP_EEPROM_FC_TX_TECH_ADDR + 1,
  7218. (u8 *)val) != 0) {
  7219. DP(NETIF_MSG_LINK, "Failed to read from SFP+ module EEPROM\n");
  7220. return -EINVAL;
  7221. }
  7222. params->link_attr_sync &= ~LINK_SFP_EEPROM_COMP_CODE_MASK;
  7223. params->link_attr_sync |= val[SFP_EEPROM_10G_COMP_CODE_ADDR] <<
  7224. LINK_SFP_EEPROM_COMP_CODE_SHIFT;
  7225. bnx2x_update_link_attr(params, params->link_attr_sync);
  7226. switch (val[SFP_EEPROM_CON_TYPE_ADDR]) {
  7227. case SFP_EEPROM_CON_TYPE_VAL_COPPER:
  7228. {
  7229. u8 copper_module_type;
  7230. phy->media_type = ETH_PHY_DA_TWINAX;
  7231. /* Check if its active cable (includes SFP+ module)
  7232. * of passive cable
  7233. */
  7234. copper_module_type = val[SFP_EEPROM_FC_TX_TECH_ADDR];
  7235. if (copper_module_type &
  7236. SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_ACTIVE) {
  7237. DP(NETIF_MSG_LINK, "Active Copper cable detected\n");
  7238. if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  7239. *edc_mode = EDC_MODE_ACTIVE_DAC;
  7240. else
  7241. check_limiting_mode = 1;
  7242. } else {
  7243. *edc_mode = EDC_MODE_PASSIVE_DAC;
  7244. /* Even in case PASSIVE_DAC indication is not set,
  7245. * treat it as a passive DAC cable, since some cables
  7246. * don't have this indication.
  7247. */
  7248. if (copper_module_type &
  7249. SFP_EEPROM_FC_TX_TECH_BITMASK_COPPER_PASSIVE) {
  7250. DP(NETIF_MSG_LINK,
  7251. "Passive Copper cable detected\n");
  7252. } else {
  7253. DP(NETIF_MSG_LINK,
  7254. "Unknown copper-cable-type\n");
  7255. }
  7256. }
  7257. break;
  7258. }
  7259. case SFP_EEPROM_CON_TYPE_VAL_UNKNOWN:
  7260. case SFP_EEPROM_CON_TYPE_VAL_LC:
  7261. case SFP_EEPROM_CON_TYPE_VAL_RJ45:
  7262. check_limiting_mode = 1;
  7263. if (((val[SFP_EEPROM_10G_COMP_CODE_ADDR] &
  7264. (SFP_EEPROM_10G_COMP_CODE_SR_MASK |
  7265. SFP_EEPROM_10G_COMP_CODE_LR_MASK |
  7266. SFP_EEPROM_10G_COMP_CODE_LRM_MASK)) == 0) &&
  7267. (val[SFP_EEPROM_1G_COMP_CODE_ADDR] != 0)) {
  7268. DP(NETIF_MSG_LINK, "1G SFP module detected\n");
  7269. phy->media_type = ETH_PHY_SFP_1G_FIBER;
  7270. if (phy->req_line_speed != SPEED_1000) {
  7271. u8 gport = params->port;
  7272. phy->req_line_speed = SPEED_1000;
  7273. if (!CHIP_IS_E1x(bp)) {
  7274. gport = BP_PATH(bp) +
  7275. (params->port << 1);
  7276. }
  7277. netdev_err(bp->dev,
  7278. "Warning: Link speed was forced to 1000Mbps. Current SFP module in port %d is not compliant with 10G Ethernet\n",
  7279. gport);
  7280. }
  7281. if (val[SFP_EEPROM_1G_COMP_CODE_ADDR] &
  7282. SFP_EEPROM_1G_COMP_CODE_BASE_T) {
  7283. bnx2x_sfp_set_transmitter(params, phy, 0);
  7284. msleep(40);
  7285. bnx2x_sfp_set_transmitter(params, phy, 1);
  7286. }
  7287. } else {
  7288. int idx, cfg_idx = 0;
  7289. DP(NETIF_MSG_LINK, "10G Optic module detected\n");
  7290. for (idx = INT_PHY; idx < MAX_PHYS; idx++) {
  7291. if (params->phy[idx].type == phy->type) {
  7292. cfg_idx = LINK_CONFIG_IDX(idx);
  7293. break;
  7294. }
  7295. }
  7296. phy->media_type = ETH_PHY_SFPP_10G_FIBER;
  7297. phy->req_line_speed = params->req_line_speed[cfg_idx];
  7298. }
  7299. break;
  7300. default:
  7301. DP(NETIF_MSG_LINK, "Unable to determine module type 0x%x !!!\n",
  7302. val[SFP_EEPROM_CON_TYPE_ADDR]);
  7303. return -EINVAL;
  7304. }
  7305. sync_offset = params->shmem_base +
  7306. offsetof(struct shmem_region,
  7307. dev_info.port_hw_config[params->port].media_type);
  7308. media_types = REG_RD(bp, sync_offset);
  7309. /* Update media type for non-PMF sync */
  7310. for (phy_idx = INT_PHY; phy_idx < MAX_PHYS; phy_idx++) {
  7311. if (&(params->phy[phy_idx]) == phy) {
  7312. media_types &= ~(PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK <<
  7313. (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT * phy_idx));
  7314. media_types |= ((phy->media_type &
  7315. PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK) <<
  7316. (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT * phy_idx));
  7317. break;
  7318. }
  7319. }
  7320. REG_WR(bp, sync_offset, media_types);
  7321. if (check_limiting_mode) {
  7322. u8 options[SFP_EEPROM_OPTIONS_SIZE];
  7323. if (bnx2x_read_sfp_module_eeprom(phy,
  7324. params,
  7325. I2C_DEV_ADDR_A0,
  7326. SFP_EEPROM_OPTIONS_ADDR,
  7327. SFP_EEPROM_OPTIONS_SIZE,
  7328. options) != 0) {
  7329. DP(NETIF_MSG_LINK,
  7330. "Failed to read Option field from module EEPROM\n");
  7331. return -EINVAL;
  7332. }
  7333. if ((options[0] & SFP_EEPROM_OPTIONS_LINEAR_RX_OUT_MASK))
  7334. *edc_mode = EDC_MODE_LINEAR;
  7335. else
  7336. *edc_mode = EDC_MODE_LIMITING;
  7337. }
  7338. DP(NETIF_MSG_LINK, "EDC mode is set to 0x%x\n", *edc_mode);
  7339. return 0;
  7340. }
  7341. /* This function read the relevant field from the module (SFP+), and verify it
  7342. * is compliant with this board
  7343. */
  7344. static int bnx2x_verify_sfp_module(struct bnx2x_phy *phy,
  7345. struct link_params *params)
  7346. {
  7347. struct bnx2x *bp = params->bp;
  7348. u32 val, cmd;
  7349. u32 fw_resp, fw_cmd_param;
  7350. char vendor_name[SFP_EEPROM_VENDOR_NAME_SIZE+1];
  7351. char vendor_pn[SFP_EEPROM_PART_NO_SIZE+1];
  7352. phy->flags &= ~FLAGS_SFP_NOT_APPROVED;
  7353. val = REG_RD(bp, params->shmem_base +
  7354. offsetof(struct shmem_region, dev_info.
  7355. port_feature_config[params->port].config));
  7356. if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
  7357. PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_NO_ENFORCEMENT) {
  7358. DP(NETIF_MSG_LINK, "NOT enforcing module verification\n");
  7359. return 0;
  7360. }
  7361. if (params->feature_config_flags &
  7362. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY) {
  7363. /* Use specific phy request */
  7364. cmd = DRV_MSG_CODE_VRFY_SPECIFIC_PHY_OPT_MDL;
  7365. } else if (params->feature_config_flags &
  7366. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY) {
  7367. /* Use first phy request only in case of non-dual media*/
  7368. if (DUAL_MEDIA(params)) {
  7369. DP(NETIF_MSG_LINK,
  7370. "FW does not support OPT MDL verification\n");
  7371. return -EINVAL;
  7372. }
  7373. cmd = DRV_MSG_CODE_VRFY_FIRST_PHY_OPT_MDL;
  7374. } else {
  7375. /* No support in OPT MDL detection */
  7376. DP(NETIF_MSG_LINK,
  7377. "FW does not support OPT MDL verification\n");
  7378. return -EINVAL;
  7379. }
  7380. fw_cmd_param = FW_PARAM_SET(phy->addr, phy->type, phy->mdio_ctrl);
  7381. fw_resp = bnx2x_fw_command(bp, cmd, fw_cmd_param);
  7382. if (fw_resp == FW_MSG_CODE_VRFY_OPT_MDL_SUCCESS) {
  7383. DP(NETIF_MSG_LINK, "Approved module\n");
  7384. return 0;
  7385. }
  7386. /* Format the warning message */
  7387. if (bnx2x_read_sfp_module_eeprom(phy,
  7388. params,
  7389. I2C_DEV_ADDR_A0,
  7390. SFP_EEPROM_VENDOR_NAME_ADDR,
  7391. SFP_EEPROM_VENDOR_NAME_SIZE,
  7392. (u8 *)vendor_name))
  7393. vendor_name[0] = '\0';
  7394. else
  7395. vendor_name[SFP_EEPROM_VENDOR_NAME_SIZE] = '\0';
  7396. if (bnx2x_read_sfp_module_eeprom(phy,
  7397. params,
  7398. I2C_DEV_ADDR_A0,
  7399. SFP_EEPROM_PART_NO_ADDR,
  7400. SFP_EEPROM_PART_NO_SIZE,
  7401. (u8 *)vendor_pn))
  7402. vendor_pn[0] = '\0';
  7403. else
  7404. vendor_pn[SFP_EEPROM_PART_NO_SIZE] = '\0';
  7405. netdev_err(bp->dev, "Warning: Unqualified SFP+ module detected,"
  7406. " Port %d from %s part number %s\n",
  7407. params->port, vendor_name, vendor_pn);
  7408. if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) !=
  7409. PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_WARNING_MSG)
  7410. phy->flags |= FLAGS_SFP_NOT_APPROVED;
  7411. return -EINVAL;
  7412. }
  7413. static int bnx2x_wait_for_sfp_module_initialized(struct bnx2x_phy *phy,
  7414. struct link_params *params)
  7415. {
  7416. u8 val;
  7417. int rc;
  7418. struct bnx2x *bp = params->bp;
  7419. u16 timeout;
  7420. /* Initialization time after hot-plug may take up to 300ms for
  7421. * some phys type ( e.g. JDSU )
  7422. */
  7423. for (timeout = 0; timeout < 60; timeout++) {
  7424. if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  7425. rc = bnx2x_warpcore_read_sfp_module_eeprom(
  7426. phy, params, I2C_DEV_ADDR_A0, 1, 1, &val,
  7427. 1);
  7428. else
  7429. rc = bnx2x_read_sfp_module_eeprom(phy, params,
  7430. I2C_DEV_ADDR_A0,
  7431. 1, 1, &val);
  7432. if (rc == 0) {
  7433. DP(NETIF_MSG_LINK,
  7434. "SFP+ module initialization took %d ms\n",
  7435. timeout * 5);
  7436. return 0;
  7437. }
  7438. usleep_range(5000, 10000);
  7439. }
  7440. rc = bnx2x_read_sfp_module_eeprom(phy, params, I2C_DEV_ADDR_A0,
  7441. 1, 1, &val);
  7442. return rc;
  7443. }
  7444. static void bnx2x_8727_power_module(struct bnx2x *bp,
  7445. struct bnx2x_phy *phy,
  7446. u8 is_power_up) {
  7447. /* Make sure GPIOs are not using for LED mode */
  7448. u16 val;
  7449. /* In the GPIO register, bit 4 is use to determine if the GPIOs are
  7450. * operating as INPUT or as OUTPUT. Bit 1 is for input, and 0 for
  7451. * output
  7452. * Bits 0-1 determine the GPIOs value for OUTPUT in case bit 4 val is 0
  7453. * Bits 8-9 determine the GPIOs value for INPUT in case bit 4 val is 1
  7454. * where the 1st bit is the over-current(only input), and 2nd bit is
  7455. * for power( only output )
  7456. *
  7457. * In case of NOC feature is disabled and power is up, set GPIO control
  7458. * as input to enable listening of over-current indication
  7459. */
  7460. if (phy->flags & FLAGS_NOC)
  7461. return;
  7462. if (is_power_up)
  7463. val = (1<<4);
  7464. else
  7465. /* Set GPIO control to OUTPUT, and set the power bit
  7466. * to according to the is_power_up
  7467. */
  7468. val = (1<<1);
  7469. bnx2x_cl45_write(bp, phy,
  7470. MDIO_PMA_DEVAD,
  7471. MDIO_PMA_REG_8727_GPIO_CTRL,
  7472. val);
  7473. }
  7474. static int bnx2x_8726_set_limiting_mode(struct bnx2x *bp,
  7475. struct bnx2x_phy *phy,
  7476. u16 edc_mode)
  7477. {
  7478. u16 cur_limiting_mode;
  7479. bnx2x_cl45_read(bp, phy,
  7480. MDIO_PMA_DEVAD,
  7481. MDIO_PMA_REG_ROM_VER2,
  7482. &cur_limiting_mode);
  7483. DP(NETIF_MSG_LINK, "Current Limiting mode is 0x%x\n",
  7484. cur_limiting_mode);
  7485. if (edc_mode == EDC_MODE_LIMITING) {
  7486. DP(NETIF_MSG_LINK, "Setting LIMITING MODE\n");
  7487. bnx2x_cl45_write(bp, phy,
  7488. MDIO_PMA_DEVAD,
  7489. MDIO_PMA_REG_ROM_VER2,
  7490. EDC_MODE_LIMITING);
  7491. } else { /* LRM mode ( default )*/
  7492. DP(NETIF_MSG_LINK, "Setting LRM MODE\n");
  7493. /* Changing to LRM mode takes quite few seconds. So do it only
  7494. * if current mode is limiting (default is LRM)
  7495. */
  7496. if (cur_limiting_mode != EDC_MODE_LIMITING)
  7497. return 0;
  7498. bnx2x_cl45_write(bp, phy,
  7499. MDIO_PMA_DEVAD,
  7500. MDIO_PMA_REG_LRM_MODE,
  7501. 0);
  7502. bnx2x_cl45_write(bp, phy,
  7503. MDIO_PMA_DEVAD,
  7504. MDIO_PMA_REG_ROM_VER2,
  7505. 0x128);
  7506. bnx2x_cl45_write(bp, phy,
  7507. MDIO_PMA_DEVAD,
  7508. MDIO_PMA_REG_MISC_CTRL0,
  7509. 0x4008);
  7510. bnx2x_cl45_write(bp, phy,
  7511. MDIO_PMA_DEVAD,
  7512. MDIO_PMA_REG_LRM_MODE,
  7513. 0xaaaa);
  7514. }
  7515. return 0;
  7516. }
  7517. static int bnx2x_8727_set_limiting_mode(struct bnx2x *bp,
  7518. struct bnx2x_phy *phy,
  7519. u16 edc_mode)
  7520. {
  7521. u16 phy_identifier;
  7522. u16 rom_ver2_val;
  7523. bnx2x_cl45_read(bp, phy,
  7524. MDIO_PMA_DEVAD,
  7525. MDIO_PMA_REG_PHY_IDENTIFIER,
  7526. &phy_identifier);
  7527. bnx2x_cl45_write(bp, phy,
  7528. MDIO_PMA_DEVAD,
  7529. MDIO_PMA_REG_PHY_IDENTIFIER,
  7530. (phy_identifier & ~(1<<9)));
  7531. bnx2x_cl45_read(bp, phy,
  7532. MDIO_PMA_DEVAD,
  7533. MDIO_PMA_REG_ROM_VER2,
  7534. &rom_ver2_val);
  7535. /* Keep the MSB 8-bits, and set the LSB 8-bits with the edc_mode */
  7536. bnx2x_cl45_write(bp, phy,
  7537. MDIO_PMA_DEVAD,
  7538. MDIO_PMA_REG_ROM_VER2,
  7539. (rom_ver2_val & 0xff00) | (edc_mode & 0x00ff));
  7540. bnx2x_cl45_write(bp, phy,
  7541. MDIO_PMA_DEVAD,
  7542. MDIO_PMA_REG_PHY_IDENTIFIER,
  7543. (phy_identifier | (1<<9)));
  7544. return 0;
  7545. }
  7546. static void bnx2x_8727_specific_func(struct bnx2x_phy *phy,
  7547. struct link_params *params,
  7548. u32 action)
  7549. {
  7550. struct bnx2x *bp = params->bp;
  7551. u16 val;
  7552. switch (action) {
  7553. case DISABLE_TX:
  7554. bnx2x_sfp_set_transmitter(params, phy, 0);
  7555. break;
  7556. case ENABLE_TX:
  7557. if (!(phy->flags & FLAGS_SFP_NOT_APPROVED))
  7558. bnx2x_sfp_set_transmitter(params, phy, 1);
  7559. break;
  7560. case PHY_INIT:
  7561. bnx2x_cl45_write(bp, phy,
  7562. MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
  7563. (1<<2) | (1<<5));
  7564. bnx2x_cl45_write(bp, phy,
  7565. MDIO_PMA_DEVAD, MDIO_PMA_LASI_TXCTRL,
  7566. 0);
  7567. bnx2x_cl45_write(bp, phy,
  7568. MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x0006);
  7569. /* Make MOD_ABS give interrupt on change */
  7570. bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
  7571. MDIO_PMA_REG_8727_PCS_OPT_CTRL,
  7572. &val);
  7573. val |= (1<<12);
  7574. if (phy->flags & FLAGS_NOC)
  7575. val |= (3<<5);
  7576. /* Set 8727 GPIOs to input to allow reading from the 8727 GPIO0
  7577. * status which reflect SFP+ module over-current
  7578. */
  7579. if (!(phy->flags & FLAGS_NOC))
  7580. val &= 0xff8f; /* Reset bits 4-6 */
  7581. bnx2x_cl45_write(bp, phy,
  7582. MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_PCS_OPT_CTRL,
  7583. val);
  7584. break;
  7585. default:
  7586. DP(NETIF_MSG_LINK, "Function 0x%x not supported by 8727\n",
  7587. action);
  7588. return;
  7589. }
  7590. }
  7591. static void bnx2x_set_e1e2_module_fault_led(struct link_params *params,
  7592. u8 gpio_mode)
  7593. {
  7594. struct bnx2x *bp = params->bp;
  7595. u32 fault_led_gpio = REG_RD(bp, params->shmem_base +
  7596. offsetof(struct shmem_region,
  7597. dev_info.port_hw_config[params->port].sfp_ctrl)) &
  7598. PORT_HW_CFG_FAULT_MODULE_LED_MASK;
  7599. switch (fault_led_gpio) {
  7600. case PORT_HW_CFG_FAULT_MODULE_LED_DISABLED:
  7601. return;
  7602. case PORT_HW_CFG_FAULT_MODULE_LED_GPIO0:
  7603. case PORT_HW_CFG_FAULT_MODULE_LED_GPIO1:
  7604. case PORT_HW_CFG_FAULT_MODULE_LED_GPIO2:
  7605. case PORT_HW_CFG_FAULT_MODULE_LED_GPIO3:
  7606. {
  7607. u8 gpio_port = bnx2x_get_gpio_port(params);
  7608. u16 gpio_pin = fault_led_gpio -
  7609. PORT_HW_CFG_FAULT_MODULE_LED_GPIO0;
  7610. DP(NETIF_MSG_LINK, "Set fault module-detected led "
  7611. "pin %x port %x mode %x\n",
  7612. gpio_pin, gpio_port, gpio_mode);
  7613. bnx2x_set_gpio(bp, gpio_pin, gpio_mode, gpio_port);
  7614. }
  7615. break;
  7616. default:
  7617. DP(NETIF_MSG_LINK, "Error: Invalid fault led mode 0x%x\n",
  7618. fault_led_gpio);
  7619. }
  7620. }
  7621. static void bnx2x_set_e3_module_fault_led(struct link_params *params,
  7622. u8 gpio_mode)
  7623. {
  7624. u32 pin_cfg;
  7625. u8 port = params->port;
  7626. struct bnx2x *bp = params->bp;
  7627. pin_cfg = (REG_RD(bp, params->shmem_base +
  7628. offsetof(struct shmem_region,
  7629. dev_info.port_hw_config[port].e3_sfp_ctrl)) &
  7630. PORT_HW_CFG_E3_FAULT_MDL_LED_MASK) >>
  7631. PORT_HW_CFG_E3_FAULT_MDL_LED_SHIFT;
  7632. DP(NETIF_MSG_LINK, "Setting Fault LED to %d using pin cfg %d\n",
  7633. gpio_mode, pin_cfg);
  7634. bnx2x_set_cfg_pin(bp, pin_cfg, gpio_mode);
  7635. }
  7636. static void bnx2x_set_sfp_module_fault_led(struct link_params *params,
  7637. u8 gpio_mode)
  7638. {
  7639. struct bnx2x *bp = params->bp;
  7640. DP(NETIF_MSG_LINK, "Setting SFP+ module fault LED to %d\n", gpio_mode);
  7641. if (CHIP_IS_E3(bp)) {
  7642. /* Low ==> if SFP+ module is supported otherwise
  7643. * High ==> if SFP+ module is not on the approved vendor list
  7644. */
  7645. bnx2x_set_e3_module_fault_led(params, gpio_mode);
  7646. } else
  7647. bnx2x_set_e1e2_module_fault_led(params, gpio_mode);
  7648. }
  7649. static void bnx2x_warpcore_hw_reset(struct bnx2x_phy *phy,
  7650. struct link_params *params)
  7651. {
  7652. struct bnx2x *bp = params->bp;
  7653. bnx2x_warpcore_power_module(params, 0);
  7654. /* Put Warpcore in low power mode */
  7655. REG_WR(bp, MISC_REG_WC0_RESET, 0x0c0e);
  7656. /* Put LCPLL in low power mode */
  7657. REG_WR(bp, MISC_REG_LCPLL_E40_PWRDWN, 1);
  7658. REG_WR(bp, MISC_REG_LCPLL_E40_RESETB_ANA, 0);
  7659. REG_WR(bp, MISC_REG_LCPLL_E40_RESETB_DIG, 0);
  7660. }
  7661. static void bnx2x_power_sfp_module(struct link_params *params,
  7662. struct bnx2x_phy *phy,
  7663. u8 power)
  7664. {
  7665. struct bnx2x *bp = params->bp;
  7666. DP(NETIF_MSG_LINK, "Setting SFP+ power to %x\n", power);
  7667. switch (phy->type) {
  7668. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
  7669. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
  7670. bnx2x_8727_power_module(params->bp, phy, power);
  7671. break;
  7672. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
  7673. bnx2x_warpcore_power_module(params, power);
  7674. break;
  7675. default:
  7676. break;
  7677. }
  7678. }
  7679. static void bnx2x_warpcore_set_limiting_mode(struct link_params *params,
  7680. struct bnx2x_phy *phy,
  7681. u16 edc_mode)
  7682. {
  7683. u16 val = 0;
  7684. u16 mode = MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE_DEFAULT;
  7685. struct bnx2x *bp = params->bp;
  7686. u8 lane = bnx2x_get_warpcore_lane(phy, params);
  7687. /* This is a global register which controls all lanes */
  7688. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
  7689. MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE, &val);
  7690. val &= ~(0xf << (lane << 2));
  7691. switch (edc_mode) {
  7692. case EDC_MODE_LINEAR:
  7693. case EDC_MODE_LIMITING:
  7694. mode = MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE_DEFAULT;
  7695. break;
  7696. case EDC_MODE_PASSIVE_DAC:
  7697. case EDC_MODE_ACTIVE_DAC:
  7698. mode = MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE_SFP_DAC;
  7699. break;
  7700. default:
  7701. break;
  7702. }
  7703. val |= (mode << (lane << 2));
  7704. bnx2x_cl45_write(bp, phy, MDIO_WC_DEVAD,
  7705. MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE, val);
  7706. /* A must read */
  7707. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
  7708. MDIO_WC_REG_UC_INFO_B1_FIRMWARE_MODE, &val);
  7709. /* Restart microcode to re-read the new mode */
  7710. bnx2x_warpcore_reset_lane(bp, phy, 1);
  7711. bnx2x_warpcore_reset_lane(bp, phy, 0);
  7712. }
  7713. static void bnx2x_set_limiting_mode(struct link_params *params,
  7714. struct bnx2x_phy *phy,
  7715. u16 edc_mode)
  7716. {
  7717. switch (phy->type) {
  7718. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
  7719. bnx2x_8726_set_limiting_mode(params->bp, phy, edc_mode);
  7720. break;
  7721. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
  7722. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
  7723. bnx2x_8727_set_limiting_mode(params->bp, phy, edc_mode);
  7724. break;
  7725. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
  7726. bnx2x_warpcore_set_limiting_mode(params, phy, edc_mode);
  7727. break;
  7728. }
  7729. }
  7730. static int bnx2x_sfp_module_detection(struct bnx2x_phy *phy,
  7731. struct link_params *params)
  7732. {
  7733. struct bnx2x *bp = params->bp;
  7734. u16 edc_mode;
  7735. int rc = 0;
  7736. u32 val = REG_RD(bp, params->shmem_base +
  7737. offsetof(struct shmem_region, dev_info.
  7738. port_feature_config[params->port].config));
  7739. /* Enabled transmitter by default */
  7740. bnx2x_sfp_set_transmitter(params, phy, 1);
  7741. DP(NETIF_MSG_LINK, "SFP+ module plugged in/out detected on port %d\n",
  7742. params->port);
  7743. /* Power up module */
  7744. bnx2x_power_sfp_module(params, phy, 1);
  7745. if (bnx2x_get_edc_mode(phy, params, &edc_mode) != 0) {
  7746. DP(NETIF_MSG_LINK, "Failed to get valid module type\n");
  7747. return -EINVAL;
  7748. } else if (bnx2x_verify_sfp_module(phy, params) != 0) {
  7749. /* Check SFP+ module compatibility */
  7750. DP(NETIF_MSG_LINK, "Module verification failed!!\n");
  7751. rc = -EINVAL;
  7752. /* Turn on fault module-detected led */
  7753. bnx2x_set_sfp_module_fault_led(params,
  7754. MISC_REGISTERS_GPIO_HIGH);
  7755. /* Check if need to power down the SFP+ module */
  7756. if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
  7757. PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_POWER_DOWN) {
  7758. DP(NETIF_MSG_LINK, "Shutdown SFP+ module!!\n");
  7759. bnx2x_power_sfp_module(params, phy, 0);
  7760. return rc;
  7761. }
  7762. } else {
  7763. /* Turn off fault module-detected led */
  7764. bnx2x_set_sfp_module_fault_led(params, MISC_REGISTERS_GPIO_LOW);
  7765. }
  7766. /* Check and set limiting mode / LRM mode on 8726. On 8727 it
  7767. * is done automatically
  7768. */
  7769. bnx2x_set_limiting_mode(params, phy, edc_mode);
  7770. /* Disable transmit for this module if the module is not approved, and
  7771. * laser needs to be disabled.
  7772. */
  7773. if ((rc) &&
  7774. ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
  7775. PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER))
  7776. bnx2x_sfp_set_transmitter(params, phy, 0);
  7777. return rc;
  7778. }
  7779. void bnx2x_handle_module_detect_int(struct link_params *params)
  7780. {
  7781. struct bnx2x *bp = params->bp;
  7782. struct bnx2x_phy *phy;
  7783. u32 gpio_val;
  7784. u8 gpio_num, gpio_port;
  7785. if (CHIP_IS_E3(bp)) {
  7786. phy = &params->phy[INT_PHY];
  7787. /* Always enable TX laser,will be disabled in case of fault */
  7788. bnx2x_sfp_set_transmitter(params, phy, 1);
  7789. } else {
  7790. phy = &params->phy[EXT_PHY1];
  7791. }
  7792. if (bnx2x_get_mod_abs_int_cfg(bp, params->chip_id, params->shmem_base,
  7793. params->port, &gpio_num, &gpio_port) ==
  7794. -EINVAL) {
  7795. DP(NETIF_MSG_LINK, "Failed to get MOD_ABS interrupt config\n");
  7796. return;
  7797. }
  7798. /* Set valid module led off */
  7799. bnx2x_set_sfp_module_fault_led(params, MISC_REGISTERS_GPIO_HIGH);
  7800. /* Get current gpio val reflecting module plugged in / out*/
  7801. gpio_val = bnx2x_get_gpio(bp, gpio_num, gpio_port);
  7802. /* Call the handling function in case module is detected */
  7803. if (gpio_val == 0) {
  7804. bnx2x_set_mdio_emac_per_phy(bp, params);
  7805. bnx2x_set_aer_mmd(params, phy);
  7806. bnx2x_power_sfp_module(params, phy, 1);
  7807. bnx2x_set_gpio_int(bp, gpio_num,
  7808. MISC_REGISTERS_GPIO_INT_OUTPUT_CLR,
  7809. gpio_port);
  7810. if (bnx2x_wait_for_sfp_module_initialized(phy, params) == 0) {
  7811. bnx2x_sfp_module_detection(phy, params);
  7812. if (CHIP_IS_E3(bp)) {
  7813. u16 rx_tx_in_reset;
  7814. /* In case WC is out of reset, reconfigure the
  7815. * link speed while taking into account 1G
  7816. * module limitation.
  7817. */
  7818. bnx2x_cl45_read(bp, phy,
  7819. MDIO_WC_DEVAD,
  7820. MDIO_WC_REG_DIGITAL5_MISC6,
  7821. &rx_tx_in_reset);
  7822. if ((!rx_tx_in_reset) &&
  7823. (params->link_flags &
  7824. PHY_INITIALIZED)) {
  7825. bnx2x_warpcore_reset_lane(bp, phy, 1);
  7826. bnx2x_warpcore_config_sfi(phy, params);
  7827. bnx2x_warpcore_reset_lane(bp, phy, 0);
  7828. }
  7829. }
  7830. } else {
  7831. DP(NETIF_MSG_LINK, "SFP+ module is not initialized\n");
  7832. }
  7833. } else {
  7834. bnx2x_set_gpio_int(bp, gpio_num,
  7835. MISC_REGISTERS_GPIO_INT_OUTPUT_SET,
  7836. gpio_port);
  7837. /* Module was plugged out.
  7838. * Disable transmit for this module
  7839. */
  7840. phy->media_type = ETH_PHY_NOT_PRESENT;
  7841. }
  7842. }
  7843. /******************************************************************/
  7844. /* Used by 8706 and 8727 */
  7845. /******************************************************************/
  7846. static void bnx2x_sfp_mask_fault(struct bnx2x *bp,
  7847. struct bnx2x_phy *phy,
  7848. u16 alarm_status_offset,
  7849. u16 alarm_ctrl_offset)
  7850. {
  7851. u16 alarm_status, val;
  7852. bnx2x_cl45_read(bp, phy,
  7853. MDIO_PMA_DEVAD, alarm_status_offset,
  7854. &alarm_status);
  7855. bnx2x_cl45_read(bp, phy,
  7856. MDIO_PMA_DEVAD, alarm_status_offset,
  7857. &alarm_status);
  7858. /* Mask or enable the fault event. */
  7859. bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, alarm_ctrl_offset, &val);
  7860. if (alarm_status & (1<<0))
  7861. val &= ~(1<<0);
  7862. else
  7863. val |= (1<<0);
  7864. bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, alarm_ctrl_offset, val);
  7865. }
  7866. /******************************************************************/
  7867. /* common BCM8706/BCM8726 PHY SECTION */
  7868. /******************************************************************/
  7869. static u8 bnx2x_8706_8726_read_status(struct bnx2x_phy *phy,
  7870. struct link_params *params,
  7871. struct link_vars *vars)
  7872. {
  7873. u8 link_up = 0;
  7874. u16 val1, val2, rx_sd, pcs_status;
  7875. struct bnx2x *bp = params->bp;
  7876. DP(NETIF_MSG_LINK, "XGXS 8706/8726\n");
  7877. /* Clear RX Alarm*/
  7878. bnx2x_cl45_read(bp, phy,
  7879. MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT, &val2);
  7880. bnx2x_sfp_mask_fault(bp, phy, MDIO_PMA_LASI_TXSTAT,
  7881. MDIO_PMA_LASI_TXCTRL);
  7882. /* Clear LASI indication*/
  7883. bnx2x_cl45_read(bp, phy,
  7884. MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val1);
  7885. bnx2x_cl45_read(bp, phy,
  7886. MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val2);
  7887. DP(NETIF_MSG_LINK, "8706/8726 LASI status 0x%x--> 0x%x\n", val1, val2);
  7888. bnx2x_cl45_read(bp, phy,
  7889. MDIO_PMA_DEVAD, MDIO_PMA_REG_RX_SD, &rx_sd);
  7890. bnx2x_cl45_read(bp, phy,
  7891. MDIO_PCS_DEVAD, MDIO_PCS_REG_STATUS, &pcs_status);
  7892. bnx2x_cl45_read(bp, phy,
  7893. MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &val2);
  7894. bnx2x_cl45_read(bp, phy,
  7895. MDIO_AN_DEVAD, MDIO_AN_REG_LINK_STATUS, &val2);
  7896. DP(NETIF_MSG_LINK, "8706/8726 rx_sd 0x%x pcs_status 0x%x 1Gbps"
  7897. " link_status 0x%x\n", rx_sd, pcs_status, val2);
  7898. /* Link is up if both bit 0 of pmd_rx_sd and bit 0 of pcs_status
  7899. * are set, or if the autoneg bit 1 is set
  7900. */
  7901. link_up = ((rx_sd & pcs_status & 0x1) || (val2 & (1<<1)));
  7902. if (link_up) {
  7903. if (val2 & (1<<1))
  7904. vars->line_speed = SPEED_1000;
  7905. else
  7906. vars->line_speed = SPEED_10000;
  7907. bnx2x_ext_phy_resolve_fc(phy, params, vars);
  7908. vars->duplex = DUPLEX_FULL;
  7909. }
  7910. /* Capture 10G link fault. Read twice to clear stale value. */
  7911. if (vars->line_speed == SPEED_10000) {
  7912. bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
  7913. MDIO_PMA_LASI_TXSTAT, &val1);
  7914. bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
  7915. MDIO_PMA_LASI_TXSTAT, &val1);
  7916. if (val1 & (1<<0))
  7917. vars->fault_detected = 1;
  7918. }
  7919. return link_up;
  7920. }
  7921. /******************************************************************/
  7922. /* BCM8706 PHY SECTION */
  7923. /******************************************************************/
  7924. static u8 bnx2x_8706_config_init(struct bnx2x_phy *phy,
  7925. struct link_params *params,
  7926. struct link_vars *vars)
  7927. {
  7928. u32 tx_en_mode;
  7929. u16 cnt, val, tmp1;
  7930. struct bnx2x *bp = params->bp;
  7931. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
  7932. MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
  7933. /* HW reset */
  7934. bnx2x_ext_phy_hw_reset(bp, params->port);
  7935. bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0xa040);
  7936. bnx2x_wait_reset_complete(bp, phy, params);
  7937. /* Wait until fw is loaded */
  7938. for (cnt = 0; cnt < 100; cnt++) {
  7939. bnx2x_cl45_read(bp, phy,
  7940. MDIO_PMA_DEVAD, MDIO_PMA_REG_ROM_VER1, &val);
  7941. if (val)
  7942. break;
  7943. usleep_range(10000, 20000);
  7944. }
  7945. DP(NETIF_MSG_LINK, "XGXS 8706 is initialized after %d ms\n", cnt);
  7946. if ((params->feature_config_flags &
  7947. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
  7948. u8 i;
  7949. u16 reg;
  7950. for (i = 0; i < 4; i++) {
  7951. reg = MDIO_XS_8706_REG_BANK_RX0 +
  7952. i*(MDIO_XS_8706_REG_BANK_RX1 -
  7953. MDIO_XS_8706_REG_BANK_RX0);
  7954. bnx2x_cl45_read(bp, phy, MDIO_XS_DEVAD, reg, &val);
  7955. /* Clear first 3 bits of the control */
  7956. val &= ~0x7;
  7957. /* Set control bits according to configuration */
  7958. val |= (phy->rx_preemphasis[i] & 0x7);
  7959. DP(NETIF_MSG_LINK, "Setting RX Equalizer to BCM8706"
  7960. " reg 0x%x <-- val 0x%x\n", reg, val);
  7961. bnx2x_cl45_write(bp, phy, MDIO_XS_DEVAD, reg, val);
  7962. }
  7963. }
  7964. /* Force speed */
  7965. if (phy->req_line_speed == SPEED_10000) {
  7966. DP(NETIF_MSG_LINK, "XGXS 8706 force 10Gbps\n");
  7967. bnx2x_cl45_write(bp, phy,
  7968. MDIO_PMA_DEVAD,
  7969. MDIO_PMA_REG_DIGITAL_CTRL, 0x400);
  7970. bnx2x_cl45_write(bp, phy,
  7971. MDIO_PMA_DEVAD, MDIO_PMA_LASI_TXCTRL,
  7972. 0);
  7973. /* Arm LASI for link and Tx fault. */
  7974. bnx2x_cl45_write(bp, phy,
  7975. MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 3);
  7976. } else {
  7977. /* Force 1Gbps using autoneg with 1G advertisement */
  7978. /* Allow CL37 through CL73 */
  7979. DP(NETIF_MSG_LINK, "XGXS 8706 AutoNeg\n");
  7980. bnx2x_cl45_write(bp, phy,
  7981. MDIO_AN_DEVAD, MDIO_AN_REG_CL37_CL73, 0x040c);
  7982. /* Enable Full-Duplex advertisement on CL37 */
  7983. bnx2x_cl45_write(bp, phy,
  7984. MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LP, 0x0020);
  7985. /* Enable CL37 AN */
  7986. bnx2x_cl45_write(bp, phy,
  7987. MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
  7988. /* 1G support */
  7989. bnx2x_cl45_write(bp, phy,
  7990. MDIO_AN_DEVAD, MDIO_AN_REG_ADV, (1<<5));
  7991. /* Enable clause 73 AN */
  7992. bnx2x_cl45_write(bp, phy,
  7993. MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
  7994. bnx2x_cl45_write(bp, phy,
  7995. MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
  7996. 0x0400);
  7997. bnx2x_cl45_write(bp, phy,
  7998. MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL,
  7999. 0x0004);
  8000. }
  8001. bnx2x_save_bcm_spirom_ver(bp, phy, params->port);
  8002. /* If TX Laser is controlled by GPIO_0, do not let PHY go into low
  8003. * power mode, if TX Laser is disabled
  8004. */
  8005. tx_en_mode = REG_RD(bp, params->shmem_base +
  8006. offsetof(struct shmem_region,
  8007. dev_info.port_hw_config[params->port].sfp_ctrl))
  8008. & PORT_HW_CFG_TX_LASER_MASK;
  8009. if (tx_en_mode == PORT_HW_CFG_TX_LASER_GPIO0) {
  8010. DP(NETIF_MSG_LINK, "Enabling TXONOFF_PWRDN_DIS\n");
  8011. bnx2x_cl45_read(bp, phy,
  8012. MDIO_PMA_DEVAD, MDIO_PMA_REG_DIGITAL_CTRL, &tmp1);
  8013. tmp1 |= 0x1;
  8014. bnx2x_cl45_write(bp, phy,
  8015. MDIO_PMA_DEVAD, MDIO_PMA_REG_DIGITAL_CTRL, tmp1);
  8016. }
  8017. return 0;
  8018. }
  8019. static int bnx2x_8706_read_status(struct bnx2x_phy *phy,
  8020. struct link_params *params,
  8021. struct link_vars *vars)
  8022. {
  8023. return bnx2x_8706_8726_read_status(phy, params, vars);
  8024. }
  8025. /******************************************************************/
  8026. /* BCM8726 PHY SECTION */
  8027. /******************************************************************/
  8028. static void bnx2x_8726_config_loopback(struct bnx2x_phy *phy,
  8029. struct link_params *params)
  8030. {
  8031. struct bnx2x *bp = params->bp;
  8032. DP(NETIF_MSG_LINK, "PMA/PMD ext_phy_loopback: 8726\n");
  8033. bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x0001);
  8034. }
  8035. static void bnx2x_8726_external_rom_boot(struct bnx2x_phy *phy,
  8036. struct link_params *params)
  8037. {
  8038. struct bnx2x *bp = params->bp;
  8039. /* Need to wait 100ms after reset */
  8040. msleep(100);
  8041. /* Micro controller re-boot */
  8042. bnx2x_cl45_write(bp, phy,
  8043. MDIO_PMA_DEVAD, MDIO_PMA_REG_GEN_CTRL, 0x018B);
  8044. /* Set soft reset */
  8045. bnx2x_cl45_write(bp, phy,
  8046. MDIO_PMA_DEVAD,
  8047. MDIO_PMA_REG_GEN_CTRL,
  8048. MDIO_PMA_REG_GEN_CTRL_ROM_MICRO_RESET);
  8049. bnx2x_cl45_write(bp, phy,
  8050. MDIO_PMA_DEVAD,
  8051. MDIO_PMA_REG_MISC_CTRL1, 0x0001);
  8052. bnx2x_cl45_write(bp, phy,
  8053. MDIO_PMA_DEVAD,
  8054. MDIO_PMA_REG_GEN_CTRL,
  8055. MDIO_PMA_REG_GEN_CTRL_ROM_RESET_INTERNAL_MP);
  8056. /* Wait for 150ms for microcode load */
  8057. msleep(150);
  8058. /* Disable serial boot control, tristates pins SS_N, SCK, MOSI, MISO */
  8059. bnx2x_cl45_write(bp, phy,
  8060. MDIO_PMA_DEVAD,
  8061. MDIO_PMA_REG_MISC_CTRL1, 0x0000);
  8062. msleep(200);
  8063. bnx2x_save_bcm_spirom_ver(bp, phy, params->port);
  8064. }
  8065. static u8 bnx2x_8726_read_status(struct bnx2x_phy *phy,
  8066. struct link_params *params,
  8067. struct link_vars *vars)
  8068. {
  8069. struct bnx2x *bp = params->bp;
  8070. u16 val1;
  8071. u8 link_up = bnx2x_8706_8726_read_status(phy, params, vars);
  8072. if (link_up) {
  8073. bnx2x_cl45_read(bp, phy,
  8074. MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER,
  8075. &val1);
  8076. if (val1 & (1<<15)) {
  8077. DP(NETIF_MSG_LINK, "Tx is disabled\n");
  8078. link_up = 0;
  8079. vars->line_speed = 0;
  8080. }
  8081. }
  8082. return link_up;
  8083. }
  8084. static int bnx2x_8726_config_init(struct bnx2x_phy *phy,
  8085. struct link_params *params,
  8086. struct link_vars *vars)
  8087. {
  8088. struct bnx2x *bp = params->bp;
  8089. DP(NETIF_MSG_LINK, "Initializing BCM8726\n");
  8090. bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
  8091. bnx2x_wait_reset_complete(bp, phy, params);
  8092. bnx2x_8726_external_rom_boot(phy, params);
  8093. /* Need to call module detected on initialization since the module
  8094. * detection triggered by actual module insertion might occur before
  8095. * driver is loaded, and when driver is loaded, it reset all
  8096. * registers, including the transmitter
  8097. */
  8098. bnx2x_sfp_module_detection(phy, params);
  8099. if (phy->req_line_speed == SPEED_1000) {
  8100. DP(NETIF_MSG_LINK, "Setting 1G force\n");
  8101. bnx2x_cl45_write(bp, phy,
  8102. MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x40);
  8103. bnx2x_cl45_write(bp, phy,
  8104. MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0xD);
  8105. bnx2x_cl45_write(bp, phy,
  8106. MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x5);
  8107. bnx2x_cl45_write(bp, phy,
  8108. MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
  8109. 0x400);
  8110. } else if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
  8111. (phy->speed_cap_mask &
  8112. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G) &&
  8113. ((phy->speed_cap_mask &
  8114. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) !=
  8115. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
  8116. DP(NETIF_MSG_LINK, "Setting 1G clause37\n");
  8117. /* Set Flow control */
  8118. bnx2x_ext_phy_set_pause(params, phy, vars);
  8119. bnx2x_cl45_write(bp, phy,
  8120. MDIO_AN_DEVAD, MDIO_AN_REG_ADV, 0x20);
  8121. bnx2x_cl45_write(bp, phy,
  8122. MDIO_AN_DEVAD, MDIO_AN_REG_CL37_CL73, 0x040c);
  8123. bnx2x_cl45_write(bp, phy,
  8124. MDIO_AN_DEVAD, MDIO_AN_REG_CL37_FC_LD, 0x0020);
  8125. bnx2x_cl45_write(bp, phy,
  8126. MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1000);
  8127. bnx2x_cl45_write(bp, phy,
  8128. MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x1200);
  8129. /* Enable RX-ALARM control to receive interrupt for 1G speed
  8130. * change
  8131. */
  8132. bnx2x_cl45_write(bp, phy,
  8133. MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x4);
  8134. bnx2x_cl45_write(bp, phy,
  8135. MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
  8136. 0x400);
  8137. } else { /* Default 10G. Set only LASI control */
  8138. bnx2x_cl45_write(bp, phy,
  8139. MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 1);
  8140. }
  8141. /* Set TX PreEmphasis if needed */
  8142. if ((params->feature_config_flags &
  8143. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
  8144. DP(NETIF_MSG_LINK,
  8145. "Setting TX_CTRL1 0x%x, TX_CTRL2 0x%x\n",
  8146. phy->tx_preemphasis[0],
  8147. phy->tx_preemphasis[1]);
  8148. bnx2x_cl45_write(bp, phy,
  8149. MDIO_PMA_DEVAD,
  8150. MDIO_PMA_REG_8726_TX_CTRL1,
  8151. phy->tx_preemphasis[0]);
  8152. bnx2x_cl45_write(bp, phy,
  8153. MDIO_PMA_DEVAD,
  8154. MDIO_PMA_REG_8726_TX_CTRL2,
  8155. phy->tx_preemphasis[1]);
  8156. }
  8157. return 0;
  8158. }
  8159. static void bnx2x_8726_link_reset(struct bnx2x_phy *phy,
  8160. struct link_params *params)
  8161. {
  8162. struct bnx2x *bp = params->bp;
  8163. DP(NETIF_MSG_LINK, "bnx2x_8726_link_reset port %d\n", params->port);
  8164. /* Set serial boot control for external load */
  8165. bnx2x_cl45_write(bp, phy,
  8166. MDIO_PMA_DEVAD,
  8167. MDIO_PMA_REG_GEN_CTRL, 0x0001);
  8168. }
  8169. /******************************************************************/
  8170. /* BCM8727 PHY SECTION */
  8171. /******************************************************************/
  8172. static void bnx2x_8727_set_link_led(struct bnx2x_phy *phy,
  8173. struct link_params *params, u8 mode)
  8174. {
  8175. struct bnx2x *bp = params->bp;
  8176. u16 led_mode_bitmask = 0;
  8177. u16 gpio_pins_bitmask = 0;
  8178. u16 val;
  8179. /* Only NOC flavor requires to set the LED specifically */
  8180. if (!(phy->flags & FLAGS_NOC))
  8181. return;
  8182. switch (mode) {
  8183. case LED_MODE_FRONT_PANEL_OFF:
  8184. case LED_MODE_OFF:
  8185. led_mode_bitmask = 0;
  8186. gpio_pins_bitmask = 0x03;
  8187. break;
  8188. case LED_MODE_ON:
  8189. led_mode_bitmask = 0;
  8190. gpio_pins_bitmask = 0x02;
  8191. break;
  8192. case LED_MODE_OPER:
  8193. led_mode_bitmask = 0x60;
  8194. gpio_pins_bitmask = 0x11;
  8195. break;
  8196. }
  8197. bnx2x_cl45_read(bp, phy,
  8198. MDIO_PMA_DEVAD,
  8199. MDIO_PMA_REG_8727_PCS_OPT_CTRL,
  8200. &val);
  8201. val &= 0xff8f;
  8202. val |= led_mode_bitmask;
  8203. bnx2x_cl45_write(bp, phy,
  8204. MDIO_PMA_DEVAD,
  8205. MDIO_PMA_REG_8727_PCS_OPT_CTRL,
  8206. val);
  8207. bnx2x_cl45_read(bp, phy,
  8208. MDIO_PMA_DEVAD,
  8209. MDIO_PMA_REG_8727_GPIO_CTRL,
  8210. &val);
  8211. val &= 0xffe0;
  8212. val |= gpio_pins_bitmask;
  8213. bnx2x_cl45_write(bp, phy,
  8214. MDIO_PMA_DEVAD,
  8215. MDIO_PMA_REG_8727_GPIO_CTRL,
  8216. val);
  8217. }
  8218. static void bnx2x_8727_hw_reset(struct bnx2x_phy *phy,
  8219. struct link_params *params) {
  8220. u32 swap_val, swap_override;
  8221. u8 port;
  8222. /* The PHY reset is controlled by GPIO 1. Fake the port number
  8223. * to cancel the swap done in set_gpio()
  8224. */
  8225. struct bnx2x *bp = params->bp;
  8226. swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
  8227. swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
  8228. port = (swap_val && swap_override) ^ 1;
  8229. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
  8230. MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
  8231. }
  8232. static void bnx2x_8727_config_speed(struct bnx2x_phy *phy,
  8233. struct link_params *params)
  8234. {
  8235. struct bnx2x *bp = params->bp;
  8236. u16 tmp1, val;
  8237. /* Set option 1G speed */
  8238. if ((phy->req_line_speed == SPEED_1000) ||
  8239. (phy->media_type == ETH_PHY_SFP_1G_FIBER)) {
  8240. DP(NETIF_MSG_LINK, "Setting 1G force\n");
  8241. bnx2x_cl45_write(bp, phy,
  8242. MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x40);
  8243. bnx2x_cl45_write(bp, phy,
  8244. MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, 0xD);
  8245. bnx2x_cl45_read(bp, phy,
  8246. MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2, &tmp1);
  8247. DP(NETIF_MSG_LINK, "1.7 = 0x%x\n", tmp1);
  8248. /* Power down the XAUI until link is up in case of dual-media
  8249. * and 1G
  8250. */
  8251. if (DUAL_MEDIA(params)) {
  8252. bnx2x_cl45_read(bp, phy,
  8253. MDIO_PMA_DEVAD,
  8254. MDIO_PMA_REG_8727_PCS_GP, &val);
  8255. val |= (3<<10);
  8256. bnx2x_cl45_write(bp, phy,
  8257. MDIO_PMA_DEVAD,
  8258. MDIO_PMA_REG_8727_PCS_GP, val);
  8259. }
  8260. } else if ((phy->req_line_speed == SPEED_AUTO_NEG) &&
  8261. ((phy->speed_cap_mask &
  8262. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) &&
  8263. ((phy->speed_cap_mask &
  8264. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G) !=
  8265. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) {
  8266. DP(NETIF_MSG_LINK, "Setting 1G clause37\n");
  8267. bnx2x_cl45_write(bp, phy,
  8268. MDIO_AN_DEVAD, MDIO_AN_REG_8727_MISC_CTRL, 0);
  8269. bnx2x_cl45_write(bp, phy,
  8270. MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x1300);
  8271. } else {
  8272. /* Since the 8727 has only single reset pin, need to set the 10G
  8273. * registers although it is default
  8274. */
  8275. bnx2x_cl45_write(bp, phy,
  8276. MDIO_AN_DEVAD, MDIO_AN_REG_8727_MISC_CTRL,
  8277. 0x0020);
  8278. bnx2x_cl45_write(bp, phy,
  8279. MDIO_AN_DEVAD, MDIO_AN_REG_CL37_AN, 0x0100);
  8280. bnx2x_cl45_write(bp, phy,
  8281. MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x2040);
  8282. bnx2x_cl45_write(bp, phy,
  8283. MDIO_PMA_DEVAD, MDIO_PMA_REG_10G_CTRL2,
  8284. 0x0008);
  8285. }
  8286. }
  8287. static int bnx2x_8727_config_init(struct bnx2x_phy *phy,
  8288. struct link_params *params,
  8289. struct link_vars *vars)
  8290. {
  8291. u32 tx_en_mode;
  8292. u16 tmp1, mod_abs, tmp2;
  8293. struct bnx2x *bp = params->bp;
  8294. /* Enable PMD link, MOD_ABS_FLT, and 1G link alarm */
  8295. bnx2x_wait_reset_complete(bp, phy, params);
  8296. DP(NETIF_MSG_LINK, "Initializing BCM8727\n");
  8297. bnx2x_8727_specific_func(phy, params, PHY_INIT);
  8298. /* Initially configure MOD_ABS to interrupt when module is
  8299. * presence( bit 8)
  8300. */
  8301. bnx2x_cl45_read(bp, phy,
  8302. MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, &mod_abs);
  8303. /* Set EDC off by setting OPTXLOS signal input to low (bit 9).
  8304. * When the EDC is off it locks onto a reference clock and avoids
  8305. * becoming 'lost'
  8306. */
  8307. mod_abs &= ~(1<<8);
  8308. if (!(phy->flags & FLAGS_NOC))
  8309. mod_abs &= ~(1<<9);
  8310. bnx2x_cl45_write(bp, phy,
  8311. MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
  8312. /* Enable/Disable PHY transmitter output */
  8313. bnx2x_set_disable_pmd_transmit(params, phy, 0);
  8314. bnx2x_8727_power_module(bp, phy, 1);
  8315. bnx2x_cl45_read(bp, phy,
  8316. MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &tmp1);
  8317. bnx2x_cl45_read(bp, phy,
  8318. MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT, &tmp1);
  8319. bnx2x_8727_config_speed(phy, params);
  8320. /* Set TX PreEmphasis if needed */
  8321. if ((params->feature_config_flags &
  8322. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED)) {
  8323. DP(NETIF_MSG_LINK, "Setting TX_CTRL1 0x%x, TX_CTRL2 0x%x\n",
  8324. phy->tx_preemphasis[0],
  8325. phy->tx_preemphasis[1]);
  8326. bnx2x_cl45_write(bp, phy,
  8327. MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TX_CTRL1,
  8328. phy->tx_preemphasis[0]);
  8329. bnx2x_cl45_write(bp, phy,
  8330. MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_TX_CTRL2,
  8331. phy->tx_preemphasis[1]);
  8332. }
  8333. /* If TX Laser is controlled by GPIO_0, do not let PHY go into low
  8334. * power mode, if TX Laser is disabled
  8335. */
  8336. tx_en_mode = REG_RD(bp, params->shmem_base +
  8337. offsetof(struct shmem_region,
  8338. dev_info.port_hw_config[params->port].sfp_ctrl))
  8339. & PORT_HW_CFG_TX_LASER_MASK;
  8340. if (tx_en_mode == PORT_HW_CFG_TX_LASER_GPIO0) {
  8341. DP(NETIF_MSG_LINK, "Enabling TXONOFF_PWRDN_DIS\n");
  8342. bnx2x_cl45_read(bp, phy,
  8343. MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_OPT_CFG_REG, &tmp2);
  8344. tmp2 |= 0x1000;
  8345. tmp2 &= 0xFFEF;
  8346. bnx2x_cl45_write(bp, phy,
  8347. MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_OPT_CFG_REG, tmp2);
  8348. bnx2x_cl45_read(bp, phy,
  8349. MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER,
  8350. &tmp2);
  8351. bnx2x_cl45_write(bp, phy,
  8352. MDIO_PMA_DEVAD, MDIO_PMA_REG_PHY_IDENTIFIER,
  8353. (tmp2 & 0x7fff));
  8354. }
  8355. return 0;
  8356. }
  8357. static void bnx2x_8727_handle_mod_abs(struct bnx2x_phy *phy,
  8358. struct link_params *params)
  8359. {
  8360. struct bnx2x *bp = params->bp;
  8361. u16 mod_abs, rx_alarm_status;
  8362. u32 val = REG_RD(bp, params->shmem_base +
  8363. offsetof(struct shmem_region, dev_info.
  8364. port_feature_config[params->port].
  8365. config));
  8366. bnx2x_cl45_read(bp, phy,
  8367. MDIO_PMA_DEVAD,
  8368. MDIO_PMA_REG_PHY_IDENTIFIER, &mod_abs);
  8369. if (mod_abs & (1<<8)) {
  8370. /* Module is absent */
  8371. DP(NETIF_MSG_LINK,
  8372. "MOD_ABS indication show module is absent\n");
  8373. phy->media_type = ETH_PHY_NOT_PRESENT;
  8374. /* 1. Set mod_abs to detect next module
  8375. * presence event
  8376. * 2. Set EDC off by setting OPTXLOS signal input to low
  8377. * (bit 9).
  8378. * When the EDC is off it locks onto a reference clock and
  8379. * avoids becoming 'lost'.
  8380. */
  8381. mod_abs &= ~(1<<8);
  8382. if (!(phy->flags & FLAGS_NOC))
  8383. mod_abs &= ~(1<<9);
  8384. bnx2x_cl45_write(bp, phy,
  8385. MDIO_PMA_DEVAD,
  8386. MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
  8387. /* Clear RX alarm since it stays up as long as
  8388. * the mod_abs wasn't changed
  8389. */
  8390. bnx2x_cl45_read(bp, phy,
  8391. MDIO_PMA_DEVAD,
  8392. MDIO_PMA_LASI_RXSTAT, &rx_alarm_status);
  8393. } else {
  8394. /* Module is present */
  8395. DP(NETIF_MSG_LINK,
  8396. "MOD_ABS indication show module is present\n");
  8397. /* First disable transmitter, and if the module is ok, the
  8398. * module_detection will enable it
  8399. * 1. Set mod_abs to detect next module absent event ( bit 8)
  8400. * 2. Restore the default polarity of the OPRXLOS signal and
  8401. * this signal will then correctly indicate the presence or
  8402. * absence of the Rx signal. (bit 9)
  8403. */
  8404. mod_abs |= (1<<8);
  8405. if (!(phy->flags & FLAGS_NOC))
  8406. mod_abs |= (1<<9);
  8407. bnx2x_cl45_write(bp, phy,
  8408. MDIO_PMA_DEVAD,
  8409. MDIO_PMA_REG_PHY_IDENTIFIER, mod_abs);
  8410. /* Clear RX alarm since it stays up as long as the mod_abs
  8411. * wasn't changed. This is need to be done before calling the
  8412. * module detection, otherwise it will clear* the link update
  8413. * alarm
  8414. */
  8415. bnx2x_cl45_read(bp, phy,
  8416. MDIO_PMA_DEVAD,
  8417. MDIO_PMA_LASI_RXSTAT, &rx_alarm_status);
  8418. if ((val & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_MASK) ==
  8419. PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_DISABLE_TX_LASER)
  8420. bnx2x_sfp_set_transmitter(params, phy, 0);
  8421. if (bnx2x_wait_for_sfp_module_initialized(phy, params) == 0)
  8422. bnx2x_sfp_module_detection(phy, params);
  8423. else
  8424. DP(NETIF_MSG_LINK, "SFP+ module is not initialized\n");
  8425. /* Reconfigure link speed based on module type limitations */
  8426. bnx2x_8727_config_speed(phy, params);
  8427. }
  8428. DP(NETIF_MSG_LINK, "8727 RX_ALARM_STATUS 0x%x\n",
  8429. rx_alarm_status);
  8430. /* No need to check link status in case of module plugged in/out */
  8431. }
  8432. static u8 bnx2x_8727_read_status(struct bnx2x_phy *phy,
  8433. struct link_params *params,
  8434. struct link_vars *vars)
  8435. {
  8436. struct bnx2x *bp = params->bp;
  8437. u8 link_up = 0, oc_port = params->port;
  8438. u16 link_status = 0;
  8439. u16 rx_alarm_status, lasi_ctrl, val1;
  8440. /* If PHY is not initialized, do not check link status */
  8441. bnx2x_cl45_read(bp, phy,
  8442. MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL,
  8443. &lasi_ctrl);
  8444. if (!lasi_ctrl)
  8445. return 0;
  8446. /* Check the LASI on Rx */
  8447. bnx2x_cl45_read(bp, phy,
  8448. MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXSTAT,
  8449. &rx_alarm_status);
  8450. vars->line_speed = 0;
  8451. DP(NETIF_MSG_LINK, "8727 RX_ALARM_STATUS 0x%x\n", rx_alarm_status);
  8452. bnx2x_sfp_mask_fault(bp, phy, MDIO_PMA_LASI_TXSTAT,
  8453. MDIO_PMA_LASI_TXCTRL);
  8454. bnx2x_cl45_read(bp, phy,
  8455. MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val1);
  8456. DP(NETIF_MSG_LINK, "8727 LASI status 0x%x\n", val1);
  8457. /* Clear MSG-OUT */
  8458. bnx2x_cl45_read(bp, phy,
  8459. MDIO_PMA_DEVAD, MDIO_PMA_REG_M8051_MSGOUT_REG, &val1);
  8460. /* If a module is present and there is need to check
  8461. * for over current
  8462. */
  8463. if (!(phy->flags & FLAGS_NOC) && !(rx_alarm_status & (1<<5))) {
  8464. /* Check over-current using 8727 GPIO0 input*/
  8465. bnx2x_cl45_read(bp, phy,
  8466. MDIO_PMA_DEVAD, MDIO_PMA_REG_8727_GPIO_CTRL,
  8467. &val1);
  8468. if ((val1 & (1<<8)) == 0) {
  8469. if (!CHIP_IS_E1x(bp))
  8470. oc_port = BP_PATH(bp) + (params->port << 1);
  8471. DP(NETIF_MSG_LINK,
  8472. "8727 Power fault has been detected on port %d\n",
  8473. oc_port);
  8474. netdev_err(bp->dev, "Error: Power fault on Port %d has "
  8475. "been detected and the power to "
  8476. "that SFP+ module has been removed "
  8477. "to prevent failure of the card. "
  8478. "Please remove the SFP+ module and "
  8479. "restart the system to clear this "
  8480. "error.\n",
  8481. oc_port);
  8482. /* Disable all RX_ALARMs except for mod_abs */
  8483. bnx2x_cl45_write(bp, phy,
  8484. MDIO_PMA_DEVAD,
  8485. MDIO_PMA_LASI_RXCTRL, (1<<5));
  8486. bnx2x_cl45_read(bp, phy,
  8487. MDIO_PMA_DEVAD,
  8488. MDIO_PMA_REG_PHY_IDENTIFIER, &val1);
  8489. /* Wait for module_absent_event */
  8490. val1 |= (1<<8);
  8491. bnx2x_cl45_write(bp, phy,
  8492. MDIO_PMA_DEVAD,
  8493. MDIO_PMA_REG_PHY_IDENTIFIER, val1);
  8494. /* Clear RX alarm */
  8495. bnx2x_cl45_read(bp, phy,
  8496. MDIO_PMA_DEVAD,
  8497. MDIO_PMA_LASI_RXSTAT, &rx_alarm_status);
  8498. bnx2x_8727_power_module(params->bp, phy, 0);
  8499. return 0;
  8500. }
  8501. } /* Over current check */
  8502. /* When module absent bit is set, check module */
  8503. if (rx_alarm_status & (1<<5)) {
  8504. bnx2x_8727_handle_mod_abs(phy, params);
  8505. /* Enable all mod_abs and link detection bits */
  8506. bnx2x_cl45_write(bp, phy,
  8507. MDIO_PMA_DEVAD, MDIO_PMA_LASI_RXCTRL,
  8508. ((1<<5) | (1<<2)));
  8509. }
  8510. if (!(phy->flags & FLAGS_SFP_NOT_APPROVED)) {
  8511. DP(NETIF_MSG_LINK, "Enabling 8727 TX laser\n");
  8512. bnx2x_sfp_set_transmitter(params, phy, 1);
  8513. } else {
  8514. DP(NETIF_MSG_LINK, "Tx is disabled\n");
  8515. return 0;
  8516. }
  8517. bnx2x_cl45_read(bp, phy,
  8518. MDIO_PMA_DEVAD,
  8519. MDIO_PMA_REG_8073_SPEED_LINK_STATUS, &link_status);
  8520. /* Bits 0..2 --> speed detected,
  8521. * Bits 13..15--> link is down
  8522. */
  8523. if ((link_status & (1<<2)) && (!(link_status & (1<<15)))) {
  8524. link_up = 1;
  8525. vars->line_speed = SPEED_10000;
  8526. DP(NETIF_MSG_LINK, "port %x: External link up in 10G\n",
  8527. params->port);
  8528. } else if ((link_status & (1<<0)) && (!(link_status & (1<<13)))) {
  8529. link_up = 1;
  8530. vars->line_speed = SPEED_1000;
  8531. DP(NETIF_MSG_LINK, "port %x: External link up in 1G\n",
  8532. params->port);
  8533. } else {
  8534. link_up = 0;
  8535. DP(NETIF_MSG_LINK, "port %x: External link is down\n",
  8536. params->port);
  8537. }
  8538. /* Capture 10G link fault. */
  8539. if (vars->line_speed == SPEED_10000) {
  8540. bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
  8541. MDIO_PMA_LASI_TXSTAT, &val1);
  8542. bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD,
  8543. MDIO_PMA_LASI_TXSTAT, &val1);
  8544. if (val1 & (1<<0)) {
  8545. vars->fault_detected = 1;
  8546. }
  8547. }
  8548. if (link_up) {
  8549. bnx2x_ext_phy_resolve_fc(phy, params, vars);
  8550. vars->duplex = DUPLEX_FULL;
  8551. DP(NETIF_MSG_LINK, "duplex = 0x%x\n", vars->duplex);
  8552. }
  8553. if ((DUAL_MEDIA(params)) &&
  8554. (phy->req_line_speed == SPEED_1000)) {
  8555. bnx2x_cl45_read(bp, phy,
  8556. MDIO_PMA_DEVAD,
  8557. MDIO_PMA_REG_8727_PCS_GP, &val1);
  8558. /* In case of dual-media board and 1G, power up the XAUI side,
  8559. * otherwise power it down. For 10G it is done automatically
  8560. */
  8561. if (link_up)
  8562. val1 &= ~(3<<10);
  8563. else
  8564. val1 |= (3<<10);
  8565. bnx2x_cl45_write(bp, phy,
  8566. MDIO_PMA_DEVAD,
  8567. MDIO_PMA_REG_8727_PCS_GP, val1);
  8568. }
  8569. return link_up;
  8570. }
  8571. static void bnx2x_8727_link_reset(struct bnx2x_phy *phy,
  8572. struct link_params *params)
  8573. {
  8574. struct bnx2x *bp = params->bp;
  8575. /* Enable/Disable PHY transmitter output */
  8576. bnx2x_set_disable_pmd_transmit(params, phy, 1);
  8577. /* Disable Transmitter */
  8578. bnx2x_sfp_set_transmitter(params, phy, 0);
  8579. /* Clear LASI */
  8580. bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0);
  8581. }
  8582. /******************************************************************/
  8583. /* BCM8481/BCM84823/BCM84833 PHY SECTION */
  8584. /******************************************************************/
  8585. static int bnx2x_is_8483x_8485x(struct bnx2x_phy *phy)
  8586. {
  8587. return ((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) ||
  8588. (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84834) ||
  8589. (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84858));
  8590. }
  8591. static void bnx2x_save_848xx_spirom_version(struct bnx2x_phy *phy,
  8592. struct bnx2x *bp,
  8593. u8 port)
  8594. {
  8595. u16 val, fw_ver2, cnt, i;
  8596. static struct bnx2x_reg_set reg_set[] = {
  8597. {MDIO_PMA_DEVAD, 0xA819, 0x0014},
  8598. {MDIO_PMA_DEVAD, 0xA81A, 0xc200},
  8599. {MDIO_PMA_DEVAD, 0xA81B, 0x0000},
  8600. {MDIO_PMA_DEVAD, 0xA81C, 0x0300},
  8601. {MDIO_PMA_DEVAD, 0xA817, 0x0009}
  8602. };
  8603. u16 fw_ver1;
  8604. if (bnx2x_is_8483x_8485x(phy)) {
  8605. bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD, 0x400f, &fw_ver1);
  8606. if (phy->type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84858)
  8607. fw_ver1 &= 0xfff;
  8608. bnx2x_save_spirom_version(bp, port, fw_ver1, phy->ver_addr);
  8609. } else {
  8610. /* For 32-bit registers in 848xx, access via MDIO2ARM i/f. */
  8611. /* (1) set reg 0xc200_0014(SPI_BRIDGE_CTRL_2) to 0x03000000 */
  8612. for (i = 0; i < ARRAY_SIZE(reg_set); i++)
  8613. bnx2x_cl45_write(bp, phy, reg_set[i].devad,
  8614. reg_set[i].reg, reg_set[i].val);
  8615. for (cnt = 0; cnt < 100; cnt++) {
  8616. bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA818, &val);
  8617. if (val & 1)
  8618. break;
  8619. udelay(5);
  8620. }
  8621. if (cnt == 100) {
  8622. DP(NETIF_MSG_LINK, "Unable to read 848xx "
  8623. "phy fw version(1)\n");
  8624. bnx2x_save_spirom_version(bp, port, 0,
  8625. phy->ver_addr);
  8626. return;
  8627. }
  8628. /* 2) read register 0xc200_0000 (SPI_FW_STATUS) */
  8629. bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA819, 0x0000);
  8630. bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA81A, 0xc200);
  8631. bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, 0xA817, 0x000A);
  8632. for (cnt = 0; cnt < 100; cnt++) {
  8633. bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA818, &val);
  8634. if (val & 1)
  8635. break;
  8636. udelay(5);
  8637. }
  8638. if (cnt == 100) {
  8639. DP(NETIF_MSG_LINK, "Unable to read 848xx phy fw "
  8640. "version(2)\n");
  8641. bnx2x_save_spirom_version(bp, port, 0,
  8642. phy->ver_addr);
  8643. return;
  8644. }
  8645. /* lower 16 bits of the register SPI_FW_STATUS */
  8646. bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA81B, &fw_ver1);
  8647. /* upper 16 bits of register SPI_FW_STATUS */
  8648. bnx2x_cl45_read(bp, phy, MDIO_PMA_DEVAD, 0xA81C, &fw_ver2);
  8649. bnx2x_save_spirom_version(bp, port, (fw_ver2<<16) | fw_ver1,
  8650. phy->ver_addr);
  8651. }
  8652. }
  8653. static void bnx2x_848xx_set_led(struct bnx2x *bp,
  8654. struct bnx2x_phy *phy)
  8655. {
  8656. u16 val, led3_blink_rate, offset, i;
  8657. static struct bnx2x_reg_set reg_set[] = {
  8658. {MDIO_PMA_DEVAD, MDIO_PMA_REG_8481_LED1_MASK, 0x0080},
  8659. {MDIO_PMA_DEVAD, MDIO_PMA_REG_8481_LED2_MASK, 0x0018},
  8660. {MDIO_PMA_DEVAD, MDIO_PMA_REG_8481_LED3_MASK, 0x0006},
  8661. {MDIO_PMA_DEVAD, MDIO_PMA_REG_84823_CTL_SLOW_CLK_CNT_HIGH,
  8662. MDIO_PMA_REG_84823_BLINK_RATE_VAL_15P9HZ},
  8663. {MDIO_AN_DEVAD, 0xFFFB, 0xFFFD}
  8664. };
  8665. if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84858) {
  8666. /* Set LED5 source */
  8667. bnx2x_cl45_write(bp, phy,
  8668. MDIO_PMA_DEVAD,
  8669. MDIO_PMA_REG_8481_LED5_MASK,
  8670. 0x90);
  8671. led3_blink_rate = 0x000f;
  8672. } else {
  8673. led3_blink_rate = 0x0000;
  8674. }
  8675. /* Set LED3 BLINK */
  8676. bnx2x_cl45_write(bp, phy,
  8677. MDIO_PMA_DEVAD,
  8678. MDIO_PMA_REG_8481_LED3_BLINK,
  8679. led3_blink_rate);
  8680. /* PHYC_CTL_LED_CTL */
  8681. bnx2x_cl45_read(bp, phy,
  8682. MDIO_PMA_DEVAD,
  8683. MDIO_PMA_REG_8481_LINK_SIGNAL, &val);
  8684. val &= 0xFE00;
  8685. val |= 0x0092;
  8686. if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84858)
  8687. val |= 2 << 12; /* LED5 ON based on source */
  8688. bnx2x_cl45_write(bp, phy,
  8689. MDIO_PMA_DEVAD,
  8690. MDIO_PMA_REG_8481_LINK_SIGNAL, val);
  8691. for (i = 0; i < ARRAY_SIZE(reg_set); i++)
  8692. bnx2x_cl45_write(bp, phy, reg_set[i].devad, reg_set[i].reg,
  8693. reg_set[i].val);
  8694. if (bnx2x_is_8483x_8485x(phy))
  8695. offset = MDIO_PMA_REG_84833_CTL_LED_CTL_1;
  8696. else
  8697. offset = MDIO_PMA_REG_84823_CTL_LED_CTL_1;
  8698. if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84858)
  8699. val = MDIO_PMA_REG_84858_ALLOW_GPHY_ACT |
  8700. MDIO_PMA_REG_84823_LED3_STRETCH_EN;
  8701. else
  8702. val = MDIO_PMA_REG_84823_LED3_STRETCH_EN;
  8703. /* stretch_en for LEDs */
  8704. bnx2x_cl45_read_or_write(bp, phy,
  8705. MDIO_PMA_DEVAD,
  8706. offset,
  8707. val);
  8708. }
  8709. static void bnx2x_848xx_specific_func(struct bnx2x_phy *phy,
  8710. struct link_params *params,
  8711. u32 action)
  8712. {
  8713. struct bnx2x *bp = params->bp;
  8714. switch (action) {
  8715. case PHY_INIT:
  8716. if (bnx2x_is_8483x_8485x(phy)) {
  8717. /* Save spirom version */
  8718. bnx2x_save_848xx_spirom_version(phy, bp, params->port);
  8719. }
  8720. /* This phy uses the NIG latch mechanism since link indication
  8721. * arrives through its LED4 and not via its LASI signal, so we
  8722. * get steady signal instead of clear on read
  8723. */
  8724. bnx2x_bits_en(bp, NIG_REG_LATCH_BC_0 + params->port*4,
  8725. 1 << NIG_LATCH_BC_ENABLE_MI_INT);
  8726. bnx2x_848xx_set_led(bp, phy);
  8727. break;
  8728. }
  8729. }
  8730. static int bnx2x_848xx_cmn_config_init(struct bnx2x_phy *phy,
  8731. struct link_params *params,
  8732. struct link_vars *vars)
  8733. {
  8734. struct bnx2x *bp = params->bp;
  8735. u16 autoneg_val, an_1000_val, an_10_100_val;
  8736. bnx2x_848xx_specific_func(phy, params, PHY_INIT);
  8737. bnx2x_cl45_write(bp, phy,
  8738. MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 0x0000);
  8739. /* set 1000 speed advertisement */
  8740. bnx2x_cl45_read(bp, phy,
  8741. MDIO_AN_DEVAD, MDIO_AN_REG_8481_1000T_CTRL,
  8742. &an_1000_val);
  8743. bnx2x_ext_phy_set_pause(params, phy, vars);
  8744. bnx2x_cl45_read(bp, phy,
  8745. MDIO_AN_DEVAD,
  8746. MDIO_AN_REG_8481_LEGACY_AN_ADV,
  8747. &an_10_100_val);
  8748. bnx2x_cl45_read(bp, phy,
  8749. MDIO_AN_DEVAD, MDIO_AN_REG_8481_LEGACY_MII_CTRL,
  8750. &autoneg_val);
  8751. /* Disable forced speed */
  8752. autoneg_val &= ~((1<<6) | (1<<8) | (1<<9) | (1<<12) | (1<<13));
  8753. an_10_100_val &= ~((1<<5) | (1<<6) | (1<<7) | (1<<8));
  8754. if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
  8755. (phy->speed_cap_mask &
  8756. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
  8757. (phy->req_line_speed == SPEED_1000)) {
  8758. an_1000_val |= (1<<8);
  8759. autoneg_val |= (1<<9 | 1<<12);
  8760. if (phy->req_duplex == DUPLEX_FULL)
  8761. an_1000_val |= (1<<9);
  8762. DP(NETIF_MSG_LINK, "Advertising 1G\n");
  8763. } else
  8764. an_1000_val &= ~((1<<8) | (1<<9));
  8765. bnx2x_cl45_write(bp, phy,
  8766. MDIO_AN_DEVAD, MDIO_AN_REG_8481_1000T_CTRL,
  8767. an_1000_val);
  8768. /* Set 10/100 speed advertisement */
  8769. if (phy->req_line_speed == SPEED_AUTO_NEG) {
  8770. if (phy->speed_cap_mask &
  8771. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL) {
  8772. /* Enable autoneg and restart autoneg for legacy speeds
  8773. */
  8774. autoneg_val |= (1<<9 | 1<<12);
  8775. an_10_100_val |= (1<<8);
  8776. DP(NETIF_MSG_LINK, "Advertising 100M-FD\n");
  8777. }
  8778. if (phy->speed_cap_mask &
  8779. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF) {
  8780. /* Enable autoneg and restart autoneg for legacy speeds
  8781. */
  8782. autoneg_val |= (1<<9 | 1<<12);
  8783. an_10_100_val |= (1<<7);
  8784. DP(NETIF_MSG_LINK, "Advertising 100M-HD\n");
  8785. }
  8786. if ((phy->speed_cap_mask &
  8787. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL) &&
  8788. (phy->supported & SUPPORTED_10baseT_Full)) {
  8789. an_10_100_val |= (1<<6);
  8790. autoneg_val |= (1<<9 | 1<<12);
  8791. DP(NETIF_MSG_LINK, "Advertising 10M-FD\n");
  8792. }
  8793. if ((phy->speed_cap_mask &
  8794. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF) &&
  8795. (phy->supported & SUPPORTED_10baseT_Half)) {
  8796. an_10_100_val |= (1<<5);
  8797. autoneg_val |= (1<<9 | 1<<12);
  8798. DP(NETIF_MSG_LINK, "Advertising 10M-HD\n");
  8799. }
  8800. }
  8801. /* Only 10/100 are allowed to work in FORCE mode */
  8802. if ((phy->req_line_speed == SPEED_100) &&
  8803. (phy->supported &
  8804. (SUPPORTED_100baseT_Half |
  8805. SUPPORTED_100baseT_Full))) {
  8806. autoneg_val |= (1<<13);
  8807. /* Enabled AUTO-MDIX when autoneg is disabled */
  8808. bnx2x_cl45_write(bp, phy,
  8809. MDIO_AN_DEVAD, MDIO_AN_REG_8481_AUX_CTRL,
  8810. (1<<15 | 1<<9 | 7<<0));
  8811. /* The PHY needs this set even for forced link. */
  8812. an_10_100_val |= (1<<8) | (1<<7);
  8813. DP(NETIF_MSG_LINK, "Setting 100M force\n");
  8814. }
  8815. if ((phy->req_line_speed == SPEED_10) &&
  8816. (phy->supported &
  8817. (SUPPORTED_10baseT_Half |
  8818. SUPPORTED_10baseT_Full))) {
  8819. /* Enabled AUTO-MDIX when autoneg is disabled */
  8820. bnx2x_cl45_write(bp, phy,
  8821. MDIO_AN_DEVAD, MDIO_AN_REG_8481_AUX_CTRL,
  8822. (1<<15 | 1<<9 | 7<<0));
  8823. DP(NETIF_MSG_LINK, "Setting 10M force\n");
  8824. }
  8825. bnx2x_cl45_write(bp, phy,
  8826. MDIO_AN_DEVAD, MDIO_AN_REG_8481_LEGACY_AN_ADV,
  8827. an_10_100_val);
  8828. if (phy->req_duplex == DUPLEX_FULL)
  8829. autoneg_val |= (1<<8);
  8830. /* Always write this if this is not 84833/4.
  8831. * For 84833/4, write it only when it's a forced speed.
  8832. */
  8833. if (!bnx2x_is_8483x_8485x(phy) ||
  8834. ((autoneg_val & (1<<12)) == 0))
  8835. bnx2x_cl45_write(bp, phy,
  8836. MDIO_AN_DEVAD,
  8837. MDIO_AN_REG_8481_LEGACY_MII_CTRL, autoneg_val);
  8838. if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
  8839. (phy->speed_cap_mask &
  8840. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) ||
  8841. (phy->req_line_speed == SPEED_10000)) {
  8842. DP(NETIF_MSG_LINK, "Advertising 10G\n");
  8843. /* Restart autoneg for 10G*/
  8844. bnx2x_cl45_read_or_write(
  8845. bp, phy,
  8846. MDIO_AN_DEVAD,
  8847. MDIO_AN_REG_8481_10GBASE_T_AN_CTRL,
  8848. 0x1000);
  8849. bnx2x_cl45_write(bp, phy,
  8850. MDIO_AN_DEVAD, MDIO_AN_REG_CTRL,
  8851. 0x3200);
  8852. } else
  8853. bnx2x_cl45_write(bp, phy,
  8854. MDIO_AN_DEVAD,
  8855. MDIO_AN_REG_8481_10GBASE_T_AN_CTRL,
  8856. 1);
  8857. return 0;
  8858. }
  8859. static int bnx2x_8481_config_init(struct bnx2x_phy *phy,
  8860. struct link_params *params,
  8861. struct link_vars *vars)
  8862. {
  8863. struct bnx2x *bp = params->bp;
  8864. /* Restore normal power mode*/
  8865. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
  8866. MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
  8867. /* HW reset */
  8868. bnx2x_ext_phy_hw_reset(bp, params->port);
  8869. bnx2x_wait_reset_complete(bp, phy, params);
  8870. bnx2x_cl45_write(bp, phy, MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
  8871. return bnx2x_848xx_cmn_config_init(phy, params, vars);
  8872. }
  8873. #define PHY848xx_CMDHDLR_WAIT 300
  8874. #define PHY848xx_CMDHDLR_MAX_ARGS 5
  8875. static int bnx2x_84858_cmd_hdlr(struct bnx2x_phy *phy,
  8876. struct link_params *params,
  8877. u16 fw_cmd,
  8878. u16 cmd_args[], int argc)
  8879. {
  8880. int idx;
  8881. u16 val;
  8882. struct bnx2x *bp = params->bp;
  8883. /* Step 1: Poll the STATUS register to see whether the previous command
  8884. * is in progress or the system is busy (CMD_IN_PROGRESS or
  8885. * SYSTEM_BUSY). If previous command is in progress or system is busy,
  8886. * check again until the previous command finishes execution and the
  8887. * system is available for taking command
  8888. */
  8889. for (idx = 0; idx < PHY848xx_CMDHDLR_WAIT; idx++) {
  8890. bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
  8891. MDIO_848xx_CMD_HDLR_STATUS, &val);
  8892. if ((val != PHY84858_STATUS_CMD_IN_PROGRESS) &&
  8893. (val != PHY84858_STATUS_CMD_SYSTEM_BUSY))
  8894. break;
  8895. usleep_range(1000, 2000);
  8896. }
  8897. if (idx >= PHY848xx_CMDHDLR_WAIT) {
  8898. DP(NETIF_MSG_LINK, "FW cmd: FW not ready.\n");
  8899. return -EINVAL;
  8900. }
  8901. /* Step2: If any parameters are required for the function, write them
  8902. * to the required DATA registers
  8903. */
  8904. for (idx = 0; idx < argc; idx++) {
  8905. bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
  8906. MDIO_848xx_CMD_HDLR_DATA1 + idx,
  8907. cmd_args[idx]);
  8908. }
  8909. /* Step3: When the firmware is ready for commands, write the 'Command
  8910. * code' to the CMD register
  8911. */
  8912. bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
  8913. MDIO_848xx_CMD_HDLR_COMMAND, fw_cmd);
  8914. /* Step4: Once the command has been written, poll the STATUS register
  8915. * to check whether the command has completed (CMD_COMPLETED_PASS/
  8916. * CMD_FOR_CMDS or CMD_COMPLETED_ERROR).
  8917. */
  8918. for (idx = 0; idx < PHY848xx_CMDHDLR_WAIT; idx++) {
  8919. bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
  8920. MDIO_848xx_CMD_HDLR_STATUS, &val);
  8921. if ((val == PHY84858_STATUS_CMD_COMPLETE_PASS) ||
  8922. (val == PHY84858_STATUS_CMD_COMPLETE_ERROR))
  8923. break;
  8924. usleep_range(1000, 2000);
  8925. }
  8926. if ((idx >= PHY848xx_CMDHDLR_WAIT) ||
  8927. (val == PHY84858_STATUS_CMD_COMPLETE_ERROR)) {
  8928. DP(NETIF_MSG_LINK, "FW cmd failed.\n");
  8929. return -EINVAL;
  8930. }
  8931. /* Step5: Once the command has completed, read the specficied DATA
  8932. * registers for any saved results for the command, if applicable
  8933. */
  8934. /* Gather returning data */
  8935. for (idx = 0; idx < argc; idx++) {
  8936. bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
  8937. MDIO_848xx_CMD_HDLR_DATA1 + idx,
  8938. &cmd_args[idx]);
  8939. }
  8940. return 0;
  8941. }
  8942. static int bnx2x_84833_cmd_hdlr(struct bnx2x_phy *phy,
  8943. struct link_params *params, u16 fw_cmd,
  8944. u16 cmd_args[], int argc, int process)
  8945. {
  8946. int idx;
  8947. u16 val;
  8948. struct bnx2x *bp = params->bp;
  8949. int rc = 0;
  8950. if (process == PHY84833_MB_PROCESS2) {
  8951. /* Write CMD_OPEN_OVERRIDE to STATUS reg */
  8952. bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
  8953. MDIO_848xx_CMD_HDLR_STATUS,
  8954. PHY84833_STATUS_CMD_OPEN_OVERRIDE);
  8955. }
  8956. for (idx = 0; idx < PHY848xx_CMDHDLR_WAIT; idx++) {
  8957. bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
  8958. MDIO_848xx_CMD_HDLR_STATUS, &val);
  8959. if (val == PHY84833_STATUS_CMD_OPEN_FOR_CMDS)
  8960. break;
  8961. usleep_range(1000, 2000);
  8962. }
  8963. if (idx >= PHY848xx_CMDHDLR_WAIT) {
  8964. DP(NETIF_MSG_LINK, "FW cmd: FW not ready.\n");
  8965. /* if the status is CMD_COMPLETE_PASS or CMD_COMPLETE_ERROR
  8966. * clear the status to CMD_CLEAR_COMPLETE
  8967. */
  8968. if (val == PHY84833_STATUS_CMD_COMPLETE_PASS ||
  8969. val == PHY84833_STATUS_CMD_COMPLETE_ERROR) {
  8970. bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
  8971. MDIO_848xx_CMD_HDLR_STATUS,
  8972. PHY84833_STATUS_CMD_CLEAR_COMPLETE);
  8973. }
  8974. return -EINVAL;
  8975. }
  8976. if (process == PHY84833_MB_PROCESS1 ||
  8977. process == PHY84833_MB_PROCESS2) {
  8978. /* Prepare argument(s) */
  8979. for (idx = 0; idx < argc; idx++) {
  8980. bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
  8981. MDIO_848xx_CMD_HDLR_DATA1 + idx,
  8982. cmd_args[idx]);
  8983. }
  8984. }
  8985. bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
  8986. MDIO_848xx_CMD_HDLR_COMMAND, fw_cmd);
  8987. for (idx = 0; idx < PHY848xx_CMDHDLR_WAIT; idx++) {
  8988. bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
  8989. MDIO_848xx_CMD_HDLR_STATUS, &val);
  8990. if ((val == PHY84833_STATUS_CMD_COMPLETE_PASS) ||
  8991. (val == PHY84833_STATUS_CMD_COMPLETE_ERROR))
  8992. break;
  8993. usleep_range(1000, 2000);
  8994. }
  8995. if ((idx >= PHY848xx_CMDHDLR_WAIT) ||
  8996. (val == PHY84833_STATUS_CMD_COMPLETE_ERROR)) {
  8997. DP(NETIF_MSG_LINK, "FW cmd failed.\n");
  8998. rc = -EINVAL;
  8999. }
  9000. if (process == PHY84833_MB_PROCESS3 && rc == 0) {
  9001. /* Gather returning data */
  9002. for (idx = 0; idx < argc; idx++) {
  9003. bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
  9004. MDIO_848xx_CMD_HDLR_DATA1 + idx,
  9005. &cmd_args[idx]);
  9006. }
  9007. }
  9008. if (val == PHY84833_STATUS_CMD_COMPLETE_ERROR ||
  9009. val == PHY84833_STATUS_CMD_COMPLETE_PASS) {
  9010. bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
  9011. MDIO_848xx_CMD_HDLR_STATUS,
  9012. PHY84833_STATUS_CMD_CLEAR_COMPLETE);
  9013. }
  9014. return rc;
  9015. }
  9016. static int bnx2x_848xx_cmd_hdlr(struct bnx2x_phy *phy,
  9017. struct link_params *params,
  9018. u16 fw_cmd,
  9019. u16 cmd_args[], int argc,
  9020. int process)
  9021. {
  9022. struct bnx2x *bp = params->bp;
  9023. if ((phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84858) ||
  9024. (REG_RD(bp, params->shmem2_base +
  9025. offsetof(struct shmem2_region,
  9026. link_attr_sync[params->port])) &
  9027. LINK_ATTR_84858)) {
  9028. return bnx2x_84858_cmd_hdlr(phy, params, fw_cmd, cmd_args,
  9029. argc);
  9030. } else {
  9031. return bnx2x_84833_cmd_hdlr(phy, params, fw_cmd, cmd_args,
  9032. argc, process);
  9033. }
  9034. }
  9035. static int bnx2x_848xx_pair_swap_cfg(struct bnx2x_phy *phy,
  9036. struct link_params *params,
  9037. struct link_vars *vars)
  9038. {
  9039. u32 pair_swap;
  9040. u16 data[PHY848xx_CMDHDLR_MAX_ARGS];
  9041. int status;
  9042. struct bnx2x *bp = params->bp;
  9043. /* Check for configuration. */
  9044. pair_swap = REG_RD(bp, params->shmem_base +
  9045. offsetof(struct shmem_region,
  9046. dev_info.port_hw_config[params->port].xgbt_phy_cfg)) &
  9047. PORT_HW_CFG_RJ45_PAIR_SWAP_MASK;
  9048. if (pair_swap == 0)
  9049. return 0;
  9050. /* Only the second argument is used for this command */
  9051. data[1] = (u16)pair_swap;
  9052. status = bnx2x_848xx_cmd_hdlr(phy, params,
  9053. PHY848xx_CMD_SET_PAIR_SWAP, data,
  9054. 2, PHY84833_MB_PROCESS2);
  9055. if (status == 0)
  9056. DP(NETIF_MSG_LINK, "Pairswap OK, val=0x%x\n", data[1]);
  9057. return status;
  9058. }
  9059. static u8 bnx2x_84833_get_reset_gpios(struct bnx2x *bp,
  9060. u32 shmem_base_path[],
  9061. u32 chip_id)
  9062. {
  9063. u32 reset_pin[2];
  9064. u32 idx;
  9065. u8 reset_gpios;
  9066. if (CHIP_IS_E3(bp)) {
  9067. /* Assume that these will be GPIOs, not EPIOs. */
  9068. for (idx = 0; idx < 2; idx++) {
  9069. /* Map config param to register bit. */
  9070. reset_pin[idx] = REG_RD(bp, shmem_base_path[idx] +
  9071. offsetof(struct shmem_region,
  9072. dev_info.port_hw_config[0].e3_cmn_pin_cfg));
  9073. reset_pin[idx] = (reset_pin[idx] &
  9074. PORT_HW_CFG_E3_PHY_RESET_MASK) >>
  9075. PORT_HW_CFG_E3_PHY_RESET_SHIFT;
  9076. reset_pin[idx] -= PIN_CFG_GPIO0_P0;
  9077. reset_pin[idx] = (1 << reset_pin[idx]);
  9078. }
  9079. reset_gpios = (u8)(reset_pin[0] | reset_pin[1]);
  9080. } else {
  9081. /* E2, look from diff place of shmem. */
  9082. for (idx = 0; idx < 2; idx++) {
  9083. reset_pin[idx] = REG_RD(bp, shmem_base_path[idx] +
  9084. offsetof(struct shmem_region,
  9085. dev_info.port_hw_config[0].default_cfg));
  9086. reset_pin[idx] &= PORT_HW_CFG_EXT_PHY_GPIO_RST_MASK;
  9087. reset_pin[idx] -= PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P0;
  9088. reset_pin[idx] >>= PORT_HW_CFG_EXT_PHY_GPIO_RST_SHIFT;
  9089. reset_pin[idx] = (1 << reset_pin[idx]);
  9090. }
  9091. reset_gpios = (u8)(reset_pin[0] | reset_pin[1]);
  9092. }
  9093. return reset_gpios;
  9094. }
  9095. static int bnx2x_84833_hw_reset_phy(struct bnx2x_phy *phy,
  9096. struct link_params *params)
  9097. {
  9098. struct bnx2x *bp = params->bp;
  9099. u8 reset_gpios;
  9100. u32 other_shmem_base_addr = REG_RD(bp, params->shmem2_base +
  9101. offsetof(struct shmem2_region,
  9102. other_shmem_base_addr));
  9103. u32 shmem_base_path[2];
  9104. /* Work around for 84833 LED failure inside RESET status */
  9105. bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
  9106. MDIO_AN_REG_8481_LEGACY_MII_CTRL,
  9107. MDIO_AN_REG_8481_MII_CTRL_FORCE_1G);
  9108. bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
  9109. MDIO_AN_REG_8481_1G_100T_EXT_CTRL,
  9110. MIDO_AN_REG_8481_EXT_CTRL_FORCE_LEDS_OFF);
  9111. shmem_base_path[0] = params->shmem_base;
  9112. shmem_base_path[1] = other_shmem_base_addr;
  9113. reset_gpios = bnx2x_84833_get_reset_gpios(bp, shmem_base_path,
  9114. params->chip_id);
  9115. bnx2x_set_mult_gpio(bp, reset_gpios, MISC_REGISTERS_GPIO_OUTPUT_LOW);
  9116. udelay(10);
  9117. DP(NETIF_MSG_LINK, "84833 hw reset on pin values 0x%x\n",
  9118. reset_gpios);
  9119. return 0;
  9120. }
  9121. static int bnx2x_8483x_disable_eee(struct bnx2x_phy *phy,
  9122. struct link_params *params,
  9123. struct link_vars *vars)
  9124. {
  9125. int rc;
  9126. struct bnx2x *bp = params->bp;
  9127. u16 cmd_args = 0;
  9128. DP(NETIF_MSG_LINK, "Don't Advertise 10GBase-T EEE\n");
  9129. /* Prevent Phy from working in EEE and advertising it */
  9130. rc = bnx2x_848xx_cmd_hdlr(phy, params, PHY848xx_CMD_SET_EEE_MODE,
  9131. &cmd_args, 1, PHY84833_MB_PROCESS1);
  9132. if (rc) {
  9133. DP(NETIF_MSG_LINK, "EEE disable failed.\n");
  9134. return rc;
  9135. }
  9136. return bnx2x_eee_disable(phy, params, vars);
  9137. }
  9138. static int bnx2x_8483x_enable_eee(struct bnx2x_phy *phy,
  9139. struct link_params *params,
  9140. struct link_vars *vars)
  9141. {
  9142. int rc;
  9143. struct bnx2x *bp = params->bp;
  9144. u16 cmd_args = 1;
  9145. rc = bnx2x_848xx_cmd_hdlr(phy, params, PHY848xx_CMD_SET_EEE_MODE,
  9146. &cmd_args, 1, PHY84833_MB_PROCESS1);
  9147. if (rc) {
  9148. DP(NETIF_MSG_LINK, "EEE enable failed.\n");
  9149. return rc;
  9150. }
  9151. return bnx2x_eee_advertise(phy, params, vars, SHMEM_EEE_10G_ADV);
  9152. }
  9153. #define PHY84833_CONSTANT_LATENCY 1193
  9154. static int bnx2x_848x3_config_init(struct bnx2x_phy *phy,
  9155. struct link_params *params,
  9156. struct link_vars *vars)
  9157. {
  9158. struct bnx2x *bp = params->bp;
  9159. u8 port, initialize = 1;
  9160. u16 val;
  9161. u32 actual_phy_selection;
  9162. u16 cmd_args[PHY848xx_CMDHDLR_MAX_ARGS];
  9163. int rc = 0;
  9164. usleep_range(1000, 2000);
  9165. if (!(CHIP_IS_E1x(bp)))
  9166. port = BP_PATH(bp);
  9167. else
  9168. port = params->port;
  9169. if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823) {
  9170. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
  9171. MISC_REGISTERS_GPIO_OUTPUT_HIGH,
  9172. port);
  9173. } else {
  9174. /* MDIO reset */
  9175. bnx2x_cl45_write(bp, phy,
  9176. MDIO_PMA_DEVAD,
  9177. MDIO_PMA_REG_CTRL, 0x8000);
  9178. }
  9179. bnx2x_wait_reset_complete(bp, phy, params);
  9180. /* Wait for GPHY to come out of reset */
  9181. msleep(50);
  9182. if (!bnx2x_is_8483x_8485x(phy)) {
  9183. /* BCM84823 requires that XGXS links up first @ 10G for normal
  9184. * behavior.
  9185. */
  9186. u16 temp;
  9187. temp = vars->line_speed;
  9188. vars->line_speed = SPEED_10000;
  9189. bnx2x_set_autoneg(&params->phy[INT_PHY], params, vars, 0);
  9190. bnx2x_program_serdes(&params->phy[INT_PHY], params, vars);
  9191. vars->line_speed = temp;
  9192. }
  9193. /* Check if this is actually BCM84858 */
  9194. if (phy->type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84858) {
  9195. u16 hw_rev;
  9196. bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
  9197. MDIO_AN_REG_848xx_ID_MSB, &hw_rev);
  9198. if (hw_rev == BCM84858_PHY_ID) {
  9199. params->link_attr_sync |= LINK_ATTR_84858;
  9200. bnx2x_update_link_attr(params, params->link_attr_sync);
  9201. }
  9202. }
  9203. /* Set dual-media configuration according to configuration */
  9204. bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
  9205. MDIO_CTL_REG_84823_MEDIA, &val);
  9206. val &= ~(MDIO_CTL_REG_84823_MEDIA_MAC_MASK |
  9207. MDIO_CTL_REG_84823_MEDIA_LINE_MASK |
  9208. MDIO_CTL_REG_84823_MEDIA_COPPER_CORE_DOWN |
  9209. MDIO_CTL_REG_84823_MEDIA_PRIORITY_MASK |
  9210. MDIO_CTL_REG_84823_MEDIA_FIBER_1G);
  9211. if (CHIP_IS_E3(bp)) {
  9212. val &= ~(MDIO_CTL_REG_84823_MEDIA_MAC_MASK |
  9213. MDIO_CTL_REG_84823_MEDIA_LINE_MASK);
  9214. } else {
  9215. val |= (MDIO_CTL_REG_84823_CTRL_MAC_XFI |
  9216. MDIO_CTL_REG_84823_MEDIA_LINE_XAUI_L);
  9217. }
  9218. actual_phy_selection = bnx2x_phy_selection(params);
  9219. switch (actual_phy_selection) {
  9220. case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
  9221. /* Do nothing. Essentially this is like the priority copper */
  9222. break;
  9223. case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
  9224. val |= MDIO_CTL_REG_84823_MEDIA_PRIORITY_COPPER;
  9225. break;
  9226. case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
  9227. val |= MDIO_CTL_REG_84823_MEDIA_PRIORITY_FIBER;
  9228. break;
  9229. case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
  9230. /* Do nothing here. The first PHY won't be initialized at all */
  9231. break;
  9232. case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
  9233. val |= MDIO_CTL_REG_84823_MEDIA_COPPER_CORE_DOWN;
  9234. initialize = 0;
  9235. break;
  9236. }
  9237. if (params->phy[EXT_PHY2].req_line_speed == SPEED_1000)
  9238. val |= MDIO_CTL_REG_84823_MEDIA_FIBER_1G;
  9239. bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
  9240. MDIO_CTL_REG_84823_MEDIA, val);
  9241. DP(NETIF_MSG_LINK, "Multi_phy config = 0x%x, Media control = 0x%x\n",
  9242. params->multi_phy_config, val);
  9243. if (bnx2x_is_8483x_8485x(phy)) {
  9244. bnx2x_848xx_pair_swap_cfg(phy, params, vars);
  9245. /* Keep AutogrEEEn disabled. */
  9246. cmd_args[0] = 0x0;
  9247. cmd_args[1] = 0x0;
  9248. cmd_args[2] = PHY84833_CONSTANT_LATENCY + 1;
  9249. cmd_args[3] = PHY84833_CONSTANT_LATENCY;
  9250. rc = bnx2x_848xx_cmd_hdlr(phy, params,
  9251. PHY848xx_CMD_SET_EEE_MODE, cmd_args,
  9252. 4, PHY84833_MB_PROCESS1);
  9253. if (rc)
  9254. DP(NETIF_MSG_LINK, "Cfg AutogrEEEn failed.\n");
  9255. }
  9256. if (initialize)
  9257. rc = bnx2x_848xx_cmn_config_init(phy, params, vars);
  9258. else
  9259. bnx2x_save_848xx_spirom_version(phy, bp, params->port);
  9260. /* 84833 PHY has a better feature and doesn't need to support this. */
  9261. if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823) {
  9262. u32 cms_enable = REG_RD(bp, params->shmem_base +
  9263. offsetof(struct shmem_region,
  9264. dev_info.port_hw_config[params->port].default_cfg)) &
  9265. PORT_HW_CFG_ENABLE_CMS_MASK;
  9266. bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
  9267. MDIO_CTL_REG_84823_USER_CTRL_REG, &val);
  9268. if (cms_enable)
  9269. val |= MDIO_CTL_REG_84823_USER_CTRL_CMS;
  9270. else
  9271. val &= ~MDIO_CTL_REG_84823_USER_CTRL_CMS;
  9272. bnx2x_cl45_write(bp, phy, MDIO_CTL_DEVAD,
  9273. MDIO_CTL_REG_84823_USER_CTRL_REG, val);
  9274. }
  9275. bnx2x_cl45_read(bp, phy, MDIO_CTL_DEVAD,
  9276. MDIO_84833_TOP_CFG_FW_REV, &val);
  9277. /* Configure EEE support */
  9278. if ((val >= MDIO_84833_TOP_CFG_FW_EEE) &&
  9279. (val != MDIO_84833_TOP_CFG_FW_NO_EEE) &&
  9280. bnx2x_eee_has_cap(params)) {
  9281. rc = bnx2x_eee_initial_config(params, vars, SHMEM_EEE_10G_ADV);
  9282. if (rc) {
  9283. DP(NETIF_MSG_LINK, "Failed to configure EEE timers\n");
  9284. bnx2x_8483x_disable_eee(phy, params, vars);
  9285. return rc;
  9286. }
  9287. if ((phy->req_duplex == DUPLEX_FULL) &&
  9288. (params->eee_mode & EEE_MODE_ADV_LPI) &&
  9289. (bnx2x_eee_calc_timer(params) ||
  9290. !(params->eee_mode & EEE_MODE_ENABLE_LPI)))
  9291. rc = bnx2x_8483x_enable_eee(phy, params, vars);
  9292. else
  9293. rc = bnx2x_8483x_disable_eee(phy, params, vars);
  9294. if (rc) {
  9295. DP(NETIF_MSG_LINK, "Failed to set EEE advertisement\n");
  9296. return rc;
  9297. }
  9298. } else {
  9299. vars->eee_status &= ~SHMEM_EEE_SUPPORTED_MASK;
  9300. }
  9301. if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833) {
  9302. /* Additional settings for jumbo packets in 1000BASE-T mode */
  9303. /* Allow rx extended length */
  9304. bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
  9305. MDIO_AN_REG_8481_AUX_CTRL, &val);
  9306. val |= 0x4000;
  9307. bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
  9308. MDIO_AN_REG_8481_AUX_CTRL, val);
  9309. /* TX FIFO Elasticity LSB */
  9310. bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
  9311. MDIO_AN_REG_8481_1G_100T_EXT_CTRL, &val);
  9312. val |= 0x1;
  9313. bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
  9314. MDIO_AN_REG_8481_1G_100T_EXT_CTRL, val);
  9315. /* TX FIFO Elasticity MSB */
  9316. /* Enable expansion register 0x46 (Pattern Generator status) */
  9317. bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
  9318. MDIO_AN_REG_8481_EXPANSION_REG_ACCESS, 0xf46);
  9319. bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
  9320. MDIO_AN_REG_8481_EXPANSION_REG_RD_RW, &val);
  9321. val |= 0x4000;
  9322. bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
  9323. MDIO_AN_REG_8481_EXPANSION_REG_RD_RW, val);
  9324. }
  9325. if (bnx2x_is_8483x_8485x(phy)) {
  9326. /* Bring PHY out of super isolate mode as the final step. */
  9327. bnx2x_cl45_read_and_write(bp, phy,
  9328. MDIO_CTL_DEVAD,
  9329. MDIO_84833_TOP_CFG_XGPHY_STRAP1,
  9330. (u16)~MDIO_84833_SUPER_ISOLATE);
  9331. }
  9332. return rc;
  9333. }
  9334. static u8 bnx2x_848xx_read_status(struct bnx2x_phy *phy,
  9335. struct link_params *params,
  9336. struct link_vars *vars)
  9337. {
  9338. struct bnx2x *bp = params->bp;
  9339. u16 val, val1, val2;
  9340. u8 link_up = 0;
  9341. /* Check 10G-BaseT link status */
  9342. /* Check PMD signal ok */
  9343. bnx2x_cl45_read(bp, phy,
  9344. MDIO_AN_DEVAD, 0xFFFA, &val1);
  9345. bnx2x_cl45_read(bp, phy,
  9346. MDIO_PMA_DEVAD, MDIO_PMA_REG_8481_PMD_SIGNAL,
  9347. &val2);
  9348. DP(NETIF_MSG_LINK, "BCM848xx: PMD_SIGNAL 1.a811 = 0x%x\n", val2);
  9349. /* Check link 10G */
  9350. if (val2 & (1<<11)) {
  9351. vars->line_speed = SPEED_10000;
  9352. vars->duplex = DUPLEX_FULL;
  9353. link_up = 1;
  9354. bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
  9355. } else { /* Check Legacy speed link */
  9356. u16 legacy_status, legacy_speed;
  9357. /* Enable expansion register 0x42 (Operation mode status) */
  9358. bnx2x_cl45_write(bp, phy,
  9359. MDIO_AN_DEVAD,
  9360. MDIO_AN_REG_8481_EXPANSION_REG_ACCESS, 0xf42);
  9361. /* Get legacy speed operation status */
  9362. bnx2x_cl45_read(bp, phy,
  9363. MDIO_AN_DEVAD,
  9364. MDIO_AN_REG_8481_EXPANSION_REG_RD_RW,
  9365. &legacy_status);
  9366. DP(NETIF_MSG_LINK, "Legacy speed status = 0x%x\n",
  9367. legacy_status);
  9368. link_up = ((legacy_status & (1<<11)) == (1<<11));
  9369. legacy_speed = (legacy_status & (3<<9));
  9370. if (legacy_speed == (0<<9))
  9371. vars->line_speed = SPEED_10;
  9372. else if (legacy_speed == (1<<9))
  9373. vars->line_speed = SPEED_100;
  9374. else if (legacy_speed == (2<<9))
  9375. vars->line_speed = SPEED_1000;
  9376. else { /* Should not happen: Treat as link down */
  9377. vars->line_speed = 0;
  9378. link_up = 0;
  9379. }
  9380. if (link_up) {
  9381. if (legacy_status & (1<<8))
  9382. vars->duplex = DUPLEX_FULL;
  9383. else
  9384. vars->duplex = DUPLEX_HALF;
  9385. DP(NETIF_MSG_LINK,
  9386. "Link is up in %dMbps, is_duplex_full= %d\n",
  9387. vars->line_speed,
  9388. (vars->duplex == DUPLEX_FULL));
  9389. /* Check legacy speed AN resolution */
  9390. bnx2x_cl45_read(bp, phy,
  9391. MDIO_AN_DEVAD,
  9392. MDIO_AN_REG_8481_LEGACY_MII_STATUS,
  9393. &val);
  9394. if (val & (1<<5))
  9395. vars->link_status |=
  9396. LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
  9397. bnx2x_cl45_read(bp, phy,
  9398. MDIO_AN_DEVAD,
  9399. MDIO_AN_REG_8481_LEGACY_AN_EXPANSION,
  9400. &val);
  9401. if ((val & (1<<0)) == 0)
  9402. vars->link_status |=
  9403. LINK_STATUS_PARALLEL_DETECTION_USED;
  9404. }
  9405. }
  9406. if (link_up) {
  9407. DP(NETIF_MSG_LINK, "BCM848x3: link speed is %d\n",
  9408. vars->line_speed);
  9409. bnx2x_ext_phy_resolve_fc(phy, params, vars);
  9410. /* Read LP advertised speeds */
  9411. bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
  9412. MDIO_AN_REG_CL37_FC_LP, &val);
  9413. if (val & (1<<5))
  9414. vars->link_status |=
  9415. LINK_STATUS_LINK_PARTNER_10THD_CAPABLE;
  9416. if (val & (1<<6))
  9417. vars->link_status |=
  9418. LINK_STATUS_LINK_PARTNER_10TFD_CAPABLE;
  9419. if (val & (1<<7))
  9420. vars->link_status |=
  9421. LINK_STATUS_LINK_PARTNER_100TXHD_CAPABLE;
  9422. if (val & (1<<8))
  9423. vars->link_status |=
  9424. LINK_STATUS_LINK_PARTNER_100TXFD_CAPABLE;
  9425. if (val & (1<<9))
  9426. vars->link_status |=
  9427. LINK_STATUS_LINK_PARTNER_100T4_CAPABLE;
  9428. bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
  9429. MDIO_AN_REG_1000T_STATUS, &val);
  9430. if (val & (1<<10))
  9431. vars->link_status |=
  9432. LINK_STATUS_LINK_PARTNER_1000THD_CAPABLE;
  9433. if (val & (1<<11))
  9434. vars->link_status |=
  9435. LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE;
  9436. bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
  9437. MDIO_AN_REG_MASTER_STATUS, &val);
  9438. if (val & (1<<11))
  9439. vars->link_status |=
  9440. LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
  9441. /* Determine if EEE was negotiated */
  9442. if (bnx2x_is_8483x_8485x(phy))
  9443. bnx2x_eee_an_resolve(phy, params, vars);
  9444. }
  9445. return link_up;
  9446. }
  9447. static int bnx2x_8485x_format_ver(u32 raw_ver, u8 *str, u16 *len)
  9448. {
  9449. int status = 0;
  9450. u32 num;
  9451. num = ((raw_ver & 0xF80) >> 7) << 16 | ((raw_ver & 0x7F) << 8) |
  9452. ((raw_ver & 0xF000) >> 12);
  9453. status = bnx2x_3_seq_format_ver(num, str, len);
  9454. return status;
  9455. }
  9456. static int bnx2x_848xx_format_ver(u32 raw_ver, u8 *str, u16 *len)
  9457. {
  9458. int status = 0;
  9459. u32 spirom_ver;
  9460. spirom_ver = ((raw_ver & 0xF80) >> 7) << 16 | (raw_ver & 0x7F);
  9461. status = bnx2x_format_ver(spirom_ver, str, len);
  9462. return status;
  9463. }
  9464. static void bnx2x_8481_hw_reset(struct bnx2x_phy *phy,
  9465. struct link_params *params)
  9466. {
  9467. bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
  9468. MISC_REGISTERS_GPIO_OUTPUT_LOW, 0);
  9469. bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
  9470. MISC_REGISTERS_GPIO_OUTPUT_LOW, 1);
  9471. }
  9472. static void bnx2x_8481_link_reset(struct bnx2x_phy *phy,
  9473. struct link_params *params)
  9474. {
  9475. bnx2x_cl45_write(params->bp, phy,
  9476. MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, 0x0000);
  9477. bnx2x_cl45_write(params->bp, phy,
  9478. MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1);
  9479. }
  9480. static void bnx2x_848x3_link_reset(struct bnx2x_phy *phy,
  9481. struct link_params *params)
  9482. {
  9483. struct bnx2x *bp = params->bp;
  9484. u8 port;
  9485. u16 val16;
  9486. if (!(CHIP_IS_E1x(bp)))
  9487. port = BP_PATH(bp);
  9488. else
  9489. port = params->port;
  9490. if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823) {
  9491. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
  9492. MISC_REGISTERS_GPIO_OUTPUT_LOW,
  9493. port);
  9494. } else {
  9495. bnx2x_cl45_read(bp, phy,
  9496. MDIO_CTL_DEVAD,
  9497. MDIO_84833_TOP_CFG_XGPHY_STRAP1, &val16);
  9498. val16 |= MDIO_84833_SUPER_ISOLATE;
  9499. bnx2x_cl45_write(bp, phy,
  9500. MDIO_CTL_DEVAD,
  9501. MDIO_84833_TOP_CFG_XGPHY_STRAP1, val16);
  9502. }
  9503. }
  9504. static void bnx2x_848xx_set_link_led(struct bnx2x_phy *phy,
  9505. struct link_params *params, u8 mode)
  9506. {
  9507. struct bnx2x *bp = params->bp;
  9508. u16 val;
  9509. u8 port;
  9510. if (!(CHIP_IS_E1x(bp)))
  9511. port = BP_PATH(bp);
  9512. else
  9513. port = params->port;
  9514. switch (mode) {
  9515. case LED_MODE_OFF:
  9516. DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE OFF\n", port);
  9517. if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
  9518. SHARED_HW_CFG_LED_EXTPHY1) {
  9519. /* Set LED masks */
  9520. bnx2x_cl45_write(bp, phy,
  9521. MDIO_PMA_DEVAD,
  9522. MDIO_PMA_REG_8481_LED1_MASK,
  9523. 0x0);
  9524. bnx2x_cl45_write(bp, phy,
  9525. MDIO_PMA_DEVAD,
  9526. MDIO_PMA_REG_8481_LED2_MASK,
  9527. 0x0);
  9528. bnx2x_cl45_write(bp, phy,
  9529. MDIO_PMA_DEVAD,
  9530. MDIO_PMA_REG_8481_LED3_MASK,
  9531. 0x0);
  9532. bnx2x_cl45_write(bp, phy,
  9533. MDIO_PMA_DEVAD,
  9534. MDIO_PMA_REG_8481_LED5_MASK,
  9535. 0x0);
  9536. } else {
  9537. /* LED 1 OFF */
  9538. bnx2x_cl45_write(bp, phy,
  9539. MDIO_PMA_DEVAD,
  9540. MDIO_PMA_REG_8481_LED1_MASK,
  9541. 0x0);
  9542. if (phy->type ==
  9543. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84858) {
  9544. /* LED 2 OFF */
  9545. bnx2x_cl45_write(bp, phy,
  9546. MDIO_PMA_DEVAD,
  9547. MDIO_PMA_REG_8481_LED2_MASK,
  9548. 0x0);
  9549. /* LED 3 OFF */
  9550. bnx2x_cl45_write(bp, phy,
  9551. MDIO_PMA_DEVAD,
  9552. MDIO_PMA_REG_8481_LED3_MASK,
  9553. 0x0);
  9554. }
  9555. }
  9556. break;
  9557. case LED_MODE_FRONT_PANEL_OFF:
  9558. DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE FRONT PANEL OFF\n",
  9559. port);
  9560. if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
  9561. SHARED_HW_CFG_LED_EXTPHY1) {
  9562. /* Set LED masks */
  9563. bnx2x_cl45_write(bp, phy,
  9564. MDIO_PMA_DEVAD,
  9565. MDIO_PMA_REG_8481_LED1_MASK,
  9566. 0x0);
  9567. bnx2x_cl45_write(bp, phy,
  9568. MDIO_PMA_DEVAD,
  9569. MDIO_PMA_REG_8481_LED2_MASK,
  9570. 0x0);
  9571. bnx2x_cl45_write(bp, phy,
  9572. MDIO_PMA_DEVAD,
  9573. MDIO_PMA_REG_8481_LED3_MASK,
  9574. 0x0);
  9575. bnx2x_cl45_write(bp, phy,
  9576. MDIO_PMA_DEVAD,
  9577. MDIO_PMA_REG_8481_LED5_MASK,
  9578. 0x20);
  9579. } else {
  9580. bnx2x_cl45_write(bp, phy,
  9581. MDIO_PMA_DEVAD,
  9582. MDIO_PMA_REG_8481_LED1_MASK,
  9583. 0x0);
  9584. if (phy->type ==
  9585. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84834) {
  9586. /* Disable MI_INT interrupt before setting LED4
  9587. * source to constant off.
  9588. */
  9589. if (REG_RD(bp, NIG_REG_MASK_INTERRUPT_PORT0 +
  9590. params->port*4) &
  9591. NIG_MASK_MI_INT) {
  9592. params->link_flags |=
  9593. LINK_FLAGS_INT_DISABLED;
  9594. bnx2x_bits_dis(
  9595. bp,
  9596. NIG_REG_MASK_INTERRUPT_PORT0 +
  9597. params->port*4,
  9598. NIG_MASK_MI_INT);
  9599. }
  9600. bnx2x_cl45_write(bp, phy,
  9601. MDIO_PMA_DEVAD,
  9602. MDIO_PMA_REG_8481_SIGNAL_MASK,
  9603. 0x0);
  9604. }
  9605. if (phy->type ==
  9606. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84858) {
  9607. /* LED 2 OFF */
  9608. bnx2x_cl45_write(bp, phy,
  9609. MDIO_PMA_DEVAD,
  9610. MDIO_PMA_REG_8481_LED2_MASK,
  9611. 0x0);
  9612. /* LED 3 OFF */
  9613. bnx2x_cl45_write(bp, phy,
  9614. MDIO_PMA_DEVAD,
  9615. MDIO_PMA_REG_8481_LED3_MASK,
  9616. 0x0);
  9617. }
  9618. }
  9619. break;
  9620. case LED_MODE_ON:
  9621. DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE ON\n", port);
  9622. if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
  9623. SHARED_HW_CFG_LED_EXTPHY1) {
  9624. /* Set control reg */
  9625. bnx2x_cl45_read(bp, phy,
  9626. MDIO_PMA_DEVAD,
  9627. MDIO_PMA_REG_8481_LINK_SIGNAL,
  9628. &val);
  9629. val &= 0x8000;
  9630. val |= 0x2492;
  9631. bnx2x_cl45_write(bp, phy,
  9632. MDIO_PMA_DEVAD,
  9633. MDIO_PMA_REG_8481_LINK_SIGNAL,
  9634. val);
  9635. /* Set LED masks */
  9636. bnx2x_cl45_write(bp, phy,
  9637. MDIO_PMA_DEVAD,
  9638. MDIO_PMA_REG_8481_LED1_MASK,
  9639. 0x0);
  9640. bnx2x_cl45_write(bp, phy,
  9641. MDIO_PMA_DEVAD,
  9642. MDIO_PMA_REG_8481_LED2_MASK,
  9643. 0x20);
  9644. bnx2x_cl45_write(bp, phy,
  9645. MDIO_PMA_DEVAD,
  9646. MDIO_PMA_REG_8481_LED3_MASK,
  9647. 0x20);
  9648. bnx2x_cl45_write(bp, phy,
  9649. MDIO_PMA_DEVAD,
  9650. MDIO_PMA_REG_8481_LED5_MASK,
  9651. 0x0);
  9652. } else {
  9653. bnx2x_cl45_write(bp, phy,
  9654. MDIO_PMA_DEVAD,
  9655. MDIO_PMA_REG_8481_LED1_MASK,
  9656. 0x20);
  9657. if (phy->type ==
  9658. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84834) {
  9659. /* Disable MI_INT interrupt before setting LED4
  9660. * source to constant on.
  9661. */
  9662. if (REG_RD(bp, NIG_REG_MASK_INTERRUPT_PORT0 +
  9663. params->port*4) &
  9664. NIG_MASK_MI_INT) {
  9665. params->link_flags |=
  9666. LINK_FLAGS_INT_DISABLED;
  9667. bnx2x_bits_dis(
  9668. bp,
  9669. NIG_REG_MASK_INTERRUPT_PORT0 +
  9670. params->port*4,
  9671. NIG_MASK_MI_INT);
  9672. }
  9673. }
  9674. if (phy->type ==
  9675. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84858) {
  9676. /* Tell LED3 to constant on */
  9677. bnx2x_cl45_read(bp, phy,
  9678. MDIO_PMA_DEVAD,
  9679. MDIO_PMA_REG_8481_LINK_SIGNAL,
  9680. &val);
  9681. val &= ~(7<<6);
  9682. val |= (2<<6); /* A83B[8:6]= 2 */
  9683. bnx2x_cl45_write(bp, phy,
  9684. MDIO_PMA_DEVAD,
  9685. MDIO_PMA_REG_8481_LINK_SIGNAL,
  9686. val);
  9687. bnx2x_cl45_write(bp, phy,
  9688. MDIO_PMA_DEVAD,
  9689. MDIO_PMA_REG_8481_LED3_MASK,
  9690. 0x20);
  9691. } else {
  9692. bnx2x_cl45_write(bp, phy,
  9693. MDIO_PMA_DEVAD,
  9694. MDIO_PMA_REG_8481_SIGNAL_MASK,
  9695. 0x20);
  9696. }
  9697. }
  9698. break;
  9699. case LED_MODE_OPER:
  9700. DP(NETIF_MSG_LINK, "Port 0x%x: LED MODE OPER\n", port);
  9701. if ((params->hw_led_mode << SHARED_HW_CFG_LED_MODE_SHIFT) ==
  9702. SHARED_HW_CFG_LED_EXTPHY1) {
  9703. /* Set control reg */
  9704. bnx2x_cl45_read(bp, phy,
  9705. MDIO_PMA_DEVAD,
  9706. MDIO_PMA_REG_8481_LINK_SIGNAL,
  9707. &val);
  9708. if (!((val &
  9709. MDIO_PMA_REG_8481_LINK_SIGNAL_LED4_ENABLE_MASK)
  9710. >> MDIO_PMA_REG_8481_LINK_SIGNAL_LED4_ENABLE_SHIFT)) {
  9711. DP(NETIF_MSG_LINK, "Setting LINK_SIGNAL\n");
  9712. bnx2x_cl45_write(bp, phy,
  9713. MDIO_PMA_DEVAD,
  9714. MDIO_PMA_REG_8481_LINK_SIGNAL,
  9715. 0xa492);
  9716. }
  9717. /* Set LED masks */
  9718. bnx2x_cl45_write(bp, phy,
  9719. MDIO_PMA_DEVAD,
  9720. MDIO_PMA_REG_8481_LED1_MASK,
  9721. 0x10);
  9722. bnx2x_cl45_write(bp, phy,
  9723. MDIO_PMA_DEVAD,
  9724. MDIO_PMA_REG_8481_LED2_MASK,
  9725. 0x80);
  9726. bnx2x_cl45_write(bp, phy,
  9727. MDIO_PMA_DEVAD,
  9728. MDIO_PMA_REG_8481_LED3_MASK,
  9729. 0x98);
  9730. bnx2x_cl45_write(bp, phy,
  9731. MDIO_PMA_DEVAD,
  9732. MDIO_PMA_REG_8481_LED5_MASK,
  9733. 0x40);
  9734. } else {
  9735. /* EXTPHY2 LED mode indicate that the 100M/1G/10G LED
  9736. * sources are all wired through LED1, rather than only
  9737. * 10G in other modes.
  9738. */
  9739. val = ((params->hw_led_mode <<
  9740. SHARED_HW_CFG_LED_MODE_SHIFT) ==
  9741. SHARED_HW_CFG_LED_EXTPHY2) ? 0x98 : 0x80;
  9742. bnx2x_cl45_write(bp, phy,
  9743. MDIO_PMA_DEVAD,
  9744. MDIO_PMA_REG_8481_LED1_MASK,
  9745. val);
  9746. /* Tell LED3 to blink on source */
  9747. bnx2x_cl45_read(bp, phy,
  9748. MDIO_PMA_DEVAD,
  9749. MDIO_PMA_REG_8481_LINK_SIGNAL,
  9750. &val);
  9751. val &= ~(7<<6);
  9752. val |= (1<<6); /* A83B[8:6]= 1 */
  9753. bnx2x_cl45_write(bp, phy,
  9754. MDIO_PMA_DEVAD,
  9755. MDIO_PMA_REG_8481_LINK_SIGNAL,
  9756. val);
  9757. if (phy->type ==
  9758. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84858) {
  9759. bnx2x_cl45_write(bp, phy,
  9760. MDIO_PMA_DEVAD,
  9761. MDIO_PMA_REG_8481_LED2_MASK,
  9762. 0x18);
  9763. bnx2x_cl45_write(bp, phy,
  9764. MDIO_PMA_DEVAD,
  9765. MDIO_PMA_REG_8481_LED3_MASK,
  9766. 0x06);
  9767. }
  9768. if (phy->type ==
  9769. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84834) {
  9770. /* Restore LED4 source to external link,
  9771. * and re-enable interrupts.
  9772. */
  9773. bnx2x_cl45_write(bp, phy,
  9774. MDIO_PMA_DEVAD,
  9775. MDIO_PMA_REG_8481_SIGNAL_MASK,
  9776. 0x40);
  9777. if (params->link_flags &
  9778. LINK_FLAGS_INT_DISABLED) {
  9779. bnx2x_link_int_enable(params);
  9780. params->link_flags &=
  9781. ~LINK_FLAGS_INT_DISABLED;
  9782. }
  9783. }
  9784. }
  9785. break;
  9786. }
  9787. /* This is a workaround for E3+84833 until autoneg
  9788. * restart is fixed in f/w
  9789. */
  9790. if (CHIP_IS_E3(bp)) {
  9791. bnx2x_cl45_read(bp, phy, MDIO_WC_DEVAD,
  9792. MDIO_WC_REG_GP2_STATUS_GP_2_1, &val);
  9793. }
  9794. }
  9795. /******************************************************************/
  9796. /* 54618SE PHY SECTION */
  9797. /******************************************************************/
  9798. static void bnx2x_54618se_specific_func(struct bnx2x_phy *phy,
  9799. struct link_params *params,
  9800. u32 action)
  9801. {
  9802. struct bnx2x *bp = params->bp;
  9803. u16 temp;
  9804. switch (action) {
  9805. case PHY_INIT:
  9806. /* Configure LED4: set to INTR (0x6). */
  9807. /* Accessing shadow register 0xe. */
  9808. bnx2x_cl22_write(bp, phy,
  9809. MDIO_REG_GPHY_SHADOW,
  9810. MDIO_REG_GPHY_SHADOW_LED_SEL2);
  9811. bnx2x_cl22_read(bp, phy,
  9812. MDIO_REG_GPHY_SHADOW,
  9813. &temp);
  9814. temp &= ~(0xf << 4);
  9815. temp |= (0x6 << 4);
  9816. bnx2x_cl22_write(bp, phy,
  9817. MDIO_REG_GPHY_SHADOW,
  9818. MDIO_REG_GPHY_SHADOW_WR_ENA | temp);
  9819. /* Configure INTR based on link status change. */
  9820. bnx2x_cl22_write(bp, phy,
  9821. MDIO_REG_INTR_MASK,
  9822. ~MDIO_REG_INTR_MASK_LINK_STATUS);
  9823. break;
  9824. }
  9825. }
  9826. static int bnx2x_54618se_config_init(struct bnx2x_phy *phy,
  9827. struct link_params *params,
  9828. struct link_vars *vars)
  9829. {
  9830. struct bnx2x *bp = params->bp;
  9831. u8 port;
  9832. u16 autoneg_val, an_1000_val, an_10_100_val, fc_val, temp;
  9833. u32 cfg_pin;
  9834. DP(NETIF_MSG_LINK, "54618SE cfg init\n");
  9835. usleep_range(1000, 2000);
  9836. /* This works with E3 only, no need to check the chip
  9837. * before determining the port.
  9838. */
  9839. port = params->port;
  9840. cfg_pin = (REG_RD(bp, params->shmem_base +
  9841. offsetof(struct shmem_region,
  9842. dev_info.port_hw_config[port].e3_cmn_pin_cfg)) &
  9843. PORT_HW_CFG_E3_PHY_RESET_MASK) >>
  9844. PORT_HW_CFG_E3_PHY_RESET_SHIFT;
  9845. /* Drive pin high to bring the GPHY out of reset. */
  9846. bnx2x_set_cfg_pin(bp, cfg_pin, 1);
  9847. /* wait for GPHY to reset */
  9848. msleep(50);
  9849. /* reset phy */
  9850. bnx2x_cl22_write(bp, phy,
  9851. MDIO_PMA_REG_CTRL, 0x8000);
  9852. bnx2x_wait_reset_complete(bp, phy, params);
  9853. /* Wait for GPHY to reset */
  9854. msleep(50);
  9855. bnx2x_54618se_specific_func(phy, params, PHY_INIT);
  9856. /* Flip the signal detect polarity (set 0x1c.0x1e[8]). */
  9857. bnx2x_cl22_write(bp, phy,
  9858. MDIO_REG_GPHY_SHADOW,
  9859. MDIO_REG_GPHY_SHADOW_AUTO_DET_MED);
  9860. bnx2x_cl22_read(bp, phy,
  9861. MDIO_REG_GPHY_SHADOW,
  9862. &temp);
  9863. temp |= MDIO_REG_GPHY_SHADOW_INVERT_FIB_SD;
  9864. bnx2x_cl22_write(bp, phy,
  9865. MDIO_REG_GPHY_SHADOW,
  9866. MDIO_REG_GPHY_SHADOW_WR_ENA | temp);
  9867. /* Set up fc */
  9868. /* Please refer to Table 28B-3 of 802.3ab-1999 spec. */
  9869. bnx2x_calc_ieee_aneg_adv(phy, params, &vars->ieee_fc);
  9870. fc_val = 0;
  9871. if ((vars->ieee_fc & MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC) ==
  9872. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC)
  9873. fc_val |= MDIO_AN_REG_ADV_PAUSE_ASYMMETRIC;
  9874. if ((vars->ieee_fc & MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH) ==
  9875. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH)
  9876. fc_val |= MDIO_AN_REG_ADV_PAUSE_PAUSE;
  9877. /* Read all advertisement */
  9878. bnx2x_cl22_read(bp, phy,
  9879. 0x09,
  9880. &an_1000_val);
  9881. bnx2x_cl22_read(bp, phy,
  9882. 0x04,
  9883. &an_10_100_val);
  9884. bnx2x_cl22_read(bp, phy,
  9885. MDIO_PMA_REG_CTRL,
  9886. &autoneg_val);
  9887. /* Disable forced speed */
  9888. autoneg_val &= ~((1<<6) | (1<<8) | (1<<9) | (1<<12) | (1<<13));
  9889. an_10_100_val &= ~((1<<5) | (1<<6) | (1<<7) | (1<<8) | (1<<10) |
  9890. (1<<11));
  9891. if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
  9892. (phy->speed_cap_mask &
  9893. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) ||
  9894. (phy->req_line_speed == SPEED_1000)) {
  9895. an_1000_val |= (1<<8);
  9896. autoneg_val |= (1<<9 | 1<<12);
  9897. if (phy->req_duplex == DUPLEX_FULL)
  9898. an_1000_val |= (1<<9);
  9899. DP(NETIF_MSG_LINK, "Advertising 1G\n");
  9900. } else
  9901. an_1000_val &= ~((1<<8) | (1<<9));
  9902. bnx2x_cl22_write(bp, phy,
  9903. 0x09,
  9904. an_1000_val);
  9905. bnx2x_cl22_read(bp, phy,
  9906. 0x09,
  9907. &an_1000_val);
  9908. /* Advertise 10/100 link speed */
  9909. if (phy->req_line_speed == SPEED_AUTO_NEG) {
  9910. if (phy->speed_cap_mask &
  9911. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF) {
  9912. an_10_100_val |= (1<<5);
  9913. autoneg_val |= (1<<9 | 1<<12);
  9914. DP(NETIF_MSG_LINK, "Advertising 10M-HD\n");
  9915. }
  9916. if (phy->speed_cap_mask &
  9917. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL) {
  9918. an_10_100_val |= (1<<6);
  9919. autoneg_val |= (1<<9 | 1<<12);
  9920. DP(NETIF_MSG_LINK, "Advertising 10M-FD\n");
  9921. }
  9922. if (phy->speed_cap_mask &
  9923. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF) {
  9924. an_10_100_val |= (1<<7);
  9925. autoneg_val |= (1<<9 | 1<<12);
  9926. DP(NETIF_MSG_LINK, "Advertising 100M-HD\n");
  9927. }
  9928. if (phy->speed_cap_mask &
  9929. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL) {
  9930. an_10_100_val |= (1<<8);
  9931. autoneg_val |= (1<<9 | 1<<12);
  9932. DP(NETIF_MSG_LINK, "Advertising 100M-FD\n");
  9933. }
  9934. }
  9935. /* Only 10/100 are allowed to work in FORCE mode */
  9936. if (phy->req_line_speed == SPEED_100) {
  9937. autoneg_val |= (1<<13);
  9938. /* Enabled AUTO-MDIX when autoneg is disabled */
  9939. bnx2x_cl22_write(bp, phy,
  9940. 0x18,
  9941. (1<<15 | 1<<9 | 7<<0));
  9942. DP(NETIF_MSG_LINK, "Setting 100M force\n");
  9943. }
  9944. if (phy->req_line_speed == SPEED_10) {
  9945. /* Enabled AUTO-MDIX when autoneg is disabled */
  9946. bnx2x_cl22_write(bp, phy,
  9947. 0x18,
  9948. (1<<15 | 1<<9 | 7<<0));
  9949. DP(NETIF_MSG_LINK, "Setting 10M force\n");
  9950. }
  9951. if ((phy->flags & FLAGS_EEE) && bnx2x_eee_has_cap(params)) {
  9952. int rc;
  9953. bnx2x_cl22_write(bp, phy, MDIO_REG_GPHY_EXP_ACCESS,
  9954. MDIO_REG_GPHY_EXP_ACCESS_TOP |
  9955. MDIO_REG_GPHY_EXP_TOP_2K_BUF);
  9956. bnx2x_cl22_read(bp, phy, MDIO_REG_GPHY_EXP_ACCESS_GATE, &temp);
  9957. temp &= 0xfffe;
  9958. bnx2x_cl22_write(bp, phy, MDIO_REG_GPHY_EXP_ACCESS_GATE, temp);
  9959. rc = bnx2x_eee_initial_config(params, vars, SHMEM_EEE_1G_ADV);
  9960. if (rc) {
  9961. DP(NETIF_MSG_LINK, "Failed to configure EEE timers\n");
  9962. bnx2x_eee_disable(phy, params, vars);
  9963. } else if ((params->eee_mode & EEE_MODE_ADV_LPI) &&
  9964. (phy->req_duplex == DUPLEX_FULL) &&
  9965. (bnx2x_eee_calc_timer(params) ||
  9966. !(params->eee_mode & EEE_MODE_ENABLE_LPI))) {
  9967. /* Need to advertise EEE only when requested,
  9968. * and either no LPI assertion was requested,
  9969. * or it was requested and a valid timer was set.
  9970. * Also notice full duplex is required for EEE.
  9971. */
  9972. bnx2x_eee_advertise(phy, params, vars,
  9973. SHMEM_EEE_1G_ADV);
  9974. } else {
  9975. DP(NETIF_MSG_LINK, "Don't Advertise 1GBase-T EEE\n");
  9976. bnx2x_eee_disable(phy, params, vars);
  9977. }
  9978. } else {
  9979. vars->eee_status &= ~SHMEM_EEE_1G_ADV <<
  9980. SHMEM_EEE_SUPPORTED_SHIFT;
  9981. if (phy->flags & FLAGS_EEE) {
  9982. /* Handle legacy auto-grEEEn */
  9983. if (params->feature_config_flags &
  9984. FEATURE_CONFIG_AUTOGREEEN_ENABLED) {
  9985. temp = 6;
  9986. DP(NETIF_MSG_LINK, "Enabling Auto-GrEEEn\n");
  9987. } else {
  9988. temp = 0;
  9989. DP(NETIF_MSG_LINK, "Don't Adv. EEE\n");
  9990. }
  9991. bnx2x_cl45_write(bp, phy, MDIO_AN_DEVAD,
  9992. MDIO_AN_REG_EEE_ADV, temp);
  9993. }
  9994. }
  9995. bnx2x_cl22_write(bp, phy,
  9996. 0x04,
  9997. an_10_100_val | fc_val);
  9998. if (phy->req_duplex == DUPLEX_FULL)
  9999. autoneg_val |= (1<<8);
  10000. bnx2x_cl22_write(bp, phy,
  10001. MDIO_PMA_REG_CTRL, autoneg_val);
  10002. return 0;
  10003. }
  10004. static void bnx2x_5461x_set_link_led(struct bnx2x_phy *phy,
  10005. struct link_params *params, u8 mode)
  10006. {
  10007. struct bnx2x *bp = params->bp;
  10008. u16 temp;
  10009. bnx2x_cl22_write(bp, phy,
  10010. MDIO_REG_GPHY_SHADOW,
  10011. MDIO_REG_GPHY_SHADOW_LED_SEL1);
  10012. bnx2x_cl22_read(bp, phy,
  10013. MDIO_REG_GPHY_SHADOW,
  10014. &temp);
  10015. temp &= 0xff00;
  10016. DP(NETIF_MSG_LINK, "54618x set link led (mode=%x)\n", mode);
  10017. switch (mode) {
  10018. case LED_MODE_FRONT_PANEL_OFF:
  10019. case LED_MODE_OFF:
  10020. temp |= 0x00ee;
  10021. break;
  10022. case LED_MODE_OPER:
  10023. temp |= 0x0001;
  10024. break;
  10025. case LED_MODE_ON:
  10026. temp |= 0x00ff;
  10027. break;
  10028. default:
  10029. break;
  10030. }
  10031. bnx2x_cl22_write(bp, phy,
  10032. MDIO_REG_GPHY_SHADOW,
  10033. MDIO_REG_GPHY_SHADOW_WR_ENA | temp);
  10034. return;
  10035. }
  10036. static void bnx2x_54618se_link_reset(struct bnx2x_phy *phy,
  10037. struct link_params *params)
  10038. {
  10039. struct bnx2x *bp = params->bp;
  10040. u32 cfg_pin;
  10041. u8 port;
  10042. /* In case of no EPIO routed to reset the GPHY, put it
  10043. * in low power mode.
  10044. */
  10045. bnx2x_cl22_write(bp, phy, MDIO_PMA_REG_CTRL, 0x800);
  10046. /* This works with E3 only, no need to check the chip
  10047. * before determining the port.
  10048. */
  10049. port = params->port;
  10050. cfg_pin = (REG_RD(bp, params->shmem_base +
  10051. offsetof(struct shmem_region,
  10052. dev_info.port_hw_config[port].e3_cmn_pin_cfg)) &
  10053. PORT_HW_CFG_E3_PHY_RESET_MASK) >>
  10054. PORT_HW_CFG_E3_PHY_RESET_SHIFT;
  10055. /* Drive pin low to put GPHY in reset. */
  10056. bnx2x_set_cfg_pin(bp, cfg_pin, 0);
  10057. }
  10058. static u8 bnx2x_54618se_read_status(struct bnx2x_phy *phy,
  10059. struct link_params *params,
  10060. struct link_vars *vars)
  10061. {
  10062. struct bnx2x *bp = params->bp;
  10063. u16 val;
  10064. u8 link_up = 0;
  10065. u16 legacy_status, legacy_speed;
  10066. /* Get speed operation status */
  10067. bnx2x_cl22_read(bp, phy,
  10068. MDIO_REG_GPHY_AUX_STATUS,
  10069. &legacy_status);
  10070. DP(NETIF_MSG_LINK, "54618SE read_status: 0x%x\n", legacy_status);
  10071. /* Read status to clear the PHY interrupt. */
  10072. bnx2x_cl22_read(bp, phy,
  10073. MDIO_REG_INTR_STATUS,
  10074. &val);
  10075. link_up = ((legacy_status & (1<<2)) == (1<<2));
  10076. if (link_up) {
  10077. legacy_speed = (legacy_status & (7<<8));
  10078. if (legacy_speed == (7<<8)) {
  10079. vars->line_speed = SPEED_1000;
  10080. vars->duplex = DUPLEX_FULL;
  10081. } else if (legacy_speed == (6<<8)) {
  10082. vars->line_speed = SPEED_1000;
  10083. vars->duplex = DUPLEX_HALF;
  10084. } else if (legacy_speed == (5<<8)) {
  10085. vars->line_speed = SPEED_100;
  10086. vars->duplex = DUPLEX_FULL;
  10087. }
  10088. /* Omitting 100Base-T4 for now */
  10089. else if (legacy_speed == (3<<8)) {
  10090. vars->line_speed = SPEED_100;
  10091. vars->duplex = DUPLEX_HALF;
  10092. } else if (legacy_speed == (2<<8)) {
  10093. vars->line_speed = SPEED_10;
  10094. vars->duplex = DUPLEX_FULL;
  10095. } else if (legacy_speed == (1<<8)) {
  10096. vars->line_speed = SPEED_10;
  10097. vars->duplex = DUPLEX_HALF;
  10098. } else /* Should not happen */
  10099. vars->line_speed = 0;
  10100. DP(NETIF_MSG_LINK,
  10101. "Link is up in %dMbps, is_duplex_full= %d\n",
  10102. vars->line_speed,
  10103. (vars->duplex == DUPLEX_FULL));
  10104. /* Check legacy speed AN resolution */
  10105. bnx2x_cl22_read(bp, phy,
  10106. 0x01,
  10107. &val);
  10108. if (val & (1<<5))
  10109. vars->link_status |=
  10110. LINK_STATUS_AUTO_NEGOTIATE_COMPLETE;
  10111. bnx2x_cl22_read(bp, phy,
  10112. 0x06,
  10113. &val);
  10114. if ((val & (1<<0)) == 0)
  10115. vars->link_status |=
  10116. LINK_STATUS_PARALLEL_DETECTION_USED;
  10117. DP(NETIF_MSG_LINK, "BCM54618SE: link speed is %d\n",
  10118. vars->line_speed);
  10119. bnx2x_ext_phy_resolve_fc(phy, params, vars);
  10120. if (vars->link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) {
  10121. /* Report LP advertised speeds */
  10122. bnx2x_cl22_read(bp, phy, 0x5, &val);
  10123. if (val & (1<<5))
  10124. vars->link_status |=
  10125. LINK_STATUS_LINK_PARTNER_10THD_CAPABLE;
  10126. if (val & (1<<6))
  10127. vars->link_status |=
  10128. LINK_STATUS_LINK_PARTNER_10TFD_CAPABLE;
  10129. if (val & (1<<7))
  10130. vars->link_status |=
  10131. LINK_STATUS_LINK_PARTNER_100TXHD_CAPABLE;
  10132. if (val & (1<<8))
  10133. vars->link_status |=
  10134. LINK_STATUS_LINK_PARTNER_100TXFD_CAPABLE;
  10135. if (val & (1<<9))
  10136. vars->link_status |=
  10137. LINK_STATUS_LINK_PARTNER_100T4_CAPABLE;
  10138. bnx2x_cl22_read(bp, phy, 0xa, &val);
  10139. if (val & (1<<10))
  10140. vars->link_status |=
  10141. LINK_STATUS_LINK_PARTNER_1000THD_CAPABLE;
  10142. if (val & (1<<11))
  10143. vars->link_status |=
  10144. LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE;
  10145. if ((phy->flags & FLAGS_EEE) &&
  10146. bnx2x_eee_has_cap(params))
  10147. bnx2x_eee_an_resolve(phy, params, vars);
  10148. }
  10149. }
  10150. return link_up;
  10151. }
  10152. static void bnx2x_54618se_config_loopback(struct bnx2x_phy *phy,
  10153. struct link_params *params)
  10154. {
  10155. struct bnx2x *bp = params->bp;
  10156. u16 val;
  10157. u32 umac_base = params->port ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  10158. DP(NETIF_MSG_LINK, "2PMA/PMD ext_phy_loopback: 54618se\n");
  10159. /* Enable master/slave manual mmode and set to master */
  10160. /* mii write 9 [bits set 11 12] */
  10161. bnx2x_cl22_write(bp, phy, 0x09, 3<<11);
  10162. /* forced 1G and disable autoneg */
  10163. /* set val [mii read 0] */
  10164. /* set val [expr $val & [bits clear 6 12 13]] */
  10165. /* set val [expr $val | [bits set 6 8]] */
  10166. /* mii write 0 $val */
  10167. bnx2x_cl22_read(bp, phy, 0x00, &val);
  10168. val &= ~((1<<6) | (1<<12) | (1<<13));
  10169. val |= (1<<6) | (1<<8);
  10170. bnx2x_cl22_write(bp, phy, 0x00, val);
  10171. /* Set external loopback and Tx using 6dB coding */
  10172. /* mii write 0x18 7 */
  10173. /* set val [mii read 0x18] */
  10174. /* mii write 0x18 [expr $val | [bits set 10 15]] */
  10175. bnx2x_cl22_write(bp, phy, 0x18, 7);
  10176. bnx2x_cl22_read(bp, phy, 0x18, &val);
  10177. bnx2x_cl22_write(bp, phy, 0x18, val | (1<<10) | (1<<15));
  10178. /* This register opens the gate for the UMAC despite its name */
  10179. REG_WR(bp, NIG_REG_EGRESS_EMAC0_PORT + params->port*4, 1);
  10180. /* Maximum Frame Length (RW). Defines a 14-Bit maximum frame
  10181. * length used by the MAC receive logic to check frames.
  10182. */
  10183. REG_WR(bp, umac_base + UMAC_REG_MAXFR, 0x2710);
  10184. }
  10185. /******************************************************************/
  10186. /* SFX7101 PHY SECTION */
  10187. /******************************************************************/
  10188. static void bnx2x_7101_config_loopback(struct bnx2x_phy *phy,
  10189. struct link_params *params)
  10190. {
  10191. struct bnx2x *bp = params->bp;
  10192. /* SFX7101_XGXS_TEST1 */
  10193. bnx2x_cl45_write(bp, phy,
  10194. MDIO_XS_DEVAD, MDIO_XS_SFX7101_XGXS_TEST1, 0x100);
  10195. }
  10196. static int bnx2x_7101_config_init(struct bnx2x_phy *phy,
  10197. struct link_params *params,
  10198. struct link_vars *vars)
  10199. {
  10200. u16 fw_ver1, fw_ver2, val;
  10201. struct bnx2x *bp = params->bp;
  10202. DP(NETIF_MSG_LINK, "Setting the SFX7101 LASI indication\n");
  10203. /* Restore normal power mode*/
  10204. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
  10205. MISC_REGISTERS_GPIO_OUTPUT_HIGH, params->port);
  10206. /* HW reset */
  10207. bnx2x_ext_phy_hw_reset(bp, params->port);
  10208. bnx2x_wait_reset_complete(bp, phy, params);
  10209. bnx2x_cl45_write(bp, phy,
  10210. MDIO_PMA_DEVAD, MDIO_PMA_LASI_CTRL, 0x1);
  10211. DP(NETIF_MSG_LINK, "Setting the SFX7101 LED to blink on traffic\n");
  10212. bnx2x_cl45_write(bp, phy,
  10213. MDIO_PMA_DEVAD, MDIO_PMA_REG_7107_LED_CNTL, (1<<3));
  10214. bnx2x_ext_phy_set_pause(params, phy, vars);
  10215. /* Restart autoneg */
  10216. bnx2x_cl45_read(bp, phy,
  10217. MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, &val);
  10218. val |= 0x200;
  10219. bnx2x_cl45_write(bp, phy,
  10220. MDIO_AN_DEVAD, MDIO_AN_REG_CTRL, val);
  10221. /* Save spirom version */
  10222. bnx2x_cl45_read(bp, phy,
  10223. MDIO_PMA_DEVAD, MDIO_PMA_REG_7101_VER1, &fw_ver1);
  10224. bnx2x_cl45_read(bp, phy,
  10225. MDIO_PMA_DEVAD, MDIO_PMA_REG_7101_VER2, &fw_ver2);
  10226. bnx2x_save_spirom_version(bp, params->port,
  10227. (u32)(fw_ver1<<16 | fw_ver2), phy->ver_addr);
  10228. return 0;
  10229. }
  10230. static u8 bnx2x_7101_read_status(struct bnx2x_phy *phy,
  10231. struct link_params *params,
  10232. struct link_vars *vars)
  10233. {
  10234. struct bnx2x *bp = params->bp;
  10235. u8 link_up;
  10236. u16 val1, val2;
  10237. bnx2x_cl45_read(bp, phy,
  10238. MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val2);
  10239. bnx2x_cl45_read(bp, phy,
  10240. MDIO_PMA_DEVAD, MDIO_PMA_LASI_STAT, &val1);
  10241. DP(NETIF_MSG_LINK, "10G-base-T LASI status 0x%x->0x%x\n",
  10242. val2, val1);
  10243. bnx2x_cl45_read(bp, phy,
  10244. MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val2);
  10245. bnx2x_cl45_read(bp, phy,
  10246. MDIO_PMA_DEVAD, MDIO_PMA_REG_STATUS, &val1);
  10247. DP(NETIF_MSG_LINK, "10G-base-T PMA status 0x%x->0x%x\n",
  10248. val2, val1);
  10249. link_up = ((val1 & 4) == 4);
  10250. /* If link is up print the AN outcome of the SFX7101 PHY */
  10251. if (link_up) {
  10252. bnx2x_cl45_read(bp, phy,
  10253. MDIO_AN_DEVAD, MDIO_AN_REG_MASTER_STATUS,
  10254. &val2);
  10255. vars->line_speed = SPEED_10000;
  10256. vars->duplex = DUPLEX_FULL;
  10257. DP(NETIF_MSG_LINK, "SFX7101 AN status 0x%x->Master=%x\n",
  10258. val2, (val2 & (1<<14)));
  10259. bnx2x_ext_phy_10G_an_resolve(bp, phy, vars);
  10260. bnx2x_ext_phy_resolve_fc(phy, params, vars);
  10261. /* Read LP advertised speeds */
  10262. if (val2 & (1<<11))
  10263. vars->link_status |=
  10264. LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE;
  10265. }
  10266. return link_up;
  10267. }
  10268. static int bnx2x_7101_format_ver(u32 spirom_ver, u8 *str, u16 *len)
  10269. {
  10270. if (*len < 5)
  10271. return -EINVAL;
  10272. str[0] = (spirom_ver & 0xFF);
  10273. str[1] = (spirom_ver & 0xFF00) >> 8;
  10274. str[2] = (spirom_ver & 0xFF0000) >> 16;
  10275. str[3] = (spirom_ver & 0xFF000000) >> 24;
  10276. str[4] = '\0';
  10277. *len -= 5;
  10278. return 0;
  10279. }
  10280. void bnx2x_sfx7101_sp_sw_reset(struct bnx2x *bp, struct bnx2x_phy *phy)
  10281. {
  10282. u16 val, cnt;
  10283. bnx2x_cl45_read(bp, phy,
  10284. MDIO_PMA_DEVAD,
  10285. MDIO_PMA_REG_7101_RESET, &val);
  10286. for (cnt = 0; cnt < 10; cnt++) {
  10287. msleep(50);
  10288. /* Writes a self-clearing reset */
  10289. bnx2x_cl45_write(bp, phy,
  10290. MDIO_PMA_DEVAD,
  10291. MDIO_PMA_REG_7101_RESET,
  10292. (val | (1<<15)));
  10293. /* Wait for clear */
  10294. bnx2x_cl45_read(bp, phy,
  10295. MDIO_PMA_DEVAD,
  10296. MDIO_PMA_REG_7101_RESET, &val);
  10297. if ((val & (1<<15)) == 0)
  10298. break;
  10299. }
  10300. }
  10301. static void bnx2x_7101_hw_reset(struct bnx2x_phy *phy,
  10302. struct link_params *params) {
  10303. /* Low power mode is controlled by GPIO 2 */
  10304. bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_2,
  10305. MISC_REGISTERS_GPIO_OUTPUT_LOW, params->port);
  10306. /* The PHY reset is controlled by GPIO 1 */
  10307. bnx2x_set_gpio(params->bp, MISC_REGISTERS_GPIO_1,
  10308. MISC_REGISTERS_GPIO_OUTPUT_LOW, params->port);
  10309. }
  10310. static void bnx2x_7101_set_link_led(struct bnx2x_phy *phy,
  10311. struct link_params *params, u8 mode)
  10312. {
  10313. u16 val = 0;
  10314. struct bnx2x *bp = params->bp;
  10315. switch (mode) {
  10316. case LED_MODE_FRONT_PANEL_OFF:
  10317. case LED_MODE_OFF:
  10318. val = 2;
  10319. break;
  10320. case LED_MODE_ON:
  10321. val = 1;
  10322. break;
  10323. case LED_MODE_OPER:
  10324. val = 0;
  10325. break;
  10326. }
  10327. bnx2x_cl45_write(bp, phy,
  10328. MDIO_PMA_DEVAD,
  10329. MDIO_PMA_REG_7107_LINK_LED_CNTL,
  10330. val);
  10331. }
  10332. /******************************************************************/
  10333. /* STATIC PHY DECLARATION */
  10334. /******************************************************************/
  10335. static const struct bnx2x_phy phy_null = {
  10336. .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN,
  10337. .addr = 0,
  10338. .def_md_devad = 0,
  10339. .flags = FLAGS_INIT_XGXS_FIRST,
  10340. .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10341. .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10342. .mdio_ctrl = 0,
  10343. .supported = 0,
  10344. .media_type = ETH_PHY_NOT_PRESENT,
  10345. .ver_addr = 0,
  10346. .req_flow_ctrl = 0,
  10347. .req_line_speed = 0,
  10348. .speed_cap_mask = 0,
  10349. .req_duplex = 0,
  10350. .rsrv = 0,
  10351. .config_init = (config_init_t)NULL,
  10352. .read_status = (read_status_t)NULL,
  10353. .link_reset = (link_reset_t)NULL,
  10354. .config_loopback = (config_loopback_t)NULL,
  10355. .format_fw_ver = (format_fw_ver_t)NULL,
  10356. .hw_reset = (hw_reset_t)NULL,
  10357. .set_link_led = (set_link_led_t)NULL,
  10358. .phy_specific_func = (phy_specific_func_t)NULL
  10359. };
  10360. static const struct bnx2x_phy phy_serdes = {
  10361. .type = PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT,
  10362. .addr = 0xff,
  10363. .def_md_devad = 0,
  10364. .flags = 0,
  10365. .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10366. .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10367. .mdio_ctrl = 0,
  10368. .supported = (SUPPORTED_10baseT_Half |
  10369. SUPPORTED_10baseT_Full |
  10370. SUPPORTED_100baseT_Half |
  10371. SUPPORTED_100baseT_Full |
  10372. SUPPORTED_1000baseT_Full |
  10373. SUPPORTED_2500baseX_Full |
  10374. SUPPORTED_TP |
  10375. SUPPORTED_Autoneg |
  10376. SUPPORTED_Pause |
  10377. SUPPORTED_Asym_Pause),
  10378. .media_type = ETH_PHY_BASE_T,
  10379. .ver_addr = 0,
  10380. .req_flow_ctrl = 0,
  10381. .req_line_speed = 0,
  10382. .speed_cap_mask = 0,
  10383. .req_duplex = 0,
  10384. .rsrv = 0,
  10385. .config_init = (config_init_t)bnx2x_xgxs_config_init,
  10386. .read_status = (read_status_t)bnx2x_link_settings_status,
  10387. .link_reset = (link_reset_t)bnx2x_int_link_reset,
  10388. .config_loopback = (config_loopback_t)NULL,
  10389. .format_fw_ver = (format_fw_ver_t)NULL,
  10390. .hw_reset = (hw_reset_t)NULL,
  10391. .set_link_led = (set_link_led_t)NULL,
  10392. .phy_specific_func = (phy_specific_func_t)NULL
  10393. };
  10394. static const struct bnx2x_phy phy_xgxs = {
  10395. .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT,
  10396. .addr = 0xff,
  10397. .def_md_devad = 0,
  10398. .flags = 0,
  10399. .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10400. .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10401. .mdio_ctrl = 0,
  10402. .supported = (SUPPORTED_10baseT_Half |
  10403. SUPPORTED_10baseT_Full |
  10404. SUPPORTED_100baseT_Half |
  10405. SUPPORTED_100baseT_Full |
  10406. SUPPORTED_1000baseT_Full |
  10407. SUPPORTED_2500baseX_Full |
  10408. SUPPORTED_10000baseT_Full |
  10409. SUPPORTED_FIBRE |
  10410. SUPPORTED_Autoneg |
  10411. SUPPORTED_Pause |
  10412. SUPPORTED_Asym_Pause),
  10413. .media_type = ETH_PHY_CX4,
  10414. .ver_addr = 0,
  10415. .req_flow_ctrl = 0,
  10416. .req_line_speed = 0,
  10417. .speed_cap_mask = 0,
  10418. .req_duplex = 0,
  10419. .rsrv = 0,
  10420. .config_init = (config_init_t)bnx2x_xgxs_config_init,
  10421. .read_status = (read_status_t)bnx2x_link_settings_status,
  10422. .link_reset = (link_reset_t)bnx2x_int_link_reset,
  10423. .config_loopback = (config_loopback_t)bnx2x_set_xgxs_loopback,
  10424. .format_fw_ver = (format_fw_ver_t)NULL,
  10425. .hw_reset = (hw_reset_t)NULL,
  10426. .set_link_led = (set_link_led_t)NULL,
  10427. .phy_specific_func = (phy_specific_func_t)bnx2x_xgxs_specific_func
  10428. };
  10429. static const struct bnx2x_phy phy_warpcore = {
  10430. .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT,
  10431. .addr = 0xff,
  10432. .def_md_devad = 0,
  10433. .flags = FLAGS_TX_ERROR_CHECK,
  10434. .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10435. .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10436. .mdio_ctrl = 0,
  10437. .supported = (SUPPORTED_10baseT_Half |
  10438. SUPPORTED_10baseT_Full |
  10439. SUPPORTED_100baseT_Half |
  10440. SUPPORTED_100baseT_Full |
  10441. SUPPORTED_1000baseT_Full |
  10442. SUPPORTED_1000baseKX_Full |
  10443. SUPPORTED_10000baseT_Full |
  10444. SUPPORTED_10000baseKR_Full |
  10445. SUPPORTED_20000baseKR2_Full |
  10446. SUPPORTED_20000baseMLD2_Full |
  10447. SUPPORTED_FIBRE |
  10448. SUPPORTED_Autoneg |
  10449. SUPPORTED_Pause |
  10450. SUPPORTED_Asym_Pause),
  10451. .media_type = ETH_PHY_UNSPECIFIED,
  10452. .ver_addr = 0,
  10453. .req_flow_ctrl = 0,
  10454. .req_line_speed = 0,
  10455. .speed_cap_mask = 0,
  10456. /* req_duplex = */0,
  10457. /* rsrv = */0,
  10458. .config_init = (config_init_t)bnx2x_warpcore_config_init,
  10459. .read_status = (read_status_t)bnx2x_warpcore_read_status,
  10460. .link_reset = (link_reset_t)bnx2x_warpcore_link_reset,
  10461. .config_loopback = (config_loopback_t)bnx2x_set_warpcore_loopback,
  10462. .format_fw_ver = (format_fw_ver_t)NULL,
  10463. .hw_reset = (hw_reset_t)bnx2x_warpcore_hw_reset,
  10464. .set_link_led = (set_link_led_t)NULL,
  10465. .phy_specific_func = (phy_specific_func_t)NULL
  10466. };
  10467. static const struct bnx2x_phy phy_7101 = {
  10468. .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101,
  10469. .addr = 0xff,
  10470. .def_md_devad = 0,
  10471. .flags = FLAGS_FAN_FAILURE_DET_REQ,
  10472. .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10473. .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10474. .mdio_ctrl = 0,
  10475. .supported = (SUPPORTED_10000baseT_Full |
  10476. SUPPORTED_TP |
  10477. SUPPORTED_Autoneg |
  10478. SUPPORTED_Pause |
  10479. SUPPORTED_Asym_Pause),
  10480. .media_type = ETH_PHY_BASE_T,
  10481. .ver_addr = 0,
  10482. .req_flow_ctrl = 0,
  10483. .req_line_speed = 0,
  10484. .speed_cap_mask = 0,
  10485. .req_duplex = 0,
  10486. .rsrv = 0,
  10487. .config_init = (config_init_t)bnx2x_7101_config_init,
  10488. .read_status = (read_status_t)bnx2x_7101_read_status,
  10489. .link_reset = (link_reset_t)bnx2x_common_ext_link_reset,
  10490. .config_loopback = (config_loopback_t)bnx2x_7101_config_loopback,
  10491. .format_fw_ver = (format_fw_ver_t)bnx2x_7101_format_ver,
  10492. .hw_reset = (hw_reset_t)bnx2x_7101_hw_reset,
  10493. .set_link_led = (set_link_led_t)bnx2x_7101_set_link_led,
  10494. .phy_specific_func = (phy_specific_func_t)NULL
  10495. };
  10496. static const struct bnx2x_phy phy_8073 = {
  10497. .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073,
  10498. .addr = 0xff,
  10499. .def_md_devad = 0,
  10500. .flags = 0,
  10501. .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10502. .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10503. .mdio_ctrl = 0,
  10504. .supported = (SUPPORTED_10000baseT_Full |
  10505. SUPPORTED_2500baseX_Full |
  10506. SUPPORTED_1000baseT_Full |
  10507. SUPPORTED_FIBRE |
  10508. SUPPORTED_Autoneg |
  10509. SUPPORTED_Pause |
  10510. SUPPORTED_Asym_Pause),
  10511. .media_type = ETH_PHY_KR,
  10512. .ver_addr = 0,
  10513. .req_flow_ctrl = 0,
  10514. .req_line_speed = 0,
  10515. .speed_cap_mask = 0,
  10516. .req_duplex = 0,
  10517. .rsrv = 0,
  10518. .config_init = (config_init_t)bnx2x_8073_config_init,
  10519. .read_status = (read_status_t)bnx2x_8073_read_status,
  10520. .link_reset = (link_reset_t)bnx2x_8073_link_reset,
  10521. .config_loopback = (config_loopback_t)NULL,
  10522. .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
  10523. .hw_reset = (hw_reset_t)NULL,
  10524. .set_link_led = (set_link_led_t)NULL,
  10525. .phy_specific_func = (phy_specific_func_t)bnx2x_8073_specific_func
  10526. };
  10527. static const struct bnx2x_phy phy_8705 = {
  10528. .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705,
  10529. .addr = 0xff,
  10530. .def_md_devad = 0,
  10531. .flags = FLAGS_INIT_XGXS_FIRST,
  10532. .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10533. .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10534. .mdio_ctrl = 0,
  10535. .supported = (SUPPORTED_10000baseT_Full |
  10536. SUPPORTED_FIBRE |
  10537. SUPPORTED_Pause |
  10538. SUPPORTED_Asym_Pause),
  10539. .media_type = ETH_PHY_XFP_FIBER,
  10540. .ver_addr = 0,
  10541. .req_flow_ctrl = 0,
  10542. .req_line_speed = 0,
  10543. .speed_cap_mask = 0,
  10544. .req_duplex = 0,
  10545. .rsrv = 0,
  10546. .config_init = (config_init_t)bnx2x_8705_config_init,
  10547. .read_status = (read_status_t)bnx2x_8705_read_status,
  10548. .link_reset = (link_reset_t)bnx2x_common_ext_link_reset,
  10549. .config_loopback = (config_loopback_t)NULL,
  10550. .format_fw_ver = (format_fw_ver_t)bnx2x_null_format_ver,
  10551. .hw_reset = (hw_reset_t)NULL,
  10552. .set_link_led = (set_link_led_t)NULL,
  10553. .phy_specific_func = (phy_specific_func_t)NULL
  10554. };
  10555. static const struct bnx2x_phy phy_8706 = {
  10556. .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706,
  10557. .addr = 0xff,
  10558. .def_md_devad = 0,
  10559. .flags = FLAGS_INIT_XGXS_FIRST,
  10560. .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10561. .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10562. .mdio_ctrl = 0,
  10563. .supported = (SUPPORTED_10000baseT_Full |
  10564. SUPPORTED_1000baseT_Full |
  10565. SUPPORTED_FIBRE |
  10566. SUPPORTED_Pause |
  10567. SUPPORTED_Asym_Pause),
  10568. .media_type = ETH_PHY_SFPP_10G_FIBER,
  10569. .ver_addr = 0,
  10570. .req_flow_ctrl = 0,
  10571. .req_line_speed = 0,
  10572. .speed_cap_mask = 0,
  10573. .req_duplex = 0,
  10574. .rsrv = 0,
  10575. .config_init = (config_init_t)bnx2x_8706_config_init,
  10576. .read_status = (read_status_t)bnx2x_8706_read_status,
  10577. .link_reset = (link_reset_t)bnx2x_common_ext_link_reset,
  10578. .config_loopback = (config_loopback_t)NULL,
  10579. .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
  10580. .hw_reset = (hw_reset_t)NULL,
  10581. .set_link_led = (set_link_led_t)NULL,
  10582. .phy_specific_func = (phy_specific_func_t)NULL
  10583. };
  10584. static const struct bnx2x_phy phy_8726 = {
  10585. .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726,
  10586. .addr = 0xff,
  10587. .def_md_devad = 0,
  10588. .flags = (FLAGS_INIT_XGXS_FIRST |
  10589. FLAGS_TX_ERROR_CHECK),
  10590. .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10591. .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10592. .mdio_ctrl = 0,
  10593. .supported = (SUPPORTED_10000baseT_Full |
  10594. SUPPORTED_1000baseT_Full |
  10595. SUPPORTED_Autoneg |
  10596. SUPPORTED_FIBRE |
  10597. SUPPORTED_Pause |
  10598. SUPPORTED_Asym_Pause),
  10599. .media_type = ETH_PHY_NOT_PRESENT,
  10600. .ver_addr = 0,
  10601. .req_flow_ctrl = 0,
  10602. .req_line_speed = 0,
  10603. .speed_cap_mask = 0,
  10604. .req_duplex = 0,
  10605. .rsrv = 0,
  10606. .config_init = (config_init_t)bnx2x_8726_config_init,
  10607. .read_status = (read_status_t)bnx2x_8726_read_status,
  10608. .link_reset = (link_reset_t)bnx2x_8726_link_reset,
  10609. .config_loopback = (config_loopback_t)bnx2x_8726_config_loopback,
  10610. .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
  10611. .hw_reset = (hw_reset_t)NULL,
  10612. .set_link_led = (set_link_led_t)NULL,
  10613. .phy_specific_func = (phy_specific_func_t)NULL
  10614. };
  10615. static const struct bnx2x_phy phy_8727 = {
  10616. .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727,
  10617. .addr = 0xff,
  10618. .def_md_devad = 0,
  10619. .flags = (FLAGS_FAN_FAILURE_DET_REQ |
  10620. FLAGS_TX_ERROR_CHECK),
  10621. .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10622. .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10623. .mdio_ctrl = 0,
  10624. .supported = (SUPPORTED_10000baseT_Full |
  10625. SUPPORTED_1000baseT_Full |
  10626. SUPPORTED_FIBRE |
  10627. SUPPORTED_Pause |
  10628. SUPPORTED_Asym_Pause),
  10629. .media_type = ETH_PHY_NOT_PRESENT,
  10630. .ver_addr = 0,
  10631. .req_flow_ctrl = 0,
  10632. .req_line_speed = 0,
  10633. .speed_cap_mask = 0,
  10634. .req_duplex = 0,
  10635. .rsrv = 0,
  10636. .config_init = (config_init_t)bnx2x_8727_config_init,
  10637. .read_status = (read_status_t)bnx2x_8727_read_status,
  10638. .link_reset = (link_reset_t)bnx2x_8727_link_reset,
  10639. .config_loopback = (config_loopback_t)NULL,
  10640. .format_fw_ver = (format_fw_ver_t)bnx2x_format_ver,
  10641. .hw_reset = (hw_reset_t)bnx2x_8727_hw_reset,
  10642. .set_link_led = (set_link_led_t)bnx2x_8727_set_link_led,
  10643. .phy_specific_func = (phy_specific_func_t)bnx2x_8727_specific_func
  10644. };
  10645. static const struct bnx2x_phy phy_8481 = {
  10646. .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481,
  10647. .addr = 0xff,
  10648. .def_md_devad = 0,
  10649. .flags = FLAGS_FAN_FAILURE_DET_REQ |
  10650. FLAGS_REARM_LATCH_SIGNAL,
  10651. .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10652. .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10653. .mdio_ctrl = 0,
  10654. .supported = (SUPPORTED_10baseT_Half |
  10655. SUPPORTED_10baseT_Full |
  10656. SUPPORTED_100baseT_Half |
  10657. SUPPORTED_100baseT_Full |
  10658. SUPPORTED_1000baseT_Full |
  10659. SUPPORTED_10000baseT_Full |
  10660. SUPPORTED_TP |
  10661. SUPPORTED_Autoneg |
  10662. SUPPORTED_Pause |
  10663. SUPPORTED_Asym_Pause),
  10664. .media_type = ETH_PHY_BASE_T,
  10665. .ver_addr = 0,
  10666. .req_flow_ctrl = 0,
  10667. .req_line_speed = 0,
  10668. .speed_cap_mask = 0,
  10669. .req_duplex = 0,
  10670. .rsrv = 0,
  10671. .config_init = (config_init_t)bnx2x_8481_config_init,
  10672. .read_status = (read_status_t)bnx2x_848xx_read_status,
  10673. .link_reset = (link_reset_t)bnx2x_8481_link_reset,
  10674. .config_loopback = (config_loopback_t)NULL,
  10675. .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
  10676. .hw_reset = (hw_reset_t)bnx2x_8481_hw_reset,
  10677. .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
  10678. .phy_specific_func = (phy_specific_func_t)NULL
  10679. };
  10680. static const struct bnx2x_phy phy_84823 = {
  10681. .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823,
  10682. .addr = 0xff,
  10683. .def_md_devad = 0,
  10684. .flags = (FLAGS_FAN_FAILURE_DET_REQ |
  10685. FLAGS_REARM_LATCH_SIGNAL |
  10686. FLAGS_TX_ERROR_CHECK),
  10687. .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10688. .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10689. .mdio_ctrl = 0,
  10690. .supported = (SUPPORTED_10baseT_Half |
  10691. SUPPORTED_10baseT_Full |
  10692. SUPPORTED_100baseT_Half |
  10693. SUPPORTED_100baseT_Full |
  10694. SUPPORTED_1000baseT_Full |
  10695. SUPPORTED_10000baseT_Full |
  10696. SUPPORTED_TP |
  10697. SUPPORTED_Autoneg |
  10698. SUPPORTED_Pause |
  10699. SUPPORTED_Asym_Pause),
  10700. .media_type = ETH_PHY_BASE_T,
  10701. .ver_addr = 0,
  10702. .req_flow_ctrl = 0,
  10703. .req_line_speed = 0,
  10704. .speed_cap_mask = 0,
  10705. .req_duplex = 0,
  10706. .rsrv = 0,
  10707. .config_init = (config_init_t)bnx2x_848x3_config_init,
  10708. .read_status = (read_status_t)bnx2x_848xx_read_status,
  10709. .link_reset = (link_reset_t)bnx2x_848x3_link_reset,
  10710. .config_loopback = (config_loopback_t)NULL,
  10711. .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
  10712. .hw_reset = (hw_reset_t)NULL,
  10713. .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
  10714. .phy_specific_func = (phy_specific_func_t)bnx2x_848xx_specific_func
  10715. };
  10716. static const struct bnx2x_phy phy_84833 = {
  10717. .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833,
  10718. .addr = 0xff,
  10719. .def_md_devad = 0,
  10720. .flags = (FLAGS_FAN_FAILURE_DET_REQ |
  10721. FLAGS_REARM_LATCH_SIGNAL |
  10722. FLAGS_TX_ERROR_CHECK),
  10723. .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10724. .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10725. .mdio_ctrl = 0,
  10726. .supported = (SUPPORTED_100baseT_Half |
  10727. SUPPORTED_100baseT_Full |
  10728. SUPPORTED_1000baseT_Full |
  10729. SUPPORTED_10000baseT_Full |
  10730. SUPPORTED_TP |
  10731. SUPPORTED_Autoneg |
  10732. SUPPORTED_Pause |
  10733. SUPPORTED_Asym_Pause),
  10734. .media_type = ETH_PHY_BASE_T,
  10735. .ver_addr = 0,
  10736. .req_flow_ctrl = 0,
  10737. .req_line_speed = 0,
  10738. .speed_cap_mask = 0,
  10739. .req_duplex = 0,
  10740. .rsrv = 0,
  10741. .config_init = (config_init_t)bnx2x_848x3_config_init,
  10742. .read_status = (read_status_t)bnx2x_848xx_read_status,
  10743. .link_reset = (link_reset_t)bnx2x_848x3_link_reset,
  10744. .config_loopback = (config_loopback_t)NULL,
  10745. .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
  10746. .hw_reset = (hw_reset_t)bnx2x_84833_hw_reset_phy,
  10747. .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
  10748. .phy_specific_func = (phy_specific_func_t)bnx2x_848xx_specific_func
  10749. };
  10750. static const struct bnx2x_phy phy_84834 = {
  10751. .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84834,
  10752. .addr = 0xff,
  10753. .def_md_devad = 0,
  10754. .flags = FLAGS_FAN_FAILURE_DET_REQ |
  10755. FLAGS_REARM_LATCH_SIGNAL,
  10756. .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10757. .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10758. .mdio_ctrl = 0,
  10759. .supported = (SUPPORTED_100baseT_Half |
  10760. SUPPORTED_100baseT_Full |
  10761. SUPPORTED_1000baseT_Full |
  10762. SUPPORTED_10000baseT_Full |
  10763. SUPPORTED_TP |
  10764. SUPPORTED_Autoneg |
  10765. SUPPORTED_Pause |
  10766. SUPPORTED_Asym_Pause),
  10767. .media_type = ETH_PHY_BASE_T,
  10768. .ver_addr = 0,
  10769. .req_flow_ctrl = 0,
  10770. .req_line_speed = 0,
  10771. .speed_cap_mask = 0,
  10772. .req_duplex = 0,
  10773. .rsrv = 0,
  10774. .config_init = (config_init_t)bnx2x_848x3_config_init,
  10775. .read_status = (read_status_t)bnx2x_848xx_read_status,
  10776. .link_reset = (link_reset_t)bnx2x_848x3_link_reset,
  10777. .config_loopback = (config_loopback_t)NULL,
  10778. .format_fw_ver = (format_fw_ver_t)bnx2x_848xx_format_ver,
  10779. .hw_reset = (hw_reset_t)bnx2x_84833_hw_reset_phy,
  10780. .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
  10781. .phy_specific_func = (phy_specific_func_t)bnx2x_848xx_specific_func
  10782. };
  10783. static const struct bnx2x_phy phy_84858 = {
  10784. .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84858,
  10785. .addr = 0xff,
  10786. .def_md_devad = 0,
  10787. .flags = FLAGS_FAN_FAILURE_DET_REQ |
  10788. FLAGS_REARM_LATCH_SIGNAL,
  10789. .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10790. .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10791. .mdio_ctrl = 0,
  10792. .supported = (SUPPORTED_100baseT_Half |
  10793. SUPPORTED_100baseT_Full |
  10794. SUPPORTED_1000baseT_Full |
  10795. SUPPORTED_10000baseT_Full |
  10796. SUPPORTED_TP |
  10797. SUPPORTED_Autoneg |
  10798. SUPPORTED_Pause |
  10799. SUPPORTED_Asym_Pause),
  10800. .media_type = ETH_PHY_BASE_T,
  10801. .ver_addr = 0,
  10802. .req_flow_ctrl = 0,
  10803. .req_line_speed = 0,
  10804. .speed_cap_mask = 0,
  10805. .req_duplex = 0,
  10806. .rsrv = 0,
  10807. .config_init = (config_init_t)bnx2x_848x3_config_init,
  10808. .read_status = (read_status_t)bnx2x_848xx_read_status,
  10809. .link_reset = (link_reset_t)bnx2x_848x3_link_reset,
  10810. .config_loopback = (config_loopback_t)NULL,
  10811. .format_fw_ver = (format_fw_ver_t)bnx2x_8485x_format_ver,
  10812. .hw_reset = (hw_reset_t)bnx2x_84833_hw_reset_phy,
  10813. .set_link_led = (set_link_led_t)bnx2x_848xx_set_link_led,
  10814. .phy_specific_func = (phy_specific_func_t)bnx2x_848xx_specific_func
  10815. };
  10816. static const struct bnx2x_phy phy_54618se = {
  10817. .type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE,
  10818. .addr = 0xff,
  10819. .def_md_devad = 0,
  10820. .flags = FLAGS_INIT_XGXS_FIRST,
  10821. .rx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10822. .tx_preemphasis = {0xffff, 0xffff, 0xffff, 0xffff},
  10823. .mdio_ctrl = 0,
  10824. .supported = (SUPPORTED_10baseT_Half |
  10825. SUPPORTED_10baseT_Full |
  10826. SUPPORTED_100baseT_Half |
  10827. SUPPORTED_100baseT_Full |
  10828. SUPPORTED_1000baseT_Full |
  10829. SUPPORTED_TP |
  10830. SUPPORTED_Autoneg |
  10831. SUPPORTED_Pause |
  10832. SUPPORTED_Asym_Pause),
  10833. .media_type = ETH_PHY_BASE_T,
  10834. .ver_addr = 0,
  10835. .req_flow_ctrl = 0,
  10836. .req_line_speed = 0,
  10837. .speed_cap_mask = 0,
  10838. /* req_duplex = */0,
  10839. /* rsrv = */0,
  10840. .config_init = (config_init_t)bnx2x_54618se_config_init,
  10841. .read_status = (read_status_t)bnx2x_54618se_read_status,
  10842. .link_reset = (link_reset_t)bnx2x_54618se_link_reset,
  10843. .config_loopback = (config_loopback_t)bnx2x_54618se_config_loopback,
  10844. .format_fw_ver = (format_fw_ver_t)NULL,
  10845. .hw_reset = (hw_reset_t)NULL,
  10846. .set_link_led = (set_link_led_t)bnx2x_5461x_set_link_led,
  10847. .phy_specific_func = (phy_specific_func_t)bnx2x_54618se_specific_func
  10848. };
  10849. /*****************************************************************/
  10850. /* */
  10851. /* Populate the phy according. Main function: bnx2x_populate_phy */
  10852. /* */
  10853. /*****************************************************************/
  10854. static void bnx2x_populate_preemphasis(struct bnx2x *bp, u32 shmem_base,
  10855. struct bnx2x_phy *phy, u8 port,
  10856. u8 phy_index)
  10857. {
  10858. /* Get the 4 lanes xgxs config rx and tx */
  10859. u32 rx = 0, tx = 0, i;
  10860. for (i = 0; i < 2; i++) {
  10861. /* INT_PHY and EXT_PHY1 share the same value location in
  10862. * the shmem. When num_phys is greater than 1, than this value
  10863. * applies only to EXT_PHY1
  10864. */
  10865. if (phy_index == INT_PHY || phy_index == EXT_PHY1) {
  10866. rx = REG_RD(bp, shmem_base +
  10867. offsetof(struct shmem_region,
  10868. dev_info.port_hw_config[port].xgxs_config_rx[i<<1]));
  10869. tx = REG_RD(bp, shmem_base +
  10870. offsetof(struct shmem_region,
  10871. dev_info.port_hw_config[port].xgxs_config_tx[i<<1]));
  10872. } else {
  10873. rx = REG_RD(bp, shmem_base +
  10874. offsetof(struct shmem_region,
  10875. dev_info.port_hw_config[port].xgxs_config2_rx[i<<1]));
  10876. tx = REG_RD(bp, shmem_base +
  10877. offsetof(struct shmem_region,
  10878. dev_info.port_hw_config[port].xgxs_config2_rx[i<<1]));
  10879. }
  10880. phy->rx_preemphasis[i << 1] = ((rx>>16) & 0xffff);
  10881. phy->rx_preemphasis[(i << 1) + 1] = (rx & 0xffff);
  10882. phy->tx_preemphasis[i << 1] = ((tx>>16) & 0xffff);
  10883. phy->tx_preemphasis[(i << 1) + 1] = (tx & 0xffff);
  10884. }
  10885. }
  10886. static u32 bnx2x_get_ext_phy_config(struct bnx2x *bp, u32 shmem_base,
  10887. u8 phy_index, u8 port)
  10888. {
  10889. u32 ext_phy_config = 0;
  10890. switch (phy_index) {
  10891. case EXT_PHY1:
  10892. ext_phy_config = REG_RD(bp, shmem_base +
  10893. offsetof(struct shmem_region,
  10894. dev_info.port_hw_config[port].external_phy_config));
  10895. break;
  10896. case EXT_PHY2:
  10897. ext_phy_config = REG_RD(bp, shmem_base +
  10898. offsetof(struct shmem_region,
  10899. dev_info.port_hw_config[port].external_phy_config2));
  10900. break;
  10901. default:
  10902. DP(NETIF_MSG_LINK, "Invalid phy_index %d\n", phy_index);
  10903. return -EINVAL;
  10904. }
  10905. return ext_phy_config;
  10906. }
  10907. static int bnx2x_populate_int_phy(struct bnx2x *bp, u32 shmem_base, u8 port,
  10908. struct bnx2x_phy *phy)
  10909. {
  10910. u32 phy_addr;
  10911. u32 chip_id;
  10912. u32 switch_cfg = (REG_RD(bp, shmem_base +
  10913. offsetof(struct shmem_region,
  10914. dev_info.port_feature_config[port].link_config)) &
  10915. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  10916. chip_id = (REG_RD(bp, MISC_REG_CHIP_NUM) << 16) |
  10917. ((REG_RD(bp, MISC_REG_CHIP_REV) & 0xf) << 12);
  10918. DP(NETIF_MSG_LINK, ":chip_id = 0x%x\n", chip_id);
  10919. if (USES_WARPCORE(bp)) {
  10920. u32 serdes_net_if;
  10921. phy_addr = REG_RD(bp,
  10922. MISC_REG_WC0_CTRL_PHY_ADDR);
  10923. *phy = phy_warpcore;
  10924. if (REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR) == 0x3)
  10925. phy->flags |= FLAGS_4_PORT_MODE;
  10926. else
  10927. phy->flags &= ~FLAGS_4_PORT_MODE;
  10928. /* Check Dual mode */
  10929. serdes_net_if = (REG_RD(bp, shmem_base +
  10930. offsetof(struct shmem_region, dev_info.
  10931. port_hw_config[port].default_cfg)) &
  10932. PORT_HW_CFG_NET_SERDES_IF_MASK);
  10933. /* Set the appropriate supported and flags indications per
  10934. * interface type of the chip
  10935. */
  10936. switch (serdes_net_if) {
  10937. case PORT_HW_CFG_NET_SERDES_IF_SGMII:
  10938. phy->supported &= (SUPPORTED_10baseT_Half |
  10939. SUPPORTED_10baseT_Full |
  10940. SUPPORTED_100baseT_Half |
  10941. SUPPORTED_100baseT_Full |
  10942. SUPPORTED_1000baseT_Full |
  10943. SUPPORTED_FIBRE |
  10944. SUPPORTED_Autoneg |
  10945. SUPPORTED_Pause |
  10946. SUPPORTED_Asym_Pause);
  10947. phy->media_type = ETH_PHY_BASE_T;
  10948. break;
  10949. case PORT_HW_CFG_NET_SERDES_IF_XFI:
  10950. phy->supported &= (SUPPORTED_1000baseT_Full |
  10951. SUPPORTED_10000baseT_Full |
  10952. SUPPORTED_FIBRE |
  10953. SUPPORTED_Pause |
  10954. SUPPORTED_Asym_Pause);
  10955. phy->media_type = ETH_PHY_XFP_FIBER;
  10956. break;
  10957. case PORT_HW_CFG_NET_SERDES_IF_SFI:
  10958. phy->supported &= (SUPPORTED_1000baseT_Full |
  10959. SUPPORTED_10000baseT_Full |
  10960. SUPPORTED_FIBRE |
  10961. SUPPORTED_Pause |
  10962. SUPPORTED_Asym_Pause);
  10963. phy->media_type = ETH_PHY_SFPP_10G_FIBER;
  10964. break;
  10965. case PORT_HW_CFG_NET_SERDES_IF_KR:
  10966. phy->media_type = ETH_PHY_KR;
  10967. phy->supported &= (SUPPORTED_1000baseKX_Full |
  10968. SUPPORTED_10000baseKR_Full |
  10969. SUPPORTED_FIBRE |
  10970. SUPPORTED_Autoneg |
  10971. SUPPORTED_Pause |
  10972. SUPPORTED_Asym_Pause);
  10973. break;
  10974. case PORT_HW_CFG_NET_SERDES_IF_DXGXS:
  10975. phy->media_type = ETH_PHY_KR;
  10976. phy->flags |= FLAGS_WC_DUAL_MODE;
  10977. phy->supported &= (SUPPORTED_20000baseMLD2_Full |
  10978. SUPPORTED_FIBRE |
  10979. SUPPORTED_Pause |
  10980. SUPPORTED_Asym_Pause);
  10981. break;
  10982. case PORT_HW_CFG_NET_SERDES_IF_KR2:
  10983. phy->media_type = ETH_PHY_KR;
  10984. phy->flags |= FLAGS_WC_DUAL_MODE;
  10985. phy->supported &= (SUPPORTED_20000baseKR2_Full |
  10986. SUPPORTED_10000baseKR_Full |
  10987. SUPPORTED_1000baseKX_Full |
  10988. SUPPORTED_Autoneg |
  10989. SUPPORTED_FIBRE |
  10990. SUPPORTED_Pause |
  10991. SUPPORTED_Asym_Pause);
  10992. phy->flags &= ~FLAGS_TX_ERROR_CHECK;
  10993. break;
  10994. default:
  10995. DP(NETIF_MSG_LINK, "Unknown WC interface type 0x%x\n",
  10996. serdes_net_if);
  10997. break;
  10998. }
  10999. /* Enable MDC/MDIO work-around for E3 A0 since free running MDC
  11000. * was not set as expected. For B0, ECO will be enabled so there
  11001. * won't be an issue there
  11002. */
  11003. if (CHIP_REV(bp) == CHIP_REV_Ax)
  11004. phy->flags |= FLAGS_MDC_MDIO_WA;
  11005. else
  11006. phy->flags |= FLAGS_MDC_MDIO_WA_B0;
  11007. } else {
  11008. switch (switch_cfg) {
  11009. case SWITCH_CFG_1G:
  11010. phy_addr = REG_RD(bp,
  11011. NIG_REG_SERDES0_CTRL_PHY_ADDR +
  11012. port * 0x10);
  11013. *phy = phy_serdes;
  11014. break;
  11015. case SWITCH_CFG_10G:
  11016. phy_addr = REG_RD(bp,
  11017. NIG_REG_XGXS0_CTRL_PHY_ADDR +
  11018. port * 0x18);
  11019. *phy = phy_xgxs;
  11020. break;
  11021. default:
  11022. DP(NETIF_MSG_LINK, "Invalid switch_cfg\n");
  11023. return -EINVAL;
  11024. }
  11025. }
  11026. phy->addr = (u8)phy_addr;
  11027. phy->mdio_ctrl = bnx2x_get_emac_base(bp,
  11028. SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH,
  11029. port);
  11030. if (CHIP_IS_E2(bp))
  11031. phy->def_md_devad = E2_DEFAULT_PHY_DEV_ADDR;
  11032. else
  11033. phy->def_md_devad = DEFAULT_PHY_DEV_ADDR;
  11034. DP(NETIF_MSG_LINK, "Internal phy port=%d, addr=0x%x, mdio_ctl=0x%x\n",
  11035. port, phy->addr, phy->mdio_ctrl);
  11036. bnx2x_populate_preemphasis(bp, shmem_base, phy, port, INT_PHY);
  11037. return 0;
  11038. }
  11039. static int bnx2x_populate_ext_phy(struct bnx2x *bp,
  11040. u8 phy_index,
  11041. u32 shmem_base,
  11042. u32 shmem2_base,
  11043. u8 port,
  11044. struct bnx2x_phy *phy)
  11045. {
  11046. u32 ext_phy_config, phy_type, config2;
  11047. u32 mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_BOTH;
  11048. ext_phy_config = bnx2x_get_ext_phy_config(bp, shmem_base,
  11049. phy_index, port);
  11050. phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  11051. /* Select the phy type */
  11052. switch (phy_type) {
  11053. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
  11054. mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_SWAPPED;
  11055. *phy = phy_8073;
  11056. break;
  11057. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705:
  11058. *phy = phy_8705;
  11059. break;
  11060. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706:
  11061. *phy = phy_8706;
  11062. break;
  11063. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
  11064. mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
  11065. *phy = phy_8726;
  11066. break;
  11067. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727_NOC:
  11068. /* BCM8727_NOC => BCM8727 no over current */
  11069. mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
  11070. *phy = phy_8727;
  11071. phy->flags |= FLAGS_NOC;
  11072. break;
  11073. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
  11074. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
  11075. mdc_mdio_access = SHARED_HW_CFG_MDC_MDIO_ACCESS1_EMAC1;
  11076. *phy = phy_8727;
  11077. break;
  11078. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481:
  11079. *phy = phy_8481;
  11080. break;
  11081. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84823:
  11082. *phy = phy_84823;
  11083. break;
  11084. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833:
  11085. *phy = phy_84833;
  11086. break;
  11087. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84834:
  11088. *phy = phy_84834;
  11089. break;
  11090. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84858:
  11091. *phy = phy_84858;
  11092. break;
  11093. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54616:
  11094. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE:
  11095. *phy = phy_54618se;
  11096. if (phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM54618SE)
  11097. phy->flags |= FLAGS_EEE;
  11098. break;
  11099. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
  11100. *phy = phy_7101;
  11101. break;
  11102. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
  11103. *phy = phy_null;
  11104. return -EINVAL;
  11105. default:
  11106. *phy = phy_null;
  11107. /* In case external PHY wasn't found */
  11108. if ((phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT) &&
  11109. (phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  11110. return -EINVAL;
  11111. return 0;
  11112. }
  11113. phy->addr = XGXS_EXT_PHY_ADDR(ext_phy_config);
  11114. bnx2x_populate_preemphasis(bp, shmem_base, phy, port, phy_index);
  11115. /* The shmem address of the phy version is located on different
  11116. * structures. In case this structure is too old, do not set
  11117. * the address
  11118. */
  11119. config2 = REG_RD(bp, shmem_base + offsetof(struct shmem_region,
  11120. dev_info.shared_hw_config.config2));
  11121. if (phy_index == EXT_PHY1) {
  11122. phy->ver_addr = shmem_base + offsetof(struct shmem_region,
  11123. port_mb[port].ext_phy_fw_version);
  11124. /* Check specific mdc mdio settings */
  11125. if (config2 & SHARED_HW_CFG_MDC_MDIO_ACCESS1_MASK)
  11126. mdc_mdio_access = config2 &
  11127. SHARED_HW_CFG_MDC_MDIO_ACCESS1_MASK;
  11128. } else {
  11129. u32 size = REG_RD(bp, shmem2_base);
  11130. if (size >
  11131. offsetof(struct shmem2_region, ext_phy_fw_version2)) {
  11132. phy->ver_addr = shmem2_base +
  11133. offsetof(struct shmem2_region,
  11134. ext_phy_fw_version2[port]);
  11135. }
  11136. /* Check specific mdc mdio settings */
  11137. if (config2 & SHARED_HW_CFG_MDC_MDIO_ACCESS2_MASK)
  11138. mdc_mdio_access = (config2 &
  11139. SHARED_HW_CFG_MDC_MDIO_ACCESS2_MASK) >>
  11140. (SHARED_HW_CFG_MDC_MDIO_ACCESS2_SHIFT -
  11141. SHARED_HW_CFG_MDC_MDIO_ACCESS1_SHIFT);
  11142. }
  11143. phy->mdio_ctrl = bnx2x_get_emac_base(bp, mdc_mdio_access, port);
  11144. if (bnx2x_is_8483x_8485x(phy) && (phy->ver_addr)) {
  11145. /* Remove 100Mb link supported for BCM84833/4 when phy fw
  11146. * version lower than or equal to 1.39
  11147. */
  11148. u32 raw_ver = REG_RD(bp, phy->ver_addr);
  11149. if (((raw_ver & 0x7F) <= 39) &&
  11150. (((raw_ver & 0xF80) >> 7) <= 1))
  11151. phy->supported &= ~(SUPPORTED_100baseT_Half |
  11152. SUPPORTED_100baseT_Full);
  11153. }
  11154. DP(NETIF_MSG_LINK, "phy_type 0x%x port %d found in index %d\n",
  11155. phy_type, port, phy_index);
  11156. DP(NETIF_MSG_LINK, " addr=0x%x, mdio_ctl=0x%x\n",
  11157. phy->addr, phy->mdio_ctrl);
  11158. return 0;
  11159. }
  11160. static int bnx2x_populate_phy(struct bnx2x *bp, u8 phy_index, u32 shmem_base,
  11161. u32 shmem2_base, u8 port, struct bnx2x_phy *phy)
  11162. {
  11163. int status = 0;
  11164. phy->type = PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN;
  11165. if (phy_index == INT_PHY)
  11166. return bnx2x_populate_int_phy(bp, shmem_base, port, phy);
  11167. status = bnx2x_populate_ext_phy(bp, phy_index, shmem_base, shmem2_base,
  11168. port, phy);
  11169. return status;
  11170. }
  11171. static void bnx2x_phy_def_cfg(struct link_params *params,
  11172. struct bnx2x_phy *phy,
  11173. u8 phy_index)
  11174. {
  11175. struct bnx2x *bp = params->bp;
  11176. u32 link_config;
  11177. /* Populate the default phy configuration for MF mode */
  11178. if (phy_index == EXT_PHY2) {
  11179. link_config = REG_RD(bp, params->shmem_base +
  11180. offsetof(struct shmem_region, dev_info.
  11181. port_feature_config[params->port].link_config2));
  11182. phy->speed_cap_mask = REG_RD(bp, params->shmem_base +
  11183. offsetof(struct shmem_region,
  11184. dev_info.
  11185. port_hw_config[params->port].speed_capability_mask2));
  11186. } else {
  11187. link_config = REG_RD(bp, params->shmem_base +
  11188. offsetof(struct shmem_region, dev_info.
  11189. port_feature_config[params->port].link_config));
  11190. phy->speed_cap_mask = REG_RD(bp, params->shmem_base +
  11191. offsetof(struct shmem_region,
  11192. dev_info.
  11193. port_hw_config[params->port].speed_capability_mask));
  11194. }
  11195. DP(NETIF_MSG_LINK,
  11196. "Default config phy idx %x cfg 0x%x speed_cap_mask 0x%x\n",
  11197. phy_index, link_config, phy->speed_cap_mask);
  11198. phy->req_duplex = DUPLEX_FULL;
  11199. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  11200. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  11201. phy->req_duplex = DUPLEX_HALF;
  11202. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  11203. phy->req_line_speed = SPEED_10;
  11204. break;
  11205. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  11206. phy->req_duplex = DUPLEX_HALF;
  11207. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  11208. phy->req_line_speed = SPEED_100;
  11209. break;
  11210. case PORT_FEATURE_LINK_SPEED_1G:
  11211. phy->req_line_speed = SPEED_1000;
  11212. break;
  11213. case PORT_FEATURE_LINK_SPEED_2_5G:
  11214. phy->req_line_speed = SPEED_2500;
  11215. break;
  11216. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  11217. phy->req_line_speed = SPEED_10000;
  11218. break;
  11219. default:
  11220. phy->req_line_speed = SPEED_AUTO_NEG;
  11221. break;
  11222. }
  11223. switch (link_config & PORT_FEATURE_FLOW_CONTROL_MASK) {
  11224. case PORT_FEATURE_FLOW_CONTROL_AUTO:
  11225. phy->req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO;
  11226. break;
  11227. case PORT_FEATURE_FLOW_CONTROL_TX:
  11228. phy->req_flow_ctrl = BNX2X_FLOW_CTRL_TX;
  11229. break;
  11230. case PORT_FEATURE_FLOW_CONTROL_RX:
  11231. phy->req_flow_ctrl = BNX2X_FLOW_CTRL_RX;
  11232. break;
  11233. case PORT_FEATURE_FLOW_CONTROL_BOTH:
  11234. phy->req_flow_ctrl = BNX2X_FLOW_CTRL_BOTH;
  11235. break;
  11236. default:
  11237. phy->req_flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  11238. break;
  11239. }
  11240. }
  11241. u32 bnx2x_phy_selection(struct link_params *params)
  11242. {
  11243. u32 phy_config_swapped, prio_cfg;
  11244. u32 return_cfg = PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT;
  11245. phy_config_swapped = params->multi_phy_config &
  11246. PORT_HW_CFG_PHY_SWAPPED_ENABLED;
  11247. prio_cfg = params->multi_phy_config &
  11248. PORT_HW_CFG_PHY_SELECTION_MASK;
  11249. if (phy_config_swapped) {
  11250. switch (prio_cfg) {
  11251. case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
  11252. return_cfg = PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY;
  11253. break;
  11254. case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
  11255. return_cfg = PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY;
  11256. break;
  11257. case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
  11258. return_cfg = PORT_HW_CFG_PHY_SELECTION_FIRST_PHY;
  11259. break;
  11260. case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
  11261. return_cfg = PORT_HW_CFG_PHY_SELECTION_SECOND_PHY;
  11262. break;
  11263. }
  11264. } else
  11265. return_cfg = prio_cfg;
  11266. return return_cfg;
  11267. }
  11268. int bnx2x_phy_probe(struct link_params *params)
  11269. {
  11270. u8 phy_index, actual_phy_idx;
  11271. u32 phy_config_swapped, sync_offset, media_types;
  11272. struct bnx2x *bp = params->bp;
  11273. struct bnx2x_phy *phy;
  11274. params->num_phys = 0;
  11275. DP(NETIF_MSG_LINK, "Begin phy probe\n");
  11276. phy_config_swapped = params->multi_phy_config &
  11277. PORT_HW_CFG_PHY_SWAPPED_ENABLED;
  11278. for (phy_index = INT_PHY; phy_index < MAX_PHYS;
  11279. phy_index++) {
  11280. actual_phy_idx = phy_index;
  11281. if (phy_config_swapped) {
  11282. if (phy_index == EXT_PHY1)
  11283. actual_phy_idx = EXT_PHY2;
  11284. else if (phy_index == EXT_PHY2)
  11285. actual_phy_idx = EXT_PHY1;
  11286. }
  11287. DP(NETIF_MSG_LINK, "phy_config_swapped %x, phy_index %x,"
  11288. " actual_phy_idx %x\n", phy_config_swapped,
  11289. phy_index, actual_phy_idx);
  11290. phy = &params->phy[actual_phy_idx];
  11291. if (bnx2x_populate_phy(bp, phy_index, params->shmem_base,
  11292. params->shmem2_base, params->port,
  11293. phy) != 0) {
  11294. params->num_phys = 0;
  11295. DP(NETIF_MSG_LINK, "phy probe failed in phy index %d\n",
  11296. phy_index);
  11297. for (phy_index = INT_PHY;
  11298. phy_index < MAX_PHYS;
  11299. phy_index++)
  11300. *phy = phy_null;
  11301. return -EINVAL;
  11302. }
  11303. if (phy->type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN)
  11304. break;
  11305. if (params->feature_config_flags &
  11306. FEATURE_CONFIG_DISABLE_REMOTE_FAULT_DET)
  11307. phy->flags &= ~FLAGS_TX_ERROR_CHECK;
  11308. if (!(params->feature_config_flags &
  11309. FEATURE_CONFIG_MT_SUPPORT))
  11310. phy->flags |= FLAGS_MDC_MDIO_WA_G;
  11311. sync_offset = params->shmem_base +
  11312. offsetof(struct shmem_region,
  11313. dev_info.port_hw_config[params->port].media_type);
  11314. media_types = REG_RD(bp, sync_offset);
  11315. /* Update media type for non-PMF sync only for the first time
  11316. * In case the media type changes afterwards, it will be updated
  11317. * using the update_status function
  11318. */
  11319. if ((media_types & (PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK <<
  11320. (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT *
  11321. actual_phy_idx))) == 0) {
  11322. media_types |= ((phy->media_type &
  11323. PORT_HW_CFG_MEDIA_TYPE_PHY0_MASK) <<
  11324. (PORT_HW_CFG_MEDIA_TYPE_PHY1_SHIFT *
  11325. actual_phy_idx));
  11326. }
  11327. REG_WR(bp, sync_offset, media_types);
  11328. bnx2x_phy_def_cfg(params, phy, phy_index);
  11329. params->num_phys++;
  11330. }
  11331. DP(NETIF_MSG_LINK, "End phy probe. #phys found %x\n", params->num_phys);
  11332. return 0;
  11333. }
  11334. static void bnx2x_init_bmac_loopback(struct link_params *params,
  11335. struct link_vars *vars)
  11336. {
  11337. struct bnx2x *bp = params->bp;
  11338. vars->link_up = 1;
  11339. vars->line_speed = SPEED_10000;
  11340. vars->duplex = DUPLEX_FULL;
  11341. vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  11342. vars->mac_type = MAC_TYPE_BMAC;
  11343. vars->phy_flags = PHY_XGXS_FLAG;
  11344. bnx2x_xgxs_deassert(params);
  11345. /* Set bmac loopback */
  11346. bnx2x_bmac_enable(params, vars, 1, 1);
  11347. REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
  11348. }
  11349. static void bnx2x_init_emac_loopback(struct link_params *params,
  11350. struct link_vars *vars)
  11351. {
  11352. struct bnx2x *bp = params->bp;
  11353. vars->link_up = 1;
  11354. vars->line_speed = SPEED_1000;
  11355. vars->duplex = DUPLEX_FULL;
  11356. vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  11357. vars->mac_type = MAC_TYPE_EMAC;
  11358. vars->phy_flags = PHY_XGXS_FLAG;
  11359. bnx2x_xgxs_deassert(params);
  11360. /* Set bmac loopback */
  11361. bnx2x_emac_enable(params, vars, 1);
  11362. bnx2x_emac_program(params, vars);
  11363. REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
  11364. }
  11365. static void bnx2x_init_xmac_loopback(struct link_params *params,
  11366. struct link_vars *vars)
  11367. {
  11368. struct bnx2x *bp = params->bp;
  11369. vars->link_up = 1;
  11370. if (!params->req_line_speed[0])
  11371. vars->line_speed = SPEED_10000;
  11372. else
  11373. vars->line_speed = params->req_line_speed[0];
  11374. vars->duplex = DUPLEX_FULL;
  11375. vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  11376. vars->mac_type = MAC_TYPE_XMAC;
  11377. vars->phy_flags = PHY_XGXS_FLAG;
  11378. /* Set WC to loopback mode since link is required to provide clock
  11379. * to the XMAC in 20G mode
  11380. */
  11381. bnx2x_set_aer_mmd(params, &params->phy[0]);
  11382. bnx2x_warpcore_reset_lane(bp, &params->phy[0], 0);
  11383. params->phy[INT_PHY].config_loopback(
  11384. &params->phy[INT_PHY],
  11385. params);
  11386. bnx2x_xmac_enable(params, vars, 1);
  11387. REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
  11388. }
  11389. static void bnx2x_init_umac_loopback(struct link_params *params,
  11390. struct link_vars *vars)
  11391. {
  11392. struct bnx2x *bp = params->bp;
  11393. vars->link_up = 1;
  11394. vars->line_speed = SPEED_1000;
  11395. vars->duplex = DUPLEX_FULL;
  11396. vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  11397. vars->mac_type = MAC_TYPE_UMAC;
  11398. vars->phy_flags = PHY_XGXS_FLAG;
  11399. bnx2x_umac_enable(params, vars, 1);
  11400. REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
  11401. }
  11402. static void bnx2x_init_xgxs_loopback(struct link_params *params,
  11403. struct link_vars *vars)
  11404. {
  11405. struct bnx2x *bp = params->bp;
  11406. struct bnx2x_phy *int_phy = &params->phy[INT_PHY];
  11407. vars->link_up = 1;
  11408. vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  11409. vars->duplex = DUPLEX_FULL;
  11410. if (params->req_line_speed[0] == SPEED_1000)
  11411. vars->line_speed = SPEED_1000;
  11412. else if ((params->req_line_speed[0] == SPEED_20000) ||
  11413. (int_phy->flags & FLAGS_WC_DUAL_MODE))
  11414. vars->line_speed = SPEED_20000;
  11415. else
  11416. vars->line_speed = SPEED_10000;
  11417. if (!USES_WARPCORE(bp))
  11418. bnx2x_xgxs_deassert(params);
  11419. bnx2x_link_initialize(params, vars);
  11420. if (params->req_line_speed[0] == SPEED_1000) {
  11421. if (USES_WARPCORE(bp))
  11422. bnx2x_umac_enable(params, vars, 0);
  11423. else {
  11424. bnx2x_emac_program(params, vars);
  11425. bnx2x_emac_enable(params, vars, 0);
  11426. }
  11427. } else {
  11428. if (USES_WARPCORE(bp))
  11429. bnx2x_xmac_enable(params, vars, 0);
  11430. else
  11431. bnx2x_bmac_enable(params, vars, 0, 1);
  11432. }
  11433. if (params->loopback_mode == LOOPBACK_XGXS) {
  11434. /* Set 10G XGXS loopback */
  11435. int_phy->config_loopback(int_phy, params);
  11436. } else {
  11437. /* Set external phy loopback */
  11438. u8 phy_index;
  11439. for (phy_index = EXT_PHY1;
  11440. phy_index < params->num_phys; phy_index++)
  11441. if (params->phy[phy_index].config_loopback)
  11442. params->phy[phy_index].config_loopback(
  11443. &params->phy[phy_index],
  11444. params);
  11445. }
  11446. REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
  11447. bnx2x_set_led(params, vars, LED_MODE_OPER, vars->line_speed);
  11448. }
  11449. void bnx2x_set_rx_filter(struct link_params *params, u8 en)
  11450. {
  11451. struct bnx2x *bp = params->bp;
  11452. u8 val = en * 0x1F;
  11453. /* Open / close the gate between the NIG and the BRB */
  11454. if (!CHIP_IS_E1x(bp))
  11455. val |= en * 0x20;
  11456. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + params->port*4, val);
  11457. if (!CHIP_IS_E1(bp)) {
  11458. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + params->port*4,
  11459. en*0x3);
  11460. }
  11461. REG_WR(bp, (params->port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  11462. NIG_REG_LLH0_BRB1_NOT_MCP), en);
  11463. }
  11464. static int bnx2x_avoid_link_flap(struct link_params *params,
  11465. struct link_vars *vars)
  11466. {
  11467. u32 phy_idx;
  11468. u32 dont_clear_stat, lfa_sts;
  11469. struct bnx2x *bp = params->bp;
  11470. bnx2x_set_mdio_emac_per_phy(bp, params);
  11471. /* Sync the link parameters */
  11472. bnx2x_link_status_update(params, vars);
  11473. /*
  11474. * The module verification was already done by previous link owner,
  11475. * so this call is meant only to get warning message
  11476. */
  11477. for (phy_idx = INT_PHY; phy_idx < params->num_phys; phy_idx++) {
  11478. struct bnx2x_phy *phy = &params->phy[phy_idx];
  11479. if (phy->phy_specific_func) {
  11480. DP(NETIF_MSG_LINK, "Calling PHY specific func\n");
  11481. phy->phy_specific_func(phy, params, PHY_INIT);
  11482. }
  11483. if ((phy->media_type == ETH_PHY_SFPP_10G_FIBER) ||
  11484. (phy->media_type == ETH_PHY_SFP_1G_FIBER) ||
  11485. (phy->media_type == ETH_PHY_DA_TWINAX))
  11486. bnx2x_verify_sfp_module(phy, params);
  11487. }
  11488. lfa_sts = REG_RD(bp, params->lfa_base +
  11489. offsetof(struct shmem_lfa,
  11490. lfa_sts));
  11491. dont_clear_stat = lfa_sts & SHMEM_LFA_DONT_CLEAR_STAT;
  11492. /* Re-enable the NIG/MAC */
  11493. if (CHIP_IS_E3(bp)) {
  11494. if (!dont_clear_stat) {
  11495. REG_WR(bp, GRCBASE_MISC +
  11496. MISC_REGISTERS_RESET_REG_2_CLEAR,
  11497. (MISC_REGISTERS_RESET_REG_2_MSTAT0 <<
  11498. params->port));
  11499. REG_WR(bp, GRCBASE_MISC +
  11500. MISC_REGISTERS_RESET_REG_2_SET,
  11501. (MISC_REGISTERS_RESET_REG_2_MSTAT0 <<
  11502. params->port));
  11503. }
  11504. if (vars->line_speed < SPEED_10000)
  11505. bnx2x_umac_enable(params, vars, 0);
  11506. else
  11507. bnx2x_xmac_enable(params, vars, 0);
  11508. } else {
  11509. if (vars->line_speed < SPEED_10000)
  11510. bnx2x_emac_enable(params, vars, 0);
  11511. else
  11512. bnx2x_bmac_enable(params, vars, 0, !dont_clear_stat);
  11513. }
  11514. /* Increment LFA count */
  11515. lfa_sts = ((lfa_sts & ~LINK_FLAP_AVOIDANCE_COUNT_MASK) |
  11516. (((((lfa_sts & LINK_FLAP_AVOIDANCE_COUNT_MASK) >>
  11517. LINK_FLAP_AVOIDANCE_COUNT_OFFSET) + 1) & 0xff)
  11518. << LINK_FLAP_AVOIDANCE_COUNT_OFFSET));
  11519. /* Clear link flap reason */
  11520. lfa_sts &= ~LFA_LINK_FLAP_REASON_MASK;
  11521. REG_WR(bp, params->lfa_base +
  11522. offsetof(struct shmem_lfa, lfa_sts), lfa_sts);
  11523. /* Disable NIG DRAIN */
  11524. REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
  11525. /* Enable interrupts */
  11526. bnx2x_link_int_enable(params);
  11527. return 0;
  11528. }
  11529. static void bnx2x_cannot_avoid_link_flap(struct link_params *params,
  11530. struct link_vars *vars,
  11531. int lfa_status)
  11532. {
  11533. u32 lfa_sts, cfg_idx, tmp_val;
  11534. struct bnx2x *bp = params->bp;
  11535. bnx2x_link_reset(params, vars, 1);
  11536. if (!params->lfa_base)
  11537. return;
  11538. /* Store the new link parameters */
  11539. REG_WR(bp, params->lfa_base +
  11540. offsetof(struct shmem_lfa, req_duplex),
  11541. params->req_duplex[0] | (params->req_duplex[1] << 16));
  11542. REG_WR(bp, params->lfa_base +
  11543. offsetof(struct shmem_lfa, req_flow_ctrl),
  11544. params->req_flow_ctrl[0] | (params->req_flow_ctrl[1] << 16));
  11545. REG_WR(bp, params->lfa_base +
  11546. offsetof(struct shmem_lfa, req_line_speed),
  11547. params->req_line_speed[0] | (params->req_line_speed[1] << 16));
  11548. for (cfg_idx = 0; cfg_idx < SHMEM_LINK_CONFIG_SIZE; cfg_idx++) {
  11549. REG_WR(bp, params->lfa_base +
  11550. offsetof(struct shmem_lfa,
  11551. speed_cap_mask[cfg_idx]),
  11552. params->speed_cap_mask[cfg_idx]);
  11553. }
  11554. tmp_val = REG_RD(bp, params->lfa_base +
  11555. offsetof(struct shmem_lfa, additional_config));
  11556. tmp_val &= ~REQ_FC_AUTO_ADV_MASK;
  11557. tmp_val |= params->req_fc_auto_adv;
  11558. REG_WR(bp, params->lfa_base +
  11559. offsetof(struct shmem_lfa, additional_config), tmp_val);
  11560. lfa_sts = REG_RD(bp, params->lfa_base +
  11561. offsetof(struct shmem_lfa, lfa_sts));
  11562. /* Clear the "Don't Clear Statistics" bit, and set reason */
  11563. lfa_sts &= ~SHMEM_LFA_DONT_CLEAR_STAT;
  11564. /* Set link flap reason */
  11565. lfa_sts &= ~LFA_LINK_FLAP_REASON_MASK;
  11566. lfa_sts |= ((lfa_status & LFA_LINK_FLAP_REASON_MASK) <<
  11567. LFA_LINK_FLAP_REASON_OFFSET);
  11568. /* Increment link flap counter */
  11569. lfa_sts = ((lfa_sts & ~LINK_FLAP_COUNT_MASK) |
  11570. (((((lfa_sts & LINK_FLAP_COUNT_MASK) >>
  11571. LINK_FLAP_COUNT_OFFSET) + 1) & 0xff)
  11572. << LINK_FLAP_COUNT_OFFSET));
  11573. REG_WR(bp, params->lfa_base +
  11574. offsetof(struct shmem_lfa, lfa_sts), lfa_sts);
  11575. /* Proceed with regular link initialization */
  11576. }
  11577. int bnx2x_phy_init(struct link_params *params, struct link_vars *vars)
  11578. {
  11579. int lfa_status;
  11580. struct bnx2x *bp = params->bp;
  11581. DP(NETIF_MSG_LINK, "Phy Initialization started\n");
  11582. DP(NETIF_MSG_LINK, "(1) req_speed %d, req_flowctrl %d\n",
  11583. params->req_line_speed[0], params->req_flow_ctrl[0]);
  11584. DP(NETIF_MSG_LINK, "(2) req_speed %d, req_flowctrl %d\n",
  11585. params->req_line_speed[1], params->req_flow_ctrl[1]);
  11586. DP(NETIF_MSG_LINK, "req_adv_flow_ctrl 0x%x\n", params->req_fc_auto_adv);
  11587. vars->link_status = 0;
  11588. vars->phy_link_up = 0;
  11589. vars->link_up = 0;
  11590. vars->line_speed = 0;
  11591. vars->duplex = DUPLEX_FULL;
  11592. vars->flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  11593. vars->mac_type = MAC_TYPE_NONE;
  11594. vars->phy_flags = 0;
  11595. vars->check_kr2_recovery_cnt = 0;
  11596. params->link_flags = PHY_INITIALIZED;
  11597. /* Driver opens NIG-BRB filters */
  11598. bnx2x_set_rx_filter(params, 1);
  11599. bnx2x_chng_link_count(params, true);
  11600. /* Check if link flap can be avoided */
  11601. lfa_status = bnx2x_check_lfa(params);
  11602. if (lfa_status == 0) {
  11603. DP(NETIF_MSG_LINK, "Link Flap Avoidance in progress\n");
  11604. return bnx2x_avoid_link_flap(params, vars);
  11605. }
  11606. DP(NETIF_MSG_LINK, "Cannot avoid link flap lfa_sta=0x%x\n",
  11607. lfa_status);
  11608. bnx2x_cannot_avoid_link_flap(params, vars, lfa_status);
  11609. /* Disable attentions */
  11610. bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + params->port*4,
  11611. (NIG_MASK_XGXS0_LINK_STATUS |
  11612. NIG_MASK_XGXS0_LINK10G |
  11613. NIG_MASK_SERDES0_LINK_STATUS |
  11614. NIG_MASK_MI_INT));
  11615. bnx2x_emac_init(params, vars);
  11616. if (params->feature_config_flags & FEATURE_CONFIG_PFC_ENABLED)
  11617. vars->link_status |= LINK_STATUS_PFC_ENABLED;
  11618. if (params->num_phys == 0) {
  11619. DP(NETIF_MSG_LINK, "No phy found for initialization !!\n");
  11620. return -EINVAL;
  11621. }
  11622. set_phy_vars(params, vars);
  11623. DP(NETIF_MSG_LINK, "Num of phys on board: %d\n", params->num_phys);
  11624. switch (params->loopback_mode) {
  11625. case LOOPBACK_BMAC:
  11626. bnx2x_init_bmac_loopback(params, vars);
  11627. break;
  11628. case LOOPBACK_EMAC:
  11629. bnx2x_init_emac_loopback(params, vars);
  11630. break;
  11631. case LOOPBACK_XMAC:
  11632. bnx2x_init_xmac_loopback(params, vars);
  11633. break;
  11634. case LOOPBACK_UMAC:
  11635. bnx2x_init_umac_loopback(params, vars);
  11636. break;
  11637. case LOOPBACK_XGXS:
  11638. case LOOPBACK_EXT_PHY:
  11639. bnx2x_init_xgxs_loopback(params, vars);
  11640. break;
  11641. default:
  11642. if (!CHIP_IS_E3(bp)) {
  11643. if (params->switch_cfg == SWITCH_CFG_10G)
  11644. bnx2x_xgxs_deassert(params);
  11645. else
  11646. bnx2x_serdes_deassert(bp, params->port);
  11647. }
  11648. bnx2x_link_initialize(params, vars);
  11649. msleep(30);
  11650. bnx2x_link_int_enable(params);
  11651. break;
  11652. }
  11653. bnx2x_update_mng(params, vars->link_status);
  11654. bnx2x_update_mng_eee(params, vars->eee_status);
  11655. return 0;
  11656. }
  11657. int bnx2x_link_reset(struct link_params *params, struct link_vars *vars,
  11658. u8 reset_ext_phy)
  11659. {
  11660. struct bnx2x *bp = params->bp;
  11661. u8 phy_index, port = params->port, clear_latch_ind = 0;
  11662. DP(NETIF_MSG_LINK, "Resetting the link of port %d\n", port);
  11663. /* Disable attentions */
  11664. vars->link_status = 0;
  11665. bnx2x_chng_link_count(params, true);
  11666. bnx2x_update_mng(params, vars->link_status);
  11667. vars->eee_status &= ~(SHMEM_EEE_LP_ADV_STATUS_MASK |
  11668. SHMEM_EEE_ACTIVE_BIT);
  11669. bnx2x_update_mng_eee(params, vars->eee_status);
  11670. bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4,
  11671. (NIG_MASK_XGXS0_LINK_STATUS |
  11672. NIG_MASK_XGXS0_LINK10G |
  11673. NIG_MASK_SERDES0_LINK_STATUS |
  11674. NIG_MASK_MI_INT));
  11675. /* Activate nig drain */
  11676. REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + port*4, 1);
  11677. /* Disable nig egress interface */
  11678. if (!CHIP_IS_E3(bp)) {
  11679. REG_WR(bp, NIG_REG_BMAC0_OUT_EN + port*4, 0);
  11680. REG_WR(bp, NIG_REG_EGRESS_EMAC0_OUT_EN + port*4, 0);
  11681. }
  11682. if (!CHIP_IS_E3(bp)) {
  11683. bnx2x_set_bmac_rx(bp, params->chip_id, port, 0);
  11684. } else {
  11685. bnx2x_set_xmac_rxtx(params, 0);
  11686. bnx2x_set_umac_rxtx(params, 0);
  11687. }
  11688. /* Disable emac */
  11689. if (!CHIP_IS_E3(bp))
  11690. REG_WR(bp, NIG_REG_NIG_EMAC0_EN + port*4, 0);
  11691. usleep_range(10000, 20000);
  11692. /* The PHY reset is controlled by GPIO 1
  11693. * Hold it as vars low
  11694. */
  11695. /* Clear link led */
  11696. bnx2x_set_mdio_emac_per_phy(bp, params);
  11697. bnx2x_set_led(params, vars, LED_MODE_OFF, 0);
  11698. if (reset_ext_phy) {
  11699. for (phy_index = EXT_PHY1; phy_index < params->num_phys;
  11700. phy_index++) {
  11701. if (params->phy[phy_index].link_reset) {
  11702. bnx2x_set_aer_mmd(params,
  11703. &params->phy[phy_index]);
  11704. params->phy[phy_index].link_reset(
  11705. &params->phy[phy_index],
  11706. params);
  11707. }
  11708. if (params->phy[phy_index].flags &
  11709. FLAGS_REARM_LATCH_SIGNAL)
  11710. clear_latch_ind = 1;
  11711. }
  11712. }
  11713. if (clear_latch_ind) {
  11714. /* Clear latching indication */
  11715. bnx2x_rearm_latch_signal(bp, port, 0);
  11716. bnx2x_bits_dis(bp, NIG_REG_LATCH_BC_0 + port*4,
  11717. 1 << NIG_LATCH_BC_ENABLE_MI_INT);
  11718. }
  11719. if (params->phy[INT_PHY].link_reset)
  11720. params->phy[INT_PHY].link_reset(
  11721. &params->phy[INT_PHY], params);
  11722. /* Disable nig ingress interface */
  11723. if (!CHIP_IS_E3(bp)) {
  11724. /* Reset BigMac */
  11725. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  11726. (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port));
  11727. REG_WR(bp, NIG_REG_BMAC0_IN_EN + port*4, 0);
  11728. REG_WR(bp, NIG_REG_EMAC0_IN_EN + port*4, 0);
  11729. } else {
  11730. u32 xmac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  11731. bnx2x_set_xumac_nig(params, 0, 0);
  11732. if (REG_RD(bp, MISC_REG_RESET_REG_2) &
  11733. MISC_REGISTERS_RESET_REG_2_XMAC)
  11734. REG_WR(bp, xmac_base + XMAC_REG_CTRL,
  11735. XMAC_CTRL_REG_SOFT_RESET);
  11736. }
  11737. vars->link_up = 0;
  11738. vars->phy_flags = 0;
  11739. return 0;
  11740. }
  11741. int bnx2x_lfa_reset(struct link_params *params,
  11742. struct link_vars *vars)
  11743. {
  11744. struct bnx2x *bp = params->bp;
  11745. vars->link_up = 0;
  11746. vars->phy_flags = 0;
  11747. params->link_flags &= ~PHY_INITIALIZED;
  11748. if (!params->lfa_base)
  11749. return bnx2x_link_reset(params, vars, 1);
  11750. /*
  11751. * Activate NIG drain so that during this time the device won't send
  11752. * anything while it is unable to response.
  11753. */
  11754. REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 1);
  11755. /*
  11756. * Close gracefully the gate from BMAC to NIG such that no half packets
  11757. * are passed.
  11758. */
  11759. if (!CHIP_IS_E3(bp))
  11760. bnx2x_set_bmac_rx(bp, params->chip_id, params->port, 0);
  11761. if (CHIP_IS_E3(bp)) {
  11762. bnx2x_set_xmac_rxtx(params, 0);
  11763. bnx2x_set_umac_rxtx(params, 0);
  11764. }
  11765. /* Wait 10ms for the pipe to clean up*/
  11766. usleep_range(10000, 20000);
  11767. /* Clean the NIG-BRB using the network filters in a way that will
  11768. * not cut a packet in the middle.
  11769. */
  11770. bnx2x_set_rx_filter(params, 0);
  11771. /*
  11772. * Re-open the gate between the BMAC and the NIG, after verifying the
  11773. * gate to the BRB is closed, otherwise packets may arrive to the
  11774. * firmware before driver had initialized it. The target is to achieve
  11775. * minimum management protocol down time.
  11776. */
  11777. if (!CHIP_IS_E3(bp))
  11778. bnx2x_set_bmac_rx(bp, params->chip_id, params->port, 1);
  11779. if (CHIP_IS_E3(bp)) {
  11780. bnx2x_set_xmac_rxtx(params, 1);
  11781. bnx2x_set_umac_rxtx(params, 1);
  11782. }
  11783. /* Disable NIG drain */
  11784. REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
  11785. return 0;
  11786. }
  11787. /****************************************************************************/
  11788. /* Common function */
  11789. /****************************************************************************/
  11790. static int bnx2x_8073_common_init_phy(struct bnx2x *bp,
  11791. u32 shmem_base_path[],
  11792. u32 shmem2_base_path[], u8 phy_index,
  11793. u32 chip_id)
  11794. {
  11795. struct bnx2x_phy phy[PORT_MAX];
  11796. struct bnx2x_phy *phy_blk[PORT_MAX];
  11797. u16 val;
  11798. s8 port = 0;
  11799. s8 port_of_path = 0;
  11800. u32 swap_val, swap_override;
  11801. swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
  11802. swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
  11803. port ^= (swap_val && swap_override);
  11804. bnx2x_ext_phy_hw_reset(bp, port);
  11805. /* PART1 - Reset both phys */
  11806. for (port = PORT_MAX - 1; port >= PORT_0; port--) {
  11807. u32 shmem_base, shmem2_base;
  11808. /* In E2, same phy is using for port0 of the two paths */
  11809. if (CHIP_IS_E1x(bp)) {
  11810. shmem_base = shmem_base_path[0];
  11811. shmem2_base = shmem2_base_path[0];
  11812. port_of_path = port;
  11813. } else {
  11814. shmem_base = shmem_base_path[port];
  11815. shmem2_base = shmem2_base_path[port];
  11816. port_of_path = 0;
  11817. }
  11818. /* Extract the ext phy address for the port */
  11819. if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
  11820. port_of_path, &phy[port]) !=
  11821. 0) {
  11822. DP(NETIF_MSG_LINK, "populate_phy failed\n");
  11823. return -EINVAL;
  11824. }
  11825. /* Disable attentions */
  11826. bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 +
  11827. port_of_path*4,
  11828. (NIG_MASK_XGXS0_LINK_STATUS |
  11829. NIG_MASK_XGXS0_LINK10G |
  11830. NIG_MASK_SERDES0_LINK_STATUS |
  11831. NIG_MASK_MI_INT));
  11832. /* Need to take the phy out of low power mode in order
  11833. * to write to access its registers
  11834. */
  11835. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
  11836. MISC_REGISTERS_GPIO_OUTPUT_HIGH,
  11837. port);
  11838. /* Reset the phy */
  11839. bnx2x_cl45_write(bp, &phy[port],
  11840. MDIO_PMA_DEVAD,
  11841. MDIO_PMA_REG_CTRL,
  11842. 1<<15);
  11843. }
  11844. /* Add delay of 150ms after reset */
  11845. msleep(150);
  11846. if (phy[PORT_0].addr & 0x1) {
  11847. phy_blk[PORT_0] = &(phy[PORT_1]);
  11848. phy_blk[PORT_1] = &(phy[PORT_0]);
  11849. } else {
  11850. phy_blk[PORT_0] = &(phy[PORT_0]);
  11851. phy_blk[PORT_1] = &(phy[PORT_1]);
  11852. }
  11853. /* PART2 - Download firmware to both phys */
  11854. for (port = PORT_MAX - 1; port >= PORT_0; port--) {
  11855. if (CHIP_IS_E1x(bp))
  11856. port_of_path = port;
  11857. else
  11858. port_of_path = 0;
  11859. DP(NETIF_MSG_LINK, "Loading spirom for phy address 0x%x\n",
  11860. phy_blk[port]->addr);
  11861. if (bnx2x_8073_8727_external_rom_boot(bp, phy_blk[port],
  11862. port_of_path))
  11863. return -EINVAL;
  11864. /* Only set bit 10 = 1 (Tx power down) */
  11865. bnx2x_cl45_read(bp, phy_blk[port],
  11866. MDIO_PMA_DEVAD,
  11867. MDIO_PMA_REG_TX_POWER_DOWN, &val);
  11868. /* Phase1 of TX_POWER_DOWN reset */
  11869. bnx2x_cl45_write(bp, phy_blk[port],
  11870. MDIO_PMA_DEVAD,
  11871. MDIO_PMA_REG_TX_POWER_DOWN,
  11872. (val | 1<<10));
  11873. }
  11874. /* Toggle Transmitter: Power down and then up with 600ms delay
  11875. * between
  11876. */
  11877. msleep(600);
  11878. /* PART3 - complete TX_POWER_DOWN process, and set GPIO2 back to low */
  11879. for (port = PORT_MAX - 1; port >= PORT_0; port--) {
  11880. /* Phase2 of POWER_DOWN_RESET */
  11881. /* Release bit 10 (Release Tx power down) */
  11882. bnx2x_cl45_read(bp, phy_blk[port],
  11883. MDIO_PMA_DEVAD,
  11884. MDIO_PMA_REG_TX_POWER_DOWN, &val);
  11885. bnx2x_cl45_write(bp, phy_blk[port],
  11886. MDIO_PMA_DEVAD,
  11887. MDIO_PMA_REG_TX_POWER_DOWN, (val & (~(1<<10))));
  11888. usleep_range(15000, 30000);
  11889. /* Read modify write the SPI-ROM version select register */
  11890. bnx2x_cl45_read(bp, phy_blk[port],
  11891. MDIO_PMA_DEVAD,
  11892. MDIO_PMA_REG_EDC_FFE_MAIN, &val);
  11893. bnx2x_cl45_write(bp, phy_blk[port],
  11894. MDIO_PMA_DEVAD,
  11895. MDIO_PMA_REG_EDC_FFE_MAIN, (val | (1<<12)));
  11896. /* set GPIO2 back to LOW */
  11897. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
  11898. MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
  11899. }
  11900. return 0;
  11901. }
  11902. static int bnx2x_8726_common_init_phy(struct bnx2x *bp,
  11903. u32 shmem_base_path[],
  11904. u32 shmem2_base_path[], u8 phy_index,
  11905. u32 chip_id)
  11906. {
  11907. u32 val;
  11908. s8 port;
  11909. struct bnx2x_phy phy;
  11910. /* Use port1 because of the static port-swap */
  11911. /* Enable the module detection interrupt */
  11912. val = REG_RD(bp, MISC_REG_GPIO_EVENT_EN);
  11913. val |= ((1<<MISC_REGISTERS_GPIO_3)|
  11914. (1<<(MISC_REGISTERS_GPIO_3 + MISC_REGISTERS_GPIO_PORT_SHIFT)));
  11915. REG_WR(bp, MISC_REG_GPIO_EVENT_EN, val);
  11916. bnx2x_ext_phy_hw_reset(bp, 0);
  11917. usleep_range(5000, 10000);
  11918. for (port = 0; port < PORT_MAX; port++) {
  11919. u32 shmem_base, shmem2_base;
  11920. /* In E2, same phy is using for port0 of the two paths */
  11921. if (CHIP_IS_E1x(bp)) {
  11922. shmem_base = shmem_base_path[0];
  11923. shmem2_base = shmem2_base_path[0];
  11924. } else {
  11925. shmem_base = shmem_base_path[port];
  11926. shmem2_base = shmem2_base_path[port];
  11927. }
  11928. /* Extract the ext phy address for the port */
  11929. if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
  11930. port, &phy) !=
  11931. 0) {
  11932. DP(NETIF_MSG_LINK, "populate phy failed\n");
  11933. return -EINVAL;
  11934. }
  11935. /* Reset phy*/
  11936. bnx2x_cl45_write(bp, &phy,
  11937. MDIO_PMA_DEVAD, MDIO_PMA_REG_GEN_CTRL, 0x0001);
  11938. /* Set fault module detected LED on */
  11939. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
  11940. MISC_REGISTERS_GPIO_HIGH,
  11941. port);
  11942. }
  11943. return 0;
  11944. }
  11945. static void bnx2x_get_ext_phy_reset_gpio(struct bnx2x *bp, u32 shmem_base,
  11946. u8 *io_gpio, u8 *io_port)
  11947. {
  11948. u32 phy_gpio_reset = REG_RD(bp, shmem_base +
  11949. offsetof(struct shmem_region,
  11950. dev_info.port_hw_config[PORT_0].default_cfg));
  11951. switch (phy_gpio_reset) {
  11952. case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P0:
  11953. *io_gpio = 0;
  11954. *io_port = 0;
  11955. break;
  11956. case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO1_P0:
  11957. *io_gpio = 1;
  11958. *io_port = 0;
  11959. break;
  11960. case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO2_P0:
  11961. *io_gpio = 2;
  11962. *io_port = 0;
  11963. break;
  11964. case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO3_P0:
  11965. *io_gpio = 3;
  11966. *io_port = 0;
  11967. break;
  11968. case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO0_P1:
  11969. *io_gpio = 0;
  11970. *io_port = 1;
  11971. break;
  11972. case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO1_P1:
  11973. *io_gpio = 1;
  11974. *io_port = 1;
  11975. break;
  11976. case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO2_P1:
  11977. *io_gpio = 2;
  11978. *io_port = 1;
  11979. break;
  11980. case PORT_HW_CFG_EXT_PHY_GPIO_RST_GPIO3_P1:
  11981. *io_gpio = 3;
  11982. *io_port = 1;
  11983. break;
  11984. default:
  11985. /* Don't override the io_gpio and io_port */
  11986. break;
  11987. }
  11988. }
  11989. static int bnx2x_8727_common_init_phy(struct bnx2x *bp,
  11990. u32 shmem_base_path[],
  11991. u32 shmem2_base_path[], u8 phy_index,
  11992. u32 chip_id)
  11993. {
  11994. s8 port, reset_gpio;
  11995. u32 swap_val, swap_override;
  11996. struct bnx2x_phy phy[PORT_MAX];
  11997. struct bnx2x_phy *phy_blk[PORT_MAX];
  11998. s8 port_of_path;
  11999. swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
  12000. swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
  12001. reset_gpio = MISC_REGISTERS_GPIO_1;
  12002. port = 1;
  12003. /* Retrieve the reset gpio/port which control the reset.
  12004. * Default is GPIO1, PORT1
  12005. */
  12006. bnx2x_get_ext_phy_reset_gpio(bp, shmem_base_path[0],
  12007. (u8 *)&reset_gpio, (u8 *)&port);
  12008. /* Calculate the port based on port swap */
  12009. port ^= (swap_val && swap_override);
  12010. /* Initiate PHY reset*/
  12011. bnx2x_set_gpio(bp, reset_gpio, MISC_REGISTERS_GPIO_OUTPUT_LOW,
  12012. port);
  12013. usleep_range(1000, 2000);
  12014. bnx2x_set_gpio(bp, reset_gpio, MISC_REGISTERS_GPIO_OUTPUT_HIGH,
  12015. port);
  12016. usleep_range(5000, 10000);
  12017. /* PART1 - Reset both phys */
  12018. for (port = PORT_MAX - 1; port >= PORT_0; port--) {
  12019. u32 shmem_base, shmem2_base;
  12020. /* In E2, same phy is using for port0 of the two paths */
  12021. if (CHIP_IS_E1x(bp)) {
  12022. shmem_base = shmem_base_path[0];
  12023. shmem2_base = shmem2_base_path[0];
  12024. port_of_path = port;
  12025. } else {
  12026. shmem_base = shmem_base_path[port];
  12027. shmem2_base = shmem2_base_path[port];
  12028. port_of_path = 0;
  12029. }
  12030. /* Extract the ext phy address for the port */
  12031. if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
  12032. port_of_path, &phy[port]) !=
  12033. 0) {
  12034. DP(NETIF_MSG_LINK, "populate phy failed\n");
  12035. return -EINVAL;
  12036. }
  12037. /* disable attentions */
  12038. bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 +
  12039. port_of_path*4,
  12040. (NIG_MASK_XGXS0_LINK_STATUS |
  12041. NIG_MASK_XGXS0_LINK10G |
  12042. NIG_MASK_SERDES0_LINK_STATUS |
  12043. NIG_MASK_MI_INT));
  12044. /* Reset the phy */
  12045. bnx2x_cl45_write(bp, &phy[port],
  12046. MDIO_PMA_DEVAD, MDIO_PMA_REG_CTRL, 1<<15);
  12047. }
  12048. /* Add delay of 150ms after reset */
  12049. msleep(150);
  12050. if (phy[PORT_0].addr & 0x1) {
  12051. phy_blk[PORT_0] = &(phy[PORT_1]);
  12052. phy_blk[PORT_1] = &(phy[PORT_0]);
  12053. } else {
  12054. phy_blk[PORT_0] = &(phy[PORT_0]);
  12055. phy_blk[PORT_1] = &(phy[PORT_1]);
  12056. }
  12057. /* PART2 - Download firmware to both phys */
  12058. for (port = PORT_MAX - 1; port >= PORT_0; port--) {
  12059. if (CHIP_IS_E1x(bp))
  12060. port_of_path = port;
  12061. else
  12062. port_of_path = 0;
  12063. DP(NETIF_MSG_LINK, "Loading spirom for phy address 0x%x\n",
  12064. phy_blk[port]->addr);
  12065. if (bnx2x_8073_8727_external_rom_boot(bp, phy_blk[port],
  12066. port_of_path))
  12067. return -EINVAL;
  12068. /* Disable PHY transmitter output */
  12069. bnx2x_cl45_write(bp, phy_blk[port],
  12070. MDIO_PMA_DEVAD,
  12071. MDIO_PMA_REG_TX_DISABLE, 1);
  12072. }
  12073. return 0;
  12074. }
  12075. static int bnx2x_84833_common_init_phy(struct bnx2x *bp,
  12076. u32 shmem_base_path[],
  12077. u32 shmem2_base_path[],
  12078. u8 phy_index,
  12079. u32 chip_id)
  12080. {
  12081. u8 reset_gpios;
  12082. reset_gpios = bnx2x_84833_get_reset_gpios(bp, shmem_base_path, chip_id);
  12083. bnx2x_set_mult_gpio(bp, reset_gpios, MISC_REGISTERS_GPIO_OUTPUT_LOW);
  12084. udelay(10);
  12085. bnx2x_set_mult_gpio(bp, reset_gpios, MISC_REGISTERS_GPIO_OUTPUT_HIGH);
  12086. DP(NETIF_MSG_LINK, "84833 reset pulse on pin values 0x%x\n",
  12087. reset_gpios);
  12088. return 0;
  12089. }
  12090. static int bnx2x_ext_phy_common_init(struct bnx2x *bp, u32 shmem_base_path[],
  12091. u32 shmem2_base_path[], u8 phy_index,
  12092. u32 ext_phy_type, u32 chip_id)
  12093. {
  12094. int rc = 0;
  12095. switch (ext_phy_type) {
  12096. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
  12097. rc = bnx2x_8073_common_init_phy(bp, shmem_base_path,
  12098. shmem2_base_path,
  12099. phy_index, chip_id);
  12100. break;
  12101. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8722:
  12102. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
  12103. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727_NOC:
  12104. rc = bnx2x_8727_common_init_phy(bp, shmem_base_path,
  12105. shmem2_base_path,
  12106. phy_index, chip_id);
  12107. break;
  12108. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
  12109. /* GPIO1 affects both ports, so there's need to pull
  12110. * it for single port alone
  12111. */
  12112. rc = bnx2x_8726_common_init_phy(bp, shmem_base_path,
  12113. shmem2_base_path,
  12114. phy_index, chip_id);
  12115. break;
  12116. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833:
  12117. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84834:
  12118. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84858:
  12119. /* GPIO3's are linked, and so both need to be toggled
  12120. * to obtain required 2us pulse.
  12121. */
  12122. rc = bnx2x_84833_common_init_phy(bp, shmem_base_path,
  12123. shmem2_base_path,
  12124. phy_index, chip_id);
  12125. break;
  12126. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
  12127. rc = -EINVAL;
  12128. break;
  12129. default:
  12130. DP(NETIF_MSG_LINK,
  12131. "ext_phy 0x%x common init not required\n",
  12132. ext_phy_type);
  12133. break;
  12134. }
  12135. if (rc)
  12136. netdev_err(bp->dev, "Warning: PHY was not initialized,"
  12137. " Port %d\n",
  12138. 0);
  12139. return rc;
  12140. }
  12141. int bnx2x_common_init_phy(struct bnx2x *bp, u32 shmem_base_path[],
  12142. u32 shmem2_base_path[], u32 chip_id)
  12143. {
  12144. int rc = 0;
  12145. u32 phy_ver, val;
  12146. u8 phy_index = 0;
  12147. u32 ext_phy_type, ext_phy_config;
  12148. bnx2x_set_mdio_clk(bp, chip_id, GRCBASE_EMAC0);
  12149. bnx2x_set_mdio_clk(bp, chip_id, GRCBASE_EMAC1);
  12150. DP(NETIF_MSG_LINK, "Begin common phy init\n");
  12151. if (CHIP_IS_E3(bp)) {
  12152. /* Enable EPIO */
  12153. val = REG_RD(bp, MISC_REG_GEN_PURP_HWG);
  12154. REG_WR(bp, MISC_REG_GEN_PURP_HWG, val | 1);
  12155. }
  12156. /* Check if common init was already done */
  12157. phy_ver = REG_RD(bp, shmem_base_path[0] +
  12158. offsetof(struct shmem_region,
  12159. port_mb[PORT_0].ext_phy_fw_version));
  12160. if (phy_ver) {
  12161. DP(NETIF_MSG_LINK, "Not doing common init; phy ver is 0x%x\n",
  12162. phy_ver);
  12163. return 0;
  12164. }
  12165. /* Read the ext_phy_type for arbitrary port(0) */
  12166. for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
  12167. phy_index++) {
  12168. ext_phy_config = bnx2x_get_ext_phy_config(bp,
  12169. shmem_base_path[0],
  12170. phy_index, 0);
  12171. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  12172. rc |= bnx2x_ext_phy_common_init(bp, shmem_base_path,
  12173. shmem2_base_path,
  12174. phy_index, ext_phy_type,
  12175. chip_id);
  12176. }
  12177. return rc;
  12178. }
  12179. static void bnx2x_check_over_curr(struct link_params *params,
  12180. struct link_vars *vars)
  12181. {
  12182. struct bnx2x *bp = params->bp;
  12183. u32 cfg_pin;
  12184. u8 port = params->port;
  12185. u32 pin_val;
  12186. cfg_pin = (REG_RD(bp, params->shmem_base +
  12187. offsetof(struct shmem_region,
  12188. dev_info.port_hw_config[port].e3_cmn_pin_cfg1)) &
  12189. PORT_HW_CFG_E3_OVER_CURRENT_MASK) >>
  12190. PORT_HW_CFG_E3_OVER_CURRENT_SHIFT;
  12191. /* Ignore check if no external input PIN available */
  12192. if (bnx2x_get_cfg_pin(bp, cfg_pin, &pin_val) != 0)
  12193. return;
  12194. if (!pin_val) {
  12195. if ((vars->phy_flags & PHY_OVER_CURRENT_FLAG) == 0) {
  12196. netdev_err(bp->dev, "Error: Power fault on Port %d has"
  12197. " been detected and the power to "
  12198. "that SFP+ module has been removed"
  12199. " to prevent failure of the card."
  12200. " Please remove the SFP+ module and"
  12201. " restart the system to clear this"
  12202. " error.\n",
  12203. params->port);
  12204. vars->phy_flags |= PHY_OVER_CURRENT_FLAG;
  12205. bnx2x_warpcore_power_module(params, 0);
  12206. }
  12207. } else
  12208. vars->phy_flags &= ~PHY_OVER_CURRENT_FLAG;
  12209. }
  12210. /* Returns 0 if no change occurred since last check; 1 otherwise. */
  12211. static u8 bnx2x_analyze_link_error(struct link_params *params,
  12212. struct link_vars *vars, u32 status,
  12213. u32 phy_flag, u32 link_flag, u8 notify)
  12214. {
  12215. struct bnx2x *bp = params->bp;
  12216. /* Compare new value with previous value */
  12217. u8 led_mode;
  12218. u32 old_status = (vars->phy_flags & phy_flag) ? 1 : 0;
  12219. if ((status ^ old_status) == 0)
  12220. return 0;
  12221. /* If values differ */
  12222. switch (phy_flag) {
  12223. case PHY_HALF_OPEN_CONN_FLAG:
  12224. DP(NETIF_MSG_LINK, "Analyze Remote Fault\n");
  12225. break;
  12226. case PHY_SFP_TX_FAULT_FLAG:
  12227. DP(NETIF_MSG_LINK, "Analyze TX Fault\n");
  12228. break;
  12229. default:
  12230. DP(NETIF_MSG_LINK, "Analyze UNKNOWN\n");
  12231. }
  12232. DP(NETIF_MSG_LINK, "Link changed:[%x %x]->%x\n", vars->link_up,
  12233. old_status, status);
  12234. /* Do not touch the link in case physical link down */
  12235. if ((vars->phy_flags & PHY_PHYSICAL_LINK_FLAG) == 0)
  12236. return 1;
  12237. /* a. Update shmem->link_status accordingly
  12238. * b. Update link_vars->link_up
  12239. */
  12240. if (status) {
  12241. vars->link_status &= ~LINK_STATUS_LINK_UP;
  12242. vars->link_status |= link_flag;
  12243. vars->link_up = 0;
  12244. vars->phy_flags |= phy_flag;
  12245. /* activate nig drain */
  12246. REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 1);
  12247. /* Set LED mode to off since the PHY doesn't know about these
  12248. * errors
  12249. */
  12250. led_mode = LED_MODE_OFF;
  12251. } else {
  12252. vars->link_status |= LINK_STATUS_LINK_UP;
  12253. vars->link_status &= ~link_flag;
  12254. vars->link_up = 1;
  12255. vars->phy_flags &= ~phy_flag;
  12256. led_mode = LED_MODE_OPER;
  12257. /* Clear nig drain */
  12258. REG_WR(bp, NIG_REG_EGRESS_DRAIN0_MODE + params->port*4, 0);
  12259. }
  12260. bnx2x_sync_link(params, vars);
  12261. /* Update the LED according to the link state */
  12262. bnx2x_set_led(params, vars, led_mode, SPEED_10000);
  12263. /* Update link status in the shared memory */
  12264. bnx2x_update_mng(params, vars->link_status);
  12265. /* C. Trigger General Attention */
  12266. vars->periodic_flags |= PERIODIC_FLAGS_LINK_EVENT;
  12267. if (notify)
  12268. bnx2x_notify_link_changed(bp);
  12269. return 1;
  12270. }
  12271. /******************************************************************************
  12272. * Description:
  12273. * This function checks for half opened connection change indication.
  12274. * When such change occurs, it calls the bnx2x_analyze_link_error
  12275. * to check if Remote Fault is set or cleared. Reception of remote fault
  12276. * status message in the MAC indicates that the peer's MAC has detected
  12277. * a fault, for example, due to break in the TX side of fiber.
  12278. *
  12279. ******************************************************************************/
  12280. static int bnx2x_check_half_open_conn(struct link_params *params,
  12281. struct link_vars *vars,
  12282. u8 notify)
  12283. {
  12284. struct bnx2x *bp = params->bp;
  12285. u32 lss_status = 0;
  12286. u32 mac_base;
  12287. /* In case link status is physically up @ 10G do */
  12288. if (((vars->phy_flags & PHY_PHYSICAL_LINK_FLAG) == 0) ||
  12289. (REG_RD(bp, NIG_REG_EGRESS_EMAC0_PORT + params->port*4)))
  12290. return 0;
  12291. if (CHIP_IS_E3(bp) &&
  12292. (REG_RD(bp, MISC_REG_RESET_REG_2) &
  12293. (MISC_REGISTERS_RESET_REG_2_XMAC))) {
  12294. /* Check E3 XMAC */
  12295. /* Note that link speed cannot be queried here, since it may be
  12296. * zero while link is down. In case UMAC is active, LSS will
  12297. * simply not be set
  12298. */
  12299. mac_base = (params->port) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  12300. /* Clear stick bits (Requires rising edge) */
  12301. REG_WR(bp, mac_base + XMAC_REG_CLEAR_RX_LSS_STATUS, 0);
  12302. REG_WR(bp, mac_base + XMAC_REG_CLEAR_RX_LSS_STATUS,
  12303. XMAC_CLEAR_RX_LSS_STATUS_REG_CLEAR_LOCAL_FAULT_STATUS |
  12304. XMAC_CLEAR_RX_LSS_STATUS_REG_CLEAR_REMOTE_FAULT_STATUS);
  12305. if (REG_RD(bp, mac_base + XMAC_REG_RX_LSS_STATUS))
  12306. lss_status = 1;
  12307. bnx2x_analyze_link_error(params, vars, lss_status,
  12308. PHY_HALF_OPEN_CONN_FLAG,
  12309. LINK_STATUS_NONE, notify);
  12310. } else if (REG_RD(bp, MISC_REG_RESET_REG_2) &
  12311. (MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << params->port)) {
  12312. /* Check E1X / E2 BMAC */
  12313. u32 lss_status_reg;
  12314. u32 wb_data[2];
  12315. mac_base = params->port ? NIG_REG_INGRESS_BMAC1_MEM :
  12316. NIG_REG_INGRESS_BMAC0_MEM;
  12317. /* Read BIGMAC_REGISTER_RX_LSS_STATUS */
  12318. if (CHIP_IS_E2(bp))
  12319. lss_status_reg = BIGMAC2_REGISTER_RX_LSS_STAT;
  12320. else
  12321. lss_status_reg = BIGMAC_REGISTER_RX_LSS_STATUS;
  12322. REG_RD_DMAE(bp, mac_base + lss_status_reg, wb_data, 2);
  12323. lss_status = (wb_data[0] > 0);
  12324. bnx2x_analyze_link_error(params, vars, lss_status,
  12325. PHY_HALF_OPEN_CONN_FLAG,
  12326. LINK_STATUS_NONE, notify);
  12327. }
  12328. return 0;
  12329. }
  12330. static void bnx2x_sfp_tx_fault_detection(struct bnx2x_phy *phy,
  12331. struct link_params *params,
  12332. struct link_vars *vars)
  12333. {
  12334. struct bnx2x *bp = params->bp;
  12335. u32 cfg_pin, value = 0;
  12336. u8 led_change, port = params->port;
  12337. /* Get The SFP+ TX_Fault controlling pin ([eg]pio) */
  12338. cfg_pin = (REG_RD(bp, params->shmem_base + offsetof(struct shmem_region,
  12339. dev_info.port_hw_config[port].e3_cmn_pin_cfg)) &
  12340. PORT_HW_CFG_E3_TX_FAULT_MASK) >>
  12341. PORT_HW_CFG_E3_TX_FAULT_SHIFT;
  12342. if (bnx2x_get_cfg_pin(bp, cfg_pin, &value)) {
  12343. DP(NETIF_MSG_LINK, "Failed to read pin 0x%02x\n", cfg_pin);
  12344. return;
  12345. }
  12346. led_change = bnx2x_analyze_link_error(params, vars, value,
  12347. PHY_SFP_TX_FAULT_FLAG,
  12348. LINK_STATUS_SFP_TX_FAULT, 1);
  12349. if (led_change) {
  12350. /* Change TX_Fault led, set link status for further syncs */
  12351. u8 led_mode;
  12352. if (vars->phy_flags & PHY_SFP_TX_FAULT_FLAG) {
  12353. led_mode = MISC_REGISTERS_GPIO_HIGH;
  12354. vars->link_status |= LINK_STATUS_SFP_TX_FAULT;
  12355. } else {
  12356. led_mode = MISC_REGISTERS_GPIO_LOW;
  12357. vars->link_status &= ~LINK_STATUS_SFP_TX_FAULT;
  12358. }
  12359. /* If module is unapproved, led should be on regardless */
  12360. if (!(phy->flags & FLAGS_SFP_NOT_APPROVED)) {
  12361. DP(NETIF_MSG_LINK, "Change TX_Fault LED: ->%x\n",
  12362. led_mode);
  12363. bnx2x_set_e3_module_fault_led(params, led_mode);
  12364. }
  12365. }
  12366. }
  12367. static void bnx2x_kr2_recovery(struct link_params *params,
  12368. struct link_vars *vars,
  12369. struct bnx2x_phy *phy)
  12370. {
  12371. struct bnx2x *bp = params->bp;
  12372. DP(NETIF_MSG_LINK, "KR2 recovery\n");
  12373. bnx2x_warpcore_enable_AN_KR2(phy, params, vars);
  12374. bnx2x_warpcore_restart_AN_KR(phy, params);
  12375. }
  12376. static void bnx2x_check_kr2_wa(struct link_params *params,
  12377. struct link_vars *vars,
  12378. struct bnx2x_phy *phy)
  12379. {
  12380. struct bnx2x *bp = params->bp;
  12381. u16 base_page, next_page, not_kr2_device, lane;
  12382. int sigdet;
  12383. /* Once KR2 was disabled, wait 5 seconds before checking KR2 recovery
  12384. * Since some switches tend to reinit the AN process and clear the
  12385. * the advertised BP/NP after ~2 seconds causing the KR2 to be disabled
  12386. * and recovered many times
  12387. */
  12388. if (vars->check_kr2_recovery_cnt > 0) {
  12389. vars->check_kr2_recovery_cnt--;
  12390. return;
  12391. }
  12392. sigdet = bnx2x_warpcore_get_sigdet(phy, params);
  12393. if (!sigdet) {
  12394. if (!(params->link_attr_sync & LINK_ATTR_SYNC_KR2_ENABLE)) {
  12395. bnx2x_kr2_recovery(params, vars, phy);
  12396. DP(NETIF_MSG_LINK, "No sigdet\n");
  12397. }
  12398. return;
  12399. }
  12400. lane = bnx2x_get_warpcore_lane(phy, params);
  12401. CL22_WR_OVER_CL45(bp, phy, MDIO_REG_BANK_AER_BLOCK,
  12402. MDIO_AER_BLOCK_AER_REG, lane);
  12403. bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
  12404. MDIO_AN_REG_LP_AUTO_NEG, &base_page);
  12405. bnx2x_cl45_read(bp, phy, MDIO_AN_DEVAD,
  12406. MDIO_AN_REG_LP_AUTO_NEG2, &next_page);
  12407. bnx2x_set_aer_mmd(params, phy);
  12408. /* CL73 has not begun yet */
  12409. if (base_page == 0) {
  12410. if (!(params->link_attr_sync & LINK_ATTR_SYNC_KR2_ENABLE)) {
  12411. bnx2x_kr2_recovery(params, vars, phy);
  12412. DP(NETIF_MSG_LINK, "No BP\n");
  12413. }
  12414. return;
  12415. }
  12416. /* In case NP bit is not set in the BasePage, or it is set,
  12417. * but only KX is advertised, declare this link partner as non-KR2
  12418. * device.
  12419. */
  12420. not_kr2_device = (((base_page & 0x8000) == 0) ||
  12421. (((base_page & 0x8000) &&
  12422. ((next_page & 0xe0) == 0x20))));
  12423. /* In case KR2 is already disabled, check if we need to re-enable it */
  12424. if (!(params->link_attr_sync & LINK_ATTR_SYNC_KR2_ENABLE)) {
  12425. if (!not_kr2_device) {
  12426. DP(NETIF_MSG_LINK, "BP=0x%x, NP=0x%x\n", base_page,
  12427. next_page);
  12428. bnx2x_kr2_recovery(params, vars, phy);
  12429. }
  12430. return;
  12431. }
  12432. /* KR2 is enabled, but not KR2 device */
  12433. if (not_kr2_device) {
  12434. /* Disable KR2 on both lanes */
  12435. DP(NETIF_MSG_LINK, "BP=0x%x, NP=0x%x\n", base_page, next_page);
  12436. bnx2x_disable_kr2(params, vars, phy);
  12437. /* Restart AN on leading lane */
  12438. bnx2x_warpcore_restart_AN_KR(phy, params);
  12439. return;
  12440. }
  12441. }
  12442. void bnx2x_period_func(struct link_params *params, struct link_vars *vars)
  12443. {
  12444. u16 phy_idx;
  12445. struct bnx2x *bp = params->bp;
  12446. for (phy_idx = INT_PHY; phy_idx < MAX_PHYS; phy_idx++) {
  12447. if (params->phy[phy_idx].flags & FLAGS_TX_ERROR_CHECK) {
  12448. bnx2x_set_aer_mmd(params, &params->phy[phy_idx]);
  12449. if (bnx2x_check_half_open_conn(params, vars, 1) !=
  12450. 0)
  12451. DP(NETIF_MSG_LINK, "Fault detection failed\n");
  12452. break;
  12453. }
  12454. }
  12455. if (CHIP_IS_E3(bp)) {
  12456. struct bnx2x_phy *phy = &params->phy[INT_PHY];
  12457. bnx2x_set_aer_mmd(params, phy);
  12458. if (((phy->req_line_speed == SPEED_AUTO_NEG) &&
  12459. (phy->speed_cap_mask &
  12460. PORT_HW_CFG_SPEED_CAPABILITY_D0_20G)) ||
  12461. (phy->req_line_speed == SPEED_20000))
  12462. bnx2x_check_kr2_wa(params, vars, phy);
  12463. bnx2x_check_over_curr(params, vars);
  12464. if (vars->rx_tx_asic_rst)
  12465. bnx2x_warpcore_config_runtime(phy, params, vars);
  12466. if ((REG_RD(bp, params->shmem_base +
  12467. offsetof(struct shmem_region, dev_info.
  12468. port_hw_config[params->port].default_cfg))
  12469. & PORT_HW_CFG_NET_SERDES_IF_MASK) ==
  12470. PORT_HW_CFG_NET_SERDES_IF_SFI) {
  12471. if (bnx2x_is_sfp_module_plugged(phy, params)) {
  12472. bnx2x_sfp_tx_fault_detection(phy, params, vars);
  12473. } else if (vars->link_status &
  12474. LINK_STATUS_SFP_TX_FAULT) {
  12475. /* Clean trail, interrupt corrects the leds */
  12476. vars->link_status &= ~LINK_STATUS_SFP_TX_FAULT;
  12477. vars->phy_flags &= ~PHY_SFP_TX_FAULT_FLAG;
  12478. /* Update link status in the shared memory */
  12479. bnx2x_update_mng(params, vars->link_status);
  12480. }
  12481. }
  12482. }
  12483. }
  12484. u8 bnx2x_fan_failure_det_req(struct bnx2x *bp,
  12485. u32 shmem_base,
  12486. u32 shmem2_base,
  12487. u8 port)
  12488. {
  12489. u8 phy_index, fan_failure_det_req = 0;
  12490. struct bnx2x_phy phy;
  12491. for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
  12492. phy_index++) {
  12493. if (bnx2x_populate_phy(bp, phy_index, shmem_base, shmem2_base,
  12494. port, &phy)
  12495. != 0) {
  12496. DP(NETIF_MSG_LINK, "populate phy failed\n");
  12497. return 0;
  12498. }
  12499. fan_failure_det_req |= (phy.flags &
  12500. FLAGS_FAN_FAILURE_DET_REQ);
  12501. }
  12502. return fan_failure_det_req;
  12503. }
  12504. void bnx2x_hw_reset_phy(struct link_params *params)
  12505. {
  12506. u8 phy_index;
  12507. struct bnx2x *bp = params->bp;
  12508. bnx2x_update_mng(params, 0);
  12509. bnx2x_bits_dis(bp, NIG_REG_MASK_INTERRUPT_PORT0 + params->port*4,
  12510. (NIG_MASK_XGXS0_LINK_STATUS |
  12511. NIG_MASK_XGXS0_LINK10G |
  12512. NIG_MASK_SERDES0_LINK_STATUS |
  12513. NIG_MASK_MI_INT));
  12514. for (phy_index = INT_PHY; phy_index < MAX_PHYS;
  12515. phy_index++) {
  12516. if (params->phy[phy_index].hw_reset) {
  12517. params->phy[phy_index].hw_reset(
  12518. &params->phy[phy_index],
  12519. params);
  12520. params->phy[phy_index] = phy_null;
  12521. }
  12522. }
  12523. }
  12524. void bnx2x_init_mod_abs_int(struct bnx2x *bp, struct link_vars *vars,
  12525. u32 chip_id, u32 shmem_base, u32 shmem2_base,
  12526. u8 port)
  12527. {
  12528. u8 gpio_num = 0xff, gpio_port = 0xff, phy_index;
  12529. u32 val;
  12530. u32 offset, aeu_mask, swap_val, swap_override, sync_offset;
  12531. if (CHIP_IS_E3(bp)) {
  12532. if (bnx2x_get_mod_abs_int_cfg(bp, chip_id,
  12533. shmem_base,
  12534. port,
  12535. &gpio_num,
  12536. &gpio_port) != 0)
  12537. return;
  12538. } else {
  12539. struct bnx2x_phy phy;
  12540. for (phy_index = EXT_PHY1; phy_index < MAX_PHYS;
  12541. phy_index++) {
  12542. if (bnx2x_populate_phy(bp, phy_index, shmem_base,
  12543. shmem2_base, port, &phy)
  12544. != 0) {
  12545. DP(NETIF_MSG_LINK, "populate phy failed\n");
  12546. return;
  12547. }
  12548. if (phy.type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726) {
  12549. gpio_num = MISC_REGISTERS_GPIO_3;
  12550. gpio_port = port;
  12551. break;
  12552. }
  12553. }
  12554. }
  12555. if (gpio_num == 0xff)
  12556. return;
  12557. /* Set GPIO3 to trigger SFP+ module insertion/removal */
  12558. bnx2x_set_gpio(bp, gpio_num, MISC_REGISTERS_GPIO_INPUT_HI_Z, gpio_port);
  12559. swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
  12560. swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
  12561. gpio_port ^= (swap_val && swap_override);
  12562. vars->aeu_int_mask = AEU_INPUTS_ATTN_BITS_GPIO0_FUNCTION_0 <<
  12563. (gpio_num + (gpio_port << 2));
  12564. sync_offset = shmem_base +
  12565. offsetof(struct shmem_region,
  12566. dev_info.port_hw_config[port].aeu_int_mask);
  12567. REG_WR(bp, sync_offset, vars->aeu_int_mask);
  12568. DP(NETIF_MSG_LINK, "Setting MOD_ABS (GPIO%d_P%d) AEU to 0x%x\n",
  12569. gpio_num, gpio_port, vars->aeu_int_mask);
  12570. if (port == 0)
  12571. offset = MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0;
  12572. else
  12573. offset = MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0;
  12574. /* Open appropriate AEU for interrupts */
  12575. aeu_mask = REG_RD(bp, offset);
  12576. aeu_mask |= vars->aeu_int_mask;
  12577. REG_WR(bp, offset, aeu_mask);
  12578. /* Enable the GPIO to trigger interrupt */
  12579. val = REG_RD(bp, MISC_REG_GPIO_EVENT_EN);
  12580. val |= 1 << (gpio_num + (gpio_port << 2));
  12581. REG_WR(bp, MISC_REG_GPIO_EVENT_EN, val);
  12582. }