bnx2.c 188 KB

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