bnx2.c 145 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954
  1. /* bnx2.c: Broadcom NX2 network driver.
  2. *
  3. * Copyright (c) 2004, 2005, 2006 Broadcom Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation.
  8. *
  9. * Written by: Michael Chan (mchan@broadcom.com)
  10. */
  11. #include "bnx2.h"
  12. #include "bnx2_fw.h"
  13. #define DRV_MODULE_NAME "bnx2"
  14. #define PFX DRV_MODULE_NAME ": "
  15. #define DRV_MODULE_VERSION "1.4.31"
  16. #define DRV_MODULE_RELDATE "January 19, 2006"
  17. #define RUN_AT(x) (jiffies + (x))
  18. /* Time in jiffies before concluding the transmitter is hung. */
  19. #define TX_TIMEOUT (5*HZ)
  20. static char version[] __devinitdata =
  21. "Broadcom NetXtreme II Gigabit Ethernet Driver " DRV_MODULE_NAME " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  22. MODULE_AUTHOR("Michael Chan <mchan@broadcom.com>");
  23. MODULE_DESCRIPTION("Broadcom NetXtreme II BCM5706/5708 Driver");
  24. MODULE_LICENSE("GPL");
  25. MODULE_VERSION(DRV_MODULE_VERSION);
  26. static int disable_msi = 0;
  27. module_param(disable_msi, int, 0);
  28. MODULE_PARM_DESC(disable_msi, "Disable Message Signaled Interrupt (MSI)");
  29. typedef enum {
  30. BCM5706 = 0,
  31. NC370T,
  32. NC370I,
  33. BCM5706S,
  34. NC370F,
  35. BCM5708,
  36. BCM5708S,
  37. } board_t;
  38. /* indexed by board_t, above */
  39. static struct {
  40. char *name;
  41. } board_info[] __devinitdata = {
  42. { "Broadcom NetXtreme II BCM5706 1000Base-T" },
  43. { "HP NC370T Multifunction Gigabit Server Adapter" },
  44. { "HP NC370i Multifunction Gigabit Server Adapter" },
  45. { "Broadcom NetXtreme II BCM5706 1000Base-SX" },
  46. { "HP NC370F Multifunction Gigabit Server Adapter" },
  47. { "Broadcom NetXtreme II BCM5708 1000Base-T" },
  48. { "Broadcom NetXtreme II BCM5708 1000Base-SX" },
  49. };
  50. static struct pci_device_id bnx2_pci_tbl[] = {
  51. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706,
  52. PCI_VENDOR_ID_HP, 0x3101, 0, 0, NC370T },
  53. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706,
  54. PCI_VENDOR_ID_HP, 0x3106, 0, 0, NC370I },
  55. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706,
  56. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5706 },
  57. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5708,
  58. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5708 },
  59. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706S,
  60. PCI_VENDOR_ID_HP, 0x3102, 0, 0, NC370F },
  61. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706S,
  62. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5706S },
  63. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5708S,
  64. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5708S },
  65. { 0, }
  66. };
  67. static struct flash_spec flash_table[] =
  68. {
  69. /* Slow EEPROM */
  70. {0x00000000, 0x40830380, 0x009f0081, 0xa184a053, 0xaf000400,
  71. 1, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
  72. SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
  73. "EEPROM - slow"},
  74. /* Expansion entry 0001 */
  75. {0x08000002, 0x4b808201, 0x00050081, 0x03840253, 0xaf020406,
  76. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  77. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  78. "Entry 0001"},
  79. /* Saifun SA25F010 (non-buffered flash) */
  80. /* strap, cfg1, & write1 need updates */
  81. {0x04000001, 0x47808201, 0x00050081, 0x03840253, 0xaf020406,
  82. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  83. SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*2,
  84. "Non-buffered flash (128kB)"},
  85. /* Saifun SA25F020 (non-buffered flash) */
  86. /* strap, cfg1, & write1 need updates */
  87. {0x0c000003, 0x4f808201, 0x00050081, 0x03840253, 0xaf020406,
  88. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  89. SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*4,
  90. "Non-buffered flash (256kB)"},
  91. /* Expansion entry 0100 */
  92. {0x11000000, 0x53808201, 0x00050081, 0x03840253, 0xaf020406,
  93. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  94. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  95. "Entry 0100"},
  96. /* Entry 0101: ST M45PE10 (non-buffered flash, TetonII B0) */
  97. {0x19000002, 0x5b808201, 0x000500db, 0x03840253, 0xaf020406,
  98. 0, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
  99. ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*2,
  100. "Entry 0101: ST M45PE10 (128kB non-bufferred)"},
  101. /* Entry 0110: ST M45PE20 (non-buffered flash)*/
  102. {0x15000001, 0x57808201, 0x000500db, 0x03840253, 0xaf020406,
  103. 0, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
  104. ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*4,
  105. "Entry 0110: ST M45PE20 (256kB non-bufferred)"},
  106. /* Saifun SA25F005 (non-buffered flash) */
  107. /* strap, cfg1, & write1 need updates */
  108. {0x1d000003, 0x5f808201, 0x00050081, 0x03840253, 0xaf020406,
  109. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  110. SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE,
  111. "Non-buffered flash (64kB)"},
  112. /* Fast EEPROM */
  113. {0x22000000, 0x62808380, 0x009f0081, 0xa184a053, 0xaf000400,
  114. 1, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
  115. SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
  116. "EEPROM - fast"},
  117. /* Expansion entry 1001 */
  118. {0x2a000002, 0x6b808201, 0x00050081, 0x03840253, 0xaf020406,
  119. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  120. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  121. "Entry 1001"},
  122. /* Expansion entry 1010 */
  123. {0x26000001, 0x67808201, 0x00050081, 0x03840253, 0xaf020406,
  124. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  125. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  126. "Entry 1010"},
  127. /* ATMEL AT45DB011B (buffered flash) */
  128. {0x2e000003, 0x6e808273, 0x00570081, 0x68848353, 0xaf000400,
  129. 1, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
  130. BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE,
  131. "Buffered flash (128kB)"},
  132. /* Expansion entry 1100 */
  133. {0x33000000, 0x73808201, 0x00050081, 0x03840253, 0xaf020406,
  134. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  135. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  136. "Entry 1100"},
  137. /* Expansion entry 1101 */
  138. {0x3b000002, 0x7b808201, 0x00050081, 0x03840253, 0xaf020406,
  139. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  140. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  141. "Entry 1101"},
  142. /* Ateml Expansion entry 1110 */
  143. {0x37000001, 0x76808273, 0x00570081, 0x68848353, 0xaf000400,
  144. 1, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
  145. BUFFERED_FLASH_BYTE_ADDR_MASK, 0,
  146. "Entry 1110 (Atmel)"},
  147. /* ATMEL AT45DB021B (buffered flash) */
  148. {0x3f000003, 0x7e808273, 0x00570081, 0x68848353, 0xaf000400,
  149. 1, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
  150. BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE*2,
  151. "Buffered flash (256kB)"},
  152. };
  153. MODULE_DEVICE_TABLE(pci, bnx2_pci_tbl);
  154. static inline u32 bnx2_tx_avail(struct bnx2 *bp)
  155. {
  156. u32 diff = TX_RING_IDX(bp->tx_prod) - TX_RING_IDX(bp->tx_cons);
  157. if (diff > MAX_TX_DESC_CNT)
  158. diff = (diff & MAX_TX_DESC_CNT) - 1;
  159. return (bp->tx_ring_size - diff);
  160. }
  161. static u32
  162. bnx2_reg_rd_ind(struct bnx2 *bp, u32 offset)
  163. {
  164. REG_WR(bp, BNX2_PCICFG_REG_WINDOW_ADDRESS, offset);
  165. return (REG_RD(bp, BNX2_PCICFG_REG_WINDOW));
  166. }
  167. static void
  168. bnx2_reg_wr_ind(struct bnx2 *bp, u32 offset, u32 val)
  169. {
  170. REG_WR(bp, BNX2_PCICFG_REG_WINDOW_ADDRESS, offset);
  171. REG_WR(bp, BNX2_PCICFG_REG_WINDOW, val);
  172. }
  173. static void
  174. bnx2_ctx_wr(struct bnx2 *bp, u32 cid_addr, u32 offset, u32 val)
  175. {
  176. offset += cid_addr;
  177. REG_WR(bp, BNX2_CTX_DATA_ADR, offset);
  178. REG_WR(bp, BNX2_CTX_DATA, val);
  179. }
  180. static int
  181. bnx2_read_phy(struct bnx2 *bp, u32 reg, u32 *val)
  182. {
  183. u32 val1;
  184. int i, ret;
  185. if (bp->phy_flags & PHY_INT_MODE_AUTO_POLLING_FLAG) {
  186. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  187. val1 &= ~BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  188. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  189. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  190. udelay(40);
  191. }
  192. val1 = (bp->phy_addr << 21) | (reg << 16) |
  193. BNX2_EMAC_MDIO_COMM_COMMAND_READ | BNX2_EMAC_MDIO_COMM_DISEXT |
  194. BNX2_EMAC_MDIO_COMM_START_BUSY;
  195. REG_WR(bp, BNX2_EMAC_MDIO_COMM, val1);
  196. for (i = 0; i < 50; i++) {
  197. udelay(10);
  198. val1 = REG_RD(bp, BNX2_EMAC_MDIO_COMM);
  199. if (!(val1 & BNX2_EMAC_MDIO_COMM_START_BUSY)) {
  200. udelay(5);
  201. val1 = REG_RD(bp, BNX2_EMAC_MDIO_COMM);
  202. val1 &= BNX2_EMAC_MDIO_COMM_DATA;
  203. break;
  204. }
  205. }
  206. if (val1 & BNX2_EMAC_MDIO_COMM_START_BUSY) {
  207. *val = 0x0;
  208. ret = -EBUSY;
  209. }
  210. else {
  211. *val = val1;
  212. ret = 0;
  213. }
  214. if (bp->phy_flags & PHY_INT_MODE_AUTO_POLLING_FLAG) {
  215. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  216. val1 |= BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  217. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  218. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  219. udelay(40);
  220. }
  221. return ret;
  222. }
  223. static int
  224. bnx2_write_phy(struct bnx2 *bp, u32 reg, u32 val)
  225. {
  226. u32 val1;
  227. int i, ret;
  228. if (bp->phy_flags & PHY_INT_MODE_AUTO_POLLING_FLAG) {
  229. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  230. val1 &= ~BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  231. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  232. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  233. udelay(40);
  234. }
  235. val1 = (bp->phy_addr << 21) | (reg << 16) | val |
  236. BNX2_EMAC_MDIO_COMM_COMMAND_WRITE |
  237. BNX2_EMAC_MDIO_COMM_START_BUSY | BNX2_EMAC_MDIO_COMM_DISEXT;
  238. REG_WR(bp, BNX2_EMAC_MDIO_COMM, val1);
  239. for (i = 0; i < 50; i++) {
  240. udelay(10);
  241. val1 = REG_RD(bp, BNX2_EMAC_MDIO_COMM);
  242. if (!(val1 & BNX2_EMAC_MDIO_COMM_START_BUSY)) {
  243. udelay(5);
  244. break;
  245. }
  246. }
  247. if (val1 & BNX2_EMAC_MDIO_COMM_START_BUSY)
  248. ret = -EBUSY;
  249. else
  250. ret = 0;
  251. if (bp->phy_flags & PHY_INT_MODE_AUTO_POLLING_FLAG) {
  252. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  253. val1 |= BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  254. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  255. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  256. udelay(40);
  257. }
  258. return ret;
  259. }
  260. static void
  261. bnx2_disable_int(struct bnx2 *bp)
  262. {
  263. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  264. BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  265. REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD);
  266. }
  267. static void
  268. bnx2_enable_int(struct bnx2 *bp)
  269. {
  270. u32 val;
  271. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  272. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  273. BNX2_PCICFG_INT_ACK_CMD_MASK_INT | bp->last_status_idx);
  274. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  275. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID | bp->last_status_idx);
  276. val = REG_RD(bp, BNX2_HC_COMMAND);
  277. REG_WR(bp, BNX2_HC_COMMAND, val | BNX2_HC_COMMAND_COAL_NOW);
  278. }
  279. static void
  280. bnx2_disable_int_sync(struct bnx2 *bp)
  281. {
  282. atomic_inc(&bp->intr_sem);
  283. bnx2_disable_int(bp);
  284. synchronize_irq(bp->pdev->irq);
  285. }
  286. static void
  287. bnx2_netif_stop(struct bnx2 *bp)
  288. {
  289. bnx2_disable_int_sync(bp);
  290. if (netif_running(bp->dev)) {
  291. netif_poll_disable(bp->dev);
  292. netif_tx_disable(bp->dev);
  293. bp->dev->trans_start = jiffies; /* prevent tx timeout */
  294. }
  295. }
  296. static void
  297. bnx2_netif_start(struct bnx2 *bp)
  298. {
  299. if (atomic_dec_and_test(&bp->intr_sem)) {
  300. if (netif_running(bp->dev)) {
  301. netif_wake_queue(bp->dev);
  302. netif_poll_enable(bp->dev);
  303. bnx2_enable_int(bp);
  304. }
  305. }
  306. }
  307. static void
  308. bnx2_free_mem(struct bnx2 *bp)
  309. {
  310. if (bp->stats_blk) {
  311. pci_free_consistent(bp->pdev, sizeof(struct statistics_block),
  312. bp->stats_blk, bp->stats_blk_mapping);
  313. bp->stats_blk = NULL;
  314. }
  315. if (bp->status_blk) {
  316. pci_free_consistent(bp->pdev, sizeof(struct status_block),
  317. bp->status_blk, bp->status_blk_mapping);
  318. bp->status_blk = NULL;
  319. }
  320. if (bp->tx_desc_ring) {
  321. pci_free_consistent(bp->pdev,
  322. sizeof(struct tx_bd) * TX_DESC_CNT,
  323. bp->tx_desc_ring, bp->tx_desc_mapping);
  324. bp->tx_desc_ring = NULL;
  325. }
  326. kfree(bp->tx_buf_ring);
  327. bp->tx_buf_ring = NULL;
  328. if (bp->rx_desc_ring) {
  329. pci_free_consistent(bp->pdev,
  330. sizeof(struct rx_bd) * RX_DESC_CNT,
  331. bp->rx_desc_ring, bp->rx_desc_mapping);
  332. bp->rx_desc_ring = NULL;
  333. }
  334. kfree(bp->rx_buf_ring);
  335. bp->rx_buf_ring = NULL;
  336. }
  337. static int
  338. bnx2_alloc_mem(struct bnx2 *bp)
  339. {
  340. bp->tx_buf_ring = kmalloc(sizeof(struct sw_bd) * TX_DESC_CNT,
  341. GFP_KERNEL);
  342. if (bp->tx_buf_ring == NULL)
  343. return -ENOMEM;
  344. memset(bp->tx_buf_ring, 0, sizeof(struct sw_bd) * TX_DESC_CNT);
  345. bp->tx_desc_ring = pci_alloc_consistent(bp->pdev,
  346. sizeof(struct tx_bd) *
  347. TX_DESC_CNT,
  348. &bp->tx_desc_mapping);
  349. if (bp->tx_desc_ring == NULL)
  350. goto alloc_mem_err;
  351. bp->rx_buf_ring = kmalloc(sizeof(struct sw_bd) * RX_DESC_CNT,
  352. GFP_KERNEL);
  353. if (bp->rx_buf_ring == NULL)
  354. goto alloc_mem_err;
  355. memset(bp->rx_buf_ring, 0, sizeof(struct sw_bd) * RX_DESC_CNT);
  356. bp->rx_desc_ring = pci_alloc_consistent(bp->pdev,
  357. sizeof(struct rx_bd) *
  358. RX_DESC_CNT,
  359. &bp->rx_desc_mapping);
  360. if (bp->rx_desc_ring == NULL)
  361. goto alloc_mem_err;
  362. bp->status_blk = pci_alloc_consistent(bp->pdev,
  363. sizeof(struct status_block),
  364. &bp->status_blk_mapping);
  365. if (bp->status_blk == NULL)
  366. goto alloc_mem_err;
  367. memset(bp->status_blk, 0, sizeof(struct status_block));
  368. bp->stats_blk = pci_alloc_consistent(bp->pdev,
  369. sizeof(struct statistics_block),
  370. &bp->stats_blk_mapping);
  371. if (bp->stats_blk == NULL)
  372. goto alloc_mem_err;
  373. memset(bp->stats_blk, 0, sizeof(struct statistics_block));
  374. return 0;
  375. alloc_mem_err:
  376. bnx2_free_mem(bp);
  377. return -ENOMEM;
  378. }
  379. static void
  380. bnx2_report_fw_link(struct bnx2 *bp)
  381. {
  382. u32 fw_link_status = 0;
  383. if (bp->link_up) {
  384. u32 bmsr;
  385. switch (bp->line_speed) {
  386. case SPEED_10:
  387. if (bp->duplex == DUPLEX_HALF)
  388. fw_link_status = BNX2_LINK_STATUS_10HALF;
  389. else
  390. fw_link_status = BNX2_LINK_STATUS_10FULL;
  391. break;
  392. case SPEED_100:
  393. if (bp->duplex == DUPLEX_HALF)
  394. fw_link_status = BNX2_LINK_STATUS_100HALF;
  395. else
  396. fw_link_status = BNX2_LINK_STATUS_100FULL;
  397. break;
  398. case SPEED_1000:
  399. if (bp->duplex == DUPLEX_HALF)
  400. fw_link_status = BNX2_LINK_STATUS_1000HALF;
  401. else
  402. fw_link_status = BNX2_LINK_STATUS_1000FULL;
  403. break;
  404. case SPEED_2500:
  405. if (bp->duplex == DUPLEX_HALF)
  406. fw_link_status = BNX2_LINK_STATUS_2500HALF;
  407. else
  408. fw_link_status = BNX2_LINK_STATUS_2500FULL;
  409. break;
  410. }
  411. fw_link_status |= BNX2_LINK_STATUS_LINK_UP;
  412. if (bp->autoneg) {
  413. fw_link_status |= BNX2_LINK_STATUS_AN_ENABLED;
  414. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  415. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  416. if (!(bmsr & BMSR_ANEGCOMPLETE) ||
  417. bp->phy_flags & PHY_PARALLEL_DETECT_FLAG)
  418. fw_link_status |= BNX2_LINK_STATUS_PARALLEL_DET;
  419. else
  420. fw_link_status |= BNX2_LINK_STATUS_AN_COMPLETE;
  421. }
  422. }
  423. else
  424. fw_link_status = BNX2_LINK_STATUS_LINK_DOWN;
  425. REG_WR_IND(bp, bp->shmem_base + BNX2_LINK_STATUS, fw_link_status);
  426. }
  427. static void
  428. bnx2_report_link(struct bnx2 *bp)
  429. {
  430. if (bp->link_up) {
  431. netif_carrier_on(bp->dev);
  432. printk(KERN_INFO PFX "%s NIC Link is Up, ", bp->dev->name);
  433. printk("%d Mbps ", bp->line_speed);
  434. if (bp->duplex == DUPLEX_FULL)
  435. printk("full duplex");
  436. else
  437. printk("half duplex");
  438. if (bp->flow_ctrl) {
  439. if (bp->flow_ctrl & FLOW_CTRL_RX) {
  440. printk(", receive ");
  441. if (bp->flow_ctrl & FLOW_CTRL_TX)
  442. printk("& transmit ");
  443. }
  444. else {
  445. printk(", transmit ");
  446. }
  447. printk("flow control ON");
  448. }
  449. printk("\n");
  450. }
  451. else {
  452. netif_carrier_off(bp->dev);
  453. printk(KERN_ERR PFX "%s NIC Link is Down\n", bp->dev->name);
  454. }
  455. bnx2_report_fw_link(bp);
  456. }
  457. static void
  458. bnx2_resolve_flow_ctrl(struct bnx2 *bp)
  459. {
  460. u32 local_adv, remote_adv;
  461. bp->flow_ctrl = 0;
  462. if ((bp->autoneg & (AUTONEG_SPEED | AUTONEG_FLOW_CTRL)) !=
  463. (AUTONEG_SPEED | AUTONEG_FLOW_CTRL)) {
  464. if (bp->duplex == DUPLEX_FULL) {
  465. bp->flow_ctrl = bp->req_flow_ctrl;
  466. }
  467. return;
  468. }
  469. if (bp->duplex != DUPLEX_FULL) {
  470. return;
  471. }
  472. if ((bp->phy_flags & PHY_SERDES_FLAG) &&
  473. (CHIP_NUM(bp) == CHIP_NUM_5708)) {
  474. u32 val;
  475. bnx2_read_phy(bp, BCM5708S_1000X_STAT1, &val);
  476. if (val & BCM5708S_1000X_STAT1_TX_PAUSE)
  477. bp->flow_ctrl |= FLOW_CTRL_TX;
  478. if (val & BCM5708S_1000X_STAT1_RX_PAUSE)
  479. bp->flow_ctrl |= FLOW_CTRL_RX;
  480. return;
  481. }
  482. bnx2_read_phy(bp, MII_ADVERTISE, &local_adv);
  483. bnx2_read_phy(bp, MII_LPA, &remote_adv);
  484. if (bp->phy_flags & PHY_SERDES_FLAG) {
  485. u32 new_local_adv = 0;
  486. u32 new_remote_adv = 0;
  487. if (local_adv & ADVERTISE_1000XPAUSE)
  488. new_local_adv |= ADVERTISE_PAUSE_CAP;
  489. if (local_adv & ADVERTISE_1000XPSE_ASYM)
  490. new_local_adv |= ADVERTISE_PAUSE_ASYM;
  491. if (remote_adv & ADVERTISE_1000XPAUSE)
  492. new_remote_adv |= ADVERTISE_PAUSE_CAP;
  493. if (remote_adv & ADVERTISE_1000XPSE_ASYM)
  494. new_remote_adv |= ADVERTISE_PAUSE_ASYM;
  495. local_adv = new_local_adv;
  496. remote_adv = new_remote_adv;
  497. }
  498. /* See Table 28B-3 of 802.3ab-1999 spec. */
  499. if (local_adv & ADVERTISE_PAUSE_CAP) {
  500. if(local_adv & ADVERTISE_PAUSE_ASYM) {
  501. if (remote_adv & ADVERTISE_PAUSE_CAP) {
  502. bp->flow_ctrl = FLOW_CTRL_TX | FLOW_CTRL_RX;
  503. }
  504. else if (remote_adv & ADVERTISE_PAUSE_ASYM) {
  505. bp->flow_ctrl = FLOW_CTRL_RX;
  506. }
  507. }
  508. else {
  509. if (remote_adv & ADVERTISE_PAUSE_CAP) {
  510. bp->flow_ctrl = FLOW_CTRL_TX | FLOW_CTRL_RX;
  511. }
  512. }
  513. }
  514. else if (local_adv & ADVERTISE_PAUSE_ASYM) {
  515. if ((remote_adv & ADVERTISE_PAUSE_CAP) &&
  516. (remote_adv & ADVERTISE_PAUSE_ASYM)) {
  517. bp->flow_ctrl = FLOW_CTRL_TX;
  518. }
  519. }
  520. }
  521. static int
  522. bnx2_5708s_linkup(struct bnx2 *bp)
  523. {
  524. u32 val;
  525. bp->link_up = 1;
  526. bnx2_read_phy(bp, BCM5708S_1000X_STAT1, &val);
  527. switch (val & BCM5708S_1000X_STAT1_SPEED_MASK) {
  528. case BCM5708S_1000X_STAT1_SPEED_10:
  529. bp->line_speed = SPEED_10;
  530. break;
  531. case BCM5708S_1000X_STAT1_SPEED_100:
  532. bp->line_speed = SPEED_100;
  533. break;
  534. case BCM5708S_1000X_STAT1_SPEED_1G:
  535. bp->line_speed = SPEED_1000;
  536. break;
  537. case BCM5708S_1000X_STAT1_SPEED_2G5:
  538. bp->line_speed = SPEED_2500;
  539. break;
  540. }
  541. if (val & BCM5708S_1000X_STAT1_FD)
  542. bp->duplex = DUPLEX_FULL;
  543. else
  544. bp->duplex = DUPLEX_HALF;
  545. return 0;
  546. }
  547. static int
  548. bnx2_5706s_linkup(struct bnx2 *bp)
  549. {
  550. u32 bmcr, local_adv, remote_adv, common;
  551. bp->link_up = 1;
  552. bp->line_speed = SPEED_1000;
  553. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  554. if (bmcr & BMCR_FULLDPLX) {
  555. bp->duplex = DUPLEX_FULL;
  556. }
  557. else {
  558. bp->duplex = DUPLEX_HALF;
  559. }
  560. if (!(bmcr & BMCR_ANENABLE)) {
  561. return 0;
  562. }
  563. bnx2_read_phy(bp, MII_ADVERTISE, &local_adv);
  564. bnx2_read_phy(bp, MII_LPA, &remote_adv);
  565. common = local_adv & remote_adv;
  566. if (common & (ADVERTISE_1000XHALF | ADVERTISE_1000XFULL)) {
  567. if (common & ADVERTISE_1000XFULL) {
  568. bp->duplex = DUPLEX_FULL;
  569. }
  570. else {
  571. bp->duplex = DUPLEX_HALF;
  572. }
  573. }
  574. return 0;
  575. }
  576. static int
  577. bnx2_copper_linkup(struct bnx2 *bp)
  578. {
  579. u32 bmcr;
  580. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  581. if (bmcr & BMCR_ANENABLE) {
  582. u32 local_adv, remote_adv, common;
  583. bnx2_read_phy(bp, MII_CTRL1000, &local_adv);
  584. bnx2_read_phy(bp, MII_STAT1000, &remote_adv);
  585. common = local_adv & (remote_adv >> 2);
  586. if (common & ADVERTISE_1000FULL) {
  587. bp->line_speed = SPEED_1000;
  588. bp->duplex = DUPLEX_FULL;
  589. }
  590. else if (common & ADVERTISE_1000HALF) {
  591. bp->line_speed = SPEED_1000;
  592. bp->duplex = DUPLEX_HALF;
  593. }
  594. else {
  595. bnx2_read_phy(bp, MII_ADVERTISE, &local_adv);
  596. bnx2_read_phy(bp, MII_LPA, &remote_adv);
  597. common = local_adv & remote_adv;
  598. if (common & ADVERTISE_100FULL) {
  599. bp->line_speed = SPEED_100;
  600. bp->duplex = DUPLEX_FULL;
  601. }
  602. else if (common & ADVERTISE_100HALF) {
  603. bp->line_speed = SPEED_100;
  604. bp->duplex = DUPLEX_HALF;
  605. }
  606. else if (common & ADVERTISE_10FULL) {
  607. bp->line_speed = SPEED_10;
  608. bp->duplex = DUPLEX_FULL;
  609. }
  610. else if (common & ADVERTISE_10HALF) {
  611. bp->line_speed = SPEED_10;
  612. bp->duplex = DUPLEX_HALF;
  613. }
  614. else {
  615. bp->line_speed = 0;
  616. bp->link_up = 0;
  617. }
  618. }
  619. }
  620. else {
  621. if (bmcr & BMCR_SPEED100) {
  622. bp->line_speed = SPEED_100;
  623. }
  624. else {
  625. bp->line_speed = SPEED_10;
  626. }
  627. if (bmcr & BMCR_FULLDPLX) {
  628. bp->duplex = DUPLEX_FULL;
  629. }
  630. else {
  631. bp->duplex = DUPLEX_HALF;
  632. }
  633. }
  634. return 0;
  635. }
  636. static int
  637. bnx2_set_mac_link(struct bnx2 *bp)
  638. {
  639. u32 val;
  640. REG_WR(bp, BNX2_EMAC_TX_LENGTHS, 0x2620);
  641. if (bp->link_up && (bp->line_speed == SPEED_1000) &&
  642. (bp->duplex == DUPLEX_HALF)) {
  643. REG_WR(bp, BNX2_EMAC_TX_LENGTHS, 0x26ff);
  644. }
  645. /* Configure the EMAC mode register. */
  646. val = REG_RD(bp, BNX2_EMAC_MODE);
  647. val &= ~(BNX2_EMAC_MODE_PORT | BNX2_EMAC_MODE_HALF_DUPLEX |
  648. BNX2_EMAC_MODE_MAC_LOOP | BNX2_EMAC_MODE_FORCE_LINK |
  649. BNX2_EMAC_MODE_25G);
  650. if (bp->link_up) {
  651. switch (bp->line_speed) {
  652. case SPEED_10:
  653. if (CHIP_NUM(bp) == CHIP_NUM_5708) {
  654. val |= BNX2_EMAC_MODE_PORT_MII_10;
  655. break;
  656. }
  657. /* fall through */
  658. case SPEED_100:
  659. val |= BNX2_EMAC_MODE_PORT_MII;
  660. break;
  661. case SPEED_2500:
  662. val |= BNX2_EMAC_MODE_25G;
  663. /* fall through */
  664. case SPEED_1000:
  665. val |= BNX2_EMAC_MODE_PORT_GMII;
  666. break;
  667. }
  668. }
  669. else {
  670. val |= BNX2_EMAC_MODE_PORT_GMII;
  671. }
  672. /* Set the MAC to operate in the appropriate duplex mode. */
  673. if (bp->duplex == DUPLEX_HALF)
  674. val |= BNX2_EMAC_MODE_HALF_DUPLEX;
  675. REG_WR(bp, BNX2_EMAC_MODE, val);
  676. /* Enable/disable rx PAUSE. */
  677. bp->rx_mode &= ~BNX2_EMAC_RX_MODE_FLOW_EN;
  678. if (bp->flow_ctrl & FLOW_CTRL_RX)
  679. bp->rx_mode |= BNX2_EMAC_RX_MODE_FLOW_EN;
  680. REG_WR(bp, BNX2_EMAC_RX_MODE, bp->rx_mode);
  681. /* Enable/disable tx PAUSE. */
  682. val = REG_RD(bp, BNX2_EMAC_TX_MODE);
  683. val &= ~BNX2_EMAC_TX_MODE_FLOW_EN;
  684. if (bp->flow_ctrl & FLOW_CTRL_TX)
  685. val |= BNX2_EMAC_TX_MODE_FLOW_EN;
  686. REG_WR(bp, BNX2_EMAC_TX_MODE, val);
  687. /* Acknowledge the interrupt. */
  688. REG_WR(bp, BNX2_EMAC_STATUS, BNX2_EMAC_STATUS_LINK_CHANGE);
  689. return 0;
  690. }
  691. static int
  692. bnx2_set_link(struct bnx2 *bp)
  693. {
  694. u32 bmsr;
  695. u8 link_up;
  696. if (bp->loopback == MAC_LOOPBACK) {
  697. bp->link_up = 1;
  698. return 0;
  699. }
  700. link_up = bp->link_up;
  701. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  702. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  703. if ((bp->phy_flags & PHY_SERDES_FLAG) &&
  704. (CHIP_NUM(bp) == CHIP_NUM_5706)) {
  705. u32 val;
  706. val = REG_RD(bp, BNX2_EMAC_STATUS);
  707. if (val & BNX2_EMAC_STATUS_LINK)
  708. bmsr |= BMSR_LSTATUS;
  709. else
  710. bmsr &= ~BMSR_LSTATUS;
  711. }
  712. if (bmsr & BMSR_LSTATUS) {
  713. bp->link_up = 1;
  714. if (bp->phy_flags & PHY_SERDES_FLAG) {
  715. if (CHIP_NUM(bp) == CHIP_NUM_5706)
  716. bnx2_5706s_linkup(bp);
  717. else if (CHIP_NUM(bp) == CHIP_NUM_5708)
  718. bnx2_5708s_linkup(bp);
  719. }
  720. else {
  721. bnx2_copper_linkup(bp);
  722. }
  723. bnx2_resolve_flow_ctrl(bp);
  724. }
  725. else {
  726. if ((bp->phy_flags & PHY_SERDES_FLAG) &&
  727. (bp->autoneg & AUTONEG_SPEED)) {
  728. u32 bmcr;
  729. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  730. if (!(bmcr & BMCR_ANENABLE)) {
  731. bnx2_write_phy(bp, MII_BMCR, bmcr |
  732. BMCR_ANENABLE);
  733. }
  734. }
  735. bp->phy_flags &= ~PHY_PARALLEL_DETECT_FLAG;
  736. bp->link_up = 0;
  737. }
  738. if (bp->link_up != link_up) {
  739. bnx2_report_link(bp);
  740. }
  741. bnx2_set_mac_link(bp);
  742. return 0;
  743. }
  744. static int
  745. bnx2_reset_phy(struct bnx2 *bp)
  746. {
  747. int i;
  748. u32 reg;
  749. bnx2_write_phy(bp, MII_BMCR, BMCR_RESET);
  750. #define PHY_RESET_MAX_WAIT 100
  751. for (i = 0; i < PHY_RESET_MAX_WAIT; i++) {
  752. udelay(10);
  753. bnx2_read_phy(bp, MII_BMCR, &reg);
  754. if (!(reg & BMCR_RESET)) {
  755. udelay(20);
  756. break;
  757. }
  758. }
  759. if (i == PHY_RESET_MAX_WAIT) {
  760. return -EBUSY;
  761. }
  762. return 0;
  763. }
  764. static u32
  765. bnx2_phy_get_pause_adv(struct bnx2 *bp)
  766. {
  767. u32 adv = 0;
  768. if ((bp->req_flow_ctrl & (FLOW_CTRL_RX | FLOW_CTRL_TX)) ==
  769. (FLOW_CTRL_RX | FLOW_CTRL_TX)) {
  770. if (bp->phy_flags & PHY_SERDES_FLAG) {
  771. adv = ADVERTISE_1000XPAUSE;
  772. }
  773. else {
  774. adv = ADVERTISE_PAUSE_CAP;
  775. }
  776. }
  777. else if (bp->req_flow_ctrl & FLOW_CTRL_TX) {
  778. if (bp->phy_flags & PHY_SERDES_FLAG) {
  779. adv = ADVERTISE_1000XPSE_ASYM;
  780. }
  781. else {
  782. adv = ADVERTISE_PAUSE_ASYM;
  783. }
  784. }
  785. else if (bp->req_flow_ctrl & FLOW_CTRL_RX) {
  786. if (bp->phy_flags & PHY_SERDES_FLAG) {
  787. adv = ADVERTISE_1000XPAUSE | ADVERTISE_1000XPSE_ASYM;
  788. }
  789. else {
  790. adv = ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
  791. }
  792. }
  793. return adv;
  794. }
  795. static int
  796. bnx2_setup_serdes_phy(struct bnx2 *bp)
  797. {
  798. u32 adv, bmcr, up1;
  799. u32 new_adv = 0;
  800. if (!(bp->autoneg & AUTONEG_SPEED)) {
  801. u32 new_bmcr;
  802. int force_link_down = 0;
  803. if (CHIP_NUM(bp) == CHIP_NUM_5708) {
  804. bnx2_read_phy(bp, BCM5708S_UP1, &up1);
  805. if (up1 & BCM5708S_UP1_2G5) {
  806. up1 &= ~BCM5708S_UP1_2G5;
  807. bnx2_write_phy(bp, BCM5708S_UP1, up1);
  808. force_link_down = 1;
  809. }
  810. }
  811. bnx2_read_phy(bp, MII_ADVERTISE, &adv);
  812. adv &= ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF);
  813. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  814. new_bmcr = bmcr & ~BMCR_ANENABLE;
  815. new_bmcr |= BMCR_SPEED1000;
  816. if (bp->req_duplex == DUPLEX_FULL) {
  817. adv |= ADVERTISE_1000XFULL;
  818. new_bmcr |= BMCR_FULLDPLX;
  819. }
  820. else {
  821. adv |= ADVERTISE_1000XHALF;
  822. new_bmcr &= ~BMCR_FULLDPLX;
  823. }
  824. if ((new_bmcr != bmcr) || (force_link_down)) {
  825. /* Force a link down visible on the other side */
  826. if (bp->link_up) {
  827. bnx2_write_phy(bp, MII_ADVERTISE, adv &
  828. ~(ADVERTISE_1000XFULL |
  829. ADVERTISE_1000XHALF));
  830. bnx2_write_phy(bp, MII_BMCR, bmcr |
  831. BMCR_ANRESTART | BMCR_ANENABLE);
  832. bp->link_up = 0;
  833. netif_carrier_off(bp->dev);
  834. bnx2_write_phy(bp, MII_BMCR, new_bmcr);
  835. }
  836. bnx2_write_phy(bp, MII_ADVERTISE, adv);
  837. bnx2_write_phy(bp, MII_BMCR, new_bmcr);
  838. }
  839. return 0;
  840. }
  841. if (bp->phy_flags & PHY_2_5G_CAPABLE_FLAG) {
  842. bnx2_read_phy(bp, BCM5708S_UP1, &up1);
  843. up1 |= BCM5708S_UP1_2G5;
  844. bnx2_write_phy(bp, BCM5708S_UP1, up1);
  845. }
  846. if (bp->advertising & ADVERTISED_1000baseT_Full)
  847. new_adv |= ADVERTISE_1000XFULL;
  848. new_adv |= bnx2_phy_get_pause_adv(bp);
  849. bnx2_read_phy(bp, MII_ADVERTISE, &adv);
  850. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  851. bp->serdes_an_pending = 0;
  852. if ((adv != new_adv) || ((bmcr & BMCR_ANENABLE) == 0)) {
  853. /* Force a link down visible on the other side */
  854. if (bp->link_up) {
  855. int i;
  856. bnx2_write_phy(bp, MII_BMCR, BMCR_LOOPBACK);
  857. for (i = 0; i < 110; i++) {
  858. udelay(100);
  859. }
  860. }
  861. bnx2_write_phy(bp, MII_ADVERTISE, new_adv);
  862. bnx2_write_phy(bp, MII_BMCR, bmcr | BMCR_ANRESTART |
  863. BMCR_ANENABLE);
  864. if (CHIP_NUM(bp) == CHIP_NUM_5706) {
  865. /* Speed up link-up time when the link partner
  866. * does not autonegotiate which is very common
  867. * in blade servers. Some blade servers use
  868. * IPMI for kerboard input and it's important
  869. * to minimize link disruptions. Autoneg. involves
  870. * exchanging base pages plus 3 next pages and
  871. * normally completes in about 120 msec.
  872. */
  873. bp->current_interval = SERDES_AN_TIMEOUT;
  874. bp->serdes_an_pending = 1;
  875. mod_timer(&bp->timer, jiffies + bp->current_interval);
  876. }
  877. }
  878. return 0;
  879. }
  880. #define ETHTOOL_ALL_FIBRE_SPEED \
  881. (ADVERTISED_1000baseT_Full)
  882. #define ETHTOOL_ALL_COPPER_SPEED \
  883. (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | \
  884. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | \
  885. ADVERTISED_1000baseT_Full)
  886. #define PHY_ALL_10_100_SPEED (ADVERTISE_10HALF | ADVERTISE_10FULL | \
  887. ADVERTISE_100HALF | ADVERTISE_100FULL | ADVERTISE_CSMA)
  888. #define PHY_ALL_1000_SPEED (ADVERTISE_1000HALF | ADVERTISE_1000FULL)
  889. static int
  890. bnx2_setup_copper_phy(struct bnx2 *bp)
  891. {
  892. u32 bmcr;
  893. u32 new_bmcr;
  894. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  895. if (bp->autoneg & AUTONEG_SPEED) {
  896. u32 adv_reg, adv1000_reg;
  897. u32 new_adv_reg = 0;
  898. u32 new_adv1000_reg = 0;
  899. bnx2_read_phy(bp, MII_ADVERTISE, &adv_reg);
  900. adv_reg &= (PHY_ALL_10_100_SPEED | ADVERTISE_PAUSE_CAP |
  901. ADVERTISE_PAUSE_ASYM);
  902. bnx2_read_phy(bp, MII_CTRL1000, &adv1000_reg);
  903. adv1000_reg &= PHY_ALL_1000_SPEED;
  904. if (bp->advertising & ADVERTISED_10baseT_Half)
  905. new_adv_reg |= ADVERTISE_10HALF;
  906. if (bp->advertising & ADVERTISED_10baseT_Full)
  907. new_adv_reg |= ADVERTISE_10FULL;
  908. if (bp->advertising & ADVERTISED_100baseT_Half)
  909. new_adv_reg |= ADVERTISE_100HALF;
  910. if (bp->advertising & ADVERTISED_100baseT_Full)
  911. new_adv_reg |= ADVERTISE_100FULL;
  912. if (bp->advertising & ADVERTISED_1000baseT_Full)
  913. new_adv1000_reg |= ADVERTISE_1000FULL;
  914. new_adv_reg |= ADVERTISE_CSMA;
  915. new_adv_reg |= bnx2_phy_get_pause_adv(bp);
  916. if ((adv1000_reg != new_adv1000_reg) ||
  917. (adv_reg != new_adv_reg) ||
  918. ((bmcr & BMCR_ANENABLE) == 0)) {
  919. bnx2_write_phy(bp, MII_ADVERTISE, new_adv_reg);
  920. bnx2_write_phy(bp, MII_CTRL1000, new_adv1000_reg);
  921. bnx2_write_phy(bp, MII_BMCR, BMCR_ANRESTART |
  922. BMCR_ANENABLE);
  923. }
  924. else if (bp->link_up) {
  925. /* Flow ctrl may have changed from auto to forced */
  926. /* or vice-versa. */
  927. bnx2_resolve_flow_ctrl(bp);
  928. bnx2_set_mac_link(bp);
  929. }
  930. return 0;
  931. }
  932. new_bmcr = 0;
  933. if (bp->req_line_speed == SPEED_100) {
  934. new_bmcr |= BMCR_SPEED100;
  935. }
  936. if (bp->req_duplex == DUPLEX_FULL) {
  937. new_bmcr |= BMCR_FULLDPLX;
  938. }
  939. if (new_bmcr != bmcr) {
  940. u32 bmsr;
  941. int i = 0;
  942. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  943. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  944. if (bmsr & BMSR_LSTATUS) {
  945. /* Force link down */
  946. bnx2_write_phy(bp, MII_BMCR, BMCR_LOOPBACK);
  947. do {
  948. udelay(100);
  949. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  950. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  951. i++;
  952. } while ((bmsr & BMSR_LSTATUS) && (i < 620));
  953. }
  954. bnx2_write_phy(bp, MII_BMCR, new_bmcr);
  955. /* Normally, the new speed is setup after the link has
  956. * gone down and up again. In some cases, link will not go
  957. * down so we need to set up the new speed here.
  958. */
  959. if (bmsr & BMSR_LSTATUS) {
  960. bp->line_speed = bp->req_line_speed;
  961. bp->duplex = bp->req_duplex;
  962. bnx2_resolve_flow_ctrl(bp);
  963. bnx2_set_mac_link(bp);
  964. }
  965. }
  966. return 0;
  967. }
  968. static int
  969. bnx2_setup_phy(struct bnx2 *bp)
  970. {
  971. if (bp->loopback == MAC_LOOPBACK)
  972. return 0;
  973. if (bp->phy_flags & PHY_SERDES_FLAG) {
  974. return (bnx2_setup_serdes_phy(bp));
  975. }
  976. else {
  977. return (bnx2_setup_copper_phy(bp));
  978. }
  979. }
  980. static int
  981. bnx2_init_5708s_phy(struct bnx2 *bp)
  982. {
  983. u32 val;
  984. bnx2_write_phy(bp, BCM5708S_BLK_ADDR, BCM5708S_BLK_ADDR_DIG3);
  985. bnx2_write_phy(bp, BCM5708S_DIG_3_0, BCM5708S_DIG_3_0_USE_IEEE);
  986. bnx2_write_phy(bp, BCM5708S_BLK_ADDR, BCM5708S_BLK_ADDR_DIG);
  987. bnx2_read_phy(bp, BCM5708S_1000X_CTL1, &val);
  988. val |= BCM5708S_1000X_CTL1_FIBER_MODE | BCM5708S_1000X_CTL1_AUTODET_EN;
  989. bnx2_write_phy(bp, BCM5708S_1000X_CTL1, val);
  990. bnx2_read_phy(bp, BCM5708S_1000X_CTL2, &val);
  991. val |= BCM5708S_1000X_CTL2_PLLEL_DET_EN;
  992. bnx2_write_phy(bp, BCM5708S_1000X_CTL2, val);
  993. if (bp->phy_flags & PHY_2_5G_CAPABLE_FLAG) {
  994. bnx2_read_phy(bp, BCM5708S_UP1, &val);
  995. val |= BCM5708S_UP1_2G5;
  996. bnx2_write_phy(bp, BCM5708S_UP1, val);
  997. }
  998. if ((CHIP_ID(bp) == CHIP_ID_5708_A0) ||
  999. (CHIP_ID(bp) == CHIP_ID_5708_B0) ||
  1000. (CHIP_ID(bp) == CHIP_ID_5708_B1)) {
  1001. /* increase tx signal amplitude */
  1002. bnx2_write_phy(bp, BCM5708S_BLK_ADDR,
  1003. BCM5708S_BLK_ADDR_TX_MISC);
  1004. bnx2_read_phy(bp, BCM5708S_TX_ACTL1, &val);
  1005. val &= ~BCM5708S_TX_ACTL1_DRIVER_VCM;
  1006. bnx2_write_phy(bp, BCM5708S_TX_ACTL1, val);
  1007. bnx2_write_phy(bp, BCM5708S_BLK_ADDR, BCM5708S_BLK_ADDR_DIG);
  1008. }
  1009. val = REG_RD_IND(bp, bp->shmem_base + BNX2_PORT_HW_CFG_CONFIG) &
  1010. BNX2_PORT_HW_CFG_CFG_TXCTL3_MASK;
  1011. if (val) {
  1012. u32 is_backplane;
  1013. is_backplane = REG_RD_IND(bp, bp->shmem_base +
  1014. BNX2_SHARED_HW_CFG_CONFIG);
  1015. if (is_backplane & BNX2_SHARED_HW_CFG_PHY_BACKPLANE) {
  1016. bnx2_write_phy(bp, BCM5708S_BLK_ADDR,
  1017. BCM5708S_BLK_ADDR_TX_MISC);
  1018. bnx2_write_phy(bp, BCM5708S_TX_ACTL3, val);
  1019. bnx2_write_phy(bp, BCM5708S_BLK_ADDR,
  1020. BCM5708S_BLK_ADDR_DIG);
  1021. }
  1022. }
  1023. return 0;
  1024. }
  1025. static int
  1026. bnx2_init_5706s_phy(struct bnx2 *bp)
  1027. {
  1028. bp->phy_flags &= ~PHY_PARALLEL_DETECT_FLAG;
  1029. if (CHIP_NUM(bp) == CHIP_NUM_5706) {
  1030. REG_WR(bp, BNX2_MISC_UNUSED0, 0x300);
  1031. }
  1032. if (bp->dev->mtu > 1500) {
  1033. u32 val;
  1034. /* Set extended packet length bit */
  1035. bnx2_write_phy(bp, 0x18, 0x7);
  1036. bnx2_read_phy(bp, 0x18, &val);
  1037. bnx2_write_phy(bp, 0x18, (val & 0xfff8) | 0x4000);
  1038. bnx2_write_phy(bp, 0x1c, 0x6c00);
  1039. bnx2_read_phy(bp, 0x1c, &val);
  1040. bnx2_write_phy(bp, 0x1c, (val & 0x3ff) | 0xec02);
  1041. }
  1042. else {
  1043. u32 val;
  1044. bnx2_write_phy(bp, 0x18, 0x7);
  1045. bnx2_read_phy(bp, 0x18, &val);
  1046. bnx2_write_phy(bp, 0x18, val & ~0x4007);
  1047. bnx2_write_phy(bp, 0x1c, 0x6c00);
  1048. bnx2_read_phy(bp, 0x1c, &val);
  1049. bnx2_write_phy(bp, 0x1c, (val & 0x3fd) | 0xec00);
  1050. }
  1051. return 0;
  1052. }
  1053. static int
  1054. bnx2_init_copper_phy(struct bnx2 *bp)
  1055. {
  1056. u32 val;
  1057. bp->phy_flags |= PHY_CRC_FIX_FLAG;
  1058. if (bp->phy_flags & PHY_CRC_FIX_FLAG) {
  1059. bnx2_write_phy(bp, 0x18, 0x0c00);
  1060. bnx2_write_phy(bp, 0x17, 0x000a);
  1061. bnx2_write_phy(bp, 0x15, 0x310b);
  1062. bnx2_write_phy(bp, 0x17, 0x201f);
  1063. bnx2_write_phy(bp, 0x15, 0x9506);
  1064. bnx2_write_phy(bp, 0x17, 0x401f);
  1065. bnx2_write_phy(bp, 0x15, 0x14e2);
  1066. bnx2_write_phy(bp, 0x18, 0x0400);
  1067. }
  1068. if (bp->dev->mtu > 1500) {
  1069. /* Set extended packet length bit */
  1070. bnx2_write_phy(bp, 0x18, 0x7);
  1071. bnx2_read_phy(bp, 0x18, &val);
  1072. bnx2_write_phy(bp, 0x18, val | 0x4000);
  1073. bnx2_read_phy(bp, 0x10, &val);
  1074. bnx2_write_phy(bp, 0x10, val | 0x1);
  1075. }
  1076. else {
  1077. bnx2_write_phy(bp, 0x18, 0x7);
  1078. bnx2_read_phy(bp, 0x18, &val);
  1079. bnx2_write_phy(bp, 0x18, val & ~0x4007);
  1080. bnx2_read_phy(bp, 0x10, &val);
  1081. bnx2_write_phy(bp, 0x10, val & ~0x1);
  1082. }
  1083. /* ethernet@wirespeed */
  1084. bnx2_write_phy(bp, 0x18, 0x7007);
  1085. bnx2_read_phy(bp, 0x18, &val);
  1086. bnx2_write_phy(bp, 0x18, val | (1 << 15) | (1 << 4));
  1087. return 0;
  1088. }
  1089. static int
  1090. bnx2_init_phy(struct bnx2 *bp)
  1091. {
  1092. u32 val;
  1093. int rc = 0;
  1094. bp->phy_flags &= ~PHY_INT_MODE_MASK_FLAG;
  1095. bp->phy_flags |= PHY_INT_MODE_LINK_READY_FLAG;
  1096. REG_WR(bp, BNX2_EMAC_ATTENTION_ENA, BNX2_EMAC_ATTENTION_ENA_LINK);
  1097. bnx2_reset_phy(bp);
  1098. bnx2_read_phy(bp, MII_PHYSID1, &val);
  1099. bp->phy_id = val << 16;
  1100. bnx2_read_phy(bp, MII_PHYSID2, &val);
  1101. bp->phy_id |= val & 0xffff;
  1102. if (bp->phy_flags & PHY_SERDES_FLAG) {
  1103. if (CHIP_NUM(bp) == CHIP_NUM_5706)
  1104. rc = bnx2_init_5706s_phy(bp);
  1105. else if (CHIP_NUM(bp) == CHIP_NUM_5708)
  1106. rc = bnx2_init_5708s_phy(bp);
  1107. }
  1108. else {
  1109. rc = bnx2_init_copper_phy(bp);
  1110. }
  1111. bnx2_setup_phy(bp);
  1112. return rc;
  1113. }
  1114. static int
  1115. bnx2_set_mac_loopback(struct bnx2 *bp)
  1116. {
  1117. u32 mac_mode;
  1118. mac_mode = REG_RD(bp, BNX2_EMAC_MODE);
  1119. mac_mode &= ~BNX2_EMAC_MODE_PORT;
  1120. mac_mode |= BNX2_EMAC_MODE_MAC_LOOP | BNX2_EMAC_MODE_FORCE_LINK;
  1121. REG_WR(bp, BNX2_EMAC_MODE, mac_mode);
  1122. bp->link_up = 1;
  1123. return 0;
  1124. }
  1125. static int bnx2_test_link(struct bnx2 *);
  1126. static int
  1127. bnx2_set_phy_loopback(struct bnx2 *bp)
  1128. {
  1129. u32 mac_mode;
  1130. int rc, i;
  1131. spin_lock_bh(&bp->phy_lock);
  1132. rc = bnx2_write_phy(bp, MII_BMCR, BMCR_LOOPBACK | BMCR_FULLDPLX |
  1133. BMCR_SPEED1000);
  1134. spin_unlock_bh(&bp->phy_lock);
  1135. if (rc)
  1136. return rc;
  1137. for (i = 0; i < 10; i++) {
  1138. if (bnx2_test_link(bp) == 0)
  1139. break;
  1140. udelay(10);
  1141. }
  1142. mac_mode = REG_RD(bp, BNX2_EMAC_MODE);
  1143. mac_mode &= ~(BNX2_EMAC_MODE_PORT | BNX2_EMAC_MODE_HALF_DUPLEX |
  1144. BNX2_EMAC_MODE_MAC_LOOP | BNX2_EMAC_MODE_FORCE_LINK |
  1145. BNX2_EMAC_MODE_25G);
  1146. mac_mode |= BNX2_EMAC_MODE_PORT_GMII;
  1147. REG_WR(bp, BNX2_EMAC_MODE, mac_mode);
  1148. bp->link_up = 1;
  1149. return 0;
  1150. }
  1151. static int
  1152. bnx2_fw_sync(struct bnx2 *bp, u32 msg_data, int silent)
  1153. {
  1154. int i;
  1155. u32 val;
  1156. bp->fw_wr_seq++;
  1157. msg_data |= bp->fw_wr_seq;
  1158. REG_WR_IND(bp, bp->shmem_base + BNX2_DRV_MB, msg_data);
  1159. /* wait for an acknowledgement. */
  1160. for (i = 0; i < (FW_ACK_TIME_OUT_MS / 10); i++) {
  1161. msleep(10);
  1162. val = REG_RD_IND(bp, bp->shmem_base + BNX2_FW_MB);
  1163. if ((val & BNX2_FW_MSG_ACK) == (msg_data & BNX2_DRV_MSG_SEQ))
  1164. break;
  1165. }
  1166. if ((msg_data & BNX2_DRV_MSG_DATA) == BNX2_DRV_MSG_DATA_WAIT0)
  1167. return 0;
  1168. /* If we timed out, inform the firmware that this is the case. */
  1169. if ((val & BNX2_FW_MSG_ACK) != (msg_data & BNX2_DRV_MSG_SEQ)) {
  1170. if (!silent)
  1171. printk(KERN_ERR PFX "fw sync timeout, reset code = "
  1172. "%x\n", msg_data);
  1173. msg_data &= ~BNX2_DRV_MSG_CODE;
  1174. msg_data |= BNX2_DRV_MSG_CODE_FW_TIMEOUT;
  1175. REG_WR_IND(bp, bp->shmem_base + BNX2_DRV_MB, msg_data);
  1176. return -EBUSY;
  1177. }
  1178. if ((val & BNX2_FW_MSG_STATUS_MASK) != BNX2_FW_MSG_STATUS_OK)
  1179. return -EIO;
  1180. return 0;
  1181. }
  1182. static void
  1183. bnx2_init_context(struct bnx2 *bp)
  1184. {
  1185. u32 vcid;
  1186. vcid = 96;
  1187. while (vcid) {
  1188. u32 vcid_addr, pcid_addr, offset;
  1189. vcid--;
  1190. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  1191. u32 new_vcid;
  1192. vcid_addr = GET_PCID_ADDR(vcid);
  1193. if (vcid & 0x8) {
  1194. new_vcid = 0x60 + (vcid & 0xf0) + (vcid & 0x7);
  1195. }
  1196. else {
  1197. new_vcid = vcid;
  1198. }
  1199. pcid_addr = GET_PCID_ADDR(new_vcid);
  1200. }
  1201. else {
  1202. vcid_addr = GET_CID_ADDR(vcid);
  1203. pcid_addr = vcid_addr;
  1204. }
  1205. REG_WR(bp, BNX2_CTX_VIRT_ADDR, 0x00);
  1206. REG_WR(bp, BNX2_CTX_PAGE_TBL, pcid_addr);
  1207. /* Zero out the context. */
  1208. for (offset = 0; offset < PHY_CTX_SIZE; offset += 4) {
  1209. CTX_WR(bp, 0x00, offset, 0);
  1210. }
  1211. REG_WR(bp, BNX2_CTX_VIRT_ADDR, vcid_addr);
  1212. REG_WR(bp, BNX2_CTX_PAGE_TBL, pcid_addr);
  1213. }
  1214. }
  1215. static int
  1216. bnx2_alloc_bad_rbuf(struct bnx2 *bp)
  1217. {
  1218. u16 *good_mbuf;
  1219. u32 good_mbuf_cnt;
  1220. u32 val;
  1221. good_mbuf = kmalloc(512 * sizeof(u16), GFP_KERNEL);
  1222. if (good_mbuf == NULL) {
  1223. printk(KERN_ERR PFX "Failed to allocate memory in "
  1224. "bnx2_alloc_bad_rbuf\n");
  1225. return -ENOMEM;
  1226. }
  1227. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS,
  1228. BNX2_MISC_ENABLE_SET_BITS_RX_MBUF_ENABLE);
  1229. good_mbuf_cnt = 0;
  1230. /* Allocate a bunch of mbufs and save the good ones in an array. */
  1231. val = REG_RD_IND(bp, BNX2_RBUF_STATUS1);
  1232. while (val & BNX2_RBUF_STATUS1_FREE_COUNT) {
  1233. REG_WR_IND(bp, BNX2_RBUF_COMMAND, BNX2_RBUF_COMMAND_ALLOC_REQ);
  1234. val = REG_RD_IND(bp, BNX2_RBUF_FW_BUF_ALLOC);
  1235. val &= BNX2_RBUF_FW_BUF_ALLOC_VALUE;
  1236. /* The addresses with Bit 9 set are bad memory blocks. */
  1237. if (!(val & (1 << 9))) {
  1238. good_mbuf[good_mbuf_cnt] = (u16) val;
  1239. good_mbuf_cnt++;
  1240. }
  1241. val = REG_RD_IND(bp, BNX2_RBUF_STATUS1);
  1242. }
  1243. /* Free the good ones back to the mbuf pool thus discarding
  1244. * all the bad ones. */
  1245. while (good_mbuf_cnt) {
  1246. good_mbuf_cnt--;
  1247. val = good_mbuf[good_mbuf_cnt];
  1248. val = (val << 9) | val | 1;
  1249. REG_WR_IND(bp, BNX2_RBUF_FW_BUF_FREE, val);
  1250. }
  1251. kfree(good_mbuf);
  1252. return 0;
  1253. }
  1254. static void
  1255. bnx2_set_mac_addr(struct bnx2 *bp)
  1256. {
  1257. u32 val;
  1258. u8 *mac_addr = bp->dev->dev_addr;
  1259. val = (mac_addr[0] << 8) | mac_addr[1];
  1260. REG_WR(bp, BNX2_EMAC_MAC_MATCH0, val);
  1261. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  1262. (mac_addr[4] << 8) | mac_addr[5];
  1263. REG_WR(bp, BNX2_EMAC_MAC_MATCH1, val);
  1264. }
  1265. static inline int
  1266. bnx2_alloc_rx_skb(struct bnx2 *bp, u16 index)
  1267. {
  1268. struct sk_buff *skb;
  1269. struct sw_bd *rx_buf = &bp->rx_buf_ring[index];
  1270. dma_addr_t mapping;
  1271. struct rx_bd *rxbd = &bp->rx_desc_ring[index];
  1272. unsigned long align;
  1273. skb = dev_alloc_skb(bp->rx_buf_size);
  1274. if (skb == NULL) {
  1275. return -ENOMEM;
  1276. }
  1277. if (unlikely((align = (unsigned long) skb->data & 0x7))) {
  1278. skb_reserve(skb, 8 - align);
  1279. }
  1280. skb->dev = bp->dev;
  1281. mapping = pci_map_single(bp->pdev, skb->data, bp->rx_buf_use_size,
  1282. PCI_DMA_FROMDEVICE);
  1283. rx_buf->skb = skb;
  1284. pci_unmap_addr_set(rx_buf, mapping, mapping);
  1285. rxbd->rx_bd_haddr_hi = (u64) mapping >> 32;
  1286. rxbd->rx_bd_haddr_lo = (u64) mapping & 0xffffffff;
  1287. bp->rx_prod_bseq += bp->rx_buf_use_size;
  1288. return 0;
  1289. }
  1290. static void
  1291. bnx2_phy_int(struct bnx2 *bp)
  1292. {
  1293. u32 new_link_state, old_link_state;
  1294. new_link_state = bp->status_blk->status_attn_bits &
  1295. STATUS_ATTN_BITS_LINK_STATE;
  1296. old_link_state = bp->status_blk->status_attn_bits_ack &
  1297. STATUS_ATTN_BITS_LINK_STATE;
  1298. if (new_link_state != old_link_state) {
  1299. if (new_link_state) {
  1300. REG_WR(bp, BNX2_PCICFG_STATUS_BIT_SET_CMD,
  1301. STATUS_ATTN_BITS_LINK_STATE);
  1302. }
  1303. else {
  1304. REG_WR(bp, BNX2_PCICFG_STATUS_BIT_CLEAR_CMD,
  1305. STATUS_ATTN_BITS_LINK_STATE);
  1306. }
  1307. bnx2_set_link(bp);
  1308. }
  1309. }
  1310. static void
  1311. bnx2_tx_int(struct bnx2 *bp)
  1312. {
  1313. struct status_block *sblk = bp->status_blk;
  1314. u16 hw_cons, sw_cons, sw_ring_cons;
  1315. int tx_free_bd = 0;
  1316. hw_cons = bp->hw_tx_cons = sblk->status_tx_quick_consumer_index0;
  1317. if ((hw_cons & MAX_TX_DESC_CNT) == MAX_TX_DESC_CNT) {
  1318. hw_cons++;
  1319. }
  1320. sw_cons = bp->tx_cons;
  1321. while (sw_cons != hw_cons) {
  1322. struct sw_bd *tx_buf;
  1323. struct sk_buff *skb;
  1324. int i, last;
  1325. sw_ring_cons = TX_RING_IDX(sw_cons);
  1326. tx_buf = &bp->tx_buf_ring[sw_ring_cons];
  1327. skb = tx_buf->skb;
  1328. #ifdef BCM_TSO
  1329. /* partial BD completions possible with TSO packets */
  1330. if (skb_shinfo(skb)->tso_size) {
  1331. u16 last_idx, last_ring_idx;
  1332. last_idx = sw_cons +
  1333. skb_shinfo(skb)->nr_frags + 1;
  1334. last_ring_idx = sw_ring_cons +
  1335. skb_shinfo(skb)->nr_frags + 1;
  1336. if (unlikely(last_ring_idx >= MAX_TX_DESC_CNT)) {
  1337. last_idx++;
  1338. }
  1339. if (((s16) ((s16) last_idx - (s16) hw_cons)) > 0) {
  1340. break;
  1341. }
  1342. }
  1343. #endif
  1344. pci_unmap_single(bp->pdev, pci_unmap_addr(tx_buf, mapping),
  1345. skb_headlen(skb), PCI_DMA_TODEVICE);
  1346. tx_buf->skb = NULL;
  1347. last = skb_shinfo(skb)->nr_frags;
  1348. for (i = 0; i < last; i++) {
  1349. sw_cons = NEXT_TX_BD(sw_cons);
  1350. pci_unmap_page(bp->pdev,
  1351. pci_unmap_addr(
  1352. &bp->tx_buf_ring[TX_RING_IDX(sw_cons)],
  1353. mapping),
  1354. skb_shinfo(skb)->frags[i].size,
  1355. PCI_DMA_TODEVICE);
  1356. }
  1357. sw_cons = NEXT_TX_BD(sw_cons);
  1358. tx_free_bd += last + 1;
  1359. dev_kfree_skb_irq(skb);
  1360. hw_cons = bp->hw_tx_cons =
  1361. sblk->status_tx_quick_consumer_index0;
  1362. if ((hw_cons & MAX_TX_DESC_CNT) == MAX_TX_DESC_CNT) {
  1363. hw_cons++;
  1364. }
  1365. }
  1366. bp->tx_cons = sw_cons;
  1367. if (unlikely(netif_queue_stopped(bp->dev))) {
  1368. spin_lock(&bp->tx_lock);
  1369. if ((netif_queue_stopped(bp->dev)) &&
  1370. (bnx2_tx_avail(bp) > MAX_SKB_FRAGS)) {
  1371. netif_wake_queue(bp->dev);
  1372. }
  1373. spin_unlock(&bp->tx_lock);
  1374. }
  1375. }
  1376. static inline void
  1377. bnx2_reuse_rx_skb(struct bnx2 *bp, struct sk_buff *skb,
  1378. u16 cons, u16 prod)
  1379. {
  1380. struct sw_bd *cons_rx_buf = &bp->rx_buf_ring[cons];
  1381. struct sw_bd *prod_rx_buf = &bp->rx_buf_ring[prod];
  1382. struct rx_bd *cons_bd = &bp->rx_desc_ring[cons];
  1383. struct rx_bd *prod_bd = &bp->rx_desc_ring[prod];
  1384. pci_dma_sync_single_for_device(bp->pdev,
  1385. pci_unmap_addr(cons_rx_buf, mapping),
  1386. bp->rx_offset + RX_COPY_THRESH, PCI_DMA_FROMDEVICE);
  1387. prod_rx_buf->skb = cons_rx_buf->skb;
  1388. pci_unmap_addr_set(prod_rx_buf, mapping,
  1389. pci_unmap_addr(cons_rx_buf, mapping));
  1390. memcpy(prod_bd, cons_bd, 8);
  1391. bp->rx_prod_bseq += bp->rx_buf_use_size;
  1392. }
  1393. static int
  1394. bnx2_rx_int(struct bnx2 *bp, int budget)
  1395. {
  1396. struct status_block *sblk = bp->status_blk;
  1397. u16 hw_cons, sw_cons, sw_ring_cons, sw_prod, sw_ring_prod;
  1398. struct l2_fhdr *rx_hdr;
  1399. int rx_pkt = 0;
  1400. hw_cons = bp->hw_rx_cons = sblk->status_rx_quick_consumer_index0;
  1401. if ((hw_cons & MAX_RX_DESC_CNT) == MAX_RX_DESC_CNT) {
  1402. hw_cons++;
  1403. }
  1404. sw_cons = bp->rx_cons;
  1405. sw_prod = bp->rx_prod;
  1406. /* Memory barrier necessary as speculative reads of the rx
  1407. * buffer can be ahead of the index in the status block
  1408. */
  1409. rmb();
  1410. while (sw_cons != hw_cons) {
  1411. unsigned int len;
  1412. u32 status;
  1413. struct sw_bd *rx_buf;
  1414. struct sk_buff *skb;
  1415. sw_ring_cons = RX_RING_IDX(sw_cons);
  1416. sw_ring_prod = RX_RING_IDX(sw_prod);
  1417. rx_buf = &bp->rx_buf_ring[sw_ring_cons];
  1418. skb = rx_buf->skb;
  1419. pci_dma_sync_single_for_cpu(bp->pdev,
  1420. pci_unmap_addr(rx_buf, mapping),
  1421. bp->rx_offset + RX_COPY_THRESH, PCI_DMA_FROMDEVICE);
  1422. rx_hdr = (struct l2_fhdr *) skb->data;
  1423. len = rx_hdr->l2_fhdr_pkt_len - 4;
  1424. if ((status = rx_hdr->l2_fhdr_status) &
  1425. (L2_FHDR_ERRORS_BAD_CRC |
  1426. L2_FHDR_ERRORS_PHY_DECODE |
  1427. L2_FHDR_ERRORS_ALIGNMENT |
  1428. L2_FHDR_ERRORS_TOO_SHORT |
  1429. L2_FHDR_ERRORS_GIANT_FRAME)) {
  1430. goto reuse_rx;
  1431. }
  1432. /* Since we don't have a jumbo ring, copy small packets
  1433. * if mtu > 1500
  1434. */
  1435. if ((bp->dev->mtu > 1500) && (len <= RX_COPY_THRESH)) {
  1436. struct sk_buff *new_skb;
  1437. new_skb = dev_alloc_skb(len + 2);
  1438. if (new_skb == NULL)
  1439. goto reuse_rx;
  1440. /* aligned copy */
  1441. memcpy(new_skb->data,
  1442. skb->data + bp->rx_offset - 2,
  1443. len + 2);
  1444. skb_reserve(new_skb, 2);
  1445. skb_put(new_skb, len);
  1446. new_skb->dev = bp->dev;
  1447. bnx2_reuse_rx_skb(bp, skb,
  1448. sw_ring_cons, sw_ring_prod);
  1449. skb = new_skb;
  1450. }
  1451. else if (bnx2_alloc_rx_skb(bp, sw_ring_prod) == 0) {
  1452. pci_unmap_single(bp->pdev,
  1453. pci_unmap_addr(rx_buf, mapping),
  1454. bp->rx_buf_use_size, PCI_DMA_FROMDEVICE);
  1455. skb_reserve(skb, bp->rx_offset);
  1456. skb_put(skb, len);
  1457. }
  1458. else {
  1459. reuse_rx:
  1460. bnx2_reuse_rx_skb(bp, skb,
  1461. sw_ring_cons, sw_ring_prod);
  1462. goto next_rx;
  1463. }
  1464. skb->protocol = eth_type_trans(skb, bp->dev);
  1465. if ((len > (bp->dev->mtu + ETH_HLEN)) &&
  1466. (htons(skb->protocol) != 0x8100)) {
  1467. dev_kfree_skb_irq(skb);
  1468. goto next_rx;
  1469. }
  1470. skb->ip_summed = CHECKSUM_NONE;
  1471. if (bp->rx_csum &&
  1472. (status & (L2_FHDR_STATUS_TCP_SEGMENT |
  1473. L2_FHDR_STATUS_UDP_DATAGRAM))) {
  1474. if (likely((status & (L2_FHDR_ERRORS_TCP_XSUM |
  1475. L2_FHDR_ERRORS_UDP_XSUM)) == 0))
  1476. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1477. }
  1478. #ifdef BCM_VLAN
  1479. if ((status & L2_FHDR_STATUS_L2_VLAN_TAG) && (bp->vlgrp != 0)) {
  1480. vlan_hwaccel_receive_skb(skb, bp->vlgrp,
  1481. rx_hdr->l2_fhdr_vlan_tag);
  1482. }
  1483. else
  1484. #endif
  1485. netif_receive_skb(skb);
  1486. bp->dev->last_rx = jiffies;
  1487. rx_pkt++;
  1488. next_rx:
  1489. rx_buf->skb = NULL;
  1490. sw_cons = NEXT_RX_BD(sw_cons);
  1491. sw_prod = NEXT_RX_BD(sw_prod);
  1492. if ((rx_pkt == budget))
  1493. break;
  1494. /* Refresh hw_cons to see if there is new work */
  1495. if (sw_cons == hw_cons) {
  1496. hw_cons = bp->hw_rx_cons =
  1497. sblk->status_rx_quick_consumer_index0;
  1498. if ((hw_cons & MAX_RX_DESC_CNT) == MAX_RX_DESC_CNT)
  1499. hw_cons++;
  1500. rmb();
  1501. }
  1502. }
  1503. bp->rx_cons = sw_cons;
  1504. bp->rx_prod = sw_prod;
  1505. REG_WR16(bp, MB_RX_CID_ADDR + BNX2_L2CTX_HOST_BDIDX, sw_prod);
  1506. REG_WR(bp, MB_RX_CID_ADDR + BNX2_L2CTX_HOST_BSEQ, bp->rx_prod_bseq);
  1507. mmiowb();
  1508. return rx_pkt;
  1509. }
  1510. /* MSI ISR - The only difference between this and the INTx ISR
  1511. * is that the MSI interrupt is always serviced.
  1512. */
  1513. static irqreturn_t
  1514. bnx2_msi(int irq, void *dev_instance, struct pt_regs *regs)
  1515. {
  1516. struct net_device *dev = dev_instance;
  1517. struct bnx2 *bp = netdev_priv(dev);
  1518. prefetch(bp->status_blk);
  1519. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  1520. BNX2_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
  1521. BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  1522. /* Return here if interrupt is disabled. */
  1523. if (unlikely(atomic_read(&bp->intr_sem) != 0))
  1524. return IRQ_HANDLED;
  1525. netif_rx_schedule(dev);
  1526. return IRQ_HANDLED;
  1527. }
  1528. static irqreturn_t
  1529. bnx2_interrupt(int irq, void *dev_instance, struct pt_regs *regs)
  1530. {
  1531. struct net_device *dev = dev_instance;
  1532. struct bnx2 *bp = netdev_priv(dev);
  1533. /* When using INTx, it is possible for the interrupt to arrive
  1534. * at the CPU before the status block posted prior to the
  1535. * interrupt. Reading a register will flush the status block.
  1536. * When using MSI, the MSI message will always complete after
  1537. * the status block write.
  1538. */
  1539. if ((bp->status_blk->status_idx == bp->last_status_idx) &&
  1540. (REG_RD(bp, BNX2_PCICFG_MISC_STATUS) &
  1541. BNX2_PCICFG_MISC_STATUS_INTA_VALUE))
  1542. return IRQ_NONE;
  1543. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  1544. BNX2_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
  1545. BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  1546. /* Return here if interrupt is shared and is disabled. */
  1547. if (unlikely(atomic_read(&bp->intr_sem) != 0))
  1548. return IRQ_HANDLED;
  1549. netif_rx_schedule(dev);
  1550. return IRQ_HANDLED;
  1551. }
  1552. static inline int
  1553. bnx2_has_work(struct bnx2 *bp)
  1554. {
  1555. struct status_block *sblk = bp->status_blk;
  1556. if ((sblk->status_rx_quick_consumer_index0 != bp->hw_rx_cons) ||
  1557. (sblk->status_tx_quick_consumer_index0 != bp->hw_tx_cons))
  1558. return 1;
  1559. if (((sblk->status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) != 0) !=
  1560. bp->link_up)
  1561. return 1;
  1562. return 0;
  1563. }
  1564. static int
  1565. bnx2_poll(struct net_device *dev, int *budget)
  1566. {
  1567. struct bnx2 *bp = netdev_priv(dev);
  1568. if ((bp->status_blk->status_attn_bits &
  1569. STATUS_ATTN_BITS_LINK_STATE) !=
  1570. (bp->status_blk->status_attn_bits_ack &
  1571. STATUS_ATTN_BITS_LINK_STATE)) {
  1572. spin_lock(&bp->phy_lock);
  1573. bnx2_phy_int(bp);
  1574. spin_unlock(&bp->phy_lock);
  1575. }
  1576. if (bp->status_blk->status_tx_quick_consumer_index0 != bp->hw_tx_cons)
  1577. bnx2_tx_int(bp);
  1578. if (bp->status_blk->status_rx_quick_consumer_index0 != bp->hw_rx_cons) {
  1579. int orig_budget = *budget;
  1580. int work_done;
  1581. if (orig_budget > dev->quota)
  1582. orig_budget = dev->quota;
  1583. work_done = bnx2_rx_int(bp, orig_budget);
  1584. *budget -= work_done;
  1585. dev->quota -= work_done;
  1586. }
  1587. bp->last_status_idx = bp->status_blk->status_idx;
  1588. rmb();
  1589. if (!bnx2_has_work(bp)) {
  1590. netif_rx_complete(dev);
  1591. if (likely(bp->flags & USING_MSI_FLAG)) {
  1592. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  1593. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  1594. bp->last_status_idx);
  1595. return 0;
  1596. }
  1597. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  1598. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  1599. BNX2_PCICFG_INT_ACK_CMD_MASK_INT |
  1600. bp->last_status_idx);
  1601. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  1602. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  1603. bp->last_status_idx);
  1604. return 0;
  1605. }
  1606. return 1;
  1607. }
  1608. /* Called with rtnl_lock from vlan functions and also dev->xmit_lock
  1609. * from set_multicast.
  1610. */
  1611. static void
  1612. bnx2_set_rx_mode(struct net_device *dev)
  1613. {
  1614. struct bnx2 *bp = netdev_priv(dev);
  1615. u32 rx_mode, sort_mode;
  1616. int i;
  1617. spin_lock_bh(&bp->phy_lock);
  1618. rx_mode = bp->rx_mode & ~(BNX2_EMAC_RX_MODE_PROMISCUOUS |
  1619. BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG);
  1620. sort_mode = 1 | BNX2_RPM_SORT_USER0_BC_EN;
  1621. #ifdef BCM_VLAN
  1622. if (!bp->vlgrp && !(bp->flags & ASF_ENABLE_FLAG))
  1623. rx_mode |= BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG;
  1624. #else
  1625. if (!(bp->flags & ASF_ENABLE_FLAG))
  1626. rx_mode |= BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG;
  1627. #endif
  1628. if (dev->flags & IFF_PROMISC) {
  1629. /* Promiscuous mode. */
  1630. rx_mode |= BNX2_EMAC_RX_MODE_PROMISCUOUS;
  1631. sort_mode |= BNX2_RPM_SORT_USER0_PROM_EN;
  1632. }
  1633. else if (dev->flags & IFF_ALLMULTI) {
  1634. for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
  1635. REG_WR(bp, BNX2_EMAC_MULTICAST_HASH0 + (i * 4),
  1636. 0xffffffff);
  1637. }
  1638. sort_mode |= BNX2_RPM_SORT_USER0_MC_EN;
  1639. }
  1640. else {
  1641. /* Accept one or more multicast(s). */
  1642. struct dev_mc_list *mclist;
  1643. u32 mc_filter[NUM_MC_HASH_REGISTERS];
  1644. u32 regidx;
  1645. u32 bit;
  1646. u32 crc;
  1647. memset(mc_filter, 0, 4 * NUM_MC_HASH_REGISTERS);
  1648. for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
  1649. i++, mclist = mclist->next) {
  1650. crc = ether_crc_le(ETH_ALEN, mclist->dmi_addr);
  1651. bit = crc & 0xff;
  1652. regidx = (bit & 0xe0) >> 5;
  1653. bit &= 0x1f;
  1654. mc_filter[regidx] |= (1 << bit);
  1655. }
  1656. for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
  1657. REG_WR(bp, BNX2_EMAC_MULTICAST_HASH0 + (i * 4),
  1658. mc_filter[i]);
  1659. }
  1660. sort_mode |= BNX2_RPM_SORT_USER0_MC_HSH_EN;
  1661. }
  1662. if (rx_mode != bp->rx_mode) {
  1663. bp->rx_mode = rx_mode;
  1664. REG_WR(bp, BNX2_EMAC_RX_MODE, rx_mode);
  1665. }
  1666. REG_WR(bp, BNX2_RPM_SORT_USER0, 0x0);
  1667. REG_WR(bp, BNX2_RPM_SORT_USER0, sort_mode);
  1668. REG_WR(bp, BNX2_RPM_SORT_USER0, sort_mode | BNX2_RPM_SORT_USER0_ENA);
  1669. spin_unlock_bh(&bp->phy_lock);
  1670. }
  1671. static void
  1672. load_rv2p_fw(struct bnx2 *bp, u32 *rv2p_code, u32 rv2p_code_len,
  1673. u32 rv2p_proc)
  1674. {
  1675. int i;
  1676. u32 val;
  1677. for (i = 0; i < rv2p_code_len; i += 8) {
  1678. REG_WR(bp, BNX2_RV2P_INSTR_HIGH, *rv2p_code);
  1679. rv2p_code++;
  1680. REG_WR(bp, BNX2_RV2P_INSTR_LOW, *rv2p_code);
  1681. rv2p_code++;
  1682. if (rv2p_proc == RV2P_PROC1) {
  1683. val = (i / 8) | BNX2_RV2P_PROC1_ADDR_CMD_RDWR;
  1684. REG_WR(bp, BNX2_RV2P_PROC1_ADDR_CMD, val);
  1685. }
  1686. else {
  1687. val = (i / 8) | BNX2_RV2P_PROC2_ADDR_CMD_RDWR;
  1688. REG_WR(bp, BNX2_RV2P_PROC2_ADDR_CMD, val);
  1689. }
  1690. }
  1691. /* Reset the processor, un-stall is done later. */
  1692. if (rv2p_proc == RV2P_PROC1) {
  1693. REG_WR(bp, BNX2_RV2P_COMMAND, BNX2_RV2P_COMMAND_PROC1_RESET);
  1694. }
  1695. else {
  1696. REG_WR(bp, BNX2_RV2P_COMMAND, BNX2_RV2P_COMMAND_PROC2_RESET);
  1697. }
  1698. }
  1699. static void
  1700. load_cpu_fw(struct bnx2 *bp, struct cpu_reg *cpu_reg, struct fw_info *fw)
  1701. {
  1702. u32 offset;
  1703. u32 val;
  1704. /* Halt the CPU. */
  1705. val = REG_RD_IND(bp, cpu_reg->mode);
  1706. val |= cpu_reg->mode_value_halt;
  1707. REG_WR_IND(bp, cpu_reg->mode, val);
  1708. REG_WR_IND(bp, cpu_reg->state, cpu_reg->state_value_clear);
  1709. /* Load the Text area. */
  1710. offset = cpu_reg->spad_base + (fw->text_addr - cpu_reg->mips_view_base);
  1711. if (fw->text) {
  1712. int j;
  1713. for (j = 0; j < (fw->text_len / 4); j++, offset += 4) {
  1714. REG_WR_IND(bp, offset, fw->text[j]);
  1715. }
  1716. }
  1717. /* Load the Data area. */
  1718. offset = cpu_reg->spad_base + (fw->data_addr - cpu_reg->mips_view_base);
  1719. if (fw->data) {
  1720. int j;
  1721. for (j = 0; j < (fw->data_len / 4); j++, offset += 4) {
  1722. REG_WR_IND(bp, offset, fw->data[j]);
  1723. }
  1724. }
  1725. /* Load the SBSS area. */
  1726. offset = cpu_reg->spad_base + (fw->sbss_addr - cpu_reg->mips_view_base);
  1727. if (fw->sbss) {
  1728. int j;
  1729. for (j = 0; j < (fw->sbss_len / 4); j++, offset += 4) {
  1730. REG_WR_IND(bp, offset, fw->sbss[j]);
  1731. }
  1732. }
  1733. /* Load the BSS area. */
  1734. offset = cpu_reg->spad_base + (fw->bss_addr - cpu_reg->mips_view_base);
  1735. if (fw->bss) {
  1736. int j;
  1737. for (j = 0; j < (fw->bss_len/4); j++, offset += 4) {
  1738. REG_WR_IND(bp, offset, fw->bss[j]);
  1739. }
  1740. }
  1741. /* Load the Read-Only area. */
  1742. offset = cpu_reg->spad_base +
  1743. (fw->rodata_addr - cpu_reg->mips_view_base);
  1744. if (fw->rodata) {
  1745. int j;
  1746. for (j = 0; j < (fw->rodata_len / 4); j++, offset += 4) {
  1747. REG_WR_IND(bp, offset, fw->rodata[j]);
  1748. }
  1749. }
  1750. /* Clear the pre-fetch instruction. */
  1751. REG_WR_IND(bp, cpu_reg->inst, 0);
  1752. REG_WR_IND(bp, cpu_reg->pc, fw->start_addr);
  1753. /* Start the CPU. */
  1754. val = REG_RD_IND(bp, cpu_reg->mode);
  1755. val &= ~cpu_reg->mode_value_halt;
  1756. REG_WR_IND(bp, cpu_reg->state, cpu_reg->state_value_clear);
  1757. REG_WR_IND(bp, cpu_reg->mode, val);
  1758. }
  1759. static void
  1760. bnx2_init_cpus(struct bnx2 *bp)
  1761. {
  1762. struct cpu_reg cpu_reg;
  1763. struct fw_info fw;
  1764. /* Initialize the RV2P processor. */
  1765. load_rv2p_fw(bp, bnx2_rv2p_proc1, sizeof(bnx2_rv2p_proc1), RV2P_PROC1);
  1766. load_rv2p_fw(bp, bnx2_rv2p_proc2, sizeof(bnx2_rv2p_proc2), RV2P_PROC2);
  1767. /* Initialize the RX Processor. */
  1768. cpu_reg.mode = BNX2_RXP_CPU_MODE;
  1769. cpu_reg.mode_value_halt = BNX2_RXP_CPU_MODE_SOFT_HALT;
  1770. cpu_reg.mode_value_sstep = BNX2_RXP_CPU_MODE_STEP_ENA;
  1771. cpu_reg.state = BNX2_RXP_CPU_STATE;
  1772. cpu_reg.state_value_clear = 0xffffff;
  1773. cpu_reg.gpr0 = BNX2_RXP_CPU_REG_FILE;
  1774. cpu_reg.evmask = BNX2_RXP_CPU_EVENT_MASK;
  1775. cpu_reg.pc = BNX2_RXP_CPU_PROGRAM_COUNTER;
  1776. cpu_reg.inst = BNX2_RXP_CPU_INSTRUCTION;
  1777. cpu_reg.bp = BNX2_RXP_CPU_HW_BREAKPOINT;
  1778. cpu_reg.spad_base = BNX2_RXP_SCRATCH;
  1779. cpu_reg.mips_view_base = 0x8000000;
  1780. fw.ver_major = bnx2_RXP_b06FwReleaseMajor;
  1781. fw.ver_minor = bnx2_RXP_b06FwReleaseMinor;
  1782. fw.ver_fix = bnx2_RXP_b06FwReleaseFix;
  1783. fw.start_addr = bnx2_RXP_b06FwStartAddr;
  1784. fw.text_addr = bnx2_RXP_b06FwTextAddr;
  1785. fw.text_len = bnx2_RXP_b06FwTextLen;
  1786. fw.text_index = 0;
  1787. fw.text = bnx2_RXP_b06FwText;
  1788. fw.data_addr = bnx2_RXP_b06FwDataAddr;
  1789. fw.data_len = bnx2_RXP_b06FwDataLen;
  1790. fw.data_index = 0;
  1791. fw.data = bnx2_RXP_b06FwData;
  1792. fw.sbss_addr = bnx2_RXP_b06FwSbssAddr;
  1793. fw.sbss_len = bnx2_RXP_b06FwSbssLen;
  1794. fw.sbss_index = 0;
  1795. fw.sbss = bnx2_RXP_b06FwSbss;
  1796. fw.bss_addr = bnx2_RXP_b06FwBssAddr;
  1797. fw.bss_len = bnx2_RXP_b06FwBssLen;
  1798. fw.bss_index = 0;
  1799. fw.bss = bnx2_RXP_b06FwBss;
  1800. fw.rodata_addr = bnx2_RXP_b06FwRodataAddr;
  1801. fw.rodata_len = bnx2_RXP_b06FwRodataLen;
  1802. fw.rodata_index = 0;
  1803. fw.rodata = bnx2_RXP_b06FwRodata;
  1804. load_cpu_fw(bp, &cpu_reg, &fw);
  1805. /* Initialize the TX Processor. */
  1806. cpu_reg.mode = BNX2_TXP_CPU_MODE;
  1807. cpu_reg.mode_value_halt = BNX2_TXP_CPU_MODE_SOFT_HALT;
  1808. cpu_reg.mode_value_sstep = BNX2_TXP_CPU_MODE_STEP_ENA;
  1809. cpu_reg.state = BNX2_TXP_CPU_STATE;
  1810. cpu_reg.state_value_clear = 0xffffff;
  1811. cpu_reg.gpr0 = BNX2_TXP_CPU_REG_FILE;
  1812. cpu_reg.evmask = BNX2_TXP_CPU_EVENT_MASK;
  1813. cpu_reg.pc = BNX2_TXP_CPU_PROGRAM_COUNTER;
  1814. cpu_reg.inst = BNX2_TXP_CPU_INSTRUCTION;
  1815. cpu_reg.bp = BNX2_TXP_CPU_HW_BREAKPOINT;
  1816. cpu_reg.spad_base = BNX2_TXP_SCRATCH;
  1817. cpu_reg.mips_view_base = 0x8000000;
  1818. fw.ver_major = bnx2_TXP_b06FwReleaseMajor;
  1819. fw.ver_minor = bnx2_TXP_b06FwReleaseMinor;
  1820. fw.ver_fix = bnx2_TXP_b06FwReleaseFix;
  1821. fw.start_addr = bnx2_TXP_b06FwStartAddr;
  1822. fw.text_addr = bnx2_TXP_b06FwTextAddr;
  1823. fw.text_len = bnx2_TXP_b06FwTextLen;
  1824. fw.text_index = 0;
  1825. fw.text = bnx2_TXP_b06FwText;
  1826. fw.data_addr = bnx2_TXP_b06FwDataAddr;
  1827. fw.data_len = bnx2_TXP_b06FwDataLen;
  1828. fw.data_index = 0;
  1829. fw.data = bnx2_TXP_b06FwData;
  1830. fw.sbss_addr = bnx2_TXP_b06FwSbssAddr;
  1831. fw.sbss_len = bnx2_TXP_b06FwSbssLen;
  1832. fw.sbss_index = 0;
  1833. fw.sbss = bnx2_TXP_b06FwSbss;
  1834. fw.bss_addr = bnx2_TXP_b06FwBssAddr;
  1835. fw.bss_len = bnx2_TXP_b06FwBssLen;
  1836. fw.bss_index = 0;
  1837. fw.bss = bnx2_TXP_b06FwBss;
  1838. fw.rodata_addr = bnx2_TXP_b06FwRodataAddr;
  1839. fw.rodata_len = bnx2_TXP_b06FwRodataLen;
  1840. fw.rodata_index = 0;
  1841. fw.rodata = bnx2_TXP_b06FwRodata;
  1842. load_cpu_fw(bp, &cpu_reg, &fw);
  1843. /* Initialize the TX Patch-up Processor. */
  1844. cpu_reg.mode = BNX2_TPAT_CPU_MODE;
  1845. cpu_reg.mode_value_halt = BNX2_TPAT_CPU_MODE_SOFT_HALT;
  1846. cpu_reg.mode_value_sstep = BNX2_TPAT_CPU_MODE_STEP_ENA;
  1847. cpu_reg.state = BNX2_TPAT_CPU_STATE;
  1848. cpu_reg.state_value_clear = 0xffffff;
  1849. cpu_reg.gpr0 = BNX2_TPAT_CPU_REG_FILE;
  1850. cpu_reg.evmask = BNX2_TPAT_CPU_EVENT_MASK;
  1851. cpu_reg.pc = BNX2_TPAT_CPU_PROGRAM_COUNTER;
  1852. cpu_reg.inst = BNX2_TPAT_CPU_INSTRUCTION;
  1853. cpu_reg.bp = BNX2_TPAT_CPU_HW_BREAKPOINT;
  1854. cpu_reg.spad_base = BNX2_TPAT_SCRATCH;
  1855. cpu_reg.mips_view_base = 0x8000000;
  1856. fw.ver_major = bnx2_TPAT_b06FwReleaseMajor;
  1857. fw.ver_minor = bnx2_TPAT_b06FwReleaseMinor;
  1858. fw.ver_fix = bnx2_TPAT_b06FwReleaseFix;
  1859. fw.start_addr = bnx2_TPAT_b06FwStartAddr;
  1860. fw.text_addr = bnx2_TPAT_b06FwTextAddr;
  1861. fw.text_len = bnx2_TPAT_b06FwTextLen;
  1862. fw.text_index = 0;
  1863. fw.text = bnx2_TPAT_b06FwText;
  1864. fw.data_addr = bnx2_TPAT_b06FwDataAddr;
  1865. fw.data_len = bnx2_TPAT_b06FwDataLen;
  1866. fw.data_index = 0;
  1867. fw.data = bnx2_TPAT_b06FwData;
  1868. fw.sbss_addr = bnx2_TPAT_b06FwSbssAddr;
  1869. fw.sbss_len = bnx2_TPAT_b06FwSbssLen;
  1870. fw.sbss_index = 0;
  1871. fw.sbss = bnx2_TPAT_b06FwSbss;
  1872. fw.bss_addr = bnx2_TPAT_b06FwBssAddr;
  1873. fw.bss_len = bnx2_TPAT_b06FwBssLen;
  1874. fw.bss_index = 0;
  1875. fw.bss = bnx2_TPAT_b06FwBss;
  1876. fw.rodata_addr = bnx2_TPAT_b06FwRodataAddr;
  1877. fw.rodata_len = bnx2_TPAT_b06FwRodataLen;
  1878. fw.rodata_index = 0;
  1879. fw.rodata = bnx2_TPAT_b06FwRodata;
  1880. load_cpu_fw(bp, &cpu_reg, &fw);
  1881. /* Initialize the Completion Processor. */
  1882. cpu_reg.mode = BNX2_COM_CPU_MODE;
  1883. cpu_reg.mode_value_halt = BNX2_COM_CPU_MODE_SOFT_HALT;
  1884. cpu_reg.mode_value_sstep = BNX2_COM_CPU_MODE_STEP_ENA;
  1885. cpu_reg.state = BNX2_COM_CPU_STATE;
  1886. cpu_reg.state_value_clear = 0xffffff;
  1887. cpu_reg.gpr0 = BNX2_COM_CPU_REG_FILE;
  1888. cpu_reg.evmask = BNX2_COM_CPU_EVENT_MASK;
  1889. cpu_reg.pc = BNX2_COM_CPU_PROGRAM_COUNTER;
  1890. cpu_reg.inst = BNX2_COM_CPU_INSTRUCTION;
  1891. cpu_reg.bp = BNX2_COM_CPU_HW_BREAKPOINT;
  1892. cpu_reg.spad_base = BNX2_COM_SCRATCH;
  1893. cpu_reg.mips_view_base = 0x8000000;
  1894. fw.ver_major = bnx2_COM_b06FwReleaseMajor;
  1895. fw.ver_minor = bnx2_COM_b06FwReleaseMinor;
  1896. fw.ver_fix = bnx2_COM_b06FwReleaseFix;
  1897. fw.start_addr = bnx2_COM_b06FwStartAddr;
  1898. fw.text_addr = bnx2_COM_b06FwTextAddr;
  1899. fw.text_len = bnx2_COM_b06FwTextLen;
  1900. fw.text_index = 0;
  1901. fw.text = bnx2_COM_b06FwText;
  1902. fw.data_addr = bnx2_COM_b06FwDataAddr;
  1903. fw.data_len = bnx2_COM_b06FwDataLen;
  1904. fw.data_index = 0;
  1905. fw.data = bnx2_COM_b06FwData;
  1906. fw.sbss_addr = bnx2_COM_b06FwSbssAddr;
  1907. fw.sbss_len = bnx2_COM_b06FwSbssLen;
  1908. fw.sbss_index = 0;
  1909. fw.sbss = bnx2_COM_b06FwSbss;
  1910. fw.bss_addr = bnx2_COM_b06FwBssAddr;
  1911. fw.bss_len = bnx2_COM_b06FwBssLen;
  1912. fw.bss_index = 0;
  1913. fw.bss = bnx2_COM_b06FwBss;
  1914. fw.rodata_addr = bnx2_COM_b06FwRodataAddr;
  1915. fw.rodata_len = bnx2_COM_b06FwRodataLen;
  1916. fw.rodata_index = 0;
  1917. fw.rodata = bnx2_COM_b06FwRodata;
  1918. load_cpu_fw(bp, &cpu_reg, &fw);
  1919. }
  1920. static int
  1921. bnx2_set_power_state(struct bnx2 *bp, pci_power_t state)
  1922. {
  1923. u16 pmcsr;
  1924. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmcsr);
  1925. switch (state) {
  1926. case PCI_D0: {
  1927. u32 val;
  1928. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
  1929. (pmcsr & ~PCI_PM_CTRL_STATE_MASK) |
  1930. PCI_PM_CTRL_PME_STATUS);
  1931. if (pmcsr & PCI_PM_CTRL_STATE_MASK)
  1932. /* delay required during transition out of D3hot */
  1933. msleep(20);
  1934. val = REG_RD(bp, BNX2_EMAC_MODE);
  1935. val |= BNX2_EMAC_MODE_MPKT_RCVD | BNX2_EMAC_MODE_ACPI_RCVD;
  1936. val &= ~BNX2_EMAC_MODE_MPKT;
  1937. REG_WR(bp, BNX2_EMAC_MODE, val);
  1938. val = REG_RD(bp, BNX2_RPM_CONFIG);
  1939. val &= ~BNX2_RPM_CONFIG_ACPI_ENA;
  1940. REG_WR(bp, BNX2_RPM_CONFIG, val);
  1941. break;
  1942. }
  1943. case PCI_D3hot: {
  1944. int i;
  1945. u32 val, wol_msg;
  1946. if (bp->wol) {
  1947. u32 advertising;
  1948. u8 autoneg;
  1949. autoneg = bp->autoneg;
  1950. advertising = bp->advertising;
  1951. bp->autoneg = AUTONEG_SPEED;
  1952. bp->advertising = ADVERTISED_10baseT_Half |
  1953. ADVERTISED_10baseT_Full |
  1954. ADVERTISED_100baseT_Half |
  1955. ADVERTISED_100baseT_Full |
  1956. ADVERTISED_Autoneg;
  1957. bnx2_setup_copper_phy(bp);
  1958. bp->autoneg = autoneg;
  1959. bp->advertising = advertising;
  1960. bnx2_set_mac_addr(bp);
  1961. val = REG_RD(bp, BNX2_EMAC_MODE);
  1962. /* Enable port mode. */
  1963. val &= ~BNX2_EMAC_MODE_PORT;
  1964. val |= BNX2_EMAC_MODE_PORT_MII |
  1965. BNX2_EMAC_MODE_MPKT_RCVD |
  1966. BNX2_EMAC_MODE_ACPI_RCVD |
  1967. BNX2_EMAC_MODE_MPKT;
  1968. REG_WR(bp, BNX2_EMAC_MODE, val);
  1969. /* receive all multicast */
  1970. for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
  1971. REG_WR(bp, BNX2_EMAC_MULTICAST_HASH0 + (i * 4),
  1972. 0xffffffff);
  1973. }
  1974. REG_WR(bp, BNX2_EMAC_RX_MODE,
  1975. BNX2_EMAC_RX_MODE_SORT_MODE);
  1976. val = 1 | BNX2_RPM_SORT_USER0_BC_EN |
  1977. BNX2_RPM_SORT_USER0_MC_EN;
  1978. REG_WR(bp, BNX2_RPM_SORT_USER0, 0x0);
  1979. REG_WR(bp, BNX2_RPM_SORT_USER0, val);
  1980. REG_WR(bp, BNX2_RPM_SORT_USER0, val |
  1981. BNX2_RPM_SORT_USER0_ENA);
  1982. /* Need to enable EMAC and RPM for WOL. */
  1983. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS,
  1984. BNX2_MISC_ENABLE_SET_BITS_RX_PARSER_MAC_ENABLE |
  1985. BNX2_MISC_ENABLE_SET_BITS_TX_HEADER_Q_ENABLE |
  1986. BNX2_MISC_ENABLE_SET_BITS_EMAC_ENABLE);
  1987. val = REG_RD(bp, BNX2_RPM_CONFIG);
  1988. val &= ~BNX2_RPM_CONFIG_ACPI_ENA;
  1989. REG_WR(bp, BNX2_RPM_CONFIG, val);
  1990. wol_msg = BNX2_DRV_MSG_CODE_SUSPEND_WOL;
  1991. }
  1992. else {
  1993. wol_msg = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
  1994. }
  1995. if (!(bp->flags & NO_WOL_FLAG))
  1996. bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT3 | wol_msg, 0);
  1997. pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
  1998. if ((CHIP_ID(bp) == CHIP_ID_5706_A0) ||
  1999. (CHIP_ID(bp) == CHIP_ID_5706_A1)) {
  2000. if (bp->wol)
  2001. pmcsr |= 3;
  2002. }
  2003. else {
  2004. pmcsr |= 3;
  2005. }
  2006. if (bp->wol) {
  2007. pmcsr |= PCI_PM_CTRL_PME_ENABLE;
  2008. }
  2009. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
  2010. pmcsr);
  2011. /* No more memory access after this point until
  2012. * device is brought back to D0.
  2013. */
  2014. udelay(50);
  2015. break;
  2016. }
  2017. default:
  2018. return -EINVAL;
  2019. }
  2020. return 0;
  2021. }
  2022. static int
  2023. bnx2_acquire_nvram_lock(struct bnx2 *bp)
  2024. {
  2025. u32 val;
  2026. int j;
  2027. /* Request access to the flash interface. */
  2028. REG_WR(bp, BNX2_NVM_SW_ARB, BNX2_NVM_SW_ARB_ARB_REQ_SET2);
  2029. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  2030. val = REG_RD(bp, BNX2_NVM_SW_ARB);
  2031. if (val & BNX2_NVM_SW_ARB_ARB_ARB2)
  2032. break;
  2033. udelay(5);
  2034. }
  2035. if (j >= NVRAM_TIMEOUT_COUNT)
  2036. return -EBUSY;
  2037. return 0;
  2038. }
  2039. static int
  2040. bnx2_release_nvram_lock(struct bnx2 *bp)
  2041. {
  2042. int j;
  2043. u32 val;
  2044. /* Relinquish nvram interface. */
  2045. REG_WR(bp, BNX2_NVM_SW_ARB, BNX2_NVM_SW_ARB_ARB_REQ_CLR2);
  2046. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  2047. val = REG_RD(bp, BNX2_NVM_SW_ARB);
  2048. if (!(val & BNX2_NVM_SW_ARB_ARB_ARB2))
  2049. break;
  2050. udelay(5);
  2051. }
  2052. if (j >= NVRAM_TIMEOUT_COUNT)
  2053. return -EBUSY;
  2054. return 0;
  2055. }
  2056. static int
  2057. bnx2_enable_nvram_write(struct bnx2 *bp)
  2058. {
  2059. u32 val;
  2060. val = REG_RD(bp, BNX2_MISC_CFG);
  2061. REG_WR(bp, BNX2_MISC_CFG, val | BNX2_MISC_CFG_NVM_WR_EN_PCI);
  2062. if (!bp->flash_info->buffered) {
  2063. int j;
  2064. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  2065. REG_WR(bp, BNX2_NVM_COMMAND,
  2066. BNX2_NVM_COMMAND_WREN | BNX2_NVM_COMMAND_DOIT);
  2067. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  2068. udelay(5);
  2069. val = REG_RD(bp, BNX2_NVM_COMMAND);
  2070. if (val & BNX2_NVM_COMMAND_DONE)
  2071. break;
  2072. }
  2073. if (j >= NVRAM_TIMEOUT_COUNT)
  2074. return -EBUSY;
  2075. }
  2076. return 0;
  2077. }
  2078. static void
  2079. bnx2_disable_nvram_write(struct bnx2 *bp)
  2080. {
  2081. u32 val;
  2082. val = REG_RD(bp, BNX2_MISC_CFG);
  2083. REG_WR(bp, BNX2_MISC_CFG, val & ~BNX2_MISC_CFG_NVM_WR_EN);
  2084. }
  2085. static void
  2086. bnx2_enable_nvram_access(struct bnx2 *bp)
  2087. {
  2088. u32 val;
  2089. val = REG_RD(bp, BNX2_NVM_ACCESS_ENABLE);
  2090. /* Enable both bits, even on read. */
  2091. REG_WR(bp, BNX2_NVM_ACCESS_ENABLE,
  2092. val | BNX2_NVM_ACCESS_ENABLE_EN | BNX2_NVM_ACCESS_ENABLE_WR_EN);
  2093. }
  2094. static void
  2095. bnx2_disable_nvram_access(struct bnx2 *bp)
  2096. {
  2097. u32 val;
  2098. val = REG_RD(bp, BNX2_NVM_ACCESS_ENABLE);
  2099. /* Disable both bits, even after read. */
  2100. REG_WR(bp, BNX2_NVM_ACCESS_ENABLE,
  2101. val & ~(BNX2_NVM_ACCESS_ENABLE_EN |
  2102. BNX2_NVM_ACCESS_ENABLE_WR_EN));
  2103. }
  2104. static int
  2105. bnx2_nvram_erase_page(struct bnx2 *bp, u32 offset)
  2106. {
  2107. u32 cmd;
  2108. int j;
  2109. if (bp->flash_info->buffered)
  2110. /* Buffered flash, no erase needed */
  2111. return 0;
  2112. /* Build an erase command */
  2113. cmd = BNX2_NVM_COMMAND_ERASE | BNX2_NVM_COMMAND_WR |
  2114. BNX2_NVM_COMMAND_DOIT;
  2115. /* Need to clear DONE bit separately. */
  2116. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  2117. /* Address of the NVRAM to read from. */
  2118. REG_WR(bp, BNX2_NVM_ADDR, offset & BNX2_NVM_ADDR_NVM_ADDR_VALUE);
  2119. /* Issue an erase command. */
  2120. REG_WR(bp, BNX2_NVM_COMMAND, cmd);
  2121. /* Wait for completion. */
  2122. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  2123. u32 val;
  2124. udelay(5);
  2125. val = REG_RD(bp, BNX2_NVM_COMMAND);
  2126. if (val & BNX2_NVM_COMMAND_DONE)
  2127. break;
  2128. }
  2129. if (j >= NVRAM_TIMEOUT_COUNT)
  2130. return -EBUSY;
  2131. return 0;
  2132. }
  2133. static int
  2134. bnx2_nvram_read_dword(struct bnx2 *bp, u32 offset, u8 *ret_val, u32 cmd_flags)
  2135. {
  2136. u32 cmd;
  2137. int j;
  2138. /* Build the command word. */
  2139. cmd = BNX2_NVM_COMMAND_DOIT | cmd_flags;
  2140. /* Calculate an offset of a buffered flash. */
  2141. if (bp->flash_info->buffered) {
  2142. offset = ((offset / bp->flash_info->page_size) <<
  2143. bp->flash_info->page_bits) +
  2144. (offset % bp->flash_info->page_size);
  2145. }
  2146. /* Need to clear DONE bit separately. */
  2147. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  2148. /* Address of the NVRAM to read from. */
  2149. REG_WR(bp, BNX2_NVM_ADDR, offset & BNX2_NVM_ADDR_NVM_ADDR_VALUE);
  2150. /* Issue a read command. */
  2151. REG_WR(bp, BNX2_NVM_COMMAND, cmd);
  2152. /* Wait for completion. */
  2153. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  2154. u32 val;
  2155. udelay(5);
  2156. val = REG_RD(bp, BNX2_NVM_COMMAND);
  2157. if (val & BNX2_NVM_COMMAND_DONE) {
  2158. val = REG_RD(bp, BNX2_NVM_READ);
  2159. val = be32_to_cpu(val);
  2160. memcpy(ret_val, &val, 4);
  2161. break;
  2162. }
  2163. }
  2164. if (j >= NVRAM_TIMEOUT_COUNT)
  2165. return -EBUSY;
  2166. return 0;
  2167. }
  2168. static int
  2169. bnx2_nvram_write_dword(struct bnx2 *bp, u32 offset, u8 *val, u32 cmd_flags)
  2170. {
  2171. u32 cmd, val32;
  2172. int j;
  2173. /* Build the command word. */
  2174. cmd = BNX2_NVM_COMMAND_DOIT | BNX2_NVM_COMMAND_WR | cmd_flags;
  2175. /* Calculate an offset of a buffered flash. */
  2176. if (bp->flash_info->buffered) {
  2177. offset = ((offset / bp->flash_info->page_size) <<
  2178. bp->flash_info->page_bits) +
  2179. (offset % bp->flash_info->page_size);
  2180. }
  2181. /* Need to clear DONE bit separately. */
  2182. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  2183. memcpy(&val32, val, 4);
  2184. val32 = cpu_to_be32(val32);
  2185. /* Write the data. */
  2186. REG_WR(bp, BNX2_NVM_WRITE, val32);
  2187. /* Address of the NVRAM to write to. */
  2188. REG_WR(bp, BNX2_NVM_ADDR, offset & BNX2_NVM_ADDR_NVM_ADDR_VALUE);
  2189. /* Issue the write command. */
  2190. REG_WR(bp, BNX2_NVM_COMMAND, cmd);
  2191. /* Wait for completion. */
  2192. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  2193. udelay(5);
  2194. if (REG_RD(bp, BNX2_NVM_COMMAND) & BNX2_NVM_COMMAND_DONE)
  2195. break;
  2196. }
  2197. if (j >= NVRAM_TIMEOUT_COUNT)
  2198. return -EBUSY;
  2199. return 0;
  2200. }
  2201. static int
  2202. bnx2_init_nvram(struct bnx2 *bp)
  2203. {
  2204. u32 val;
  2205. int j, entry_count, rc;
  2206. struct flash_spec *flash;
  2207. /* Determine the selected interface. */
  2208. val = REG_RD(bp, BNX2_NVM_CFG1);
  2209. entry_count = sizeof(flash_table) / sizeof(struct flash_spec);
  2210. rc = 0;
  2211. if (val & 0x40000000) {
  2212. /* Flash interface has been reconfigured */
  2213. for (j = 0, flash = &flash_table[0]; j < entry_count;
  2214. j++, flash++) {
  2215. if ((val & FLASH_BACKUP_STRAP_MASK) ==
  2216. (flash->config1 & FLASH_BACKUP_STRAP_MASK)) {
  2217. bp->flash_info = flash;
  2218. break;
  2219. }
  2220. }
  2221. }
  2222. else {
  2223. u32 mask;
  2224. /* Not yet been reconfigured */
  2225. if (val & (1 << 23))
  2226. mask = FLASH_BACKUP_STRAP_MASK;
  2227. else
  2228. mask = FLASH_STRAP_MASK;
  2229. for (j = 0, flash = &flash_table[0]; j < entry_count;
  2230. j++, flash++) {
  2231. if ((val & mask) == (flash->strapping & mask)) {
  2232. bp->flash_info = flash;
  2233. /* Request access to the flash interface. */
  2234. if ((rc = bnx2_acquire_nvram_lock(bp)) != 0)
  2235. return rc;
  2236. /* Enable access to flash interface */
  2237. bnx2_enable_nvram_access(bp);
  2238. /* Reconfigure the flash interface */
  2239. REG_WR(bp, BNX2_NVM_CFG1, flash->config1);
  2240. REG_WR(bp, BNX2_NVM_CFG2, flash->config2);
  2241. REG_WR(bp, BNX2_NVM_CFG3, flash->config3);
  2242. REG_WR(bp, BNX2_NVM_WRITE1, flash->write1);
  2243. /* Disable access to flash interface */
  2244. bnx2_disable_nvram_access(bp);
  2245. bnx2_release_nvram_lock(bp);
  2246. break;
  2247. }
  2248. }
  2249. } /* if (val & 0x40000000) */
  2250. if (j == entry_count) {
  2251. bp->flash_info = NULL;
  2252. printk(KERN_ALERT PFX "Unknown flash/EEPROM type.\n");
  2253. return -ENODEV;
  2254. }
  2255. val = REG_RD_IND(bp, bp->shmem_base + BNX2_SHARED_HW_CFG_CONFIG2);
  2256. val &= BNX2_SHARED_HW_CFG2_NVM_SIZE_MASK;
  2257. if (val)
  2258. bp->flash_size = val;
  2259. else
  2260. bp->flash_size = bp->flash_info->total_size;
  2261. return rc;
  2262. }
  2263. static int
  2264. bnx2_nvram_read(struct bnx2 *bp, u32 offset, u8 *ret_buf,
  2265. int buf_size)
  2266. {
  2267. int rc = 0;
  2268. u32 cmd_flags, offset32, len32, extra;
  2269. if (buf_size == 0)
  2270. return 0;
  2271. /* Request access to the flash interface. */
  2272. if ((rc = bnx2_acquire_nvram_lock(bp)) != 0)
  2273. return rc;
  2274. /* Enable access to flash interface */
  2275. bnx2_enable_nvram_access(bp);
  2276. len32 = buf_size;
  2277. offset32 = offset;
  2278. extra = 0;
  2279. cmd_flags = 0;
  2280. if (offset32 & 3) {
  2281. u8 buf[4];
  2282. u32 pre_len;
  2283. offset32 &= ~3;
  2284. pre_len = 4 - (offset & 3);
  2285. if (pre_len >= len32) {
  2286. pre_len = len32;
  2287. cmd_flags = BNX2_NVM_COMMAND_FIRST |
  2288. BNX2_NVM_COMMAND_LAST;
  2289. }
  2290. else {
  2291. cmd_flags = BNX2_NVM_COMMAND_FIRST;
  2292. }
  2293. rc = bnx2_nvram_read_dword(bp, offset32, buf, cmd_flags);
  2294. if (rc)
  2295. return rc;
  2296. memcpy(ret_buf, buf + (offset & 3), pre_len);
  2297. offset32 += 4;
  2298. ret_buf += pre_len;
  2299. len32 -= pre_len;
  2300. }
  2301. if (len32 & 3) {
  2302. extra = 4 - (len32 & 3);
  2303. len32 = (len32 + 4) & ~3;
  2304. }
  2305. if (len32 == 4) {
  2306. u8 buf[4];
  2307. if (cmd_flags)
  2308. cmd_flags = BNX2_NVM_COMMAND_LAST;
  2309. else
  2310. cmd_flags = BNX2_NVM_COMMAND_FIRST |
  2311. BNX2_NVM_COMMAND_LAST;
  2312. rc = bnx2_nvram_read_dword(bp, offset32, buf, cmd_flags);
  2313. memcpy(ret_buf, buf, 4 - extra);
  2314. }
  2315. else if (len32 > 0) {
  2316. u8 buf[4];
  2317. /* Read the first word. */
  2318. if (cmd_flags)
  2319. cmd_flags = 0;
  2320. else
  2321. cmd_flags = BNX2_NVM_COMMAND_FIRST;
  2322. rc = bnx2_nvram_read_dword(bp, offset32, ret_buf, cmd_flags);
  2323. /* Advance to the next dword. */
  2324. offset32 += 4;
  2325. ret_buf += 4;
  2326. len32 -= 4;
  2327. while (len32 > 4 && rc == 0) {
  2328. rc = bnx2_nvram_read_dword(bp, offset32, ret_buf, 0);
  2329. /* Advance to the next dword. */
  2330. offset32 += 4;
  2331. ret_buf += 4;
  2332. len32 -= 4;
  2333. }
  2334. if (rc)
  2335. return rc;
  2336. cmd_flags = BNX2_NVM_COMMAND_LAST;
  2337. rc = bnx2_nvram_read_dword(bp, offset32, buf, cmd_flags);
  2338. memcpy(ret_buf, buf, 4 - extra);
  2339. }
  2340. /* Disable access to flash interface */
  2341. bnx2_disable_nvram_access(bp);
  2342. bnx2_release_nvram_lock(bp);
  2343. return rc;
  2344. }
  2345. static int
  2346. bnx2_nvram_write(struct bnx2 *bp, u32 offset, u8 *data_buf,
  2347. int buf_size)
  2348. {
  2349. u32 written, offset32, len32;
  2350. u8 *buf, start[4], end[4];
  2351. int rc = 0;
  2352. int align_start, align_end;
  2353. buf = data_buf;
  2354. offset32 = offset;
  2355. len32 = buf_size;
  2356. align_start = align_end = 0;
  2357. if ((align_start = (offset32 & 3))) {
  2358. offset32 &= ~3;
  2359. len32 += align_start;
  2360. if ((rc = bnx2_nvram_read(bp, offset32, start, 4)))
  2361. return rc;
  2362. }
  2363. if (len32 & 3) {
  2364. if ((len32 > 4) || !align_start) {
  2365. align_end = 4 - (len32 & 3);
  2366. len32 += align_end;
  2367. if ((rc = bnx2_nvram_read(bp, offset32 + len32 - 4,
  2368. end, 4))) {
  2369. return rc;
  2370. }
  2371. }
  2372. }
  2373. if (align_start || align_end) {
  2374. buf = kmalloc(len32, GFP_KERNEL);
  2375. if (buf == 0)
  2376. return -ENOMEM;
  2377. if (align_start) {
  2378. memcpy(buf, start, 4);
  2379. }
  2380. if (align_end) {
  2381. memcpy(buf + len32 - 4, end, 4);
  2382. }
  2383. memcpy(buf + align_start, data_buf, buf_size);
  2384. }
  2385. written = 0;
  2386. while ((written < len32) && (rc == 0)) {
  2387. u32 page_start, page_end, data_start, data_end;
  2388. u32 addr, cmd_flags;
  2389. int i;
  2390. u8 flash_buffer[264];
  2391. /* Find the page_start addr */
  2392. page_start = offset32 + written;
  2393. page_start -= (page_start % bp->flash_info->page_size);
  2394. /* Find the page_end addr */
  2395. page_end = page_start + bp->flash_info->page_size;
  2396. /* Find the data_start addr */
  2397. data_start = (written == 0) ? offset32 : page_start;
  2398. /* Find the data_end addr */
  2399. data_end = (page_end > offset32 + len32) ?
  2400. (offset32 + len32) : page_end;
  2401. /* Request access to the flash interface. */
  2402. if ((rc = bnx2_acquire_nvram_lock(bp)) != 0)
  2403. goto nvram_write_end;
  2404. /* Enable access to flash interface */
  2405. bnx2_enable_nvram_access(bp);
  2406. cmd_flags = BNX2_NVM_COMMAND_FIRST;
  2407. if (bp->flash_info->buffered == 0) {
  2408. int j;
  2409. /* Read the whole page into the buffer
  2410. * (non-buffer flash only) */
  2411. for (j = 0; j < bp->flash_info->page_size; j += 4) {
  2412. if (j == (bp->flash_info->page_size - 4)) {
  2413. cmd_flags |= BNX2_NVM_COMMAND_LAST;
  2414. }
  2415. rc = bnx2_nvram_read_dword(bp,
  2416. page_start + j,
  2417. &flash_buffer[j],
  2418. cmd_flags);
  2419. if (rc)
  2420. goto nvram_write_end;
  2421. cmd_flags = 0;
  2422. }
  2423. }
  2424. /* Enable writes to flash interface (unlock write-protect) */
  2425. if ((rc = bnx2_enable_nvram_write(bp)) != 0)
  2426. goto nvram_write_end;
  2427. /* Erase the page */
  2428. if ((rc = bnx2_nvram_erase_page(bp, page_start)) != 0)
  2429. goto nvram_write_end;
  2430. /* Re-enable the write again for the actual write */
  2431. bnx2_enable_nvram_write(bp);
  2432. /* Loop to write back the buffer data from page_start to
  2433. * data_start */
  2434. i = 0;
  2435. if (bp->flash_info->buffered == 0) {
  2436. for (addr = page_start; addr < data_start;
  2437. addr += 4, i += 4) {
  2438. rc = bnx2_nvram_write_dword(bp, addr,
  2439. &flash_buffer[i], cmd_flags);
  2440. if (rc != 0)
  2441. goto nvram_write_end;
  2442. cmd_flags = 0;
  2443. }
  2444. }
  2445. /* Loop to write the new data from data_start to data_end */
  2446. for (addr = data_start; addr < data_end; addr += 4, i++) {
  2447. if ((addr == page_end - 4) ||
  2448. ((bp->flash_info->buffered) &&
  2449. (addr == data_end - 4))) {
  2450. cmd_flags |= BNX2_NVM_COMMAND_LAST;
  2451. }
  2452. rc = bnx2_nvram_write_dword(bp, addr, buf,
  2453. cmd_flags);
  2454. if (rc != 0)
  2455. goto nvram_write_end;
  2456. cmd_flags = 0;
  2457. buf += 4;
  2458. }
  2459. /* Loop to write back the buffer data from data_end
  2460. * to page_end */
  2461. if (bp->flash_info->buffered == 0) {
  2462. for (addr = data_end; addr < page_end;
  2463. addr += 4, i += 4) {
  2464. if (addr == page_end-4) {
  2465. cmd_flags = BNX2_NVM_COMMAND_LAST;
  2466. }
  2467. rc = bnx2_nvram_write_dword(bp, addr,
  2468. &flash_buffer[i], cmd_flags);
  2469. if (rc != 0)
  2470. goto nvram_write_end;
  2471. cmd_flags = 0;
  2472. }
  2473. }
  2474. /* Disable writes to flash interface (lock write-protect) */
  2475. bnx2_disable_nvram_write(bp);
  2476. /* Disable access to flash interface */
  2477. bnx2_disable_nvram_access(bp);
  2478. bnx2_release_nvram_lock(bp);
  2479. /* Increment written */
  2480. written += data_end - data_start;
  2481. }
  2482. nvram_write_end:
  2483. if (align_start || align_end)
  2484. kfree(buf);
  2485. return rc;
  2486. }
  2487. static int
  2488. bnx2_reset_chip(struct bnx2 *bp, u32 reset_code)
  2489. {
  2490. u32 val;
  2491. int i, rc = 0;
  2492. /* Wait for the current PCI transaction to complete before
  2493. * issuing a reset. */
  2494. REG_WR(bp, BNX2_MISC_ENABLE_CLR_BITS,
  2495. BNX2_MISC_ENABLE_CLR_BITS_TX_DMA_ENABLE |
  2496. BNX2_MISC_ENABLE_CLR_BITS_DMA_ENGINE_ENABLE |
  2497. BNX2_MISC_ENABLE_CLR_BITS_RX_DMA_ENABLE |
  2498. BNX2_MISC_ENABLE_CLR_BITS_HOST_COALESCE_ENABLE);
  2499. val = REG_RD(bp, BNX2_MISC_ENABLE_CLR_BITS);
  2500. udelay(5);
  2501. /* Wait for the firmware to tell us it is ok to issue a reset. */
  2502. bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT0 | reset_code, 1);
  2503. /* Deposit a driver reset signature so the firmware knows that
  2504. * this is a soft reset. */
  2505. REG_WR_IND(bp, bp->shmem_base + BNX2_DRV_RESET_SIGNATURE,
  2506. BNX2_DRV_RESET_SIGNATURE_MAGIC);
  2507. /* Do a dummy read to force the chip to complete all current transaction
  2508. * before we issue a reset. */
  2509. val = REG_RD(bp, BNX2_MISC_ID);
  2510. val = BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
  2511. BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
  2512. BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
  2513. /* Chip reset. */
  2514. REG_WR(bp, BNX2_PCICFG_MISC_CONFIG, val);
  2515. if ((CHIP_ID(bp) == CHIP_ID_5706_A0) ||
  2516. (CHIP_ID(bp) == CHIP_ID_5706_A1))
  2517. msleep(15);
  2518. /* Reset takes approximate 30 usec */
  2519. for (i = 0; i < 10; i++) {
  2520. val = REG_RD(bp, BNX2_PCICFG_MISC_CONFIG);
  2521. if ((val & (BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
  2522. BNX2_PCICFG_MISC_CONFIG_CORE_RST_BSY)) == 0) {
  2523. break;
  2524. }
  2525. udelay(10);
  2526. }
  2527. if (val & (BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
  2528. BNX2_PCICFG_MISC_CONFIG_CORE_RST_BSY)) {
  2529. printk(KERN_ERR PFX "Chip reset did not complete\n");
  2530. return -EBUSY;
  2531. }
  2532. /* Make sure byte swapping is properly configured. */
  2533. val = REG_RD(bp, BNX2_PCI_SWAP_DIAG0);
  2534. if (val != 0x01020304) {
  2535. printk(KERN_ERR PFX "Chip not in correct endian mode\n");
  2536. return -ENODEV;
  2537. }
  2538. /* Wait for the firmware to finish its initialization. */
  2539. rc = bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT1 | reset_code, 0);
  2540. if (rc)
  2541. return rc;
  2542. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  2543. /* Adjust the voltage regular to two steps lower. The default
  2544. * of this register is 0x0000000e. */
  2545. REG_WR(bp, BNX2_MISC_VREG_CONTROL, 0x000000fa);
  2546. /* Remove bad rbuf memory from the free pool. */
  2547. rc = bnx2_alloc_bad_rbuf(bp);
  2548. }
  2549. return rc;
  2550. }
  2551. static int
  2552. bnx2_init_chip(struct bnx2 *bp)
  2553. {
  2554. u32 val;
  2555. int rc;
  2556. /* Make sure the interrupt is not active. */
  2557. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD, BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  2558. val = BNX2_DMA_CONFIG_DATA_BYTE_SWAP |
  2559. BNX2_DMA_CONFIG_DATA_WORD_SWAP |
  2560. #ifdef __BIG_ENDIAN
  2561. BNX2_DMA_CONFIG_CNTL_BYTE_SWAP |
  2562. #endif
  2563. BNX2_DMA_CONFIG_CNTL_WORD_SWAP |
  2564. DMA_READ_CHANS << 12 |
  2565. DMA_WRITE_CHANS << 16;
  2566. val |= (0x2 << 20) | (1 << 11);
  2567. if ((bp->flags & PCIX_FLAG) && (bp->bus_speed_mhz == 133))
  2568. val |= (1 << 23);
  2569. if ((CHIP_NUM(bp) == CHIP_NUM_5706) &&
  2570. (CHIP_ID(bp) != CHIP_ID_5706_A0) && !(bp->flags & PCIX_FLAG))
  2571. val |= BNX2_DMA_CONFIG_CNTL_PING_PONG_DMA;
  2572. REG_WR(bp, BNX2_DMA_CONFIG, val);
  2573. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  2574. val = REG_RD(bp, BNX2_TDMA_CONFIG);
  2575. val |= BNX2_TDMA_CONFIG_ONE_DMA;
  2576. REG_WR(bp, BNX2_TDMA_CONFIG, val);
  2577. }
  2578. if (bp->flags & PCIX_FLAG) {
  2579. u16 val16;
  2580. pci_read_config_word(bp->pdev, bp->pcix_cap + PCI_X_CMD,
  2581. &val16);
  2582. pci_write_config_word(bp->pdev, bp->pcix_cap + PCI_X_CMD,
  2583. val16 & ~PCI_X_CMD_ERO);
  2584. }
  2585. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS,
  2586. BNX2_MISC_ENABLE_SET_BITS_HOST_COALESCE_ENABLE |
  2587. BNX2_MISC_ENABLE_STATUS_BITS_RX_V2P_ENABLE |
  2588. BNX2_MISC_ENABLE_STATUS_BITS_CONTEXT_ENABLE);
  2589. /* Initialize context mapping and zero out the quick contexts. The
  2590. * context block must have already been enabled. */
  2591. bnx2_init_context(bp);
  2592. bnx2_init_cpus(bp);
  2593. bnx2_init_nvram(bp);
  2594. bnx2_set_mac_addr(bp);
  2595. val = REG_RD(bp, BNX2_MQ_CONFIG);
  2596. val &= ~BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE;
  2597. val |= BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE_256;
  2598. REG_WR(bp, BNX2_MQ_CONFIG, val);
  2599. val = 0x10000 + (MAX_CID_CNT * MB_KERNEL_CTX_SIZE);
  2600. REG_WR(bp, BNX2_MQ_KNL_BYP_WIND_START, val);
  2601. REG_WR(bp, BNX2_MQ_KNL_WIND_END, val);
  2602. val = (BCM_PAGE_BITS - 8) << 24;
  2603. REG_WR(bp, BNX2_RV2P_CONFIG, val);
  2604. /* Configure page size. */
  2605. val = REG_RD(bp, BNX2_TBDR_CONFIG);
  2606. val &= ~BNX2_TBDR_CONFIG_PAGE_SIZE;
  2607. val |= (BCM_PAGE_BITS - 8) << 24 | 0x40;
  2608. REG_WR(bp, BNX2_TBDR_CONFIG, val);
  2609. val = bp->mac_addr[0] +
  2610. (bp->mac_addr[1] << 8) +
  2611. (bp->mac_addr[2] << 16) +
  2612. bp->mac_addr[3] +
  2613. (bp->mac_addr[4] << 8) +
  2614. (bp->mac_addr[5] << 16);
  2615. REG_WR(bp, BNX2_EMAC_BACKOFF_SEED, val);
  2616. /* Program the MTU. Also include 4 bytes for CRC32. */
  2617. val = bp->dev->mtu + ETH_HLEN + 4;
  2618. if (val > (MAX_ETHERNET_PACKET_SIZE + 4))
  2619. val |= BNX2_EMAC_RX_MTU_SIZE_JUMBO_ENA;
  2620. REG_WR(bp, BNX2_EMAC_RX_MTU_SIZE, val);
  2621. bp->last_status_idx = 0;
  2622. bp->rx_mode = BNX2_EMAC_RX_MODE_SORT_MODE;
  2623. /* Set up how to generate a link change interrupt. */
  2624. REG_WR(bp, BNX2_EMAC_ATTENTION_ENA, BNX2_EMAC_ATTENTION_ENA_LINK);
  2625. REG_WR(bp, BNX2_HC_STATUS_ADDR_L,
  2626. (u64) bp->status_blk_mapping & 0xffffffff);
  2627. REG_WR(bp, BNX2_HC_STATUS_ADDR_H, (u64) bp->status_blk_mapping >> 32);
  2628. REG_WR(bp, BNX2_HC_STATISTICS_ADDR_L,
  2629. (u64) bp->stats_blk_mapping & 0xffffffff);
  2630. REG_WR(bp, BNX2_HC_STATISTICS_ADDR_H,
  2631. (u64) bp->stats_blk_mapping >> 32);
  2632. REG_WR(bp, BNX2_HC_TX_QUICK_CONS_TRIP,
  2633. (bp->tx_quick_cons_trip_int << 16) | bp->tx_quick_cons_trip);
  2634. REG_WR(bp, BNX2_HC_RX_QUICK_CONS_TRIP,
  2635. (bp->rx_quick_cons_trip_int << 16) | bp->rx_quick_cons_trip);
  2636. REG_WR(bp, BNX2_HC_COMP_PROD_TRIP,
  2637. (bp->comp_prod_trip_int << 16) | bp->comp_prod_trip);
  2638. REG_WR(bp, BNX2_HC_TX_TICKS, (bp->tx_ticks_int << 16) | bp->tx_ticks);
  2639. REG_WR(bp, BNX2_HC_RX_TICKS, (bp->rx_ticks_int << 16) | bp->rx_ticks);
  2640. REG_WR(bp, BNX2_HC_COM_TICKS,
  2641. (bp->com_ticks_int << 16) | bp->com_ticks);
  2642. REG_WR(bp, BNX2_HC_CMD_TICKS,
  2643. (bp->cmd_ticks_int << 16) | bp->cmd_ticks);
  2644. REG_WR(bp, BNX2_HC_STATS_TICKS, bp->stats_ticks & 0xffff00);
  2645. REG_WR(bp, BNX2_HC_STAT_COLLECT_TICKS, 0xbb8); /* 3ms */
  2646. if (CHIP_ID(bp) == CHIP_ID_5706_A1)
  2647. REG_WR(bp, BNX2_HC_CONFIG, BNX2_HC_CONFIG_COLLECT_STATS);
  2648. else {
  2649. REG_WR(bp, BNX2_HC_CONFIG, BNX2_HC_CONFIG_RX_TMR_MODE |
  2650. BNX2_HC_CONFIG_TX_TMR_MODE |
  2651. BNX2_HC_CONFIG_COLLECT_STATS);
  2652. }
  2653. /* Clear internal stats counters. */
  2654. REG_WR(bp, BNX2_HC_COMMAND, BNX2_HC_COMMAND_CLR_STAT_NOW);
  2655. REG_WR(bp, BNX2_HC_ATTN_BITS_ENABLE, STATUS_ATTN_BITS_LINK_STATE);
  2656. if (REG_RD_IND(bp, bp->shmem_base + BNX2_PORT_FEATURE) &
  2657. BNX2_PORT_FEATURE_ASF_ENABLED)
  2658. bp->flags |= ASF_ENABLE_FLAG;
  2659. /* Initialize the receive filter. */
  2660. bnx2_set_rx_mode(bp->dev);
  2661. rc = bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT2 | BNX2_DRV_MSG_CODE_RESET,
  2662. 0);
  2663. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS, 0x5ffffff);
  2664. REG_RD(bp, BNX2_MISC_ENABLE_SET_BITS);
  2665. udelay(20);
  2666. return rc;
  2667. }
  2668. static void
  2669. bnx2_init_tx_ring(struct bnx2 *bp)
  2670. {
  2671. struct tx_bd *txbd;
  2672. u32 val;
  2673. txbd = &bp->tx_desc_ring[MAX_TX_DESC_CNT];
  2674. txbd->tx_bd_haddr_hi = (u64) bp->tx_desc_mapping >> 32;
  2675. txbd->tx_bd_haddr_lo = (u64) bp->tx_desc_mapping & 0xffffffff;
  2676. bp->tx_prod = 0;
  2677. bp->tx_cons = 0;
  2678. bp->hw_tx_cons = 0;
  2679. bp->tx_prod_bseq = 0;
  2680. val = BNX2_L2CTX_TYPE_TYPE_L2;
  2681. val |= BNX2_L2CTX_TYPE_SIZE_L2;
  2682. CTX_WR(bp, GET_CID_ADDR(TX_CID), BNX2_L2CTX_TYPE, val);
  2683. val = BNX2_L2CTX_CMD_TYPE_TYPE_L2;
  2684. val |= 8 << 16;
  2685. CTX_WR(bp, GET_CID_ADDR(TX_CID), BNX2_L2CTX_CMD_TYPE, val);
  2686. val = (u64) bp->tx_desc_mapping >> 32;
  2687. CTX_WR(bp, GET_CID_ADDR(TX_CID), BNX2_L2CTX_TBDR_BHADDR_HI, val);
  2688. val = (u64) bp->tx_desc_mapping & 0xffffffff;
  2689. CTX_WR(bp, GET_CID_ADDR(TX_CID), BNX2_L2CTX_TBDR_BHADDR_LO, val);
  2690. }
  2691. static void
  2692. bnx2_init_rx_ring(struct bnx2 *bp)
  2693. {
  2694. struct rx_bd *rxbd;
  2695. int i;
  2696. u16 prod, ring_prod;
  2697. u32 val;
  2698. /* 8 for CRC and VLAN */
  2699. bp->rx_buf_use_size = bp->dev->mtu + ETH_HLEN + bp->rx_offset + 8;
  2700. /* 8 for alignment */
  2701. bp->rx_buf_size = bp->rx_buf_use_size + 8;
  2702. ring_prod = prod = bp->rx_prod = 0;
  2703. bp->rx_cons = 0;
  2704. bp->hw_rx_cons = 0;
  2705. bp->rx_prod_bseq = 0;
  2706. rxbd = &bp->rx_desc_ring[0];
  2707. for (i = 0; i < MAX_RX_DESC_CNT; i++, rxbd++) {
  2708. rxbd->rx_bd_len = bp->rx_buf_use_size;
  2709. rxbd->rx_bd_flags = RX_BD_FLAGS_START | RX_BD_FLAGS_END;
  2710. }
  2711. rxbd->rx_bd_haddr_hi = (u64) bp->rx_desc_mapping >> 32;
  2712. rxbd->rx_bd_haddr_lo = (u64) bp->rx_desc_mapping & 0xffffffff;
  2713. val = BNX2_L2CTX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE;
  2714. val |= BNX2_L2CTX_CTX_TYPE_SIZE_L2;
  2715. val |= 0x02 << 8;
  2716. CTX_WR(bp, GET_CID_ADDR(RX_CID), BNX2_L2CTX_CTX_TYPE, val);
  2717. val = (u64) bp->rx_desc_mapping >> 32;
  2718. CTX_WR(bp, GET_CID_ADDR(RX_CID), BNX2_L2CTX_NX_BDHADDR_HI, val);
  2719. val = (u64) bp->rx_desc_mapping & 0xffffffff;
  2720. CTX_WR(bp, GET_CID_ADDR(RX_CID), BNX2_L2CTX_NX_BDHADDR_LO, val);
  2721. for ( ;ring_prod < bp->rx_ring_size; ) {
  2722. if (bnx2_alloc_rx_skb(bp, ring_prod) < 0) {
  2723. break;
  2724. }
  2725. prod = NEXT_RX_BD(prod);
  2726. ring_prod = RX_RING_IDX(prod);
  2727. }
  2728. bp->rx_prod = prod;
  2729. REG_WR16(bp, MB_RX_CID_ADDR + BNX2_L2CTX_HOST_BDIDX, prod);
  2730. REG_WR(bp, MB_RX_CID_ADDR + BNX2_L2CTX_HOST_BSEQ, bp->rx_prod_bseq);
  2731. }
  2732. static void
  2733. bnx2_free_tx_skbs(struct bnx2 *bp)
  2734. {
  2735. int i;
  2736. if (bp->tx_buf_ring == NULL)
  2737. return;
  2738. for (i = 0; i < TX_DESC_CNT; ) {
  2739. struct sw_bd *tx_buf = &bp->tx_buf_ring[i];
  2740. struct sk_buff *skb = tx_buf->skb;
  2741. int j, last;
  2742. if (skb == NULL) {
  2743. i++;
  2744. continue;
  2745. }
  2746. pci_unmap_single(bp->pdev, pci_unmap_addr(tx_buf, mapping),
  2747. skb_headlen(skb), PCI_DMA_TODEVICE);
  2748. tx_buf->skb = NULL;
  2749. last = skb_shinfo(skb)->nr_frags;
  2750. for (j = 0; j < last; j++) {
  2751. tx_buf = &bp->tx_buf_ring[i + j + 1];
  2752. pci_unmap_page(bp->pdev,
  2753. pci_unmap_addr(tx_buf, mapping),
  2754. skb_shinfo(skb)->frags[j].size,
  2755. PCI_DMA_TODEVICE);
  2756. }
  2757. dev_kfree_skb_any(skb);
  2758. i += j + 1;
  2759. }
  2760. }
  2761. static void
  2762. bnx2_free_rx_skbs(struct bnx2 *bp)
  2763. {
  2764. int i;
  2765. if (bp->rx_buf_ring == NULL)
  2766. return;
  2767. for (i = 0; i < RX_DESC_CNT; i++) {
  2768. struct sw_bd *rx_buf = &bp->rx_buf_ring[i];
  2769. struct sk_buff *skb = rx_buf->skb;
  2770. if (skb == NULL)
  2771. continue;
  2772. pci_unmap_single(bp->pdev, pci_unmap_addr(rx_buf, mapping),
  2773. bp->rx_buf_use_size, PCI_DMA_FROMDEVICE);
  2774. rx_buf->skb = NULL;
  2775. dev_kfree_skb_any(skb);
  2776. }
  2777. }
  2778. static void
  2779. bnx2_free_skbs(struct bnx2 *bp)
  2780. {
  2781. bnx2_free_tx_skbs(bp);
  2782. bnx2_free_rx_skbs(bp);
  2783. }
  2784. static int
  2785. bnx2_reset_nic(struct bnx2 *bp, u32 reset_code)
  2786. {
  2787. int rc;
  2788. rc = bnx2_reset_chip(bp, reset_code);
  2789. bnx2_free_skbs(bp);
  2790. if (rc)
  2791. return rc;
  2792. bnx2_init_chip(bp);
  2793. bnx2_init_tx_ring(bp);
  2794. bnx2_init_rx_ring(bp);
  2795. return 0;
  2796. }
  2797. static int
  2798. bnx2_init_nic(struct bnx2 *bp)
  2799. {
  2800. int rc;
  2801. if ((rc = bnx2_reset_nic(bp, BNX2_DRV_MSG_CODE_RESET)) != 0)
  2802. return rc;
  2803. bnx2_init_phy(bp);
  2804. bnx2_set_link(bp);
  2805. return 0;
  2806. }
  2807. static int
  2808. bnx2_test_registers(struct bnx2 *bp)
  2809. {
  2810. int ret;
  2811. int i;
  2812. static struct {
  2813. u16 offset;
  2814. u16 flags;
  2815. u32 rw_mask;
  2816. u32 ro_mask;
  2817. } reg_tbl[] = {
  2818. { 0x006c, 0, 0x00000000, 0x0000003f },
  2819. { 0x0090, 0, 0xffffffff, 0x00000000 },
  2820. { 0x0094, 0, 0x00000000, 0x00000000 },
  2821. { 0x0404, 0, 0x00003f00, 0x00000000 },
  2822. { 0x0418, 0, 0x00000000, 0xffffffff },
  2823. { 0x041c, 0, 0x00000000, 0xffffffff },
  2824. { 0x0420, 0, 0x00000000, 0x80ffffff },
  2825. { 0x0424, 0, 0x00000000, 0x00000000 },
  2826. { 0x0428, 0, 0x00000000, 0x00000001 },
  2827. { 0x0450, 0, 0x00000000, 0x0000ffff },
  2828. { 0x0454, 0, 0x00000000, 0xffffffff },
  2829. { 0x0458, 0, 0x00000000, 0xffffffff },
  2830. { 0x0808, 0, 0x00000000, 0xffffffff },
  2831. { 0x0854, 0, 0x00000000, 0xffffffff },
  2832. { 0x0868, 0, 0x00000000, 0x77777777 },
  2833. { 0x086c, 0, 0x00000000, 0x77777777 },
  2834. { 0x0870, 0, 0x00000000, 0x77777777 },
  2835. { 0x0874, 0, 0x00000000, 0x77777777 },
  2836. { 0x0c00, 0, 0x00000000, 0x00000001 },
  2837. { 0x0c04, 0, 0x00000000, 0x03ff0001 },
  2838. { 0x0c08, 0, 0x0f0ff073, 0x00000000 },
  2839. { 0x0c0c, 0, 0x00ffffff, 0x00000000 },
  2840. { 0x0c30, 0, 0x00000000, 0xffffffff },
  2841. { 0x0c34, 0, 0x00000000, 0xffffffff },
  2842. { 0x0c38, 0, 0x00000000, 0xffffffff },
  2843. { 0x0c3c, 0, 0x00000000, 0xffffffff },
  2844. { 0x0c40, 0, 0x00000000, 0xffffffff },
  2845. { 0x0c44, 0, 0x00000000, 0xffffffff },
  2846. { 0x0c48, 0, 0x00000000, 0x0007ffff },
  2847. { 0x0c4c, 0, 0x00000000, 0xffffffff },
  2848. { 0x0c50, 0, 0x00000000, 0xffffffff },
  2849. { 0x0c54, 0, 0x00000000, 0xffffffff },
  2850. { 0x0c58, 0, 0x00000000, 0xffffffff },
  2851. { 0x0c5c, 0, 0x00000000, 0xffffffff },
  2852. { 0x0c60, 0, 0x00000000, 0xffffffff },
  2853. { 0x0c64, 0, 0x00000000, 0xffffffff },
  2854. { 0x0c68, 0, 0x00000000, 0xffffffff },
  2855. { 0x0c6c, 0, 0x00000000, 0xffffffff },
  2856. { 0x0c70, 0, 0x00000000, 0xffffffff },
  2857. { 0x0c74, 0, 0x00000000, 0xffffffff },
  2858. { 0x0c78, 0, 0x00000000, 0xffffffff },
  2859. { 0x0c7c, 0, 0x00000000, 0xffffffff },
  2860. { 0x0c80, 0, 0x00000000, 0xffffffff },
  2861. { 0x0c84, 0, 0x00000000, 0xffffffff },
  2862. { 0x0c88, 0, 0x00000000, 0xffffffff },
  2863. { 0x0c8c, 0, 0x00000000, 0xffffffff },
  2864. { 0x0c90, 0, 0x00000000, 0xffffffff },
  2865. { 0x0c94, 0, 0x00000000, 0xffffffff },
  2866. { 0x0c98, 0, 0x00000000, 0xffffffff },
  2867. { 0x0c9c, 0, 0x00000000, 0xffffffff },
  2868. { 0x0ca0, 0, 0x00000000, 0xffffffff },
  2869. { 0x0ca4, 0, 0x00000000, 0xffffffff },
  2870. { 0x0ca8, 0, 0x00000000, 0x0007ffff },
  2871. { 0x0cac, 0, 0x00000000, 0xffffffff },
  2872. { 0x0cb0, 0, 0x00000000, 0xffffffff },
  2873. { 0x0cb4, 0, 0x00000000, 0xffffffff },
  2874. { 0x0cb8, 0, 0x00000000, 0xffffffff },
  2875. { 0x0cbc, 0, 0x00000000, 0xffffffff },
  2876. { 0x0cc0, 0, 0x00000000, 0xffffffff },
  2877. { 0x0cc4, 0, 0x00000000, 0xffffffff },
  2878. { 0x0cc8, 0, 0x00000000, 0xffffffff },
  2879. { 0x0ccc, 0, 0x00000000, 0xffffffff },
  2880. { 0x0cd0, 0, 0x00000000, 0xffffffff },
  2881. { 0x0cd4, 0, 0x00000000, 0xffffffff },
  2882. { 0x0cd8, 0, 0x00000000, 0xffffffff },
  2883. { 0x0cdc, 0, 0x00000000, 0xffffffff },
  2884. { 0x0ce0, 0, 0x00000000, 0xffffffff },
  2885. { 0x0ce4, 0, 0x00000000, 0xffffffff },
  2886. { 0x0ce8, 0, 0x00000000, 0xffffffff },
  2887. { 0x0cec, 0, 0x00000000, 0xffffffff },
  2888. { 0x0cf0, 0, 0x00000000, 0xffffffff },
  2889. { 0x0cf4, 0, 0x00000000, 0xffffffff },
  2890. { 0x0cf8, 0, 0x00000000, 0xffffffff },
  2891. { 0x0cfc, 0, 0x00000000, 0xffffffff },
  2892. { 0x0d00, 0, 0x00000000, 0xffffffff },
  2893. { 0x0d04, 0, 0x00000000, 0xffffffff },
  2894. { 0x1000, 0, 0x00000000, 0x00000001 },
  2895. { 0x1004, 0, 0x00000000, 0x000f0001 },
  2896. { 0x1044, 0, 0x00000000, 0xffc003ff },
  2897. { 0x1080, 0, 0x00000000, 0x0001ffff },
  2898. { 0x1084, 0, 0x00000000, 0xffffffff },
  2899. { 0x1088, 0, 0x00000000, 0xffffffff },
  2900. { 0x108c, 0, 0x00000000, 0xffffffff },
  2901. { 0x1090, 0, 0x00000000, 0xffffffff },
  2902. { 0x1094, 0, 0x00000000, 0xffffffff },
  2903. { 0x1098, 0, 0x00000000, 0xffffffff },
  2904. { 0x109c, 0, 0x00000000, 0xffffffff },
  2905. { 0x10a0, 0, 0x00000000, 0xffffffff },
  2906. { 0x1408, 0, 0x01c00800, 0x00000000 },
  2907. { 0x149c, 0, 0x8000ffff, 0x00000000 },
  2908. { 0x14a8, 0, 0x00000000, 0x000001ff },
  2909. { 0x14ac, 0, 0x0fffffff, 0x10000000 },
  2910. { 0x14b0, 0, 0x00000002, 0x00000001 },
  2911. { 0x14b8, 0, 0x00000000, 0x00000000 },
  2912. { 0x14c0, 0, 0x00000000, 0x00000009 },
  2913. { 0x14c4, 0, 0x00003fff, 0x00000000 },
  2914. { 0x14cc, 0, 0x00000000, 0x00000001 },
  2915. { 0x14d0, 0, 0xffffffff, 0x00000000 },
  2916. { 0x1500, 0, 0x00000000, 0xffffffff },
  2917. { 0x1504, 0, 0x00000000, 0xffffffff },
  2918. { 0x1508, 0, 0x00000000, 0xffffffff },
  2919. { 0x150c, 0, 0x00000000, 0xffffffff },
  2920. { 0x1510, 0, 0x00000000, 0xffffffff },
  2921. { 0x1514, 0, 0x00000000, 0xffffffff },
  2922. { 0x1518, 0, 0x00000000, 0xffffffff },
  2923. { 0x151c, 0, 0x00000000, 0xffffffff },
  2924. { 0x1520, 0, 0x00000000, 0xffffffff },
  2925. { 0x1524, 0, 0x00000000, 0xffffffff },
  2926. { 0x1528, 0, 0x00000000, 0xffffffff },
  2927. { 0x152c, 0, 0x00000000, 0xffffffff },
  2928. { 0x1530, 0, 0x00000000, 0xffffffff },
  2929. { 0x1534, 0, 0x00000000, 0xffffffff },
  2930. { 0x1538, 0, 0x00000000, 0xffffffff },
  2931. { 0x153c, 0, 0x00000000, 0xffffffff },
  2932. { 0x1540, 0, 0x00000000, 0xffffffff },
  2933. { 0x1544, 0, 0x00000000, 0xffffffff },
  2934. { 0x1548, 0, 0x00000000, 0xffffffff },
  2935. { 0x154c, 0, 0x00000000, 0xffffffff },
  2936. { 0x1550, 0, 0x00000000, 0xffffffff },
  2937. { 0x1554, 0, 0x00000000, 0xffffffff },
  2938. { 0x1558, 0, 0x00000000, 0xffffffff },
  2939. { 0x1600, 0, 0x00000000, 0xffffffff },
  2940. { 0x1604, 0, 0x00000000, 0xffffffff },
  2941. { 0x1608, 0, 0x00000000, 0xffffffff },
  2942. { 0x160c, 0, 0x00000000, 0xffffffff },
  2943. { 0x1610, 0, 0x00000000, 0xffffffff },
  2944. { 0x1614, 0, 0x00000000, 0xffffffff },
  2945. { 0x1618, 0, 0x00000000, 0xffffffff },
  2946. { 0x161c, 0, 0x00000000, 0xffffffff },
  2947. { 0x1620, 0, 0x00000000, 0xffffffff },
  2948. { 0x1624, 0, 0x00000000, 0xffffffff },
  2949. { 0x1628, 0, 0x00000000, 0xffffffff },
  2950. { 0x162c, 0, 0x00000000, 0xffffffff },
  2951. { 0x1630, 0, 0x00000000, 0xffffffff },
  2952. { 0x1634, 0, 0x00000000, 0xffffffff },
  2953. { 0x1638, 0, 0x00000000, 0xffffffff },
  2954. { 0x163c, 0, 0x00000000, 0xffffffff },
  2955. { 0x1640, 0, 0x00000000, 0xffffffff },
  2956. { 0x1644, 0, 0x00000000, 0xffffffff },
  2957. { 0x1648, 0, 0x00000000, 0xffffffff },
  2958. { 0x164c, 0, 0x00000000, 0xffffffff },
  2959. { 0x1650, 0, 0x00000000, 0xffffffff },
  2960. { 0x1654, 0, 0x00000000, 0xffffffff },
  2961. { 0x1800, 0, 0x00000000, 0x00000001 },
  2962. { 0x1804, 0, 0x00000000, 0x00000003 },
  2963. { 0x1840, 0, 0x00000000, 0xffffffff },
  2964. { 0x1844, 0, 0x00000000, 0xffffffff },
  2965. { 0x1848, 0, 0x00000000, 0xffffffff },
  2966. { 0x184c, 0, 0x00000000, 0xffffffff },
  2967. { 0x1850, 0, 0x00000000, 0xffffffff },
  2968. { 0x1900, 0, 0x7ffbffff, 0x00000000 },
  2969. { 0x1904, 0, 0xffffffff, 0x00000000 },
  2970. { 0x190c, 0, 0xffffffff, 0x00000000 },
  2971. { 0x1914, 0, 0xffffffff, 0x00000000 },
  2972. { 0x191c, 0, 0xffffffff, 0x00000000 },
  2973. { 0x1924, 0, 0xffffffff, 0x00000000 },
  2974. { 0x192c, 0, 0xffffffff, 0x00000000 },
  2975. { 0x1934, 0, 0xffffffff, 0x00000000 },
  2976. { 0x193c, 0, 0xffffffff, 0x00000000 },
  2977. { 0x1944, 0, 0xffffffff, 0x00000000 },
  2978. { 0x194c, 0, 0xffffffff, 0x00000000 },
  2979. { 0x1954, 0, 0xffffffff, 0x00000000 },
  2980. { 0x195c, 0, 0xffffffff, 0x00000000 },
  2981. { 0x1964, 0, 0xffffffff, 0x00000000 },
  2982. { 0x196c, 0, 0xffffffff, 0x00000000 },
  2983. { 0x1974, 0, 0xffffffff, 0x00000000 },
  2984. { 0x197c, 0, 0xffffffff, 0x00000000 },
  2985. { 0x1980, 0, 0x0700ffff, 0x00000000 },
  2986. { 0x1c00, 0, 0x00000000, 0x00000001 },
  2987. { 0x1c04, 0, 0x00000000, 0x00000003 },
  2988. { 0x1c08, 0, 0x0000000f, 0x00000000 },
  2989. { 0x1c40, 0, 0x00000000, 0xffffffff },
  2990. { 0x1c44, 0, 0x00000000, 0xffffffff },
  2991. { 0x1c48, 0, 0x00000000, 0xffffffff },
  2992. { 0x1c4c, 0, 0x00000000, 0xffffffff },
  2993. { 0x1c50, 0, 0x00000000, 0xffffffff },
  2994. { 0x1d00, 0, 0x7ffbffff, 0x00000000 },
  2995. { 0x1d04, 0, 0xffffffff, 0x00000000 },
  2996. { 0x1d0c, 0, 0xffffffff, 0x00000000 },
  2997. { 0x1d14, 0, 0xffffffff, 0x00000000 },
  2998. { 0x1d1c, 0, 0xffffffff, 0x00000000 },
  2999. { 0x1d24, 0, 0xffffffff, 0x00000000 },
  3000. { 0x1d2c, 0, 0xffffffff, 0x00000000 },
  3001. { 0x1d34, 0, 0xffffffff, 0x00000000 },
  3002. { 0x1d3c, 0, 0xffffffff, 0x00000000 },
  3003. { 0x1d44, 0, 0xffffffff, 0x00000000 },
  3004. { 0x1d4c, 0, 0xffffffff, 0x00000000 },
  3005. { 0x1d54, 0, 0xffffffff, 0x00000000 },
  3006. { 0x1d5c, 0, 0xffffffff, 0x00000000 },
  3007. { 0x1d64, 0, 0xffffffff, 0x00000000 },
  3008. { 0x1d6c, 0, 0xffffffff, 0x00000000 },
  3009. { 0x1d74, 0, 0xffffffff, 0x00000000 },
  3010. { 0x1d7c, 0, 0xffffffff, 0x00000000 },
  3011. { 0x1d80, 0, 0x0700ffff, 0x00000000 },
  3012. { 0x2004, 0, 0x00000000, 0x0337000f },
  3013. { 0x2008, 0, 0xffffffff, 0x00000000 },
  3014. { 0x200c, 0, 0xffffffff, 0x00000000 },
  3015. { 0x2010, 0, 0xffffffff, 0x00000000 },
  3016. { 0x2014, 0, 0x801fff80, 0x00000000 },
  3017. { 0x2018, 0, 0x000003ff, 0x00000000 },
  3018. { 0x2800, 0, 0x00000000, 0x00000001 },
  3019. { 0x2804, 0, 0x00000000, 0x00003f01 },
  3020. { 0x2808, 0, 0x0f3f3f03, 0x00000000 },
  3021. { 0x2810, 0, 0xffff0000, 0x00000000 },
  3022. { 0x2814, 0, 0xffff0000, 0x00000000 },
  3023. { 0x2818, 0, 0xffff0000, 0x00000000 },
  3024. { 0x281c, 0, 0xffff0000, 0x00000000 },
  3025. { 0x2834, 0, 0xffffffff, 0x00000000 },
  3026. { 0x2840, 0, 0x00000000, 0xffffffff },
  3027. { 0x2844, 0, 0x00000000, 0xffffffff },
  3028. { 0x2848, 0, 0xffffffff, 0x00000000 },
  3029. { 0x284c, 0, 0xf800f800, 0x07ff07ff },
  3030. { 0x2c00, 0, 0x00000000, 0x00000011 },
  3031. { 0x2c04, 0, 0x00000000, 0x00030007 },
  3032. { 0x3000, 0, 0x00000000, 0x00000001 },
  3033. { 0x3004, 0, 0x00000000, 0x007007ff },
  3034. { 0x3008, 0, 0x00000003, 0x00000000 },
  3035. { 0x300c, 0, 0xffffffff, 0x00000000 },
  3036. { 0x3010, 0, 0xffffffff, 0x00000000 },
  3037. { 0x3014, 0, 0xffffffff, 0x00000000 },
  3038. { 0x3034, 0, 0xffffffff, 0x00000000 },
  3039. { 0x3038, 0, 0xffffffff, 0x00000000 },
  3040. { 0x3050, 0, 0x00000001, 0x00000000 },
  3041. { 0x3c00, 0, 0x00000000, 0x00000001 },
  3042. { 0x3c04, 0, 0x00000000, 0x00070000 },
  3043. { 0x3c08, 0, 0x00007f71, 0x07f00000 },
  3044. { 0x3c0c, 0, 0x1f3ffffc, 0x00000000 },
  3045. { 0x3c10, 0, 0xffffffff, 0x00000000 },
  3046. { 0x3c14, 0, 0x00000000, 0xffffffff },
  3047. { 0x3c18, 0, 0x00000000, 0xffffffff },
  3048. { 0x3c1c, 0, 0xfffff000, 0x00000000 },
  3049. { 0x3c20, 0, 0xffffff00, 0x00000000 },
  3050. { 0x3c24, 0, 0xffffffff, 0x00000000 },
  3051. { 0x3c28, 0, 0xffffffff, 0x00000000 },
  3052. { 0x3c2c, 0, 0xffffffff, 0x00000000 },
  3053. { 0x3c30, 0, 0xffffffff, 0x00000000 },
  3054. { 0x3c34, 0, 0xffffffff, 0x00000000 },
  3055. { 0x3c38, 0, 0xffffffff, 0x00000000 },
  3056. { 0x3c3c, 0, 0xffffffff, 0x00000000 },
  3057. { 0x3c40, 0, 0xffffffff, 0x00000000 },
  3058. { 0x3c44, 0, 0xffffffff, 0x00000000 },
  3059. { 0x3c48, 0, 0xffffffff, 0x00000000 },
  3060. { 0x3c4c, 0, 0xffffffff, 0x00000000 },
  3061. { 0x3c50, 0, 0xffffffff, 0x00000000 },
  3062. { 0x3c54, 0, 0xffffffff, 0x00000000 },
  3063. { 0x3c58, 0, 0xffffffff, 0x00000000 },
  3064. { 0x3c5c, 0, 0xffffffff, 0x00000000 },
  3065. { 0x3c60, 0, 0xffffffff, 0x00000000 },
  3066. { 0x3c64, 0, 0xffffffff, 0x00000000 },
  3067. { 0x3c68, 0, 0xffffffff, 0x00000000 },
  3068. { 0x3c6c, 0, 0xffffffff, 0x00000000 },
  3069. { 0x3c70, 0, 0xffffffff, 0x00000000 },
  3070. { 0x3c74, 0, 0x0000003f, 0x00000000 },
  3071. { 0x3c78, 0, 0x00000000, 0x00000000 },
  3072. { 0x3c7c, 0, 0x00000000, 0x00000000 },
  3073. { 0x3c80, 0, 0x3fffffff, 0x00000000 },
  3074. { 0x3c84, 0, 0x0000003f, 0x00000000 },
  3075. { 0x3c88, 0, 0x00000000, 0xffffffff },
  3076. { 0x3c8c, 0, 0x00000000, 0xffffffff },
  3077. { 0x4000, 0, 0x00000000, 0x00000001 },
  3078. { 0x4004, 0, 0x00000000, 0x00030000 },
  3079. { 0x4008, 0, 0x00000ff0, 0x00000000 },
  3080. { 0x400c, 0, 0xffffffff, 0x00000000 },
  3081. { 0x4088, 0, 0x00000000, 0x00070303 },
  3082. { 0x4400, 0, 0x00000000, 0x00000001 },
  3083. { 0x4404, 0, 0x00000000, 0x00003f01 },
  3084. { 0x4408, 0, 0x7fff00ff, 0x00000000 },
  3085. { 0x440c, 0, 0xffffffff, 0x00000000 },
  3086. { 0x4410, 0, 0xffff, 0x0000 },
  3087. { 0x4414, 0, 0xffff, 0x0000 },
  3088. { 0x4418, 0, 0xffff, 0x0000 },
  3089. { 0x441c, 0, 0xffff, 0x0000 },
  3090. { 0x4428, 0, 0xffffffff, 0x00000000 },
  3091. { 0x442c, 0, 0xffffffff, 0x00000000 },
  3092. { 0x4430, 0, 0xffffffff, 0x00000000 },
  3093. { 0x4434, 0, 0xffffffff, 0x00000000 },
  3094. { 0x4438, 0, 0xffffffff, 0x00000000 },
  3095. { 0x443c, 0, 0xffffffff, 0x00000000 },
  3096. { 0x4440, 0, 0xffffffff, 0x00000000 },
  3097. { 0x4444, 0, 0xffffffff, 0x00000000 },
  3098. { 0x4c00, 0, 0x00000000, 0x00000001 },
  3099. { 0x4c04, 0, 0x00000000, 0x0000003f },
  3100. { 0x4c08, 0, 0xffffffff, 0x00000000 },
  3101. { 0x4c0c, 0, 0x0007fc00, 0x00000000 },
  3102. { 0x4c10, 0, 0x80003fe0, 0x00000000 },
  3103. { 0x4c14, 0, 0xffffffff, 0x00000000 },
  3104. { 0x4c44, 0, 0x00000000, 0x9fff9fff },
  3105. { 0x4c48, 0, 0x00000000, 0xb3009fff },
  3106. { 0x4c4c, 0, 0x00000000, 0x77f33b30 },
  3107. { 0x4c50, 0, 0x00000000, 0xffffffff },
  3108. { 0x5004, 0, 0x00000000, 0x0000007f },
  3109. { 0x5008, 0, 0x0f0007ff, 0x00000000 },
  3110. { 0x500c, 0, 0xf800f800, 0x07ff07ff },
  3111. { 0x5400, 0, 0x00000008, 0x00000001 },
  3112. { 0x5404, 0, 0x00000000, 0x0000003f },
  3113. { 0x5408, 0, 0x0000001f, 0x00000000 },
  3114. { 0x540c, 0, 0xffffffff, 0x00000000 },
  3115. { 0x5410, 0, 0xffffffff, 0x00000000 },
  3116. { 0x5414, 0, 0x0000ffff, 0x00000000 },
  3117. { 0x5418, 0, 0x0000ffff, 0x00000000 },
  3118. { 0x541c, 0, 0x0000ffff, 0x00000000 },
  3119. { 0x5420, 0, 0x0000ffff, 0x00000000 },
  3120. { 0x5428, 0, 0x000000ff, 0x00000000 },
  3121. { 0x542c, 0, 0xff00ffff, 0x00000000 },
  3122. { 0x5430, 0, 0x001fff80, 0x00000000 },
  3123. { 0x5438, 0, 0xffffffff, 0x00000000 },
  3124. { 0x543c, 0, 0xffffffff, 0x00000000 },
  3125. { 0x5440, 0, 0xf800f800, 0x07ff07ff },
  3126. { 0x5c00, 0, 0x00000000, 0x00000001 },
  3127. { 0x5c04, 0, 0x00000000, 0x0003000f },
  3128. { 0x5c08, 0, 0x00000003, 0x00000000 },
  3129. { 0x5c0c, 0, 0x0000fff8, 0x00000000 },
  3130. { 0x5c10, 0, 0x00000000, 0xffffffff },
  3131. { 0x5c80, 0, 0x00000000, 0x0f7113f1 },
  3132. { 0x5c84, 0, 0x00000000, 0x0000f333 },
  3133. { 0x5c88, 0, 0x00000000, 0x00077373 },
  3134. { 0x5c8c, 0, 0x00000000, 0x0007f737 },
  3135. { 0x6808, 0, 0x0000ff7f, 0x00000000 },
  3136. { 0x680c, 0, 0xffffffff, 0x00000000 },
  3137. { 0x6810, 0, 0xffffffff, 0x00000000 },
  3138. { 0x6814, 0, 0xffffffff, 0x00000000 },
  3139. { 0x6818, 0, 0xffffffff, 0x00000000 },
  3140. { 0x681c, 0, 0xffffffff, 0x00000000 },
  3141. { 0x6820, 0, 0x00ff00ff, 0x00000000 },
  3142. { 0x6824, 0, 0x00ff00ff, 0x00000000 },
  3143. { 0x6828, 0, 0x00ff00ff, 0x00000000 },
  3144. { 0x682c, 0, 0x03ff03ff, 0x00000000 },
  3145. { 0x6830, 0, 0x03ff03ff, 0x00000000 },
  3146. { 0x6834, 0, 0x03ff03ff, 0x00000000 },
  3147. { 0x6838, 0, 0x03ff03ff, 0x00000000 },
  3148. { 0x683c, 0, 0x0000ffff, 0x00000000 },
  3149. { 0x6840, 0, 0x00000ff0, 0x00000000 },
  3150. { 0x6844, 0, 0x00ffff00, 0x00000000 },
  3151. { 0x684c, 0, 0xffffffff, 0x00000000 },
  3152. { 0x6850, 0, 0x7f7f7f7f, 0x00000000 },
  3153. { 0x6854, 0, 0x7f7f7f7f, 0x00000000 },
  3154. { 0x6858, 0, 0x7f7f7f7f, 0x00000000 },
  3155. { 0x685c, 0, 0x7f7f7f7f, 0x00000000 },
  3156. { 0x6908, 0, 0x00000000, 0x0001ff0f },
  3157. { 0x690c, 0, 0x00000000, 0x0ffe00f0 },
  3158. { 0xffff, 0, 0x00000000, 0x00000000 },
  3159. };
  3160. ret = 0;
  3161. for (i = 0; reg_tbl[i].offset != 0xffff; i++) {
  3162. u32 offset, rw_mask, ro_mask, save_val, val;
  3163. offset = (u32) reg_tbl[i].offset;
  3164. rw_mask = reg_tbl[i].rw_mask;
  3165. ro_mask = reg_tbl[i].ro_mask;
  3166. save_val = readl(bp->regview + offset);
  3167. writel(0, bp->regview + offset);
  3168. val = readl(bp->regview + offset);
  3169. if ((val & rw_mask) != 0) {
  3170. goto reg_test_err;
  3171. }
  3172. if ((val & ro_mask) != (save_val & ro_mask)) {
  3173. goto reg_test_err;
  3174. }
  3175. writel(0xffffffff, bp->regview + offset);
  3176. val = readl(bp->regview + offset);
  3177. if ((val & rw_mask) != rw_mask) {
  3178. goto reg_test_err;
  3179. }
  3180. if ((val & ro_mask) != (save_val & ro_mask)) {
  3181. goto reg_test_err;
  3182. }
  3183. writel(save_val, bp->regview + offset);
  3184. continue;
  3185. reg_test_err:
  3186. writel(save_val, bp->regview + offset);
  3187. ret = -ENODEV;
  3188. break;
  3189. }
  3190. return ret;
  3191. }
  3192. static int
  3193. bnx2_do_mem_test(struct bnx2 *bp, u32 start, u32 size)
  3194. {
  3195. static u32 test_pattern[] = { 0x00000000, 0xffffffff, 0x55555555,
  3196. 0xaaaaaaaa , 0xaa55aa55, 0x55aa55aa };
  3197. int i;
  3198. for (i = 0; i < sizeof(test_pattern) / 4; i++) {
  3199. u32 offset;
  3200. for (offset = 0; offset < size; offset += 4) {
  3201. REG_WR_IND(bp, start + offset, test_pattern[i]);
  3202. if (REG_RD_IND(bp, start + offset) !=
  3203. test_pattern[i]) {
  3204. return -ENODEV;
  3205. }
  3206. }
  3207. }
  3208. return 0;
  3209. }
  3210. static int
  3211. bnx2_test_memory(struct bnx2 *bp)
  3212. {
  3213. int ret = 0;
  3214. int i;
  3215. static struct {
  3216. u32 offset;
  3217. u32 len;
  3218. } mem_tbl[] = {
  3219. { 0x60000, 0x4000 },
  3220. { 0xa0000, 0x3000 },
  3221. { 0xe0000, 0x4000 },
  3222. { 0x120000, 0x4000 },
  3223. { 0x1a0000, 0x4000 },
  3224. { 0x160000, 0x4000 },
  3225. { 0xffffffff, 0 },
  3226. };
  3227. for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) {
  3228. if ((ret = bnx2_do_mem_test(bp, mem_tbl[i].offset,
  3229. mem_tbl[i].len)) != 0) {
  3230. return ret;
  3231. }
  3232. }
  3233. return ret;
  3234. }
  3235. #define BNX2_MAC_LOOPBACK 0
  3236. #define BNX2_PHY_LOOPBACK 1
  3237. static int
  3238. bnx2_run_loopback(struct bnx2 *bp, int loopback_mode)
  3239. {
  3240. unsigned int pkt_size, num_pkts, i;
  3241. struct sk_buff *skb, *rx_skb;
  3242. unsigned char *packet;
  3243. u16 rx_start_idx, rx_idx;
  3244. u32 val;
  3245. dma_addr_t map;
  3246. struct tx_bd *txbd;
  3247. struct sw_bd *rx_buf;
  3248. struct l2_fhdr *rx_hdr;
  3249. int ret = -ENODEV;
  3250. if (loopback_mode == BNX2_MAC_LOOPBACK) {
  3251. bp->loopback = MAC_LOOPBACK;
  3252. bnx2_set_mac_loopback(bp);
  3253. }
  3254. else if (loopback_mode == BNX2_PHY_LOOPBACK) {
  3255. bp->loopback = 0;
  3256. bnx2_set_phy_loopback(bp);
  3257. }
  3258. else
  3259. return -EINVAL;
  3260. pkt_size = 1514;
  3261. skb = dev_alloc_skb(pkt_size);
  3262. if (!skb)
  3263. return -ENOMEM;
  3264. packet = skb_put(skb, pkt_size);
  3265. memcpy(packet, bp->mac_addr, 6);
  3266. memset(packet + 6, 0x0, 8);
  3267. for (i = 14; i < pkt_size; i++)
  3268. packet[i] = (unsigned char) (i & 0xff);
  3269. map = pci_map_single(bp->pdev, skb->data, pkt_size,
  3270. PCI_DMA_TODEVICE);
  3271. val = REG_RD(bp, BNX2_HC_COMMAND);
  3272. REG_WR(bp, BNX2_HC_COMMAND, val | BNX2_HC_COMMAND_COAL_NOW_WO_INT);
  3273. REG_RD(bp, BNX2_HC_COMMAND);
  3274. udelay(5);
  3275. rx_start_idx = bp->status_blk->status_rx_quick_consumer_index0;
  3276. num_pkts = 0;
  3277. txbd = &bp->tx_desc_ring[TX_RING_IDX(bp->tx_prod)];
  3278. txbd->tx_bd_haddr_hi = (u64) map >> 32;
  3279. txbd->tx_bd_haddr_lo = (u64) map & 0xffffffff;
  3280. txbd->tx_bd_mss_nbytes = pkt_size;
  3281. txbd->tx_bd_vlan_tag_flags = TX_BD_FLAGS_START | TX_BD_FLAGS_END;
  3282. num_pkts++;
  3283. bp->tx_prod = NEXT_TX_BD(bp->tx_prod);
  3284. bp->tx_prod_bseq += pkt_size;
  3285. REG_WR16(bp, MB_TX_CID_ADDR + BNX2_L2CTX_TX_HOST_BIDX, bp->tx_prod);
  3286. REG_WR(bp, MB_TX_CID_ADDR + BNX2_L2CTX_TX_HOST_BSEQ, bp->tx_prod_bseq);
  3287. udelay(100);
  3288. val = REG_RD(bp, BNX2_HC_COMMAND);
  3289. REG_WR(bp, BNX2_HC_COMMAND, val | BNX2_HC_COMMAND_COAL_NOW_WO_INT);
  3290. REG_RD(bp, BNX2_HC_COMMAND);
  3291. udelay(5);
  3292. pci_unmap_single(bp->pdev, map, pkt_size, PCI_DMA_TODEVICE);
  3293. dev_kfree_skb_irq(skb);
  3294. if (bp->status_blk->status_tx_quick_consumer_index0 != bp->tx_prod) {
  3295. goto loopback_test_done;
  3296. }
  3297. rx_idx = bp->status_blk->status_rx_quick_consumer_index0;
  3298. if (rx_idx != rx_start_idx + num_pkts) {
  3299. goto loopback_test_done;
  3300. }
  3301. rx_buf = &bp->rx_buf_ring[rx_start_idx];
  3302. rx_skb = rx_buf->skb;
  3303. rx_hdr = (struct l2_fhdr *) rx_skb->data;
  3304. skb_reserve(rx_skb, bp->rx_offset);
  3305. pci_dma_sync_single_for_cpu(bp->pdev,
  3306. pci_unmap_addr(rx_buf, mapping),
  3307. bp->rx_buf_size, PCI_DMA_FROMDEVICE);
  3308. if (rx_hdr->l2_fhdr_status &
  3309. (L2_FHDR_ERRORS_BAD_CRC |
  3310. L2_FHDR_ERRORS_PHY_DECODE |
  3311. L2_FHDR_ERRORS_ALIGNMENT |
  3312. L2_FHDR_ERRORS_TOO_SHORT |
  3313. L2_FHDR_ERRORS_GIANT_FRAME)) {
  3314. goto loopback_test_done;
  3315. }
  3316. if ((rx_hdr->l2_fhdr_pkt_len - 4) != pkt_size) {
  3317. goto loopback_test_done;
  3318. }
  3319. for (i = 14; i < pkt_size; i++) {
  3320. if (*(rx_skb->data + i) != (unsigned char) (i & 0xff)) {
  3321. goto loopback_test_done;
  3322. }
  3323. }
  3324. ret = 0;
  3325. loopback_test_done:
  3326. bp->loopback = 0;
  3327. return ret;
  3328. }
  3329. #define BNX2_MAC_LOOPBACK_FAILED 1
  3330. #define BNX2_PHY_LOOPBACK_FAILED 2
  3331. #define BNX2_LOOPBACK_FAILED (BNX2_MAC_LOOPBACK_FAILED | \
  3332. BNX2_PHY_LOOPBACK_FAILED)
  3333. static int
  3334. bnx2_test_loopback(struct bnx2 *bp)
  3335. {
  3336. int rc = 0;
  3337. if (!netif_running(bp->dev))
  3338. return BNX2_LOOPBACK_FAILED;
  3339. bnx2_reset_nic(bp, BNX2_DRV_MSG_CODE_RESET);
  3340. spin_lock_bh(&bp->phy_lock);
  3341. bnx2_init_phy(bp);
  3342. spin_unlock_bh(&bp->phy_lock);
  3343. if (bnx2_run_loopback(bp, BNX2_MAC_LOOPBACK))
  3344. rc |= BNX2_MAC_LOOPBACK_FAILED;
  3345. if (bnx2_run_loopback(bp, BNX2_PHY_LOOPBACK))
  3346. rc |= BNX2_PHY_LOOPBACK_FAILED;
  3347. return rc;
  3348. }
  3349. #define NVRAM_SIZE 0x200
  3350. #define CRC32_RESIDUAL 0xdebb20e3
  3351. static int
  3352. bnx2_test_nvram(struct bnx2 *bp)
  3353. {
  3354. u32 buf[NVRAM_SIZE / 4];
  3355. u8 *data = (u8 *) buf;
  3356. int rc = 0;
  3357. u32 magic, csum;
  3358. if ((rc = bnx2_nvram_read(bp, 0, data, 4)) != 0)
  3359. goto test_nvram_done;
  3360. magic = be32_to_cpu(buf[0]);
  3361. if (magic != 0x669955aa) {
  3362. rc = -ENODEV;
  3363. goto test_nvram_done;
  3364. }
  3365. if ((rc = bnx2_nvram_read(bp, 0x100, data, NVRAM_SIZE)) != 0)
  3366. goto test_nvram_done;
  3367. csum = ether_crc_le(0x100, data);
  3368. if (csum != CRC32_RESIDUAL) {
  3369. rc = -ENODEV;
  3370. goto test_nvram_done;
  3371. }
  3372. csum = ether_crc_le(0x100, data + 0x100);
  3373. if (csum != CRC32_RESIDUAL) {
  3374. rc = -ENODEV;
  3375. }
  3376. test_nvram_done:
  3377. return rc;
  3378. }
  3379. static int
  3380. bnx2_test_link(struct bnx2 *bp)
  3381. {
  3382. u32 bmsr;
  3383. spin_lock_bh(&bp->phy_lock);
  3384. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  3385. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  3386. spin_unlock_bh(&bp->phy_lock);
  3387. if (bmsr & BMSR_LSTATUS) {
  3388. return 0;
  3389. }
  3390. return -ENODEV;
  3391. }
  3392. static int
  3393. bnx2_test_intr(struct bnx2 *bp)
  3394. {
  3395. int i;
  3396. u32 val;
  3397. u16 status_idx;
  3398. if (!netif_running(bp->dev))
  3399. return -ENODEV;
  3400. status_idx = REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD) & 0xffff;
  3401. /* This register is not touched during run-time. */
  3402. val = REG_RD(bp, BNX2_HC_COMMAND);
  3403. REG_WR(bp, BNX2_HC_COMMAND, val | BNX2_HC_COMMAND_COAL_NOW);
  3404. REG_RD(bp, BNX2_HC_COMMAND);
  3405. for (i = 0; i < 10; i++) {
  3406. if ((REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD) & 0xffff) !=
  3407. status_idx) {
  3408. break;
  3409. }
  3410. msleep_interruptible(10);
  3411. }
  3412. if (i < 10)
  3413. return 0;
  3414. return -ENODEV;
  3415. }
  3416. static void
  3417. bnx2_timer(unsigned long data)
  3418. {
  3419. struct bnx2 *bp = (struct bnx2 *) data;
  3420. u32 msg;
  3421. if (!netif_running(bp->dev))
  3422. return;
  3423. if (atomic_read(&bp->intr_sem) != 0)
  3424. goto bnx2_restart_timer;
  3425. msg = (u32) ++bp->fw_drv_pulse_wr_seq;
  3426. REG_WR_IND(bp, bp->shmem_base + BNX2_DRV_PULSE_MB, msg);
  3427. if ((bp->phy_flags & PHY_SERDES_FLAG) &&
  3428. (CHIP_NUM(bp) == CHIP_NUM_5706)) {
  3429. spin_lock(&bp->phy_lock);
  3430. if (bp->serdes_an_pending) {
  3431. bp->serdes_an_pending--;
  3432. }
  3433. else if ((bp->link_up == 0) && (bp->autoneg & AUTONEG_SPEED)) {
  3434. u32 bmcr;
  3435. bp->current_interval = bp->timer_interval;
  3436. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  3437. if (bmcr & BMCR_ANENABLE) {
  3438. u32 phy1, phy2;
  3439. bnx2_write_phy(bp, 0x1c, 0x7c00);
  3440. bnx2_read_phy(bp, 0x1c, &phy1);
  3441. bnx2_write_phy(bp, 0x17, 0x0f01);
  3442. bnx2_read_phy(bp, 0x15, &phy2);
  3443. bnx2_write_phy(bp, 0x17, 0x0f01);
  3444. bnx2_read_phy(bp, 0x15, &phy2);
  3445. if ((phy1 & 0x10) && /* SIGNAL DETECT */
  3446. !(phy2 & 0x20)) { /* no CONFIG */
  3447. bmcr &= ~BMCR_ANENABLE;
  3448. bmcr |= BMCR_SPEED1000 |
  3449. BMCR_FULLDPLX;
  3450. bnx2_write_phy(bp, MII_BMCR, bmcr);
  3451. bp->phy_flags |=
  3452. PHY_PARALLEL_DETECT_FLAG;
  3453. }
  3454. }
  3455. }
  3456. else if ((bp->link_up) && (bp->autoneg & AUTONEG_SPEED) &&
  3457. (bp->phy_flags & PHY_PARALLEL_DETECT_FLAG)) {
  3458. u32 phy2;
  3459. bnx2_write_phy(bp, 0x17, 0x0f01);
  3460. bnx2_read_phy(bp, 0x15, &phy2);
  3461. if (phy2 & 0x20) {
  3462. u32 bmcr;
  3463. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  3464. bmcr |= BMCR_ANENABLE;
  3465. bnx2_write_phy(bp, MII_BMCR, bmcr);
  3466. bp->phy_flags &= ~PHY_PARALLEL_DETECT_FLAG;
  3467. }
  3468. }
  3469. else
  3470. bp->current_interval = bp->timer_interval;
  3471. spin_unlock(&bp->phy_lock);
  3472. }
  3473. bnx2_restart_timer:
  3474. mod_timer(&bp->timer, jiffies + bp->current_interval);
  3475. }
  3476. /* Called with rtnl_lock */
  3477. static int
  3478. bnx2_open(struct net_device *dev)
  3479. {
  3480. struct bnx2 *bp = netdev_priv(dev);
  3481. int rc;
  3482. bnx2_set_power_state(bp, PCI_D0);
  3483. bnx2_disable_int(bp);
  3484. rc = bnx2_alloc_mem(bp);
  3485. if (rc)
  3486. return rc;
  3487. if ((CHIP_ID(bp) != CHIP_ID_5706_A0) &&
  3488. (CHIP_ID(bp) != CHIP_ID_5706_A1) &&
  3489. !disable_msi) {
  3490. if (pci_enable_msi(bp->pdev) == 0) {
  3491. bp->flags |= USING_MSI_FLAG;
  3492. rc = request_irq(bp->pdev->irq, bnx2_msi, 0, dev->name,
  3493. dev);
  3494. }
  3495. else {
  3496. rc = request_irq(bp->pdev->irq, bnx2_interrupt,
  3497. SA_SHIRQ, dev->name, dev);
  3498. }
  3499. }
  3500. else {
  3501. rc = request_irq(bp->pdev->irq, bnx2_interrupt, SA_SHIRQ,
  3502. dev->name, dev);
  3503. }
  3504. if (rc) {
  3505. bnx2_free_mem(bp);
  3506. return rc;
  3507. }
  3508. rc = bnx2_init_nic(bp);
  3509. if (rc) {
  3510. free_irq(bp->pdev->irq, dev);
  3511. if (bp->flags & USING_MSI_FLAG) {
  3512. pci_disable_msi(bp->pdev);
  3513. bp->flags &= ~USING_MSI_FLAG;
  3514. }
  3515. bnx2_free_skbs(bp);
  3516. bnx2_free_mem(bp);
  3517. return rc;
  3518. }
  3519. mod_timer(&bp->timer, jiffies + bp->current_interval);
  3520. atomic_set(&bp->intr_sem, 0);
  3521. bnx2_enable_int(bp);
  3522. if (bp->flags & USING_MSI_FLAG) {
  3523. /* Test MSI to make sure it is working
  3524. * If MSI test fails, go back to INTx mode
  3525. */
  3526. if (bnx2_test_intr(bp) != 0) {
  3527. printk(KERN_WARNING PFX "%s: No interrupt was generated"
  3528. " using MSI, switching to INTx mode. Please"
  3529. " report this failure to the PCI maintainer"
  3530. " and include system chipset information.\n",
  3531. bp->dev->name);
  3532. bnx2_disable_int(bp);
  3533. free_irq(bp->pdev->irq, dev);
  3534. pci_disable_msi(bp->pdev);
  3535. bp->flags &= ~USING_MSI_FLAG;
  3536. rc = bnx2_init_nic(bp);
  3537. if (!rc) {
  3538. rc = request_irq(bp->pdev->irq, bnx2_interrupt,
  3539. SA_SHIRQ, dev->name, dev);
  3540. }
  3541. if (rc) {
  3542. bnx2_free_skbs(bp);
  3543. bnx2_free_mem(bp);
  3544. del_timer_sync(&bp->timer);
  3545. return rc;
  3546. }
  3547. bnx2_enable_int(bp);
  3548. }
  3549. }
  3550. if (bp->flags & USING_MSI_FLAG) {
  3551. printk(KERN_INFO PFX "%s: using MSI\n", dev->name);
  3552. }
  3553. netif_start_queue(dev);
  3554. return 0;
  3555. }
  3556. static void
  3557. bnx2_reset_task(void *data)
  3558. {
  3559. struct bnx2 *bp = data;
  3560. if (!netif_running(bp->dev))
  3561. return;
  3562. bp->in_reset_task = 1;
  3563. bnx2_netif_stop(bp);
  3564. bnx2_init_nic(bp);
  3565. atomic_set(&bp->intr_sem, 1);
  3566. bnx2_netif_start(bp);
  3567. bp->in_reset_task = 0;
  3568. }
  3569. static void
  3570. bnx2_tx_timeout(struct net_device *dev)
  3571. {
  3572. struct bnx2 *bp = netdev_priv(dev);
  3573. /* This allows the netif to be shutdown gracefully before resetting */
  3574. schedule_work(&bp->reset_task);
  3575. }
  3576. #ifdef BCM_VLAN
  3577. /* Called with rtnl_lock */
  3578. static void
  3579. bnx2_vlan_rx_register(struct net_device *dev, struct vlan_group *vlgrp)
  3580. {
  3581. struct bnx2 *bp = netdev_priv(dev);
  3582. bnx2_netif_stop(bp);
  3583. bp->vlgrp = vlgrp;
  3584. bnx2_set_rx_mode(dev);
  3585. bnx2_netif_start(bp);
  3586. }
  3587. /* Called with rtnl_lock */
  3588. static void
  3589. bnx2_vlan_rx_kill_vid(struct net_device *dev, uint16_t vid)
  3590. {
  3591. struct bnx2 *bp = netdev_priv(dev);
  3592. bnx2_netif_stop(bp);
  3593. if (bp->vlgrp)
  3594. bp->vlgrp->vlan_devices[vid] = NULL;
  3595. bnx2_set_rx_mode(dev);
  3596. bnx2_netif_start(bp);
  3597. }
  3598. #endif
  3599. /* Called with dev->xmit_lock.
  3600. * hard_start_xmit is pseudo-lockless - a lock is only required when
  3601. * the tx queue is full. This way, we get the benefit of lockless
  3602. * operations most of the time without the complexities to handle
  3603. * netif_stop_queue/wake_queue race conditions.
  3604. */
  3605. static int
  3606. bnx2_start_xmit(struct sk_buff *skb, struct net_device *dev)
  3607. {
  3608. struct bnx2 *bp = netdev_priv(dev);
  3609. dma_addr_t mapping;
  3610. struct tx_bd *txbd;
  3611. struct sw_bd *tx_buf;
  3612. u32 len, vlan_tag_flags, last_frag, mss;
  3613. u16 prod, ring_prod;
  3614. int i;
  3615. if (unlikely(bnx2_tx_avail(bp) < (skb_shinfo(skb)->nr_frags + 1))) {
  3616. netif_stop_queue(dev);
  3617. printk(KERN_ERR PFX "%s: BUG! Tx ring full when queue awake!\n",
  3618. dev->name);
  3619. return NETDEV_TX_BUSY;
  3620. }
  3621. len = skb_headlen(skb);
  3622. prod = bp->tx_prod;
  3623. ring_prod = TX_RING_IDX(prod);
  3624. vlan_tag_flags = 0;
  3625. if (skb->ip_summed == CHECKSUM_HW) {
  3626. vlan_tag_flags |= TX_BD_FLAGS_TCP_UDP_CKSUM;
  3627. }
  3628. if (bp->vlgrp != 0 && vlan_tx_tag_present(skb)) {
  3629. vlan_tag_flags |=
  3630. (TX_BD_FLAGS_VLAN_TAG | (vlan_tx_tag_get(skb) << 16));
  3631. }
  3632. #ifdef BCM_TSO
  3633. if ((mss = skb_shinfo(skb)->tso_size) &&
  3634. (skb->len > (bp->dev->mtu + ETH_HLEN))) {
  3635. u32 tcp_opt_len, ip_tcp_len;
  3636. if (skb_header_cloned(skb) &&
  3637. pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
  3638. dev_kfree_skb(skb);
  3639. return NETDEV_TX_OK;
  3640. }
  3641. tcp_opt_len = ((skb->h.th->doff - 5) * 4);
  3642. vlan_tag_flags |= TX_BD_FLAGS_SW_LSO;
  3643. tcp_opt_len = 0;
  3644. if (skb->h.th->doff > 5) {
  3645. tcp_opt_len = (skb->h.th->doff - 5) << 2;
  3646. }
  3647. ip_tcp_len = (skb->nh.iph->ihl << 2) + sizeof(struct tcphdr);
  3648. skb->nh.iph->check = 0;
  3649. skb->nh.iph->tot_len = ntohs(mss + ip_tcp_len + tcp_opt_len);
  3650. skb->h.th->check =
  3651. ~csum_tcpudp_magic(skb->nh.iph->saddr,
  3652. skb->nh.iph->daddr,
  3653. 0, IPPROTO_TCP, 0);
  3654. if (tcp_opt_len || (skb->nh.iph->ihl > 5)) {
  3655. vlan_tag_flags |= ((skb->nh.iph->ihl - 5) +
  3656. (tcp_opt_len >> 2)) << 8;
  3657. }
  3658. }
  3659. else
  3660. #endif
  3661. {
  3662. mss = 0;
  3663. }
  3664. mapping = pci_map_single(bp->pdev, skb->data, len, PCI_DMA_TODEVICE);
  3665. tx_buf = &bp->tx_buf_ring[ring_prod];
  3666. tx_buf->skb = skb;
  3667. pci_unmap_addr_set(tx_buf, mapping, mapping);
  3668. txbd = &bp->tx_desc_ring[ring_prod];
  3669. txbd->tx_bd_haddr_hi = (u64) mapping >> 32;
  3670. txbd->tx_bd_haddr_lo = (u64) mapping & 0xffffffff;
  3671. txbd->tx_bd_mss_nbytes = len | (mss << 16);
  3672. txbd->tx_bd_vlan_tag_flags = vlan_tag_flags | TX_BD_FLAGS_START;
  3673. last_frag = skb_shinfo(skb)->nr_frags;
  3674. for (i = 0; i < last_frag; i++) {
  3675. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  3676. prod = NEXT_TX_BD(prod);
  3677. ring_prod = TX_RING_IDX(prod);
  3678. txbd = &bp->tx_desc_ring[ring_prod];
  3679. len = frag->size;
  3680. mapping = pci_map_page(bp->pdev, frag->page, frag->page_offset,
  3681. len, PCI_DMA_TODEVICE);
  3682. pci_unmap_addr_set(&bp->tx_buf_ring[ring_prod],
  3683. mapping, mapping);
  3684. txbd->tx_bd_haddr_hi = (u64) mapping >> 32;
  3685. txbd->tx_bd_haddr_lo = (u64) mapping & 0xffffffff;
  3686. txbd->tx_bd_mss_nbytes = len | (mss << 16);
  3687. txbd->tx_bd_vlan_tag_flags = vlan_tag_flags;
  3688. }
  3689. txbd->tx_bd_vlan_tag_flags |= TX_BD_FLAGS_END;
  3690. prod = NEXT_TX_BD(prod);
  3691. bp->tx_prod_bseq += skb->len;
  3692. REG_WR16(bp, MB_TX_CID_ADDR + BNX2_L2CTX_TX_HOST_BIDX, prod);
  3693. REG_WR(bp, MB_TX_CID_ADDR + BNX2_L2CTX_TX_HOST_BSEQ, bp->tx_prod_bseq);
  3694. mmiowb();
  3695. bp->tx_prod = prod;
  3696. dev->trans_start = jiffies;
  3697. if (unlikely(bnx2_tx_avail(bp) <= MAX_SKB_FRAGS)) {
  3698. spin_lock(&bp->tx_lock);
  3699. netif_stop_queue(dev);
  3700. if (bnx2_tx_avail(bp) > MAX_SKB_FRAGS)
  3701. netif_wake_queue(dev);
  3702. spin_unlock(&bp->tx_lock);
  3703. }
  3704. return NETDEV_TX_OK;
  3705. }
  3706. /* Called with rtnl_lock */
  3707. static int
  3708. bnx2_close(struct net_device *dev)
  3709. {
  3710. struct bnx2 *bp = netdev_priv(dev);
  3711. u32 reset_code;
  3712. /* Calling flush_scheduled_work() may deadlock because
  3713. * linkwatch_event() may be on the workqueue and it will try to get
  3714. * the rtnl_lock which we are holding.
  3715. */
  3716. while (bp->in_reset_task)
  3717. msleep(1);
  3718. bnx2_netif_stop(bp);
  3719. del_timer_sync(&bp->timer);
  3720. if (bp->flags & NO_WOL_FLAG)
  3721. reset_code = BNX2_DRV_MSG_CODE_UNLOAD;
  3722. else if (bp->wol)
  3723. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_WOL;
  3724. else
  3725. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
  3726. bnx2_reset_chip(bp, reset_code);
  3727. free_irq(bp->pdev->irq, dev);
  3728. if (bp->flags & USING_MSI_FLAG) {
  3729. pci_disable_msi(bp->pdev);
  3730. bp->flags &= ~USING_MSI_FLAG;
  3731. }
  3732. bnx2_free_skbs(bp);
  3733. bnx2_free_mem(bp);
  3734. bp->link_up = 0;
  3735. netif_carrier_off(bp->dev);
  3736. bnx2_set_power_state(bp, PCI_D3hot);
  3737. return 0;
  3738. }
  3739. #define GET_NET_STATS64(ctr) \
  3740. (unsigned long) ((unsigned long) (ctr##_hi) << 32) + \
  3741. (unsigned long) (ctr##_lo)
  3742. #define GET_NET_STATS32(ctr) \
  3743. (ctr##_lo)
  3744. #if (BITS_PER_LONG == 64)
  3745. #define GET_NET_STATS GET_NET_STATS64
  3746. #else
  3747. #define GET_NET_STATS GET_NET_STATS32
  3748. #endif
  3749. static struct net_device_stats *
  3750. bnx2_get_stats(struct net_device *dev)
  3751. {
  3752. struct bnx2 *bp = netdev_priv(dev);
  3753. struct statistics_block *stats_blk = bp->stats_blk;
  3754. struct net_device_stats *net_stats = &bp->net_stats;
  3755. if (bp->stats_blk == NULL) {
  3756. return net_stats;
  3757. }
  3758. net_stats->rx_packets =
  3759. GET_NET_STATS(stats_blk->stat_IfHCInUcastPkts) +
  3760. GET_NET_STATS(stats_blk->stat_IfHCInMulticastPkts) +
  3761. GET_NET_STATS(stats_blk->stat_IfHCInBroadcastPkts);
  3762. net_stats->tx_packets =
  3763. GET_NET_STATS(stats_blk->stat_IfHCOutUcastPkts) +
  3764. GET_NET_STATS(stats_blk->stat_IfHCOutMulticastPkts) +
  3765. GET_NET_STATS(stats_blk->stat_IfHCOutBroadcastPkts);
  3766. net_stats->rx_bytes =
  3767. GET_NET_STATS(stats_blk->stat_IfHCInOctets);
  3768. net_stats->tx_bytes =
  3769. GET_NET_STATS(stats_blk->stat_IfHCOutOctets);
  3770. net_stats->multicast =
  3771. GET_NET_STATS(stats_blk->stat_IfHCOutMulticastPkts);
  3772. net_stats->collisions =
  3773. (unsigned long) stats_blk->stat_EtherStatsCollisions;
  3774. net_stats->rx_length_errors =
  3775. (unsigned long) (stats_blk->stat_EtherStatsUndersizePkts +
  3776. stats_blk->stat_EtherStatsOverrsizePkts);
  3777. net_stats->rx_over_errors =
  3778. (unsigned long) stats_blk->stat_IfInMBUFDiscards;
  3779. net_stats->rx_frame_errors =
  3780. (unsigned long) stats_blk->stat_Dot3StatsAlignmentErrors;
  3781. net_stats->rx_crc_errors =
  3782. (unsigned long) stats_blk->stat_Dot3StatsFCSErrors;
  3783. net_stats->rx_errors = net_stats->rx_length_errors +
  3784. net_stats->rx_over_errors + net_stats->rx_frame_errors +
  3785. net_stats->rx_crc_errors;
  3786. net_stats->tx_aborted_errors =
  3787. (unsigned long) (stats_blk->stat_Dot3StatsExcessiveCollisions +
  3788. stats_blk->stat_Dot3StatsLateCollisions);
  3789. if ((CHIP_NUM(bp) == CHIP_NUM_5706) ||
  3790. (CHIP_ID(bp) == CHIP_ID_5708_A0))
  3791. net_stats->tx_carrier_errors = 0;
  3792. else {
  3793. net_stats->tx_carrier_errors =
  3794. (unsigned long)
  3795. stats_blk->stat_Dot3StatsCarrierSenseErrors;
  3796. }
  3797. net_stats->tx_errors =
  3798. (unsigned long)
  3799. stats_blk->stat_emac_tx_stat_dot3statsinternalmactransmiterrors
  3800. +
  3801. net_stats->tx_aborted_errors +
  3802. net_stats->tx_carrier_errors;
  3803. return net_stats;
  3804. }
  3805. /* All ethtool functions called with rtnl_lock */
  3806. static int
  3807. bnx2_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  3808. {
  3809. struct bnx2 *bp = netdev_priv(dev);
  3810. cmd->supported = SUPPORTED_Autoneg;
  3811. if (bp->phy_flags & PHY_SERDES_FLAG) {
  3812. cmd->supported |= SUPPORTED_1000baseT_Full |
  3813. SUPPORTED_FIBRE;
  3814. cmd->port = PORT_FIBRE;
  3815. }
  3816. else {
  3817. cmd->supported |= SUPPORTED_10baseT_Half |
  3818. SUPPORTED_10baseT_Full |
  3819. SUPPORTED_100baseT_Half |
  3820. SUPPORTED_100baseT_Full |
  3821. SUPPORTED_1000baseT_Full |
  3822. SUPPORTED_TP;
  3823. cmd->port = PORT_TP;
  3824. }
  3825. cmd->advertising = bp->advertising;
  3826. if (bp->autoneg & AUTONEG_SPEED) {
  3827. cmd->autoneg = AUTONEG_ENABLE;
  3828. }
  3829. else {
  3830. cmd->autoneg = AUTONEG_DISABLE;
  3831. }
  3832. if (netif_carrier_ok(dev)) {
  3833. cmd->speed = bp->line_speed;
  3834. cmd->duplex = bp->duplex;
  3835. }
  3836. else {
  3837. cmd->speed = -1;
  3838. cmd->duplex = -1;
  3839. }
  3840. cmd->transceiver = XCVR_INTERNAL;
  3841. cmd->phy_address = bp->phy_addr;
  3842. return 0;
  3843. }
  3844. static int
  3845. bnx2_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  3846. {
  3847. struct bnx2 *bp = netdev_priv(dev);
  3848. u8 autoneg = bp->autoneg;
  3849. u8 req_duplex = bp->req_duplex;
  3850. u16 req_line_speed = bp->req_line_speed;
  3851. u32 advertising = bp->advertising;
  3852. if (cmd->autoneg == AUTONEG_ENABLE) {
  3853. autoneg |= AUTONEG_SPEED;
  3854. cmd->advertising &= ETHTOOL_ALL_COPPER_SPEED;
  3855. /* allow advertising 1 speed */
  3856. if ((cmd->advertising == ADVERTISED_10baseT_Half) ||
  3857. (cmd->advertising == ADVERTISED_10baseT_Full) ||
  3858. (cmd->advertising == ADVERTISED_100baseT_Half) ||
  3859. (cmd->advertising == ADVERTISED_100baseT_Full)) {
  3860. if (bp->phy_flags & PHY_SERDES_FLAG)
  3861. return -EINVAL;
  3862. advertising = cmd->advertising;
  3863. }
  3864. else if (cmd->advertising == ADVERTISED_1000baseT_Full) {
  3865. advertising = cmd->advertising;
  3866. }
  3867. else if (cmd->advertising == ADVERTISED_1000baseT_Half) {
  3868. return -EINVAL;
  3869. }
  3870. else {
  3871. if (bp->phy_flags & PHY_SERDES_FLAG) {
  3872. advertising = ETHTOOL_ALL_FIBRE_SPEED;
  3873. }
  3874. else {
  3875. advertising = ETHTOOL_ALL_COPPER_SPEED;
  3876. }
  3877. }
  3878. advertising |= ADVERTISED_Autoneg;
  3879. }
  3880. else {
  3881. if (bp->phy_flags & PHY_SERDES_FLAG) {
  3882. if ((cmd->speed != SPEED_1000) ||
  3883. (cmd->duplex != DUPLEX_FULL)) {
  3884. return -EINVAL;
  3885. }
  3886. }
  3887. else if (cmd->speed == SPEED_1000) {
  3888. return -EINVAL;
  3889. }
  3890. autoneg &= ~AUTONEG_SPEED;
  3891. req_line_speed = cmd->speed;
  3892. req_duplex = cmd->duplex;
  3893. advertising = 0;
  3894. }
  3895. bp->autoneg = autoneg;
  3896. bp->advertising = advertising;
  3897. bp->req_line_speed = req_line_speed;
  3898. bp->req_duplex = req_duplex;
  3899. spin_lock_bh(&bp->phy_lock);
  3900. bnx2_setup_phy(bp);
  3901. spin_unlock_bh(&bp->phy_lock);
  3902. return 0;
  3903. }
  3904. static void
  3905. bnx2_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  3906. {
  3907. struct bnx2 *bp = netdev_priv(dev);
  3908. strcpy(info->driver, DRV_MODULE_NAME);
  3909. strcpy(info->version, DRV_MODULE_VERSION);
  3910. strcpy(info->bus_info, pci_name(bp->pdev));
  3911. info->fw_version[0] = ((bp->fw_ver & 0xff000000) >> 24) + '0';
  3912. info->fw_version[2] = ((bp->fw_ver & 0xff0000) >> 16) + '0';
  3913. info->fw_version[4] = ((bp->fw_ver & 0xff00) >> 8) + '0';
  3914. info->fw_version[1] = info->fw_version[3] = '.';
  3915. info->fw_version[5] = 0;
  3916. }
  3917. static void
  3918. bnx2_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  3919. {
  3920. struct bnx2 *bp = netdev_priv(dev);
  3921. if (bp->flags & NO_WOL_FLAG) {
  3922. wol->supported = 0;
  3923. wol->wolopts = 0;
  3924. }
  3925. else {
  3926. wol->supported = WAKE_MAGIC;
  3927. if (bp->wol)
  3928. wol->wolopts = WAKE_MAGIC;
  3929. else
  3930. wol->wolopts = 0;
  3931. }
  3932. memset(&wol->sopass, 0, sizeof(wol->sopass));
  3933. }
  3934. static int
  3935. bnx2_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  3936. {
  3937. struct bnx2 *bp = netdev_priv(dev);
  3938. if (wol->wolopts & ~WAKE_MAGIC)
  3939. return -EINVAL;
  3940. if (wol->wolopts & WAKE_MAGIC) {
  3941. if (bp->flags & NO_WOL_FLAG)
  3942. return -EINVAL;
  3943. bp->wol = 1;
  3944. }
  3945. else {
  3946. bp->wol = 0;
  3947. }
  3948. return 0;
  3949. }
  3950. static int
  3951. bnx2_nway_reset(struct net_device *dev)
  3952. {
  3953. struct bnx2 *bp = netdev_priv(dev);
  3954. u32 bmcr;
  3955. if (!(bp->autoneg & AUTONEG_SPEED)) {
  3956. return -EINVAL;
  3957. }
  3958. spin_lock_bh(&bp->phy_lock);
  3959. /* Force a link down visible on the other side */
  3960. if (bp->phy_flags & PHY_SERDES_FLAG) {
  3961. bnx2_write_phy(bp, MII_BMCR, BMCR_LOOPBACK);
  3962. spin_unlock_bh(&bp->phy_lock);
  3963. msleep(20);
  3964. spin_lock_bh(&bp->phy_lock);
  3965. if (CHIP_NUM(bp) == CHIP_NUM_5706) {
  3966. bp->current_interval = SERDES_AN_TIMEOUT;
  3967. bp->serdes_an_pending = 1;
  3968. mod_timer(&bp->timer, jiffies + bp->current_interval);
  3969. }
  3970. }
  3971. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  3972. bmcr &= ~BMCR_LOOPBACK;
  3973. bnx2_write_phy(bp, MII_BMCR, bmcr | BMCR_ANRESTART | BMCR_ANENABLE);
  3974. spin_unlock_bh(&bp->phy_lock);
  3975. return 0;
  3976. }
  3977. static int
  3978. bnx2_get_eeprom_len(struct net_device *dev)
  3979. {
  3980. struct bnx2 *bp = netdev_priv(dev);
  3981. if (bp->flash_info == NULL)
  3982. return 0;
  3983. return (int) bp->flash_size;
  3984. }
  3985. static int
  3986. bnx2_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  3987. u8 *eebuf)
  3988. {
  3989. struct bnx2 *bp = netdev_priv(dev);
  3990. int rc;
  3991. /* parameters already validated in ethtool_get_eeprom */
  3992. rc = bnx2_nvram_read(bp, eeprom->offset, eebuf, eeprom->len);
  3993. return rc;
  3994. }
  3995. static int
  3996. bnx2_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  3997. u8 *eebuf)
  3998. {
  3999. struct bnx2 *bp = netdev_priv(dev);
  4000. int rc;
  4001. /* parameters already validated in ethtool_set_eeprom */
  4002. rc = bnx2_nvram_write(bp, eeprom->offset, eebuf, eeprom->len);
  4003. return rc;
  4004. }
  4005. static int
  4006. bnx2_get_coalesce(struct net_device *dev, struct ethtool_coalesce *coal)
  4007. {
  4008. struct bnx2 *bp = netdev_priv(dev);
  4009. memset(coal, 0, sizeof(struct ethtool_coalesce));
  4010. coal->rx_coalesce_usecs = bp->rx_ticks;
  4011. coal->rx_max_coalesced_frames = bp->rx_quick_cons_trip;
  4012. coal->rx_coalesce_usecs_irq = bp->rx_ticks_int;
  4013. coal->rx_max_coalesced_frames_irq = bp->rx_quick_cons_trip_int;
  4014. coal->tx_coalesce_usecs = bp->tx_ticks;
  4015. coal->tx_max_coalesced_frames = bp->tx_quick_cons_trip;
  4016. coal->tx_coalesce_usecs_irq = bp->tx_ticks_int;
  4017. coal->tx_max_coalesced_frames_irq = bp->tx_quick_cons_trip_int;
  4018. coal->stats_block_coalesce_usecs = bp->stats_ticks;
  4019. return 0;
  4020. }
  4021. static int
  4022. bnx2_set_coalesce(struct net_device *dev, struct ethtool_coalesce *coal)
  4023. {
  4024. struct bnx2 *bp = netdev_priv(dev);
  4025. bp->rx_ticks = (u16) coal->rx_coalesce_usecs;
  4026. if (bp->rx_ticks > 0x3ff) bp->rx_ticks = 0x3ff;
  4027. bp->rx_quick_cons_trip = (u16) coal->rx_max_coalesced_frames;
  4028. if (bp->rx_quick_cons_trip > 0xff) bp->rx_quick_cons_trip = 0xff;
  4029. bp->rx_ticks_int = (u16) coal->rx_coalesce_usecs_irq;
  4030. if (bp->rx_ticks_int > 0x3ff) bp->rx_ticks_int = 0x3ff;
  4031. bp->rx_quick_cons_trip_int = (u16) coal->rx_max_coalesced_frames_irq;
  4032. if (bp->rx_quick_cons_trip_int > 0xff)
  4033. bp->rx_quick_cons_trip_int = 0xff;
  4034. bp->tx_ticks = (u16) coal->tx_coalesce_usecs;
  4035. if (bp->tx_ticks > 0x3ff) bp->tx_ticks = 0x3ff;
  4036. bp->tx_quick_cons_trip = (u16) coal->tx_max_coalesced_frames;
  4037. if (bp->tx_quick_cons_trip > 0xff) bp->tx_quick_cons_trip = 0xff;
  4038. bp->tx_ticks_int = (u16) coal->tx_coalesce_usecs_irq;
  4039. if (bp->tx_ticks_int > 0x3ff) bp->tx_ticks_int = 0x3ff;
  4040. bp->tx_quick_cons_trip_int = (u16) coal->tx_max_coalesced_frames_irq;
  4041. if (bp->tx_quick_cons_trip_int > 0xff) bp->tx_quick_cons_trip_int =
  4042. 0xff;
  4043. bp->stats_ticks = coal->stats_block_coalesce_usecs;
  4044. if (bp->stats_ticks > 0xffff00) bp->stats_ticks = 0xffff00;
  4045. bp->stats_ticks &= 0xffff00;
  4046. if (netif_running(bp->dev)) {
  4047. bnx2_netif_stop(bp);
  4048. bnx2_init_nic(bp);
  4049. bnx2_netif_start(bp);
  4050. }
  4051. return 0;
  4052. }
  4053. static void
  4054. bnx2_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  4055. {
  4056. struct bnx2 *bp = netdev_priv(dev);
  4057. ering->rx_max_pending = MAX_RX_DESC_CNT;
  4058. ering->rx_mini_max_pending = 0;
  4059. ering->rx_jumbo_max_pending = 0;
  4060. ering->rx_pending = bp->rx_ring_size;
  4061. ering->rx_mini_pending = 0;
  4062. ering->rx_jumbo_pending = 0;
  4063. ering->tx_max_pending = MAX_TX_DESC_CNT;
  4064. ering->tx_pending = bp->tx_ring_size;
  4065. }
  4066. static int
  4067. bnx2_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  4068. {
  4069. struct bnx2 *bp = netdev_priv(dev);
  4070. if ((ering->rx_pending > MAX_RX_DESC_CNT) ||
  4071. (ering->tx_pending > MAX_TX_DESC_CNT) ||
  4072. (ering->tx_pending <= MAX_SKB_FRAGS)) {
  4073. return -EINVAL;
  4074. }
  4075. bp->rx_ring_size = ering->rx_pending;
  4076. bp->tx_ring_size = ering->tx_pending;
  4077. if (netif_running(bp->dev)) {
  4078. bnx2_netif_stop(bp);
  4079. bnx2_init_nic(bp);
  4080. bnx2_netif_start(bp);
  4081. }
  4082. return 0;
  4083. }
  4084. static void
  4085. bnx2_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  4086. {
  4087. struct bnx2 *bp = netdev_priv(dev);
  4088. epause->autoneg = ((bp->autoneg & AUTONEG_FLOW_CTRL) != 0);
  4089. epause->rx_pause = ((bp->flow_ctrl & FLOW_CTRL_RX) != 0);
  4090. epause->tx_pause = ((bp->flow_ctrl & FLOW_CTRL_TX) != 0);
  4091. }
  4092. static int
  4093. bnx2_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  4094. {
  4095. struct bnx2 *bp = netdev_priv(dev);
  4096. bp->req_flow_ctrl = 0;
  4097. if (epause->rx_pause)
  4098. bp->req_flow_ctrl |= FLOW_CTRL_RX;
  4099. if (epause->tx_pause)
  4100. bp->req_flow_ctrl |= FLOW_CTRL_TX;
  4101. if (epause->autoneg) {
  4102. bp->autoneg |= AUTONEG_FLOW_CTRL;
  4103. }
  4104. else {
  4105. bp->autoneg &= ~AUTONEG_FLOW_CTRL;
  4106. }
  4107. spin_lock_bh(&bp->phy_lock);
  4108. bnx2_setup_phy(bp);
  4109. spin_unlock_bh(&bp->phy_lock);
  4110. return 0;
  4111. }
  4112. static u32
  4113. bnx2_get_rx_csum(struct net_device *dev)
  4114. {
  4115. struct bnx2 *bp = netdev_priv(dev);
  4116. return bp->rx_csum;
  4117. }
  4118. static int
  4119. bnx2_set_rx_csum(struct net_device *dev, u32 data)
  4120. {
  4121. struct bnx2 *bp = netdev_priv(dev);
  4122. bp->rx_csum = data;
  4123. return 0;
  4124. }
  4125. #define BNX2_NUM_STATS 45
  4126. static struct {
  4127. char string[ETH_GSTRING_LEN];
  4128. } bnx2_stats_str_arr[BNX2_NUM_STATS] = {
  4129. { "rx_bytes" },
  4130. { "rx_error_bytes" },
  4131. { "tx_bytes" },
  4132. { "tx_error_bytes" },
  4133. { "rx_ucast_packets" },
  4134. { "rx_mcast_packets" },
  4135. { "rx_bcast_packets" },
  4136. { "tx_ucast_packets" },
  4137. { "tx_mcast_packets" },
  4138. { "tx_bcast_packets" },
  4139. { "tx_mac_errors" },
  4140. { "tx_carrier_errors" },
  4141. { "rx_crc_errors" },
  4142. { "rx_align_errors" },
  4143. { "tx_single_collisions" },
  4144. { "tx_multi_collisions" },
  4145. { "tx_deferred" },
  4146. { "tx_excess_collisions" },
  4147. { "tx_late_collisions" },
  4148. { "tx_total_collisions" },
  4149. { "rx_fragments" },
  4150. { "rx_jabbers" },
  4151. { "rx_undersize_packets" },
  4152. { "rx_oversize_packets" },
  4153. { "rx_64_byte_packets" },
  4154. { "rx_65_to_127_byte_packets" },
  4155. { "rx_128_to_255_byte_packets" },
  4156. { "rx_256_to_511_byte_packets" },
  4157. { "rx_512_to_1023_byte_packets" },
  4158. { "rx_1024_to_1522_byte_packets" },
  4159. { "rx_1523_to_9022_byte_packets" },
  4160. { "tx_64_byte_packets" },
  4161. { "tx_65_to_127_byte_packets" },
  4162. { "tx_128_to_255_byte_packets" },
  4163. { "tx_256_to_511_byte_packets" },
  4164. { "tx_512_to_1023_byte_packets" },
  4165. { "tx_1024_to_1522_byte_packets" },
  4166. { "tx_1523_to_9022_byte_packets" },
  4167. { "rx_xon_frames" },
  4168. { "rx_xoff_frames" },
  4169. { "tx_xon_frames" },
  4170. { "tx_xoff_frames" },
  4171. { "rx_mac_ctrl_frames" },
  4172. { "rx_filtered_packets" },
  4173. { "rx_discards" },
  4174. };
  4175. #define STATS_OFFSET32(offset_name) (offsetof(struct statistics_block, offset_name) / 4)
  4176. static unsigned long bnx2_stats_offset_arr[BNX2_NUM_STATS] = {
  4177. STATS_OFFSET32(stat_IfHCInOctets_hi),
  4178. STATS_OFFSET32(stat_IfHCInBadOctets_hi),
  4179. STATS_OFFSET32(stat_IfHCOutOctets_hi),
  4180. STATS_OFFSET32(stat_IfHCOutBadOctets_hi),
  4181. STATS_OFFSET32(stat_IfHCInUcastPkts_hi),
  4182. STATS_OFFSET32(stat_IfHCInMulticastPkts_hi),
  4183. STATS_OFFSET32(stat_IfHCInBroadcastPkts_hi),
  4184. STATS_OFFSET32(stat_IfHCOutUcastPkts_hi),
  4185. STATS_OFFSET32(stat_IfHCOutMulticastPkts_hi),
  4186. STATS_OFFSET32(stat_IfHCOutBroadcastPkts_hi),
  4187. STATS_OFFSET32(stat_emac_tx_stat_dot3statsinternalmactransmiterrors),
  4188. STATS_OFFSET32(stat_Dot3StatsCarrierSenseErrors),
  4189. STATS_OFFSET32(stat_Dot3StatsFCSErrors),
  4190. STATS_OFFSET32(stat_Dot3StatsAlignmentErrors),
  4191. STATS_OFFSET32(stat_Dot3StatsSingleCollisionFrames),
  4192. STATS_OFFSET32(stat_Dot3StatsMultipleCollisionFrames),
  4193. STATS_OFFSET32(stat_Dot3StatsDeferredTransmissions),
  4194. STATS_OFFSET32(stat_Dot3StatsExcessiveCollisions),
  4195. STATS_OFFSET32(stat_Dot3StatsLateCollisions),
  4196. STATS_OFFSET32(stat_EtherStatsCollisions),
  4197. STATS_OFFSET32(stat_EtherStatsFragments),
  4198. STATS_OFFSET32(stat_EtherStatsJabbers),
  4199. STATS_OFFSET32(stat_EtherStatsUndersizePkts),
  4200. STATS_OFFSET32(stat_EtherStatsOverrsizePkts),
  4201. STATS_OFFSET32(stat_EtherStatsPktsRx64Octets),
  4202. STATS_OFFSET32(stat_EtherStatsPktsRx65Octetsto127Octets),
  4203. STATS_OFFSET32(stat_EtherStatsPktsRx128Octetsto255Octets),
  4204. STATS_OFFSET32(stat_EtherStatsPktsRx256Octetsto511Octets),
  4205. STATS_OFFSET32(stat_EtherStatsPktsRx512Octetsto1023Octets),
  4206. STATS_OFFSET32(stat_EtherStatsPktsRx1024Octetsto1522Octets),
  4207. STATS_OFFSET32(stat_EtherStatsPktsRx1523Octetsto9022Octets),
  4208. STATS_OFFSET32(stat_EtherStatsPktsTx64Octets),
  4209. STATS_OFFSET32(stat_EtherStatsPktsTx65Octetsto127Octets),
  4210. STATS_OFFSET32(stat_EtherStatsPktsTx128Octetsto255Octets),
  4211. STATS_OFFSET32(stat_EtherStatsPktsTx256Octetsto511Octets),
  4212. STATS_OFFSET32(stat_EtherStatsPktsTx512Octetsto1023Octets),
  4213. STATS_OFFSET32(stat_EtherStatsPktsTx1024Octetsto1522Octets),
  4214. STATS_OFFSET32(stat_EtherStatsPktsTx1523Octetsto9022Octets),
  4215. STATS_OFFSET32(stat_XonPauseFramesReceived),
  4216. STATS_OFFSET32(stat_XoffPauseFramesReceived),
  4217. STATS_OFFSET32(stat_OutXonSent),
  4218. STATS_OFFSET32(stat_OutXoffSent),
  4219. STATS_OFFSET32(stat_MacControlFramesReceived),
  4220. STATS_OFFSET32(stat_IfInFramesL2FilterDiscards),
  4221. STATS_OFFSET32(stat_IfInMBUFDiscards),
  4222. };
  4223. /* stat_IfHCInBadOctets and stat_Dot3StatsCarrierSenseErrors are
  4224. * skipped because of errata.
  4225. */
  4226. static u8 bnx2_5706_stats_len_arr[BNX2_NUM_STATS] = {
  4227. 8,0,8,8,8,8,8,8,8,8,
  4228. 4,0,4,4,4,4,4,4,4,4,
  4229. 4,4,4,4,4,4,4,4,4,4,
  4230. 4,4,4,4,4,4,4,4,4,4,
  4231. 4,4,4,4,4,
  4232. };
  4233. static u8 bnx2_5708_stats_len_arr[BNX2_NUM_STATS] = {
  4234. 8,0,8,8,8,8,8,8,8,8,
  4235. 4,4,4,4,4,4,4,4,4,4,
  4236. 4,4,4,4,4,4,4,4,4,4,
  4237. 4,4,4,4,4,4,4,4,4,4,
  4238. 4,4,4,4,4,
  4239. };
  4240. #define BNX2_NUM_TESTS 6
  4241. static struct {
  4242. char string[ETH_GSTRING_LEN];
  4243. } bnx2_tests_str_arr[BNX2_NUM_TESTS] = {
  4244. { "register_test (offline)" },
  4245. { "memory_test (offline)" },
  4246. { "loopback_test (offline)" },
  4247. { "nvram_test (online)" },
  4248. { "interrupt_test (online)" },
  4249. { "link_test (online)" },
  4250. };
  4251. static int
  4252. bnx2_self_test_count(struct net_device *dev)
  4253. {
  4254. return BNX2_NUM_TESTS;
  4255. }
  4256. static void
  4257. bnx2_self_test(struct net_device *dev, struct ethtool_test *etest, u64 *buf)
  4258. {
  4259. struct bnx2 *bp = netdev_priv(dev);
  4260. memset(buf, 0, sizeof(u64) * BNX2_NUM_TESTS);
  4261. if (etest->flags & ETH_TEST_FL_OFFLINE) {
  4262. bnx2_netif_stop(bp);
  4263. bnx2_reset_chip(bp, BNX2_DRV_MSG_CODE_DIAG);
  4264. bnx2_free_skbs(bp);
  4265. if (bnx2_test_registers(bp) != 0) {
  4266. buf[0] = 1;
  4267. etest->flags |= ETH_TEST_FL_FAILED;
  4268. }
  4269. if (bnx2_test_memory(bp) != 0) {
  4270. buf[1] = 1;
  4271. etest->flags |= ETH_TEST_FL_FAILED;
  4272. }
  4273. if ((buf[2] = bnx2_test_loopback(bp)) != 0)
  4274. etest->flags |= ETH_TEST_FL_FAILED;
  4275. if (!netif_running(bp->dev)) {
  4276. bnx2_reset_chip(bp, BNX2_DRV_MSG_CODE_RESET);
  4277. }
  4278. else {
  4279. bnx2_init_nic(bp);
  4280. bnx2_netif_start(bp);
  4281. }
  4282. /* wait for link up */
  4283. msleep_interruptible(3000);
  4284. if ((!bp->link_up) && !(bp->phy_flags & PHY_SERDES_FLAG))
  4285. msleep_interruptible(4000);
  4286. }
  4287. if (bnx2_test_nvram(bp) != 0) {
  4288. buf[3] = 1;
  4289. etest->flags |= ETH_TEST_FL_FAILED;
  4290. }
  4291. if (bnx2_test_intr(bp) != 0) {
  4292. buf[4] = 1;
  4293. etest->flags |= ETH_TEST_FL_FAILED;
  4294. }
  4295. if (bnx2_test_link(bp) != 0) {
  4296. buf[5] = 1;
  4297. etest->flags |= ETH_TEST_FL_FAILED;
  4298. }
  4299. }
  4300. static void
  4301. bnx2_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
  4302. {
  4303. switch (stringset) {
  4304. case ETH_SS_STATS:
  4305. memcpy(buf, bnx2_stats_str_arr,
  4306. sizeof(bnx2_stats_str_arr));
  4307. break;
  4308. case ETH_SS_TEST:
  4309. memcpy(buf, bnx2_tests_str_arr,
  4310. sizeof(bnx2_tests_str_arr));
  4311. break;
  4312. }
  4313. }
  4314. static int
  4315. bnx2_get_stats_count(struct net_device *dev)
  4316. {
  4317. return BNX2_NUM_STATS;
  4318. }
  4319. static void
  4320. bnx2_get_ethtool_stats(struct net_device *dev,
  4321. struct ethtool_stats *stats, u64 *buf)
  4322. {
  4323. struct bnx2 *bp = netdev_priv(dev);
  4324. int i;
  4325. u32 *hw_stats = (u32 *) bp->stats_blk;
  4326. u8 *stats_len_arr = NULL;
  4327. if (hw_stats == NULL) {
  4328. memset(buf, 0, sizeof(u64) * BNX2_NUM_STATS);
  4329. return;
  4330. }
  4331. if ((CHIP_ID(bp) == CHIP_ID_5706_A0) ||
  4332. (CHIP_ID(bp) == CHIP_ID_5706_A1) ||
  4333. (CHIP_ID(bp) == CHIP_ID_5706_A2) ||
  4334. (CHIP_ID(bp) == CHIP_ID_5708_A0))
  4335. stats_len_arr = bnx2_5706_stats_len_arr;
  4336. else
  4337. stats_len_arr = bnx2_5708_stats_len_arr;
  4338. for (i = 0; i < BNX2_NUM_STATS; i++) {
  4339. if (stats_len_arr[i] == 0) {
  4340. /* skip this counter */
  4341. buf[i] = 0;
  4342. continue;
  4343. }
  4344. if (stats_len_arr[i] == 4) {
  4345. /* 4-byte counter */
  4346. buf[i] = (u64)
  4347. *(hw_stats + bnx2_stats_offset_arr[i]);
  4348. continue;
  4349. }
  4350. /* 8-byte counter */
  4351. buf[i] = (((u64) *(hw_stats +
  4352. bnx2_stats_offset_arr[i])) << 32) +
  4353. *(hw_stats + bnx2_stats_offset_arr[i] + 1);
  4354. }
  4355. }
  4356. static int
  4357. bnx2_phys_id(struct net_device *dev, u32 data)
  4358. {
  4359. struct bnx2 *bp = netdev_priv(dev);
  4360. int i;
  4361. u32 save;
  4362. if (data == 0)
  4363. data = 2;
  4364. save = REG_RD(bp, BNX2_MISC_CFG);
  4365. REG_WR(bp, BNX2_MISC_CFG, BNX2_MISC_CFG_LEDMODE_MAC);
  4366. for (i = 0; i < (data * 2); i++) {
  4367. if ((i % 2) == 0) {
  4368. REG_WR(bp, BNX2_EMAC_LED, BNX2_EMAC_LED_OVERRIDE);
  4369. }
  4370. else {
  4371. REG_WR(bp, BNX2_EMAC_LED, BNX2_EMAC_LED_OVERRIDE |
  4372. BNX2_EMAC_LED_1000MB_OVERRIDE |
  4373. BNX2_EMAC_LED_100MB_OVERRIDE |
  4374. BNX2_EMAC_LED_10MB_OVERRIDE |
  4375. BNX2_EMAC_LED_TRAFFIC_OVERRIDE |
  4376. BNX2_EMAC_LED_TRAFFIC);
  4377. }
  4378. msleep_interruptible(500);
  4379. if (signal_pending(current))
  4380. break;
  4381. }
  4382. REG_WR(bp, BNX2_EMAC_LED, 0);
  4383. REG_WR(bp, BNX2_MISC_CFG, save);
  4384. return 0;
  4385. }
  4386. static struct ethtool_ops bnx2_ethtool_ops = {
  4387. .get_settings = bnx2_get_settings,
  4388. .set_settings = bnx2_set_settings,
  4389. .get_drvinfo = bnx2_get_drvinfo,
  4390. .get_wol = bnx2_get_wol,
  4391. .set_wol = bnx2_set_wol,
  4392. .nway_reset = bnx2_nway_reset,
  4393. .get_link = ethtool_op_get_link,
  4394. .get_eeprom_len = bnx2_get_eeprom_len,
  4395. .get_eeprom = bnx2_get_eeprom,
  4396. .set_eeprom = bnx2_set_eeprom,
  4397. .get_coalesce = bnx2_get_coalesce,
  4398. .set_coalesce = bnx2_set_coalesce,
  4399. .get_ringparam = bnx2_get_ringparam,
  4400. .set_ringparam = bnx2_set_ringparam,
  4401. .get_pauseparam = bnx2_get_pauseparam,
  4402. .set_pauseparam = bnx2_set_pauseparam,
  4403. .get_rx_csum = bnx2_get_rx_csum,
  4404. .set_rx_csum = bnx2_set_rx_csum,
  4405. .get_tx_csum = ethtool_op_get_tx_csum,
  4406. .set_tx_csum = ethtool_op_set_tx_csum,
  4407. .get_sg = ethtool_op_get_sg,
  4408. .set_sg = ethtool_op_set_sg,
  4409. #ifdef BCM_TSO
  4410. .get_tso = ethtool_op_get_tso,
  4411. .set_tso = ethtool_op_set_tso,
  4412. #endif
  4413. .self_test_count = bnx2_self_test_count,
  4414. .self_test = bnx2_self_test,
  4415. .get_strings = bnx2_get_strings,
  4416. .phys_id = bnx2_phys_id,
  4417. .get_stats_count = bnx2_get_stats_count,
  4418. .get_ethtool_stats = bnx2_get_ethtool_stats,
  4419. .get_perm_addr = ethtool_op_get_perm_addr,
  4420. };
  4421. /* Called with rtnl_lock */
  4422. static int
  4423. bnx2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  4424. {
  4425. struct mii_ioctl_data *data = if_mii(ifr);
  4426. struct bnx2 *bp = netdev_priv(dev);
  4427. int err;
  4428. switch(cmd) {
  4429. case SIOCGMIIPHY:
  4430. data->phy_id = bp->phy_addr;
  4431. /* fallthru */
  4432. case SIOCGMIIREG: {
  4433. u32 mii_regval;
  4434. spin_lock_bh(&bp->phy_lock);
  4435. err = bnx2_read_phy(bp, data->reg_num & 0x1f, &mii_regval);
  4436. spin_unlock_bh(&bp->phy_lock);
  4437. data->val_out = mii_regval;
  4438. return err;
  4439. }
  4440. case SIOCSMIIREG:
  4441. if (!capable(CAP_NET_ADMIN))
  4442. return -EPERM;
  4443. spin_lock_bh(&bp->phy_lock);
  4444. err = bnx2_write_phy(bp, data->reg_num & 0x1f, data->val_in);
  4445. spin_unlock_bh(&bp->phy_lock);
  4446. return err;
  4447. default:
  4448. /* do nothing */
  4449. break;
  4450. }
  4451. return -EOPNOTSUPP;
  4452. }
  4453. /* Called with rtnl_lock */
  4454. static int
  4455. bnx2_change_mac_addr(struct net_device *dev, void *p)
  4456. {
  4457. struct sockaddr *addr = p;
  4458. struct bnx2 *bp = netdev_priv(dev);
  4459. if (!is_valid_ether_addr(addr->sa_data))
  4460. return -EINVAL;
  4461. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  4462. if (netif_running(dev))
  4463. bnx2_set_mac_addr(bp);
  4464. return 0;
  4465. }
  4466. /* Called with rtnl_lock */
  4467. static int
  4468. bnx2_change_mtu(struct net_device *dev, int new_mtu)
  4469. {
  4470. struct bnx2 *bp = netdev_priv(dev);
  4471. if (((new_mtu + ETH_HLEN) > MAX_ETHERNET_JUMBO_PACKET_SIZE) ||
  4472. ((new_mtu + ETH_HLEN) < MIN_ETHERNET_PACKET_SIZE))
  4473. return -EINVAL;
  4474. dev->mtu = new_mtu;
  4475. if (netif_running(dev)) {
  4476. bnx2_netif_stop(bp);
  4477. bnx2_init_nic(bp);
  4478. bnx2_netif_start(bp);
  4479. }
  4480. return 0;
  4481. }
  4482. #if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
  4483. static void
  4484. poll_bnx2(struct net_device *dev)
  4485. {
  4486. struct bnx2 *bp = netdev_priv(dev);
  4487. disable_irq(bp->pdev->irq);
  4488. bnx2_interrupt(bp->pdev->irq, dev, NULL);
  4489. enable_irq(bp->pdev->irq);
  4490. }
  4491. #endif
  4492. static int __devinit
  4493. bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
  4494. {
  4495. struct bnx2 *bp;
  4496. unsigned long mem_len;
  4497. int rc;
  4498. u32 reg;
  4499. SET_MODULE_OWNER(dev);
  4500. SET_NETDEV_DEV(dev, &pdev->dev);
  4501. bp = netdev_priv(dev);
  4502. bp->flags = 0;
  4503. bp->phy_flags = 0;
  4504. /* enable device (incl. PCI PM wakeup), and bus-mastering */
  4505. rc = pci_enable_device(pdev);
  4506. if (rc) {
  4507. printk(KERN_ERR PFX "Cannot enable PCI device, aborting.");
  4508. goto err_out;
  4509. }
  4510. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  4511. printk(KERN_ERR PFX "Cannot find PCI device base address, "
  4512. "aborting.\n");
  4513. rc = -ENODEV;
  4514. goto err_out_disable;
  4515. }
  4516. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  4517. if (rc) {
  4518. printk(KERN_ERR PFX "Cannot obtain PCI resources, aborting.\n");
  4519. goto err_out_disable;
  4520. }
  4521. pci_set_master(pdev);
  4522. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  4523. if (bp->pm_cap == 0) {
  4524. printk(KERN_ERR PFX "Cannot find power management capability, "
  4525. "aborting.\n");
  4526. rc = -EIO;
  4527. goto err_out_release;
  4528. }
  4529. bp->pcix_cap = pci_find_capability(pdev, PCI_CAP_ID_PCIX);
  4530. if (bp->pcix_cap == 0) {
  4531. printk(KERN_ERR PFX "Cannot find PCIX capability, aborting.\n");
  4532. rc = -EIO;
  4533. goto err_out_release;
  4534. }
  4535. if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) == 0) {
  4536. bp->flags |= USING_DAC_FLAG;
  4537. if (pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK) != 0) {
  4538. printk(KERN_ERR PFX "pci_set_consistent_dma_mask "
  4539. "failed, aborting.\n");
  4540. rc = -EIO;
  4541. goto err_out_release;
  4542. }
  4543. }
  4544. else if (pci_set_dma_mask(pdev, DMA_32BIT_MASK) != 0) {
  4545. printk(KERN_ERR PFX "System does not support DMA, aborting.\n");
  4546. rc = -EIO;
  4547. goto err_out_release;
  4548. }
  4549. bp->dev = dev;
  4550. bp->pdev = pdev;
  4551. spin_lock_init(&bp->phy_lock);
  4552. spin_lock_init(&bp->tx_lock);
  4553. INIT_WORK(&bp->reset_task, bnx2_reset_task, bp);
  4554. dev->base_addr = dev->mem_start = pci_resource_start(pdev, 0);
  4555. mem_len = MB_GET_CID_ADDR(17);
  4556. dev->mem_end = dev->mem_start + mem_len;
  4557. dev->irq = pdev->irq;
  4558. bp->regview = ioremap_nocache(dev->base_addr, mem_len);
  4559. if (!bp->regview) {
  4560. printk(KERN_ERR PFX "Cannot map register space, aborting.\n");
  4561. rc = -ENOMEM;
  4562. goto err_out_release;
  4563. }
  4564. /* Configure byte swap and enable write to the reg_window registers.
  4565. * Rely on CPU to do target byte swapping on big endian systems
  4566. * The chip's target access swapping will not swap all accesses
  4567. */
  4568. pci_write_config_dword(bp->pdev, BNX2_PCICFG_MISC_CONFIG,
  4569. BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
  4570. BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP);
  4571. bnx2_set_power_state(bp, PCI_D0);
  4572. bp->chip_id = REG_RD(bp, BNX2_MISC_ID);
  4573. /* Get bus information. */
  4574. reg = REG_RD(bp, BNX2_PCICFG_MISC_STATUS);
  4575. if (reg & BNX2_PCICFG_MISC_STATUS_PCIX_DET) {
  4576. u32 clkreg;
  4577. bp->flags |= PCIX_FLAG;
  4578. clkreg = REG_RD(bp, BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS);
  4579. clkreg &= BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET;
  4580. switch (clkreg) {
  4581. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_133MHZ:
  4582. bp->bus_speed_mhz = 133;
  4583. break;
  4584. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_95MHZ:
  4585. bp->bus_speed_mhz = 100;
  4586. break;
  4587. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_66MHZ:
  4588. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_80MHZ:
  4589. bp->bus_speed_mhz = 66;
  4590. break;
  4591. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_48MHZ:
  4592. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_55MHZ:
  4593. bp->bus_speed_mhz = 50;
  4594. break;
  4595. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_LOW:
  4596. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_32MHZ:
  4597. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_38MHZ:
  4598. bp->bus_speed_mhz = 33;
  4599. break;
  4600. }
  4601. }
  4602. else {
  4603. if (reg & BNX2_PCICFG_MISC_STATUS_M66EN)
  4604. bp->bus_speed_mhz = 66;
  4605. else
  4606. bp->bus_speed_mhz = 33;
  4607. }
  4608. if (reg & BNX2_PCICFG_MISC_STATUS_32BIT_DET)
  4609. bp->flags |= PCI_32BIT_FLAG;
  4610. /* 5706A0 may falsely detect SERR and PERR. */
  4611. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  4612. reg = REG_RD(bp, PCI_COMMAND);
  4613. reg &= ~(PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
  4614. REG_WR(bp, PCI_COMMAND, reg);
  4615. }
  4616. else if ((CHIP_ID(bp) == CHIP_ID_5706_A1) &&
  4617. !(bp->flags & PCIX_FLAG)) {
  4618. printk(KERN_ERR PFX "5706 A1 can only be used in a PCIX bus, "
  4619. "aborting.\n");
  4620. goto err_out_unmap;
  4621. }
  4622. bnx2_init_nvram(bp);
  4623. reg = REG_RD_IND(bp, BNX2_SHM_HDR_SIGNATURE);
  4624. if ((reg & BNX2_SHM_HDR_SIGNATURE_SIG_MASK) ==
  4625. BNX2_SHM_HDR_SIGNATURE_SIG)
  4626. bp->shmem_base = REG_RD_IND(bp, BNX2_SHM_HDR_ADDR_0);
  4627. else
  4628. bp->shmem_base = HOST_VIEW_SHMEM_BASE;
  4629. /* Get the permanent MAC address. First we need to make sure the
  4630. * firmware is actually running.
  4631. */
  4632. reg = REG_RD_IND(bp, bp->shmem_base + BNX2_DEV_INFO_SIGNATURE);
  4633. if ((reg & BNX2_DEV_INFO_SIGNATURE_MAGIC_MASK) !=
  4634. BNX2_DEV_INFO_SIGNATURE_MAGIC) {
  4635. printk(KERN_ERR PFX "Firmware not running, aborting.\n");
  4636. rc = -ENODEV;
  4637. goto err_out_unmap;
  4638. }
  4639. bp->fw_ver = REG_RD_IND(bp, bp->shmem_base + BNX2_DEV_INFO_BC_REV);
  4640. reg = REG_RD_IND(bp, bp->shmem_base + BNX2_PORT_HW_CFG_MAC_UPPER);
  4641. bp->mac_addr[0] = (u8) (reg >> 8);
  4642. bp->mac_addr[1] = (u8) reg;
  4643. reg = REG_RD_IND(bp, bp->shmem_base + BNX2_PORT_HW_CFG_MAC_LOWER);
  4644. bp->mac_addr[2] = (u8) (reg >> 24);
  4645. bp->mac_addr[3] = (u8) (reg >> 16);
  4646. bp->mac_addr[4] = (u8) (reg >> 8);
  4647. bp->mac_addr[5] = (u8) reg;
  4648. bp->tx_ring_size = MAX_TX_DESC_CNT;
  4649. bp->rx_ring_size = 100;
  4650. bp->rx_csum = 1;
  4651. bp->rx_offset = sizeof(struct l2_fhdr) + 2;
  4652. bp->tx_quick_cons_trip_int = 20;
  4653. bp->tx_quick_cons_trip = 20;
  4654. bp->tx_ticks_int = 80;
  4655. bp->tx_ticks = 80;
  4656. bp->rx_quick_cons_trip_int = 6;
  4657. bp->rx_quick_cons_trip = 6;
  4658. bp->rx_ticks_int = 18;
  4659. bp->rx_ticks = 18;
  4660. bp->stats_ticks = 1000000 & 0xffff00;
  4661. bp->timer_interval = HZ;
  4662. bp->current_interval = HZ;
  4663. bp->phy_addr = 1;
  4664. /* Disable WOL support if we are running on a SERDES chip. */
  4665. if (CHIP_BOND_ID(bp) & CHIP_BOND_ID_SERDES_BIT) {
  4666. bp->phy_flags |= PHY_SERDES_FLAG;
  4667. bp->flags |= NO_WOL_FLAG;
  4668. if (CHIP_NUM(bp) == CHIP_NUM_5708) {
  4669. bp->phy_addr = 2;
  4670. reg = REG_RD_IND(bp, bp->shmem_base +
  4671. BNX2_SHARED_HW_CFG_CONFIG);
  4672. if (reg & BNX2_SHARED_HW_CFG_PHY_2_5G)
  4673. bp->phy_flags |= PHY_2_5G_CAPABLE_FLAG;
  4674. }
  4675. }
  4676. if (CHIP_NUM(bp) == CHIP_NUM_5708)
  4677. bp->flags |= NO_WOL_FLAG;
  4678. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  4679. bp->tx_quick_cons_trip_int =
  4680. bp->tx_quick_cons_trip;
  4681. bp->tx_ticks_int = bp->tx_ticks;
  4682. bp->rx_quick_cons_trip_int =
  4683. bp->rx_quick_cons_trip;
  4684. bp->rx_ticks_int = bp->rx_ticks;
  4685. bp->comp_prod_trip_int = bp->comp_prod_trip;
  4686. bp->com_ticks_int = bp->com_ticks;
  4687. bp->cmd_ticks_int = bp->cmd_ticks;
  4688. }
  4689. bp->autoneg = AUTONEG_SPEED | AUTONEG_FLOW_CTRL;
  4690. bp->req_line_speed = 0;
  4691. if (bp->phy_flags & PHY_SERDES_FLAG) {
  4692. bp->advertising = ETHTOOL_ALL_FIBRE_SPEED | ADVERTISED_Autoneg;
  4693. reg = REG_RD_IND(bp, bp->shmem_base + BNX2_PORT_HW_CFG_CONFIG);
  4694. reg &= BNX2_PORT_HW_CFG_CFG_DFLT_LINK_MASK;
  4695. if (reg == BNX2_PORT_HW_CFG_CFG_DFLT_LINK_1G) {
  4696. bp->autoneg = 0;
  4697. bp->req_line_speed = bp->line_speed = SPEED_1000;
  4698. bp->req_duplex = DUPLEX_FULL;
  4699. }
  4700. }
  4701. else {
  4702. bp->advertising = ETHTOOL_ALL_COPPER_SPEED | ADVERTISED_Autoneg;
  4703. }
  4704. bp->req_flow_ctrl = FLOW_CTRL_RX | FLOW_CTRL_TX;
  4705. init_timer(&bp->timer);
  4706. bp->timer.expires = RUN_AT(bp->timer_interval);
  4707. bp->timer.data = (unsigned long) bp;
  4708. bp->timer.function = bnx2_timer;
  4709. return 0;
  4710. err_out_unmap:
  4711. if (bp->regview) {
  4712. iounmap(bp->regview);
  4713. bp->regview = NULL;
  4714. }
  4715. err_out_release:
  4716. pci_release_regions(pdev);
  4717. err_out_disable:
  4718. pci_disable_device(pdev);
  4719. pci_set_drvdata(pdev, NULL);
  4720. err_out:
  4721. return rc;
  4722. }
  4723. static int __devinit
  4724. bnx2_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  4725. {
  4726. static int version_printed = 0;
  4727. struct net_device *dev = NULL;
  4728. struct bnx2 *bp;
  4729. int rc, i;
  4730. if (version_printed++ == 0)
  4731. printk(KERN_INFO "%s", version);
  4732. /* dev zeroed in init_etherdev */
  4733. dev = alloc_etherdev(sizeof(*bp));
  4734. if (!dev)
  4735. return -ENOMEM;
  4736. rc = bnx2_init_board(pdev, dev);
  4737. if (rc < 0) {
  4738. free_netdev(dev);
  4739. return rc;
  4740. }
  4741. dev->open = bnx2_open;
  4742. dev->hard_start_xmit = bnx2_start_xmit;
  4743. dev->stop = bnx2_close;
  4744. dev->get_stats = bnx2_get_stats;
  4745. dev->set_multicast_list = bnx2_set_rx_mode;
  4746. dev->do_ioctl = bnx2_ioctl;
  4747. dev->set_mac_address = bnx2_change_mac_addr;
  4748. dev->change_mtu = bnx2_change_mtu;
  4749. dev->tx_timeout = bnx2_tx_timeout;
  4750. dev->watchdog_timeo = TX_TIMEOUT;
  4751. #ifdef BCM_VLAN
  4752. dev->vlan_rx_register = bnx2_vlan_rx_register;
  4753. dev->vlan_rx_kill_vid = bnx2_vlan_rx_kill_vid;
  4754. #endif
  4755. dev->poll = bnx2_poll;
  4756. dev->ethtool_ops = &bnx2_ethtool_ops;
  4757. dev->weight = 64;
  4758. bp = netdev_priv(dev);
  4759. #if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
  4760. dev->poll_controller = poll_bnx2;
  4761. #endif
  4762. if ((rc = register_netdev(dev))) {
  4763. printk(KERN_ERR PFX "Cannot register net device\n");
  4764. if (bp->regview)
  4765. iounmap(bp->regview);
  4766. pci_release_regions(pdev);
  4767. pci_disable_device(pdev);
  4768. pci_set_drvdata(pdev, NULL);
  4769. free_netdev(dev);
  4770. return rc;
  4771. }
  4772. pci_set_drvdata(pdev, dev);
  4773. memcpy(dev->dev_addr, bp->mac_addr, 6);
  4774. memcpy(dev->perm_addr, bp->mac_addr, 6);
  4775. bp->name = board_info[ent->driver_data].name,
  4776. printk(KERN_INFO "%s: %s (%c%d) PCI%s %s %dMHz found at mem %lx, "
  4777. "IRQ %d, ",
  4778. dev->name,
  4779. bp->name,
  4780. ((CHIP_ID(bp) & 0xf000) >> 12) + 'A',
  4781. ((CHIP_ID(bp) & 0x0ff0) >> 4),
  4782. ((bp->flags & PCIX_FLAG) ? "-X" : ""),
  4783. ((bp->flags & PCI_32BIT_FLAG) ? "32-bit" : "64-bit"),
  4784. bp->bus_speed_mhz,
  4785. dev->base_addr,
  4786. bp->pdev->irq);
  4787. printk("node addr ");
  4788. for (i = 0; i < 6; i++)
  4789. printk("%2.2x", dev->dev_addr[i]);
  4790. printk("\n");
  4791. dev->features |= NETIF_F_SG;
  4792. if (bp->flags & USING_DAC_FLAG)
  4793. dev->features |= NETIF_F_HIGHDMA;
  4794. dev->features |= NETIF_F_IP_CSUM;
  4795. #ifdef BCM_VLAN
  4796. dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  4797. #endif
  4798. #ifdef BCM_TSO
  4799. dev->features |= NETIF_F_TSO;
  4800. #endif
  4801. netif_carrier_off(bp->dev);
  4802. return 0;
  4803. }
  4804. static void __devexit
  4805. bnx2_remove_one(struct pci_dev *pdev)
  4806. {
  4807. struct net_device *dev = pci_get_drvdata(pdev);
  4808. struct bnx2 *bp = netdev_priv(dev);
  4809. flush_scheduled_work();
  4810. unregister_netdev(dev);
  4811. if (bp->regview)
  4812. iounmap(bp->regview);
  4813. free_netdev(dev);
  4814. pci_release_regions(pdev);
  4815. pci_disable_device(pdev);
  4816. pci_set_drvdata(pdev, NULL);
  4817. }
  4818. static int
  4819. bnx2_suspend(struct pci_dev *pdev, pm_message_t state)
  4820. {
  4821. struct net_device *dev = pci_get_drvdata(pdev);
  4822. struct bnx2 *bp = netdev_priv(dev);
  4823. u32 reset_code;
  4824. if (!netif_running(dev))
  4825. return 0;
  4826. bnx2_netif_stop(bp);
  4827. netif_device_detach(dev);
  4828. del_timer_sync(&bp->timer);
  4829. if (bp->flags & NO_WOL_FLAG)
  4830. reset_code = BNX2_DRV_MSG_CODE_UNLOAD;
  4831. else if (bp->wol)
  4832. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_WOL;
  4833. else
  4834. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
  4835. bnx2_reset_chip(bp, reset_code);
  4836. bnx2_free_skbs(bp);
  4837. bnx2_set_power_state(bp, pci_choose_state(pdev, state));
  4838. return 0;
  4839. }
  4840. static int
  4841. bnx2_resume(struct pci_dev *pdev)
  4842. {
  4843. struct net_device *dev = pci_get_drvdata(pdev);
  4844. struct bnx2 *bp = netdev_priv(dev);
  4845. if (!netif_running(dev))
  4846. return 0;
  4847. bnx2_set_power_state(bp, PCI_D0);
  4848. netif_device_attach(dev);
  4849. bnx2_init_nic(bp);
  4850. bnx2_netif_start(bp);
  4851. return 0;
  4852. }
  4853. static struct pci_driver bnx2_pci_driver = {
  4854. .name = DRV_MODULE_NAME,
  4855. .id_table = bnx2_pci_tbl,
  4856. .probe = bnx2_init_one,
  4857. .remove = __devexit_p(bnx2_remove_one),
  4858. .suspend = bnx2_suspend,
  4859. .resume = bnx2_resume,
  4860. };
  4861. static int __init bnx2_init(void)
  4862. {
  4863. return pci_module_init(&bnx2_pci_driver);
  4864. }
  4865. static void __exit bnx2_cleanup(void)
  4866. {
  4867. pci_unregister_driver(&bnx2_pci_driver);
  4868. }
  4869. module_init(bnx2_init);
  4870. module_exit(bnx2_cleanup);