bnx2.c 185 KB

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