bnx2.c 184 KB

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