bnx2.c 155 KB

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