bnx2.c 165 KB

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