bnx2.c 189 KB

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