e1000_hw.c 189 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405
  1. /*******************************************************************************
  2. Copyright(c) 1999 - 2004 Intel Corporation. All rights reserved.
  3. This program is free software; you can redistribute it and/or modify it
  4. under the terms of the GNU General Public License as published by the Free
  5. Software Foundation; either version 2 of the License, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc., 59
  13. Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. The full GNU General Public License is included in this distribution in the
  15. file called LICENSE.
  16. Contact Information:
  17. Linux NICS <linux.nics@intel.com>
  18. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  19. *******************************************************************************/
  20. /* e1000_hw.c
  21. * Shared functions for accessing and configuring the MAC
  22. */
  23. #include "e1000_hw.h"
  24. static int32_t e1000_set_phy_type(struct e1000_hw *hw);
  25. static void e1000_phy_init_script(struct e1000_hw *hw);
  26. static int32_t e1000_setup_copper_link(struct e1000_hw *hw);
  27. static int32_t e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
  28. static int32_t e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
  29. static int32_t e1000_phy_force_speed_duplex(struct e1000_hw *hw);
  30. static int32_t e1000_config_mac_to_phy(struct e1000_hw *hw);
  31. static void e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
  32. static void e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
  33. static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data,
  34. uint16_t count);
  35. static uint16_t e1000_shift_in_mdi_bits(struct e1000_hw *hw);
  36. static int32_t e1000_phy_reset_dsp(struct e1000_hw *hw);
  37. static int32_t e1000_write_eeprom_spi(struct e1000_hw *hw, uint16_t offset,
  38. uint16_t words, uint16_t *data);
  39. static int32_t e1000_write_eeprom_microwire(struct e1000_hw *hw,
  40. uint16_t offset, uint16_t words,
  41. uint16_t *data);
  42. static int32_t e1000_spi_eeprom_ready(struct e1000_hw *hw);
  43. static void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
  44. static void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
  45. static void e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data,
  46. uint16_t count);
  47. static int32_t e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
  48. uint16_t phy_data);
  49. static int32_t e1000_read_phy_reg_ex(struct e1000_hw *hw,uint32_t reg_addr,
  50. uint16_t *phy_data);
  51. static uint16_t e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count);
  52. static int32_t e1000_acquire_eeprom(struct e1000_hw *hw);
  53. static void e1000_release_eeprom(struct e1000_hw *hw);
  54. static void e1000_standby_eeprom(struct e1000_hw *hw);
  55. static int32_t e1000_id_led_init(struct e1000_hw * hw);
  56. static int32_t e1000_set_vco_speed(struct e1000_hw *hw);
  57. static int32_t e1000_polarity_reversal_workaround(struct e1000_hw *hw);
  58. static int32_t e1000_set_phy_mode(struct e1000_hw *hw);
  59. /* IGP cable length table */
  60. static const
  61. uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
  62. { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  63. 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
  64. 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
  65. 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
  66. 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
  67. 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
  68. 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
  69. 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
  70. /******************************************************************************
  71. * Set the phy type member in the hw struct.
  72. *
  73. * hw - Struct containing variables accessed by shared code
  74. *****************************************************************************/
  75. int32_t
  76. e1000_set_phy_type(struct e1000_hw *hw)
  77. {
  78. DEBUGFUNC("e1000_set_phy_type");
  79. switch(hw->phy_id) {
  80. case M88E1000_E_PHY_ID:
  81. case M88E1000_I_PHY_ID:
  82. case M88E1011_I_PHY_ID:
  83. hw->phy_type = e1000_phy_m88;
  84. break;
  85. case IGP01E1000_I_PHY_ID:
  86. if(hw->mac_type == e1000_82541 ||
  87. hw->mac_type == e1000_82541_rev_2 ||
  88. hw->mac_type == e1000_82547 ||
  89. hw->mac_type == e1000_82547_rev_2) {
  90. hw->phy_type = e1000_phy_igp;
  91. break;
  92. }
  93. /* Fall Through */
  94. default:
  95. /* Should never have loaded on this device */
  96. hw->phy_type = e1000_phy_undefined;
  97. return -E1000_ERR_PHY_TYPE;
  98. }
  99. return E1000_SUCCESS;
  100. }
  101. /******************************************************************************
  102. * IGP phy init script - initializes the GbE PHY
  103. *
  104. * hw - Struct containing variables accessed by shared code
  105. *****************************************************************************/
  106. static void
  107. e1000_phy_init_script(struct e1000_hw *hw)
  108. {
  109. uint32_t ret_val;
  110. uint16_t phy_saved_data;
  111. DEBUGFUNC("e1000_phy_init_script");
  112. if(hw->phy_init_script) {
  113. msec_delay(20);
  114. /* Save off the current value of register 0x2F5B to be restored at
  115. * the end of this routine. */
  116. ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
  117. /* Disabled the PHY transmitter */
  118. e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
  119. msec_delay(20);
  120. e1000_write_phy_reg(hw,0x0000,0x0140);
  121. msec_delay(5);
  122. switch(hw->mac_type) {
  123. case e1000_82541:
  124. case e1000_82547:
  125. e1000_write_phy_reg(hw, 0x1F95, 0x0001);
  126. e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
  127. e1000_write_phy_reg(hw, 0x1F79, 0x0018);
  128. e1000_write_phy_reg(hw, 0x1F30, 0x1600);
  129. e1000_write_phy_reg(hw, 0x1F31, 0x0014);
  130. e1000_write_phy_reg(hw, 0x1F32, 0x161C);
  131. e1000_write_phy_reg(hw, 0x1F94, 0x0003);
  132. e1000_write_phy_reg(hw, 0x1F96, 0x003F);
  133. e1000_write_phy_reg(hw, 0x2010, 0x0008);
  134. break;
  135. case e1000_82541_rev_2:
  136. case e1000_82547_rev_2:
  137. e1000_write_phy_reg(hw, 0x1F73, 0x0099);
  138. break;
  139. default:
  140. break;
  141. }
  142. e1000_write_phy_reg(hw, 0x0000, 0x3300);
  143. msec_delay(20);
  144. /* Now enable the transmitter */
  145. e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
  146. if(hw->mac_type == e1000_82547) {
  147. uint16_t fused, fine, coarse;
  148. /* Move to analog registers page */
  149. e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
  150. if(!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
  151. e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
  152. fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
  153. coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
  154. if(coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
  155. coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
  156. fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
  157. } else if(coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
  158. fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
  159. fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
  160. (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
  161. (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
  162. e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
  163. e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
  164. IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
  165. }
  166. }
  167. }
  168. }
  169. /******************************************************************************
  170. * Set the mac type member in the hw struct.
  171. *
  172. * hw - Struct containing variables accessed by shared code
  173. *****************************************************************************/
  174. int32_t
  175. e1000_set_mac_type(struct e1000_hw *hw)
  176. {
  177. DEBUGFUNC("e1000_set_mac_type");
  178. switch (hw->device_id) {
  179. case E1000_DEV_ID_82542:
  180. switch (hw->revision_id) {
  181. case E1000_82542_2_0_REV_ID:
  182. hw->mac_type = e1000_82542_rev2_0;
  183. break;
  184. case E1000_82542_2_1_REV_ID:
  185. hw->mac_type = e1000_82542_rev2_1;
  186. break;
  187. default:
  188. /* Invalid 82542 revision ID */
  189. return -E1000_ERR_MAC_TYPE;
  190. }
  191. break;
  192. case E1000_DEV_ID_82543GC_FIBER:
  193. case E1000_DEV_ID_82543GC_COPPER:
  194. hw->mac_type = e1000_82543;
  195. break;
  196. case E1000_DEV_ID_82544EI_COPPER:
  197. case E1000_DEV_ID_82544EI_FIBER:
  198. case E1000_DEV_ID_82544GC_COPPER:
  199. case E1000_DEV_ID_82544GC_LOM:
  200. hw->mac_type = e1000_82544;
  201. break;
  202. case E1000_DEV_ID_82540EM:
  203. case E1000_DEV_ID_82540EM_LOM:
  204. case E1000_DEV_ID_82540EP:
  205. case E1000_DEV_ID_82540EP_LOM:
  206. case E1000_DEV_ID_82540EP_LP:
  207. hw->mac_type = e1000_82540;
  208. break;
  209. case E1000_DEV_ID_82545EM_COPPER:
  210. case E1000_DEV_ID_82545EM_FIBER:
  211. hw->mac_type = e1000_82545;
  212. break;
  213. case E1000_DEV_ID_82545GM_COPPER:
  214. case E1000_DEV_ID_82545GM_FIBER:
  215. case E1000_DEV_ID_82545GM_SERDES:
  216. hw->mac_type = e1000_82545_rev_3;
  217. break;
  218. case E1000_DEV_ID_82546EB_COPPER:
  219. case E1000_DEV_ID_82546EB_FIBER:
  220. case E1000_DEV_ID_82546EB_QUAD_COPPER:
  221. hw->mac_type = e1000_82546;
  222. break;
  223. case E1000_DEV_ID_82546GB_COPPER:
  224. case E1000_DEV_ID_82546GB_FIBER:
  225. case E1000_DEV_ID_82546GB_SERDES:
  226. case E1000_DEV_ID_82546GB_PCIE:
  227. hw->mac_type = e1000_82546_rev_3;
  228. break;
  229. case E1000_DEV_ID_82541EI:
  230. case E1000_DEV_ID_82541EI_MOBILE:
  231. hw->mac_type = e1000_82541;
  232. break;
  233. case E1000_DEV_ID_82541ER:
  234. case E1000_DEV_ID_82541GI:
  235. case E1000_DEV_ID_82541GI_LF:
  236. case E1000_DEV_ID_82541GI_MOBILE:
  237. hw->mac_type = e1000_82541_rev_2;
  238. break;
  239. case E1000_DEV_ID_82547EI:
  240. hw->mac_type = e1000_82547;
  241. break;
  242. case E1000_DEV_ID_82547GI:
  243. hw->mac_type = e1000_82547_rev_2;
  244. break;
  245. default:
  246. /* Should never have loaded on this device */
  247. return -E1000_ERR_MAC_TYPE;
  248. }
  249. switch(hw->mac_type) {
  250. case e1000_82541:
  251. case e1000_82547:
  252. case e1000_82541_rev_2:
  253. case e1000_82547_rev_2:
  254. hw->asf_firmware_present = TRUE;
  255. break;
  256. default:
  257. break;
  258. }
  259. return E1000_SUCCESS;
  260. }
  261. /*****************************************************************************
  262. * Set media type and TBI compatibility.
  263. *
  264. * hw - Struct containing variables accessed by shared code
  265. * **************************************************************************/
  266. void
  267. e1000_set_media_type(struct e1000_hw *hw)
  268. {
  269. uint32_t status;
  270. DEBUGFUNC("e1000_set_media_type");
  271. if(hw->mac_type != e1000_82543) {
  272. /* tbi_compatibility is only valid on 82543 */
  273. hw->tbi_compatibility_en = FALSE;
  274. }
  275. switch (hw->device_id) {
  276. case E1000_DEV_ID_82545GM_SERDES:
  277. case E1000_DEV_ID_82546GB_SERDES:
  278. hw->media_type = e1000_media_type_internal_serdes;
  279. break;
  280. default:
  281. if(hw->mac_type >= e1000_82543) {
  282. status = E1000_READ_REG(hw, STATUS);
  283. if(status & E1000_STATUS_TBIMODE) {
  284. hw->media_type = e1000_media_type_fiber;
  285. /* tbi_compatibility not valid on fiber */
  286. hw->tbi_compatibility_en = FALSE;
  287. } else {
  288. hw->media_type = e1000_media_type_copper;
  289. }
  290. } else {
  291. /* This is an 82542 (fiber only) */
  292. hw->media_type = e1000_media_type_fiber;
  293. }
  294. }
  295. }
  296. /******************************************************************************
  297. * Reset the transmit and receive units; mask and clear all interrupts.
  298. *
  299. * hw - Struct containing variables accessed by shared code
  300. *****************************************************************************/
  301. int32_t
  302. e1000_reset_hw(struct e1000_hw *hw)
  303. {
  304. uint32_t ctrl;
  305. uint32_t ctrl_ext;
  306. uint32_t icr;
  307. uint32_t manc;
  308. uint32_t led_ctrl;
  309. DEBUGFUNC("e1000_reset_hw");
  310. /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
  311. if(hw->mac_type == e1000_82542_rev2_0) {
  312. DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
  313. e1000_pci_clear_mwi(hw);
  314. }
  315. /* Clear interrupt mask to stop board from generating interrupts */
  316. DEBUGOUT("Masking off all interrupts\n");
  317. E1000_WRITE_REG(hw, IMC, 0xffffffff);
  318. /* Disable the Transmit and Receive units. Then delay to allow
  319. * any pending transactions to complete before we hit the MAC with
  320. * the global reset.
  321. */
  322. E1000_WRITE_REG(hw, RCTL, 0);
  323. E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
  324. E1000_WRITE_FLUSH(hw);
  325. /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
  326. hw->tbi_compatibility_on = FALSE;
  327. /* Delay to allow any outstanding PCI transactions to complete before
  328. * resetting the device
  329. */
  330. msec_delay(10);
  331. ctrl = E1000_READ_REG(hw, CTRL);
  332. /* Must reset the PHY before resetting the MAC */
  333. if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
  334. E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
  335. msec_delay(5);
  336. }
  337. /* Issue a global reset to the MAC. This will reset the chip's
  338. * transmit, receive, DMA, and link units. It will not effect
  339. * the current PCI configuration. The global reset bit is self-
  340. * clearing, and should clear within a microsecond.
  341. */
  342. DEBUGOUT("Issuing a global reset to MAC\n");
  343. switch(hw->mac_type) {
  344. case e1000_82544:
  345. case e1000_82540:
  346. case e1000_82545:
  347. case e1000_82546:
  348. case e1000_82541:
  349. case e1000_82541_rev_2:
  350. /* These controllers can't ack the 64-bit write when issuing the
  351. * reset, so use IO-mapping as a workaround to issue the reset */
  352. E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
  353. break;
  354. case e1000_82545_rev_3:
  355. case e1000_82546_rev_3:
  356. /* Reset is performed on a shadow of the control register */
  357. E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
  358. break;
  359. default:
  360. E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
  361. break;
  362. }
  363. /* After MAC reset, force reload of EEPROM to restore power-on settings to
  364. * device. Later controllers reload the EEPROM automatically, so just wait
  365. * for reload to complete.
  366. */
  367. switch(hw->mac_type) {
  368. case e1000_82542_rev2_0:
  369. case e1000_82542_rev2_1:
  370. case e1000_82543:
  371. case e1000_82544:
  372. /* Wait for reset to complete */
  373. udelay(10);
  374. ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  375. ctrl_ext |= E1000_CTRL_EXT_EE_RST;
  376. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  377. E1000_WRITE_FLUSH(hw);
  378. /* Wait for EEPROM reload */
  379. msec_delay(2);
  380. break;
  381. case e1000_82541:
  382. case e1000_82541_rev_2:
  383. case e1000_82547:
  384. case e1000_82547_rev_2:
  385. /* Wait for EEPROM reload */
  386. msec_delay(20);
  387. break;
  388. default:
  389. /* Wait for EEPROM reload (it happens automatically) */
  390. msec_delay(5);
  391. break;
  392. }
  393. /* Disable HW ARPs on ASF enabled adapters */
  394. if(hw->mac_type >= e1000_82540) {
  395. manc = E1000_READ_REG(hw, MANC);
  396. manc &= ~(E1000_MANC_ARP_EN);
  397. E1000_WRITE_REG(hw, MANC, manc);
  398. }
  399. if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
  400. e1000_phy_init_script(hw);
  401. /* Configure activity LED after PHY reset */
  402. led_ctrl = E1000_READ_REG(hw, LEDCTL);
  403. led_ctrl &= IGP_ACTIVITY_LED_MASK;
  404. led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
  405. E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
  406. }
  407. /* Clear interrupt mask to stop board from generating interrupts */
  408. DEBUGOUT("Masking off all interrupts\n");
  409. E1000_WRITE_REG(hw, IMC, 0xffffffff);
  410. /* Clear any pending interrupt events. */
  411. icr = E1000_READ_REG(hw, ICR);
  412. /* If MWI was previously enabled, reenable it. */
  413. if(hw->mac_type == e1000_82542_rev2_0) {
  414. if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
  415. e1000_pci_set_mwi(hw);
  416. }
  417. return E1000_SUCCESS;
  418. }
  419. /******************************************************************************
  420. * Performs basic configuration of the adapter.
  421. *
  422. * hw - Struct containing variables accessed by shared code
  423. *
  424. * Assumes that the controller has previously been reset and is in a
  425. * post-reset uninitialized state. Initializes the receive address registers,
  426. * multicast table, and VLAN filter table. Calls routines to setup link
  427. * configuration and flow control settings. Clears all on-chip counters. Leaves
  428. * the transmit and receive units disabled and uninitialized.
  429. *****************************************************************************/
  430. int32_t
  431. e1000_init_hw(struct e1000_hw *hw)
  432. {
  433. uint32_t ctrl;
  434. uint32_t i;
  435. int32_t ret_val;
  436. uint16_t pcix_cmd_word;
  437. uint16_t pcix_stat_hi_word;
  438. uint16_t cmd_mmrbc;
  439. uint16_t stat_mmrbc;
  440. DEBUGFUNC("e1000_init_hw");
  441. /* Initialize Identification LED */
  442. ret_val = e1000_id_led_init(hw);
  443. if(ret_val) {
  444. DEBUGOUT("Error Initializing Identification LED\n");
  445. return ret_val;
  446. }
  447. /* Set the media type and TBI compatibility */
  448. e1000_set_media_type(hw);
  449. /* Disabling VLAN filtering. */
  450. DEBUGOUT("Initializing the IEEE VLAN\n");
  451. E1000_WRITE_REG(hw, VET, 0);
  452. e1000_clear_vfta(hw);
  453. /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
  454. if(hw->mac_type == e1000_82542_rev2_0) {
  455. DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
  456. e1000_pci_clear_mwi(hw);
  457. E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
  458. E1000_WRITE_FLUSH(hw);
  459. msec_delay(5);
  460. }
  461. /* Setup the receive address. This involves initializing all of the Receive
  462. * Address Registers (RARs 0 - 15).
  463. */
  464. e1000_init_rx_addrs(hw);
  465. /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
  466. if(hw->mac_type == e1000_82542_rev2_0) {
  467. E1000_WRITE_REG(hw, RCTL, 0);
  468. E1000_WRITE_FLUSH(hw);
  469. msec_delay(1);
  470. if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
  471. e1000_pci_set_mwi(hw);
  472. }
  473. /* Zero out the Multicast HASH table */
  474. DEBUGOUT("Zeroing the MTA\n");
  475. for(i = 0; i < E1000_MC_TBL_SIZE; i++)
  476. E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
  477. /* Set the PCI priority bit correctly in the CTRL register. This
  478. * determines if the adapter gives priority to receives, or if it
  479. * gives equal priority to transmits and receives.
  480. */
  481. if(hw->dma_fairness) {
  482. ctrl = E1000_READ_REG(hw, CTRL);
  483. E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
  484. }
  485. switch(hw->mac_type) {
  486. case e1000_82545_rev_3:
  487. case e1000_82546_rev_3:
  488. break;
  489. default:
  490. /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
  491. if(hw->bus_type == e1000_bus_type_pcix) {
  492. e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
  493. e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
  494. &pcix_stat_hi_word);
  495. cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
  496. PCIX_COMMAND_MMRBC_SHIFT;
  497. stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
  498. PCIX_STATUS_HI_MMRBC_SHIFT;
  499. if(stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
  500. stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
  501. if(cmd_mmrbc > stat_mmrbc) {
  502. pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
  503. pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
  504. e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
  505. &pcix_cmd_word);
  506. }
  507. }
  508. break;
  509. }
  510. /* Call a subroutine to configure the link and setup flow control. */
  511. ret_val = e1000_setup_link(hw);
  512. /* Set the transmit descriptor write-back policy */
  513. if(hw->mac_type > e1000_82544) {
  514. ctrl = E1000_READ_REG(hw, TXDCTL);
  515. ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
  516. E1000_WRITE_REG(hw, TXDCTL, ctrl);
  517. }
  518. /* Clear all of the statistics registers (clear on read). It is
  519. * important that we do this after we have tried to establish link
  520. * because the symbol error count will increment wildly if there
  521. * is no link.
  522. */
  523. e1000_clear_hw_cntrs(hw);
  524. return ret_val;
  525. }
  526. /******************************************************************************
  527. * Adjust SERDES output amplitude based on EEPROM setting.
  528. *
  529. * hw - Struct containing variables accessed by shared code.
  530. *****************************************************************************/
  531. static int32_t
  532. e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
  533. {
  534. uint16_t eeprom_data;
  535. int32_t ret_val;
  536. DEBUGFUNC("e1000_adjust_serdes_amplitude");
  537. if(hw->media_type != e1000_media_type_internal_serdes)
  538. return E1000_SUCCESS;
  539. switch(hw->mac_type) {
  540. case e1000_82545_rev_3:
  541. case e1000_82546_rev_3:
  542. break;
  543. default:
  544. return E1000_SUCCESS;
  545. }
  546. ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
  547. if (ret_val) {
  548. return ret_val;
  549. }
  550. if(eeprom_data != EEPROM_RESERVED_WORD) {
  551. /* Adjust SERDES output amplitude only. */
  552. eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
  553. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
  554. if(ret_val)
  555. return ret_val;
  556. }
  557. return E1000_SUCCESS;
  558. }
  559. /******************************************************************************
  560. * Configures flow control and link settings.
  561. *
  562. * hw - Struct containing variables accessed by shared code
  563. *
  564. * Determines which flow control settings to use. Calls the apropriate media-
  565. * specific link configuration function. Configures the flow control settings.
  566. * Assuming the adapter has a valid link partner, a valid link should be
  567. * established. Assumes the hardware has previously been reset and the
  568. * transmitter and receiver are not enabled.
  569. *****************************************************************************/
  570. int32_t
  571. e1000_setup_link(struct e1000_hw *hw)
  572. {
  573. uint32_t ctrl_ext;
  574. int32_t ret_val;
  575. uint16_t eeprom_data;
  576. DEBUGFUNC("e1000_setup_link");
  577. /* Read and store word 0x0F of the EEPROM. This word contains bits
  578. * that determine the hardware's default PAUSE (flow control) mode,
  579. * a bit that determines whether the HW defaults to enabling or
  580. * disabling auto-negotiation, and the direction of the
  581. * SW defined pins. If there is no SW over-ride of the flow
  582. * control setting, then the variable hw->fc will
  583. * be initialized based on a value in the EEPROM.
  584. */
  585. if(e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data) < 0) {
  586. DEBUGOUT("EEPROM Read Error\n");
  587. return -E1000_ERR_EEPROM;
  588. }
  589. if(hw->fc == e1000_fc_default) {
  590. if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
  591. hw->fc = e1000_fc_none;
  592. else if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
  593. EEPROM_WORD0F_ASM_DIR)
  594. hw->fc = e1000_fc_tx_pause;
  595. else
  596. hw->fc = e1000_fc_full;
  597. }
  598. /* We want to save off the original Flow Control configuration just
  599. * in case we get disconnected and then reconnected into a different
  600. * hub or switch with different Flow Control capabilities.
  601. */
  602. if(hw->mac_type == e1000_82542_rev2_0)
  603. hw->fc &= (~e1000_fc_tx_pause);
  604. if((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
  605. hw->fc &= (~e1000_fc_rx_pause);
  606. hw->original_fc = hw->fc;
  607. DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
  608. /* Take the 4 bits from EEPROM word 0x0F that determine the initial
  609. * polarity value for the SW controlled pins, and setup the
  610. * Extended Device Control reg with that info.
  611. * This is needed because one of the SW controlled pins is used for
  612. * signal detection. So this should be done before e1000_setup_pcs_link()
  613. * or e1000_phy_setup() is called.
  614. */
  615. if(hw->mac_type == e1000_82543) {
  616. ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
  617. SWDPIO__EXT_SHIFT);
  618. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  619. }
  620. /* Call the necessary subroutine to configure the link. */
  621. ret_val = (hw->media_type == e1000_media_type_copper) ?
  622. e1000_setup_copper_link(hw) :
  623. e1000_setup_fiber_serdes_link(hw);
  624. /* Initialize the flow control address, type, and PAUSE timer
  625. * registers to their default values. This is done even if flow
  626. * control is disabled, because it does not hurt anything to
  627. * initialize these registers.
  628. */
  629. DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
  630. E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
  631. E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
  632. E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
  633. E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
  634. /* Set the flow control receive threshold registers. Normally,
  635. * these registers will be set to a default threshold that may be
  636. * adjusted later by the driver's runtime code. However, if the
  637. * ability to transmit pause frames in not enabled, then these
  638. * registers will be set to 0.
  639. */
  640. if(!(hw->fc & e1000_fc_tx_pause)) {
  641. E1000_WRITE_REG(hw, FCRTL, 0);
  642. E1000_WRITE_REG(hw, FCRTH, 0);
  643. } else {
  644. /* We need to set up the Receive Threshold high and low water marks
  645. * as well as (optionally) enabling the transmission of XON frames.
  646. */
  647. if(hw->fc_send_xon) {
  648. E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
  649. E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
  650. } else {
  651. E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
  652. E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
  653. }
  654. }
  655. return ret_val;
  656. }
  657. /******************************************************************************
  658. * Sets up link for a fiber based or serdes based adapter
  659. *
  660. * hw - Struct containing variables accessed by shared code
  661. *
  662. * Manipulates Physical Coding Sublayer functions in order to configure
  663. * link. Assumes the hardware has been previously reset and the transmitter
  664. * and receiver are not enabled.
  665. *****************************************************************************/
  666. static int32_t
  667. e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
  668. {
  669. uint32_t ctrl;
  670. uint32_t status;
  671. uint32_t txcw = 0;
  672. uint32_t i;
  673. uint32_t signal = 0;
  674. int32_t ret_val;
  675. DEBUGFUNC("e1000_setup_fiber_serdes_link");
  676. /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
  677. * set when the optics detect a signal. On older adapters, it will be
  678. * cleared when there is a signal. This applies to fiber media only.
  679. * If we're on serdes media, adjust the output amplitude to value set in
  680. * the EEPROM.
  681. */
  682. ctrl = E1000_READ_REG(hw, CTRL);
  683. if(hw->media_type == e1000_media_type_fiber)
  684. signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
  685. ret_val = e1000_adjust_serdes_amplitude(hw);
  686. if(ret_val)
  687. return ret_val;
  688. /* Take the link out of reset */
  689. ctrl &= ~(E1000_CTRL_LRST);
  690. /* Adjust VCO speed to improve BER performance */
  691. ret_val = e1000_set_vco_speed(hw);
  692. if(ret_val)
  693. return ret_val;
  694. e1000_config_collision_dist(hw);
  695. /* Check for a software override of the flow control settings, and setup
  696. * the device accordingly. If auto-negotiation is enabled, then software
  697. * will have to set the "PAUSE" bits to the correct value in the Tranmsit
  698. * Config Word Register (TXCW) and re-start auto-negotiation. However, if
  699. * auto-negotiation is disabled, then software will have to manually
  700. * configure the two flow control enable bits in the CTRL register.
  701. *
  702. * The possible values of the "fc" parameter are:
  703. * 0: Flow control is completely disabled
  704. * 1: Rx flow control is enabled (we can receive pause frames, but
  705. * not send pause frames).
  706. * 2: Tx flow control is enabled (we can send pause frames but we do
  707. * not support receiving pause frames).
  708. * 3: Both Rx and TX flow control (symmetric) are enabled.
  709. */
  710. switch (hw->fc) {
  711. case e1000_fc_none:
  712. /* Flow control is completely disabled by a software over-ride. */
  713. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
  714. break;
  715. case e1000_fc_rx_pause:
  716. /* RX Flow control is enabled and TX Flow control is disabled by a
  717. * software over-ride. Since there really isn't a way to advertise
  718. * that we are capable of RX Pause ONLY, we will advertise that we
  719. * support both symmetric and asymmetric RX PAUSE. Later, we will
  720. * disable the adapter's ability to send PAUSE frames.
  721. */
  722. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
  723. break;
  724. case e1000_fc_tx_pause:
  725. /* TX Flow control is enabled, and RX Flow control is disabled, by a
  726. * software over-ride.
  727. */
  728. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
  729. break;
  730. case e1000_fc_full:
  731. /* Flow control (both RX and TX) is enabled by a software over-ride. */
  732. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
  733. break;
  734. default:
  735. DEBUGOUT("Flow control param set incorrectly\n");
  736. return -E1000_ERR_CONFIG;
  737. break;
  738. }
  739. /* Since auto-negotiation is enabled, take the link out of reset (the link
  740. * will be in reset, because we previously reset the chip). This will
  741. * restart auto-negotiation. If auto-neogtiation is successful then the
  742. * link-up status bit will be set and the flow control enable bits (RFCE
  743. * and TFCE) will be set according to their negotiated value.
  744. */
  745. DEBUGOUT("Auto-negotiation enabled\n");
  746. E1000_WRITE_REG(hw, TXCW, txcw);
  747. E1000_WRITE_REG(hw, CTRL, ctrl);
  748. E1000_WRITE_FLUSH(hw);
  749. hw->txcw = txcw;
  750. msec_delay(1);
  751. /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
  752. * indication in the Device Status Register. Time-out if a link isn't
  753. * seen in 500 milliseconds seconds (Auto-negotiation should complete in
  754. * less than 500 milliseconds even if the other end is doing it in SW).
  755. * For internal serdes, we just assume a signal is present, then poll.
  756. */
  757. if(hw->media_type == e1000_media_type_internal_serdes ||
  758. (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
  759. DEBUGOUT("Looking for Link\n");
  760. for(i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
  761. msec_delay(10);
  762. status = E1000_READ_REG(hw, STATUS);
  763. if(status & E1000_STATUS_LU) break;
  764. }
  765. if(i == (LINK_UP_TIMEOUT / 10)) {
  766. DEBUGOUT("Never got a valid link from auto-neg!!!\n");
  767. hw->autoneg_failed = 1;
  768. /* AutoNeg failed to achieve a link, so we'll call
  769. * e1000_check_for_link. This routine will force the link up if
  770. * we detect a signal. This will allow us to communicate with
  771. * non-autonegotiating link partners.
  772. */
  773. ret_val = e1000_check_for_link(hw);
  774. if(ret_val) {
  775. DEBUGOUT("Error while checking for link\n");
  776. return ret_val;
  777. }
  778. hw->autoneg_failed = 0;
  779. } else {
  780. hw->autoneg_failed = 0;
  781. DEBUGOUT("Valid Link Found\n");
  782. }
  783. } else {
  784. DEBUGOUT("No Signal Detected\n");
  785. }
  786. return E1000_SUCCESS;
  787. }
  788. /******************************************************************************
  789. * Detects which PHY is present and the speed and duplex
  790. *
  791. * hw - Struct containing variables accessed by shared code
  792. ******************************************************************************/
  793. static int32_t
  794. e1000_setup_copper_link(struct e1000_hw *hw)
  795. {
  796. uint32_t ctrl;
  797. uint32_t led_ctrl;
  798. int32_t ret_val;
  799. uint16_t i;
  800. uint16_t phy_data;
  801. DEBUGFUNC("e1000_setup_copper_link");
  802. ctrl = E1000_READ_REG(hw, CTRL);
  803. /* With 82543, we need to force speed and duplex on the MAC equal to what
  804. * the PHY speed and duplex configuration is. In addition, we need to
  805. * perform a hardware reset on the PHY to take it out of reset.
  806. */
  807. if(hw->mac_type > e1000_82543) {
  808. ctrl |= E1000_CTRL_SLU;
  809. ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  810. E1000_WRITE_REG(hw, CTRL, ctrl);
  811. } else {
  812. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
  813. E1000_WRITE_REG(hw, CTRL, ctrl);
  814. e1000_phy_hw_reset(hw);
  815. }
  816. /* Make sure we have a valid PHY */
  817. ret_val = e1000_detect_gig_phy(hw);
  818. if(ret_val) {
  819. DEBUGOUT("Error, did not detect valid phy.\n");
  820. return ret_val;
  821. }
  822. DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
  823. /* Set PHY to class A mode (if necessary) */
  824. ret_val = e1000_set_phy_mode(hw);
  825. if(ret_val)
  826. return ret_val;
  827. if((hw->mac_type == e1000_82545_rev_3) ||
  828. (hw->mac_type == e1000_82546_rev_3)) {
  829. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  830. phy_data |= 0x00000008;
  831. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  832. }
  833. if(hw->mac_type <= e1000_82543 ||
  834. hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
  835. hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
  836. hw->phy_reset_disable = FALSE;
  837. if(!hw->phy_reset_disable) {
  838. if (hw->phy_type == e1000_phy_igp) {
  839. ret_val = e1000_phy_reset(hw);
  840. if(ret_val) {
  841. DEBUGOUT("Error Resetting the PHY\n");
  842. return ret_val;
  843. }
  844. /* Wait 10ms for MAC to configure PHY from eeprom settings */
  845. msec_delay(15);
  846. /* Configure activity LED after PHY reset */
  847. led_ctrl = E1000_READ_REG(hw, LEDCTL);
  848. led_ctrl &= IGP_ACTIVITY_LED_MASK;
  849. led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
  850. E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
  851. /* disable lplu d3 during driver init */
  852. ret_val = e1000_set_d3_lplu_state(hw, FALSE);
  853. if(ret_val) {
  854. DEBUGOUT("Error Disabling LPLU D3\n");
  855. return ret_val;
  856. }
  857. /* Configure mdi-mdix settings */
  858. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL,
  859. &phy_data);
  860. if(ret_val)
  861. return ret_val;
  862. if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
  863. hw->dsp_config_state = e1000_dsp_config_disabled;
  864. /* Force MDI for earlier revs of the IGP PHY */
  865. phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX |
  866. IGP01E1000_PSCR_FORCE_MDI_MDIX);
  867. hw->mdix = 1;
  868. } else {
  869. hw->dsp_config_state = e1000_dsp_config_enabled;
  870. phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
  871. switch (hw->mdix) {
  872. case 1:
  873. phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
  874. break;
  875. case 2:
  876. phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
  877. break;
  878. case 0:
  879. default:
  880. phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
  881. break;
  882. }
  883. }
  884. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL,
  885. phy_data);
  886. if(ret_val)
  887. return ret_val;
  888. /* set auto-master slave resolution settings */
  889. if(hw->autoneg) {
  890. e1000_ms_type phy_ms_setting = hw->master_slave;
  891. if(hw->ffe_config_state == e1000_ffe_config_active)
  892. hw->ffe_config_state = e1000_ffe_config_enabled;
  893. if(hw->dsp_config_state == e1000_dsp_config_activated)
  894. hw->dsp_config_state = e1000_dsp_config_enabled;
  895. /* when autonegotiation advertisment is only 1000Mbps then we
  896. * should disable SmartSpeed and enable Auto MasterSlave
  897. * resolution as hardware default. */
  898. if(hw->autoneg_advertised == ADVERTISE_1000_FULL) {
  899. /* Disable SmartSpeed */
  900. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  901. &phy_data);
  902. if(ret_val)
  903. return ret_val;
  904. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  905. ret_val = e1000_write_phy_reg(hw,
  906. IGP01E1000_PHY_PORT_CONFIG,
  907. phy_data);
  908. if(ret_val)
  909. return ret_val;
  910. /* Set auto Master/Slave resolution process */
  911. ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
  912. if(ret_val)
  913. return ret_val;
  914. phy_data &= ~CR_1000T_MS_ENABLE;
  915. ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
  916. if(ret_val)
  917. return ret_val;
  918. }
  919. ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
  920. if(ret_val)
  921. return ret_val;
  922. /* load defaults for future use */
  923. hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
  924. ((phy_data & CR_1000T_MS_VALUE) ?
  925. e1000_ms_force_master :
  926. e1000_ms_force_slave) :
  927. e1000_ms_auto;
  928. switch (phy_ms_setting) {
  929. case e1000_ms_force_master:
  930. phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
  931. break;
  932. case e1000_ms_force_slave:
  933. phy_data |= CR_1000T_MS_ENABLE;
  934. phy_data &= ~(CR_1000T_MS_VALUE);
  935. break;
  936. case e1000_ms_auto:
  937. phy_data &= ~CR_1000T_MS_ENABLE;
  938. default:
  939. break;
  940. }
  941. ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
  942. if(ret_val)
  943. return ret_val;
  944. }
  945. } else {
  946. /* Enable CRS on TX. This must be set for half-duplex operation. */
  947. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
  948. &phy_data);
  949. if(ret_val)
  950. return ret_val;
  951. phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  952. /* Options:
  953. * MDI/MDI-X = 0 (default)
  954. * 0 - Auto for all speeds
  955. * 1 - MDI mode
  956. * 2 - MDI-X mode
  957. * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
  958. */
  959. phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
  960. switch (hw->mdix) {
  961. case 1:
  962. phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
  963. break;
  964. case 2:
  965. phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
  966. break;
  967. case 3:
  968. phy_data |= M88E1000_PSCR_AUTO_X_1000T;
  969. break;
  970. case 0:
  971. default:
  972. phy_data |= M88E1000_PSCR_AUTO_X_MODE;
  973. break;
  974. }
  975. /* Options:
  976. * disable_polarity_correction = 0 (default)
  977. * Automatic Correction for Reversed Cable Polarity
  978. * 0 - Disabled
  979. * 1 - Enabled
  980. */
  981. phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
  982. if(hw->disable_polarity_correction == 1)
  983. phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
  984. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
  985. phy_data);
  986. if(ret_val)
  987. return ret_val;
  988. /* Force TX_CLK in the Extended PHY Specific Control Register
  989. * to 25MHz clock.
  990. */
  991. ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
  992. &phy_data);
  993. if(ret_val)
  994. return ret_val;
  995. phy_data |= M88E1000_EPSCR_TX_CLK_25;
  996. if (hw->phy_revision < M88E1011_I_REV_4) {
  997. /* Configure Master and Slave downshift values */
  998. phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
  999. M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
  1000. phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
  1001. M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
  1002. ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
  1003. phy_data);
  1004. if(ret_val)
  1005. return ret_val;
  1006. }
  1007. /* SW Reset the PHY so all changes take effect */
  1008. ret_val = e1000_phy_reset(hw);
  1009. if(ret_val) {
  1010. DEBUGOUT("Error Resetting the PHY\n");
  1011. return ret_val;
  1012. }
  1013. }
  1014. /* Options:
  1015. * autoneg = 1 (default)
  1016. * PHY will advertise value(s) parsed from
  1017. * autoneg_advertised and fc
  1018. * autoneg = 0
  1019. * PHY will be set to 10H, 10F, 100H, or 100F
  1020. * depending on value parsed from forced_speed_duplex.
  1021. */
  1022. /* Is autoneg enabled? This is enabled by default or by software
  1023. * override. If so, call e1000_phy_setup_autoneg routine to parse the
  1024. * autoneg_advertised and fc options. If autoneg is NOT enabled, then
  1025. * the user should have provided a speed/duplex override. If so, then
  1026. * call e1000_phy_force_speed_duplex to parse and set this up.
  1027. */
  1028. if(hw->autoneg) {
  1029. /* Perform some bounds checking on the hw->autoneg_advertised
  1030. * parameter. If this variable is zero, then set it to the default.
  1031. */
  1032. hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
  1033. /* If autoneg_advertised is zero, we assume it was not defaulted
  1034. * by the calling code so we set to advertise full capability.
  1035. */
  1036. if(hw->autoneg_advertised == 0)
  1037. hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  1038. DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
  1039. ret_val = e1000_phy_setup_autoneg(hw);
  1040. if(ret_val) {
  1041. DEBUGOUT("Error Setting up Auto-Negotiation\n");
  1042. return ret_val;
  1043. }
  1044. DEBUGOUT("Restarting Auto-Neg\n");
  1045. /* Restart auto-negotiation by setting the Auto Neg Enable bit and
  1046. * the Auto Neg Restart bit in the PHY control register.
  1047. */
  1048. ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
  1049. if(ret_val)
  1050. return ret_val;
  1051. phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
  1052. ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
  1053. if(ret_val)
  1054. return ret_val;
  1055. /* Does the user want to wait for Auto-Neg to complete here, or
  1056. * check at a later time (for example, callback routine).
  1057. */
  1058. if(hw->wait_autoneg_complete) {
  1059. ret_val = e1000_wait_autoneg(hw);
  1060. if(ret_val) {
  1061. DEBUGOUT("Error while waiting for autoneg to complete\n");
  1062. return ret_val;
  1063. }
  1064. }
  1065. hw->get_link_status = TRUE;
  1066. } else {
  1067. DEBUGOUT("Forcing speed and duplex\n");
  1068. ret_val = e1000_phy_force_speed_duplex(hw);
  1069. if(ret_val) {
  1070. DEBUGOUT("Error Forcing Speed and Duplex\n");
  1071. return ret_val;
  1072. }
  1073. }
  1074. } /* !hw->phy_reset_disable */
  1075. /* Check link status. Wait up to 100 microseconds for link to become
  1076. * valid.
  1077. */
  1078. for(i = 0; i < 10; i++) {
  1079. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  1080. if(ret_val)
  1081. return ret_val;
  1082. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  1083. if(ret_val)
  1084. return ret_val;
  1085. if(phy_data & MII_SR_LINK_STATUS) {
  1086. /* We have link, so we need to finish the config process:
  1087. * 1) Set up the MAC to the current PHY speed/duplex
  1088. * if we are on 82543. If we
  1089. * are on newer silicon, we only need to configure
  1090. * collision distance in the Transmit Control Register.
  1091. * 2) Set up flow control on the MAC to that established with
  1092. * the link partner.
  1093. */
  1094. if(hw->mac_type >= e1000_82544) {
  1095. e1000_config_collision_dist(hw);
  1096. } else {
  1097. ret_val = e1000_config_mac_to_phy(hw);
  1098. if(ret_val) {
  1099. DEBUGOUT("Error configuring MAC to PHY settings\n");
  1100. return ret_val;
  1101. }
  1102. }
  1103. ret_val = e1000_config_fc_after_link_up(hw);
  1104. if(ret_val) {
  1105. DEBUGOUT("Error Configuring Flow Control\n");
  1106. return ret_val;
  1107. }
  1108. DEBUGOUT("Valid link established!!!\n");
  1109. if(hw->phy_type == e1000_phy_igp) {
  1110. ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
  1111. if(ret_val) {
  1112. DEBUGOUT("Error Configuring DSP after link up\n");
  1113. return ret_val;
  1114. }
  1115. }
  1116. DEBUGOUT("Valid link established!!!\n");
  1117. return E1000_SUCCESS;
  1118. }
  1119. udelay(10);
  1120. }
  1121. DEBUGOUT("Unable to establish link!!!\n");
  1122. return E1000_SUCCESS;
  1123. }
  1124. /******************************************************************************
  1125. * Configures PHY autoneg and flow control advertisement settings
  1126. *
  1127. * hw - Struct containing variables accessed by shared code
  1128. ******************************************************************************/
  1129. int32_t
  1130. e1000_phy_setup_autoneg(struct e1000_hw *hw)
  1131. {
  1132. int32_t ret_val;
  1133. uint16_t mii_autoneg_adv_reg;
  1134. uint16_t mii_1000t_ctrl_reg;
  1135. DEBUGFUNC("e1000_phy_setup_autoneg");
  1136. /* Read the MII Auto-Neg Advertisement Register (Address 4). */
  1137. ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
  1138. if(ret_val)
  1139. return ret_val;
  1140. /* Read the MII 1000Base-T Control Register (Address 9). */
  1141. ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
  1142. if(ret_val)
  1143. return ret_val;
  1144. /* Need to parse both autoneg_advertised and fc and set up
  1145. * the appropriate PHY registers. First we will parse for
  1146. * autoneg_advertised software override. Since we can advertise
  1147. * a plethora of combinations, we need to check each bit
  1148. * individually.
  1149. */
  1150. /* First we clear all the 10/100 mb speed bits in the Auto-Neg
  1151. * Advertisement Register (Address 4) and the 1000 mb speed bits in
  1152. * the 1000Base-T Control Register (Address 9).
  1153. */
  1154. mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
  1155. mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
  1156. DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
  1157. /* Do we want to advertise 10 Mb Half Duplex? */
  1158. if(hw->autoneg_advertised & ADVERTISE_10_HALF) {
  1159. DEBUGOUT("Advertise 10mb Half duplex\n");
  1160. mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
  1161. }
  1162. /* Do we want to advertise 10 Mb Full Duplex? */
  1163. if(hw->autoneg_advertised & ADVERTISE_10_FULL) {
  1164. DEBUGOUT("Advertise 10mb Full duplex\n");
  1165. mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
  1166. }
  1167. /* Do we want to advertise 100 Mb Half Duplex? */
  1168. if(hw->autoneg_advertised & ADVERTISE_100_HALF) {
  1169. DEBUGOUT("Advertise 100mb Half duplex\n");
  1170. mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
  1171. }
  1172. /* Do we want to advertise 100 Mb Full Duplex? */
  1173. if(hw->autoneg_advertised & ADVERTISE_100_FULL) {
  1174. DEBUGOUT("Advertise 100mb Full duplex\n");
  1175. mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
  1176. }
  1177. /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
  1178. if(hw->autoneg_advertised & ADVERTISE_1000_HALF) {
  1179. DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
  1180. }
  1181. /* Do we want to advertise 1000 Mb Full Duplex? */
  1182. if(hw->autoneg_advertised & ADVERTISE_1000_FULL) {
  1183. DEBUGOUT("Advertise 1000mb Full duplex\n");
  1184. mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
  1185. }
  1186. /* Check for a software override of the flow control settings, and
  1187. * setup the PHY advertisement registers accordingly. If
  1188. * auto-negotiation is enabled, then software will have to set the
  1189. * "PAUSE" bits to the correct value in the Auto-Negotiation
  1190. * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
  1191. *
  1192. * The possible values of the "fc" parameter are:
  1193. * 0: Flow control is completely disabled
  1194. * 1: Rx flow control is enabled (we can receive pause frames
  1195. * but not send pause frames).
  1196. * 2: Tx flow control is enabled (we can send pause frames
  1197. * but we do not support receiving pause frames).
  1198. * 3: Both Rx and TX flow control (symmetric) are enabled.
  1199. * other: No software override. The flow control configuration
  1200. * in the EEPROM is used.
  1201. */
  1202. switch (hw->fc) {
  1203. case e1000_fc_none: /* 0 */
  1204. /* Flow control (RX & TX) is completely disabled by a
  1205. * software over-ride.
  1206. */
  1207. mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  1208. break;
  1209. case e1000_fc_rx_pause: /* 1 */
  1210. /* RX Flow control is enabled, and TX Flow control is
  1211. * disabled, by a software over-ride.
  1212. */
  1213. /* Since there really isn't a way to advertise that we are
  1214. * capable of RX Pause ONLY, we will advertise that we
  1215. * support both symmetric and asymmetric RX PAUSE. Later
  1216. * (in e1000_config_fc_after_link_up) we will disable the
  1217. *hw's ability to send PAUSE frames.
  1218. */
  1219. mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  1220. break;
  1221. case e1000_fc_tx_pause: /* 2 */
  1222. /* TX Flow control is enabled, and RX Flow control is
  1223. * disabled, by a software over-ride.
  1224. */
  1225. mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
  1226. mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
  1227. break;
  1228. case e1000_fc_full: /* 3 */
  1229. /* Flow control (both RX and TX) is enabled by a software
  1230. * over-ride.
  1231. */
  1232. mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  1233. break;
  1234. default:
  1235. DEBUGOUT("Flow control param set incorrectly\n");
  1236. return -E1000_ERR_CONFIG;
  1237. }
  1238. ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
  1239. if(ret_val)
  1240. return ret_val;
  1241. DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
  1242. ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
  1243. if(ret_val)
  1244. return ret_val;
  1245. return E1000_SUCCESS;
  1246. }
  1247. /******************************************************************************
  1248. * Force PHY speed and duplex settings to hw->forced_speed_duplex
  1249. *
  1250. * hw - Struct containing variables accessed by shared code
  1251. ******************************************************************************/
  1252. static int32_t
  1253. e1000_phy_force_speed_duplex(struct e1000_hw *hw)
  1254. {
  1255. uint32_t ctrl;
  1256. int32_t ret_val;
  1257. uint16_t mii_ctrl_reg;
  1258. uint16_t mii_status_reg;
  1259. uint16_t phy_data;
  1260. uint16_t i;
  1261. DEBUGFUNC("e1000_phy_force_speed_duplex");
  1262. /* Turn off Flow control if we are forcing speed and duplex. */
  1263. hw->fc = e1000_fc_none;
  1264. DEBUGOUT1("hw->fc = %d\n", hw->fc);
  1265. /* Read the Device Control Register. */
  1266. ctrl = E1000_READ_REG(hw, CTRL);
  1267. /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
  1268. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  1269. ctrl &= ~(DEVICE_SPEED_MASK);
  1270. /* Clear the Auto Speed Detect Enable bit. */
  1271. ctrl &= ~E1000_CTRL_ASDE;
  1272. /* Read the MII Control Register. */
  1273. ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
  1274. if(ret_val)
  1275. return ret_val;
  1276. /* We need to disable autoneg in order to force link and duplex. */
  1277. mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
  1278. /* Are we forcing Full or Half Duplex? */
  1279. if(hw->forced_speed_duplex == e1000_100_full ||
  1280. hw->forced_speed_duplex == e1000_10_full) {
  1281. /* We want to force full duplex so we SET the full duplex bits in the
  1282. * Device and MII Control Registers.
  1283. */
  1284. ctrl |= E1000_CTRL_FD;
  1285. mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
  1286. DEBUGOUT("Full Duplex\n");
  1287. } else {
  1288. /* We want to force half duplex so we CLEAR the full duplex bits in
  1289. * the Device and MII Control Registers.
  1290. */
  1291. ctrl &= ~E1000_CTRL_FD;
  1292. mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
  1293. DEBUGOUT("Half Duplex\n");
  1294. }
  1295. /* Are we forcing 100Mbps??? */
  1296. if(hw->forced_speed_duplex == e1000_100_full ||
  1297. hw->forced_speed_duplex == e1000_100_half) {
  1298. /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
  1299. ctrl |= E1000_CTRL_SPD_100;
  1300. mii_ctrl_reg |= MII_CR_SPEED_100;
  1301. mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
  1302. DEBUGOUT("Forcing 100mb ");
  1303. } else {
  1304. /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
  1305. ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
  1306. mii_ctrl_reg |= MII_CR_SPEED_10;
  1307. mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
  1308. DEBUGOUT("Forcing 10mb ");
  1309. }
  1310. e1000_config_collision_dist(hw);
  1311. /* Write the configured values back to the Device Control Reg. */
  1312. E1000_WRITE_REG(hw, CTRL, ctrl);
  1313. if (hw->phy_type == e1000_phy_m88) {
  1314. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  1315. if(ret_val)
  1316. return ret_val;
  1317. /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
  1318. * forced whenever speed are duplex are forced.
  1319. */
  1320. phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
  1321. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  1322. if(ret_val)
  1323. return ret_val;
  1324. DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
  1325. /* Need to reset the PHY or these changes will be ignored */
  1326. mii_ctrl_reg |= MII_CR_RESET;
  1327. } else {
  1328. /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
  1329. * forced whenever speed or duplex are forced.
  1330. */
  1331. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
  1332. if(ret_val)
  1333. return ret_val;
  1334. phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
  1335. phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
  1336. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
  1337. if(ret_val)
  1338. return ret_val;
  1339. }
  1340. /* Write back the modified PHY MII control register. */
  1341. ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
  1342. if(ret_val)
  1343. return ret_val;
  1344. udelay(1);
  1345. /* The wait_autoneg_complete flag may be a little misleading here.
  1346. * Since we are forcing speed and duplex, Auto-Neg is not enabled.
  1347. * But we do want to delay for a period while forcing only so we
  1348. * don't generate false No Link messages. So we will wait here
  1349. * only if the user has set wait_autoneg_complete to 1, which is
  1350. * the default.
  1351. */
  1352. if(hw->wait_autoneg_complete) {
  1353. /* We will wait for autoneg to complete. */
  1354. DEBUGOUT("Waiting for forced speed/duplex link.\n");
  1355. mii_status_reg = 0;
  1356. /* We will wait for autoneg to complete or 4.5 seconds to expire. */
  1357. for(i = PHY_FORCE_TIME; i > 0; i--) {
  1358. /* Read the MII Status Register and wait for Auto-Neg Complete bit
  1359. * to be set.
  1360. */
  1361. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  1362. if(ret_val)
  1363. return ret_val;
  1364. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  1365. if(ret_val)
  1366. return ret_val;
  1367. if(mii_status_reg & MII_SR_LINK_STATUS) break;
  1368. msec_delay(100);
  1369. }
  1370. if((i == 0) &&
  1371. (hw->phy_type == e1000_phy_m88)) {
  1372. /* We didn't get link. Reset the DSP and wait again for link. */
  1373. ret_val = e1000_phy_reset_dsp(hw);
  1374. if(ret_val) {
  1375. DEBUGOUT("Error Resetting PHY DSP\n");
  1376. return ret_val;
  1377. }
  1378. }
  1379. /* This loop will early-out if the link condition has been met. */
  1380. for(i = PHY_FORCE_TIME; i > 0; i--) {
  1381. if(mii_status_reg & MII_SR_LINK_STATUS) break;
  1382. msec_delay(100);
  1383. /* Read the MII Status Register and wait for Auto-Neg Complete bit
  1384. * to be set.
  1385. */
  1386. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  1387. if(ret_val)
  1388. return ret_val;
  1389. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  1390. if(ret_val)
  1391. return ret_val;
  1392. }
  1393. }
  1394. if (hw->phy_type == e1000_phy_m88) {
  1395. /* Because we reset the PHY above, we need to re-force TX_CLK in the
  1396. * Extended PHY Specific Control Register to 25MHz clock. This value
  1397. * defaults back to a 2.5MHz clock when the PHY is reset.
  1398. */
  1399. ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
  1400. if(ret_val)
  1401. return ret_val;
  1402. phy_data |= M88E1000_EPSCR_TX_CLK_25;
  1403. ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
  1404. if(ret_val)
  1405. return ret_val;
  1406. /* In addition, because of the s/w reset above, we need to enable CRS on
  1407. * TX. This must be set for both full and half duplex operation.
  1408. */
  1409. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  1410. if(ret_val)
  1411. return ret_val;
  1412. phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  1413. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  1414. if(ret_val)
  1415. return ret_val;
  1416. if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
  1417. (!hw->autoneg) &&
  1418. (hw->forced_speed_duplex == e1000_10_full ||
  1419. hw->forced_speed_duplex == e1000_10_half)) {
  1420. ret_val = e1000_polarity_reversal_workaround(hw);
  1421. if(ret_val)
  1422. return ret_val;
  1423. }
  1424. }
  1425. return E1000_SUCCESS;
  1426. }
  1427. /******************************************************************************
  1428. * Sets the collision distance in the Transmit Control register
  1429. *
  1430. * hw - Struct containing variables accessed by shared code
  1431. *
  1432. * Link should have been established previously. Reads the speed and duplex
  1433. * information from the Device Status register.
  1434. ******************************************************************************/
  1435. void
  1436. e1000_config_collision_dist(struct e1000_hw *hw)
  1437. {
  1438. uint32_t tctl;
  1439. DEBUGFUNC("e1000_config_collision_dist");
  1440. tctl = E1000_READ_REG(hw, TCTL);
  1441. tctl &= ~E1000_TCTL_COLD;
  1442. tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
  1443. E1000_WRITE_REG(hw, TCTL, tctl);
  1444. E1000_WRITE_FLUSH(hw);
  1445. }
  1446. /******************************************************************************
  1447. * Sets MAC speed and duplex settings to reflect the those in the PHY
  1448. *
  1449. * hw - Struct containing variables accessed by shared code
  1450. * mii_reg - data to write to the MII control register
  1451. *
  1452. * The contents of the PHY register containing the needed information need to
  1453. * be passed in.
  1454. ******************************************************************************/
  1455. static int32_t
  1456. e1000_config_mac_to_phy(struct e1000_hw *hw)
  1457. {
  1458. uint32_t ctrl;
  1459. int32_t ret_val;
  1460. uint16_t phy_data;
  1461. DEBUGFUNC("e1000_config_mac_to_phy");
  1462. /* Read the Device Control Register and set the bits to Force Speed
  1463. * and Duplex.
  1464. */
  1465. ctrl = E1000_READ_REG(hw, CTRL);
  1466. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  1467. ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
  1468. /* Set up duplex in the Device Control and Transmit Control
  1469. * registers depending on negotiated values.
  1470. */
  1471. if (hw->phy_type == e1000_phy_igp) {
  1472. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
  1473. &phy_data);
  1474. if(ret_val)
  1475. return ret_val;
  1476. if(phy_data & IGP01E1000_PSSR_FULL_DUPLEX) ctrl |= E1000_CTRL_FD;
  1477. else ctrl &= ~E1000_CTRL_FD;
  1478. e1000_config_collision_dist(hw);
  1479. /* Set up speed in the Device Control register depending on
  1480. * negotiated values.
  1481. */
  1482. if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
  1483. IGP01E1000_PSSR_SPEED_1000MBPS)
  1484. ctrl |= E1000_CTRL_SPD_1000;
  1485. else if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
  1486. IGP01E1000_PSSR_SPEED_100MBPS)
  1487. ctrl |= E1000_CTRL_SPD_100;
  1488. } else {
  1489. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
  1490. &phy_data);
  1491. if(ret_val)
  1492. return ret_val;
  1493. if(phy_data & M88E1000_PSSR_DPLX) ctrl |= E1000_CTRL_FD;
  1494. else ctrl &= ~E1000_CTRL_FD;
  1495. e1000_config_collision_dist(hw);
  1496. /* Set up speed in the Device Control register depending on
  1497. * negotiated values.
  1498. */
  1499. if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
  1500. ctrl |= E1000_CTRL_SPD_1000;
  1501. else if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
  1502. ctrl |= E1000_CTRL_SPD_100;
  1503. }
  1504. /* Write the configured values back to the Device Control Reg. */
  1505. E1000_WRITE_REG(hw, CTRL, ctrl);
  1506. return E1000_SUCCESS;
  1507. }
  1508. /******************************************************************************
  1509. * Forces the MAC's flow control settings.
  1510. *
  1511. * hw - Struct containing variables accessed by shared code
  1512. *
  1513. * Sets the TFCE and RFCE bits in the device control register to reflect
  1514. * the adapter settings. TFCE and RFCE need to be explicitly set by
  1515. * software when a Copper PHY is used because autonegotiation is managed
  1516. * by the PHY rather than the MAC. Software must also configure these
  1517. * bits when link is forced on a fiber connection.
  1518. *****************************************************************************/
  1519. int32_t
  1520. e1000_force_mac_fc(struct e1000_hw *hw)
  1521. {
  1522. uint32_t ctrl;
  1523. DEBUGFUNC("e1000_force_mac_fc");
  1524. /* Get the current configuration of the Device Control Register */
  1525. ctrl = E1000_READ_REG(hw, CTRL);
  1526. /* Because we didn't get link via the internal auto-negotiation
  1527. * mechanism (we either forced link or we got link via PHY
  1528. * auto-neg), we have to manually enable/disable transmit an
  1529. * receive flow control.
  1530. *
  1531. * The "Case" statement below enables/disable flow control
  1532. * according to the "hw->fc" parameter.
  1533. *
  1534. * The possible values of the "fc" parameter are:
  1535. * 0: Flow control is completely disabled
  1536. * 1: Rx flow control is enabled (we can receive pause
  1537. * frames but not send pause frames).
  1538. * 2: Tx flow control is enabled (we can send pause frames
  1539. * frames but we do not receive pause frames).
  1540. * 3: Both Rx and TX flow control (symmetric) is enabled.
  1541. * other: No other values should be possible at this point.
  1542. */
  1543. switch (hw->fc) {
  1544. case e1000_fc_none:
  1545. ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
  1546. break;
  1547. case e1000_fc_rx_pause:
  1548. ctrl &= (~E1000_CTRL_TFCE);
  1549. ctrl |= E1000_CTRL_RFCE;
  1550. break;
  1551. case e1000_fc_tx_pause:
  1552. ctrl &= (~E1000_CTRL_RFCE);
  1553. ctrl |= E1000_CTRL_TFCE;
  1554. break;
  1555. case e1000_fc_full:
  1556. ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
  1557. break;
  1558. default:
  1559. DEBUGOUT("Flow control param set incorrectly\n");
  1560. return -E1000_ERR_CONFIG;
  1561. }
  1562. /* Disable TX Flow Control for 82542 (rev 2.0) */
  1563. if(hw->mac_type == e1000_82542_rev2_0)
  1564. ctrl &= (~E1000_CTRL_TFCE);
  1565. E1000_WRITE_REG(hw, CTRL, ctrl);
  1566. return E1000_SUCCESS;
  1567. }
  1568. /******************************************************************************
  1569. * Configures flow control settings after link is established
  1570. *
  1571. * hw - Struct containing variables accessed by shared code
  1572. *
  1573. * Should be called immediately after a valid link has been established.
  1574. * Forces MAC flow control settings if link was forced. When in MII/GMII mode
  1575. * and autonegotiation is enabled, the MAC flow control settings will be set
  1576. * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
  1577. * and RFCE bits will be automaticaly set to the negotiated flow control mode.
  1578. *****************************************************************************/
  1579. int32_t
  1580. e1000_config_fc_after_link_up(struct e1000_hw *hw)
  1581. {
  1582. int32_t ret_val;
  1583. uint16_t mii_status_reg;
  1584. uint16_t mii_nway_adv_reg;
  1585. uint16_t mii_nway_lp_ability_reg;
  1586. uint16_t speed;
  1587. uint16_t duplex;
  1588. DEBUGFUNC("e1000_config_fc_after_link_up");
  1589. /* Check for the case where we have fiber media and auto-neg failed
  1590. * so we had to force link. In this case, we need to force the
  1591. * configuration of the MAC to match the "fc" parameter.
  1592. */
  1593. if(((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
  1594. ((hw->media_type == e1000_media_type_internal_serdes) && (hw->autoneg_failed)) ||
  1595. ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
  1596. ret_val = e1000_force_mac_fc(hw);
  1597. if(ret_val) {
  1598. DEBUGOUT("Error forcing flow control settings\n");
  1599. return ret_val;
  1600. }
  1601. }
  1602. /* Check for the case where we have copper media and auto-neg is
  1603. * enabled. In this case, we need to check and see if Auto-Neg
  1604. * has completed, and if so, how the PHY and link partner has
  1605. * flow control configured.
  1606. */
  1607. if((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
  1608. /* Read the MII Status Register and check to see if AutoNeg
  1609. * has completed. We read this twice because this reg has
  1610. * some "sticky" (latched) bits.
  1611. */
  1612. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  1613. if(ret_val)
  1614. return ret_val;
  1615. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  1616. if(ret_val)
  1617. return ret_val;
  1618. if(mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
  1619. /* The AutoNeg process has completed, so we now need to
  1620. * read both the Auto Negotiation Advertisement Register
  1621. * (Address 4) and the Auto_Negotiation Base Page Ability
  1622. * Register (Address 5) to determine how flow control was
  1623. * negotiated.
  1624. */
  1625. ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
  1626. &mii_nway_adv_reg);
  1627. if(ret_val)
  1628. return ret_val;
  1629. ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
  1630. &mii_nway_lp_ability_reg);
  1631. if(ret_val)
  1632. return ret_val;
  1633. /* Two bits in the Auto Negotiation Advertisement Register
  1634. * (Address 4) and two bits in the Auto Negotiation Base
  1635. * Page Ability Register (Address 5) determine flow control
  1636. * for both the PHY and the link partner. The following
  1637. * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
  1638. * 1999, describes these PAUSE resolution bits and how flow
  1639. * control is determined based upon these settings.
  1640. * NOTE: DC = Don't Care
  1641. *
  1642. * LOCAL DEVICE | LINK PARTNER
  1643. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
  1644. *-------|---------|-------|---------|--------------------
  1645. * 0 | 0 | DC | DC | e1000_fc_none
  1646. * 0 | 1 | 0 | DC | e1000_fc_none
  1647. * 0 | 1 | 1 | 0 | e1000_fc_none
  1648. * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
  1649. * 1 | 0 | 0 | DC | e1000_fc_none
  1650. * 1 | DC | 1 | DC | e1000_fc_full
  1651. * 1 | 1 | 0 | 0 | e1000_fc_none
  1652. * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
  1653. *
  1654. */
  1655. /* Are both PAUSE bits set to 1? If so, this implies
  1656. * Symmetric Flow Control is enabled at both ends. The
  1657. * ASM_DIR bits are irrelevant per the spec.
  1658. *
  1659. * For Symmetric Flow Control:
  1660. *
  1661. * LOCAL DEVICE | LINK PARTNER
  1662. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  1663. *-------|---------|-------|---------|--------------------
  1664. * 1 | DC | 1 | DC | e1000_fc_full
  1665. *
  1666. */
  1667. if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  1668. (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
  1669. /* Now we need to check if the user selected RX ONLY
  1670. * of pause frames. In this case, we had to advertise
  1671. * FULL flow control because we could not advertise RX
  1672. * ONLY. Hence, we must now check to see if we need to
  1673. * turn OFF the TRANSMISSION of PAUSE frames.
  1674. */
  1675. if(hw->original_fc == e1000_fc_full) {
  1676. hw->fc = e1000_fc_full;
  1677. DEBUGOUT("Flow Control = FULL.\r\n");
  1678. } else {
  1679. hw->fc = e1000_fc_rx_pause;
  1680. DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
  1681. }
  1682. }
  1683. /* For receiving PAUSE frames ONLY.
  1684. *
  1685. * LOCAL DEVICE | LINK PARTNER
  1686. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  1687. *-------|---------|-------|---------|--------------------
  1688. * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
  1689. *
  1690. */
  1691. else if(!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  1692. (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
  1693. (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
  1694. (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
  1695. hw->fc = e1000_fc_tx_pause;
  1696. DEBUGOUT("Flow Control = TX PAUSE frames only.\r\n");
  1697. }
  1698. /* For transmitting PAUSE frames ONLY.
  1699. *
  1700. * LOCAL DEVICE | LINK PARTNER
  1701. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  1702. *-------|---------|-------|---------|--------------------
  1703. * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
  1704. *
  1705. */
  1706. else if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  1707. (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
  1708. !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
  1709. (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
  1710. hw->fc = e1000_fc_rx_pause;
  1711. DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
  1712. }
  1713. /* Per the IEEE spec, at this point flow control should be
  1714. * disabled. However, we want to consider that we could
  1715. * be connected to a legacy switch that doesn't advertise
  1716. * desired flow control, but can be forced on the link
  1717. * partner. So if we advertised no flow control, that is
  1718. * what we will resolve to. If we advertised some kind of
  1719. * receive capability (Rx Pause Only or Full Flow Control)
  1720. * and the link partner advertised none, we will configure
  1721. * ourselves to enable Rx Flow Control only. We can do
  1722. * this safely for two reasons: If the link partner really
  1723. * didn't want flow control enabled, and we enable Rx, no
  1724. * harm done since we won't be receiving any PAUSE frames
  1725. * anyway. If the intent on the link partner was to have
  1726. * flow control enabled, then by us enabling RX only, we
  1727. * can at least receive pause frames and process them.
  1728. * This is a good idea because in most cases, since we are
  1729. * predominantly a server NIC, more times than not we will
  1730. * be asked to delay transmission of packets than asking
  1731. * our link partner to pause transmission of frames.
  1732. */
  1733. else if((hw->original_fc == e1000_fc_none ||
  1734. hw->original_fc == e1000_fc_tx_pause) ||
  1735. hw->fc_strict_ieee) {
  1736. hw->fc = e1000_fc_none;
  1737. DEBUGOUT("Flow Control = NONE.\r\n");
  1738. } else {
  1739. hw->fc = e1000_fc_rx_pause;
  1740. DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
  1741. }
  1742. /* Now we need to do one last check... If we auto-
  1743. * negotiated to HALF DUPLEX, flow control should not be
  1744. * enabled per IEEE 802.3 spec.
  1745. */
  1746. ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
  1747. if(ret_val) {
  1748. DEBUGOUT("Error getting link speed and duplex\n");
  1749. return ret_val;
  1750. }
  1751. if(duplex == HALF_DUPLEX)
  1752. hw->fc = e1000_fc_none;
  1753. /* Now we call a subroutine to actually force the MAC
  1754. * controller to use the correct flow control settings.
  1755. */
  1756. ret_val = e1000_force_mac_fc(hw);
  1757. if(ret_val) {
  1758. DEBUGOUT("Error forcing flow control settings\n");
  1759. return ret_val;
  1760. }
  1761. } else {
  1762. DEBUGOUT("Copper PHY and Auto Neg has not completed.\r\n");
  1763. }
  1764. }
  1765. return E1000_SUCCESS;
  1766. }
  1767. /******************************************************************************
  1768. * Checks to see if the link status of the hardware has changed.
  1769. *
  1770. * hw - Struct containing variables accessed by shared code
  1771. *
  1772. * Called by any function that needs to check the link status of the adapter.
  1773. *****************************************************************************/
  1774. int32_t
  1775. e1000_check_for_link(struct e1000_hw *hw)
  1776. {
  1777. uint32_t rxcw = 0;
  1778. uint32_t ctrl;
  1779. uint32_t status;
  1780. uint32_t rctl;
  1781. uint32_t icr;
  1782. uint32_t signal = 0;
  1783. int32_t ret_val;
  1784. uint16_t phy_data;
  1785. DEBUGFUNC("e1000_check_for_link");
  1786. ctrl = E1000_READ_REG(hw, CTRL);
  1787. status = E1000_READ_REG(hw, STATUS);
  1788. /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
  1789. * set when the optics detect a signal. On older adapters, it will be
  1790. * cleared when there is a signal. This applies to fiber media only.
  1791. */
  1792. if((hw->media_type == e1000_media_type_fiber) ||
  1793. (hw->media_type == e1000_media_type_internal_serdes)) {
  1794. rxcw = E1000_READ_REG(hw, RXCW);
  1795. if(hw->media_type == e1000_media_type_fiber) {
  1796. signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
  1797. if(status & E1000_STATUS_LU)
  1798. hw->get_link_status = FALSE;
  1799. }
  1800. }
  1801. /* If we have a copper PHY then we only want to go out to the PHY
  1802. * registers to see if Auto-Neg has completed and/or if our link
  1803. * status has changed. The get_link_status flag will be set if we
  1804. * receive a Link Status Change interrupt or we have Rx Sequence
  1805. * Errors.
  1806. */
  1807. if((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
  1808. /* First we want to see if the MII Status Register reports
  1809. * link. If so, then we want to get the current speed/duplex
  1810. * of the PHY.
  1811. * Read the register twice since the link bit is sticky.
  1812. */
  1813. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  1814. if(ret_val)
  1815. return ret_val;
  1816. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  1817. if(ret_val)
  1818. return ret_val;
  1819. if(phy_data & MII_SR_LINK_STATUS) {
  1820. hw->get_link_status = FALSE;
  1821. /* Check if there was DownShift, must be checked immediately after
  1822. * link-up */
  1823. e1000_check_downshift(hw);
  1824. /* If we are on 82544 or 82543 silicon and speed/duplex
  1825. * are forced to 10H or 10F, then we will implement the polarity
  1826. * reversal workaround. We disable interrupts first, and upon
  1827. * returning, place the devices interrupt state to its previous
  1828. * value except for the link status change interrupt which will
  1829. * happen due to the execution of this workaround.
  1830. */
  1831. if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
  1832. (!hw->autoneg) &&
  1833. (hw->forced_speed_duplex == e1000_10_full ||
  1834. hw->forced_speed_duplex == e1000_10_half)) {
  1835. E1000_WRITE_REG(hw, IMC, 0xffffffff);
  1836. ret_val = e1000_polarity_reversal_workaround(hw);
  1837. icr = E1000_READ_REG(hw, ICR);
  1838. E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
  1839. E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
  1840. }
  1841. } else {
  1842. /* No link detected */
  1843. e1000_config_dsp_after_link_change(hw, FALSE);
  1844. return 0;
  1845. }
  1846. /* If we are forcing speed/duplex, then we simply return since
  1847. * we have already determined whether we have link or not.
  1848. */
  1849. if(!hw->autoneg) return -E1000_ERR_CONFIG;
  1850. /* optimize the dsp settings for the igp phy */
  1851. e1000_config_dsp_after_link_change(hw, TRUE);
  1852. /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
  1853. * have Si on board that is 82544 or newer, Auto
  1854. * Speed Detection takes care of MAC speed/duplex
  1855. * configuration. So we only need to configure Collision
  1856. * Distance in the MAC. Otherwise, we need to force
  1857. * speed/duplex on the MAC to the current PHY speed/duplex
  1858. * settings.
  1859. */
  1860. if(hw->mac_type >= e1000_82544)
  1861. e1000_config_collision_dist(hw);
  1862. else {
  1863. ret_val = e1000_config_mac_to_phy(hw);
  1864. if(ret_val) {
  1865. DEBUGOUT("Error configuring MAC to PHY settings\n");
  1866. return ret_val;
  1867. }
  1868. }
  1869. /* Configure Flow Control now that Auto-Neg has completed. First, we
  1870. * need to restore the desired flow control settings because we may
  1871. * have had to re-autoneg with a different link partner.
  1872. */
  1873. ret_val = e1000_config_fc_after_link_up(hw);
  1874. if(ret_val) {
  1875. DEBUGOUT("Error configuring flow control\n");
  1876. return ret_val;
  1877. }
  1878. /* At this point we know that we are on copper and we have
  1879. * auto-negotiated link. These are conditions for checking the link
  1880. * partner capability register. We use the link speed to determine if
  1881. * TBI compatibility needs to be turned on or off. If the link is not
  1882. * at gigabit speed, then TBI compatibility is not needed. If we are
  1883. * at gigabit speed, we turn on TBI compatibility.
  1884. */
  1885. if(hw->tbi_compatibility_en) {
  1886. uint16_t speed, duplex;
  1887. e1000_get_speed_and_duplex(hw, &speed, &duplex);
  1888. if(speed != SPEED_1000) {
  1889. /* If link speed is not set to gigabit speed, we do not need
  1890. * to enable TBI compatibility.
  1891. */
  1892. if(hw->tbi_compatibility_on) {
  1893. /* If we previously were in the mode, turn it off. */
  1894. rctl = E1000_READ_REG(hw, RCTL);
  1895. rctl &= ~E1000_RCTL_SBP;
  1896. E1000_WRITE_REG(hw, RCTL, rctl);
  1897. hw->tbi_compatibility_on = FALSE;
  1898. }
  1899. } else {
  1900. /* If TBI compatibility is was previously off, turn it on. For
  1901. * compatibility with a TBI link partner, we will store bad
  1902. * packets. Some frames have an additional byte on the end and
  1903. * will look like CRC errors to to the hardware.
  1904. */
  1905. if(!hw->tbi_compatibility_on) {
  1906. hw->tbi_compatibility_on = TRUE;
  1907. rctl = E1000_READ_REG(hw, RCTL);
  1908. rctl |= E1000_RCTL_SBP;
  1909. E1000_WRITE_REG(hw, RCTL, rctl);
  1910. }
  1911. }
  1912. }
  1913. }
  1914. /* If we don't have link (auto-negotiation failed or link partner cannot
  1915. * auto-negotiate), the cable is plugged in (we have signal), and our
  1916. * link partner is not trying to auto-negotiate with us (we are receiving
  1917. * idles or data), we need to force link up. We also need to give
  1918. * auto-negotiation time to complete, in case the cable was just plugged
  1919. * in. The autoneg_failed flag does this.
  1920. */
  1921. else if((((hw->media_type == e1000_media_type_fiber) &&
  1922. ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
  1923. (hw->media_type == e1000_media_type_internal_serdes)) &&
  1924. (!(status & E1000_STATUS_LU)) &&
  1925. (!(rxcw & E1000_RXCW_C))) {
  1926. if(hw->autoneg_failed == 0) {
  1927. hw->autoneg_failed = 1;
  1928. return 0;
  1929. }
  1930. DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
  1931. /* Disable auto-negotiation in the TXCW register */
  1932. E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
  1933. /* Force link-up and also force full-duplex. */
  1934. ctrl = E1000_READ_REG(hw, CTRL);
  1935. ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
  1936. E1000_WRITE_REG(hw, CTRL, ctrl);
  1937. /* Configure Flow Control after forcing link up. */
  1938. ret_val = e1000_config_fc_after_link_up(hw);
  1939. if(ret_val) {
  1940. DEBUGOUT("Error configuring flow control\n");
  1941. return ret_val;
  1942. }
  1943. }
  1944. /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
  1945. * auto-negotiation in the TXCW register and disable forced link in the
  1946. * Device Control register in an attempt to auto-negotiate with our link
  1947. * partner.
  1948. */
  1949. else if(((hw->media_type == e1000_media_type_fiber) ||
  1950. (hw->media_type == e1000_media_type_internal_serdes)) &&
  1951. (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
  1952. DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
  1953. E1000_WRITE_REG(hw, TXCW, hw->txcw);
  1954. E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
  1955. hw->serdes_link_down = FALSE;
  1956. }
  1957. /* If we force link for non-auto-negotiation switch, check link status
  1958. * based on MAC synchronization for internal serdes media type.
  1959. */
  1960. else if((hw->media_type == e1000_media_type_internal_serdes) &&
  1961. !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
  1962. /* SYNCH bit and IV bit are sticky. */
  1963. udelay(10);
  1964. if(E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
  1965. if(!(rxcw & E1000_RXCW_IV)) {
  1966. hw->serdes_link_down = FALSE;
  1967. DEBUGOUT("SERDES: Link is up.\n");
  1968. }
  1969. } else {
  1970. hw->serdes_link_down = TRUE;
  1971. DEBUGOUT("SERDES: Link is down.\n");
  1972. }
  1973. }
  1974. if((hw->media_type == e1000_media_type_internal_serdes) &&
  1975. (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
  1976. hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
  1977. }
  1978. return E1000_SUCCESS;
  1979. }
  1980. /******************************************************************************
  1981. * Detects the current speed and duplex settings of the hardware.
  1982. *
  1983. * hw - Struct containing variables accessed by shared code
  1984. * speed - Speed of the connection
  1985. * duplex - Duplex setting of the connection
  1986. *****************************************************************************/
  1987. int32_t
  1988. e1000_get_speed_and_duplex(struct e1000_hw *hw,
  1989. uint16_t *speed,
  1990. uint16_t *duplex)
  1991. {
  1992. uint32_t status;
  1993. int32_t ret_val;
  1994. uint16_t phy_data;
  1995. DEBUGFUNC("e1000_get_speed_and_duplex");
  1996. if(hw->mac_type >= e1000_82543) {
  1997. status = E1000_READ_REG(hw, STATUS);
  1998. if(status & E1000_STATUS_SPEED_1000) {
  1999. *speed = SPEED_1000;
  2000. DEBUGOUT("1000 Mbs, ");
  2001. } else if(status & E1000_STATUS_SPEED_100) {
  2002. *speed = SPEED_100;
  2003. DEBUGOUT("100 Mbs, ");
  2004. } else {
  2005. *speed = SPEED_10;
  2006. DEBUGOUT("10 Mbs, ");
  2007. }
  2008. if(status & E1000_STATUS_FD) {
  2009. *duplex = FULL_DUPLEX;
  2010. DEBUGOUT("Full Duplex\r\n");
  2011. } else {
  2012. *duplex = HALF_DUPLEX;
  2013. DEBUGOUT(" Half Duplex\r\n");
  2014. }
  2015. } else {
  2016. DEBUGOUT("1000 Mbs, Full Duplex\r\n");
  2017. *speed = SPEED_1000;
  2018. *duplex = FULL_DUPLEX;
  2019. }
  2020. /* IGP01 PHY may advertise full duplex operation after speed downgrade even
  2021. * if it is operating at half duplex. Here we set the duplex settings to
  2022. * match the duplex in the link partner's capabilities.
  2023. */
  2024. if(hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
  2025. ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
  2026. if(ret_val)
  2027. return ret_val;
  2028. if(!(phy_data & NWAY_ER_LP_NWAY_CAPS))
  2029. *duplex = HALF_DUPLEX;
  2030. else {
  2031. ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
  2032. if(ret_val)
  2033. return ret_val;
  2034. if((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
  2035. (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
  2036. *duplex = HALF_DUPLEX;
  2037. }
  2038. }
  2039. return E1000_SUCCESS;
  2040. }
  2041. /******************************************************************************
  2042. * Blocks until autoneg completes or times out (~4.5 seconds)
  2043. *
  2044. * hw - Struct containing variables accessed by shared code
  2045. ******************************************************************************/
  2046. int32_t
  2047. e1000_wait_autoneg(struct e1000_hw *hw)
  2048. {
  2049. int32_t ret_val;
  2050. uint16_t i;
  2051. uint16_t phy_data;
  2052. DEBUGFUNC("e1000_wait_autoneg");
  2053. DEBUGOUT("Waiting for Auto-Neg to complete.\n");
  2054. /* We will wait for autoneg to complete or 4.5 seconds to expire. */
  2055. for(i = PHY_AUTO_NEG_TIME; i > 0; i--) {
  2056. /* Read the MII Status Register and wait for Auto-Neg
  2057. * Complete bit to be set.
  2058. */
  2059. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  2060. if(ret_val)
  2061. return ret_val;
  2062. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  2063. if(ret_val)
  2064. return ret_val;
  2065. if(phy_data & MII_SR_AUTONEG_COMPLETE) {
  2066. return E1000_SUCCESS;
  2067. }
  2068. msec_delay(100);
  2069. }
  2070. return E1000_SUCCESS;
  2071. }
  2072. /******************************************************************************
  2073. * Raises the Management Data Clock
  2074. *
  2075. * hw - Struct containing variables accessed by shared code
  2076. * ctrl - Device control register's current value
  2077. ******************************************************************************/
  2078. static void
  2079. e1000_raise_mdi_clk(struct e1000_hw *hw,
  2080. uint32_t *ctrl)
  2081. {
  2082. /* Raise the clock input to the Management Data Clock (by setting the MDC
  2083. * bit), and then delay 10 microseconds.
  2084. */
  2085. E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
  2086. E1000_WRITE_FLUSH(hw);
  2087. udelay(10);
  2088. }
  2089. /******************************************************************************
  2090. * Lowers the Management Data Clock
  2091. *
  2092. * hw - Struct containing variables accessed by shared code
  2093. * ctrl - Device control register's current value
  2094. ******************************************************************************/
  2095. static void
  2096. e1000_lower_mdi_clk(struct e1000_hw *hw,
  2097. uint32_t *ctrl)
  2098. {
  2099. /* Lower the clock input to the Management Data Clock (by clearing the MDC
  2100. * bit), and then delay 10 microseconds.
  2101. */
  2102. E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
  2103. E1000_WRITE_FLUSH(hw);
  2104. udelay(10);
  2105. }
  2106. /******************************************************************************
  2107. * Shifts data bits out to the PHY
  2108. *
  2109. * hw - Struct containing variables accessed by shared code
  2110. * data - Data to send out to the PHY
  2111. * count - Number of bits to shift out
  2112. *
  2113. * Bits are shifted out in MSB to LSB order.
  2114. ******************************************************************************/
  2115. static void
  2116. e1000_shift_out_mdi_bits(struct e1000_hw *hw,
  2117. uint32_t data,
  2118. uint16_t count)
  2119. {
  2120. uint32_t ctrl;
  2121. uint32_t mask;
  2122. /* We need to shift "count" number of bits out to the PHY. So, the value
  2123. * in the "data" parameter will be shifted out to the PHY one bit at a
  2124. * time. In order to do this, "data" must be broken down into bits.
  2125. */
  2126. mask = 0x01;
  2127. mask <<= (count - 1);
  2128. ctrl = E1000_READ_REG(hw, CTRL);
  2129. /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
  2130. ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
  2131. while(mask) {
  2132. /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
  2133. * then raising and lowering the Management Data Clock. A "0" is
  2134. * shifted out to the PHY by setting the MDIO bit to "0" and then
  2135. * raising and lowering the clock.
  2136. */
  2137. if(data & mask) ctrl |= E1000_CTRL_MDIO;
  2138. else ctrl &= ~E1000_CTRL_MDIO;
  2139. E1000_WRITE_REG(hw, CTRL, ctrl);
  2140. E1000_WRITE_FLUSH(hw);
  2141. udelay(10);
  2142. e1000_raise_mdi_clk(hw, &ctrl);
  2143. e1000_lower_mdi_clk(hw, &ctrl);
  2144. mask = mask >> 1;
  2145. }
  2146. }
  2147. /******************************************************************************
  2148. * Shifts data bits in from the PHY
  2149. *
  2150. * hw - Struct containing variables accessed by shared code
  2151. *
  2152. * Bits are shifted in in MSB to LSB order.
  2153. ******************************************************************************/
  2154. static uint16_t
  2155. e1000_shift_in_mdi_bits(struct e1000_hw *hw)
  2156. {
  2157. uint32_t ctrl;
  2158. uint16_t data = 0;
  2159. uint8_t i;
  2160. /* In order to read a register from the PHY, we need to shift in a total
  2161. * of 18 bits from the PHY. The first two bit (turnaround) times are used
  2162. * to avoid contention on the MDIO pin when a read operation is performed.
  2163. * These two bits are ignored by us and thrown away. Bits are "shifted in"
  2164. * by raising the input to the Management Data Clock (setting the MDC bit),
  2165. * and then reading the value of the MDIO bit.
  2166. */
  2167. ctrl = E1000_READ_REG(hw, CTRL);
  2168. /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
  2169. ctrl &= ~E1000_CTRL_MDIO_DIR;
  2170. ctrl &= ~E1000_CTRL_MDIO;
  2171. E1000_WRITE_REG(hw, CTRL, ctrl);
  2172. E1000_WRITE_FLUSH(hw);
  2173. /* Raise and Lower the clock before reading in the data. This accounts for
  2174. * the turnaround bits. The first clock occurred when we clocked out the
  2175. * last bit of the Register Address.
  2176. */
  2177. e1000_raise_mdi_clk(hw, &ctrl);
  2178. e1000_lower_mdi_clk(hw, &ctrl);
  2179. for(data = 0, i = 0; i < 16; i++) {
  2180. data = data << 1;
  2181. e1000_raise_mdi_clk(hw, &ctrl);
  2182. ctrl = E1000_READ_REG(hw, CTRL);
  2183. /* Check to see if we shifted in a "1". */
  2184. if(ctrl & E1000_CTRL_MDIO) data |= 1;
  2185. e1000_lower_mdi_clk(hw, &ctrl);
  2186. }
  2187. e1000_raise_mdi_clk(hw, &ctrl);
  2188. e1000_lower_mdi_clk(hw, &ctrl);
  2189. return data;
  2190. }
  2191. /*****************************************************************************
  2192. * Reads the value from a PHY register, if the value is on a specific non zero
  2193. * page, sets the page first.
  2194. * hw - Struct containing variables accessed by shared code
  2195. * reg_addr - address of the PHY register to read
  2196. ******************************************************************************/
  2197. int32_t
  2198. e1000_read_phy_reg(struct e1000_hw *hw,
  2199. uint32_t reg_addr,
  2200. uint16_t *phy_data)
  2201. {
  2202. uint32_t ret_val;
  2203. DEBUGFUNC("e1000_read_phy_reg");
  2204. if(hw->phy_type == e1000_phy_igp &&
  2205. (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
  2206. ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
  2207. (uint16_t)reg_addr);
  2208. if(ret_val) {
  2209. return ret_val;
  2210. }
  2211. }
  2212. ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
  2213. phy_data);
  2214. return ret_val;
  2215. }
  2216. int32_t
  2217. e1000_read_phy_reg_ex(struct e1000_hw *hw,
  2218. uint32_t reg_addr,
  2219. uint16_t *phy_data)
  2220. {
  2221. uint32_t i;
  2222. uint32_t mdic = 0;
  2223. const uint32_t phy_addr = 1;
  2224. DEBUGFUNC("e1000_read_phy_reg_ex");
  2225. if(reg_addr > MAX_PHY_REG_ADDRESS) {
  2226. DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
  2227. return -E1000_ERR_PARAM;
  2228. }
  2229. if(hw->mac_type > e1000_82543) {
  2230. /* Set up Op-code, Phy Address, and register address in the MDI
  2231. * Control register. The MAC will take care of interfacing with the
  2232. * PHY to retrieve the desired data.
  2233. */
  2234. mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
  2235. (phy_addr << E1000_MDIC_PHY_SHIFT) |
  2236. (E1000_MDIC_OP_READ));
  2237. E1000_WRITE_REG(hw, MDIC, mdic);
  2238. /* Poll the ready bit to see if the MDI read completed */
  2239. for(i = 0; i < 64; i++) {
  2240. udelay(50);
  2241. mdic = E1000_READ_REG(hw, MDIC);
  2242. if(mdic & E1000_MDIC_READY) break;
  2243. }
  2244. if(!(mdic & E1000_MDIC_READY)) {
  2245. DEBUGOUT("MDI Read did not complete\n");
  2246. return -E1000_ERR_PHY;
  2247. }
  2248. if(mdic & E1000_MDIC_ERROR) {
  2249. DEBUGOUT("MDI Error\n");
  2250. return -E1000_ERR_PHY;
  2251. }
  2252. *phy_data = (uint16_t) mdic;
  2253. } else {
  2254. /* We must first send a preamble through the MDIO pin to signal the
  2255. * beginning of an MII instruction. This is done by sending 32
  2256. * consecutive "1" bits.
  2257. */
  2258. e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
  2259. /* Now combine the next few fields that are required for a read
  2260. * operation. We use this method instead of calling the
  2261. * e1000_shift_out_mdi_bits routine five different times. The format of
  2262. * a MII read instruction consists of a shift out of 14 bits and is
  2263. * defined as follows:
  2264. * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
  2265. * followed by a shift in of 18 bits. This first two bits shifted in
  2266. * are TurnAround bits used to avoid contention on the MDIO pin when a
  2267. * READ operation is performed. These two bits are thrown away
  2268. * followed by a shift in of 16 bits which contains the desired data.
  2269. */
  2270. mdic = ((reg_addr) | (phy_addr << 5) |
  2271. (PHY_OP_READ << 10) | (PHY_SOF << 12));
  2272. e1000_shift_out_mdi_bits(hw, mdic, 14);
  2273. /* Now that we've shifted out the read command to the MII, we need to
  2274. * "shift in" the 16-bit value (18 total bits) of the requested PHY
  2275. * register address.
  2276. */
  2277. *phy_data = e1000_shift_in_mdi_bits(hw);
  2278. }
  2279. return E1000_SUCCESS;
  2280. }
  2281. /******************************************************************************
  2282. * Writes a value to a PHY register
  2283. *
  2284. * hw - Struct containing variables accessed by shared code
  2285. * reg_addr - address of the PHY register to write
  2286. * data - data to write to the PHY
  2287. ******************************************************************************/
  2288. int32_t
  2289. e1000_write_phy_reg(struct e1000_hw *hw,
  2290. uint32_t reg_addr,
  2291. uint16_t phy_data)
  2292. {
  2293. uint32_t ret_val;
  2294. DEBUGFUNC("e1000_write_phy_reg");
  2295. if(hw->phy_type == e1000_phy_igp &&
  2296. (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
  2297. ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
  2298. (uint16_t)reg_addr);
  2299. if(ret_val) {
  2300. return ret_val;
  2301. }
  2302. }
  2303. ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
  2304. phy_data);
  2305. return ret_val;
  2306. }
  2307. int32_t
  2308. e1000_write_phy_reg_ex(struct e1000_hw *hw,
  2309. uint32_t reg_addr,
  2310. uint16_t phy_data)
  2311. {
  2312. uint32_t i;
  2313. uint32_t mdic = 0;
  2314. const uint32_t phy_addr = 1;
  2315. DEBUGFUNC("e1000_write_phy_reg_ex");
  2316. if(reg_addr > MAX_PHY_REG_ADDRESS) {
  2317. DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
  2318. return -E1000_ERR_PARAM;
  2319. }
  2320. if(hw->mac_type > e1000_82543) {
  2321. /* Set up Op-code, Phy Address, register address, and data intended
  2322. * for the PHY register in the MDI Control register. The MAC will take
  2323. * care of interfacing with the PHY to send the desired data.
  2324. */
  2325. mdic = (((uint32_t) phy_data) |
  2326. (reg_addr << E1000_MDIC_REG_SHIFT) |
  2327. (phy_addr << E1000_MDIC_PHY_SHIFT) |
  2328. (E1000_MDIC_OP_WRITE));
  2329. E1000_WRITE_REG(hw, MDIC, mdic);
  2330. /* Poll the ready bit to see if the MDI read completed */
  2331. for(i = 0; i < 640; i++) {
  2332. udelay(5);
  2333. mdic = E1000_READ_REG(hw, MDIC);
  2334. if(mdic & E1000_MDIC_READY) break;
  2335. }
  2336. if(!(mdic & E1000_MDIC_READY)) {
  2337. DEBUGOUT("MDI Write did not complete\n");
  2338. return -E1000_ERR_PHY;
  2339. }
  2340. } else {
  2341. /* We'll need to use the SW defined pins to shift the write command
  2342. * out to the PHY. We first send a preamble to the PHY to signal the
  2343. * beginning of the MII instruction. This is done by sending 32
  2344. * consecutive "1" bits.
  2345. */
  2346. e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
  2347. /* Now combine the remaining required fields that will indicate a
  2348. * write operation. We use this method instead of calling the
  2349. * e1000_shift_out_mdi_bits routine for each field in the command. The
  2350. * format of a MII write instruction is as follows:
  2351. * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
  2352. */
  2353. mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
  2354. (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
  2355. mdic <<= 16;
  2356. mdic |= (uint32_t) phy_data;
  2357. e1000_shift_out_mdi_bits(hw, mdic, 32);
  2358. }
  2359. return E1000_SUCCESS;
  2360. }
  2361. /******************************************************************************
  2362. * Returns the PHY to the power-on reset state
  2363. *
  2364. * hw - Struct containing variables accessed by shared code
  2365. ******************************************************************************/
  2366. void
  2367. e1000_phy_hw_reset(struct e1000_hw *hw)
  2368. {
  2369. uint32_t ctrl, ctrl_ext;
  2370. uint32_t led_ctrl;
  2371. DEBUGFUNC("e1000_phy_hw_reset");
  2372. DEBUGOUT("Resetting Phy...\n");
  2373. if(hw->mac_type > e1000_82543) {
  2374. /* Read the device control register and assert the E1000_CTRL_PHY_RST
  2375. * bit. Then, take it out of reset.
  2376. */
  2377. ctrl = E1000_READ_REG(hw, CTRL);
  2378. E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
  2379. E1000_WRITE_FLUSH(hw);
  2380. msec_delay(10);
  2381. E1000_WRITE_REG(hw, CTRL, ctrl);
  2382. E1000_WRITE_FLUSH(hw);
  2383. } else {
  2384. /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
  2385. * bit to put the PHY into reset. Then, take it out of reset.
  2386. */
  2387. ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  2388. ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
  2389. ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
  2390. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  2391. E1000_WRITE_FLUSH(hw);
  2392. msec_delay(10);
  2393. ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
  2394. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  2395. E1000_WRITE_FLUSH(hw);
  2396. }
  2397. udelay(150);
  2398. if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
  2399. /* Configure activity LED after PHY reset */
  2400. led_ctrl = E1000_READ_REG(hw, LEDCTL);
  2401. led_ctrl &= IGP_ACTIVITY_LED_MASK;
  2402. led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
  2403. E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
  2404. }
  2405. }
  2406. /******************************************************************************
  2407. * Resets the PHY
  2408. *
  2409. * hw - Struct containing variables accessed by shared code
  2410. *
  2411. * Sets bit 15 of the MII Control regiser
  2412. ******************************************************************************/
  2413. int32_t
  2414. e1000_phy_reset(struct e1000_hw *hw)
  2415. {
  2416. int32_t ret_val;
  2417. uint16_t phy_data;
  2418. DEBUGFUNC("e1000_phy_reset");
  2419. if(hw->mac_type != e1000_82541_rev_2) {
  2420. ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
  2421. if(ret_val)
  2422. return ret_val;
  2423. phy_data |= MII_CR_RESET;
  2424. ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
  2425. if(ret_val)
  2426. return ret_val;
  2427. udelay(1);
  2428. } else e1000_phy_hw_reset(hw);
  2429. if(hw->phy_type == e1000_phy_igp)
  2430. e1000_phy_init_script(hw);
  2431. return E1000_SUCCESS;
  2432. }
  2433. /******************************************************************************
  2434. * Probes the expected PHY address for known PHY IDs
  2435. *
  2436. * hw - Struct containing variables accessed by shared code
  2437. ******************************************************************************/
  2438. int32_t
  2439. e1000_detect_gig_phy(struct e1000_hw *hw)
  2440. {
  2441. int32_t phy_init_status, ret_val;
  2442. uint16_t phy_id_high, phy_id_low;
  2443. boolean_t match = FALSE;
  2444. DEBUGFUNC("e1000_detect_gig_phy");
  2445. /* Read the PHY ID Registers to identify which PHY is onboard. */
  2446. ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
  2447. if(ret_val)
  2448. return ret_val;
  2449. hw->phy_id = (uint32_t) (phy_id_high << 16);
  2450. udelay(20);
  2451. ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
  2452. if(ret_val)
  2453. return ret_val;
  2454. hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
  2455. hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
  2456. switch(hw->mac_type) {
  2457. case e1000_82543:
  2458. if(hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
  2459. break;
  2460. case e1000_82544:
  2461. if(hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
  2462. break;
  2463. case e1000_82540:
  2464. case e1000_82545:
  2465. case e1000_82545_rev_3:
  2466. case e1000_82546:
  2467. case e1000_82546_rev_3:
  2468. if(hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
  2469. break;
  2470. case e1000_82541:
  2471. case e1000_82541_rev_2:
  2472. case e1000_82547:
  2473. case e1000_82547_rev_2:
  2474. if(hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
  2475. break;
  2476. default:
  2477. DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
  2478. return -E1000_ERR_CONFIG;
  2479. }
  2480. phy_init_status = e1000_set_phy_type(hw);
  2481. if ((match) && (phy_init_status == E1000_SUCCESS)) {
  2482. DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
  2483. return E1000_SUCCESS;
  2484. }
  2485. DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
  2486. return -E1000_ERR_PHY;
  2487. }
  2488. /******************************************************************************
  2489. * Resets the PHY's DSP
  2490. *
  2491. * hw - Struct containing variables accessed by shared code
  2492. ******************************************************************************/
  2493. static int32_t
  2494. e1000_phy_reset_dsp(struct e1000_hw *hw)
  2495. {
  2496. int32_t ret_val;
  2497. DEBUGFUNC("e1000_phy_reset_dsp");
  2498. do {
  2499. ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
  2500. if(ret_val) break;
  2501. ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
  2502. if(ret_val) break;
  2503. ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
  2504. if(ret_val) break;
  2505. ret_val = E1000_SUCCESS;
  2506. } while(0);
  2507. return ret_val;
  2508. }
  2509. /******************************************************************************
  2510. * Get PHY information from various PHY registers for igp PHY only.
  2511. *
  2512. * hw - Struct containing variables accessed by shared code
  2513. * phy_info - PHY information structure
  2514. ******************************************************************************/
  2515. int32_t
  2516. e1000_phy_igp_get_info(struct e1000_hw *hw,
  2517. struct e1000_phy_info *phy_info)
  2518. {
  2519. int32_t ret_val;
  2520. uint16_t phy_data, polarity, min_length, max_length, average;
  2521. DEBUGFUNC("e1000_phy_igp_get_info");
  2522. /* The downshift status is checked only once, after link is established,
  2523. * and it stored in the hw->speed_downgraded parameter. */
  2524. phy_info->downshift = hw->speed_downgraded;
  2525. /* IGP01E1000 does not need to support it. */
  2526. phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
  2527. /* IGP01E1000 always correct polarity reversal */
  2528. phy_info->polarity_correction = e1000_polarity_reversal_enabled;
  2529. /* Check polarity status */
  2530. ret_val = e1000_check_polarity(hw, &polarity);
  2531. if(ret_val)
  2532. return ret_val;
  2533. phy_info->cable_polarity = polarity;
  2534. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
  2535. if(ret_val)
  2536. return ret_val;
  2537. phy_info->mdix_mode = (phy_data & IGP01E1000_PSSR_MDIX) >>
  2538. IGP01E1000_PSSR_MDIX_SHIFT;
  2539. if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
  2540. IGP01E1000_PSSR_SPEED_1000MBPS) {
  2541. /* Local/Remote Receiver Information are only valid at 1000 Mbps */
  2542. ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
  2543. if(ret_val)
  2544. return ret_val;
  2545. phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
  2546. SR_1000T_LOCAL_RX_STATUS_SHIFT;
  2547. phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
  2548. SR_1000T_REMOTE_RX_STATUS_SHIFT;
  2549. /* Get cable length */
  2550. ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
  2551. if(ret_val)
  2552. return ret_val;
  2553. /* transalte to old method */
  2554. average = (max_length + min_length) / 2;
  2555. if(average <= e1000_igp_cable_length_50)
  2556. phy_info->cable_length = e1000_cable_length_50;
  2557. else if(average <= e1000_igp_cable_length_80)
  2558. phy_info->cable_length = e1000_cable_length_50_80;
  2559. else if(average <= e1000_igp_cable_length_110)
  2560. phy_info->cable_length = e1000_cable_length_80_110;
  2561. else if(average <= e1000_igp_cable_length_140)
  2562. phy_info->cable_length = e1000_cable_length_110_140;
  2563. else
  2564. phy_info->cable_length = e1000_cable_length_140;
  2565. }
  2566. return E1000_SUCCESS;
  2567. }
  2568. /******************************************************************************
  2569. * Get PHY information from various PHY registers fot m88 PHY only.
  2570. *
  2571. * hw - Struct containing variables accessed by shared code
  2572. * phy_info - PHY information structure
  2573. ******************************************************************************/
  2574. int32_t
  2575. e1000_phy_m88_get_info(struct e1000_hw *hw,
  2576. struct e1000_phy_info *phy_info)
  2577. {
  2578. int32_t ret_val;
  2579. uint16_t phy_data, polarity;
  2580. DEBUGFUNC("e1000_phy_m88_get_info");
  2581. /* The downshift status is checked only once, after link is established,
  2582. * and it stored in the hw->speed_downgraded parameter. */
  2583. phy_info->downshift = hw->speed_downgraded;
  2584. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  2585. if(ret_val)
  2586. return ret_val;
  2587. phy_info->extended_10bt_distance =
  2588. (phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
  2589. M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT;
  2590. phy_info->polarity_correction =
  2591. (phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
  2592. M88E1000_PSCR_POLARITY_REVERSAL_SHIFT;
  2593. /* Check polarity status */
  2594. ret_val = e1000_check_polarity(hw, &polarity);
  2595. if(ret_val)
  2596. return ret_val;
  2597. phy_info->cable_polarity = polarity;
  2598. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
  2599. if(ret_val)
  2600. return ret_val;
  2601. phy_info->mdix_mode = (phy_data & M88E1000_PSSR_MDIX) >>
  2602. M88E1000_PSSR_MDIX_SHIFT;
  2603. if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
  2604. /* Cable Length Estimation and Local/Remote Receiver Information
  2605. * are only valid at 1000 Mbps.
  2606. */
  2607. phy_info->cable_length = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
  2608. M88E1000_PSSR_CABLE_LENGTH_SHIFT);
  2609. ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
  2610. if(ret_val)
  2611. return ret_val;
  2612. phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
  2613. SR_1000T_LOCAL_RX_STATUS_SHIFT;
  2614. phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
  2615. SR_1000T_REMOTE_RX_STATUS_SHIFT;
  2616. }
  2617. return E1000_SUCCESS;
  2618. }
  2619. /******************************************************************************
  2620. * Get PHY information from various PHY registers
  2621. *
  2622. * hw - Struct containing variables accessed by shared code
  2623. * phy_info - PHY information structure
  2624. ******************************************************************************/
  2625. int32_t
  2626. e1000_phy_get_info(struct e1000_hw *hw,
  2627. struct e1000_phy_info *phy_info)
  2628. {
  2629. int32_t ret_val;
  2630. uint16_t phy_data;
  2631. DEBUGFUNC("e1000_phy_get_info");
  2632. phy_info->cable_length = e1000_cable_length_undefined;
  2633. phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
  2634. phy_info->cable_polarity = e1000_rev_polarity_undefined;
  2635. phy_info->downshift = e1000_downshift_undefined;
  2636. phy_info->polarity_correction = e1000_polarity_reversal_undefined;
  2637. phy_info->mdix_mode = e1000_auto_x_mode_undefined;
  2638. phy_info->local_rx = e1000_1000t_rx_status_undefined;
  2639. phy_info->remote_rx = e1000_1000t_rx_status_undefined;
  2640. if(hw->media_type != e1000_media_type_copper) {
  2641. DEBUGOUT("PHY info is only valid for copper media\n");
  2642. return -E1000_ERR_CONFIG;
  2643. }
  2644. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  2645. if(ret_val)
  2646. return ret_val;
  2647. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  2648. if(ret_val)
  2649. return ret_val;
  2650. if((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
  2651. DEBUGOUT("PHY info is only valid if link is up\n");
  2652. return -E1000_ERR_CONFIG;
  2653. }
  2654. if(hw->phy_type == e1000_phy_igp)
  2655. return e1000_phy_igp_get_info(hw, phy_info);
  2656. else
  2657. return e1000_phy_m88_get_info(hw, phy_info);
  2658. }
  2659. int32_t
  2660. e1000_validate_mdi_setting(struct e1000_hw *hw)
  2661. {
  2662. DEBUGFUNC("e1000_validate_mdi_settings");
  2663. if(!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
  2664. DEBUGOUT("Invalid MDI setting detected\n");
  2665. hw->mdix = 1;
  2666. return -E1000_ERR_CONFIG;
  2667. }
  2668. return E1000_SUCCESS;
  2669. }
  2670. /******************************************************************************
  2671. * Sets up eeprom variables in the hw struct. Must be called after mac_type
  2672. * is configured.
  2673. *
  2674. * hw - Struct containing variables accessed by shared code
  2675. *****************************************************************************/
  2676. void
  2677. e1000_init_eeprom_params(struct e1000_hw *hw)
  2678. {
  2679. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  2680. uint32_t eecd = E1000_READ_REG(hw, EECD);
  2681. uint16_t eeprom_size;
  2682. DEBUGFUNC("e1000_init_eeprom_params");
  2683. switch (hw->mac_type) {
  2684. case e1000_82542_rev2_0:
  2685. case e1000_82542_rev2_1:
  2686. case e1000_82543:
  2687. case e1000_82544:
  2688. eeprom->type = e1000_eeprom_microwire;
  2689. eeprom->word_size = 64;
  2690. eeprom->opcode_bits = 3;
  2691. eeprom->address_bits = 6;
  2692. eeprom->delay_usec = 50;
  2693. break;
  2694. case e1000_82540:
  2695. case e1000_82545:
  2696. case e1000_82545_rev_3:
  2697. case e1000_82546:
  2698. case e1000_82546_rev_3:
  2699. eeprom->type = e1000_eeprom_microwire;
  2700. eeprom->opcode_bits = 3;
  2701. eeprom->delay_usec = 50;
  2702. if(eecd & E1000_EECD_SIZE) {
  2703. eeprom->word_size = 256;
  2704. eeprom->address_bits = 8;
  2705. } else {
  2706. eeprom->word_size = 64;
  2707. eeprom->address_bits = 6;
  2708. }
  2709. break;
  2710. case e1000_82541:
  2711. case e1000_82541_rev_2:
  2712. case e1000_82547:
  2713. case e1000_82547_rev_2:
  2714. if (eecd & E1000_EECD_TYPE) {
  2715. eeprom->type = e1000_eeprom_spi;
  2716. eeprom->opcode_bits = 8;
  2717. eeprom->delay_usec = 1;
  2718. if (eecd & E1000_EECD_ADDR_BITS) {
  2719. eeprom->page_size = 32;
  2720. eeprom->address_bits = 16;
  2721. } else {
  2722. eeprom->page_size = 8;
  2723. eeprom->address_bits = 8;
  2724. }
  2725. } else {
  2726. eeprom->type = e1000_eeprom_microwire;
  2727. eeprom->opcode_bits = 3;
  2728. eeprom->delay_usec = 50;
  2729. if (eecd & E1000_EECD_ADDR_BITS) {
  2730. eeprom->word_size = 256;
  2731. eeprom->address_bits = 8;
  2732. } else {
  2733. eeprom->word_size = 64;
  2734. eeprom->address_bits = 6;
  2735. }
  2736. }
  2737. break;
  2738. default:
  2739. break;
  2740. }
  2741. if (eeprom->type == e1000_eeprom_spi) {
  2742. eeprom->word_size = 64;
  2743. if (e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size) == 0) {
  2744. eeprom_size &= EEPROM_SIZE_MASK;
  2745. switch (eeprom_size) {
  2746. case EEPROM_SIZE_16KB:
  2747. eeprom->word_size = 8192;
  2748. break;
  2749. case EEPROM_SIZE_8KB:
  2750. eeprom->word_size = 4096;
  2751. break;
  2752. case EEPROM_SIZE_4KB:
  2753. eeprom->word_size = 2048;
  2754. break;
  2755. case EEPROM_SIZE_2KB:
  2756. eeprom->word_size = 1024;
  2757. break;
  2758. case EEPROM_SIZE_1KB:
  2759. eeprom->word_size = 512;
  2760. break;
  2761. case EEPROM_SIZE_512B:
  2762. eeprom->word_size = 256;
  2763. break;
  2764. case EEPROM_SIZE_128B:
  2765. default:
  2766. eeprom->word_size = 64;
  2767. break;
  2768. }
  2769. }
  2770. }
  2771. }
  2772. /******************************************************************************
  2773. * Raises the EEPROM's clock input.
  2774. *
  2775. * hw - Struct containing variables accessed by shared code
  2776. * eecd - EECD's current value
  2777. *****************************************************************************/
  2778. static void
  2779. e1000_raise_ee_clk(struct e1000_hw *hw,
  2780. uint32_t *eecd)
  2781. {
  2782. /* Raise the clock input to the EEPROM (by setting the SK bit), and then
  2783. * wait <delay> microseconds.
  2784. */
  2785. *eecd = *eecd | E1000_EECD_SK;
  2786. E1000_WRITE_REG(hw, EECD, *eecd);
  2787. E1000_WRITE_FLUSH(hw);
  2788. udelay(hw->eeprom.delay_usec);
  2789. }
  2790. /******************************************************************************
  2791. * Lowers the EEPROM's clock input.
  2792. *
  2793. * hw - Struct containing variables accessed by shared code
  2794. * eecd - EECD's current value
  2795. *****************************************************************************/
  2796. static void
  2797. e1000_lower_ee_clk(struct e1000_hw *hw,
  2798. uint32_t *eecd)
  2799. {
  2800. /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
  2801. * wait 50 microseconds.
  2802. */
  2803. *eecd = *eecd & ~E1000_EECD_SK;
  2804. E1000_WRITE_REG(hw, EECD, *eecd);
  2805. E1000_WRITE_FLUSH(hw);
  2806. udelay(hw->eeprom.delay_usec);
  2807. }
  2808. /******************************************************************************
  2809. * Shift data bits out to the EEPROM.
  2810. *
  2811. * hw - Struct containing variables accessed by shared code
  2812. * data - data to send to the EEPROM
  2813. * count - number of bits to shift out
  2814. *****************************************************************************/
  2815. static void
  2816. e1000_shift_out_ee_bits(struct e1000_hw *hw,
  2817. uint16_t data,
  2818. uint16_t count)
  2819. {
  2820. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  2821. uint32_t eecd;
  2822. uint32_t mask;
  2823. /* We need to shift "count" bits out to the EEPROM. So, value in the
  2824. * "data" parameter will be shifted out to the EEPROM one bit at a time.
  2825. * In order to do this, "data" must be broken down into bits.
  2826. */
  2827. mask = 0x01 << (count - 1);
  2828. eecd = E1000_READ_REG(hw, EECD);
  2829. if (eeprom->type == e1000_eeprom_microwire) {
  2830. eecd &= ~E1000_EECD_DO;
  2831. } else if (eeprom->type == e1000_eeprom_spi) {
  2832. eecd |= E1000_EECD_DO;
  2833. }
  2834. do {
  2835. /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
  2836. * and then raising and then lowering the clock (the SK bit controls
  2837. * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
  2838. * by setting "DI" to "0" and then raising and then lowering the clock.
  2839. */
  2840. eecd &= ~E1000_EECD_DI;
  2841. if(data & mask)
  2842. eecd |= E1000_EECD_DI;
  2843. E1000_WRITE_REG(hw, EECD, eecd);
  2844. E1000_WRITE_FLUSH(hw);
  2845. udelay(eeprom->delay_usec);
  2846. e1000_raise_ee_clk(hw, &eecd);
  2847. e1000_lower_ee_clk(hw, &eecd);
  2848. mask = mask >> 1;
  2849. } while(mask);
  2850. /* We leave the "DI" bit set to "0" when we leave this routine. */
  2851. eecd &= ~E1000_EECD_DI;
  2852. E1000_WRITE_REG(hw, EECD, eecd);
  2853. }
  2854. /******************************************************************************
  2855. * Shift data bits in from the EEPROM
  2856. *
  2857. * hw - Struct containing variables accessed by shared code
  2858. *****************************************************************************/
  2859. static uint16_t
  2860. e1000_shift_in_ee_bits(struct e1000_hw *hw,
  2861. uint16_t count)
  2862. {
  2863. uint32_t eecd;
  2864. uint32_t i;
  2865. uint16_t data;
  2866. /* In order to read a register from the EEPROM, we need to shift 'count'
  2867. * bits in from the EEPROM. Bits are "shifted in" by raising the clock
  2868. * input to the EEPROM (setting the SK bit), and then reading the value of
  2869. * the "DO" bit. During this "shifting in" process the "DI" bit should
  2870. * always be clear.
  2871. */
  2872. eecd = E1000_READ_REG(hw, EECD);
  2873. eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
  2874. data = 0;
  2875. for(i = 0; i < count; i++) {
  2876. data = data << 1;
  2877. e1000_raise_ee_clk(hw, &eecd);
  2878. eecd = E1000_READ_REG(hw, EECD);
  2879. eecd &= ~(E1000_EECD_DI);
  2880. if(eecd & E1000_EECD_DO)
  2881. data |= 1;
  2882. e1000_lower_ee_clk(hw, &eecd);
  2883. }
  2884. return data;
  2885. }
  2886. /******************************************************************************
  2887. * Prepares EEPROM for access
  2888. *
  2889. * hw - Struct containing variables accessed by shared code
  2890. *
  2891. * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
  2892. * function should be called before issuing a command to the EEPROM.
  2893. *****************************************************************************/
  2894. static int32_t
  2895. e1000_acquire_eeprom(struct e1000_hw *hw)
  2896. {
  2897. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  2898. uint32_t eecd, i=0;
  2899. DEBUGFUNC("e1000_acquire_eeprom");
  2900. eecd = E1000_READ_REG(hw, EECD);
  2901. /* Request EEPROM Access */
  2902. if(hw->mac_type > e1000_82544) {
  2903. eecd |= E1000_EECD_REQ;
  2904. E1000_WRITE_REG(hw, EECD, eecd);
  2905. eecd = E1000_READ_REG(hw, EECD);
  2906. while((!(eecd & E1000_EECD_GNT)) &&
  2907. (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
  2908. i++;
  2909. udelay(5);
  2910. eecd = E1000_READ_REG(hw, EECD);
  2911. }
  2912. if(!(eecd & E1000_EECD_GNT)) {
  2913. eecd &= ~E1000_EECD_REQ;
  2914. E1000_WRITE_REG(hw, EECD, eecd);
  2915. DEBUGOUT("Could not acquire EEPROM grant\n");
  2916. return -E1000_ERR_EEPROM;
  2917. }
  2918. }
  2919. /* Setup EEPROM for Read/Write */
  2920. if (eeprom->type == e1000_eeprom_microwire) {
  2921. /* Clear SK and DI */
  2922. eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
  2923. E1000_WRITE_REG(hw, EECD, eecd);
  2924. /* Set CS */
  2925. eecd |= E1000_EECD_CS;
  2926. E1000_WRITE_REG(hw, EECD, eecd);
  2927. } else if (eeprom->type == e1000_eeprom_spi) {
  2928. /* Clear SK and CS */
  2929. eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
  2930. E1000_WRITE_REG(hw, EECD, eecd);
  2931. udelay(1);
  2932. }
  2933. return E1000_SUCCESS;
  2934. }
  2935. /******************************************************************************
  2936. * Returns EEPROM to a "standby" state
  2937. *
  2938. * hw - Struct containing variables accessed by shared code
  2939. *****************************************************************************/
  2940. static void
  2941. e1000_standby_eeprom(struct e1000_hw *hw)
  2942. {
  2943. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  2944. uint32_t eecd;
  2945. eecd = E1000_READ_REG(hw, EECD);
  2946. if(eeprom->type == e1000_eeprom_microwire) {
  2947. eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
  2948. E1000_WRITE_REG(hw, EECD, eecd);
  2949. E1000_WRITE_FLUSH(hw);
  2950. udelay(eeprom->delay_usec);
  2951. /* Clock high */
  2952. eecd |= E1000_EECD_SK;
  2953. E1000_WRITE_REG(hw, EECD, eecd);
  2954. E1000_WRITE_FLUSH(hw);
  2955. udelay(eeprom->delay_usec);
  2956. /* Select EEPROM */
  2957. eecd |= E1000_EECD_CS;
  2958. E1000_WRITE_REG(hw, EECD, eecd);
  2959. E1000_WRITE_FLUSH(hw);
  2960. udelay(eeprom->delay_usec);
  2961. /* Clock low */
  2962. eecd &= ~E1000_EECD_SK;
  2963. E1000_WRITE_REG(hw, EECD, eecd);
  2964. E1000_WRITE_FLUSH(hw);
  2965. udelay(eeprom->delay_usec);
  2966. } else if(eeprom->type == e1000_eeprom_spi) {
  2967. /* Toggle CS to flush commands */
  2968. eecd |= E1000_EECD_CS;
  2969. E1000_WRITE_REG(hw, EECD, eecd);
  2970. E1000_WRITE_FLUSH(hw);
  2971. udelay(eeprom->delay_usec);
  2972. eecd &= ~E1000_EECD_CS;
  2973. E1000_WRITE_REG(hw, EECD, eecd);
  2974. E1000_WRITE_FLUSH(hw);
  2975. udelay(eeprom->delay_usec);
  2976. }
  2977. }
  2978. /******************************************************************************
  2979. * Terminates a command by inverting the EEPROM's chip select pin
  2980. *
  2981. * hw - Struct containing variables accessed by shared code
  2982. *****************************************************************************/
  2983. static void
  2984. e1000_release_eeprom(struct e1000_hw *hw)
  2985. {
  2986. uint32_t eecd;
  2987. DEBUGFUNC("e1000_release_eeprom");
  2988. eecd = E1000_READ_REG(hw, EECD);
  2989. if (hw->eeprom.type == e1000_eeprom_spi) {
  2990. eecd |= E1000_EECD_CS; /* Pull CS high */
  2991. eecd &= ~E1000_EECD_SK; /* Lower SCK */
  2992. E1000_WRITE_REG(hw, EECD, eecd);
  2993. udelay(hw->eeprom.delay_usec);
  2994. } else if(hw->eeprom.type == e1000_eeprom_microwire) {
  2995. /* cleanup eeprom */
  2996. /* CS on Microwire is active-high */
  2997. eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
  2998. E1000_WRITE_REG(hw, EECD, eecd);
  2999. /* Rising edge of clock */
  3000. eecd |= E1000_EECD_SK;
  3001. E1000_WRITE_REG(hw, EECD, eecd);
  3002. E1000_WRITE_FLUSH(hw);
  3003. udelay(hw->eeprom.delay_usec);
  3004. /* Falling edge of clock */
  3005. eecd &= ~E1000_EECD_SK;
  3006. E1000_WRITE_REG(hw, EECD, eecd);
  3007. E1000_WRITE_FLUSH(hw);
  3008. udelay(hw->eeprom.delay_usec);
  3009. }
  3010. /* Stop requesting EEPROM access */
  3011. if(hw->mac_type > e1000_82544) {
  3012. eecd &= ~E1000_EECD_REQ;
  3013. E1000_WRITE_REG(hw, EECD, eecd);
  3014. }
  3015. }
  3016. /******************************************************************************
  3017. * Reads a 16 bit word from the EEPROM.
  3018. *
  3019. * hw - Struct containing variables accessed by shared code
  3020. *****************************************************************************/
  3021. int32_t
  3022. e1000_spi_eeprom_ready(struct e1000_hw *hw)
  3023. {
  3024. uint16_t retry_count = 0;
  3025. uint8_t spi_stat_reg;
  3026. DEBUGFUNC("e1000_spi_eeprom_ready");
  3027. /* Read "Status Register" repeatedly until the LSB is cleared. The
  3028. * EEPROM will signal that the command has been completed by clearing
  3029. * bit 0 of the internal status register. If it's not cleared within
  3030. * 5 milliseconds, then error out.
  3031. */
  3032. retry_count = 0;
  3033. do {
  3034. e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
  3035. hw->eeprom.opcode_bits);
  3036. spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
  3037. if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
  3038. break;
  3039. udelay(5);
  3040. retry_count += 5;
  3041. e1000_standby_eeprom(hw);
  3042. } while(retry_count < EEPROM_MAX_RETRY_SPI);
  3043. /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
  3044. * only 0-5mSec on 5V devices)
  3045. */
  3046. if(retry_count >= EEPROM_MAX_RETRY_SPI) {
  3047. DEBUGOUT("SPI EEPROM Status error\n");
  3048. return -E1000_ERR_EEPROM;
  3049. }
  3050. return E1000_SUCCESS;
  3051. }
  3052. /******************************************************************************
  3053. * Reads a 16 bit word from the EEPROM.
  3054. *
  3055. * hw - Struct containing variables accessed by shared code
  3056. * offset - offset of word in the EEPROM to read
  3057. * data - word read from the EEPROM
  3058. * words - number of words to read
  3059. *****************************************************************************/
  3060. int32_t
  3061. e1000_read_eeprom(struct e1000_hw *hw,
  3062. uint16_t offset,
  3063. uint16_t words,
  3064. uint16_t *data)
  3065. {
  3066. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3067. uint32_t i = 0;
  3068. DEBUGFUNC("e1000_read_eeprom");
  3069. /* A check for invalid values: offset too large, too many words, and not
  3070. * enough words.
  3071. */
  3072. if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
  3073. (words == 0)) {
  3074. DEBUGOUT("\"words\" parameter out of bounds\n");
  3075. return -E1000_ERR_EEPROM;
  3076. }
  3077. /* Prepare the EEPROM for reading */
  3078. if(e1000_acquire_eeprom(hw) != E1000_SUCCESS)
  3079. return -E1000_ERR_EEPROM;
  3080. if(eeprom->type == e1000_eeprom_spi) {
  3081. uint16_t word_in;
  3082. uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
  3083. if(e1000_spi_eeprom_ready(hw)) {
  3084. e1000_release_eeprom(hw);
  3085. return -E1000_ERR_EEPROM;
  3086. }
  3087. e1000_standby_eeprom(hw);
  3088. /* Some SPI eeproms use the 8th address bit embedded in the opcode */
  3089. if((eeprom->address_bits == 8) && (offset >= 128))
  3090. read_opcode |= EEPROM_A8_OPCODE_SPI;
  3091. /* Send the READ command (opcode + addr) */
  3092. e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
  3093. e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
  3094. /* Read the data. The address of the eeprom internally increments with
  3095. * each byte (spi) being read, saving on the overhead of eeprom setup
  3096. * and tear-down. The address counter will roll over if reading beyond
  3097. * the size of the eeprom, thus allowing the entire memory to be read
  3098. * starting from any offset. */
  3099. for (i = 0; i < words; i++) {
  3100. word_in = e1000_shift_in_ee_bits(hw, 16);
  3101. data[i] = (word_in >> 8) | (word_in << 8);
  3102. }
  3103. } else if(eeprom->type == e1000_eeprom_microwire) {
  3104. for (i = 0; i < words; i++) {
  3105. /* Send the READ command (opcode + addr) */
  3106. e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
  3107. eeprom->opcode_bits);
  3108. e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
  3109. eeprom->address_bits);
  3110. /* Read the data. For microwire, each word requires the overhead
  3111. * of eeprom setup and tear-down. */
  3112. data[i] = e1000_shift_in_ee_bits(hw, 16);
  3113. e1000_standby_eeprom(hw);
  3114. }
  3115. }
  3116. /* End this read operation */
  3117. e1000_release_eeprom(hw);
  3118. return E1000_SUCCESS;
  3119. }
  3120. /******************************************************************************
  3121. * Verifies that the EEPROM has a valid checksum
  3122. *
  3123. * hw - Struct containing variables accessed by shared code
  3124. *
  3125. * Reads the first 64 16 bit words of the EEPROM and sums the values read.
  3126. * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
  3127. * valid.
  3128. *****************************************************************************/
  3129. int32_t
  3130. e1000_validate_eeprom_checksum(struct e1000_hw *hw)
  3131. {
  3132. uint16_t checksum = 0;
  3133. uint16_t i, eeprom_data;
  3134. DEBUGFUNC("e1000_validate_eeprom_checksum");
  3135. for(i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
  3136. if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
  3137. DEBUGOUT("EEPROM Read Error\n");
  3138. return -E1000_ERR_EEPROM;
  3139. }
  3140. checksum += eeprom_data;
  3141. }
  3142. if(checksum == (uint16_t) EEPROM_SUM)
  3143. return E1000_SUCCESS;
  3144. else {
  3145. DEBUGOUT("EEPROM Checksum Invalid\n");
  3146. return -E1000_ERR_EEPROM;
  3147. }
  3148. }
  3149. /******************************************************************************
  3150. * Calculates the EEPROM checksum and writes it to the EEPROM
  3151. *
  3152. * hw - Struct containing variables accessed by shared code
  3153. *
  3154. * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
  3155. * Writes the difference to word offset 63 of the EEPROM.
  3156. *****************************************************************************/
  3157. int32_t
  3158. e1000_update_eeprom_checksum(struct e1000_hw *hw)
  3159. {
  3160. uint16_t checksum = 0;
  3161. uint16_t i, eeprom_data;
  3162. DEBUGFUNC("e1000_update_eeprom_checksum");
  3163. for(i = 0; i < EEPROM_CHECKSUM_REG; i++) {
  3164. if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
  3165. DEBUGOUT("EEPROM Read Error\n");
  3166. return -E1000_ERR_EEPROM;
  3167. }
  3168. checksum += eeprom_data;
  3169. }
  3170. checksum = (uint16_t) EEPROM_SUM - checksum;
  3171. if(e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
  3172. DEBUGOUT("EEPROM Write Error\n");
  3173. return -E1000_ERR_EEPROM;
  3174. }
  3175. return E1000_SUCCESS;
  3176. }
  3177. /******************************************************************************
  3178. * Parent function for writing words to the different EEPROM types.
  3179. *
  3180. * hw - Struct containing variables accessed by shared code
  3181. * offset - offset within the EEPROM to be written to
  3182. * words - number of words to write
  3183. * data - 16 bit word to be written to the EEPROM
  3184. *
  3185. * If e1000_update_eeprom_checksum is not called after this function, the
  3186. * EEPROM will most likely contain an invalid checksum.
  3187. *****************************************************************************/
  3188. int32_t
  3189. e1000_write_eeprom(struct e1000_hw *hw,
  3190. uint16_t offset,
  3191. uint16_t words,
  3192. uint16_t *data)
  3193. {
  3194. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3195. int32_t status = 0;
  3196. DEBUGFUNC("e1000_write_eeprom");
  3197. /* A check for invalid values: offset too large, too many words, and not
  3198. * enough words.
  3199. */
  3200. if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
  3201. (words == 0)) {
  3202. DEBUGOUT("\"words\" parameter out of bounds\n");
  3203. return -E1000_ERR_EEPROM;
  3204. }
  3205. /* Prepare the EEPROM for writing */
  3206. if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
  3207. return -E1000_ERR_EEPROM;
  3208. if(eeprom->type == e1000_eeprom_microwire) {
  3209. status = e1000_write_eeprom_microwire(hw, offset, words, data);
  3210. } else {
  3211. status = e1000_write_eeprom_spi(hw, offset, words, data);
  3212. msec_delay(10);
  3213. }
  3214. /* Done with writing */
  3215. e1000_release_eeprom(hw);
  3216. return status;
  3217. }
  3218. /******************************************************************************
  3219. * Writes a 16 bit word to a given offset in an SPI EEPROM.
  3220. *
  3221. * hw - Struct containing variables accessed by shared code
  3222. * offset - offset within the EEPROM to be written to
  3223. * words - number of words to write
  3224. * data - pointer to array of 8 bit words to be written to the EEPROM
  3225. *
  3226. *****************************************************************************/
  3227. int32_t
  3228. e1000_write_eeprom_spi(struct e1000_hw *hw,
  3229. uint16_t offset,
  3230. uint16_t words,
  3231. uint16_t *data)
  3232. {
  3233. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3234. uint16_t widx = 0;
  3235. DEBUGFUNC("e1000_write_eeprom_spi");
  3236. while (widx < words) {
  3237. uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
  3238. if(e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
  3239. e1000_standby_eeprom(hw);
  3240. /* Send the WRITE ENABLE command (8 bit opcode ) */
  3241. e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
  3242. eeprom->opcode_bits);
  3243. e1000_standby_eeprom(hw);
  3244. /* Some SPI eeproms use the 8th address bit embedded in the opcode */
  3245. if((eeprom->address_bits == 8) && (offset >= 128))
  3246. write_opcode |= EEPROM_A8_OPCODE_SPI;
  3247. /* Send the Write command (8-bit opcode + addr) */
  3248. e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
  3249. e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
  3250. eeprom->address_bits);
  3251. /* Send the data */
  3252. /* Loop to allow for up to whole page write (32 bytes) of eeprom */
  3253. while (widx < words) {
  3254. uint16_t word_out = data[widx];
  3255. word_out = (word_out >> 8) | (word_out << 8);
  3256. e1000_shift_out_ee_bits(hw, word_out, 16);
  3257. widx++;
  3258. /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
  3259. * operation, while the smaller eeproms are capable of an 8-byte
  3260. * PAGE WRITE operation. Break the inner loop to pass new address
  3261. */
  3262. if((((offset + widx)*2) % eeprom->page_size) == 0) {
  3263. e1000_standby_eeprom(hw);
  3264. break;
  3265. }
  3266. }
  3267. }
  3268. return E1000_SUCCESS;
  3269. }
  3270. /******************************************************************************
  3271. * Writes a 16 bit word to a given offset in a Microwire EEPROM.
  3272. *
  3273. * hw - Struct containing variables accessed by shared code
  3274. * offset - offset within the EEPROM to be written to
  3275. * words - number of words to write
  3276. * data - pointer to array of 16 bit words to be written to the EEPROM
  3277. *
  3278. *****************************************************************************/
  3279. int32_t
  3280. e1000_write_eeprom_microwire(struct e1000_hw *hw,
  3281. uint16_t offset,
  3282. uint16_t words,
  3283. uint16_t *data)
  3284. {
  3285. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3286. uint32_t eecd;
  3287. uint16_t words_written = 0;
  3288. uint16_t i = 0;
  3289. DEBUGFUNC("e1000_write_eeprom_microwire");
  3290. /* Send the write enable command to the EEPROM (3-bit opcode plus
  3291. * 6/8-bit dummy address beginning with 11). It's less work to include
  3292. * the 11 of the dummy address as part of the opcode than it is to shift
  3293. * it over the correct number of bits for the address. This puts the
  3294. * EEPROM into write/erase mode.
  3295. */
  3296. e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
  3297. (uint16_t)(eeprom->opcode_bits + 2));
  3298. e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
  3299. /* Prepare the EEPROM */
  3300. e1000_standby_eeprom(hw);
  3301. while (words_written < words) {
  3302. /* Send the Write command (3-bit opcode + addr) */
  3303. e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
  3304. eeprom->opcode_bits);
  3305. e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
  3306. eeprom->address_bits);
  3307. /* Send the data */
  3308. e1000_shift_out_ee_bits(hw, data[words_written], 16);
  3309. /* Toggle the CS line. This in effect tells the EEPROM to execute
  3310. * the previous command.
  3311. */
  3312. e1000_standby_eeprom(hw);
  3313. /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
  3314. * signal that the command has been completed by raising the DO signal.
  3315. * If DO does not go high in 10 milliseconds, then error out.
  3316. */
  3317. for(i = 0; i < 200; i++) {
  3318. eecd = E1000_READ_REG(hw, EECD);
  3319. if(eecd & E1000_EECD_DO) break;
  3320. udelay(50);
  3321. }
  3322. if(i == 200) {
  3323. DEBUGOUT("EEPROM Write did not complete\n");
  3324. return -E1000_ERR_EEPROM;
  3325. }
  3326. /* Recover from write */
  3327. e1000_standby_eeprom(hw);
  3328. words_written++;
  3329. }
  3330. /* Send the write disable command to the EEPROM (3-bit opcode plus
  3331. * 6/8-bit dummy address beginning with 10). It's less work to include
  3332. * the 10 of the dummy address as part of the opcode than it is to shift
  3333. * it over the correct number of bits for the address. This takes the
  3334. * EEPROM out of write/erase mode.
  3335. */
  3336. e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
  3337. (uint16_t)(eeprom->opcode_bits + 2));
  3338. e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
  3339. return E1000_SUCCESS;
  3340. }
  3341. /******************************************************************************
  3342. * Reads the adapter's part number from the EEPROM
  3343. *
  3344. * hw - Struct containing variables accessed by shared code
  3345. * part_num - Adapter's part number
  3346. *****************************************************************************/
  3347. int32_t
  3348. e1000_read_part_num(struct e1000_hw *hw,
  3349. uint32_t *part_num)
  3350. {
  3351. uint16_t offset = EEPROM_PBA_BYTE_1;
  3352. uint16_t eeprom_data;
  3353. DEBUGFUNC("e1000_read_part_num");
  3354. /* Get word 0 from EEPROM */
  3355. if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
  3356. DEBUGOUT("EEPROM Read Error\n");
  3357. return -E1000_ERR_EEPROM;
  3358. }
  3359. /* Save word 0 in upper half of part_num */
  3360. *part_num = (uint32_t) (eeprom_data << 16);
  3361. /* Get word 1 from EEPROM */
  3362. if(e1000_read_eeprom(hw, ++offset, 1, &eeprom_data) < 0) {
  3363. DEBUGOUT("EEPROM Read Error\n");
  3364. return -E1000_ERR_EEPROM;
  3365. }
  3366. /* Save word 1 in lower half of part_num */
  3367. *part_num |= eeprom_data;
  3368. return E1000_SUCCESS;
  3369. }
  3370. /******************************************************************************
  3371. * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
  3372. * second function of dual function devices
  3373. *
  3374. * hw - Struct containing variables accessed by shared code
  3375. *****************************************************************************/
  3376. int32_t
  3377. e1000_read_mac_addr(struct e1000_hw * hw)
  3378. {
  3379. uint16_t offset;
  3380. uint16_t eeprom_data, i;
  3381. DEBUGFUNC("e1000_read_mac_addr");
  3382. for(i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
  3383. offset = i >> 1;
  3384. if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
  3385. DEBUGOUT("EEPROM Read Error\n");
  3386. return -E1000_ERR_EEPROM;
  3387. }
  3388. hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
  3389. hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
  3390. }
  3391. if(((hw->mac_type == e1000_82546) || (hw->mac_type == e1000_82546_rev_3)) &&
  3392. (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1))
  3393. hw->perm_mac_addr[5] ^= 0x01;
  3394. for(i = 0; i < NODE_ADDRESS_SIZE; i++)
  3395. hw->mac_addr[i] = hw->perm_mac_addr[i];
  3396. return E1000_SUCCESS;
  3397. }
  3398. /******************************************************************************
  3399. * Initializes receive address filters.
  3400. *
  3401. * hw - Struct containing variables accessed by shared code
  3402. *
  3403. * Places the MAC address in receive address register 0 and clears the rest
  3404. * of the receive addresss registers. Clears the multicast table. Assumes
  3405. * the receiver is in reset when the routine is called.
  3406. *****************************************************************************/
  3407. void
  3408. e1000_init_rx_addrs(struct e1000_hw *hw)
  3409. {
  3410. uint32_t i;
  3411. DEBUGFUNC("e1000_init_rx_addrs");
  3412. /* Setup the receive address. */
  3413. DEBUGOUT("Programming MAC Address into RAR[0]\n");
  3414. e1000_rar_set(hw, hw->mac_addr, 0);
  3415. /* Zero out the other 15 receive addresses. */
  3416. DEBUGOUT("Clearing RAR[1-15]\n");
  3417. for(i = 1; i < E1000_RAR_ENTRIES; i++) {
  3418. E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
  3419. E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
  3420. }
  3421. }
  3422. /******************************************************************************
  3423. * Updates the MAC's list of multicast addresses.
  3424. *
  3425. * hw - Struct containing variables accessed by shared code
  3426. * mc_addr_list - the list of new multicast addresses
  3427. * mc_addr_count - number of addresses
  3428. * pad - number of bytes between addresses in the list
  3429. * rar_used_count - offset where to start adding mc addresses into the RAR's
  3430. *
  3431. * The given list replaces any existing list. Clears the last 15 receive
  3432. * address registers and the multicast table. Uses receive address registers
  3433. * for the first 15 multicast addresses, and hashes the rest into the
  3434. * multicast table.
  3435. *****************************************************************************/
  3436. void
  3437. e1000_mc_addr_list_update(struct e1000_hw *hw,
  3438. uint8_t *mc_addr_list,
  3439. uint32_t mc_addr_count,
  3440. uint32_t pad,
  3441. uint32_t rar_used_count)
  3442. {
  3443. uint32_t hash_value;
  3444. uint32_t i;
  3445. DEBUGFUNC("e1000_mc_addr_list_update");
  3446. /* Set the new number of MC addresses that we are being requested to use. */
  3447. hw->num_mc_addrs = mc_addr_count;
  3448. /* Clear RAR[1-15] */
  3449. DEBUGOUT(" Clearing RAR[1-15]\n");
  3450. for(i = rar_used_count; i < E1000_RAR_ENTRIES; i++) {
  3451. E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
  3452. E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
  3453. }
  3454. /* Clear the MTA */
  3455. DEBUGOUT(" Clearing MTA\n");
  3456. for(i = 0; i < E1000_NUM_MTA_REGISTERS; i++) {
  3457. E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
  3458. }
  3459. /* Add the new addresses */
  3460. for(i = 0; i < mc_addr_count; i++) {
  3461. DEBUGOUT(" Adding the multicast addresses:\n");
  3462. DEBUGOUT7(" MC Addr #%d =%.2X %.2X %.2X %.2X %.2X %.2X\n", i,
  3463. mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad)],
  3464. mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 1],
  3465. mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 2],
  3466. mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 3],
  3467. mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 4],
  3468. mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 5]);
  3469. hash_value = e1000_hash_mc_addr(hw,
  3470. mc_addr_list +
  3471. (i * (ETH_LENGTH_OF_ADDRESS + pad)));
  3472. DEBUGOUT1(" Hash value = 0x%03X\n", hash_value);
  3473. /* Place this multicast address in the RAR if there is room, *
  3474. * else put it in the MTA
  3475. */
  3476. if(rar_used_count < E1000_RAR_ENTRIES) {
  3477. e1000_rar_set(hw,
  3478. mc_addr_list + (i * (ETH_LENGTH_OF_ADDRESS + pad)),
  3479. rar_used_count);
  3480. rar_used_count++;
  3481. } else {
  3482. e1000_mta_set(hw, hash_value);
  3483. }
  3484. }
  3485. DEBUGOUT("MC Update Complete\n");
  3486. }
  3487. /******************************************************************************
  3488. * Hashes an address to determine its location in the multicast table
  3489. *
  3490. * hw - Struct containing variables accessed by shared code
  3491. * mc_addr - the multicast address to hash
  3492. *****************************************************************************/
  3493. uint32_t
  3494. e1000_hash_mc_addr(struct e1000_hw *hw,
  3495. uint8_t *mc_addr)
  3496. {
  3497. uint32_t hash_value = 0;
  3498. /* The portion of the address that is used for the hash table is
  3499. * determined by the mc_filter_type setting.
  3500. */
  3501. switch (hw->mc_filter_type) {
  3502. /* [0] [1] [2] [3] [4] [5]
  3503. * 01 AA 00 12 34 56
  3504. * LSB MSB
  3505. */
  3506. case 0:
  3507. /* [47:36] i.e. 0x563 for above example address */
  3508. hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
  3509. break;
  3510. case 1:
  3511. /* [46:35] i.e. 0xAC6 for above example address */
  3512. hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
  3513. break;
  3514. case 2:
  3515. /* [45:34] i.e. 0x5D8 for above example address */
  3516. hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
  3517. break;
  3518. case 3:
  3519. /* [43:32] i.e. 0x634 for above example address */
  3520. hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
  3521. break;
  3522. }
  3523. hash_value &= 0xFFF;
  3524. return hash_value;
  3525. }
  3526. /******************************************************************************
  3527. * Sets the bit in the multicast table corresponding to the hash value.
  3528. *
  3529. * hw - Struct containing variables accessed by shared code
  3530. * hash_value - Multicast address hash value
  3531. *****************************************************************************/
  3532. void
  3533. e1000_mta_set(struct e1000_hw *hw,
  3534. uint32_t hash_value)
  3535. {
  3536. uint32_t hash_bit, hash_reg;
  3537. uint32_t mta;
  3538. uint32_t temp;
  3539. /* The MTA is a register array of 128 32-bit registers.
  3540. * It is treated like an array of 4096 bits. We want to set
  3541. * bit BitArray[hash_value]. So we figure out what register
  3542. * the bit is in, read it, OR in the new bit, then write
  3543. * back the new value. The register is determined by the
  3544. * upper 7 bits of the hash value and the bit within that
  3545. * register are determined by the lower 5 bits of the value.
  3546. */
  3547. hash_reg = (hash_value >> 5) & 0x7F;
  3548. hash_bit = hash_value & 0x1F;
  3549. mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
  3550. mta |= (1 << hash_bit);
  3551. /* If we are on an 82544 and we are trying to write an odd offset
  3552. * in the MTA, save off the previous entry before writing and
  3553. * restore the old value after writing.
  3554. */
  3555. if((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
  3556. temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
  3557. E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
  3558. E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
  3559. } else {
  3560. E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
  3561. }
  3562. }
  3563. /******************************************************************************
  3564. * Puts an ethernet address into a receive address register.
  3565. *
  3566. * hw - Struct containing variables accessed by shared code
  3567. * addr - Address to put into receive address register
  3568. * index - Receive address register to write
  3569. *****************************************************************************/
  3570. void
  3571. e1000_rar_set(struct e1000_hw *hw,
  3572. uint8_t *addr,
  3573. uint32_t index)
  3574. {
  3575. uint32_t rar_low, rar_high;
  3576. /* HW expects these in little endian so we reverse the byte order
  3577. * from network order (big endian) to little endian
  3578. */
  3579. rar_low = ((uint32_t) addr[0] |
  3580. ((uint32_t) addr[1] << 8) |
  3581. ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
  3582. rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8) | E1000_RAH_AV);
  3583. E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
  3584. E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
  3585. }
  3586. /******************************************************************************
  3587. * Writes a value to the specified offset in the VLAN filter table.
  3588. *
  3589. * hw - Struct containing variables accessed by shared code
  3590. * offset - Offset in VLAN filer table to write
  3591. * value - Value to write into VLAN filter table
  3592. *****************************************************************************/
  3593. void
  3594. e1000_write_vfta(struct e1000_hw *hw,
  3595. uint32_t offset,
  3596. uint32_t value)
  3597. {
  3598. uint32_t temp;
  3599. if((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
  3600. temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
  3601. E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
  3602. E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
  3603. } else {
  3604. E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
  3605. }
  3606. }
  3607. /******************************************************************************
  3608. * Clears the VLAN filer table
  3609. *
  3610. * hw - Struct containing variables accessed by shared code
  3611. *****************************************************************************/
  3612. void
  3613. e1000_clear_vfta(struct e1000_hw *hw)
  3614. {
  3615. uint32_t offset;
  3616. for(offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++)
  3617. E1000_WRITE_REG_ARRAY(hw, VFTA, offset, 0);
  3618. }
  3619. static int32_t
  3620. e1000_id_led_init(struct e1000_hw * hw)
  3621. {
  3622. uint32_t ledctl;
  3623. const uint32_t ledctl_mask = 0x000000FF;
  3624. const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
  3625. const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
  3626. uint16_t eeprom_data, i, temp;
  3627. const uint16_t led_mask = 0x0F;
  3628. DEBUGFUNC("e1000_id_led_init");
  3629. if(hw->mac_type < e1000_82540) {
  3630. /* Nothing to do */
  3631. return E1000_SUCCESS;
  3632. }
  3633. ledctl = E1000_READ_REG(hw, LEDCTL);
  3634. hw->ledctl_default = ledctl;
  3635. hw->ledctl_mode1 = hw->ledctl_default;
  3636. hw->ledctl_mode2 = hw->ledctl_default;
  3637. if(e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
  3638. DEBUGOUT("EEPROM Read Error\n");
  3639. return -E1000_ERR_EEPROM;
  3640. }
  3641. if((eeprom_data== ID_LED_RESERVED_0000) ||
  3642. (eeprom_data == ID_LED_RESERVED_FFFF)) eeprom_data = ID_LED_DEFAULT;
  3643. for(i = 0; i < 4; i++) {
  3644. temp = (eeprom_data >> (i << 2)) & led_mask;
  3645. switch(temp) {
  3646. case ID_LED_ON1_DEF2:
  3647. case ID_LED_ON1_ON2:
  3648. case ID_LED_ON1_OFF2:
  3649. hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
  3650. hw->ledctl_mode1 |= ledctl_on << (i << 3);
  3651. break;
  3652. case ID_LED_OFF1_DEF2:
  3653. case ID_LED_OFF1_ON2:
  3654. case ID_LED_OFF1_OFF2:
  3655. hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
  3656. hw->ledctl_mode1 |= ledctl_off << (i << 3);
  3657. break;
  3658. default:
  3659. /* Do nothing */
  3660. break;
  3661. }
  3662. switch(temp) {
  3663. case ID_LED_DEF1_ON2:
  3664. case ID_LED_ON1_ON2:
  3665. case ID_LED_OFF1_ON2:
  3666. hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
  3667. hw->ledctl_mode2 |= ledctl_on << (i << 3);
  3668. break;
  3669. case ID_LED_DEF1_OFF2:
  3670. case ID_LED_ON1_OFF2:
  3671. case ID_LED_OFF1_OFF2:
  3672. hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
  3673. hw->ledctl_mode2 |= ledctl_off << (i << 3);
  3674. break;
  3675. default:
  3676. /* Do nothing */
  3677. break;
  3678. }
  3679. }
  3680. return E1000_SUCCESS;
  3681. }
  3682. /******************************************************************************
  3683. * Prepares SW controlable LED for use and saves the current state of the LED.
  3684. *
  3685. * hw - Struct containing variables accessed by shared code
  3686. *****************************************************************************/
  3687. int32_t
  3688. e1000_setup_led(struct e1000_hw *hw)
  3689. {
  3690. uint32_t ledctl;
  3691. int32_t ret_val = E1000_SUCCESS;
  3692. DEBUGFUNC("e1000_setup_led");
  3693. switch(hw->mac_type) {
  3694. case e1000_82542_rev2_0:
  3695. case e1000_82542_rev2_1:
  3696. case e1000_82543:
  3697. case e1000_82544:
  3698. /* No setup necessary */
  3699. break;
  3700. case e1000_82541:
  3701. case e1000_82547:
  3702. case e1000_82541_rev_2:
  3703. case e1000_82547_rev_2:
  3704. /* Turn off PHY Smart Power Down (if enabled) */
  3705. ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
  3706. &hw->phy_spd_default);
  3707. if(ret_val)
  3708. return ret_val;
  3709. ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
  3710. (uint16_t)(hw->phy_spd_default &
  3711. ~IGP01E1000_GMII_SPD));
  3712. if(ret_val)
  3713. return ret_val;
  3714. /* Fall Through */
  3715. default:
  3716. if(hw->media_type == e1000_media_type_fiber) {
  3717. ledctl = E1000_READ_REG(hw, LEDCTL);
  3718. /* Save current LEDCTL settings */
  3719. hw->ledctl_default = ledctl;
  3720. /* Turn off LED0 */
  3721. ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
  3722. E1000_LEDCTL_LED0_BLINK |
  3723. E1000_LEDCTL_LED0_MODE_MASK);
  3724. ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
  3725. E1000_LEDCTL_LED0_MODE_SHIFT);
  3726. E1000_WRITE_REG(hw, LEDCTL, ledctl);
  3727. } else if(hw->media_type == e1000_media_type_copper)
  3728. E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
  3729. break;
  3730. }
  3731. return E1000_SUCCESS;
  3732. }
  3733. /******************************************************************************
  3734. * Restores the saved state of the SW controlable LED.
  3735. *
  3736. * hw - Struct containing variables accessed by shared code
  3737. *****************************************************************************/
  3738. int32_t
  3739. e1000_cleanup_led(struct e1000_hw *hw)
  3740. {
  3741. int32_t ret_val = E1000_SUCCESS;
  3742. DEBUGFUNC("e1000_cleanup_led");
  3743. switch(hw->mac_type) {
  3744. case e1000_82542_rev2_0:
  3745. case e1000_82542_rev2_1:
  3746. case e1000_82543:
  3747. case e1000_82544:
  3748. /* No cleanup necessary */
  3749. break;
  3750. case e1000_82541:
  3751. case e1000_82547:
  3752. case e1000_82541_rev_2:
  3753. case e1000_82547_rev_2:
  3754. /* Turn on PHY Smart Power Down (if previously enabled) */
  3755. ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
  3756. hw->phy_spd_default);
  3757. if(ret_val)
  3758. return ret_val;
  3759. /* Fall Through */
  3760. default:
  3761. /* Restore LEDCTL settings */
  3762. E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
  3763. break;
  3764. }
  3765. return E1000_SUCCESS;
  3766. }
  3767. /******************************************************************************
  3768. * Turns on the software controllable LED
  3769. *
  3770. * hw - Struct containing variables accessed by shared code
  3771. *****************************************************************************/
  3772. int32_t
  3773. e1000_led_on(struct e1000_hw *hw)
  3774. {
  3775. uint32_t ctrl = E1000_READ_REG(hw, CTRL);
  3776. DEBUGFUNC("e1000_led_on");
  3777. switch(hw->mac_type) {
  3778. case e1000_82542_rev2_0:
  3779. case e1000_82542_rev2_1:
  3780. case e1000_82543:
  3781. /* Set SW Defineable Pin 0 to turn on the LED */
  3782. ctrl |= E1000_CTRL_SWDPIN0;
  3783. ctrl |= E1000_CTRL_SWDPIO0;
  3784. break;
  3785. case e1000_82544:
  3786. if(hw->media_type == e1000_media_type_fiber) {
  3787. /* Set SW Defineable Pin 0 to turn on the LED */
  3788. ctrl |= E1000_CTRL_SWDPIN0;
  3789. ctrl |= E1000_CTRL_SWDPIO0;
  3790. } else {
  3791. /* Clear SW Defineable Pin 0 to turn on the LED */
  3792. ctrl &= ~E1000_CTRL_SWDPIN0;
  3793. ctrl |= E1000_CTRL_SWDPIO0;
  3794. }
  3795. break;
  3796. default:
  3797. if(hw->media_type == e1000_media_type_fiber) {
  3798. /* Clear SW Defineable Pin 0 to turn on the LED */
  3799. ctrl &= ~E1000_CTRL_SWDPIN0;
  3800. ctrl |= E1000_CTRL_SWDPIO0;
  3801. } else if(hw->media_type == e1000_media_type_copper) {
  3802. E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
  3803. return E1000_SUCCESS;
  3804. }
  3805. break;
  3806. }
  3807. E1000_WRITE_REG(hw, CTRL, ctrl);
  3808. return E1000_SUCCESS;
  3809. }
  3810. /******************************************************************************
  3811. * Turns off the software controllable LED
  3812. *
  3813. * hw - Struct containing variables accessed by shared code
  3814. *****************************************************************************/
  3815. int32_t
  3816. e1000_led_off(struct e1000_hw *hw)
  3817. {
  3818. uint32_t ctrl = E1000_READ_REG(hw, CTRL);
  3819. DEBUGFUNC("e1000_led_off");
  3820. switch(hw->mac_type) {
  3821. case e1000_82542_rev2_0:
  3822. case e1000_82542_rev2_1:
  3823. case e1000_82543:
  3824. /* Clear SW Defineable Pin 0 to turn off the LED */
  3825. ctrl &= ~E1000_CTRL_SWDPIN0;
  3826. ctrl |= E1000_CTRL_SWDPIO0;
  3827. break;
  3828. case e1000_82544:
  3829. if(hw->media_type == e1000_media_type_fiber) {
  3830. /* Clear SW Defineable Pin 0 to turn off the LED */
  3831. ctrl &= ~E1000_CTRL_SWDPIN0;
  3832. ctrl |= E1000_CTRL_SWDPIO0;
  3833. } else {
  3834. /* Set SW Defineable Pin 0 to turn off the LED */
  3835. ctrl |= E1000_CTRL_SWDPIN0;
  3836. ctrl |= E1000_CTRL_SWDPIO0;
  3837. }
  3838. break;
  3839. default:
  3840. if(hw->media_type == e1000_media_type_fiber) {
  3841. /* Set SW Defineable Pin 0 to turn off the LED */
  3842. ctrl |= E1000_CTRL_SWDPIN0;
  3843. ctrl |= E1000_CTRL_SWDPIO0;
  3844. } else if(hw->media_type == e1000_media_type_copper) {
  3845. E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
  3846. return E1000_SUCCESS;
  3847. }
  3848. break;
  3849. }
  3850. E1000_WRITE_REG(hw, CTRL, ctrl);
  3851. return E1000_SUCCESS;
  3852. }
  3853. /******************************************************************************
  3854. * Clears all hardware statistics counters.
  3855. *
  3856. * hw - Struct containing variables accessed by shared code
  3857. *****************************************************************************/
  3858. void
  3859. e1000_clear_hw_cntrs(struct e1000_hw *hw)
  3860. {
  3861. volatile uint32_t temp;
  3862. temp = E1000_READ_REG(hw, CRCERRS);
  3863. temp = E1000_READ_REG(hw, SYMERRS);
  3864. temp = E1000_READ_REG(hw, MPC);
  3865. temp = E1000_READ_REG(hw, SCC);
  3866. temp = E1000_READ_REG(hw, ECOL);
  3867. temp = E1000_READ_REG(hw, MCC);
  3868. temp = E1000_READ_REG(hw, LATECOL);
  3869. temp = E1000_READ_REG(hw, COLC);
  3870. temp = E1000_READ_REG(hw, DC);
  3871. temp = E1000_READ_REG(hw, SEC);
  3872. temp = E1000_READ_REG(hw, RLEC);
  3873. temp = E1000_READ_REG(hw, XONRXC);
  3874. temp = E1000_READ_REG(hw, XONTXC);
  3875. temp = E1000_READ_REG(hw, XOFFRXC);
  3876. temp = E1000_READ_REG(hw, XOFFTXC);
  3877. temp = E1000_READ_REG(hw, FCRUC);
  3878. temp = E1000_READ_REG(hw, PRC64);
  3879. temp = E1000_READ_REG(hw, PRC127);
  3880. temp = E1000_READ_REG(hw, PRC255);
  3881. temp = E1000_READ_REG(hw, PRC511);
  3882. temp = E1000_READ_REG(hw, PRC1023);
  3883. temp = E1000_READ_REG(hw, PRC1522);
  3884. temp = E1000_READ_REG(hw, GPRC);
  3885. temp = E1000_READ_REG(hw, BPRC);
  3886. temp = E1000_READ_REG(hw, MPRC);
  3887. temp = E1000_READ_REG(hw, GPTC);
  3888. temp = E1000_READ_REG(hw, GORCL);
  3889. temp = E1000_READ_REG(hw, GORCH);
  3890. temp = E1000_READ_REG(hw, GOTCL);
  3891. temp = E1000_READ_REG(hw, GOTCH);
  3892. temp = E1000_READ_REG(hw, RNBC);
  3893. temp = E1000_READ_REG(hw, RUC);
  3894. temp = E1000_READ_REG(hw, RFC);
  3895. temp = E1000_READ_REG(hw, ROC);
  3896. temp = E1000_READ_REG(hw, RJC);
  3897. temp = E1000_READ_REG(hw, TORL);
  3898. temp = E1000_READ_REG(hw, TORH);
  3899. temp = E1000_READ_REG(hw, TOTL);
  3900. temp = E1000_READ_REG(hw, TOTH);
  3901. temp = E1000_READ_REG(hw, TPR);
  3902. temp = E1000_READ_REG(hw, TPT);
  3903. temp = E1000_READ_REG(hw, PTC64);
  3904. temp = E1000_READ_REG(hw, PTC127);
  3905. temp = E1000_READ_REG(hw, PTC255);
  3906. temp = E1000_READ_REG(hw, PTC511);
  3907. temp = E1000_READ_REG(hw, PTC1023);
  3908. temp = E1000_READ_REG(hw, PTC1522);
  3909. temp = E1000_READ_REG(hw, MPTC);
  3910. temp = E1000_READ_REG(hw, BPTC);
  3911. if(hw->mac_type < e1000_82543) return;
  3912. temp = E1000_READ_REG(hw, ALGNERRC);
  3913. temp = E1000_READ_REG(hw, RXERRC);
  3914. temp = E1000_READ_REG(hw, TNCRS);
  3915. temp = E1000_READ_REG(hw, CEXTERR);
  3916. temp = E1000_READ_REG(hw, TSCTC);
  3917. temp = E1000_READ_REG(hw, TSCTFC);
  3918. if(hw->mac_type <= e1000_82544) return;
  3919. temp = E1000_READ_REG(hw, MGTPRC);
  3920. temp = E1000_READ_REG(hw, MGTPDC);
  3921. temp = E1000_READ_REG(hw, MGTPTC);
  3922. }
  3923. /******************************************************************************
  3924. * Resets Adaptive IFS to its default state.
  3925. *
  3926. * hw - Struct containing variables accessed by shared code
  3927. *
  3928. * Call this after e1000_init_hw. You may override the IFS defaults by setting
  3929. * hw->ifs_params_forced to TRUE. However, you must initialize hw->
  3930. * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
  3931. * before calling this function.
  3932. *****************************************************************************/
  3933. void
  3934. e1000_reset_adaptive(struct e1000_hw *hw)
  3935. {
  3936. DEBUGFUNC("e1000_reset_adaptive");
  3937. if(hw->adaptive_ifs) {
  3938. if(!hw->ifs_params_forced) {
  3939. hw->current_ifs_val = 0;
  3940. hw->ifs_min_val = IFS_MIN;
  3941. hw->ifs_max_val = IFS_MAX;
  3942. hw->ifs_step_size = IFS_STEP;
  3943. hw->ifs_ratio = IFS_RATIO;
  3944. }
  3945. hw->in_ifs_mode = FALSE;
  3946. E1000_WRITE_REG(hw, AIT, 0);
  3947. } else {
  3948. DEBUGOUT("Not in Adaptive IFS mode!\n");
  3949. }
  3950. }
  3951. /******************************************************************************
  3952. * Called during the callback/watchdog routine to update IFS value based on
  3953. * the ratio of transmits to collisions.
  3954. *
  3955. * hw - Struct containing variables accessed by shared code
  3956. * tx_packets - Number of transmits since last callback
  3957. * total_collisions - Number of collisions since last callback
  3958. *****************************************************************************/
  3959. void
  3960. e1000_update_adaptive(struct e1000_hw *hw)
  3961. {
  3962. DEBUGFUNC("e1000_update_adaptive");
  3963. if(hw->adaptive_ifs) {
  3964. if((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
  3965. if(hw->tx_packet_delta > MIN_NUM_XMITS) {
  3966. hw->in_ifs_mode = TRUE;
  3967. if(hw->current_ifs_val < hw->ifs_max_val) {
  3968. if(hw->current_ifs_val == 0)
  3969. hw->current_ifs_val = hw->ifs_min_val;
  3970. else
  3971. hw->current_ifs_val += hw->ifs_step_size;
  3972. E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
  3973. }
  3974. }
  3975. } else {
  3976. if(hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
  3977. hw->current_ifs_val = 0;
  3978. hw->in_ifs_mode = FALSE;
  3979. E1000_WRITE_REG(hw, AIT, 0);
  3980. }
  3981. }
  3982. } else {
  3983. DEBUGOUT("Not in Adaptive IFS mode!\n");
  3984. }
  3985. }
  3986. /******************************************************************************
  3987. * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
  3988. *
  3989. * hw - Struct containing variables accessed by shared code
  3990. * frame_len - The length of the frame in question
  3991. * mac_addr - The Ethernet destination address of the frame in question
  3992. *****************************************************************************/
  3993. void
  3994. e1000_tbi_adjust_stats(struct e1000_hw *hw,
  3995. struct e1000_hw_stats *stats,
  3996. uint32_t frame_len,
  3997. uint8_t *mac_addr)
  3998. {
  3999. uint64_t carry_bit;
  4000. /* First adjust the frame length. */
  4001. frame_len--;
  4002. /* We need to adjust the statistics counters, since the hardware
  4003. * counters overcount this packet as a CRC error and undercount
  4004. * the packet as a good packet
  4005. */
  4006. /* This packet should not be counted as a CRC error. */
  4007. stats->crcerrs--;
  4008. /* This packet does count as a Good Packet Received. */
  4009. stats->gprc++;
  4010. /* Adjust the Good Octets received counters */
  4011. carry_bit = 0x80000000 & stats->gorcl;
  4012. stats->gorcl += frame_len;
  4013. /* If the high bit of Gorcl (the low 32 bits of the Good Octets
  4014. * Received Count) was one before the addition,
  4015. * AND it is zero after, then we lost the carry out,
  4016. * need to add one to Gorch (Good Octets Received Count High).
  4017. * This could be simplified if all environments supported
  4018. * 64-bit integers.
  4019. */
  4020. if(carry_bit && ((stats->gorcl & 0x80000000) == 0))
  4021. stats->gorch++;
  4022. /* Is this a broadcast or multicast? Check broadcast first,
  4023. * since the test for a multicast frame will test positive on
  4024. * a broadcast frame.
  4025. */
  4026. if((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
  4027. /* Broadcast packet */
  4028. stats->bprc++;
  4029. else if(*mac_addr & 0x01)
  4030. /* Multicast packet */
  4031. stats->mprc++;
  4032. if(frame_len == hw->max_frame_size) {
  4033. /* In this case, the hardware has overcounted the number of
  4034. * oversize frames.
  4035. */
  4036. if(stats->roc > 0)
  4037. stats->roc--;
  4038. }
  4039. /* Adjust the bin counters when the extra byte put the frame in the
  4040. * wrong bin. Remember that the frame_len was adjusted above.
  4041. */
  4042. if(frame_len == 64) {
  4043. stats->prc64++;
  4044. stats->prc127--;
  4045. } else if(frame_len == 127) {
  4046. stats->prc127++;
  4047. stats->prc255--;
  4048. } else if(frame_len == 255) {
  4049. stats->prc255++;
  4050. stats->prc511--;
  4051. } else if(frame_len == 511) {
  4052. stats->prc511++;
  4053. stats->prc1023--;
  4054. } else if(frame_len == 1023) {
  4055. stats->prc1023++;
  4056. stats->prc1522--;
  4057. } else if(frame_len == 1522) {
  4058. stats->prc1522++;
  4059. }
  4060. }
  4061. /******************************************************************************
  4062. * Gets the current PCI bus type, speed, and width of the hardware
  4063. *
  4064. * hw - Struct containing variables accessed by shared code
  4065. *****************************************************************************/
  4066. void
  4067. e1000_get_bus_info(struct e1000_hw *hw)
  4068. {
  4069. uint32_t status;
  4070. switch (hw->mac_type) {
  4071. case e1000_82542_rev2_0:
  4072. case e1000_82542_rev2_1:
  4073. hw->bus_type = e1000_bus_type_unknown;
  4074. hw->bus_speed = e1000_bus_speed_unknown;
  4075. hw->bus_width = e1000_bus_width_unknown;
  4076. break;
  4077. default:
  4078. status = E1000_READ_REG(hw, STATUS);
  4079. hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
  4080. e1000_bus_type_pcix : e1000_bus_type_pci;
  4081. if(hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
  4082. hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
  4083. e1000_bus_speed_66 : e1000_bus_speed_120;
  4084. } else if(hw->bus_type == e1000_bus_type_pci) {
  4085. hw->bus_speed = (status & E1000_STATUS_PCI66) ?
  4086. e1000_bus_speed_66 : e1000_bus_speed_33;
  4087. } else {
  4088. switch (status & E1000_STATUS_PCIX_SPEED) {
  4089. case E1000_STATUS_PCIX_SPEED_66:
  4090. hw->bus_speed = e1000_bus_speed_66;
  4091. break;
  4092. case E1000_STATUS_PCIX_SPEED_100:
  4093. hw->bus_speed = e1000_bus_speed_100;
  4094. break;
  4095. case E1000_STATUS_PCIX_SPEED_133:
  4096. hw->bus_speed = e1000_bus_speed_133;
  4097. break;
  4098. default:
  4099. hw->bus_speed = e1000_bus_speed_reserved;
  4100. break;
  4101. }
  4102. }
  4103. hw->bus_width = (status & E1000_STATUS_BUS64) ?
  4104. e1000_bus_width_64 : e1000_bus_width_32;
  4105. break;
  4106. }
  4107. }
  4108. /******************************************************************************
  4109. * Reads a value from one of the devices registers using port I/O (as opposed
  4110. * memory mapped I/O). Only 82544 and newer devices support port I/O.
  4111. *
  4112. * hw - Struct containing variables accessed by shared code
  4113. * offset - offset to read from
  4114. *****************************************************************************/
  4115. uint32_t
  4116. e1000_read_reg_io(struct e1000_hw *hw,
  4117. uint32_t offset)
  4118. {
  4119. unsigned long io_addr = hw->io_base;
  4120. unsigned long io_data = hw->io_base + 4;
  4121. e1000_io_write(hw, io_addr, offset);
  4122. return e1000_io_read(hw, io_data);
  4123. }
  4124. /******************************************************************************
  4125. * Writes a value to one of the devices registers using port I/O (as opposed to
  4126. * memory mapped I/O). Only 82544 and newer devices support port I/O.
  4127. *
  4128. * hw - Struct containing variables accessed by shared code
  4129. * offset - offset to write to
  4130. * value - value to write
  4131. *****************************************************************************/
  4132. void
  4133. e1000_write_reg_io(struct e1000_hw *hw,
  4134. uint32_t offset,
  4135. uint32_t value)
  4136. {
  4137. unsigned long io_addr = hw->io_base;
  4138. unsigned long io_data = hw->io_base + 4;
  4139. e1000_io_write(hw, io_addr, offset);
  4140. e1000_io_write(hw, io_data, value);
  4141. }
  4142. /******************************************************************************
  4143. * Estimates the cable length.
  4144. *
  4145. * hw - Struct containing variables accessed by shared code
  4146. * min_length - The estimated minimum length
  4147. * max_length - The estimated maximum length
  4148. *
  4149. * returns: - E1000_ERR_XXX
  4150. * E1000_SUCCESS
  4151. *
  4152. * This function always returns a ranged length (minimum & maximum).
  4153. * So for M88 phy's, this function interprets the one value returned from the
  4154. * register to the minimum and maximum range.
  4155. * For IGP phy's, the function calculates the range by the AGC registers.
  4156. *****************************************************************************/
  4157. int32_t
  4158. e1000_get_cable_length(struct e1000_hw *hw,
  4159. uint16_t *min_length,
  4160. uint16_t *max_length)
  4161. {
  4162. int32_t ret_val;
  4163. uint16_t agc_value = 0;
  4164. uint16_t cur_agc, min_agc = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
  4165. uint16_t i, phy_data;
  4166. uint16_t cable_length;
  4167. DEBUGFUNC("e1000_get_cable_length");
  4168. *min_length = *max_length = 0;
  4169. /* Use old method for Phy older than IGP */
  4170. if(hw->phy_type == e1000_phy_m88) {
  4171. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
  4172. &phy_data);
  4173. if(ret_val)
  4174. return ret_val;
  4175. cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
  4176. M88E1000_PSSR_CABLE_LENGTH_SHIFT;
  4177. /* Convert the enum value to ranged values */
  4178. switch (cable_length) {
  4179. case e1000_cable_length_50:
  4180. *min_length = 0;
  4181. *max_length = e1000_igp_cable_length_50;
  4182. break;
  4183. case e1000_cable_length_50_80:
  4184. *min_length = e1000_igp_cable_length_50;
  4185. *max_length = e1000_igp_cable_length_80;
  4186. break;
  4187. case e1000_cable_length_80_110:
  4188. *min_length = e1000_igp_cable_length_80;
  4189. *max_length = e1000_igp_cable_length_110;
  4190. break;
  4191. case e1000_cable_length_110_140:
  4192. *min_length = e1000_igp_cable_length_110;
  4193. *max_length = e1000_igp_cable_length_140;
  4194. break;
  4195. case e1000_cable_length_140:
  4196. *min_length = e1000_igp_cable_length_140;
  4197. *max_length = e1000_igp_cable_length_170;
  4198. break;
  4199. default:
  4200. return -E1000_ERR_PHY;
  4201. break;
  4202. }
  4203. } else if(hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
  4204. uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
  4205. {IGP01E1000_PHY_AGC_A,
  4206. IGP01E1000_PHY_AGC_B,
  4207. IGP01E1000_PHY_AGC_C,
  4208. IGP01E1000_PHY_AGC_D};
  4209. /* Read the AGC registers for all channels */
  4210. for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
  4211. ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
  4212. if(ret_val)
  4213. return ret_val;
  4214. cur_agc = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
  4215. /* Array bound check. */
  4216. if((cur_agc >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
  4217. (cur_agc == 0))
  4218. return -E1000_ERR_PHY;
  4219. agc_value += cur_agc;
  4220. /* Update minimal AGC value. */
  4221. if(min_agc > cur_agc)
  4222. min_agc = cur_agc;
  4223. }
  4224. /* Remove the minimal AGC result for length < 50m */
  4225. if(agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
  4226. agc_value -= min_agc;
  4227. /* Get the average length of the remaining 3 channels */
  4228. agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
  4229. } else {
  4230. /* Get the average length of all the 4 channels. */
  4231. agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
  4232. }
  4233. /* Set the range of the calculated length. */
  4234. *min_length = ((e1000_igp_cable_length_table[agc_value] -
  4235. IGP01E1000_AGC_RANGE) > 0) ?
  4236. (e1000_igp_cable_length_table[agc_value] -
  4237. IGP01E1000_AGC_RANGE) : 0;
  4238. *max_length = e1000_igp_cable_length_table[agc_value] +
  4239. IGP01E1000_AGC_RANGE;
  4240. }
  4241. return E1000_SUCCESS;
  4242. }
  4243. /******************************************************************************
  4244. * Check the cable polarity
  4245. *
  4246. * hw - Struct containing variables accessed by shared code
  4247. * polarity - output parameter : 0 - Polarity is not reversed
  4248. * 1 - Polarity is reversed.
  4249. *
  4250. * returns: - E1000_ERR_XXX
  4251. * E1000_SUCCESS
  4252. *
  4253. * For phy's older then IGP, this function simply reads the polarity bit in the
  4254. * Phy Status register. For IGP phy's, this bit is valid only if link speed is
  4255. * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
  4256. * return 0. If the link speed is 1000 Mbps the polarity status is in the
  4257. * IGP01E1000_PHY_PCS_INIT_REG.
  4258. *****************************************************************************/
  4259. int32_t
  4260. e1000_check_polarity(struct e1000_hw *hw,
  4261. uint16_t *polarity)
  4262. {
  4263. int32_t ret_val;
  4264. uint16_t phy_data;
  4265. DEBUGFUNC("e1000_check_polarity");
  4266. if(hw->phy_type == e1000_phy_m88) {
  4267. /* return the Polarity bit in the Status register. */
  4268. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
  4269. &phy_data);
  4270. if(ret_val)
  4271. return ret_val;
  4272. *polarity = (phy_data & M88E1000_PSSR_REV_POLARITY) >>
  4273. M88E1000_PSSR_REV_POLARITY_SHIFT;
  4274. } else if(hw->phy_type == e1000_phy_igp) {
  4275. /* Read the Status register to check the speed */
  4276. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
  4277. &phy_data);
  4278. if(ret_val)
  4279. return ret_val;
  4280. /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
  4281. * find the polarity status */
  4282. if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
  4283. IGP01E1000_PSSR_SPEED_1000MBPS) {
  4284. /* Read the GIG initialization PCS register (0x00B4) */
  4285. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
  4286. &phy_data);
  4287. if(ret_val)
  4288. return ret_val;
  4289. /* Check the polarity bits */
  4290. *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? 1 : 0;
  4291. } else {
  4292. /* For 10 Mbps, read the polarity bit in the status register. (for
  4293. * 100 Mbps this bit is always 0) */
  4294. *polarity = phy_data & IGP01E1000_PSSR_POLARITY_REVERSED;
  4295. }
  4296. }
  4297. return E1000_SUCCESS;
  4298. }
  4299. /******************************************************************************
  4300. * Check if Downshift occured
  4301. *
  4302. * hw - Struct containing variables accessed by shared code
  4303. * downshift - output parameter : 0 - No Downshift ocured.
  4304. * 1 - Downshift ocured.
  4305. *
  4306. * returns: - E1000_ERR_XXX
  4307. * E1000_SUCCESS
  4308. *
  4309. * For phy's older then IGP, this function reads the Downshift bit in the Phy
  4310. * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
  4311. * Link Health register. In IGP this bit is latched high, so the driver must
  4312. * read it immediately after link is established.
  4313. *****************************************************************************/
  4314. int32_t
  4315. e1000_check_downshift(struct e1000_hw *hw)
  4316. {
  4317. int32_t ret_val;
  4318. uint16_t phy_data;
  4319. DEBUGFUNC("e1000_check_downshift");
  4320. if(hw->phy_type == e1000_phy_igp) {
  4321. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
  4322. &phy_data);
  4323. if(ret_val)
  4324. return ret_val;
  4325. hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
  4326. } else if(hw->phy_type == e1000_phy_m88) {
  4327. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
  4328. &phy_data);
  4329. if(ret_val)
  4330. return ret_val;
  4331. hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
  4332. M88E1000_PSSR_DOWNSHIFT_SHIFT;
  4333. }
  4334. return E1000_SUCCESS;
  4335. }
  4336. /*****************************************************************************
  4337. *
  4338. * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
  4339. * gigabit link is achieved to improve link quality.
  4340. *
  4341. * hw: Struct containing variables accessed by shared code
  4342. *
  4343. * returns: - E1000_ERR_PHY if fail to read/write the PHY
  4344. * E1000_SUCCESS at any other case.
  4345. *
  4346. ****************************************************************************/
  4347. int32_t
  4348. e1000_config_dsp_after_link_change(struct e1000_hw *hw,
  4349. boolean_t link_up)
  4350. {
  4351. int32_t ret_val;
  4352. uint16_t phy_data, phy_saved_data, speed, duplex, i;
  4353. uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
  4354. {IGP01E1000_PHY_AGC_PARAM_A,
  4355. IGP01E1000_PHY_AGC_PARAM_B,
  4356. IGP01E1000_PHY_AGC_PARAM_C,
  4357. IGP01E1000_PHY_AGC_PARAM_D};
  4358. uint16_t min_length, max_length;
  4359. DEBUGFUNC("e1000_config_dsp_after_link_change");
  4360. if(hw->phy_type != e1000_phy_igp)
  4361. return E1000_SUCCESS;
  4362. if(link_up) {
  4363. ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
  4364. if(ret_val) {
  4365. DEBUGOUT("Error getting link speed and duplex\n");
  4366. return ret_val;
  4367. }
  4368. if(speed == SPEED_1000) {
  4369. e1000_get_cable_length(hw, &min_length, &max_length);
  4370. if((hw->dsp_config_state == e1000_dsp_config_enabled) &&
  4371. min_length >= e1000_igp_cable_length_50) {
  4372. for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
  4373. ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
  4374. &phy_data);
  4375. if(ret_val)
  4376. return ret_val;
  4377. phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
  4378. ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
  4379. phy_data);
  4380. if(ret_val)
  4381. return ret_val;
  4382. }
  4383. hw->dsp_config_state = e1000_dsp_config_activated;
  4384. }
  4385. if((hw->ffe_config_state == e1000_ffe_config_enabled) &&
  4386. (min_length < e1000_igp_cable_length_50)) {
  4387. uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
  4388. uint32_t idle_errs = 0;
  4389. /* clear previous idle error counts */
  4390. ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
  4391. &phy_data);
  4392. if(ret_val)
  4393. return ret_val;
  4394. for(i = 0; i < ffe_idle_err_timeout; i++) {
  4395. udelay(1000);
  4396. ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
  4397. &phy_data);
  4398. if(ret_val)
  4399. return ret_val;
  4400. idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
  4401. if(idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
  4402. hw->ffe_config_state = e1000_ffe_config_active;
  4403. ret_val = e1000_write_phy_reg(hw,
  4404. IGP01E1000_PHY_DSP_FFE,
  4405. IGP01E1000_PHY_DSP_FFE_CM_CP);
  4406. if(ret_val)
  4407. return ret_val;
  4408. break;
  4409. }
  4410. if(idle_errs)
  4411. ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
  4412. }
  4413. }
  4414. }
  4415. } else {
  4416. if(hw->dsp_config_state == e1000_dsp_config_activated) {
  4417. /* Save off the current value of register 0x2F5B to be restored at
  4418. * the end of the routines. */
  4419. ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
  4420. if(ret_val)
  4421. return ret_val;
  4422. /* Disable the PHY transmitter */
  4423. ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
  4424. if(ret_val)
  4425. return ret_val;
  4426. msec_delay(20);
  4427. ret_val = e1000_write_phy_reg(hw, 0x0000,
  4428. IGP01E1000_IEEE_FORCE_GIGA);
  4429. if(ret_val)
  4430. return ret_val;
  4431. for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
  4432. ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
  4433. if(ret_val)
  4434. return ret_val;
  4435. phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
  4436. phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
  4437. ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
  4438. if(ret_val)
  4439. return ret_val;
  4440. }
  4441. ret_val = e1000_write_phy_reg(hw, 0x0000,
  4442. IGP01E1000_IEEE_RESTART_AUTONEG);
  4443. if(ret_val)
  4444. return ret_val;
  4445. msec_delay(20);
  4446. /* Now enable the transmitter */
  4447. ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
  4448. if(ret_val)
  4449. return ret_val;
  4450. hw->dsp_config_state = e1000_dsp_config_enabled;
  4451. }
  4452. if(hw->ffe_config_state == e1000_ffe_config_active) {
  4453. /* Save off the current value of register 0x2F5B to be restored at
  4454. * the end of the routines. */
  4455. ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
  4456. if(ret_val)
  4457. return ret_val;
  4458. /* Disable the PHY transmitter */
  4459. ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
  4460. if(ret_val)
  4461. return ret_val;
  4462. msec_delay(20);
  4463. ret_val = e1000_write_phy_reg(hw, 0x0000,
  4464. IGP01E1000_IEEE_FORCE_GIGA);
  4465. if(ret_val)
  4466. return ret_val;
  4467. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
  4468. IGP01E1000_PHY_DSP_FFE_DEFAULT);
  4469. if(ret_val)
  4470. return ret_val;
  4471. ret_val = e1000_write_phy_reg(hw, 0x0000,
  4472. IGP01E1000_IEEE_RESTART_AUTONEG);
  4473. if(ret_val)
  4474. return ret_val;
  4475. msec_delay(20);
  4476. /* Now enable the transmitter */
  4477. ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
  4478. if(ret_val)
  4479. return ret_val;
  4480. hw->ffe_config_state = e1000_ffe_config_enabled;
  4481. }
  4482. }
  4483. return E1000_SUCCESS;
  4484. }
  4485. /*****************************************************************************
  4486. * Set PHY to class A mode
  4487. * Assumes the following operations will follow to enable the new class mode.
  4488. * 1. Do a PHY soft reset
  4489. * 2. Restart auto-negotiation or force link.
  4490. *
  4491. * hw - Struct containing variables accessed by shared code
  4492. ****************************************************************************/
  4493. static int32_t
  4494. e1000_set_phy_mode(struct e1000_hw *hw)
  4495. {
  4496. int32_t ret_val;
  4497. uint16_t eeprom_data;
  4498. DEBUGFUNC("e1000_set_phy_mode");
  4499. if((hw->mac_type == e1000_82545_rev_3) &&
  4500. (hw->media_type == e1000_media_type_copper)) {
  4501. ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
  4502. if(ret_val) {
  4503. return ret_val;
  4504. }
  4505. if((eeprom_data != EEPROM_RESERVED_WORD) &&
  4506. (eeprom_data & EEPROM_PHY_CLASS_A)) {
  4507. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
  4508. if(ret_val)
  4509. return ret_val;
  4510. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
  4511. if(ret_val)
  4512. return ret_val;
  4513. hw->phy_reset_disable = FALSE;
  4514. }
  4515. }
  4516. return E1000_SUCCESS;
  4517. }
  4518. /*****************************************************************************
  4519. *
  4520. * This function sets the lplu state according to the active flag. When
  4521. * activating lplu this function also disables smart speed and vise versa.
  4522. * lplu will not be activated unless the device autonegotiation advertisment
  4523. * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
  4524. * hw: Struct containing variables accessed by shared code
  4525. * active - true to enable lplu false to disable lplu.
  4526. *
  4527. * returns: - E1000_ERR_PHY if fail to read/write the PHY
  4528. * E1000_SUCCESS at any other case.
  4529. *
  4530. ****************************************************************************/
  4531. int32_t
  4532. e1000_set_d3_lplu_state(struct e1000_hw *hw,
  4533. boolean_t active)
  4534. {
  4535. int32_t ret_val;
  4536. uint16_t phy_data;
  4537. DEBUGFUNC("e1000_set_d3_lplu_state");
  4538. if(!((hw->mac_type == e1000_82541_rev_2) ||
  4539. (hw->mac_type == e1000_82547_rev_2)))
  4540. return E1000_SUCCESS;
  4541. /* During driver activity LPLU should not be used or it will attain link
  4542. * from the lowest speeds starting from 10Mbps. The capability is used for
  4543. * Dx transitions and states */
  4544. ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
  4545. if(ret_val)
  4546. return ret_val;
  4547. if(!active) {
  4548. phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
  4549. ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
  4550. if(ret_val)
  4551. return ret_val;
  4552. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
  4553. * Dx states where the power conservation is most important. During
  4554. * driver activity we should enable SmartSpeed, so performance is
  4555. * maintained. */
  4556. if (hw->smart_speed == e1000_smart_speed_on) {
  4557. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  4558. &phy_data);
  4559. if(ret_val)
  4560. return ret_val;
  4561. phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
  4562. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  4563. phy_data);
  4564. if(ret_val)
  4565. return ret_val;
  4566. } else if (hw->smart_speed == e1000_smart_speed_off) {
  4567. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  4568. &phy_data);
  4569. if (ret_val)
  4570. return ret_val;
  4571. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  4572. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  4573. phy_data);
  4574. if(ret_val)
  4575. return ret_val;
  4576. }
  4577. } else if((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
  4578. (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
  4579. (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
  4580. phy_data |= IGP01E1000_GMII_FLEX_SPD;
  4581. ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
  4582. if(ret_val)
  4583. return ret_val;
  4584. /* When LPLU is enabled we should disable SmartSpeed */
  4585. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
  4586. if(ret_val)
  4587. return ret_val;
  4588. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  4589. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
  4590. if(ret_val)
  4591. return ret_val;
  4592. }
  4593. return E1000_SUCCESS;
  4594. }
  4595. /******************************************************************************
  4596. * Change VCO speed register to improve Bit Error Rate performance of SERDES.
  4597. *
  4598. * hw - Struct containing variables accessed by shared code
  4599. *****************************************************************************/
  4600. static int32_t
  4601. e1000_set_vco_speed(struct e1000_hw *hw)
  4602. {
  4603. int32_t ret_val;
  4604. uint16_t default_page = 0;
  4605. uint16_t phy_data;
  4606. DEBUGFUNC("e1000_set_vco_speed");
  4607. switch(hw->mac_type) {
  4608. case e1000_82545_rev_3:
  4609. case e1000_82546_rev_3:
  4610. break;
  4611. default:
  4612. return E1000_SUCCESS;
  4613. }
  4614. /* Set PHY register 30, page 5, bit 8 to 0 */
  4615. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
  4616. if(ret_val)
  4617. return ret_val;
  4618. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
  4619. if(ret_val)
  4620. return ret_val;
  4621. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
  4622. if(ret_val)
  4623. return ret_val;
  4624. phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
  4625. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
  4626. if(ret_val)
  4627. return ret_val;
  4628. /* Set PHY register 30, page 4, bit 11 to 1 */
  4629. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
  4630. if(ret_val)
  4631. return ret_val;
  4632. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
  4633. if(ret_val)
  4634. return ret_val;
  4635. phy_data |= M88E1000_PHY_VCO_REG_BIT11;
  4636. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
  4637. if(ret_val)
  4638. return ret_val;
  4639. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
  4640. if(ret_val)
  4641. return ret_val;
  4642. return E1000_SUCCESS;
  4643. }
  4644. static int32_t
  4645. e1000_polarity_reversal_workaround(struct e1000_hw *hw)
  4646. {
  4647. int32_t ret_val;
  4648. uint16_t mii_status_reg;
  4649. uint16_t i;
  4650. /* Polarity reversal workaround for forced 10F/10H links. */
  4651. /* Disable the transmitter on the PHY */
  4652. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
  4653. if(ret_val)
  4654. return ret_val;
  4655. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
  4656. if(ret_val)
  4657. return ret_val;
  4658. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
  4659. if(ret_val)
  4660. return ret_val;
  4661. /* This loop will early-out if the NO link condition has been met. */
  4662. for(i = PHY_FORCE_TIME; i > 0; i--) {
  4663. /* Read the MII Status Register and wait for Link Status bit
  4664. * to be clear.
  4665. */
  4666. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  4667. if(ret_val)
  4668. return ret_val;
  4669. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  4670. if(ret_val)
  4671. return ret_val;
  4672. if((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
  4673. msec_delay_irq(100);
  4674. }
  4675. /* Recommended delay time after link has been lost */
  4676. msec_delay_irq(1000);
  4677. /* Now we will re-enable th transmitter on the PHY */
  4678. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
  4679. if(ret_val)
  4680. return ret_val;
  4681. msec_delay_irq(50);
  4682. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
  4683. if(ret_val)
  4684. return ret_val;
  4685. msec_delay_irq(50);
  4686. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
  4687. if(ret_val)
  4688. return ret_val;
  4689. msec_delay_irq(50);
  4690. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
  4691. if(ret_val)
  4692. return ret_val;
  4693. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
  4694. if(ret_val)
  4695. return ret_val;
  4696. /* This loop will early-out if the link condition has been met. */
  4697. for(i = PHY_FORCE_TIME; i > 0; i--) {
  4698. /* Read the MII Status Register and wait for Link Status bit
  4699. * to be set.
  4700. */
  4701. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  4702. if(ret_val)
  4703. return ret_val;
  4704. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  4705. if(ret_val)
  4706. return ret_val;
  4707. if(mii_status_reg & MII_SR_LINK_STATUS) break;
  4708. msec_delay_irq(100);
  4709. }
  4710. return E1000_SUCCESS;
  4711. }