bnx2.c 138 KB

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