bnx2.c 185 KB

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