bnx2.c 168 KB

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