bnx2.c 176 KB

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