bnx2.c 179 KB

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